The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [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 | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 18 | |
Sunny Goyal | 67419a1 | 2017-11-14 16:55:22 -0800 | [diff] [blame] | 19 | import static android.app.Activity.RESULT_CANCELED; |
| 20 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 21 | import android.appwidget.AppWidgetHost; |
| 22 | import android.appwidget.AppWidgetHostView; |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 23 | import android.appwidget.AppWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 24 | import android.appwidget.AppWidgetProviderInfo; |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 25 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 26 | import android.content.Context; |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 27 | import android.content.Intent; |
| 28 | import android.os.Handler; |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 29 | import android.util.SparseArray; |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 30 | import android.widget.Toast; |
| 31 | |
Sunny Goyal | 3e3d759 | 2019-09-11 16:51:50 -0700 | [diff] [blame] | 32 | import com.android.launcher3.model.WidgetsModel; |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 33 | import com.android.launcher3.widget.DeferredAppWidgetHostView; |
| 34 | import com.android.launcher3.widget.LauncherAppWidgetHostView; |
Samuel Fufa | 9151c01 | 2020-02-24 17:06:28 -0800 | [diff] [blame^] | 35 | import com.android.launcher3.widget.PendingAppWidgetHostView; |
Pinyao Ting | c7a6c29 | 2019-08-26 14:36:02 -0700 | [diff] [blame] | 36 | import com.android.launcher3.widget.custom.CustomWidgetManager; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 37 | |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 38 | import java.util.ArrayList; |
Samuel Fufa | 44043ec | 2019-08-26 15:00:30 -0700 | [diff] [blame] | 39 | import java.util.function.IntConsumer; |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 40 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 41 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 42 | /** |
| 43 | * Specific {@link AppWidgetHost} that creates our {@link LauncherAppWidgetHostView} |
| 44 | * which correctly captures all long-press events. This ensures that users can |
| 45 | * always pick up and move widgets. |
| 46 | */ |
| 47 | public class LauncherAppWidgetHost extends AppWidgetHost { |
Winson Chung | a3f78e3 | 2012-06-14 11:59:51 -0700 | [diff] [blame] | 48 | |
Sunny Goyal | 67419a1 | 2017-11-14 16:55:22 -0800 | [diff] [blame] | 49 | private static final int FLAG_LISTENING = 1; |
| 50 | private static final int FLAG_RESUMED = 1 << 1; |
| 51 | private static final int FLAG_LISTEN_IF_RESUMED = 1 << 2; |
| 52 | |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 53 | public static final int APPWIDGET_HOST_ID = 1024; |
| 54 | |
| 55 | private final ArrayList<ProviderChangedListener> mProviderChangeListeners = new ArrayList<>(); |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 56 | private final SparseArray<LauncherAppWidgetHostView> mViews = new SparseArray<>(); |
Samuel Fufa | 9151c01 | 2020-02-24 17:06:28 -0800 | [diff] [blame^] | 57 | private final SparseArray<PendingAppWidgetHostView> mPendingViews = new SparseArray<>(); |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 58 | |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 59 | private final Context mContext; |
Sunny Goyal | 67419a1 | 2017-11-14 16:55:22 -0800 | [diff] [blame] | 60 | private int mFlags = FLAG_RESUMED; |
Winson Chung | a3f78e3 | 2012-06-14 11:59:51 -0700 | [diff] [blame] | 61 | |
Samuel Fufa | 44043ec | 2019-08-26 15:00:30 -0700 | [diff] [blame] | 62 | private IntConsumer mAppWidgetRemovedCallback = null; |
| 63 | |
Samuel Fufa | 9151c01 | 2020-02-24 17:06:28 -0800 | [diff] [blame^] | 64 | |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 65 | public LauncherAppWidgetHost(Context context) { |
Samuel Fufa | 44043ec | 2019-08-26 15:00:30 -0700 | [diff] [blame] | 66 | this(context, null); |
| 67 | } |
| 68 | |
| 69 | public LauncherAppWidgetHost(Context context, |
| 70 | IntConsumer appWidgetRemovedCallback) { |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 71 | super(context, APPWIDGET_HOST_ID); |
| 72 | mContext = context; |
Samuel Fufa | 44043ec | 2019-08-26 15:00:30 -0700 | [diff] [blame] | 73 | mAppWidgetRemovedCallback = appWidgetRemovedCallback; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 74 | } |
Adam Cohen | 9415d87 | 2010-09-13 14:49:43 -0700 | [diff] [blame] | 75 | |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 76 | @Override |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 77 | protected LauncherAppWidgetHostView onCreateView(Context context, int appWidgetId, |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 78 | AppWidgetProviderInfo appWidget) { |
Samuel Fufa | 9151c01 | 2020-02-24 17:06:28 -0800 | [diff] [blame^] | 79 | final LauncherAppWidgetHostView view; |
| 80 | if (mPendingViews.get(appWidgetId) != null) { |
| 81 | view = mPendingViews.get(appWidgetId); |
| 82 | mPendingViews.remove(appWidgetId); |
| 83 | } else { |
| 84 | view = new LauncherAppWidgetHostView(context); |
| 85 | } |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 86 | mViews.put(appWidgetId, view); |
| 87 | return view; |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 88 | } |
Patrick Dubroy | 2313eff | 2011-01-11 20:01:31 -0800 | [diff] [blame] | 89 | |
| 90 | @Override |
Adam Cohen | 084c318 | 2014-06-16 15:22:56 -0700 | [diff] [blame] | 91 | public void startListening() { |
Sunny Goyal | 3e3d759 | 2019-09-11 16:51:50 -0700 | [diff] [blame] | 92 | if (WidgetsModel.GO_DISABLE_WIDGETS) { |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 93 | return; |
| 94 | } |
Sunny Goyal | 67419a1 | 2017-11-14 16:55:22 -0800 | [diff] [blame] | 95 | mFlags |= FLAG_LISTENING; |
Adam Cohen | 084c318 | 2014-06-16 15:22:56 -0700 | [diff] [blame] | 96 | try { |
| 97 | super.startListening(); |
| 98 | } catch (Exception e) { |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 99 | if (!Utilities.isBinderSizeError(e)) { |
Adam Cohen | 084c318 | 2014-06-16 15:22:56 -0700 | [diff] [blame] | 100 | throw new RuntimeException(e); |
| 101 | } |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 102 | // We're willing to let this slide. The exception is being caused by the list of |
| 103 | // RemoteViews which is being passed back. The startListening relationship will |
| 104 | // have been established by this point, and we will end up populating the |
| 105 | // widgets upon bind anyway. See issue 14255011 for more context. |
Adam Cohen | 084c318 | 2014-06-16 15:22:56 -0700 | [diff] [blame] | 106 | } |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 107 | |
| 108 | // We go in reverse order and inflate any deferred widget |
| 109 | for (int i = mViews.size() - 1; i >= 0; i--) { |
| 110 | LauncherAppWidgetHostView view = mViews.valueAt(i); |
| 111 | if (view instanceof DeferredAppWidgetHostView) { |
| 112 | view.reInflate(); |
| 113 | } |
| 114 | } |
Adam Cohen | 084c318 | 2014-06-16 15:22:56 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 117 | @Override |
| 118 | public void stopListening() { |
Sunny Goyal | 3e3d759 | 2019-09-11 16:51:50 -0700 | [diff] [blame] | 119 | if (WidgetsModel.GO_DISABLE_WIDGETS) { |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 120 | return; |
| 121 | } |
Sunny Goyal | 67419a1 | 2017-11-14 16:55:22 -0800 | [diff] [blame] | 122 | mFlags &= ~FLAG_LISTENING; |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 123 | super.stopListening(); |
| 124 | } |
| 125 | |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 126 | public boolean isListening() { |
| 127 | return (mFlags & FLAG_LISTENING) != 0; |
| 128 | } |
| 129 | |
Sunny Goyal | 67419a1 | 2017-11-14 16:55:22 -0800 | [diff] [blame] | 130 | /** |
| 131 | * Updates the resumed state of the host. |
| 132 | * When a host is not resumed, it defers calls to startListening until host is resumed again. |
| 133 | * But if the host was already listening, it will not call stopListening. |
| 134 | * |
| 135 | * @see #setListenIfResumed(boolean) |
| 136 | */ |
| 137 | public void setResumed(boolean isResumed) { |
| 138 | if (isResumed == ((mFlags & FLAG_RESUMED) != 0)) { |
| 139 | return; |
| 140 | } |
| 141 | if (isResumed) { |
| 142 | mFlags |= FLAG_RESUMED; |
| 143 | // Start listening if we were supposed to start listening on resume |
| 144 | if ((mFlags & FLAG_LISTEN_IF_RESUMED) != 0 && (mFlags & FLAG_LISTENING) == 0) { |
| 145 | startListening(); |
| 146 | } |
| 147 | } else { |
| 148 | mFlags &= ~FLAG_RESUMED; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Updates the listening state of the host. If the host is not resumed, startListening is |
| 154 | * deferred until next resume. |
| 155 | * |
| 156 | * @see #setResumed(boolean) |
| 157 | */ |
| 158 | public void setListenIfResumed(boolean listenIfResumed) { |
Sunny Goyal | 67419a1 | 2017-11-14 16:55:22 -0800 | [diff] [blame] | 159 | if (listenIfResumed == ((mFlags & FLAG_LISTEN_IF_RESUMED) != 0)) { |
| 160 | return; |
| 161 | } |
| 162 | if (listenIfResumed) { |
| 163 | mFlags |= FLAG_LISTEN_IF_RESUMED; |
| 164 | if ((mFlags & FLAG_RESUMED) != 0) { |
| 165 | // If we are resumed, start listening immediately. Note we do not check for |
| 166 | // duplicate calls before calling startListening as startListening is safe to call |
| 167 | // multiple times. |
| 168 | startListening(); |
| 169 | } |
| 170 | } else { |
| 171 | mFlags &= ~FLAG_LISTEN_IF_RESUMED; |
| 172 | stopListening(); |
| 173 | } |
| 174 | } |
| 175 | |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 176 | @Override |
| 177 | public int allocateAppWidgetId() { |
Sunny Goyal | 3e3d759 | 2019-09-11 16:51:50 -0700 | [diff] [blame] | 178 | if (WidgetsModel.GO_DISABLE_WIDGETS) { |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 179 | return AppWidgetManager.INVALID_APPWIDGET_ID; |
| 180 | } |
| 181 | |
| 182 | return super.allocateAppWidgetId(); |
| 183 | } |
| 184 | |
| 185 | public void addProviderChangeListener(ProviderChangedListener callback) { |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 186 | mProviderChangeListeners.add(callback); |
| 187 | } |
| 188 | |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 189 | public void removeProviderChangeListener(ProviderChangedListener callback) { |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 190 | mProviderChangeListeners.remove(callback); |
| 191 | } |
| 192 | |
Winson Chung | a3f78e3 | 2012-06-14 11:59:51 -0700 | [diff] [blame] | 193 | protected void onProvidersChanged() { |
Sunny Goyal | 7e2a360 | 2015-04-20 18:19:25 -0700 | [diff] [blame] | 194 | if (!mProviderChangeListeners.isEmpty()) { |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 195 | for (ProviderChangedListener callback : new ArrayList<>(mProviderChangeListeners)) { |
| 196 | callback.notifyWidgetProvidersChanged(); |
Sunny Goyal | 7e2a360 | 2015-04-20 18:19:25 -0700 | [diff] [blame] | 197 | } |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 198 | } |
Winson Chung | a3f78e3 | 2012-06-14 11:59:51 -0700 | [diff] [blame] | 199 | } |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 200 | |
Samuel Fufa | 9151c01 | 2020-02-24 17:06:28 -0800 | [diff] [blame^] | 201 | void addPendingView(int appWidgetId, PendingAppWidgetHostView view) { |
| 202 | mPendingViews.put(appWidgetId, view); |
| 203 | } |
| 204 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 205 | public AppWidgetHostView createView(Context context, int appWidgetId, |
| 206 | LauncherAppWidgetProviderInfo appWidget) { |
Sunny Goyal | 952e63d | 2017-08-16 04:59:08 -0700 | [diff] [blame] | 207 | if (appWidget.isCustomWidget()) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 208 | LauncherAppWidgetHostView lahv = new LauncherAppWidgetHostView(context); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 209 | lahv.setAppWidget(0, appWidget); |
Pinyao Ting | c7a6c29 | 2019-08-26 14:36:02 -0700 | [diff] [blame] | 210 | CustomWidgetManager.INSTANCE.get(context).onViewCreated(lahv); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 211 | return lahv; |
Sunny Goyal | 29947f0 | 2017-12-18 13:49:44 -0800 | [diff] [blame] | 212 | } else if ((mFlags & FLAG_LISTENING) == 0) { |
| 213 | DeferredAppWidgetHostView view = new DeferredAppWidgetHostView(context); |
| 214 | view.setAppWidget(appWidgetId, appWidget); |
| 215 | mViews.put(appWidgetId, view); |
| 216 | return view; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 217 | } else { |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 218 | try { |
| 219 | return super.createView(context, appWidgetId, appWidget); |
| 220 | } catch (Exception e) { |
| 221 | if (!Utilities.isBinderSizeError(e)) { |
| 222 | throw new RuntimeException(e); |
| 223 | } |
| 224 | |
| 225 | // If the exception was thrown while fetching the remote views, let the view stay. |
| 226 | // This will ensure that if the widget posts a valid update later, the view |
| 227 | // will update. |
| 228 | LauncherAppWidgetHostView view = mViews.get(appWidgetId); |
| 229 | if (view == null) { |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 230 | view = onCreateView(mContext, appWidgetId, appWidget); |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 231 | } |
| 232 | view.setAppWidget(appWidgetId, appWidget); |
| 233 | view.switchToErrorView(); |
Samuel Fufa | 44043ec | 2019-08-26 15:00:30 -0700 | [diff] [blame] | 234 | return view; |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 235 | } |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Called when the AppWidget provider for a AppWidget has been upgraded to a new apk. |
| 241 | */ |
| 242 | @Override |
| 243 | protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidget) { |
| 244 | LauncherAppWidgetProviderInfo info = LauncherAppWidgetProviderInfo.fromProviderInfo( |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 245 | mContext, appWidget); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 246 | super.onProviderChanged(appWidgetId, info); |
Sunny Goyal | ec88204 | 2015-10-05 10:36:54 -0700 | [diff] [blame] | 247 | // The super method updates the dimensions of the providerInfo. Update the |
| 248 | // launcher spans accordingly. |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 249 | info.initSpans(mContext); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 250 | } |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 251 | |
Samuel Fufa | 791ed47 | 2019-09-19 10:10:34 -0700 | [diff] [blame] | 252 | /** |
| 253 | * Called on an appWidget is removed for a widgetId |
Samuel Fufa | 9151c01 | 2020-02-24 17:06:28 -0800 | [diff] [blame^] | 254 | * |
| 255 | * @param appWidgetId TODO: make this override when SDK is updated |
Samuel Fufa | 791ed47 | 2019-09-19 10:10:34 -0700 | [diff] [blame] | 256 | */ |
| 257 | public void onAppWidgetRemoved(int appWidgetId) { |
Samuel Fufa | 44043ec | 2019-08-26 15:00:30 -0700 | [diff] [blame] | 258 | if (mAppWidgetRemovedCallback == null) { |
| 259 | return; |
| 260 | } |
| 261 | mAppWidgetRemovedCallback.accept(appWidgetId); |
| 262 | } |
| 263 | |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 264 | @Override |
| 265 | public void deleteAppWidgetId(int appWidgetId) { |
| 266 | super.deleteAppWidgetId(appWidgetId); |
| 267 | mViews.remove(appWidgetId); |
| 268 | } |
| 269 | |
| 270 | @Override |
Sunny Goyal | c11fac3 | 2018-02-27 19:20:15 -0800 | [diff] [blame] | 271 | public void clearViews() { |
Sunny Goyal | 712ee53 | 2016-11-04 10:19:58 -0700 | [diff] [blame] | 272 | super.clearViews(); |
| 273 | mViews.clear(); |
| 274 | } |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 275 | |
| 276 | public void startBindFlow(BaseActivity activity, |
| 277 | int appWidgetId, AppWidgetProviderInfo info, int requestCode) { |
| 278 | |
Sunny Goyal | 3e3d759 | 2019-09-11 16:51:50 -0700 | [diff] [blame] | 279 | if (WidgetsModel.GO_DISABLE_WIDGETS) { |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 280 | sendActionCancelled(activity, requestCode); |
| 281 | return; |
| 282 | } |
| 283 | |
| 284 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND) |
| 285 | .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) |
| 286 | .putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.provider) |
| 287 | .putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE, info.getProfile()); |
| 288 | // TODO: we need to make sure that this accounts for the options bundle. |
| 289 | // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); |
| 290 | activity.startActivityForResult(intent, requestCode); |
| 291 | } |
| 292 | |
| 293 | |
| 294 | public void startConfigActivity(BaseActivity activity, int widgetId, int requestCode) { |
Sunny Goyal | 3e3d759 | 2019-09-11 16:51:50 -0700 | [diff] [blame] | 295 | if (WidgetsModel.GO_DISABLE_WIDGETS) { |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 296 | sendActionCancelled(activity, requestCode); |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | try { |
| 301 | startAppWidgetConfigureActivityForResult(activity, widgetId, 0, requestCode, null); |
| 302 | } catch (ActivityNotFoundException | SecurityException e) { |
| 303 | Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 304 | sendActionCancelled(activity, requestCode); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | private void sendActionCancelled(final BaseActivity activity, final int requestCode) { |
Sunny Goyal | 67419a1 | 2017-11-14 16:55:22 -0800 | [diff] [blame] | 309 | new Handler().post(() -> activity.onActivityResult(requestCode, RESULT_CANCELED, null)); |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Listener for getting notifications on provider changes. |
| 314 | */ |
| 315 | public interface ProviderChangedListener { |
| 316 | |
| 317 | void notifyWidgetProvidersChanged(); |
| 318 | } |
The Android Open Source Project | 7376fae | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 319 | } |