Search in sources :

Example 91 with Launcher

use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by AOSPA.

the class NavigationModeSwitchRule method setActiveOverlay.

public static boolean setActiveOverlay(LauncherInstrumentation launcher, String overlayPackage, LauncherInstrumentation.NavigationModel expectedMode, Description description) throws Exception {
    if (!packageExists(overlayPackage)) {
        Log.d(TAG, "setActiveOverlay: " + overlayPackage + " pkg does not exist");
        return false;
    }
    Log.d(TAG, "setActiveOverlay: " + overlayPackage + "...");
    UiDevice.getInstance(getInstrumentation()).executeShellCommand("cmd overlay enable-exclusive --category " + overlayPackage);
    if (currentSysUiNavigationMode() != expectedMode) {
        final CountDownLatch latch = new CountDownLatch(1);
        final Context targetContext = getInstrumentation().getTargetContext();
        final SysUINavigationMode.NavigationModeChangeListener listener = newMode -> {
            if (LauncherInstrumentation.getNavigationModel(newMode.resValue) == expectedMode) {
                latch.countDown();
            }
        };
        targetContext.getMainExecutor().execute(() -> SYS_UI_NAVIGATION_MODE.addModeChangeListener(listener));
        latch.await(60, TimeUnit.SECONDS);
        targetContext.getMainExecutor().execute(() -> SYS_UI_NAVIGATION_MODE.removeModeChangeListener(listener));
        assertTrue(launcher, "Navigation mode didn't change to " + expectedMode, currentSysUiNavigationMode() == expectedMode, description);
    }
    Wait.atMost("Couldn't switch to " + overlayPackage, () -> launcher.getNavigationModel() == expectedMode, WAIT_TIME_MS, launcher);
    Wait.atMost(() -> "Switching nav mode: " + launcher.getNavigationModeMismatchError(false), () -> launcher.getNavigationModeMismatchError(false) == null, WAIT_TIME_MS, launcher);
    AbstractLauncherUiTest.checkDetectedLeaks(launcher);
    return true;
}
Also used : Context(android.content.Context) Context(android.content.Context) FailureWatcher(com.android.launcher3.util.rule.FailureWatcher) Statement(org.junit.runners.model.Statement) ZERO_BUTTON(com.android.quickstep.NavigationModeSwitchRule.Mode.ZERO_BUTTON) NAV_BAR_MODE_3BUTTON_OVERLAY(com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_3BUTTON_OVERLAY) TWO_BUTTON(com.android.quickstep.NavigationModeSwitchRule.Mode.TWO_BUTTON) PackageManager(android.content.pm.PackageManager) TestRule(org.junit.rules.TestRule) QuickStepContract(com.android.systemui.shared.system.QuickStepContract) NAV_BAR_MODE_GESTURAL_OVERLAY(com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_GESTURAL_OVERLAY) TestHelpers(com.android.launcher3.tapl.TestHelpers) Retention(java.lang.annotation.Retention) InstrumentationRegistry.getInstrumentation(androidx.test.InstrumentationRegistry.getInstrumentation) THREE_BUTTON(com.android.quickstep.NavigationModeSwitchRule.Mode.THREE_BUTTON) AbstractLauncherUiTest(com.android.launcher3.ui.AbstractLauncherUiTest) ALL(com.android.quickstep.NavigationModeSwitchRule.Mode.ALL) Log(android.util.Log) UiDevice(androidx.test.uiautomator.UiDevice) LauncherInstrumentation(com.android.launcher3.tapl.LauncherInstrumentation) NAV_BAR_MODE_2BUTTON_OVERLAY(com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_2BUTTON_OVERLAY) Description(org.junit.runner.Description) Target(java.lang.annotation.Target) ElementType(java.lang.annotation.ElementType) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Wait(com.android.launcher3.util.Wait) RetentionPolicy(java.lang.annotation.RetentionPolicy) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 92 with Launcher

use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by AOSPA.

the class StartLauncherViaGestureTests method runTest.

private void runTest(String... eventSequence) {
    final RaceConditionReproducer eventProcessor = new RaceConditionReproducer(eventSequence);
    // Destroy Launcher activity.
    closeLauncherActivity();
    // The test action.
    eventProcessor.startIteration();
    mLauncher.pressHome();
    eventProcessor.finishIteration();
}
Also used : RaceConditionReproducer(com.android.launcher3.util.RaceConditionReproducer)

Example 93 with Launcher

use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by AOSPA.

the class CellLayout method applyColorExtractionOnWidget.

/**
 * Applies the local color extraction to a dragging widget object.
 */
private void applyColorExtractionOnWidget(DropTarget.DragObject dragObject, int[] targetCell, int spanX, int spanY) {
    // Apply local extracted color if the DragView is an AppWidgetHostViewDrawable.
    View view = dragObject.dragView.getContentView();
    if (view instanceof LauncherAppWidgetHostView) {
        Launcher launcher = Launcher.getLauncher(getContext());
        Workspace workspace = launcher.getWorkspace();
        int screenId = workspace.getIdForScreen(this);
        cellToRect(targetCell[0], targetCell[1], spanX, spanY, mTempRect);
        ((LauncherAppWidgetHostView) view).handleDrag(mTempRect, this, screenId);
    }
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) DraggableView(com.android.launcher3.dragndrop.DraggableView) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 94 with Launcher

use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by AOSPA.

the class TaplTestsQuickstep method testBackground.

@Test
@NavigationModeSwitch
@PortraitLandscape
public void testBackground() throws Exception {
    startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
    final Background background = getAndAssertBackground();
    assertNotNull("Background.switchToOverview() returned null", background.switchToOverview());
    assertTrue("Launcher internal state didn't switch to Overview", isInState(() -> LauncherState.OVERVIEW));
}
Also used : Background(com.android.launcher3.tapl.Background) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) NavigationModeSwitch(com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch)

Example 95 with Launcher

use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by AOSPA.

the class DatabaseWidgetPreviewLoader method generateWidgetPreview.

/**
 * Generates the widget preview from either the {@link WidgetManagerHelper} or cache
 * and add badge at the bottom right corner.
 *
 * @param info                        information about the widget
 * @param maxPreviewWidth             width of the preview on either workspace or tray
 * @param preScaledWidthOut           return the width of the returned bitmap
 */
public Bitmap generateWidgetPreview(LauncherAppWidgetProviderInfo info, int maxPreviewWidth, int[] preScaledWidthOut) {
    // Load the preview image if possible
    if (maxPreviewWidth < 0)
        maxPreviewWidth = Integer.MAX_VALUE;
    Drawable drawable = null;
    if (info.previewImage != 0) {
        try {
            drawable = info.loadPreviewImage(mContext, 0);
        } catch (OutOfMemoryError e) {
            Log.w(TAG, "Error loading widget preview for: " + info.provider, e);
            // During OutOfMemoryError, the previous heap stack is not affected. Catching
            // an OOM error here should be safe & not affect other parts of launcher.
            drawable = null;
        }
        if (drawable != null) {
            drawable = mutateOnMainThread(drawable);
        } else {
            Log.w(TAG, "Can't load widget preview drawable 0x" + Integer.toHexString(info.previewImage) + " for provider: " + info.provider);
        }
    }
    final boolean widgetPreviewExists = (drawable != null);
    final int spanX = info.spanX;
    final int spanY = info.spanY;
    int previewWidth;
    int previewHeight;
    DeviceProfile dp = ActivityContext.lookupContext(mContext).getDeviceProfile();
    if (widgetPreviewExists && drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) {
        previewWidth = drawable.getIntrinsicWidth();
        previewHeight = drawable.getIntrinsicHeight();
    } else {
        Size widgetSize = WidgetSizes.getWidgetPaddedSizePx(mContext, info.provider, dp, spanX, spanY);
        previewWidth = widgetSize.getWidth();
        previewHeight = widgetSize.getHeight();
    }
    if (preScaledWidthOut != null) {
        preScaledWidthOut[0] = previewWidth;
    }
    // Scale to fit width only - let the widget preview be clipped in the
    // vertical dimension
    final float scale = previewWidth > maxPreviewWidth ? (maxPreviewWidth / (float) (previewWidth)) : 1f;
    if (scale != 1f) {
        previewWidth = Math.max((int) (scale * previewWidth), 1);
        previewHeight = Math.max((int) (scale * previewHeight), 1);
    }
    final int previewWidthF = previewWidth;
    final int previewHeightF = previewHeight;
    final Drawable drawableF = drawable;
    return BitmapRenderer.createHardwareBitmap(previewWidth, previewHeight, c -> {
        // Draw the scaled preview into the final bitmap
        if (widgetPreviewExists) {
            drawableF.setBounds(0, 0, previewWidthF, previewHeightF);
            drawableF.draw(c);
        } else {
            RectF boxRect;
            // Draw horizontal and vertical lines to represent individual columns.
            final Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
            if (Utilities.ATLEAST_S) {
                boxRect = new RectF(/* left= */
                0, /* top= */
                0, /* right= */
                previewWidthF, /* bottom= */
                previewHeightF);
                p.setStyle(Paint.Style.FILL);
                p.setColor(Color.WHITE);
                float roundedCorner = mContext.getResources().getDimension(android.R.dimen.system_app_widget_background_radius);
                c.drawRoundRect(boxRect, roundedCorner, roundedCorner, p);
            } else {
                boxRect = drawBoxWithShadow(c, previewWidthF, previewHeightF);
            }
            p.setStyle(Paint.Style.STROKE);
            p.setStrokeWidth(mContext.getResources().getDimension(R.dimen.widget_preview_cell_divider_width));
            p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
            float t = boxRect.left;
            float tileSize = boxRect.width() / spanX;
            for (int i = 1; i < spanX; i++) {
                t += tileSize;
                c.drawLine(t, 0, t, previewHeightF, p);
            }
            t = boxRect.top;
            tileSize = boxRect.height() / spanY;
            for (int i = 1; i < spanY; i++) {
                t += tileSize;
                c.drawLine(0, t, previewWidthF, t, p);
            }
            // Draw icon in the center.
            try {
                Drawable icon = LauncherAppState.getInstance(mContext).getIconCache().getFullResIcon(info.provider.getPackageName(), info.icon);
                if (icon != null) {
                    int appIconSize = dp.iconSizePx;
                    int iconSize = (int) Math.min(appIconSize * scale, Math.min(boxRect.width(), boxRect.height()));
                    icon = mutateOnMainThread(icon);
                    int hoffset = (previewWidthF - iconSize) / 2;
                    int yoffset = (previewHeightF - iconSize) / 2;
                    icon.setBounds(hoffset, yoffset, hoffset + iconSize, yoffset + iconSize);
                    icon.draw(c);
                }
            } catch (Resources.NotFoundException e) {
            }
        }
    });
}
Also used : RectF(android.graphics.RectF) DeviceProfile(com.android.launcher3.DeviceProfile) Size(android.util.Size) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint) Resources(android.content.res.Resources) Paint(android.graphics.Paint)

Aggregations

Launcher (com.android.launcher3.Launcher)194 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)102 Test (org.junit.Test)102 View (android.view.View)87 LargeTest (androidx.test.filters.LargeTest)83 ItemInfo (com.android.launcher3.model.data.ItemInfo)83 Rect (android.graphics.Rect)80 Point (android.graphics.Point)77 Intent (android.content.Intent)71 ArrayList (java.util.ArrayList)69 DeviceProfile (com.android.launcher3.DeviceProfile)66 BaseQuickstepLauncher (com.android.launcher3.BaseQuickstepLauncher)64 Context (android.content.Context)61 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)49 RecentsView (com.android.quickstep.views.RecentsView)46 DragLayer (com.android.launcher3.dragndrop.DragLayer)45 ComponentName (android.content.ComponentName)43 FolderInfo (com.android.launcher3.model.data.FolderInfo)42 ViewGroup (android.view.ViewGroup)41 AllApps (com.android.launcher3.tapl.AllApps)40