@Test public void createView_shouldSetViewsAppWidgetId() throws Exception { AppWidgetHostView hostView = appWidgetHost.createView(context, 765, null); assertThat(hostView.getAppWidgetId()).isEqualTo(765); }
@Test public void shouldKnowItsWidgetId() throws Exception { appWidgetHostView.setAppWidget(789, null); assertThat(appWidgetHostView.getAppWidgetId()).isEqualTo(789); }
/** * Removes a single widget and deletes it from persistent prefs * * @param hostView instance of a displayed widget */ private void removeAppWidget(AppWidgetHostView hostView) { // remove widget from view int appWidgetId = hostView.getAppWidgetId(); mAppWidgetHost.deleteAppWidgetId(appWidgetId); widgetArea.removeView(hostView); // remove widget id from persistent prefs SharedPreferences.Editor widgetPrefsEditor = widgetPrefs.edit(); widgetPrefsEditor.remove(String.valueOf(appWidgetId)); widgetPrefsEditor.apply(); // only one widget allowed so widgetUsed is false now widgetUsed = false; }
public void saveLoadedWidget(ComponentName cn, AppWidgetHostView hostView) { saveWidgetId(cn, hostView.getAppWidgetId()); mLoadedWidgets.put(cn, hostView); }
private AppWidgetHostView createWidgetFromId(int widget_id) { AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widget_id); if (appWidgetInfo==null) { return null; } // if (checkBindPermission(widget_id, appWidgetInfo.provider)) return null; AppWidgetHostView hostView = getLoadedAppWidgetHostView(appWidgetInfo.provider); if (hostView==null || hostView.getAppWidgetId()!=widget_id) { // Create the host view hostView = mAppWidgetHost.createView(mContext, widget_id, appWidgetInfo); hostView.setAppWidget(widget_id, appWidgetInfo); } return hostView; }
@Override public void onDragEnd() { // Cleanup up preloading state. mLauncher.getDragController().removeDragListener(this); mHandler.removeCallbacks(mBindWidgetRunnable); mHandler.removeCallbacks(mInflateWidgetRunnable); // Cleanup widget id if (mWidgetLoadingId != -1) { mLauncher.getAppWidgetHost().deleteAppWidgetId(mWidgetLoadingId); mWidgetLoadingId = -1; } // The widget was inflated and added to the DragLayer -- remove it. if (mInfo.boundWidget != null) { mLauncher.getDragLayer().removeView(mInfo.boundWidget); mLauncher.getAppWidgetHost().deleteAppWidgetId(mInfo.boundWidget.getAppWidgetId()); mInfo.boundWidget = null; } }
@Override public void onDragEnd() { // Cleanup up preloading state. mLauncher.getDragController().removeDragListener(this); mHandler.removeCallbacks(mBindWidgetRunnable); mHandler.removeCallbacks(mInflateWidgetRunnable); // Cleanup widget id if (mWidgetLoadingId != -1) { mLauncher.getAppWidgetHost().deleteAppWidgetId(mWidgetLoadingId); mWidgetLoadingId = -1; } // The widget was inflated and added to the DragLayer -- remove it. if (mInfo.boundWidget != null) { mLauncher.getDragLayer().removeView(mInfo.boundWidget); mLauncher.getAppWidgetHost().deleteAppWidgetId(mInfo.boundWidget.getAppWidgetId()); mInfo.boundWidget = null; } }
@Override public void onDragEnd() { if (LOGD) { Log.d(TAG, "Cleaning up in onDragEnd()..."); } // Cleanup up preloading state. mLauncher.getDragController().removeDragListener(this); mHandler.removeCallbacks(mBindWidgetRunnable); mHandler.removeCallbacks(mInflateWidgetRunnable); // Cleanup widget id if (mWidgetLoadingId != -1) { mLauncher.getAppWidgetHost().deleteAppWidgetId(mWidgetLoadingId); mWidgetLoadingId = -1; } // The widget was inflated and added to the DragLayer -- remove it. if (mInfo.boundWidget != null) { if (LOGD) { Log.d(TAG, "...removing widget from drag layer"); } mLauncher.getDragLayer().removeView(mInfo.boundWidget); mLauncher.getAppWidgetHost().deleteAppWidgetId(mInfo.boundWidget.getAppWidgetId()); mInfo.boundWidget = null; } }
@Override public void onDragEnd() { if (LOGD) { Log.d(TAG, "Cleaning up in onDragEnd()..."); } // Cleanup up preloading state. mLauncher.getDragController().removeDragListener(this); mHandler.removeCallbacks(mBindWidgetRunnable); mHandler.removeCallbacks(mInflateWidgetRunnable); // Cleanup widget id if (mWidgetLoadingId != -1) { mLauncher.getAppWidgetHost().deleteAppWidgetId(mWidgetLoadingId); mWidgetLoadingId = -1; } // The widget was inflated and added to the DragLayer -- remove it. if (mInfo.boundWidget != null) { if (LOGD) { Log.d(TAG, "...removing widget from drag layer"); } mLauncher.getDragLayer().removeView(mInfo.boundWidget); mLauncher.getAppWidgetHost().deleteAppWidgetId(mInfo.boundWidget.getAppWidgetId()); mInfo.boundWidget = null; } }
int appWidgetId; if (hostView != null) { appWidgetId = hostView.getAppWidgetId(); addAppWidgetImpl(appWidgetId, info, hostView, info.info); } else {
int appWidgetId; if (hostView != null) { appWidgetId = hostView.getAppWidgetId(); addAppWidgetImpl(appWidgetId, info, hostView, info.info);
appWidgetId = hostView.getAppWidgetId(); addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
appWidgetId = hostView.getAppWidgetId(); addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);
/** * Process a widget drop. */ private void addAppWidgetFromDrop(PendingAddWidgetInfo info) { AppWidgetHostView hostView = info.boundWidget; int appWidgetId; WidgetAddFlowHandler addFlowHandler = info.getHandler(); if (hostView != null) { // In the case where we've prebound the widget, we remove it from the DragLayer getDragLayer().removeView(hostView); appWidgetId = hostView.getAppWidgetId(); addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler); // Clear the boundWidget so that it doesn't get destroyed. info.boundWidget = null; } else { // In this case, we either need to start an activity to get permission to bind // the widget, or we need to start an activity to configure the widget, or both. appWidgetId = getAppWidgetHost().allocateAppWidgetId(); Bundle options = info.bindOptions; boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed( appWidgetId, info.info, options); if (success) { addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler); } else { addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET); } } }