blob: 602695a46f2bef6cf2f9ed1aa5c054265c2baaf3 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2009 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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
The Android Open Source Project7376fae2009-03-11 12:11:58 -070019import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070020import android.content.ComponentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021import android.content.ContentValues;
Adam Cohen9e05a5e2012-09-10 15:53:09 -070022import android.os.Build;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023
24/**
Patrick Dubroy6569f2c2010-07-12 14:25:18 -070025 * Represents a widget (either instantiated or about to be) in the Launcher.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080026 */
The Android Open Source Project7376fae2009-03-11 12:11:58 -070027class LauncherAppWidgetInfo extends ItemInfo {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028
29 /**
Patrick Dubroy6569f2c2010-07-12 14:25:18 -070030 * Indicates that the widget hasn't been instantiated yet.
31 */
32 static final int NO_ID = -1;
33
34 /**
Romain Guy629de3e2010-01-13 12:20:59 -080035 * Identifier for this widget when talking with
36 * {@link android.appwidget.AppWidgetManager} for updates.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037 */
Patrick Dubroy6569f2c2010-07-12 14:25:18 -070038 int appWidgetId = NO_ID;
39
Michael Jurkaaf442092010-06-10 17:01:57 -070040 ComponentName providerName;
Adam Cohended9f8d2010-11-03 13:25:16 -070041
Patrick Dubroy6569f2c2010-07-12 14:25:18 -070042 // TODO: Are these necessary here?
43 int minWidth = -1;
44 int minHeight = -1;
45
Winson Chung211bac32012-05-15 13:43:57 -070046 private boolean mHasNotifiedInitialWidgetSizeChanged;
47
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -070049 * View that holds this widget after it's been created. This view isn't created
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050 * until Launcher knows it's needed.
51 */
The Android Open Source Project7376fae2009-03-11 12:11:58 -070052 AppWidgetHostView hostView = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053
Winson Chung11a49372012-04-27 15:12:38 -070054 LauncherAppWidgetInfo(int appWidgetId, ComponentName providerName) {
Patrick Dubroy6569f2c2010-07-12 14:25:18 -070055 itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
Winson Chung11a49372012-04-27 15:12:38 -070056 this.appWidgetId = appWidgetId;
Patrick Dubroy6569f2c2010-07-12 14:25:18 -070057 this.providerName = providerName;
58
59 // Since the widget isn't instantiated yet, we don't know these values. Set them to -1
60 // to indicate that they should be calculated based on the layout and minWidth/minHeight
61 spanX = -1;
62 spanY = -1;
63 }
64
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065 @Override
66 void onAddToDatabase(ContentValues values) {
67 super.onAddToDatabase(values);
The Android Open Source Project7376fae2009-03-11 12:11:58 -070068 values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069 }
70
Winson Chung211bac32012-05-15 13:43:57 -070071 /**
72 * When we bind the widget, we should notify the widget that the size has changed if we have not
73 * done so already (only really for default workspace widgets).
74 */
75 void onBindAppWidget(Launcher launcher) {
Adam Cohenaaa5c212012-10-05 18:14:31 -070076 if (!mHasNotifiedInitialWidgetSizeChanged) {
Winson Chung211bac32012-05-15 13:43:57 -070077 notifyWidgetSizeChanged(launcher);
78 }
79 }
80
81 /**
82 * Trigger an update callback to the widget to notify it that its size has changed.
83 */
84 void notifyWidgetSizeChanged(Launcher launcher) {
85 AppWidgetResizeFrame.updateWidgetSizeRanges(hostView, launcher, spanX, spanY);
86 mHasNotifiedInitialWidgetSizeChanged = true;
87 }
88
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089 @Override
90 public String toString() {
Daniel Sandler8802e962010-05-26 16:28:16 -040091 return "AppWidget(id=" + Integer.toString(appWidgetId) + ")";
The Android Open Source Project31dd5032009-03-03 19:32:27 -080092 }
Joe Onorato9c1289c2009-08-17 11:03:03 -040093
Joe Onorato9c1289c2009-08-17 11:03:03 -040094 @Override
95 void unbind() {
96 super.unbind();
97 hostView = null;
98 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -080099}