• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.recents;
18 
19 import android.appwidget.AppWidgetHost;
20 import android.appwidget.AppWidgetHostView;
21 import android.appwidget.AppWidgetProviderInfo;
22 import android.content.Context;
23 
24 /** Our special app widget host for the Search widget */
25 public class RecentsAppWidgetHost extends AppWidgetHost {
26 
27     /* Callbacks to notify when an app package changes */
28     interface RecentsAppWidgetHostCallbacks {
refreshSearchWidgetView()29         void refreshSearchWidgetView();
30     }
31 
32     RecentsAppWidgetHostCallbacks mCb;
33     boolean mIsListening;
34 
RecentsAppWidgetHost(Context context, int hostId)35     public RecentsAppWidgetHost(Context context, int hostId) {
36         super(context, hostId);
37     }
38 
startListening(RecentsAppWidgetHostCallbacks cb)39     public void startListening(RecentsAppWidgetHostCallbacks cb) {
40         mCb = cb;
41         if (!mIsListening) {
42             mIsListening = true;
43             super.startListening();
44         }
45     }
46 
47     @Override
stopListening()48     public void stopListening() {
49         if (mIsListening) {
50             super.stopListening();
51         }
52         // Ensure that we release any references to the callbacks
53         mCb = null;
54         mIsListening = false;
55     }
56 
57     @Override
onCreateView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget)58     protected AppWidgetHostView onCreateView(Context context, int appWidgetId,
59                                              AppWidgetProviderInfo appWidget) {
60         return new RecentsAppWidgetHostView(context);
61     }
62 
63     /**
64      * Note: this is only called for packages that have updated, not removed.
65      */
66     @Override
onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidgetInfo)67     protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidgetInfo) {
68         super.onProviderChanged(appWidgetId, appWidgetInfo);
69         if (mIsListening && mCb != null) {
70             mCb.refreshSearchWidgetView();
71         }
72     }
73 }
74