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 17 package android.appwidget; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 import 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 */ 27 public 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 * Identity of this AppWidget component. This component should be a {@link 58 * android.content.BroadcastReceiver}, and it will be sent the AppWidget intents 59 * {@link android.appwidget as described in the AppWidget package documentation}. 60 * 61 * <p>This field corresponds to the <code>android:name</code> attribute in 62 * the <code><receiver></code> element in the AndroidManifest.xml file. 63 */ 64 public ComponentName provider; 65 66 /** 67 * The default height of the widget when added to a host, in dp. The widget will get 68 * at least this width, and will often be given more, depending on the host. 69 * 70 * <p>This field corresponds to the <code>android:minWidth</code> attribute in 71 * the AppWidget meta-data file. 72 */ 73 public int minWidth; 74 75 /** 76 * The default height of the widget when added to a host, in dp. The widget will get 77 * at least this height, and will often be given more, depending on the host. 78 * 79 * <p>This field corresponds to the <code>android:minHeight</code> attribute in 80 * the AppWidget meta-data file. 81 */ 82 public int minHeight; 83 84 /** 85 * Minimum width (in dp) which the widget can be resized to. This field has no effect if it 86 * is greater than minWidth or if horizontal resizing isn't enabled (see {@link #resizeMode}). 87 * 88 * <p>This field corresponds to the <code>android:minResizeWidth</code> attribute in 89 * the AppWidget meta-data file. 90 */ 91 public int minResizeWidth; 92 93 /** 94 * Minimum height (in dp) which the widget can be resized to. This field has no effect if it 95 * is greater than minHeight or if vertical resizing isn't enabled (see {@link #resizeMode}). 96 * 97 * <p>This field corresponds to the <code>android:minResizeHeight</code> attribute in 98 * the AppWidget meta-data file. 99 */ 100 public int minResizeHeight; 101 102 /** 103 * How often, in milliseconds, that this AppWidget wants to be updated. 104 * The AppWidget manager may place a limit on how often a AppWidget is updated. 105 * 106 * <p>This field corresponds to the <code>android:updatePeriodMillis</code> attribute in 107 * the AppWidget meta-data file. 108 * 109 * <p class="note"><b>Note:</b> Updates requested with <code>updatePeriodMillis</code> 110 * will not be delivered more than once every 30 minutes.</p> 111 */ 112 public int updatePeriodMillis; 113 114 /** 115 * The resource id of the initial layout for this AppWidget. This should be 116 * displayed until the RemoteViews for the AppWidget is available. 117 * 118 * <p>This field corresponds to the <code>android:initialLayout</code> attribute in 119 * the AppWidget meta-data file. 120 */ 121 public int initialLayout; 122 123 /** 124 * The resource id of the initial layout for this AppWidget when it is displayed on keyguard. 125 * This parameter only needs to be provided if the widget can be displayed on the keyguard, 126 * see {@link #widgetCategory}. 127 * 128 * <p>This field corresponds to the <code>android:initialKeyguardLayout</code> attribute in 129 * the AppWidget meta-data file. 130 */ 131 public int initialKeyguardLayout; 132 133 /** 134 * The activity to launch that will configure the AppWidget. 135 * 136 * <p>This class name of field corresponds to the <code>android:configure</code> attribute in 137 * the AppWidget meta-data file. The package name always corresponds to the package containing 138 * the AppWidget provider. 139 */ 140 public ComponentName configure; 141 142 /** 143 * The label to display to the user in the AppWidget picker. If not supplied in the 144 * xml, the application label will be used. 145 * 146 * <p>This field corresponds to the <code>android:label</code> attribute in 147 * the <code><receiver></code> element in the AndroidManifest.xml file. 148 */ 149 public String label; 150 151 /** 152 * The icon to display for this AppWidget in the AppWidget picker. If not supplied in the 153 * xml, the application icon will be used. 154 * 155 * <p>This field corresponds to the <code>android:icon</code> attribute in 156 * the <code><receiver></code> element in the AndroidManifest.xml file. 157 */ 158 public int icon; 159 160 /** 161 * The view id of the AppWidget subview which should be auto-advanced by the widget's host. 162 * 163 * <p>This field corresponds to the <code>android:autoAdvanceViewId</code> attribute in 164 * the AppWidget meta-data file. 165 */ 166 public int autoAdvanceViewId; 167 168 /** 169 * A preview of what the AppWidget will look like after it's configured. 170 * If not supplied, the AppWidget's icon will be used. 171 * 172 * <p>This field corresponds to the <code>android:previewImage</code> attribute in 173 * the <code><receiver></code> element in the AndroidManifest.xml file. 174 */ 175 public int previewImage; 176 177 /** 178 * The rules by which a widget can be resized. See {@link #RESIZE_NONE}, 179 * {@link #RESIZE_NONE}, {@link #RESIZE_HORIZONTAL}, 180 * {@link #RESIZE_VERTICAL}, {@link #RESIZE_BOTH}. 181 * 182 * <p>This field corresponds to the <code>android:resizeMode</code> attribute in 183 * the AppWidget meta-data file. 184 */ 185 public int resizeMode; 186 187 /** 188 * Determines whether this widget can be displayed on the home screen, the keyguard, or both. 189 * A widget which is displayed on both needs to ensure that it follows the design guidelines 190 * for both widget classes. This can be achieved by querying the AppWidget options in its 191 * widget provider's update method. 192 * 193 * <p>This field corresponds to the <code>widgetCategory</code> attribute in 194 * the AppWidget meta-data file. 195 */ 196 public int widgetCategory; 197 198 public AppWidgetProviderInfo() { 199 } 200 201 /** 202 * Unflatten the AppWidgetProviderInfo from a parcel. 203 */ 204 public AppWidgetProviderInfo(Parcel in) { 205 if (0 != in.readInt()) { 206 this.provider = new ComponentName(in); 207 } 208 this.minWidth = in.readInt(); 209 this.minHeight = in.readInt(); 210 this.minResizeWidth = in.readInt(); 211 this.minResizeHeight = in.readInt(); 212 this.updatePeriodMillis = in.readInt(); 213 this.initialLayout = in.readInt(); 214 this.initialKeyguardLayout = in.readInt(); 215 if (0 != in.readInt()) { 216 this.configure = new ComponentName(in); 217 } 218 this.label = in.readString(); 219 this.icon = in.readInt(); 220 this.previewImage = in.readInt(); 221 this.autoAdvanceViewId = in.readInt(); 222 this.resizeMode = in.readInt(); 223 this.widgetCategory = in.readInt(); 224 } 225 226 public void writeToParcel(android.os.Parcel out, int flags) { 227 if (this.provider != null) { 228 out.writeInt(1); 229 this.provider.writeToParcel(out, flags); 230 } else { 231 out.writeInt(0); 232 } 233 out.writeInt(this.minWidth); 234 out.writeInt(this.minHeight); 235 out.writeInt(this.minResizeWidth); 236 out.writeInt(this.minResizeHeight); 237 out.writeInt(this.updatePeriodMillis); 238 out.writeInt(this.initialLayout); 239 out.writeInt(this.initialKeyguardLayout); 240 if (this.configure != null) { 241 out.writeInt(1); 242 this.configure.writeToParcel(out, flags); 243 } else { 244 out.writeInt(0); 245 } 246 out.writeString(this.label); 247 out.writeInt(this.icon); 248 out.writeInt(this.previewImage); 249 out.writeInt(this.autoAdvanceViewId); 250 out.writeInt(this.resizeMode); 251 out.writeInt(this.widgetCategory); 252 } 253 254 @Override 255 public AppWidgetProviderInfo clone() { 256 AppWidgetProviderInfo that = new AppWidgetProviderInfo(); 257 that.provider = this.provider == null ? null : this.provider.clone(); 258 that.minWidth = this.minWidth; 259 that.minHeight = this.minHeight; 260 that.minResizeWidth = this.minResizeHeight; 261 that.minResizeHeight = this.minResizeHeight; 262 that.updatePeriodMillis = this.updatePeriodMillis; 263 that.initialLayout = this.initialLayout; 264 that.initialKeyguardLayout = this.initialKeyguardLayout; 265 that.configure = this.configure == null ? null : this.configure.clone(); 266 that.label = this.label == null ? null : this.label.substring(0); 267 that.icon = this.icon; 268 that.previewImage = this.previewImage; 269 that.autoAdvanceViewId = this.autoAdvanceViewId; 270 that.resizeMode = this.resizeMode; 271 that.widgetCategory = this.widgetCategory; 272 return that; 273 } 274 275 public int describeContents() { 276 return 0; 277 } 278 279 /** 280 * Parcelable.Creator that instantiates AppWidgetProviderInfo objects 281 */ 282 public static final Parcelable.Creator<AppWidgetProviderInfo> CREATOR 283 = new Parcelable.Creator<AppWidgetProviderInfo>() 284 { 285 public AppWidgetProviderInfo createFromParcel(Parcel parcel) 286 { 287 return new AppWidgetProviderInfo(parcel); 288 } 289 290 public AppWidgetProviderInfo[] newArray(int size) 291 { 292 return new AppWidgetProviderInfo[size]; 293 } 294 }; 295 296 public String toString() { 297 return "AppWidgetProviderInfo(provider=" + this.provider + ")"; 298 } 299 } 300