AppWidgetProviderInfo.java revision a6abd062bf437fc69131a2797d6974953dd6cd83
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>&lt;appwidget-provider&gt;</code> xml tag.
26 */
27public class AppWidgetProviderInfo implements Parcelable {
28    /**
29     * Identity of this AppWidget component.  This component should be a {@link
30     * android.content.BroadcastReceiver}, and it will be sent the AppWidget intents
31     * {@link android.appwidget as described in the AppWidget package documentation}.
32     *
33     * <p>This field corresponds to the <code>android:name</code> attribute in
34     * the <code>&lt;receiver&gt;</code> element in the AndroidManifest.xml file.
35     */
36    public ComponentName provider;
37
38    /**
39     * Minimum width of the AppWidget, in dp.
40     *
41     * <p>This field corresponds to the <code>android:minWidth</code> attribute in
42     * the AppWidget meta-data file.
43     */
44    public int minWidth;
45
46    /**
47     * Minimum height of the AppWidget, in dp.
48     *
49     * <p>This field corresponds to the <code>android:minHeight</code> attribute in
50     * the AppWidget meta-data file.
51     */
52    public int minHeight;
53
54    /**
55     * How often, in milliseconds, that this AppWidget wants to be updated.
56     * The AppWidget manager may place a limit on how often a AppWidget is updated.
57     *
58     * <p>This field corresponds to the <code>android:updatePeriodMillis</code> attribute in
59     * the AppWidget meta-data file.
60     *
61     * <p class="note"><b>Note:</b> Updates requested with <code>updatePeriodMillis</code>
62     * will not be delivered more than once every 30 minutes.</p>
63     */
64    public int updatePeriodMillis;
65
66    /**
67     * The resource id of the initial layout for this AppWidget.  This should be
68     * displayed until the RemoteViews for the AppWidget is available.
69     *
70     * <p>This field corresponds to the <code>android:initialLayout</code> attribute in
71     * the AppWidget meta-data file.
72     */
73    public int initialLayout;
74
75    /**
76     * The activity to launch that will configure the AppWidget.
77     *
78     * <p>This class name of field corresponds to the <code>android:configure</code> attribute in
79     * the AppWidget meta-data file.  The package name always corresponds to the package containing
80     * the AppWidget provider.
81     */
82    public ComponentName configure;
83
84    /**
85     * The label to display to the user in the AppWidget picker.  If not supplied in the
86     * xml, the application label will be used.
87     *
88     * <p>This field corresponds to the <code>android:label</code> attribute in
89     * the <code>&lt;receiver&gt;</code> element in the AndroidManifest.xml file.
90     */
91    public String label;
92
93    /**
94     * The icon to display for this AppWidget in the AppWidget picker.  If not supplied in the
95     * xml, the application icon will be used.
96     *
97     * <p>This field corresponds to the <code>android:icon</code> attribute in
98     * the <code>&lt;receiver&gt;</code> element in the AndroidManifest.xml file.
99     */
100    public int icon;
101
102    /**
103     * The previous name, if any, of the app widget receiver. If not supplied, it will be
104     * ignored.
105     *
106     * <p>This field corresponds to the <code>&lt;meta-data /&gt;</code> with the name
107     * <code>android.appwidget.oldName</code>.
108     *
109     * @hide Pending API approval
110     */
111    public String oldName;
112
113    /**
114     * The view id of the AppWidget subview which should be auto-advanced by the widget's host.
115     */
116    public int autoAdvanceViewId;
117
118    /**
119     * A preview of what the AppWidget will look like after it's configured.
120     * If not supplied, the AppWidget's icon will be used.
121     *
122     * <p>This field corresponds to the <code>android:previewImage</code> attribute in
123     * the <code>&lt;receiver&gt;</code> element in the AndroidManifest.xml file.
124     */
125	public int previewImage;
126
127    public AppWidgetProviderInfo() {
128    }
129
130    /**
131     * Unflatten the AppWidgetProviderInfo from a parcel.
132     */
133    public AppWidgetProviderInfo(Parcel in) {
134        if (0 != in.readInt()) {
135            this.provider = new ComponentName(in);
136        }
137        this.minWidth = in.readInt();
138        this.minHeight = in.readInt();
139        this.updatePeriodMillis = in.readInt();
140        this.initialLayout = in.readInt();
141        if (0 != in.readInt()) {
142            this.configure = new ComponentName(in);
143        }
144        this.label = in.readString();
145        this.icon = in.readInt();
146        this.previewImage = in.readInt();
147        this.autoAdvanceViewId = in.readInt();
148    }
149
150    public void writeToParcel(android.os.Parcel out, int flags) {
151        if (this.provider != null) {
152            out.writeInt(1);
153            this.provider.writeToParcel(out, flags);
154        } else {
155            out.writeInt(0);
156        }
157        out.writeInt(this.minWidth);
158        out.writeInt(this.minHeight);
159        out.writeInt(this.updatePeriodMillis);
160        out.writeInt(this.initialLayout);
161        if (this.configure != null) {
162            out.writeInt(1);
163            this.configure.writeToParcel(out, flags);
164        } else {
165            out.writeInt(0);
166        }
167        out.writeString(this.label);
168        out.writeInt(this.icon);
169        out.writeInt(this.previewImage);
170        out.writeInt(this.autoAdvanceViewId);
171    }
172
173    public int describeContents() {
174        return 0;
175    }
176
177    /**
178     * Parcelable.Creator that instantiates AppWidgetProviderInfo objects
179     */
180    public static final Parcelable.Creator<AppWidgetProviderInfo> CREATOR
181            = new Parcelable.Creator<AppWidgetProviderInfo>()
182    {
183        public AppWidgetProviderInfo createFromParcel(Parcel parcel)
184        {
185            return new AppWidgetProviderInfo(parcel);
186        }
187
188        public AppWidgetProviderInfo[] newArray(int size)
189        {
190            return new AppWidgetProviderInfo[size];
191        }
192    };
193
194    public String toString() {
195        return "AppWidgetProviderInfo(provider=" + this.provider + ")";
196    }
197}
198