Java Code Examples for android.appwidget.AppWidgetHostView#setAppWidget()
The following examples show how to use
android.appwidget.AppWidgetHostView#setAppWidget() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Widget.java From LaunchTime with GNU General Public License v3.0 | 6 votes |
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; }
Example 2
Source File: Widget.java From LaunchTime with GNU General Public License v3.0 | 5 votes |
public void updateWidgetId(int oldId, int newId) { AppWidgetProviderInfo provider = mAppWidgetManager.getAppWidgetInfo(newId); AppWidgetHostView w = mLoadedWidgets.get(provider.provider); if (w!=null) { w.setAppWidget(newId, provider); } saveWidgetId(provider.provider, newId); mAppWidgetHost.deleteAppWidgetId(oldId); }
Example 3
Source File: WidgetsDialogFragment.java From HgLauncher with GNU General Public License v3.0 | 5 votes |
/** * Adds a widget to the desktop. * * @param data Intent used to receive the ID of the widget being added. */ private void addWidget(Intent data, int index, boolean newWidget) { int widgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, WIDGET_CONFIG_DEFAULT_CODE); AppWidgetProviderInfo appWidgetInfo = appWidgetManager.getAppWidgetInfo(widgetId); AppWidgetHostView appWidgetHostView = appWidgetHost.createView( requireActivity().getApplicationContext(), widgetId, appWidgetInfo); // Prevents crashing when the widget info can't be found. // https://github.com/Neamar/KISS/commit/f81ae32ef5ff5c8befe0888e6ff818a41d8dedb4 if (appWidgetInfo == null) { removeWidget(appWidgetHostView, widgetId); } else { // Notify widget of the available minimum space. appWidgetHostView.setMinimumHeight(appWidgetInfo.minHeight); appWidgetHostView.setAppWidget(widgetId, appWidgetInfo); if (Utils.sdkIsAround(16)) { appWidgetHostView.updateAppWidgetSize(null, appWidgetInfo.minWidth, appWidgetInfo.minHeight, appWidgetInfo.minWidth, appWidgetInfo.minHeight); } // Remove existing widget if any and then add the new widget. appWidgetContainer.addView(appWidgetHostView, index); // Immediately listens for the widget. appWidgetHost.startListening(); addWidgetActionListener(index); registerForContextMenu(appWidgetContainer.getChildAt(index)); if (newWidget) { // Update our list. widgetsList.add(String.valueOf(widgetId)); // Apply preference changes. PreferenceHelper.updateWidgets(widgetsList); } } }
Example 4
Source File: WidgetsDialogFragment.java From HgLauncher with GNU General Public License v3.0 | 5 votes |
/** * Adds a widget to the desktop. * * @param data Intent used to receive the ID of the widget being added. */ private void addWidget(Intent data, int index, boolean newWidget) { int widgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, WIDGET_CONFIG_DEFAULT_CODE); AppWidgetProviderInfo appWidgetInfo = appWidgetManager.getAppWidgetInfo(widgetId); AppWidgetHostView appWidgetHostView = appWidgetHost.createView( requireActivity().getApplicationContext(), widgetId, appWidgetInfo); // Prevents crashing when the widget info can't be found. // https://github.com/Neamar/KISS/commit/f81ae32ef5ff5c8befe0888e6ff818a41d8dedb4 if (appWidgetInfo == null) { removeWidget(appWidgetHostView, widgetId); } else { // Notify widget of the available minimum space. appWidgetHostView.setMinimumHeight(appWidgetInfo.minHeight); appWidgetHostView.setAppWidget(widgetId, appWidgetInfo); if (Utils.sdkIsAround(16)) { appWidgetHostView.updateAppWidgetSize(null, appWidgetInfo.minWidth, appWidgetInfo.minHeight, appWidgetInfo.minWidth, appWidgetInfo.minHeight); } // Remove existing widget if any and then add the new widget. appWidgetContainer.addView(appWidgetHostView, index); // Immediately listens for the widget. appWidgetHost.startListening(); addWidgetActionListener(index); registerForContextMenu(appWidgetContainer.getChildAt(index)); if (newWidget) { // Update our list. widgetsList.add(String.valueOf(widgetId)); // Apply preference changes. PreferenceHelper.updateWidgets(widgetsList); } } }
Example 5
Source File: Widget.java From LaunchTime with GNU General Public License v3.0 | 4 votes |
private AppWidgetHostView loadWidget(Activity parent, AppWidgetProviderInfo appWidgetInfo) { // Allocate the hosted widget id int appWidgetId = mAppWidgetHost.allocateAppWidgetId(); if (checkBindPermission(parent, appWidgetId, appWidgetInfo)) return null; Log.d(TAG, "Allowed to bind"); Log.d(TAG, "creating widget"); // Create the host view AppWidgetHostView hostView = mAppWidgetHost.createView(mContext, appWidgetId, appWidgetInfo); // Set the desired widget hostView.setAppWidget(appWidgetId, appWidgetInfo); return hostView; }
Example 6
Source File: DashboardController.java From Taskbar with Apache License 2.0 | 4 votes |
private void addWidget(int appWidgetId, int cellId, boolean shouldSave) { AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); final DashboardCell cellLayout = cells.get(cellId); final AppWidgetHostView hostView = mAppWidgetHost.createView(context, appWidgetId, appWidgetInfo); hostView.setAppWidget(appWidgetId, appWidgetInfo); Bundle bundle = new Bundle(); bundle.putInt("cellId", cellId); hostView.setTag(bundle); cellLayout.findViewById(R.id.empty).setVisibility(View.GONE); cellLayout.findViewById(R.id.placeholder).setVisibility(View.GONE); cellLayout.setOnLongClickListener(olcl); cellLayout.setOnGenericMotionListener(ogml); cellLayout.setOnInterceptedLongPressListener(listener); LinearLayout linearLayout = cellLayout.findViewById(R.id.dashboard); linearLayout.addView(hostView); Bundle bundle2 = (Bundle) cellLayout.getTag(); bundle2.putInt("appWidgetId", appWidgetId); cellLayout.setTag(bundle2); widgets.put(cellId, hostView); if(shouldSave) { SharedPreferences pref = U.getSharedPreferences(context); SharedPreferences.Editor editor = pref.edit(); editor.putInt("dashboard_widget_" + cellId, appWidgetId); editor.putString("dashboard_widget_" + cellId + "_provider", appWidgetInfo.provider.flattenToString()); editor.remove("dashboard_widget_" + cellId + "_placeholder"); editor.apply(); } new Handler().post(() -> { ViewGroup.LayoutParams params = hostView.getLayoutParams(); params.width = cellLayout.getWidth(); params.height = cellLayout.getHeight(); hostView.setLayoutParams(params); hostView.updateAppWidgetSize(null, cellLayout.getWidth(), cellLayout.getHeight(), cellLayout.getWidth(), cellLayout.getHeight()); }); }