blob: 2faa9007fc29c66fad619df97c5269c29278a599 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 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
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070017package android.appwidget;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Sunny Goyal363fa2d2018-03-15 12:00:26 -070019import android.annotation.IntDef;
Svetoslav8e1d2992014-08-08 12:48:06 -070020import android.annotation.NonNull;
Mathew Inwoodb5962ae2018-08-09 15:15:57 +010021import android.annotation.UnsupportedAppUsage;
Sunny Goyalf5e0fd72017-10-20 15:07:07 -070022import android.app.PendingIntent;
23import android.content.ComponentName;
Svetoslav976e8bd2014-07-16 15:12:03 -070024import android.content.Context;
25import android.content.pm.ActivityInfo;
26import android.content.pm.PackageManager;
Adam Lesinski9553fb32017-05-23 18:53:44 -070027import android.content.res.ResourceId;
Svetoslav976e8bd2014-07-16 15:12:03 -070028import android.content.res.Resources;
Svetoslav976e8bd2014-07-16 15:12:03 -070029import android.graphics.drawable.Drawable;
Sunny Goyalf5e0fd72017-10-20 15:07:07 -070030import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.Parcel;
32import android.os.Parcelable;
Svetoslav976e8bd2014-07-16 15:12:03 -070033import android.os.UserHandle;
Sunny Goyal970d4b42017-01-19 15:07:36 -080034import android.util.DisplayMetrics;
35import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
Sunny Goyal363fa2d2018-03-15 12:00:26 -070037import java.lang.annotation.Retention;
38import java.lang.annotation.RetentionPolicy;
39
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040/**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070041 * Describes the meta data for an installed AppWidget provider. The fields in this class
42 * correspond to the fields in the <code>&lt;appwidget-provider&gt;</code> xml tag.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070044public class AppWidgetProviderInfo implements Parcelable {
Adam Cohend2e20de2011-02-25 12:03:37 -080045
46 /**
47 * Widget is not resizable.
48 */
49 public static final int RESIZE_NONE = 0;
50 /**
51 * Widget is resizable in the horizontal axis only.
52 */
53 public static final int RESIZE_HORIZONTAL = 1;
54 /**
55 * Widget is resizable in the vertical axis only.
56 */
57 public static final int RESIZE_VERTICAL = 2;
58 /**
59 * Widget is resizable in both the horizontal and vertical axes.
60 */
61 public static final int RESIZE_BOTH = RESIZE_HORIZONTAL | RESIZE_VERTICAL;
62
Sunny Goyal363fa2d2018-03-15 12:00:26 -070063 /** @hide */
64 @IntDef(flag = true, prefix = { "FLAG_" }, value = {
65 RESIZE_HORIZONTAL,
66 RESIZE_VERTICAL,
67 })
68 @Retention(RetentionPolicy.SOURCE)
69 public @interface ResizeModeFlags {}
70
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 /**
Adam Cohen0aa2d422012-09-07 17:37:26 -070072 * Indicates that the widget can be displayed on the home screen. This is the default value.
73 */
74 public static final int WIDGET_CATEGORY_HOME_SCREEN = 1;
75
76 /**
77 * Indicates that the widget can be displayed on the keyguard.
78 */
79 public static final int WIDGET_CATEGORY_KEYGUARD = 2;
80
81 /**
Winson Chungee0b1212014-09-04 16:42:53 +020082 * Indicates that the widget can be displayed within a space reserved for the search box.
Winson Chungf7bca432014-04-30 17:11:13 -070083 */
Winson Chungee0b1212014-09-04 16:42:53 +020084 public static final int WIDGET_CATEGORY_SEARCHBOX = 4;
Winson Chungf7bca432014-04-30 17:11:13 -070085
Sunny Goyal363fa2d2018-03-15 12:00:26 -070086 /** @hide */
87 @IntDef(flag = true, prefix = { "FLAG_" }, value = {
88 WIDGET_CATEGORY_HOME_SCREEN,
89 WIDGET_CATEGORY_KEYGUARD,
90 WIDGET_CATEGORY_SEARCHBOX,
91 })
92 @Retention(RetentionPolicy.SOURCE)
93 public @interface CategoryFlags {}
94
Winson Chungf7bca432014-04-30 17:11:13 -070095 /**
Sunny Goyalf5e0fd72017-10-20 15:07:07 -070096 * The widget can be reconfigured anytime after it is bound by starting the
97 * {@link #configure} activity.
98 *
99 * @see #widgetFeatures
100 */
101 public static final int WIDGET_FEATURE_RECONFIGURABLE = 1;
102
103 /**
104 * The widget is added directly by the app, and the host may hide this widget when providing
105 * the user with the list of available widgets to choose from.
106 *
107 * @see AppWidgetManager#requestPinAppWidget(ComponentName, Bundle, PendingIntent)
108 * @see #widgetFeatures
109 */
110 public static final int WIDGET_FEATURE_HIDE_FROM_PICKER = 2;
111
Sunny Goyal363fa2d2018-03-15 12:00:26 -0700112 /** @hide */
113 @IntDef(flag = true, prefix = { "FLAG_" }, value = {
114 WIDGET_FEATURE_RECONFIGURABLE,
115 WIDGET_FEATURE_HIDE_FROM_PICKER,
116 })
117 @Retention(RetentionPolicy.SOURCE)
118 public @interface FeatureFlags {}
119
Sunny Goyalf5e0fd72017-10-20 15:07:07 -0700120 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700121 * Identity of this AppWidget component. This component should be a {@link
122 * android.content.BroadcastReceiver}, and it will be sent the AppWidget intents
123 * {@link android.appwidget as described in the AppWidget package documentation}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 *
125 * <p>This field corresponds to the <code>android:name</code> attribute in
126 * the <code>&lt;receiver&gt;</code> element in the AndroidManifest.xml file.
127 */
128 public ComponentName provider;
129
130 /**
Adam Cohen1bfaf562011-07-19 18:05:33 -0700131 * The default height of the widget when added to a host, in dp. The widget will get
132 * at least this width, and will often be given more, depending on the host.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 *
134 * <p>This field corresponds to the <code>android:minWidth</code> attribute in
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700135 * the AppWidget meta-data file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 */
137 public int minWidth;
138
139 /**
Adam Cohen1bfaf562011-07-19 18:05:33 -0700140 * The default height of the widget when added to a host, in dp. The widget will get
141 * at least this height, and will often be given more, depending on the host.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 *
143 * <p>This field corresponds to the <code>android:minHeight</code> attribute in
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700144 * the AppWidget meta-data file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 */
146 public int minHeight;
147
148 /**
Adam Cohen1bfaf562011-07-19 18:05:33 -0700149 * Minimum width (in dp) which the widget can be resized to. This field has no effect if it
150 * is greater than minWidth or if horizontal resizing isn't enabled (see {@link #resizeMode}).
151 *
152 * <p>This field corresponds to the <code>android:minResizeWidth</code> attribute in
153 * the AppWidget meta-data file.
154 */
155 public int minResizeWidth;
156
157 /**
158 * Minimum height (in dp) which the widget can be resized to. This field has no effect if it
159 * is greater than minHeight or if vertical resizing isn't enabled (see {@link #resizeMode}).
160 *
161 * <p>This field corresponds to the <code>android:minResizeHeight</code> attribute in
162 * the AppWidget meta-data file.
163 */
164 public int minResizeHeight;
165
166 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700167 * How often, in milliseconds, that this AppWidget wants to be updated.
168 * The AppWidget manager may place a limit on how often a AppWidget is updated.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 *
170 * <p>This field corresponds to the <code>android:updatePeriodMillis</code> attribute in
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700171 * the AppWidget meta-data file.
Joe Onorato851da842009-07-14 19:49:27 -0700172 *
173 * <p class="note"><b>Note:</b> Updates requested with <code>updatePeriodMillis</code>
174 * will not be delivered more than once every 30 minutes.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 */
176 public int updatePeriodMillis;
177
178 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700179 * The resource id of the initial layout for this AppWidget. This should be
180 * displayed until the RemoteViews for the AppWidget is available.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 *
182 * <p>This field corresponds to the <code>android:initialLayout</code> attribute in
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700183 * the AppWidget meta-data file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 */
185 public int initialLayout;
186
187 /**
Adam Cohen0aa2d422012-09-07 17:37:26 -0700188 * The resource id of the initial layout for this AppWidget when it is displayed on keyguard.
189 * This parameter only needs to be provided if the widget can be displayed on the keyguard,
190 * see {@link #widgetCategory}.
191 *
192 * <p>This field corresponds to the <code>android:initialKeyguardLayout</code> attribute in
193 * the AppWidget meta-data file.
194 */
195 public int initialKeyguardLayout;
196
197 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700198 * The activity to launch that will configure the AppWidget.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 *
200 * <p>This class name of field corresponds to the <code>android:configure</code> attribute in
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700201 * the AppWidget meta-data file. The package name always corresponds to the package containing
202 * the AppWidget provider.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 */
204 public ComponentName configure;
205
206 /**
Svetoslav976e8bd2014-07-16 15:12:03 -0700207 * The label to display to the user in the AppWidget picker.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 *
Svetoslav976e8bd2014-07-16 15:12:03 -0700209 * @deprecated Use {@link #loadLabel(android.content.pm.PackageManager)}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 */
Svetoslav976e8bd2014-07-16 15:12:03 -0700211 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 public String label;
213
214 /**
Svetoslav976e8bd2014-07-16 15:12:03 -0700215 * The icon to display for this AppWidget in the AppWidget picker. If not supplied in the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 * xml, the application icon will be used.
217 *
218 * <p>This field corresponds to the <code>android:icon</code> attribute in
219 * the <code>&lt;receiver&gt;</code> element in the AndroidManifest.xml file.
220 */
221 public int icon;
Adam Cohena02fdf12010-11-03 13:27:40 -0700222
Romain Guyd2671e12010-03-11 18:06:42 -0800223 /**
Adam Cohena02fdf12010-11-03 13:27:40 -0700224 * The view id of the AppWidget subview which should be auto-advanced by the widget's host.
Adam Cohen9611f2e2011-02-28 13:39:38 -0800225 *
226 * <p>This field corresponds to the <code>android:autoAdvanceViewId</code> attribute in
227 * the AppWidget meta-data file.
Adam Cohena02fdf12010-11-03 13:27:40 -0700228 */
229 public int autoAdvanceViewId;
230
Patrick Dubroyd2db2a52010-06-23 14:56:28 -0700231 /**
232 * A preview of what the AppWidget will look like after it's configured.
233 * If not supplied, the AppWidget's icon will be used.
234 *
235 * <p>This field corresponds to the <code>android:previewImage</code> attribute in
236 * the <code>&lt;receiver&gt;</code> element in the AndroidManifest.xml file.
Patrick Dubroyd2db2a52010-06-23 14:56:28 -0700237 */
John Spurlock8a985d22014-02-25 09:40:05 -0500238 public int previewImage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239
Adam Cohend2e20de2011-02-25 12:03:37 -0800240 /**
241 * The rules by which a widget can be resized. See {@link #RESIZE_NONE},
242 * {@link #RESIZE_NONE}, {@link #RESIZE_HORIZONTAL},
243 * {@link #RESIZE_VERTICAL}, {@link #RESIZE_BOTH}.
Adam Cohen9611f2e2011-02-28 13:39:38 -0800244 *
245 * <p>This field corresponds to the <code>android:resizeMode</code> attribute in
246 * the AppWidget meta-data file.
Adam Cohend2e20de2011-02-25 12:03:37 -0800247 */
Sunny Goyal363fa2d2018-03-15 12:00:26 -0700248 @ResizeModeFlags
Adam Cohen9611f2e2011-02-28 13:39:38 -0800249 public int resizeMode;
Adam Cohend2e20de2011-02-25 12:03:37 -0800250
Adam Cohen0aa2d422012-09-07 17:37:26 -0700251 /**
252 * Determines whether this widget can be displayed on the home screen, the keyguard, or both.
253 * A widget which is displayed on both needs to ensure that it follows the design guidelines
254 * for both widget classes. This can be achieved by querying the AppWidget options in its
255 * widget provider's update method.
256 *
257 * <p>This field corresponds to the <code>widgetCategory</code> attribute in
258 * the AppWidget meta-data file.
259 */
Sunny Goyal363fa2d2018-03-15 12:00:26 -0700260 @CategoryFlags
Adam Cohen0aa2d422012-09-07 17:37:26 -0700261 public int widgetCategory;
262
Sunny Goyalf5e0fd72017-10-20 15:07:07 -0700263 /**
264 * Flags indicating various features supported by the widget. These are hints to the widget
265 * host, and do not actually change the behavior of the widget.
266 *
267 * @see #WIDGET_FEATURE_RECONFIGURABLE
268 * @see #WIDGET_FEATURE_HIDE_FROM_PICKER
269 */
Sunny Goyal363fa2d2018-03-15 12:00:26 -0700270 @FeatureFlags
Sunny Goyalf5e0fd72017-10-20 15:07:07 -0700271 public int widgetFeatures;
272
Svetoslav976e8bd2014-07-16 15:12:03 -0700273 /** @hide */
Mathew Inwoodb5962ae2018-08-09 15:15:57 +0100274 @UnsupportedAppUsage
Svetoslav976e8bd2014-07-16 15:12:03 -0700275 public ActivityInfo providerInfo;
276
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700277 public AppWidgetProviderInfo() {
Svetoslav976e8bd2014-07-16 15:12:03 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 }
280
281 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700282 * Unflatten the AppWidgetProviderInfo from a parcel.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 */
Svetoslav976e8bd2014-07-16 15:12:03 -0700284 @SuppressWarnings("deprecation")
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700285 public AppWidgetProviderInfo(Parcel in) {
Sunny Goyalf5e0fd72017-10-20 15:07:07 -0700286 this.provider = in.readTypedObject(ComponentName.CREATOR);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 this.minWidth = in.readInt();
288 this.minHeight = in.readInt();
Adam Cohen324afba2011-07-22 11:51:45 -0700289 this.minResizeWidth = in.readInt();
290 this.minResizeHeight = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 this.updatePeriodMillis = in.readInt();
292 this.initialLayout = in.readInt();
Adam Cohen0aa2d422012-09-07 17:37:26 -0700293 this.initialKeyguardLayout = in.readInt();
Sunny Goyalf5e0fd72017-10-20 15:07:07 -0700294 this.configure = in.readTypedObject(ComponentName.CREATOR);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 this.label = in.readString();
296 this.icon = in.readInt();
Patrick Dubroyd2db2a52010-06-23 14:56:28 -0700297 this.previewImage = in.readInt();
Adam Cohena02fdf12010-11-03 13:27:40 -0700298 this.autoAdvanceViewId = in.readInt();
Adam Cohen9611f2e2011-02-28 13:39:38 -0800299 this.resizeMode = in.readInt();
Adam Cohen0aa2d422012-09-07 17:37:26 -0700300 this.widgetCategory = in.readInt();
Sunny Goyalf5e0fd72017-10-20 15:07:07 -0700301 this.providerInfo = in.readTypedObject(ActivityInfo.CREATOR);
302 this.widgetFeatures = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 }
304
Svetoslav976e8bd2014-07-16 15:12:03 -0700305 /**
306 * Loads the localized label to display to the user in the AppWidget picker.
307 *
308 * @param packageManager Package manager instance for loading resources.
309 * @return The label for the current locale.
310 */
311 public final String loadLabel(PackageManager packageManager) {
312 CharSequence label = providerInfo.loadLabel(packageManager);
313 if (label != null) {
314 return label.toString().trim();
315 }
316 return null;
317 }
318
319 /**
320 * Loads the icon to display for this AppWidget in the AppWidget picker. If not
321 * supplied in the xml, the application icon will be used. A client can optionally
322 * provide a desired density such as {@link android.util.DisplayMetrics#DENSITY_LOW}
323 * {@link android.util.DisplayMetrics#DENSITY_MEDIUM}, etc. If no density is
324 * provided, the density of the current display will be used.
325 * <p>
326 * The loaded icon corresponds to the <code>android:icon</code> attribute in
327 * the <code>&lt;receiver&gt;</code> element in the AndroidManifest.xml file.
328 * </p>
Svetoslav976e8bd2014-07-16 15:12:03 -0700329 *
330 * @param context Context for accessing resources.
331 * @param density The optional desired density as per
332 * {@link android.util.DisplayMetrics#densityDpi}.
Svetoslavc71c42f2014-08-05 18:57:05 -0700333 * @return The provider icon.
Svetoslav976e8bd2014-07-16 15:12:03 -0700334 */
Svetoslav8e1d2992014-08-08 12:48:06 -0700335 public final Drawable loadIcon(@NonNull Context context, int density) {
Sunny Goyal092e1962014-08-15 12:57:11 -0700336 return loadDrawable(context, density, providerInfo.getIconResource(), true);
Svetoslav976e8bd2014-07-16 15:12:03 -0700337 }
338
339 /**
340 * Loads a preview of what the AppWidget will look like after it's configured.
Sunny Goyal092e1962014-08-15 12:57:11 -0700341 * A client can optionally provide a desired density such as
342 * {@link android.util.DisplayMetrics#DENSITY_LOW}
Svetoslav976e8bd2014-07-16 15:12:03 -0700343 * {@link android.util.DisplayMetrics#DENSITY_MEDIUM}, etc. If no density is
344 * provided, the density of the current display will be used.
345 * <p>
346 * The loaded image corresponds to the <code>android:previewImage</code> attribute
347 * in the <code>&lt;receiver&gt;</code> element in the AndroidManifest.xml file.
348 * </p>
Svetoslav976e8bd2014-07-16 15:12:03 -0700349 *
350 * @param context Context for accessing resources.
351 * @param density The optional desired density as per
352 * {@link android.util.DisplayMetrics#densityDpi}.
Sunny Goyal0308d9a2014-08-15 17:39:54 -0700353 * @return The widget preview image or null if preview image is not available.
Svetoslav976e8bd2014-07-16 15:12:03 -0700354 */
Svetoslav8e1d2992014-08-08 12:48:06 -0700355 public final Drawable loadPreviewImage(@NonNull Context context, int density) {
Sunny Goyal092e1962014-08-15 12:57:11 -0700356 return loadDrawable(context, density, previewImage, false);
Svetoslav976e8bd2014-07-16 15:12:03 -0700357 }
358
359 /**
360 * Gets the user profile in which the provider resides.
361 *
362 * @return The hosting user profile.
363 */
364 public final UserHandle getProfile() {
365 return new UserHandle(UserHandle.getUserId(providerInfo.applicationInfo.uid));
366 }
367
368 @Override
369 @SuppressWarnings("deprecation")
Sunny Goyalf5e0fd72017-10-20 15:07:07 -0700370 public void writeToParcel(Parcel out, int flags) {
371 out.writeTypedObject(this.provider, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 out.writeInt(this.minWidth);
373 out.writeInt(this.minHeight);
Adam Cohen324afba2011-07-22 11:51:45 -0700374 out.writeInt(this.minResizeWidth);
375 out.writeInt(this.minResizeHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 out.writeInt(this.updatePeriodMillis);
377 out.writeInt(this.initialLayout);
Adam Cohen0aa2d422012-09-07 17:37:26 -0700378 out.writeInt(this.initialKeyguardLayout);
Sunny Goyalf5e0fd72017-10-20 15:07:07 -0700379 out.writeTypedObject(this.configure, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 out.writeString(this.label);
381 out.writeInt(this.icon);
Patrick Dubroyd2db2a52010-06-23 14:56:28 -0700382 out.writeInt(this.previewImage);
Adam Cohena02fdf12010-11-03 13:27:40 -0700383 out.writeInt(this.autoAdvanceViewId);
Adam Cohen9611f2e2011-02-28 13:39:38 -0800384 out.writeInt(this.resizeMode);
Adam Cohen0aa2d422012-09-07 17:37:26 -0700385 out.writeInt(this.widgetCategory);
Sunny Goyalf5e0fd72017-10-20 15:07:07 -0700386 out.writeTypedObject(this.providerInfo, flags);
387 out.writeInt(this.widgetFeatures);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 }
389
Adam Cohen3ff2d862012-09-26 14:07:57 -0700390 @Override
Svetoslav976e8bd2014-07-16 15:12:03 -0700391 @SuppressWarnings("deprecation")
Adam Cohen3ff2d862012-09-26 14:07:57 -0700392 public AppWidgetProviderInfo clone() {
393 AppWidgetProviderInfo that = new AppWidgetProviderInfo();
394 that.provider = this.provider == null ? null : this.provider.clone();
395 that.minWidth = this.minWidth;
396 that.minHeight = this.minHeight;
397 that.minResizeWidth = this.minResizeHeight;
398 that.minResizeHeight = this.minResizeHeight;
399 that.updatePeriodMillis = this.updatePeriodMillis;
Adam Cohen180cfd52012-11-04 12:03:12 -0800400 that.initialLayout = this.initialLayout;
Adam Cohen3ff2d862012-09-26 14:07:57 -0700401 that.initialKeyguardLayout = this.initialKeyguardLayout;
402 that.configure = this.configure == null ? null : this.configure.clone();
Andreas Gampe214c76c2018-09-05 16:58:45 -0700403 that.label = this.label;
Adam Cohen3ff2d862012-09-26 14:07:57 -0700404 that.icon = this.icon;
405 that.previewImage = this.previewImage;
406 that.autoAdvanceViewId = this.autoAdvanceViewId;
407 that.resizeMode = this.resizeMode;
Svetoslav976e8bd2014-07-16 15:12:03 -0700408 that.widgetCategory = this.widgetCategory;
409 that.providerInfo = this.providerInfo;
Sunny Goyalf5e0fd72017-10-20 15:07:07 -0700410 that.widgetFeatures = this.widgetFeatures;
Adam Cohen3ff2d862012-09-26 14:07:57 -0700411 return that;
412 }
413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 public int describeContents() {
415 return 0;
416 }
417
Sunny Goyal092e1962014-08-15 12:57:11 -0700418 private Drawable loadDrawable(Context context, int density, int resourceId,
419 boolean loadDefaultIcon) {
Svetoslav976e8bd2014-07-16 15:12:03 -0700420 try {
421 Resources resources = context.getPackageManager().getResourcesForApplication(
422 providerInfo.applicationInfo);
Adam Lesinski9553fb32017-05-23 18:53:44 -0700423 if (ResourceId.isValid(resourceId)) {
Adam Lesinski36018212017-04-27 18:09:19 -0700424 if (density < 0) {
425 density = 0;
Svetoslav976e8bd2014-07-16 15:12:03 -0700426 }
Adam Lesinski36018212017-04-27 18:09:19 -0700427 return resources.getDrawableForDensity(resourceId, density, null);
Svetoslav976e8bd2014-07-16 15:12:03 -0700428 }
429 } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
430 /* ignore */
431 }
Sunny Goyal092e1962014-08-15 12:57:11 -0700432 return loadDefaultIcon ? providerInfo.loadIcon(context.getPackageManager()) : null;
Svetoslav976e8bd2014-07-16 15:12:03 -0700433 }
434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 /**
Sunny Goyal970d4b42017-01-19 15:07:36 -0800436 * @hide
437 */
438 public void updateDimensions(DisplayMetrics displayMetrics) {
439 // Converting complex to dp.
440 minWidth = TypedValue.complexToDimensionPixelSize(minWidth, displayMetrics);
441 minHeight = TypedValue.complexToDimensionPixelSize(minHeight, displayMetrics);
442 minResizeWidth = TypedValue.complexToDimensionPixelSize(minResizeWidth, displayMetrics);
443 minResizeHeight = TypedValue.complexToDimensionPixelSize(minResizeHeight, displayMetrics);
444 }
445
446 /**
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700447 * Parcelable.Creator that instantiates AppWidgetProviderInfo objects
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700449 public static final @android.annotation.NonNull Parcelable.Creator<AppWidgetProviderInfo> CREATOR
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700450 = new Parcelable.Creator<AppWidgetProviderInfo>()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700452 public AppWidgetProviderInfo createFromParcel(Parcel parcel)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700454 return new AppWidgetProviderInfo(parcel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 }
456
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700457 public AppWidgetProviderInfo[] newArray(int size)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700459 return new AppWidgetProviderInfo[size];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 }
461 };
462
463 public String toString() {
Svetoslav976e8bd2014-07-16 15:12:03 -0700464 return "AppWidgetProviderInfo(" + getProfile() + '/' + provider + ')';
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 }
466}