Search in sources :

Example 36 with ItemOperator

use of com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator in project android_packages_apps_Launcher3 by crdroidandroid.

the class RequestPinItemTest method runTest.

private void runTest(String activityMethod, boolean isWidget, ItemOperator itemMatcher, Intent... commandIntents) throws Throwable {
    clearHomescreen();
    mDevice.pressHome();
    // Open Pin item activity
    BlockingBroadcastReceiver openMonitor = new BlockingBroadcastReceiver(RequestPinItemActivity.class.getName());
    mLauncher.getWorkspace().switchToAllApps().getAppIcon("Test Pin Item").launch(getAppPackageName());
    assertNotNull(openMonitor.blockingGetExtraIntent());
    // Set callback
    PendingIntent callback = PendingIntent.getBroadcast(mTargetContext, 0, new Intent(mCallbackAction), PendingIntent.FLAG_ONE_SHOT);
    mTargetContext.sendBroadcast(RequestPinItemActivity.getCommandIntent(RequestPinItemActivity.class, "setCallback").putExtra(RequestPinItemActivity.EXTRA_PARAM + "0", callback));
    for (Intent command : commandIntents) {
        mTargetContext.sendBroadcast(command);
    }
    // call the requested method to start the flow
    mTargetContext.sendBroadcast(RequestPinItemActivity.getCommandIntent(RequestPinItemActivity.class, activityMethod));
    final AddToHomeScreenPrompt addToHomeScreenPrompt = mLauncher.getAddToHomeScreenPrompt();
    // Accept confirmation:
    BlockingBroadcastReceiver resultReceiver = new BlockingBroadcastReceiver(mCallbackAction);
    addToHomeScreenPrompt.addAutomatically();
    Intent result = resultReceiver.blockingGetIntent();
    assertNotNull(result);
    mAppWidgetId = result.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    if (isWidget) {
        assertNotSame(-1, mAppWidgetId);
    }
    // Go back to home
    mLauncher.pressHome();
    Wait.atMost("", new ItemSearchCondition(itemMatcher), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
}
Also used : AddToHomeScreenPrompt(com.android.launcher3.tapl.AddToHomeScreenPrompt) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) RequestPinItemActivity(com.android.launcher3.testcomponent.RequestPinItemActivity)

Example 37 with ItemOperator

use of com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator in project Neo-Launcher by NeoApplications.

the class Workspace method widgetsRestored.

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).getLauncherAppWidgetInfo(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(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;
                }
            });
        }
    }
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) OmegaBackgroundView(com.saggitt.omega.views.OmegaBackgroundView)

Example 38 with ItemOperator

use of com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator in project Neo-Launcher by NeoApplications.

the class RequestPinItemTest method testPinShortcut.

@Test
public void testPinShortcut() throws Throwable {
    // Command to set the shortcut id
    Intent command = RequestPinItemActivity.getCommandIntent(RequestPinItemActivity.class, "setShortcutId").putExtra(RequestPinItemActivity.EXTRA_PARAM + "0", mShortcutId);
    runTest("pinShortcut", false, new ItemOperator() {

        @Override
        public boolean evaluate(ItemInfo info, View view) {
            return info instanceof WorkspaceItemInfo && info.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT && ShortcutKey.fromItemInfo(info).getId().equals(mShortcutId);
        }
    }, command);
}
Also used : WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) ItemInfo(com.android.launcher3.ItemInfo) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RequestPinItemActivity(com.android.launcher3.testcomponent.RequestPinItemActivity) ItemOperator(com.android.launcher3.Workspace.ItemOperator) View(android.view.View) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 39 with ItemOperator

use of com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator in project android_packages_apps_Trebuchet by LineageOS.

the class RequestPinItemTest method runTest.

private void runTest(String activityMethod, boolean isWidget, ItemOperator itemMatcher, Intent... commandIntents) throws Throwable {
    if (!Utilities.ATLEAST_OREO) {
        return;
    }
    clearHomescreen();
    mDevice.pressHome();
    // Open Pin item activity
    BlockingBroadcastReceiver openMonitor = new BlockingBroadcastReceiver(RequestPinItemActivity.class.getName());
    mLauncher.getWorkspace().switchToAllApps().getAppIcon("Test Pin Item").launch(getAppPackageName());
    assertNotNull(openMonitor.blockingGetExtraIntent());
    // Set callback
    PendingIntent callback = PendingIntent.getBroadcast(mTargetContext, 0, new Intent(mCallbackAction), PendingIntent.FLAG_ONE_SHOT);
    mTargetContext.sendBroadcast(RequestPinItemActivity.getCommandIntent(RequestPinItemActivity.class, "setCallback").putExtra(RequestPinItemActivity.EXTRA_PARAM + "0", callback));
    for (Intent command : commandIntents) {
        mTargetContext.sendBroadcast(command);
    }
    // call the requested method to start the flow
    mTargetContext.sendBroadcast(RequestPinItemActivity.getCommandIntent(RequestPinItemActivity.class, activityMethod));
    final AddToHomeScreenPrompt addToHomeScreenPrompt = mLauncher.getAddToHomeScreenPrompt();
    // Accept confirmation:
    BlockingBroadcastReceiver resultReceiver = new BlockingBroadcastReceiver(mCallbackAction);
    addToHomeScreenPrompt.addAutomatically();
    Intent result = resultReceiver.blockingGetIntent();
    assertNotNull(result);
    mAppWidgetId = result.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    if (isWidget) {
        assertNotSame(-1, mAppWidgetId);
    }
    // Go back to home
    mLauncher.pressHome();
    Wait.atMost("", new ItemSearchCondition(itemMatcher), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
}
Also used : AddToHomeScreenPrompt(com.android.launcher3.tapl.AddToHomeScreenPrompt) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) RequestPinItemActivity(com.android.launcher3.testcomponent.RequestPinItemActivity)

Example 40 with ItemOperator

use of com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator in project android_packages_apps_Trebuchet by LineageOS.

the class RequestPinItemTest method testPinShortcut.

@Test
public void testPinShortcut() throws Throwable {
    // Command to set the shortcut id
    Intent command = RequestPinItemActivity.getCommandIntent(RequestPinItemActivity.class, "setShortcutId").putExtra(RequestPinItemActivity.EXTRA_PARAM + "0", mShortcutId);
    runTest("pinShortcut", false, new ItemOperator() {

        @Override
        public boolean evaluate(ItemInfo info, View view) {
            return info instanceof WorkspaceItemInfo && info.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT && ShortcutKey.fromItemInfo(info).getId().equals(mShortcutId);
        }
    }, command);
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RequestPinItemActivity(com.android.launcher3.testcomponent.RequestPinItemActivity) ItemOperator(com.android.launcher3.Workspace.ItemOperator) View(android.view.View) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Aggregations

View (android.view.View)42 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)35 ItemInfo (com.android.launcher3.model.data.ItemInfo)30 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)30 AppWidgetHostView (android.appwidget.AppWidgetHostView)27 DragView (com.android.launcher3.dragndrop.DragView)27 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)27 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)24 DraggableView (com.android.launcher3.dragndrop.DraggableView)22 Bitmap (android.graphics.Bitmap)21 Drawable (android.graphics.drawable.Drawable)21 Folder (com.android.launcher3.folder.Folder)21 FolderIcon (com.android.launcher3.folder.FolderIcon)21 SuppressLint (android.annotation.SuppressLint)20 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)20 Point (android.graphics.Point)20 FolderInfo (com.android.launcher3.model.data.FolderInfo)18 PreloadIconDrawable (com.android.launcher3.graphics.PreloadIconDrawable)17 HashSet (java.util.HashSet)17 List (java.util.List)15