Search in sources :

Example 41 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project Neo-Launcher by NeoApplications.

the class WidgetHostViewLoader method preloadWidget.

/**
 * Start preloading the widget.
 */
private boolean preloadWidget() {
    final LauncherAppWidgetProviderInfo pInfo = mInfo.info;
    if (pInfo.isCustomWidget()) {
        return false;
    }
    final Bundle options = getDefaultOptionsForWidget(mLauncher, mInfo);
    // If there is a configuration activity, do not follow thru bound and inflate.
    if (mInfo.getHandler().needsConfigure()) {
        mInfo.bindOptions = options;
        return false;
    }
    mBindWidgetRunnable = new Runnable() {

        @Override
        public void run() {
            mWidgetLoadingId = mLauncher.getAppWidgetHost().allocateAppWidgetId();
            if (LOGD) {
                Log.d(TAG, "Binding widget, id: " + mWidgetLoadingId);
            }
            if (AppWidgetManagerCompat.getInstance(mLauncher).bindAppWidgetIdIfAllowed(mWidgetLoadingId, pInfo, options)) {
                // Widget id bound. Inflate the widget.
                mHandler.post(mInflateWidgetRunnable);
            }
        }
    };
    mInflateWidgetRunnable = new Runnable() {

        @Override
        public void run() {
            if (LOGD) {
                Log.d(TAG, "Inflating widget, id: " + mWidgetLoadingId);
            }
            if (mWidgetLoadingId == -1) {
                return;
            }
            AppWidgetHostView hostView = mLauncher.getAppWidgetHost().createView((Context) mLauncher, mWidgetLoadingId, pInfo);
            mInfo.boundWidget = hostView;
            // We used up the widget Id in binding the above view.
            mWidgetLoadingId = -1;
            hostView.setVisibility(View.INVISIBLE);
            int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(mInfo);
            // We want the first widget layout to be the correct size. This will be important
            // for width size reporting to the AppWidgetManager.
            DragLayer.LayoutParams lp = new DragLayer.LayoutParams(unScaledSize[0], unScaledSize[1]);
            lp.x = lp.y = 0;
            lp.customPosition = true;
            hostView.setLayoutParams(lp);
            if (LOGD) {
                Log.d(TAG, "Adding host view to drag layer");
            }
            mLauncher.getDragLayer().addView(hostView);
            mView.setTag(mInfo);
        }
    };
    if (LOGD) {
        Log.d(TAG, "About to bind/inflate widget");
    }
    mHandler.post(mBindWidgetRunnable);
    return true;
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) Context(android.content.Context) AppWidgetHostView(android.appwidget.AppWidgetHostView) DragLayer(com.android.launcher3.dragndrop.DragLayer) Bundle(android.os.Bundle)

Example 42 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project Neo-Launcher by NeoApplications.

the class BindWidgetTest method testUnboundWidget_removed.

@Test
public void testUnboundWidget_removed() {
    LauncherAppWidgetProviderInfo info = TestViewHelpers.findWidgetProvider(this, false);
    LauncherAppWidgetInfo item = createWidgetInfo(info, false);
    item.appWidgetId = -33;
    setupContents(item);
    final Workspace workspace = mLauncher.getWorkspace();
    // Item deleted from db
    mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id), null, null, null, null, null);
    assertEquals(0, mCursor.getCount());
    // The view does not exist
    assertTrue("Widget exists", workspace.tryGetWidget(info.label, 0) == null);
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo) Workspace(com.android.launcher3.tapl.Workspace) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 43 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project Neo-Launcher by NeoApplications.

the class BindWidgetTest method testPendingWidget_withConfigScreen.

@Test
public void testPendingWidget_withConfigScreen() {
    // A non-restored widget with config screen get bound and shows a 'Click to setup' UI.
    LauncherAppWidgetProviderInfo info = TestViewHelpers.findWidgetProvider(this, true);
    // Do not bind the widget
    LauncherAppWidgetInfo item = createWidgetInfo(info, false);
    item.restoreStatus = LauncherAppWidgetInfo.FLAG_ID_NOT_VALID;
    setupContents(item);
    verifyPendingWidgetPresent();
    // Item deleted from db
    mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id), null, null, null, null, null);
    mCursor.moveToNext();
    // Widget has a valid Id now.
    assertEquals(0, mCursor.getInt(mCursor.getColumnIndex(LauncherSettings.Favorites.RESTORED)) & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID);
    assertNotNull(AppWidgetManager.getInstance(mTargetContext).getAppWidgetInfo(mCursor.getInt(mCursor.getColumnIndex(LauncherSettings.Favorites.APPWIDGET_ID))));
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 44 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project Neo-Launcher by NeoApplications.

the class BindWidgetTest method testBindNormalWidget_withoutConfig.

@Test
public void testBindNormalWidget_withoutConfig() {
    LauncherAppWidgetProviderInfo info = TestViewHelpers.findWidgetProvider(this, false);
    LauncherAppWidgetInfo item = createWidgetInfo(info, true);
    setupContents(item);
    verifyWidgetPresent(info);
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 45 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.LauncherAppWidgetProviderInfo in project Neo-Launcher by NeoApplications.

the class WidgetsModel method update.

/**
 * @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
 *                    only widgets and shortcuts associated with the package/user are.
 */
public List<ComponentWithLabel> update(LauncherAppState app, @Nullable PackageUserKey packageUser) {
    Preconditions.assertWorkerThread();
    Context context = app.getContext();
    final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
    List<ComponentWithLabel> updatedItems = new ArrayList<>();
    try {
        InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
        PackageManager pm = app.getContext().getPackageManager();
        // Widgets
        AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(context);
        for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
            LauncherAppWidgetProviderInfo launcherWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
            widgetsAndShortcuts.add(new WidgetItem(launcherWidgetInfo, idp, app.getIconCache()));
            updatedItems.add(launcherWidgetInfo);
        }
        // Shortcuts
        for (ShortcutConfigActivityInfo info : LauncherAppsCompat.getInstance(context).getCustomShortcutActivityList(packageUser)) {
            widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
            updatedItems.add(info);
        }
        setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
    } catch (Exception e) {
        if (!FeatureFlags.IS_DOGFOOD_BUILD && Utilities.isBinderSizeError(e)) {
        // the returned value may be incomplete and will not be refreshed until the next
        // time Launcher starts.
        // TODO: after figuring out a repro step, introduce a dirty bit to check when
        // onResume is called to refresh the widget provider list.
        } else {
            throw e;
        }
    }
    app.getWidgetCache().removeObsoletePreviews(widgetsAndShortcuts, packageUser);
    return updatedItems;
}
Also used : Context(android.content.Context) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ArrayList(java.util.ArrayList) AppWidgetManagerCompat(com.android.launcher3.compat.AppWidgetManagerCompat) PackageManager(android.content.pm.PackageManager) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) ShortcutConfigActivityInfo(com.android.launcher3.compat.ShortcutConfigActivityInfo) ComponentWithLabel(com.android.launcher3.icons.ComponentWithLabel)

Aggregations

Test (org.junit.Test)108 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)81 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)77 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)65 SmallTest (androidx.test.filters.SmallTest)52 LargeTest (androidx.test.filters.LargeTest)42 AbstractLauncherUiTest (com.android.launcher3.ui.AbstractLauncherUiTest)42 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)33 Bundle (android.os.Bundle)32 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)31 Point (android.graphics.Point)29 LauncherAppWidgetProviderInfo (com.android.launcher3.LauncherAppWidgetProviderInfo)28 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)23 Context (android.content.Context)23 DeviceProfile (com.android.launcher3.DeviceProfile)23 ArrayList (java.util.ArrayList)21 AppWidgetHostView (android.appwidget.AppWidgetHostView)20 WidgetItem (com.android.launcher3.model.WidgetItem)17 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)14 WidgetAddFlowHandler (com.android.launcher3.widget.WidgetAddFlowHandler)14