The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 17 | package android.appwidget; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Sunny Goyal | 363fa2d | 2018-03-15 12:00:26 -0700 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 20 | import android.annotation.NonNull; |
Mathew Inwood | b5962ae | 2018-08-09 15:15:57 +0100 | [diff] [blame] | 21 | import android.annotation.UnsupportedAppUsage; |
Sunny Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 22 | import android.app.PendingIntent; |
| 23 | import android.content.ComponentName; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.content.pm.ActivityInfo; |
| 26 | import android.content.pm.PackageManager; |
Adam Lesinski | 9553fb3 | 2017-05-23 18:53:44 -0700 | [diff] [blame] | 27 | import android.content.res.ResourceId; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 28 | import android.content.res.Resources; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 29 | import android.graphics.drawable.Drawable; |
Sunny Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 30 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.os.Parcel; |
| 32 | import android.os.Parcelable; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 33 | import android.os.UserHandle; |
Sunny Goyal | 970d4b4 | 2017-01-19 15:07:36 -0800 | [diff] [blame] | 34 | import android.util.DisplayMetrics; |
| 35 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
Sunny Goyal | 363fa2d | 2018-03-15 12:00:26 -0700 | [diff] [blame] | 37 | import java.lang.annotation.Retention; |
| 38 | import java.lang.annotation.RetentionPolicy; |
| 39 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 41 | * Describes the meta data for an installed AppWidget provider. The fields in this class |
| 42 | * correspond to the fields in the <code><appwidget-provider></code> xml tag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | */ |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 44 | public class AppWidgetProviderInfo implements Parcelable { |
Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 45 | |
| 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 Goyal | 363fa2d | 2018-03-15 12:00:26 -0700 | [diff] [blame] | 63 | /** @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | /** |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 72 | * 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 Chung | ee0b121 | 2014-09-04 16:42:53 +0200 | [diff] [blame] | 82 | * Indicates that the widget can be displayed within a space reserved for the search box. |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 83 | */ |
Winson Chung | ee0b121 | 2014-09-04 16:42:53 +0200 | [diff] [blame] | 84 | public static final int WIDGET_CATEGORY_SEARCHBOX = 4; |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 85 | |
Sunny Goyal | 363fa2d | 2018-03-15 12:00:26 -0700 | [diff] [blame] | 86 | /** @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 Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 95 | /** |
Sunny Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 96 | * 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 Goyal | 363fa2d | 2018-03-15 12:00:26 -0700 | [diff] [blame] | 112 | /** @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 Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 120 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 121 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | * |
| 125 | * <p>This field corresponds to the <code>android:name</code> attribute in |
| 126 | * the <code><receiver></code> element in the AndroidManifest.xml file. |
| 127 | */ |
| 128 | public ComponentName provider; |
| 129 | |
| 130 | /** |
Adam Cohen | 1bfaf56 | 2011-07-19 18:05:33 -0700 | [diff] [blame] | 131 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | * |
| 134 | * <p>This field corresponds to the <code>android:minWidth</code> attribute in |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 135 | * the AppWidget meta-data file. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | */ |
| 137 | public int minWidth; |
| 138 | |
| 139 | /** |
Adam Cohen | 1bfaf56 | 2011-07-19 18:05:33 -0700 | [diff] [blame] | 140 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | * |
| 143 | * <p>This field corresponds to the <code>android:minHeight</code> attribute in |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 144 | * the AppWidget meta-data file. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | */ |
| 146 | public int minHeight; |
| 147 | |
| 148 | /** |
Adam Cohen | 1bfaf56 | 2011-07-19 18:05:33 -0700 | [diff] [blame] | 149 | * 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 Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 167 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | * |
| 170 | * <p>This field corresponds to the <code>android:updatePeriodMillis</code> attribute in |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 171 | * the AppWidget meta-data file. |
Joe Onorato | 851da84 | 2009-07-14 19:49:27 -0700 | [diff] [blame] | 172 | * |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | */ |
| 176 | public int updatePeriodMillis; |
| 177 | |
| 178 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 179 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | * |
| 182 | * <p>This field corresponds to the <code>android:initialLayout</code> attribute in |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 183 | * the AppWidget meta-data file. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | */ |
| 185 | public int initialLayout; |
| 186 | |
| 187 | /** |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 188 | * 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 Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 198 | * The activity to launch that will configure the AppWidget. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | * |
| 200 | * <p>This class name of field corresponds to the <code>android:configure</code> attribute in |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 201 | * the AppWidget meta-data file. The package name always corresponds to the package containing |
| 202 | * the AppWidget provider. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | */ |
| 204 | public ComponentName configure; |
| 205 | |
| 206 | /** |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 207 | * The label to display to the user in the AppWidget picker. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | * |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 209 | * @deprecated Use {@link #loadLabel(android.content.pm.PackageManager)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | */ |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 211 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | public String label; |
| 213 | |
| 214 | /** |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 215 | * The icon to display for this AppWidget in the AppWidget picker. If not supplied in the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | * xml, the application icon will be used. |
| 217 | * |
| 218 | * <p>This field corresponds to the <code>android:icon</code> attribute in |
| 219 | * the <code><receiver></code> element in the AndroidManifest.xml file. |
| 220 | */ |
| 221 | public int icon; |
Adam Cohen | a02fdf1 | 2010-11-03 13:27:40 -0700 | [diff] [blame] | 222 | |
Romain Guy | d2671e1 | 2010-03-11 18:06:42 -0800 | [diff] [blame] | 223 | /** |
Adam Cohen | a02fdf1 | 2010-11-03 13:27:40 -0700 | [diff] [blame] | 224 | * The view id of the AppWidget subview which should be auto-advanced by the widget's host. |
Adam Cohen | 9611f2e | 2011-02-28 13:39:38 -0800 | [diff] [blame] | 225 | * |
| 226 | * <p>This field corresponds to the <code>android:autoAdvanceViewId</code> attribute in |
| 227 | * the AppWidget meta-data file. |
Adam Cohen | a02fdf1 | 2010-11-03 13:27:40 -0700 | [diff] [blame] | 228 | */ |
| 229 | public int autoAdvanceViewId; |
| 230 | |
Patrick Dubroy | d2db2a5 | 2010-06-23 14:56:28 -0700 | [diff] [blame] | 231 | /** |
| 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><receiver></code> element in the AndroidManifest.xml file. |
Patrick Dubroy | d2db2a5 | 2010-06-23 14:56:28 -0700 | [diff] [blame] | 237 | */ |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 238 | public int previewImage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | |
Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 240 | /** |
| 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 Cohen | 9611f2e | 2011-02-28 13:39:38 -0800 | [diff] [blame] | 244 | * |
| 245 | * <p>This field corresponds to the <code>android:resizeMode</code> attribute in |
| 246 | * the AppWidget meta-data file. |
Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 247 | */ |
Sunny Goyal | 363fa2d | 2018-03-15 12:00:26 -0700 | [diff] [blame] | 248 | @ResizeModeFlags |
Adam Cohen | 9611f2e | 2011-02-28 13:39:38 -0800 | [diff] [blame] | 249 | public int resizeMode; |
Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 250 | |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 251 | /** |
| 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 Goyal | 363fa2d | 2018-03-15 12:00:26 -0700 | [diff] [blame] | 260 | @CategoryFlags |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 261 | public int widgetCategory; |
| 262 | |
Sunny Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 263 | /** |
| 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 Goyal | 363fa2d | 2018-03-15 12:00:26 -0700 | [diff] [blame] | 270 | @FeatureFlags |
Sunny Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 271 | public int widgetFeatures; |
| 272 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 273 | /** @hide */ |
Mathew Inwood | b5962ae | 2018-08-09 15:15:57 +0100 | [diff] [blame] | 274 | @UnsupportedAppUsage |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 275 | public ActivityInfo providerInfo; |
| 276 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 277 | public AppWidgetProviderInfo() { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 282 | * Unflatten the AppWidgetProviderInfo from a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | */ |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 284 | @SuppressWarnings("deprecation") |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 285 | public AppWidgetProviderInfo(Parcel in) { |
Sunny Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 286 | this.provider = in.readTypedObject(ComponentName.CREATOR); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | this.minWidth = in.readInt(); |
| 288 | this.minHeight = in.readInt(); |
Adam Cohen | 324afba | 2011-07-22 11:51:45 -0700 | [diff] [blame] | 289 | this.minResizeWidth = in.readInt(); |
| 290 | this.minResizeHeight = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | this.updatePeriodMillis = in.readInt(); |
| 292 | this.initialLayout = in.readInt(); |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 293 | this.initialKeyguardLayout = in.readInt(); |
Sunny Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 294 | this.configure = in.readTypedObject(ComponentName.CREATOR); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | this.label = in.readString(); |
| 296 | this.icon = in.readInt(); |
Patrick Dubroy | d2db2a5 | 2010-06-23 14:56:28 -0700 | [diff] [blame] | 297 | this.previewImage = in.readInt(); |
Adam Cohen | a02fdf1 | 2010-11-03 13:27:40 -0700 | [diff] [blame] | 298 | this.autoAdvanceViewId = in.readInt(); |
Adam Cohen | 9611f2e | 2011-02-28 13:39:38 -0800 | [diff] [blame] | 299 | this.resizeMode = in.readInt(); |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 300 | this.widgetCategory = in.readInt(); |
Sunny Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 301 | this.providerInfo = in.readTypedObject(ActivityInfo.CREATOR); |
| 302 | this.widgetFeatures = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 305 | /** |
| 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><receiver></code> element in the AndroidManifest.xml file. |
| 328 | * </p> |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 329 | * |
| 330 | * @param context Context for accessing resources. |
| 331 | * @param density The optional desired density as per |
| 332 | * {@link android.util.DisplayMetrics#densityDpi}. |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame] | 333 | * @return The provider icon. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 334 | */ |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 335 | public final Drawable loadIcon(@NonNull Context context, int density) { |
Sunny Goyal | 092e196 | 2014-08-15 12:57:11 -0700 | [diff] [blame] | 336 | return loadDrawable(context, density, providerInfo.getIconResource(), true); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Loads a preview of what the AppWidget will look like after it's configured. |
Sunny Goyal | 092e196 | 2014-08-15 12:57:11 -0700 | [diff] [blame] | 341 | * A client can optionally provide a desired density such as |
| 342 | * {@link android.util.DisplayMetrics#DENSITY_LOW} |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 343 | * {@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><receiver></code> element in the AndroidManifest.xml file. |
| 348 | * </p> |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 349 | * |
| 350 | * @param context Context for accessing resources. |
| 351 | * @param density The optional desired density as per |
| 352 | * {@link android.util.DisplayMetrics#densityDpi}. |
Sunny Goyal | 0308d9a | 2014-08-15 17:39:54 -0700 | [diff] [blame] | 353 | * @return The widget preview image or null if preview image is not available. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 354 | */ |
Svetoslav | 8e1d299 | 2014-08-08 12:48:06 -0700 | [diff] [blame] | 355 | public final Drawable loadPreviewImage(@NonNull Context context, int density) { |
Sunny Goyal | 092e196 | 2014-08-15 12:57:11 -0700 | [diff] [blame] | 356 | return loadDrawable(context, density, previewImage, false); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 357 | } |
| 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 Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 370 | public void writeToParcel(Parcel out, int flags) { |
| 371 | out.writeTypedObject(this.provider, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | out.writeInt(this.minWidth); |
| 373 | out.writeInt(this.minHeight); |
Adam Cohen | 324afba | 2011-07-22 11:51:45 -0700 | [diff] [blame] | 374 | out.writeInt(this.minResizeWidth); |
| 375 | out.writeInt(this.minResizeHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | out.writeInt(this.updatePeriodMillis); |
| 377 | out.writeInt(this.initialLayout); |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 378 | out.writeInt(this.initialKeyguardLayout); |
Sunny Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 379 | out.writeTypedObject(this.configure, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | out.writeString(this.label); |
| 381 | out.writeInt(this.icon); |
Patrick Dubroy | d2db2a5 | 2010-06-23 14:56:28 -0700 | [diff] [blame] | 382 | out.writeInt(this.previewImage); |
Adam Cohen | a02fdf1 | 2010-11-03 13:27:40 -0700 | [diff] [blame] | 383 | out.writeInt(this.autoAdvanceViewId); |
Adam Cohen | 9611f2e | 2011-02-28 13:39:38 -0800 | [diff] [blame] | 384 | out.writeInt(this.resizeMode); |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 385 | out.writeInt(this.widgetCategory); |
Sunny Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 386 | out.writeTypedObject(this.providerInfo, flags); |
| 387 | out.writeInt(this.widgetFeatures); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Adam Cohen | 3ff2d86 | 2012-09-26 14:07:57 -0700 | [diff] [blame] | 390 | @Override |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 391 | @SuppressWarnings("deprecation") |
Adam Cohen | 3ff2d86 | 2012-09-26 14:07:57 -0700 | [diff] [blame] | 392 | 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 Cohen | 180cfd5 | 2012-11-04 12:03:12 -0800 | [diff] [blame] | 400 | that.initialLayout = this.initialLayout; |
Adam Cohen | 3ff2d86 | 2012-09-26 14:07:57 -0700 | [diff] [blame] | 401 | that.initialKeyguardLayout = this.initialKeyguardLayout; |
| 402 | that.configure = this.configure == null ? null : this.configure.clone(); |
Andreas Gampe | 214c76c | 2018-09-05 16:58:45 -0700 | [diff] [blame] | 403 | that.label = this.label; |
Adam Cohen | 3ff2d86 | 2012-09-26 14:07:57 -0700 | [diff] [blame] | 404 | that.icon = this.icon; |
| 405 | that.previewImage = this.previewImage; |
| 406 | that.autoAdvanceViewId = this.autoAdvanceViewId; |
| 407 | that.resizeMode = this.resizeMode; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 408 | that.widgetCategory = this.widgetCategory; |
| 409 | that.providerInfo = this.providerInfo; |
Sunny Goyal | f5e0fd7 | 2017-10-20 15:07:07 -0700 | [diff] [blame] | 410 | that.widgetFeatures = this.widgetFeatures; |
Adam Cohen | 3ff2d86 | 2012-09-26 14:07:57 -0700 | [diff] [blame] | 411 | return that; |
| 412 | } |
| 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | public int describeContents() { |
| 415 | return 0; |
| 416 | } |
| 417 | |
Sunny Goyal | 092e196 | 2014-08-15 12:57:11 -0700 | [diff] [blame] | 418 | private Drawable loadDrawable(Context context, int density, int resourceId, |
| 419 | boolean loadDefaultIcon) { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 420 | try { |
| 421 | Resources resources = context.getPackageManager().getResourcesForApplication( |
| 422 | providerInfo.applicationInfo); |
Adam Lesinski | 9553fb3 | 2017-05-23 18:53:44 -0700 | [diff] [blame] | 423 | if (ResourceId.isValid(resourceId)) { |
Adam Lesinski | 3601821 | 2017-04-27 18:09:19 -0700 | [diff] [blame] | 424 | if (density < 0) { |
| 425 | density = 0; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 426 | } |
Adam Lesinski | 3601821 | 2017-04-27 18:09:19 -0700 | [diff] [blame] | 427 | return resources.getDrawableForDensity(resourceId, density, null); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 428 | } |
| 429 | } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { |
| 430 | /* ignore */ |
| 431 | } |
Sunny Goyal | 092e196 | 2014-08-15 12:57:11 -0700 | [diff] [blame] | 432 | return loadDefaultIcon ? providerInfo.loadIcon(context.getPackageManager()) : null; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 433 | } |
| 434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | /** |
Sunny Goyal | 970d4b4 | 2017-01-19 15:07:36 -0800 | [diff] [blame] | 436 | * @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 Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 447 | * Parcelable.Creator that instantiates AppWidgetProviderInfo objects |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 449 | public static final @android.annotation.NonNull Parcelable.Creator<AppWidgetProviderInfo> CREATOR |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 450 | = new Parcelable.Creator<AppWidgetProviderInfo>() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 452 | public AppWidgetProviderInfo createFromParcel(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 454 | return new AppWidgetProviderInfo(parcel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | } |
| 456 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 457 | public AppWidgetProviderInfo[] newArray(int size) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 459 | return new AppWidgetProviderInfo[size]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | } |
| 461 | }; |
| 462 | |
| 463 | public String toString() { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 464 | return "AppWidgetProviderInfo(" + getProfile() + '/' + provider + ')'; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | } |
| 466 | } |