AppWidgetProviderInfo.java revision 82ebe6f777902f00250efc3535ad11c2c6a74258
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 17package android.appwidget; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21import android.content.ComponentName; 22 23/** 24 * Describes the meta data for an installed AppWidget provider. The fields in this class 25 * correspond to the fields in the <code><appwidget-provider></code> xml tag. 26 */ 27public class AppWidgetProviderInfo implements Parcelable { 28 29 /** 30 * Widget is not resizable. 31 */ 32 public static final int RESIZE_NONE = 0; 33 /** 34 * Widget is resizable in the horizontal axis only. 35 */ 36 public static final int RESIZE_HORIZONTAL = 1; 37 /** 38 * Widget is resizable in the vertical axis only. 39 */ 40 public static final int RESIZE_VERTICAL = 2; 41 /** 42 * Widget is resizable in both the horizontal and vertical axes. 43 */ 44 public static final int RESIZE_BOTH = RESIZE_HORIZONTAL | RESIZE_VERTICAL; 45 46 /** 47 * Indicates that the widget can be displayed on the home screen. This is the default value. 48 */ 49 public static final int WIDGET_CATEGORY_HOME_SCREEN = 1; 50 51 /** 52 * Indicates that the widget can be displayed on the keyguard. 53 */ 54 public static final int WIDGET_CATEGORY_KEYGUARD = 2; 55 56 /** 57 * Indicates that the widget supports no special features. 58 */ 59 public static final int WIDGET_FEATURES_NONE = 0; 60 61 /** 62 * Indicates that the widget is output only, ie. has nothing clickable. This may be enforced by 63 * the host. Presently, this flag is used by the keyguard to indicate that it can be placed 64 * in the first position. 65 */ 66 public static final int WIDGET_FEATURES_STATUS = 1; 67 68 /** 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}. 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 /** 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. 81 * 82 * <p>This field corresponds to the <code>android:minWidth</code> attribute in 83 * the AppWidget meta-data file. 84 */ 85 public int minWidth; 86 87 /** 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. 90 * 91 * <p>This field corresponds to the <code>android:minHeight</code> attribute in 92 * the AppWidget meta-data file. 93 */ 94 public int minHeight; 95 96 /** 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 /** 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. 117 * 118 * <p>This field corresponds to the <code>android:updatePeriodMillis</code> attribute in 119 * the AppWidget meta-data file. 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> 123 */ 124 public int updatePeriodMillis; 125 126 /** 127 * The resource id of the initial layout for this AppWidget. This should be 128 * displayed until the RemoteViews for the AppWidget is available. 129 * 130 * <p>This field corresponds to the <code>android:initialLayout</code> attribute in 131 * the AppWidget meta-data file. 132 */ 133 public int initialLayout; 134 135 /** 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 /** 146 * The activity to launch that will configure the AppWidget. 147 * 148 * <p>This class name of field corresponds to the <code>android:configure</code> attribute in 149 * the AppWidget meta-data file. The package name always corresponds to the package containing 150 * the AppWidget provider. 151 */ 152 public ComponentName configure; 153 154 /** 155 * The label to display to the user in the AppWidget picker. If not supplied in the 156 * xml, the application label will be used. 157 * 158 * <p>This field corresponds to the <code>android:label</code> attribute in 159 * the <code><receiver></code> element in the AndroidManifest.xml file. 160 */ 161 public String label; 162 163 /** 164 * The icon to display for this AppWidget in the AppWidget picker. If not supplied in the 165 * xml, the application icon will be used. 166 * 167 * <p>This field corresponds to the <code>android:icon</code> attribute in 168 * the <code><receiver></code> element in the AndroidManifest.xml file. 169 */ 170 public int icon; 171 172 /** 173 * The view id of the AppWidget subview which should be auto-advanced by the widget's host. 174 * 175 * <p>This field corresponds to the <code>android:autoAdvanceViewId</code> attribute in 176 * the AppWidget meta-data file. 177 */ 178 public int autoAdvanceViewId; 179 180 /** 181 * A preview of what the AppWidget will look like after it's configured. 182 * If not supplied, the AppWidget's icon will be used. 183 * 184 * <p>This field corresponds to the <code>android:previewImage</code> attribute in 185 * the <code><receiver></code> element in the AndroidManifest.xml file. 186 */ 187 public int previewImage; 188 189 /** 190 * The rules by which a widget can be resized. See {@link #RESIZE_NONE}, 191 * {@link #RESIZE_NONE}, {@link #RESIZE_HORIZONTAL}, 192 * {@link #RESIZE_VERTICAL}, {@link #RESIZE_BOTH}. 193 * 194 * <p>This field corresponds to the <code>android:resizeMode</code> attribute in 195 * the AppWidget meta-data file. 196 */ 197 public int resizeMode; 198 199 /** 200 * Determines whether this widget can be displayed on the home screen, the keyguard, or both. 201 * A widget which is displayed on both needs to ensure that it follows the design guidelines 202 * for both widget classes. This can be achieved by querying the AppWidget options in its 203 * widget provider's update method. 204 * 205 * <p>This field corresponds to the <code>widgetCategory</code> attribute in 206 * the AppWidget meta-data file. 207 */ 208 public int widgetCategory; 209 210 /** 211 * A field which specifies any special features that this widget supports. See 212 * {@link #WIDGET_FEATURES_NONE}, {@link #WIDGET_FEATURES_STATUS}. 213 * 214 * <p>This field corresponds to the <code>widgetFeatures</code> attribute in 215 * the AppWidget meta-data file. 216 */ 217 public int widgetFeatures; 218 219 public AppWidgetProviderInfo() { 220 } 221 222 /** 223 * Unflatten the AppWidgetProviderInfo from a parcel. 224 */ 225 public AppWidgetProviderInfo(Parcel in) { 226 if (0 != in.readInt()) { 227 this.provider = new ComponentName(in); 228 } 229 this.minWidth = in.readInt(); 230 this.minHeight = in.readInt(); 231 this.minResizeWidth = in.readInt(); 232 this.minResizeHeight = in.readInt(); 233 this.updatePeriodMillis = in.readInt(); 234 this.initialLayout = in.readInt(); 235 this.initialKeyguardLayout = in.readInt(); 236 if (0 != in.readInt()) { 237 this.configure = new ComponentName(in); 238 } 239 this.label = in.readString(); 240 this.icon = in.readInt(); 241 this.previewImage = in.readInt(); 242 this.autoAdvanceViewId = in.readInt(); 243 this.resizeMode = in.readInt(); 244 this.widgetCategory = in.readInt(); 245 this.widgetFeatures = in.readInt(); 246 } 247 248 public void writeToParcel(android.os.Parcel out, int flags) { 249 if (this.provider != null) { 250 out.writeInt(1); 251 this.provider.writeToParcel(out, flags); 252 } else { 253 out.writeInt(0); 254 } 255 out.writeInt(this.minWidth); 256 out.writeInt(this.minHeight); 257 out.writeInt(this.minResizeWidth); 258 out.writeInt(this.minResizeHeight); 259 out.writeInt(this.updatePeriodMillis); 260 out.writeInt(this.initialLayout); 261 out.writeInt(this.initialKeyguardLayout); 262 if (this.configure != null) { 263 out.writeInt(1); 264 this.configure.writeToParcel(out, flags); 265 } else { 266 out.writeInt(0); 267 } 268 out.writeString(this.label); 269 out.writeInt(this.icon); 270 out.writeInt(this.previewImage); 271 out.writeInt(this.autoAdvanceViewId); 272 out.writeInt(this.resizeMode); 273 out.writeInt(this.widgetCategory); 274 out.writeInt(this.widgetFeatures); 275 } 276 277 @Override 278 public AppWidgetProviderInfo clone() { 279 AppWidgetProviderInfo that = new AppWidgetProviderInfo(); 280 that.provider = this.provider == null ? null : this.provider.clone(); 281 that.minWidth = this.minWidth; 282 that.minHeight = this.minHeight; 283 that.minResizeWidth = this.minResizeHeight; 284 that.minResizeHeight = this.minResizeHeight; 285 that.updatePeriodMillis = this.updatePeriodMillis; 286 that.initialLayout = that.initialLayout; 287 that.initialKeyguardLayout = this.initialKeyguardLayout; 288 that.configure = this.configure == null ? null : this.configure.clone(); 289 that.label = this.label == null ? null : this.label.substring(0); 290 that.icon = this.icon; 291 that.previewImage = this.previewImage; 292 that.autoAdvanceViewId = this.autoAdvanceViewId; 293 that.resizeMode = this.resizeMode; 294 that.widgetCategory = this.widgetCategory; 295 that.widgetFeatures = this.widgetFeatures; 296 return that; 297 } 298 299 public int describeContents() { 300 return 0; 301 } 302 303 /** 304 * Parcelable.Creator that instantiates AppWidgetProviderInfo objects 305 */ 306 public static final Parcelable.Creator<AppWidgetProviderInfo> CREATOR 307 = new Parcelable.Creator<AppWidgetProviderInfo>() 308 { 309 public AppWidgetProviderInfo createFromParcel(Parcel parcel) 310 { 311 return new AppWidgetProviderInfo(parcel); 312 } 313 314 public AppWidgetProviderInfo[] newArray(int size) 315 { 316 return new AppWidgetProviderInfo[size]; 317 } 318 }; 319 320 public String toString() { 321 return "AppWidgetProviderInfo(provider=" + this.provider + ")"; 322 } 323} 324