Search in sources :

Example 51 with Widget

use of com.android.launcher3.tapl.Widget in project android_packages_apps_Launcher3 by AOSPA.

the class WidgetsPredicationUpdateTaskTest method widgetsRecommendationRan_shouldOnlyReturnNotAddedWidgetsInAppPredictionOrder.

@Test
public void widgetsRecommendationRan_shouldOnlyReturnNotAddedWidgetsInAppPredictionOrder() throws Exception {
    // WHEN newPredicationTask is executed with app predication of 5 apps.
    AppTarget app1 = new AppTarget(new AppTargetId("app1"), "app1", "className", mUserHandle);
    AppTarget app2 = new AppTarget(new AppTargetId("app2"), "app2", "className", mUserHandle);
    AppTarget app3 = new AppTarget(new AppTargetId("app3"), "app3", "className", mUserHandle);
    AppTarget app4 = new AppTarget(new AppTargetId("app4"), "app4", "className", mUserHandle);
    AppTarget app5 = new AppTarget(new AppTargetId("app5"), "app5", "className", mUserHandle);
    mModelHelper.executeTaskForTest(newWidgetsPredicationTask(List.of(app5, app3, app2, app4, app1))).forEach(Runnable::run);
    // THEN only 3 widgets are returned because
    // 1. app5/provider1 & app4/provider1 have already been added to workspace. They are
    // excluded from the result.
    // 2. app3 doesn't have a widget.
    // 3. only 1 widget is picked from app1 because we only want to promote one widget per app.
    List<PendingAddWidgetInfo> recommendedWidgets = mCallback.mRecommendedWidgets.items.stream().map(itemInfo -> (PendingAddWidgetInfo) itemInfo).collect(Collectors.toList());
    assertThat(recommendedWidgets).hasSize(3);
    assertWidgetInfo(recommendedWidgets.get(0).info, mApp2Provider1);
    assertWidgetInfo(recommendedWidgets.get(1).info, mApp4Provider2);
    assertWidgetInfo(recommendedWidgets.get(2).info, mApp1Provider1);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CONTAINER_WIDGETS_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION) Arrays(java.util.Arrays) MODEL_EXECUTOR(com.android.launcher3.util.Executors.MODEL_EXECUTOR) AppTargetId(android.app.prediction.AppTargetId) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) RunWith(org.junit.runner.RunWith) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) IconCache(com.android.launcher3.icons.IconCache) AppTarget(android.app.prediction.AppTarget) MockitoAnnotations(org.mockito.MockitoAnnotations) Process.myUserHandle(android.os.Process.myUserHandle) Mockito.doAnswer(org.mockito.Mockito.doAnswer) UserHandle(android.os.UserHandle) After(org.junit.After) MAIN_EXECUTOR(com.android.launcher3.util.Executors.MAIN_EXECUTOR) WidgetUtils.createAppWidgetProviderInfo(com.android.launcher3.util.WidgetUtils.createAppWidgetProviderInfo) Mockito.doReturn(org.mockito.Mockito.doReturn) Log(android.util.Log) Before(org.junit.Before) SmallTest(androidx.test.filters.SmallTest) LauncherModelHelper(com.android.launcher3.util.LauncherModelHelper) ComponentName(android.content.ComponentName) LauncherAppState(com.android.launcher3.LauncherAppState) TextUtils(android.text.TextUtils) FeatureFlags(com.android.launcher3.config.FeatureFlags) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) AppWidgetManager(android.appwidget.AppWidgetManager) List(java.util.List) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) ComponentWithLabel(com.android.launcher3.icons.ComponentWithLabel) PredictorState(com.android.launcher3.model.QuickstepModelDelegate.PredictorState) AppTarget(android.app.prediction.AppTarget) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) AppTargetId(android.app.prediction.AppTargetId) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 52 with Widget

use of com.android.launcher3.tapl.Widget 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 53 with Widget

use of com.android.launcher3.tapl.Widget in project android_packages_apps_Launcher3 by AOSPA.

the class ViewInflationDuringSwipeUp method testSwipeUp_with_list_widgets.

@Test
@NavigationModeSwitch(mode = ZERO_BUTTON)
// until b/190729479 is fixed
@Suppress
public void testSwipeUp_with_list_widgets() {
    SimpleViewsFactory viewFactory = new SimpleViewsFactory();
    viewFactory.viewCount = 1;
    Bundle args = new Bundle();
    args.putBinder(EXTRA_VALUE, viewFactory.toBinder());
    TestCommandReceiver.callCommand(SET_LIST_VIEW_SERVICE_BINDER, null, args);
    try {
        executeSwipeUpTestWithWidget(widgetId -> {
            // Initialize widget
            RemoteViews views = createMainWidgetViews("List widget title");
            views.setRemoteAdapter(android.R.id.list, new Intent(getContext(), ListViewService.class));
            AppWidgetManager.getInstance(getContext()).updateAppWidget(widgetId, views);
            verifyWidget(viewFactory.getLabel(0));
        }, widgetId -> {
            // Update widget
            viewFactory.viewCount = 2;
            AppWidgetManager.getInstance(getContext()).notifyAppWidgetViewDataChanged(widgetId, android.R.id.list);
        }, viewFactory.getLabel(1));
    } finally {
        TestCommandReceiver.callCommand(SET_LIST_VIEW_SERVICE_BINDER, null, new Bundle());
    }
}
Also used : RemoteViews(android.widget.RemoteViews) ListViewService(com.android.launcher3.testcomponent.ListViewService) Bundle(android.os.Bundle) Intent(android.content.Intent) SimpleViewsFactory(com.android.launcher3.testcomponent.ListViewService.SimpleViewsFactory) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) NavigationModeSwitch(com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch) Suppress(androidx.test.filters.Suppress)

Example 54 with Widget

use of com.android.launcher3.tapl.Widget 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)

Example 55 with Widget

use of com.android.launcher3.tapl.Widget in project android_packages_apps_Launcher3 by AOSPA.

the class LauncherAppWidgetHost method getConfigurationActivityOptions.

/**
 * Returns an {@link android.app.ActivityOptions} bundle from the {code activity} for launching
 * the configuration of the {@code widgetId} app widget, or null of options cannot be produced.
 */
@Nullable
private Bundle getConfigurationActivityOptions(BaseDraggingActivity activity, int widgetId) {
    LauncherAppWidgetHostView view = mViews.get(widgetId);
    if (view == null)
        return null;
    Object tag = view.getTag();
    if (!(tag instanceof ItemInfo))
        return null;
    Bundle bundle = activity.getActivityLaunchOptions(view, (ItemInfo) tag).toBundle();
    bundle.putInt(KEY_SPLASH_SCREEN_STYLE, SPLASH_SCREEN_STYLE_EMPTY);
    return bundle;
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) Bundle(android.os.Bundle) Nullable(androidx.annotation.Nullable)

Aggregations

LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)105 Test (org.junit.Test)87 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)71 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)66 Point (android.graphics.Point)62 ArrayList (java.util.ArrayList)60 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)56 View (android.view.View)55 LargeTest (androidx.test.filters.LargeTest)55 ComponentName (android.content.ComponentName)53 AppWidgetHostView (android.appwidget.AppWidgetHostView)52 Bundle (android.os.Bundle)50 WidgetItem (com.android.launcher3.model.WidgetItem)49 AbstractLauncherUiTest (com.android.launcher3.ui.AbstractLauncherUiTest)49 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)47 ItemInfo (com.android.launcher3.model.data.ItemInfo)44 PackageUserKey (com.android.launcher3.util.PackageUserKey)41 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)41 Context (android.content.Context)31 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)31