android.appwidget.AppWidgetProviderInfo Java Examples
The following examples show how to use
android.appwidget.AppWidgetProviderInfo.
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: SearchWidgetProvider.java From LaunchEnr with GNU General Public License v3.0 | 6 votes |
/** * - * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX} * - * provided by the same package which is set to be global search activity. * - * If widgetCategory is not supported, or no such widget is found, returns the first widget * - * provided by the package. * - */ public static AppWidgetProviderInfo get(Context context) { SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); ComponentName searchComponent = searchManager.getGlobalSearchActivity(); if (searchComponent == null) return null; String providerPkg = searchComponent.getPackageName(); AppWidgetProviderInfo defaultWidgetForSearchPackage = null; AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) { if (info.provider.getPackageName().equals(providerPkg) && info.configure == null) { if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) { return info; } else if (defaultWidgetForSearchPackage == null) { defaultWidgetForSearchPackage = info; } } } return defaultWidgetForSearchPackage; }
Example #2
Source File: Widget.java From LaunchTime with GNU General Public License v3.0 | 6 votes |
public Widget(Context context) { mContext = context; mPrefs = context.getSharedPreferences("widgets", Context.MODE_PRIVATE); setupHost(context); //mAppWidgetHost.deleteHost(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { for (int oid: mAppWidgetHost.getAppWidgetIds()) { AppWidgetProviderInfo provider = mAppWidgetManager.getAppWidgetInfo(oid); if (provider==null) continue; Log.d(TAG, "Widget is allocated: " + provider.provider); } } }
Example #3
Source File: ManageCrossProfileWidgetProviderUtil.java From android-testdpc with Apache License 2.0 | 6 votes |
/** * Gets a list of work profile apps that have disabled cross-profile widget providers. * * @return A list of package names which have disabled cross-profile widget providers. */ public List<String> getDisabledCrossProfileWidgetProvidersList() { Set<String> enabledCrossProfileWidgetProvidersList = new HashSet<String>( mDevicePolicyManager.getCrossProfileWidgetProviders( DeviceAdminReceiver.getComponentName(mContext))); // Cross-profile widgets are enabled by their package name. Use set to avoid duplicates. Set<String> disabledCrossProfileWidgetProvidersPackageNameSet = new HashSet<String>(); List<AppWidgetProviderInfo> appWidgetProviderInfoList = mAppWidgetManager .getInstalledProviders(); for (AppWidgetProviderInfo appWidgetProviderInfo : appWidgetProviderInfoList) { String appWidgetProviderPackage = appWidgetProviderInfo.provider.getPackageName(); if (!enabledCrossProfileWidgetProvidersList.contains(appWidgetProviderPackage)) { disabledCrossProfileWidgetProvidersPackageNameSet.add(appWidgetProviderPackage); } } return new ArrayList<String>(disabledCrossProfileWidgetProvidersPackageNameSet); }
Example #4
Source File: LauncherAppWidgetProviderInfo.java From LaunchEnr with GNU General Public License v3.0 | 6 votes |
public static LauncherAppWidgetProviderInfo fromProviderInfo(Context context, AppWidgetProviderInfo info) { final LauncherAppWidgetProviderInfo launcherInfo; if (info instanceof LauncherAppWidgetProviderInfo) { launcherInfo = (LauncherAppWidgetProviderInfo) info; } else { // In lieu of a public super copy constructor, we first write the AppWidgetProviderInfo // into a parcel, and then construct a new LauncherAppWidgetProvider info from the // associated super parcel constructor. This allows us to copy non-public members without // using reflection. Parcel p = Parcel.obtain(); info.writeToParcel(p, 0); p.setDataPosition(0); launcherInfo = new LauncherAppWidgetProviderInfo(p); p.recycle(); } launcherInfo.initSpans(context); return launcherInfo; }
Example #5
Source File: Widget.java From LaunchTime with GNU General Public License v3.0 | 6 votes |
public List<AppWidgetProviderInfo> getWidgetsForPackage(String packageName) { List<AppWidgetProviderInfo> provs; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { UserHandle user = UserHandle.getUserHandleForUid(Process.myUid()); provs = mAppWidgetManager.getInstalledProvidersForPackage(packageName, user); } else { provs = new ArrayList<>(); for (AppWidgetProviderInfo prov: mAppWidgetManager.getInstalledProviders()) { if (prov.provider.getPackageName().equals(packageName)) { provs.add(prov); } } } return provs; }
Example #6
Source File: AppWidgetResizeFrame.java From Trebuchet with GNU General Public License v3.0 | 6 votes |
public boolean beginResizeIfPointInRegion(int x, int y) { boolean horizontalActive = (mResizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0; boolean verticalActive = (mResizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0; mLeftBorderActive = (x < mTouchTargetWidth) && horizontalActive; mRightBorderActive = (x > getWidth() - mTouchTargetWidth) && horizontalActive; mTopBorderActive = (y < mTouchTargetWidth + mTopTouchRegionAdjustment) && verticalActive; mBottomBorderActive = (y > getHeight() - mTouchTargetWidth + mBottomTouchRegionAdjustment) && verticalActive; boolean anyBordersActive = mLeftBorderActive || mRightBorderActive || mTopBorderActive || mBottomBorderActive; mBaselineWidth = getMeasuredWidth(); mBaselineHeight = getMeasuredHeight(); mBaselineX = getLeft(); mBaselineY = getTop(); if (anyBordersActive) { mLeftHandle.setAlpha(mLeftBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA); mRightHandle.setAlpha(mRightBorderActive ? 1.0f :DIMMED_HANDLE_ALPHA); mTopHandle.setAlpha(mTopBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA); mBottomHandle.setAlpha(mBottomBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA); } return anyBordersActive; }
Example #7
Source File: PagedViewWidget.java From TurboLauncher with Apache License 2.0 | 6 votes |
public void applyFromAppWidgetProviderInfo(AppWidgetProviderInfo info, int maxWidth, int[] cellSpan, WidgetPreviewLoader loader) { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); mIsAppWidget = true; mInfo = info; final ImageView image = (ImageView) findViewById(R.id.widget_preview); if (maxWidth > -1) { image.setMaxWidth(maxWidth); } final TextView name = (TextView) findViewById(R.id.widget_name); name.setText(info.label); final TextView dims = (TextView) findViewById(R.id.widget_dims); if (dims != null) { int hSpan = Math.min(cellSpan[0], (int) grid.numColumns); int vSpan = Math.min(cellSpan[1], (int) grid.numRows); dims.setText(String.format(mDimensionsFormatString, hSpan, vSpan)); } mWidgetPreviewLoader = loader; }
Example #8
Source File: Launcher.java From TurboLauncher with Apache License 2.0 | 5 votes |
void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); if (v instanceof Advanceable) { mWidgetsToAdvance.put(hostView, appWidgetInfo); ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); updateRunning(); } }
Example #9
Source File: SuntimesWidgetListActivity.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
public static WidgetListItem createWidgetListItem(Context context, int appWidgetId, AppWidgetManager widgetManager, SuntimesData data, String widgetTitle, String type) throws ClassNotFoundException { AppWidgetProviderInfo info = widgetManager.getAppWidgetInfo(appWidgetId); String title = context.getString(R.string.configLabel_widgetList_itemTitle, widgetTitle); String source = ((data.calculatorMode() == null) ? "def" : data.calculatorMode().getName()); String summary = context.getString(R.string.configLabel_widgetList_itemSummaryPattern, type, source); return new WidgetListItem(appWidgetId, info.icon, title, summary, Class.forName(info.configure.getClassName()) ); }
Example #10
Source File: AppWidgetManagerCompatV16.java From LB-Launcher with Apache License 2.0 | 5 votes |
@Override public boolean bindAppWidgetIdIfAllowed(int appWidgetId, AppWidgetProviderInfo info, Bundle options) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { return mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.provider); } else { return mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.provider, options); } }
Example #11
Source File: LauncherModel.java From TurboLauncher with Apache License 2.0 | 5 votes |
public static final Comparator<AppWidgetProviderInfo> getWidgetNameComparator() { final Collator collator = Collator.getInstance(); return new Comparator<AppWidgetProviderInfo>() { public final int compare(AppWidgetProviderInfo a, AppWidgetProviderInfo b) { return collator.compare(a.label.toString().trim(), b.label .toString().trim()); } }; }
Example #12
Source File: TrackWidgetProvider.java From mytracks with Apache License 2.0 | 5 votes |
@TargetApi(16) @Override public void onAppWidgetOptionsChanged( Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) { super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions); if (newOptions != null) { int newSize; if (newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1) == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) { newSize = 1; } else { int height = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT); if (height == 0) { newSize = 2; } else if (height >= FOUR_CELLS) { newSize = 4; } else if (height >= THREE_CELLS) { newSize = 3; } else if (height >= TWO_CELLS) { newSize = 2; } else { newSize = 1; } } int size = ApiAdapterFactory.getApiAdapter().getAppWidgetSize(appWidgetManager, appWidgetId); if (size != newSize) { ApiAdapterFactory.getApiAdapter().setAppWidgetSize(appWidgetManager, appWidgetId, newSize); updateAppWidget(context, appWidgetManager, appWidgetId, -1L); } } }
Example #13
Source File: WidgetPreviewLoader.java From LB-Launcher with Apache License 2.0 | 5 votes |
public Bitmap generateWidgetPreview(AppWidgetProviderInfo info, Bitmap preview) { int[] cellSpans = Launcher.getSpanForWidget(mContext, info); int maxWidth = maxWidthForWidgetPreview(cellSpans[0]); int maxHeight = maxHeightForWidgetPreview(cellSpans[1]); return generateWidgetPreview(info, cellSpans[0], cellSpans[1], maxWidth, maxHeight, preview, null); }
Example #14
Source File: Widget.java From LaunchTime with GNU General Public License v3.0 | 5 votes |
public AppWidgetHostView onActivityResult(Activity parent, int requestCode, int resultCode, Intent data) { Log.d(TAG, "onActivityResult: requestCode=" + requestCode + " resultCode=" + resultCode); // listen for widget manager response if (resultCode == Activity.RESULT_OK) { if (requestCode == REQUEST_PICK_APPWIDGET) { Log.d(TAG, "configureWidget"); return configureWidget(parent, data); } else if (requestCode == REQUEST_CREATE_APPWIDGET || requestCode == REQUEST_BIND_APPWIDGET) { Log.d(TAG, "createWidget"); return createWidget(data); } else { Log.d(TAG, "unknown RESULT_OK"); } } else if (resultCode == Activity.RESULT_CANCELED) { Log.d(TAG, "RESULT_CANCELED"); if (data!=null) { int appWidgetId = getAppWidgetIdFromIntent(data); AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); if (appWidgetId != -1) { if (appWidgetInfo==null || getWidgetId(appWidgetInfo.provider)==-1) { mAppWidgetHost.deleteAppWidgetId(appWidgetId); } } } } return null; }
Example #15
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 #16
Source File: InstallWidgetReceiver.java From TurboLauncher with Apache License 2.0 | 5 votes |
@Override public void onClick(DialogInterface dialog, int which) { final AppWidgetProviderInfo widgetInfo = mActivities.get(which).widgetInfo; final PendingAddWidgetInfo createInfo = new PendingAddWidgetInfo(widgetInfo, mMimeType, mClipData); mLauncher.addAppWidgetFromDrop(createInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP, mTargetLayoutScreen, null, null, mTargetLayoutPos); }
Example #17
Source File: HostWidget.java From AcDisplay with GNU General Public License v2.0 | 5 votes |
private void updateAppWidgetViewIfNeeded() { if (!isStarted() || !isViewAttached()) return; int id = getConfig().getCustomWidgetId(); if (!AppWidgetUtils.isValidId(id)) { if (mHostView != null) { ViewUtils.removeViewParent(mHostView); mEmptyView.setVisibility(View.VISIBLE); mHostViewNeedsReInflate = false; mHostView = null; } return; } Context context = getFragment().getActivity(); if (mHostView == null) { mHostView = new MyAppWidgetHostView(context); updateAppWidgetTouchable(); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL); mHostContainer.addView(mHostView, lp); mEmptyView.setVisibility(View.GONE); } else if (!mHostViewNeedsReInflate && mHostView.getAppWidgetId() == id) return; AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(id); mAppWidgetHost.updateView(context, id, appWidget, mHostView); mHostViewNeedsReInflate = false; updateAppWidgetFrameSize(); }
Example #18
Source File: DashboardController.java From Taskbar with Apache License 2.0 | 5 votes |
private void addPlaceholder(int cellId) { FrameLayout placeholder = cells.get(cellId).findViewById(R.id.placeholder); SharedPreferences pref = U.getSharedPreferences(context); String providerName = pref.getString("dashboard_widget_" + cellId + "_provider", "null"); if(!providerName.equals("null")) { ImageView imageView = placeholder.findViewById(R.id.placeholder_image); ComponentName componentName = ComponentName.unflattenFromString(providerName); List<AppWidgetProviderInfo> providerInfoList = mAppWidgetManager.getInstalledProvidersForProfile(Process.myUserHandle()); for(AppWidgetProviderInfo info : providerInfoList) { if(info.provider.equals(componentName)) { Drawable drawable = info.loadPreviewImage(context, -1); if(drawable == null) drawable = info.loadIcon(context, -1); ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(0); imageView.setImageDrawable(drawable); imageView.setColorFilter(new ColorMatrixColorFilter(matrix)); break; } } } placeholder.setVisibility(View.VISIBLE); }
Example #19
Source File: MyAppWidgetHost.java From AcDisplay with GNU General Public License v2.0 | 5 votes |
/** * Create the AppWidgetHostView for the given widget. * The AppWidgetHost retains a pointer to the newly-created View. */ @NonNull public final AppWidgetHostView updateView(@NonNull Context context, int appWidgetId, @NonNull AppWidgetProviderInfo appWidget, @Nullable AppWidgetHostView view) { mTempView = view; view = createView(context, appWidgetId, appWidget); mTempView = null; return view; }
Example #20
Source File: Launcher.java From TurboLauncher with Apache License 2.0 | 5 votes |
/** * Add the views for a widget to the workspace. * * Implementation of the method from LauncherModel.Callbacks. */ public void bindAppWidget(final LauncherAppWidgetInfo item) { Runnable r = new Runnable() { public void run() { bindAppWidget(item); } }; if (waitUntilResume(r)) { return; } final Workspace workspace = mWorkspace; final int appWidgetId = item.appWidgetId; final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager .getAppWidgetInfo(appWidgetId); item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); item.hostView.setTag(item); item.onBindAppWidget(this); workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX, item.cellY, item.spanX, item.spanY, false); addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); workspace.requestLayout(); }
Example #21
Source File: Widget.java From LaunchTime with GNU General Public License v3.0 | 5 votes |
public ComponentName getComponentNameFromIntent(Intent data) { if (data!=null) { int appWidgetId = getAppWidgetIdFromIntent(data); if (appWidgetId != -1) { AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); if (appWidgetInfo != null) { return appWidgetInfo.provider; } } } return null; }
Example #22
Source File: AppWidgetManagerCompatVL.java From LB-Launcher with Apache License 2.0 | 5 votes |
@Override public List<AppWidgetProviderInfo> getAllProviders() { ArrayList<AppWidgetProviderInfo> providers = new ArrayList<AppWidgetProviderInfo>(); for (UserHandle user : mUserManager.getUserProfiles()) { providers.addAll(mAppWidgetManager.getInstalledProvidersForProfile(user)); } return providers; }
Example #23
Source File: LauncherBackupHelper.java From TurboLauncher with Apache License 2.0 | 5 votes |
private AppWidgetProviderInfo findAppWidgetProviderInfo(ComponentName component) { if (mWidgetMap == null) { List<AppWidgetProviderInfo> widgets = AppWidgetManager.getInstance(mContext).getInstalledProviders(); mWidgetMap = new HashMap<ComponentName, AppWidgetProviderInfo>(widgets.size()); for (AppWidgetProviderInfo info : widgets) { mWidgetMap.put(info.provider, info); } } return mWidgetMap.get(component); }
Example #24
Source File: LauncherModel.java From TurboLauncher with Apache License 2.0 | 5 votes |
/** * Attempts to find an AppWidgetProviderInfo that matches the given * component. */ AppWidgetProviderInfo findAppWidgetProviderInfoWithComponent( Context context, ComponentName component) { List<AppWidgetProviderInfo> widgets = AppWidgetManager.getInstance( context).getInstalledProviders(); for (AppWidgetProviderInfo info : widgets) { if (info.provider.equals(component)) { return info; } } return null; }
Example #25
Source File: WidgetPreviewLoader.java From LB-Launcher with Apache License 2.0 | 5 votes |
private String getObjectPackage(Object o) { if (o instanceof AppWidgetProviderInfo) { return ((AppWidgetProviderInfo) o).provider.getPackageName(); } else { ResolveInfo info = (ResolveInfo) o; return info.activityInfo.packageName; } }
Example #26
Source File: LauncherProvider.java From TurboLauncher with Apache License 2.0 | 5 votes |
/** * Gets an appwidget provider from the given package. If the package contains more than * one appwidget provider, an arbitrary one is returned. */ private ComponentName getProviderInPackage(String packageName) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext); List<AppWidgetProviderInfo> providers = appWidgetManager.getInstalledProviders(); if (providers == null) return null; final int providerCount = providers.size(); for (int i = 0; i < providerCount; i++) { ComponentName provider = providers.get(i).provider; if (provider != null && provider.getPackageName().equals(packageName)) { return provider; } } return null; }
Example #27
Source File: AppsCustomizePagedView.java From TurboLauncher with Apache License 2.0 | 5 votes |
public void onPackagesUpdated(ArrayList<Object> widgetsAndShortcuts) { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); // Get the list of widgets and shortcuts mWidgets.clear(); for (Object o : widgetsAndShortcuts) { if (o instanceof AppWidgetProviderInfo) { AppWidgetProviderInfo widget = (AppWidgetProviderInfo) o; if (!app.shouldShowAppOrWidgetProvider(widget.provider)) { continue; } widget.label = widget.label.trim(); if (widget.minWidth > 0 && widget.minHeight > 0) { // Ensure that all widgets we show can be added on a workspace of this size int[] spanXY = Launcher.getSpanForWidget(mLauncher, widget); int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, widget); int minSpanX = Math.min(spanXY[0], minSpanXY[0]); int minSpanY = Math.min(spanXY[1], minSpanXY[1]); if (minSpanX <= (int) grid.numColumns && minSpanY <= (int) grid.numRows) { mWidgets.add(widget); } else { Log.e(TAG, "Widget " + widget.provider + " can not fit on this device (" + widget.minWidth + ", " + widget.minHeight + ")"); } } else { Log.e(TAG, "Widget " + widget.provider + " has invalid dimensions (" + widget.minWidth + ", " + widget.minHeight + ")"); } } else { // just add shortcuts mWidgets.add(o); } } filterWidgets(); }
Example #28
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 #29
Source File: AppsCustomizePagedView.java From LB-Launcher with Apache License 2.0 | 5 votes |
public void onPackagesUpdated(ArrayList<Object> widgetsAndShortcuts) { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); // Get the list of widgets and shortcuts mWidgets.clear(); for (Object o : widgetsAndShortcuts) { if (o instanceof AppWidgetProviderInfo) { AppWidgetProviderInfo widget = (AppWidgetProviderInfo) o; if (!app.shouldShowAppOrWidgetProvider(widget.provider)) { continue; } if (widget.minWidth > 0 && widget.minHeight > 0) { // Ensure that all widgets we show can be added on a workspace of this size int[] spanXY = Launcher.getSpanForWidget(mLauncher, widget); int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, widget); int minSpanX = Math.min(spanXY[0], minSpanXY[0]); int minSpanY = Math.min(spanXY[1], minSpanXY[1]); if (minSpanX <= (int) grid.numColumns && minSpanY <= (int) grid.numRows) { mWidgets.add(widget); } else { Log.e(TAG, "Widget " + widget.provider + " can not fit on this device (" + widget.minWidth + ", " + widget.minHeight + ")"); } } else { Log.e(TAG, "Widget " + widget.provider + " has invalid dimensions (" + widget.minWidth + ", " + widget.minHeight + ")"); } } else { // just add shortcuts mWidgets.add(o); } } updatePageCountsAndInvalidateData(); }
Example #30
Source File: Workspace.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
public void widgetsRestored(final ArrayList<LauncherAppWidgetInfo> changedInfo) { if (!changedInfo.isEmpty()) { DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo, mLauncher.getAppWidgetHost()); LauncherAppWidgetInfo item = changedInfo.get(0); final AppWidgetProviderInfo widgetInfo; if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) { widgetInfo = AppWidgetManagerCompat .getInstance(mLauncher).findProvider(item.providerName, item.user); } else { widgetInfo = AppWidgetManagerCompat.getInstance(mLauncher) .getAppWidgetInfo(item.appWidgetId); } if (widgetInfo != null) { // Re-inflate the widgets which have changed status widgetRefresh.run(); } else { // widgetRefresh will automatically run when the packages are updated. // For now just update the progress bars mapOverItems(MAP_NO_RECURSE, new ItemOperator() { @Override public boolean evaluate(ItemInfo info, View view) { if (view instanceof PendingAppWidgetHostView && changedInfo.contains(info)) { ((LauncherAppWidgetInfo) info).installProgress = 100; ((PendingAppWidgetHostView) view).applyState(); } // process all the shortcuts return false; } }); } } }