blob: 1af49536582533e27164140c75fea299ebbfee77 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
Kenny Root15a4d2f2010-03-11 18:20:12 -08002 * Copyright (C) 2009 The Android Open Source Project
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003 *
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
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070017package android.appwidget;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Svetoslav7643f7e2014-12-17 17:55:34 -080019import java.lang.ref.WeakReference;
Adam Cohend2e20de2011-02-25 12:03:37 -080020import java.util.ArrayList;
21import java.util.HashMap;
22
Svetoslav8e1d2992014-08-08 12:48:06 -070023import android.annotation.NonNull;
24import android.annotation.Nullable;
Svetoslav976e8bd2014-07-16 15:12:03 -070025import android.app.Activity;
26import android.content.ActivityNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.Context;
Svetoslav976e8bd2014-07-16 15:12:03 -070028import android.content.IntentSender;
Adam Cohen3ff2d862012-09-26 14:07:57 -070029import android.os.Binder;
Svetoslav8e1d2992014-08-08 12:48:06 -070030import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.Handler;
32import android.os.IBinder;
33import android.os.Looper;
34import android.os.Message;
Jim Millerf229e4d2012-09-12 20:32:50 -070035import android.os.Process;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.os.RemoteException;
37import android.os.ServiceManager;
Adam Cohend2e20de2011-02-25 12:03:37 -080038import android.util.DisplayMetrics;
39import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.widget.RemoteViews;
Jim Millere667a7a2012-08-09 19:22:32 -070041import android.widget.RemoteViews.OnClickHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070043import com.android.internal.appwidget.IAppWidgetHost;
44import com.android.internal.appwidget.IAppWidgetService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
46/**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070047 * AppWidgetHost provides the interaction with the AppWidget service for apps,
48 * like the home screen, that want to embed AppWidgets in their UI.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070050public class AppWidgetHost {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
52 static final int HANDLE_UPDATE = 1;
53 static final int HANDLE_PROVIDER_CHANGED = 2;
Winson Chung7fbd2842012-06-13 10:35:51 -070054 static final int HANDLE_PROVIDERS_CHANGED = 3;
55 static final int HANDLE_VIEW_DATA_CHANGED = 4;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
Romain Guya5475592009-07-01 17:20:08 -070057 final static Object sServiceLock = new Object();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070058 static IAppWidgetService sService;
Adam Cohend2e20de2011-02-25 12:03:37 -080059 private DisplayMetrics mDisplayMetrics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060
Winson Chung7a96f3c2014-12-17 10:31:22 -080061 private String mContextOpPackageName;
Svetoslav7643f7e2014-12-17 17:55:34 -080062 private final Handler mHandler;
63 private final int mHostId;
64 private final Callbacks mCallbacks;
65 private final HashMap<Integer,AppWidgetHostView> mViews = new HashMap<>();
Jim Millera75a8832013-02-07 16:53:32 -080066 private OnClickHandler mOnClickHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067
Svetoslav7643f7e2014-12-17 17:55:34 -080068 static class Callbacks extends IAppWidgetHost.Stub {
69 private final WeakReference<Handler> mWeakHandler;
70
71 public Callbacks(Handler handler) {
72 mWeakHandler = new WeakReference<>(handler);
73 }
74
Svetoslav976e8bd2014-07-16 15:12:03 -070075 public void updateAppWidget(int appWidgetId, RemoteViews views) {
Adam Cohen3ff2d862012-09-26 14:07:57 -070076 if (isLocalBinder() && views != null) {
77 views = views.clone();
78 }
Svetoslav7643f7e2014-12-17 17:55:34 -080079 Handler handler = mWeakHandler.get();
80 if (handler == null) {
81 return;
82 }
83 Message msg = handler.obtainMessage(HANDLE_UPDATE, appWidgetId, 0, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 msg.sendToTarget();
85 }
86
Svetoslav976e8bd2014-07-16 15:12:03 -070087 public void providerChanged(int appWidgetId, AppWidgetProviderInfo info) {
Adam Cohen3ff2d862012-09-26 14:07:57 -070088 if (isLocalBinder() && info != null) {
89 info = info.clone();
90 }
Svetoslav7643f7e2014-12-17 17:55:34 -080091 Handler handler = mWeakHandler.get();
92 if (handler == null) {
93 return;
94 }
95 Message msg = handler.obtainMessage(HANDLE_PROVIDER_CHANGED,
Svetoslav976e8bd2014-07-16 15:12:03 -070096 appWidgetId, 0, info);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 msg.sendToTarget();
98 }
Winson Chung499cb9f2010-07-16 11:18:17 -070099
Svetoslav976e8bd2014-07-16 15:12:03 -0700100 public void providersChanged() {
Svetoslav7643f7e2014-12-17 17:55:34 -0800101 Handler handler = mWeakHandler.get();
102 if (handler == null) {
103 return;
104 }
105 handler.obtainMessage(HANDLE_PROVIDERS_CHANGED).sendToTarget();
Winson Chung7fbd2842012-06-13 10:35:51 -0700106 }
107
Svetoslav976e8bd2014-07-16 15:12:03 -0700108 public void viewDataChanged(int appWidgetId, int viewId) {
Svetoslav7643f7e2014-12-17 17:55:34 -0800109 Handler handler = mWeakHandler.get();
110 if (handler == null) {
111 return;
112 }
113 Message msg = handler.obtainMessage(HANDLE_VIEW_DATA_CHANGED,
Svetoslav976e8bd2014-07-16 15:12:03 -0700114 appWidgetId, viewId);
Winson Chung499cb9f2010-07-16 11:18:17 -0700115 msg.sendToTarget();
116 }
Svetoslav7643f7e2014-12-17 17:55:34 -0800117
118 private static boolean isLocalBinder() {
119 return Process.myPid() == Binder.getCallingPid();
120 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 }
122
123 class UpdateHandler extends Handler {
124 public UpdateHandler(Looper looper) {
125 super(looper);
126 }
Jim Millere667a7a2012-08-09 19:22:32 -0700127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 public void handleMessage(Message msg) {
129 switch (msg.what) {
130 case HANDLE_UPDATE: {
Svetoslav976e8bd2014-07-16 15:12:03 -0700131 updateAppWidgetView(msg.arg1, (RemoteViews)msg.obj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 break;
133 }
134 case HANDLE_PROVIDER_CHANGED: {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700135 onProviderChanged(msg.arg1, (AppWidgetProviderInfo)msg.obj);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 break;
137 }
Winson Chung7fbd2842012-06-13 10:35:51 -0700138 case HANDLE_PROVIDERS_CHANGED: {
Winson Chungeeb4ff42013-06-04 14:25:28 -0700139 onProvidersChanged();
Winson Chung7fbd2842012-06-13 10:35:51 -0700140 break;
141 }
Winson Chung499cb9f2010-07-16 11:18:17 -0700142 case HANDLE_VIEW_DATA_CHANGED: {
Svetoslav976e8bd2014-07-16 15:12:03 -0700143 viewDataChanged(msg.arg1, msg.arg2);
Winson Chung499cb9f2010-07-16 11:18:17 -0700144 break;
145 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 }
147 }
148 }
Jim Millere667a7a2012-08-09 19:22:32 -0700149
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700150 public AppWidgetHost(Context context, int hostId) {
Michael Jurkae6d55452012-09-17 17:30:16 -0700151 this(context, hostId, null, context.getMainLooper());
Jim Millere667a7a2012-08-09 19:22:32 -0700152 }
153
154 /**
155 * @hide
156 */
Jim Millerf229e4d2012-09-12 20:32:50 -0700157 public AppWidgetHost(Context context, int hostId, OnClickHandler handler, Looper looper) {
Winson Chung7a96f3c2014-12-17 10:31:22 -0800158 mContextOpPackageName = context.getOpPackageName();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 mHostId = hostId;
Jim Millere667a7a2012-08-09 19:22:32 -0700160 mOnClickHandler = handler;
Jim Millerf229e4d2012-09-12 20:32:50 -0700161 mHandler = new UpdateHandler(looper);
Svetoslav7643f7e2014-12-17 17:55:34 -0800162 mCallbacks = new Callbacks(mHandler);
Adam Cohend2e20de2011-02-25 12:03:37 -0800163 mDisplayMetrics = context.getResources().getDisplayMetrics();
Jim Millerf229e4d2012-09-12 20:32:50 -0700164 bindService();
165 }
166
Amith Yamasani94022e82012-12-04 11:05:39 -0800167
Jim Millerf229e4d2012-09-12 20:32:50 -0700168 private static void bindService() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 synchronized (sServiceLock) {
170 if (sService == null) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700171 IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE);
172 sService = IAppWidgetService.Stub.asInterface(b);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 }
174 }
175 }
176
177 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700178 * Start receiving onAppWidgetChanged calls for your AppWidgets. Call this when your activity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 * becomes visible, i.e. from onStart() in your Activity.
180 */
181 public void startListening() {
Romain Guya5475592009-07-01 17:20:08 -0700182 int[] updatedIds;
183 ArrayList<RemoteViews> updatedViews = new ArrayList<RemoteViews>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 try {
Winson Chung7a96f3c2014-12-17 10:31:22 -0800185 updatedIds = sService.startListening(mCallbacks, mContextOpPackageName, mHostId,
Svetoslav976e8bd2014-07-16 15:12:03 -0700186 updatedViews);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 }
188 catch (RemoteException e) {
189 throw new RuntimeException("system server dead?", e);
190 }
191
192 final int N = updatedIds.length;
Svetoslav976e8bd2014-07-16 15:12:03 -0700193 for (int i = 0; i < N; i++) {
194 updateAppWidgetView(updatedIds[i], updatedViews.get(i));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 }
196 }
197
198 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700199 * Stop receiving onAppWidgetChanged calls for your AppWidgets. Call this when your activity is
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 * no longer visible, i.e. from onStop() in your Activity.
201 */
202 public void stopListening() {
203 try {
Winson Chung7a96f3c2014-12-17 10:31:22 -0800204 sService.stopListening(mContextOpPackageName, mHostId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 }
206 catch (RemoteException e) {
207 throw new RuntimeException("system server dead?", e);
208 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209
Jim Millera75a8832013-02-07 16:53:32 -0800210 // This is here because keyguard needs it since it'll be switching users after this call.
211 // If it turns out other apps need to call this often, we should re-think how this works.
Amith Yamasanic566b432012-11-30 15:26:21 -0800212 clearViews();
213 }
214
215 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700216 * Get a appWidgetId for a host in the calling process.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 *
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700218 * @return a appWidgetId
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700220 public int allocateAppWidgetId() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 try {
Winson Chung7a96f3c2014-12-17 10:31:22 -0800222 return sService.allocateAppWidgetId(mContextOpPackageName, mHostId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 }
224 catch (RemoteException e) {
225 throw new RuntimeException("system server dead?", e);
226 }
227 }
228
229 /**
Svetoslav976e8bd2014-07-16 15:12:03 -0700230 * Starts an app widget provider configure activity for result on behalf of the caller.
231 * Use this method if the provider is in another profile as you are not allowed to start
Svetoslav8e1d2992014-08-08 12:48:06 -0700232 * an activity in another profile. You can optionally provide a request code that is
233 * returned in {@link Activity#onActivityResult(int, int, android.content.Intent)} and
234 * an options bundle to be passed to the started activity.
235 * <p>
236 * Note that the provided app widget has to be bound for this method to work.
237 * </p>
Jim Millerf229e4d2012-09-12 20:32:50 -0700238 *
Svetoslav976e8bd2014-07-16 15:12:03 -0700239 * @param activity The activity from which to start the configure one.
Svetoslav8e1d2992014-08-08 12:48:06 -0700240 * @param appWidgetId The bound app widget whose provider's config activity to start.
Svetoslav976e8bd2014-07-16 15:12:03 -0700241 * @param requestCode Optional request code retuned with the result.
Svetoslav8e1d2992014-08-08 12:48:06 -0700242 * @param intentFlags Optional intent flags.
Svetoslav976e8bd2014-07-16 15:12:03 -0700243 *
244 * @throws android.content.ActivityNotFoundException If the activity is not found.
245 *
246 * @see AppWidgetProviderInfo#getProfile()
Jim Millerf229e4d2012-09-12 20:32:50 -0700247 */
Svetoslav8e1d2992014-08-08 12:48:06 -0700248 public final void startAppWidgetConfigureActivityForResult(@NonNull Activity activity,
249 int appWidgetId, int intentFlags, int requestCode, @Nullable Bundle options) {
Jim Millerf229e4d2012-09-12 20:32:50 -0700250 try {
Svetoslav976e8bd2014-07-16 15:12:03 -0700251 IntentSender intentSender = sService.createAppWidgetConfigIntentSender(
Winson Chung7a96f3c2014-12-17 10:31:22 -0800252 mContextOpPackageName, appWidgetId, intentFlags);
Svetoslav976e8bd2014-07-16 15:12:03 -0700253 if (intentSender != null) {
Svetoslav8e1d2992014-08-08 12:48:06 -0700254 activity.startIntentSenderForResult(intentSender, requestCode, null, 0, 0, 0,
255 options);
Svetoslav976e8bd2014-07-16 15:12:03 -0700256 } else {
257 throw new ActivityNotFoundException();
Jim Millerf229e4d2012-09-12 20:32:50 -0700258 }
Svetoslav976e8bd2014-07-16 15:12:03 -0700259 } catch (IntentSender.SendIntentException e) {
260 throw new ActivityNotFoundException();
Jim Millerf229e4d2012-09-12 20:32:50 -0700261 } catch (RemoteException e) {
262 throw new RuntimeException("system server dead?", e);
263 }
264 }
265
Michael Jurka75b5cfb2012-11-15 18:22:47 -0800266 /**
267 * Gets a list of all the appWidgetIds that are bound to the current host
268 *
269 * @hide
270 */
271 public int[] getAppWidgetIds() {
272 try {
273 if (sService == null) {
274 bindService();
275 }
Winson Chung7a96f3c2014-12-17 10:31:22 -0800276 return sService.getAppWidgetIdsForHost(mContextOpPackageName, mHostId);
Michael Jurka75b5cfb2012-11-15 18:22:47 -0800277 } catch (RemoteException e) {
278 throw new RuntimeException("system server dead?", e);
279 }
280 }
281
Jim Millerf229e4d2012-09-12 20:32:50 -0700282 /**
Jim Millere667a7a2012-08-09 19:22:32 -0700283 * Stop listening to changes for this AppWidget.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700285 public void deleteAppWidgetId(int appWidgetId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 synchronized (mViews) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700287 mViews.remove(appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 try {
Winson Chung7a96f3c2014-12-17 10:31:22 -0800289 sService.deleteAppWidgetId(mContextOpPackageName, appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 }
291 catch (RemoteException e) {
292 throw new RuntimeException("system server dead?", e);
293 }
294 }
295 }
296
297 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700298 * Remove all records about this host from the AppWidget manager.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 * <ul>
300 * <li>Call this when initializing your database, as it might be because of a data wipe.</li>
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700301 * <li>Call this to have the AppWidget manager release all resources associated with your
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 * host. Any future calls about this host will cause the records to be re-allocated.</li>
303 * </ul>
304 */
305 public void deleteHost() {
306 try {
Winson Chung7a96f3c2014-12-17 10:31:22 -0800307 sService.deleteHost(mContextOpPackageName, mHostId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 }
309 catch (RemoteException e) {
310 throw new RuntimeException("system server dead?", e);
311 }
312 }
313
314 /**
315 * Remove all records about all hosts for your package.
316 * <ul>
317 * <li>Call this when initializing your database, as it might be because of a data wipe.</li>
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700318 * <li>Call this to have the AppWidget manager release all resources associated with your
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 * host. Any future calls about this host will cause the records to be re-allocated.</li>
320 * </ul>
321 */
322 public static void deleteAllHosts() {
323 try {
Svetoslav976e8bd2014-07-16 15:12:03 -0700324 sService.deleteAllHosts();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 }
326 catch (RemoteException e) {
327 throw new RuntimeException("system server dead?", e);
328 }
329 }
330
Patrick Dubroyec84c3a2011-01-13 17:55:37 -0800331 /**
332 * Create the AppWidgetHostView for the given widget.
333 * The AppWidgetHost retains a pointer to the newly-created View.
334 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700335 public final AppWidgetHostView createView(Context context, int appWidgetId,
336 AppWidgetProviderInfo appWidget) {
Winson Chung7a96f3c2014-12-17 10:31:22 -0800337 AppWidgetHostView view = onCreateView(context, appWidgetId, appWidget);
Jim Millere667a7a2012-08-09 19:22:32 -0700338 view.setOnClickHandler(mOnClickHandler);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700339 view.setAppWidget(appWidgetId, appWidget);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 synchronized (mViews) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700341 mViews.put(appWidgetId, view);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 }
Romain Guya5475592009-07-01 17:20:08 -0700343 RemoteViews views;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 try {
Winson Chung7a96f3c2014-12-17 10:31:22 -0800345 views = sService.getAppWidgetViews(mContextOpPackageName, appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 } catch (RemoteException e) {
347 throw new RuntimeException("system server dead?", e);
348 }
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700349 view.updateAppWidget(views);
Jim Millere667a7a2012-08-09 19:22:32 -0700350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 return view;
352 }
353
354 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700355 * Called to create the AppWidgetHostView. Override to return a custom subclass if you
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 * need it. {@more}
357 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700358 protected AppWidgetHostView onCreateView(Context context, int appWidgetId,
359 AppWidgetProviderInfo appWidget) {
Jim Millere667a7a2012-08-09 19:22:32 -0700360 return new AppWidgetHostView(context, mOnClickHandler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 }
Adam Cohend2e20de2011-02-25 12:03:37 -0800362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700364 * Called when the AppWidget provider for a AppWidget has been upgraded to a new apk.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700366 protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidget) {
Joe Onoratof140be62010-05-04 11:49:12 -0700367 AppWidgetHostView v;
Adam Cohend2e20de2011-02-25 12:03:37 -0800368
369 // Convert complex to dp -- we are getting the AppWidgetProviderInfo from the
Jim Millere667a7a2012-08-09 19:22:32 -0700370 // AppWidgetService, which doesn't have our context, hence we need to do the
Adam Cohend2e20de2011-02-25 12:03:37 -0800371 // conversion here.
372 appWidget.minWidth =
373 TypedValue.complexToDimensionPixelSize(appWidget.minWidth, mDisplayMetrics);
374 appWidget.minHeight =
375 TypedValue.complexToDimensionPixelSize(appWidget.minHeight, mDisplayMetrics);
Adam Cohen1bfaf562011-07-19 18:05:33 -0700376 appWidget.minResizeWidth =
377 TypedValue.complexToDimensionPixelSize(appWidget.minResizeWidth, mDisplayMetrics);
378 appWidget.minResizeHeight =
379 TypedValue.complexToDimensionPixelSize(appWidget.minResizeHeight, mDisplayMetrics);
Adam Cohend2e20de2011-02-25 12:03:37 -0800380
Joe Onoratof140be62010-05-04 11:49:12 -0700381 synchronized (mViews) {
382 v = mViews.get(appWidgetId);
383 }
384 if (v != null) {
Joe Onoratoc27bb552010-06-23 17:44:30 -0700385 v.resetAppWidget(appWidget);
Joe Onoratof140be62010-05-04 11:49:12 -0700386 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 }
388
Winson Chung7fbd2842012-06-13 10:35:51 -0700389 /**
390 * Called when the set of available widgets changes (ie. widget containing packages
391 * are added, updated or removed, or widget components are enabled or disabled.)
392 */
393 protected void onProvidersChanged() {
Jim Millera75a8832013-02-07 16:53:32 -0800394 // Does nothing
395 }
396
Svetoslav976e8bd2014-07-16 15:12:03 -0700397 void updateAppWidgetView(int appWidgetId, RemoteViews views) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700398 AppWidgetHostView v;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 synchronized (mViews) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700400 v = mViews.get(appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 }
402 if (v != null) {
Joe Onoratoc27bb552010-06-23 17:44:30 -0700403 v.updateAppWidget(views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 }
405 }
Winson Chung499cb9f2010-07-16 11:18:17 -0700406
Svetoslav976e8bd2014-07-16 15:12:03 -0700407 void viewDataChanged(int appWidgetId, int viewId) {
Winson Chung499cb9f2010-07-16 11:18:17 -0700408 AppWidgetHostView v;
409 synchronized (mViews) {
410 v = mViews.get(appWidgetId);
411 }
412 if (v != null) {
Winson Chung6394c0e2010-08-16 10:14:56 -0700413 v.viewDataChanged(viewId);
Winson Chung499cb9f2010-07-16 11:18:17 -0700414 }
415 }
Patrick Dubroyec84c3a2011-01-13 17:55:37 -0800416
417 /**
418 * Clear the list of Views that have been created by this AppWidgetHost.
419 */
420 protected void clearViews() {
421 mViews.clear();
422 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423}
424
425