The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 19 | import android.appwidget.AppWidgetHostView; |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 21 | import android.content.ContentValues; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | |
| 24 | import com.android.launcher3.compat.UserHandleCompat; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 25 | |
| 26 | /** |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 27 | * Represents a widget (either instantiated or about to be) in the Launcher. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 28 | */ |
Anjali Koppal | 7b168a1 | 2014-03-04 17:16:11 -0800 | [diff] [blame] | 29 | public class LauncherAppWidgetInfo extends ItemInfo { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 31 | public static final int RESTORE_COMPLETED = 0; |
| 32 | |
| 33 | /** |
| 34 | * This is set during the package backup creation. |
| 35 | */ |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 36 | public static final int FLAG_ID_NOT_VALID = 1; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 39 | * Indicates that the provider is not available yet. |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 40 | */ |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 41 | public static final int FLAG_PROVIDER_NOT_READY = 2; |
| 42 | |
| 43 | /** |
| 44 | * Indicates that the widget UI is not yet ready, and user needs to set it up again. |
| 45 | */ |
| 46 | public static final int FLAG_UI_NOT_READY = 4; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 47 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | /** |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 49 | * Indicates that the widget hasn't been instantiated yet. |
| 50 | */ |
| 51 | static final int NO_ID = -1; |
| 52 | |
| 53 | /** |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 54 | * Identifier for this widget when talking with |
| 55 | * {@link android.appwidget.AppWidgetManager} for updates. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 56 | */ |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 57 | int appWidgetId = NO_ID; |
| 58 | |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 59 | ComponentName providerName; |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 60 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 61 | // TODO: Are these necessary here? |
| 62 | int minWidth = -1; |
| 63 | int minHeight = -1; |
| 64 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 65 | /** |
| 66 | * Indicates the restore status of the widget. |
| 67 | */ |
| 68 | int restoreStatus; |
| 69 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame^] | 70 | /** |
| 71 | * Indicates the installation progress of the widget provider |
| 72 | */ |
| 73 | int installProgress; |
| 74 | |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 75 | private boolean mHasNotifiedInitialWidgetSizeChanged; |
| 76 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 77 | /** |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 78 | * View that holds this widget after it's been created. This view isn't created |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 79 | * until Launcher knows it's needed. |
| 80 | */ |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 81 | AppWidgetHostView hostView = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 82 | |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 83 | LauncherAppWidgetInfo(int appWidgetId, ComponentName providerName) { |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 84 | itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET; |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 85 | this.appWidgetId = appWidgetId; |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 86 | this.providerName = providerName; |
| 87 | |
| 88 | // Since the widget isn't instantiated yet, we don't know these values. Set them to -1 |
| 89 | // to indicate that they should be calculated based on the layout and minWidth/minHeight |
| 90 | spanX = -1; |
| 91 | spanY = -1; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 92 | // We only support app widgets on current user. |
| 93 | user = UserHandleCompat.myUserHandle(); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 94 | restoreStatus = RESTORE_COMPLETED; |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 95 | } |
| 96 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 97 | @Override |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 98 | void onAddToDatabase(Context context, ContentValues values) { |
| 99 | super.onAddToDatabase(context, values); |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 100 | values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId); |
Chris Wren | d5e66bf | 2013-09-16 14:02:29 -0400 | [diff] [blame] | 101 | values.put(LauncherSettings.Favorites.APPWIDGET_PROVIDER, providerName.flattenToString()); |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 102 | values.put(LauncherSettings.Favorites.RESTORED, restoreStatus); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 105 | /** |
| 106 | * When we bind the widget, we should notify the widget that the size has changed if we have not |
| 107 | * done so already (only really for default workspace widgets). |
| 108 | */ |
| 109 | void onBindAppWidget(Launcher launcher) { |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 110 | if (!mHasNotifiedInitialWidgetSizeChanged) { |
Winson Chung | 211bac3 | 2012-05-15 13:43:57 -0700 | [diff] [blame] | 111 | notifyWidgetSizeChanged(launcher); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Trigger an update callback to the widget to notify it that its size has changed. |
| 117 | */ |
| 118 | void notifyWidgetSizeChanged(Launcher launcher) { |
| 119 | AppWidgetResizeFrame.updateWidgetSizeRanges(hostView, launcher, spanX, spanY); |
| 120 | mHasNotifiedInitialWidgetSizeChanged = true; |
| 121 | } |
| 122 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 123 | @Override |
| 124 | public String toString() { |
Daniel Sandler | 8802e96 | 2010-05-26 16:28:16 -0400 | [diff] [blame] | 125 | return "AppWidget(id=" + Integer.toString(appWidgetId) + ")"; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 126 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 127 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 128 | @Override |
| 129 | void unbind() { |
| 130 | super.unbind(); |
| 131 | hostView = null; |
| 132 | } |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 133 | |
| 134 | public final boolean isWidgetIdValid() { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 135 | return (restoreStatus & FLAG_ID_NOT_VALID) == 0; |
| 136 | } |
| 137 | |
| 138 | public final boolean hasRestoreFlag(int flag) { |
| 139 | return (restoreStatus & flag) == flag; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 140 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 141 | } |