AppWidgetProviderInfo.java revision bac26a1205883ad30343f1d1f64a039dcdda9f63
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 * Identity of this AppWidget component. This component should be a {@link 48 * android.content.BroadcastReceiver}, and it will be sent the AppWidget intents 49 * {@link android.appwidget as described in the AppWidget package documentation}. 50 * 51 * <p>This field corresponds to the <code>android:name</code> attribute in 52 * the <code><receiver></code> element in the AndroidManifest.xml file. 53 */ 54 public ComponentName provider; 55 56 /** 57 * The default height of the widget when added to a host, in dp. The widget will get 58 * at least this width, and will often be given more, depending on the host. 59 * 60 * <p>This field corresponds to the <code>android:minWidth</code> attribute in 61 * the AppWidget meta-data file. 62 */ 63 public int minWidth; 64 65 /** 66 * The default height of the widget when added to a host, in dp. The widget will get 67 * at least this height, and will often be given more, depending on the host. 68 * 69 * <p>This field corresponds to the <code>android:minHeight</code> attribute in 70 * the AppWidget meta-data file. 71 */ 72 public int minHeight; 73 74 /** 75 * Minimum width (in dp) which the widget can be resized to. This field has no effect if it 76 * is greater than minWidth or if horizontal resizing isn't enabled (see {@link #resizeMode}). 77 * 78 * <p>This field corresponds to the <code>android:minResizeWidth</code> attribute in 79 * the AppWidget meta-data file. 80 */ 81 public int minResizeWidth; 82 83 /** 84 * Minimum height (in dp) which the widget can be resized to. This field has no effect if it 85 * is greater than minHeight or if vertical resizing isn't enabled (see {@link #resizeMode}). 86 * 87 * <p>This field corresponds to the <code>android:minResizeHeight</code> attribute in 88 * the AppWidget meta-data file. 89 */ 90 public int minResizeHeight; 91 92 /** 93 * How often, in milliseconds, that this AppWidget wants to be updated. 94 * The AppWidget manager may place a limit on how often a AppWidget is updated. 95 * 96 * <p>This field corresponds to the <code>android:updatePeriodMillis</code> attribute in 97 * the AppWidget meta-data file. 98 * 99 * <p class="note"><b>Note:</b> Updates requested with <code>updatePeriodMillis</code> 100 * will not be delivered more than once every 30 minutes.</p> 101 */ 102 public int updatePeriodMillis; 103 104 /** 105 * The resource id of the initial layout for this AppWidget. This should be 106 * displayed until the RemoteViews for the AppWidget is available. 107 * 108 * <p>This field corresponds to the <code>android:initialLayout</code> attribute in 109 * the AppWidget meta-data file. 110 */ 111 public int initialLayout; 112 113 /** 114 * The activity to launch that will configure the AppWidget. 115 * 116 * <p>This class name of field corresponds to the <code>android:configure</code> attribute in 117 * the AppWidget meta-data file. The package name always corresponds to the package containing 118 * the AppWidget provider. 119 */ 120 public ComponentName configure; 121 122 /** 123 * The label to display to the user in the AppWidget picker. If not supplied in the 124 * xml, the application label will be used. 125 * 126 * <p>This field corresponds to the <code>android:label</code> attribute in 127 * the <code><receiver></code> element in the AndroidManifest.xml file. 128 */ 129 public String label; 130 131 /** 132 * The icon to display for this AppWidget in the AppWidget picker. If not supplied in the 133 * xml, the application icon will be used. 134 * 135 * <p>This field corresponds to the <code>android:icon</code> attribute in 136 * the <code><receiver></code> element in the AndroidManifest.xml file. 137 */ 138 public int icon; 139 140 /** 141 * The view id of the AppWidget subview which should be auto-advanced by the widget's host. 142 * 143 * <p>This field corresponds to the <code>android:autoAdvanceViewId</code> attribute in 144 * the AppWidget meta-data file. 145 */ 146 public int autoAdvanceViewId; 147 148 /** 149 * A preview of what the AppWidget will look like after it's configured. 150 * If not supplied, the AppWidget's icon will be used. 151 * 152 * <p>This field corresponds to the <code>android:previewImage</code> attribute in 153 * the <code><receiver></code> element in the AndroidManifest.xml file. 154 */ 155 public int previewImage; 156 157 /** 158 * The rules by which a widget can be resized. See {@link #RESIZE_NONE}, 159 * {@link #RESIZE_NONE}, {@link #RESIZE_HORIZONTAL}, 160 * {@link #RESIZE_VERTICAL}, {@link #RESIZE_BOTH}. 161 * 162 * <p>This field corresponds to the <code>android:resizeMode</code> attribute in 163 * the AppWidget meta-data file. 164 */ 165 public int resizeMode; 166 167 public AppWidgetProviderInfo() { 168 } 169 170 /** 171 * Unflatten the AppWidgetProviderInfo from a parcel. 172 */ 173 public AppWidgetProviderInfo(Parcel in) { 174 if (0 != in.readInt()) { 175 this.provider = new ComponentName(in); 176 } 177 this.minWidth = in.readInt(); 178 this.minHeight = in.readInt(); 179 this.minResizeWidth = in.readInt(); 180 this.minResizeHeight = in.readInt(); 181 this.updatePeriodMillis = in.readInt(); 182 this.initialLayout = in.readInt(); 183 if (0 != in.readInt()) { 184 this.configure = new ComponentName(in); 185 } 186 this.label = in.readString(); 187 this.icon = in.readInt(); 188 this.previewImage = in.readInt(); 189 this.autoAdvanceViewId = in.readInt(); 190 this.resizeMode = in.readInt(); 191 } 192 193 public void writeToParcel(android.os.Parcel out, int flags) { 194 if (this.provider != null) { 195 out.writeInt(1); 196 this.provider.writeToParcel(out, flags); 197 } else { 198 out.writeInt(0); 199 } 200 out.writeInt(this.minWidth); 201 out.writeInt(this.minHeight); 202 out.writeInt(this.minResizeWidth); 203 out.writeInt(this.minResizeHeight); 204 out.writeInt(this.updatePeriodMillis); 205 out.writeInt(this.initialLayout); 206 if (this.configure != null) { 207 out.writeInt(1); 208 this.configure.writeToParcel(out, flags); 209 } else { 210 out.writeInt(0); 211 } 212 out.writeString(this.label); 213 out.writeInt(this.icon); 214 out.writeInt(this.previewImage); 215 out.writeInt(this.autoAdvanceViewId); 216 out.writeInt(this.resizeMode); 217 } 218 219 public int describeContents() { 220 return 0; 221 } 222 223 /** 224 * Parcelable.Creator that instantiates AppWidgetProviderInfo objects 225 */ 226 public static final Parcelable.Creator<AppWidgetProviderInfo> CREATOR 227 = new Parcelable.Creator<AppWidgetProviderInfo>() 228 { 229 public AppWidgetProviderInfo createFromParcel(Parcel parcel) 230 { 231 return new AppWidgetProviderInfo(parcel); 232 } 233 234 public AppWidgetProviderInfo[] newArray(int size) 235 { 236 return new AppWidgetProviderInfo[size]; 237 } 238 }; 239 240 public String toString() { 241 return "AppWidgetProviderInfo(provider=" + this.provider + ")"; 242 } 243} 244