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