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 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.pm.ActivityInfo; |
| 21 | import android.content.pm.PackageManager; |
| 22 | import android.content.res.Resources; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 23 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.os.Parcel; |
| 25 | import android.os.Parcelable; |
| 26 | import android.content.ComponentName; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 27 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
| 29 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 30 | * Describes the meta data for an installed AppWidget provider. The fields in this class |
| 31 | * 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] | 32 | */ |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 33 | public class AppWidgetProviderInfo implements Parcelable { |
Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Widget is not resizable. |
| 37 | */ |
| 38 | public static final int RESIZE_NONE = 0; |
| 39 | /** |
| 40 | * Widget is resizable in the horizontal axis only. |
| 41 | */ |
| 42 | public static final int RESIZE_HORIZONTAL = 1; |
| 43 | /** |
| 44 | * Widget is resizable in the vertical axis only. |
| 45 | */ |
| 46 | public static final int RESIZE_VERTICAL = 2; |
| 47 | /** |
| 48 | * Widget is resizable in both the horizontal and vertical axes. |
| 49 | */ |
| 50 | public static final int RESIZE_BOTH = RESIZE_HORIZONTAL | RESIZE_VERTICAL; |
| 51 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | /** |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 53 | * Indicates that the widget can be displayed on the home screen. This is the default value. |
| 54 | */ |
| 55 | public static final int WIDGET_CATEGORY_HOME_SCREEN = 1; |
| 56 | |
| 57 | /** |
| 58 | * Indicates that the widget can be displayed on the keyguard. |
| 59 | */ |
| 60 | public static final int WIDGET_CATEGORY_KEYGUARD = 2; |
| 61 | |
| 62 | /** |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 63 | * Indicates that the widget can be displayed within recents. |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 64 | */ |
| 65 | public static final int WIDGET_CATEGORY_RECENTS = 4; |
| 66 | |
| 67 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 68 | * Identity of this AppWidget component. This component should be a {@link |
| 69 | * android.content.BroadcastReceiver}, and it will be sent the AppWidget intents |
| 70 | * {@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] | 71 | * |
| 72 | * <p>This field corresponds to the <code>android:name</code> attribute in |
| 73 | * the <code><receiver></code> element in the AndroidManifest.xml file. |
| 74 | */ |
| 75 | public ComponentName provider; |
| 76 | |
| 77 | /** |
Adam Cohen | 1bfaf56 | 2011-07-19 18:05:33 -0700 | [diff] [blame] | 78 | * The default height of the widget when added to a host, in dp. The widget will get |
| 79 | * 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] | 80 | * |
| 81 | * <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] | 82 | * the AppWidget meta-data file. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | */ |
| 84 | public int minWidth; |
| 85 | |
| 86 | /** |
Adam Cohen | 1bfaf56 | 2011-07-19 18:05:33 -0700 | [diff] [blame] | 87 | * The default height of the widget when added to a host, in dp. The widget will get |
| 88 | * 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] | 89 | * |
| 90 | * <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] | 91 | * the AppWidget meta-data file. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | */ |
| 93 | public int minHeight; |
| 94 | |
| 95 | /** |
Adam Cohen | 1bfaf56 | 2011-07-19 18:05:33 -0700 | [diff] [blame] | 96 | * Minimum width (in dp) which the widget can be resized to. This field has no effect if it |
| 97 | * is greater than minWidth or if horizontal resizing isn't enabled (see {@link #resizeMode}). |
| 98 | * |
| 99 | * <p>This field corresponds to the <code>android:minResizeWidth</code> attribute in |
| 100 | * the AppWidget meta-data file. |
| 101 | */ |
| 102 | public int minResizeWidth; |
| 103 | |
| 104 | /** |
| 105 | * Minimum height (in dp) which the widget can be resized to. This field has no effect if it |
| 106 | * is greater than minHeight or if vertical resizing isn't enabled (see {@link #resizeMode}). |
| 107 | * |
| 108 | * <p>This field corresponds to the <code>android:minResizeHeight</code> attribute in |
| 109 | * the AppWidget meta-data file. |
| 110 | */ |
| 111 | public int minResizeHeight; |
| 112 | |
| 113 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 114 | * How often, in milliseconds, that this AppWidget wants to be updated. |
| 115 | * 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] | 116 | * |
| 117 | * <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] | 118 | * the AppWidget meta-data file. |
Joe Onorato | 851da84 | 2009-07-14 19:49:27 -0700 | [diff] [blame] | 119 | * |
| 120 | * <p class="note"><b>Note:</b> Updates requested with <code>updatePeriodMillis</code> |
| 121 | * 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] | 122 | */ |
| 123 | public int updatePeriodMillis; |
| 124 | |
| 125 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 126 | * The resource id of the initial layout for this AppWidget. This should be |
| 127 | * displayed until the RemoteViews for the AppWidget is available. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | * |
| 129 | * <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] | 130 | * the AppWidget meta-data file. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | */ |
| 132 | public int initialLayout; |
| 133 | |
| 134 | /** |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 135 | * The resource id of the initial layout for this AppWidget when it is displayed on keyguard. |
| 136 | * This parameter only needs to be provided if the widget can be displayed on the keyguard, |
| 137 | * see {@link #widgetCategory}. |
| 138 | * |
| 139 | * <p>This field corresponds to the <code>android:initialKeyguardLayout</code> attribute in |
| 140 | * the AppWidget meta-data file. |
| 141 | */ |
| 142 | public int initialKeyguardLayout; |
| 143 | |
| 144 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 145 | * The activity to launch that will configure the AppWidget. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | * |
| 147 | * <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] | 148 | * the AppWidget meta-data file. The package name always corresponds to the package containing |
| 149 | * the AppWidget provider. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | */ |
| 151 | public ComponentName configure; |
| 152 | |
| 153 | /** |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 154 | * 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] | 155 | * |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 156 | * @deprecated Use {@link #loadLabel(android.content.pm.PackageManager)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | */ |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 158 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | public String label; |
| 160 | |
| 161 | /** |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 162 | * 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] | 163 | * xml, the application icon will be used. |
| 164 | * |
| 165 | * <p>This field corresponds to the <code>android:icon</code> attribute in |
| 166 | * the <code><receiver></code> element in the AndroidManifest.xml file. |
| 167 | */ |
| 168 | public int icon; |
Adam Cohen | a02fdf1 | 2010-11-03 13:27:40 -0700 | [diff] [blame] | 169 | |
Romain Guy | d2671e1 | 2010-03-11 18:06:42 -0800 | [diff] [blame] | 170 | /** |
Adam Cohen | a02fdf1 | 2010-11-03 13:27:40 -0700 | [diff] [blame] | 171 | * 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] | 172 | * |
| 173 | * <p>This field corresponds to the <code>android:autoAdvanceViewId</code> attribute in |
| 174 | * the AppWidget meta-data file. |
Adam Cohen | a02fdf1 | 2010-11-03 13:27:40 -0700 | [diff] [blame] | 175 | */ |
| 176 | public int autoAdvanceViewId; |
| 177 | |
Patrick Dubroy | d2db2a5 | 2010-06-23 14:56:28 -0700 | [diff] [blame] | 178 | /** |
| 179 | * A preview of what the AppWidget will look like after it's configured. |
| 180 | * If not supplied, the AppWidget's icon will be used. |
| 181 | * |
| 182 | * <p>This field corresponds to the <code>android:previewImage</code> attribute in |
| 183 | * the <code><receiver></code> element in the AndroidManifest.xml file. |
Patrick Dubroy | d2db2a5 | 2010-06-23 14:56:28 -0700 | [diff] [blame] | 184 | */ |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 185 | public int previewImage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | |
Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 187 | /** |
| 188 | * The rules by which a widget can be resized. See {@link #RESIZE_NONE}, |
| 189 | * {@link #RESIZE_NONE}, {@link #RESIZE_HORIZONTAL}, |
| 190 | * {@link #RESIZE_VERTICAL}, {@link #RESIZE_BOTH}. |
Adam Cohen | 9611f2e | 2011-02-28 13:39:38 -0800 | [diff] [blame] | 191 | * |
| 192 | * <p>This field corresponds to the <code>android:resizeMode</code> attribute in |
| 193 | * the AppWidget meta-data file. |
Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 194 | */ |
Adam Cohen | 9611f2e | 2011-02-28 13:39:38 -0800 | [diff] [blame] | 195 | public int resizeMode; |
Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 196 | |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 197 | /** |
| 198 | * Determines whether this widget can be displayed on the home screen, the keyguard, or both. |
| 199 | * A widget which is displayed on both needs to ensure that it follows the design guidelines |
| 200 | * for both widget classes. This can be achieved by querying the AppWidget options in its |
| 201 | * widget provider's update method. |
| 202 | * |
| 203 | * <p>This field corresponds to the <code>widgetCategory</code> attribute in |
| 204 | * the AppWidget meta-data file. |
| 205 | */ |
| 206 | public int widgetCategory; |
| 207 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 208 | /** @hide */ |
| 209 | public ActivityInfo providerInfo; |
| 210 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 211 | public AppWidgetProviderInfo() { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 216 | * Unflatten the AppWidgetProviderInfo from a parcel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | */ |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 218 | @SuppressWarnings("deprecation") |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 219 | public AppWidgetProviderInfo(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | if (0 != in.readInt()) { |
| 221 | this.provider = new ComponentName(in); |
| 222 | } |
| 223 | this.minWidth = in.readInt(); |
| 224 | this.minHeight = in.readInt(); |
Adam Cohen | 324afba | 2011-07-22 11:51:45 -0700 | [diff] [blame] | 225 | this.minResizeWidth = in.readInt(); |
| 226 | this.minResizeHeight = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | this.updatePeriodMillis = in.readInt(); |
| 228 | this.initialLayout = in.readInt(); |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 229 | this.initialKeyguardLayout = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | if (0 != in.readInt()) { |
| 231 | this.configure = new ComponentName(in); |
| 232 | } |
| 233 | this.label = in.readString(); |
| 234 | this.icon = in.readInt(); |
Patrick Dubroy | d2db2a5 | 2010-06-23 14:56:28 -0700 | [diff] [blame] | 235 | this.previewImage = in.readInt(); |
Adam Cohen | a02fdf1 | 2010-11-03 13:27:40 -0700 | [diff] [blame] | 236 | this.autoAdvanceViewId = in.readInt(); |
Adam Cohen | 9611f2e | 2011-02-28 13:39:38 -0800 | [diff] [blame] | 237 | this.resizeMode = in.readInt(); |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 238 | this.widgetCategory = in.readInt(); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 239 | this.providerInfo = in.readParcelable(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 242 | /** |
| 243 | * Loads the localized label to display to the user in the AppWidget picker. |
| 244 | * |
| 245 | * @param packageManager Package manager instance for loading resources. |
| 246 | * @return The label for the current locale. |
| 247 | */ |
| 248 | public final String loadLabel(PackageManager packageManager) { |
| 249 | CharSequence label = providerInfo.loadLabel(packageManager); |
| 250 | if (label != null) { |
| 251 | return label.toString().trim(); |
| 252 | } |
| 253 | return null; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Loads the icon to display for this AppWidget in the AppWidget picker. If not |
| 258 | * supplied in the xml, the application icon will be used. A client can optionally |
| 259 | * provide a desired density such as {@link android.util.DisplayMetrics#DENSITY_LOW} |
| 260 | * {@link android.util.DisplayMetrics#DENSITY_MEDIUM}, etc. If no density is |
| 261 | * provided, the density of the current display will be used. |
| 262 | * <p> |
| 263 | * The loaded icon corresponds to the <code>android:icon</code> attribute in |
| 264 | * the <code><receiver></code> element in the AndroidManifest.xml file. |
| 265 | * </p> |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 266 | * |
| 267 | * @param context Context for accessing resources. |
| 268 | * @param density The optional desired density as per |
| 269 | * {@link android.util.DisplayMetrics#densityDpi}. |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame^] | 270 | * @return The provider icon. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 271 | */ |
| 272 | public final Drawable loadIcon(Context context, int density) { |
| 273 | return loadDrawable(context, density, providerInfo.getIconResource()); |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Loads a preview of what the AppWidget will look like after it's configured. |
| 278 | * If not supplied, the AppWidget's icon will be used. A client can optionally |
| 279 | * provide a desired deinsity such as {@link android.util.DisplayMetrics#DENSITY_LOW} |
| 280 | * {@link android.util.DisplayMetrics#DENSITY_MEDIUM}, etc. If no density is |
| 281 | * provided, the density of the current display will be used. |
| 282 | * <p> |
| 283 | * The loaded image corresponds to the <code>android:previewImage</code> attribute |
| 284 | * in the <code><receiver></code> element in the AndroidManifest.xml file. |
| 285 | * </p> |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 286 | * |
| 287 | * @param context Context for accessing resources. |
| 288 | * @param density The optional desired density as per |
| 289 | * {@link android.util.DisplayMetrics#densityDpi}. |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame^] | 290 | * @return The widget preview image. |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 291 | */ |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 292 | public final Drawable loadPreviewImage(Context context, int density) { |
| 293 | return loadDrawable(context, density, previewImage); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Gets the user profile in which the provider resides. |
| 298 | * |
| 299 | * @return The hosting user profile. |
| 300 | */ |
| 301 | public final UserHandle getProfile() { |
| 302 | return new UserHandle(UserHandle.getUserId(providerInfo.applicationInfo.uid)); |
| 303 | } |
| 304 | |
| 305 | @Override |
| 306 | @SuppressWarnings("deprecation") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | public void writeToParcel(android.os.Parcel out, int flags) { |
| 308 | if (this.provider != null) { |
| 309 | out.writeInt(1); |
| 310 | this.provider.writeToParcel(out, flags); |
| 311 | } else { |
| 312 | out.writeInt(0); |
| 313 | } |
| 314 | out.writeInt(this.minWidth); |
| 315 | out.writeInt(this.minHeight); |
Adam Cohen | 324afba | 2011-07-22 11:51:45 -0700 | [diff] [blame] | 316 | out.writeInt(this.minResizeWidth); |
| 317 | out.writeInt(this.minResizeHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | out.writeInt(this.updatePeriodMillis); |
| 319 | out.writeInt(this.initialLayout); |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 320 | out.writeInt(this.initialKeyguardLayout); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | if (this.configure != null) { |
| 322 | out.writeInt(1); |
| 323 | this.configure.writeToParcel(out, flags); |
| 324 | } else { |
| 325 | out.writeInt(0); |
| 326 | } |
| 327 | out.writeString(this.label); |
| 328 | out.writeInt(this.icon); |
Patrick Dubroy | d2db2a5 | 2010-06-23 14:56:28 -0700 | [diff] [blame] | 329 | out.writeInt(this.previewImage); |
Adam Cohen | a02fdf1 | 2010-11-03 13:27:40 -0700 | [diff] [blame] | 330 | out.writeInt(this.autoAdvanceViewId); |
Adam Cohen | 9611f2e | 2011-02-28 13:39:38 -0800 | [diff] [blame] | 331 | out.writeInt(this.resizeMode); |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 332 | out.writeInt(this.widgetCategory); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 333 | out.writeParcelable(this.providerInfo, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Adam Cohen | 3ff2d86 | 2012-09-26 14:07:57 -0700 | [diff] [blame] | 336 | @Override |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 337 | @SuppressWarnings("deprecation") |
Adam Cohen | 3ff2d86 | 2012-09-26 14:07:57 -0700 | [diff] [blame] | 338 | public AppWidgetProviderInfo clone() { |
| 339 | AppWidgetProviderInfo that = new AppWidgetProviderInfo(); |
| 340 | that.provider = this.provider == null ? null : this.provider.clone(); |
| 341 | that.minWidth = this.minWidth; |
| 342 | that.minHeight = this.minHeight; |
| 343 | that.minResizeWidth = this.minResizeHeight; |
| 344 | that.minResizeHeight = this.minResizeHeight; |
| 345 | that.updatePeriodMillis = this.updatePeriodMillis; |
Adam Cohen | 180cfd5 | 2012-11-04 12:03:12 -0800 | [diff] [blame] | 346 | that.initialLayout = this.initialLayout; |
Adam Cohen | 3ff2d86 | 2012-09-26 14:07:57 -0700 | [diff] [blame] | 347 | that.initialKeyguardLayout = this.initialKeyguardLayout; |
| 348 | that.configure = this.configure == null ? null : this.configure.clone(); |
| 349 | that.label = this.label == null ? null : this.label.substring(0); |
| 350 | that.icon = this.icon; |
| 351 | that.previewImage = this.previewImage; |
| 352 | that.autoAdvanceViewId = this.autoAdvanceViewId; |
| 353 | that.resizeMode = this.resizeMode; |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 354 | that.widgetCategory = this.widgetCategory; |
| 355 | that.providerInfo = this.providerInfo; |
Adam Cohen | 3ff2d86 | 2012-09-26 14:07:57 -0700 | [diff] [blame] | 356 | return that; |
| 357 | } |
| 358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | public int describeContents() { |
| 360 | return 0; |
| 361 | } |
| 362 | |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 363 | private Drawable loadDrawable(Context context, int density, int resourceId) { |
| 364 | try { |
| 365 | Resources resources = context.getPackageManager().getResourcesForApplication( |
| 366 | providerInfo.applicationInfo); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 367 | if (resourceId > 0) { |
| 368 | if (density <= 0) { |
| 369 | density = context.getResources().getDisplayMetrics().densityDpi; |
| 370 | } |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame^] | 371 | return resources.getDrawableForDensity(resourceId, density); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 372 | } |
| 373 | } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { |
| 374 | /* ignore */ |
| 375 | } |
Svetoslav | c71c42f | 2014-08-05 18:57:05 -0700 | [diff] [blame^] | 376 | return providerInfo.loadIcon(context.getPackageManager()); |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 377 | } |
| 378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 380 | * Parcelable.Creator that instantiates AppWidgetProviderInfo objects |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | */ |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 382 | public static final Parcelable.Creator<AppWidgetProviderInfo> CREATOR |
| 383 | = new Parcelable.Creator<AppWidgetProviderInfo>() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 385 | public AppWidgetProviderInfo createFromParcel(Parcel parcel) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 387 | return new AppWidgetProviderInfo(parcel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | } |
| 389 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 390 | public AppWidgetProviderInfo[] newArray(int size) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 392 | return new AppWidgetProviderInfo[size]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | } |
| 394 | }; |
| 395 | |
| 396 | public String toString() { |
Svetoslav | 976e8bd | 2014-07-16 15:12:03 -0700 | [diff] [blame] | 397 | return "AppWidgetProviderInfo(" + getProfile() + '/' + provider + ')'; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | } |
| 399 | } |