Search in sources :

Example 86 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by ProtonAOSP.

the class LauncherAppWidgetProviderInfo method initSpans.

public void initSpans(Context context, InvariantDeviceProfile idp) {
    int minSpanX = 0;
    int minSpanY = 0;
    int maxSpanX = idp.numColumns;
    int maxSpanY = idp.numRows;
    int spanX = 0;
    int spanY = 0;
    Rect widgetPadding = new Rect();
    Rect localPadding = new Rect();
    AppWidgetHostView.getDefaultPaddingForWidget(context, provider, widgetPadding);
    Point cellSize = new Point();
    for (DeviceProfile dp : idp.supportedProfiles) {
        dp.getCellSize(cellSize);
        // If grids supports insetting widgets, we do not account for widget padding.
        if (dp.shouldInsetWidgets()) {
            localPadding.setEmpty();
        } else {
            localPadding.set(widgetPadding);
        }
        minSpanX = Math.max(minSpanX, getSpanX(localPadding, minResizeWidth, dp.cellLayoutBorderSpacePx.x, cellSize.x));
        minSpanY = Math.max(minSpanY, getSpanY(localPadding, minResizeHeight, dp.cellLayoutBorderSpacePx.y, cellSize.y));
        if (ATLEAST_S) {
            if (maxResizeWidth > 0) {
                maxSpanX = Math.min(maxSpanX, getSpanX(localPadding, maxResizeWidth, dp.cellLayoutBorderSpacePx.x, cellSize.x));
            }
            if (maxResizeHeight > 0) {
                maxSpanY = Math.min(maxSpanY, getSpanY(localPadding, maxResizeHeight, dp.cellLayoutBorderSpacePx.y, cellSize.y));
            }
        }
        spanX = Math.max(spanX, getSpanX(localPadding, minWidth, dp.cellLayoutBorderSpacePx.x, cellSize.x));
        spanY = Math.max(spanY, getSpanY(localPadding, minHeight, dp.cellLayoutBorderSpacePx.y, cellSize.y));
    }
    if (ATLEAST_S) {
        // Ensures maxSpan >= minSpan
        maxSpanX = Math.max(maxSpanX, minSpanX);
        maxSpanY = Math.max(maxSpanY, minSpanY);
        // Otherwise, use the span of minWidth/Height.
        if (targetCellWidth >= minSpanX && targetCellWidth <= maxSpanX && targetCellHeight >= minSpanY && targetCellHeight <= maxSpanY) {
            spanX = targetCellWidth;
            spanY = targetCellHeight;
        }
    }
    // If minSpanX/Y > spanX/Y, ignore the minSpanX/Y to match the behavior described in
    // minResizeWidth & minResizeHeight Android documentation. See
    // https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo
    this.minSpanX = Math.min(spanX, minSpanX);
    this.minSpanY = Math.min(spanY, minSpanY);
    this.maxSpanX = maxSpanX;
    this.maxSpanY = maxSpanY;
    this.mIsMinSizeFulfilled = Math.min(spanX, minSpanX) <= idp.numColumns && Math.min(spanY, minSpanY) <= idp.numRows;
    // Ensures the default span X and span Y will not exceed the current grid size.
    this.spanX = Math.min(spanX, idp.numColumns);
    this.spanY = Math.min(spanY, idp.numRows);
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) Rect(android.graphics.Rect) Point(android.graphics.Point) Point(android.graphics.Point)

Example 87 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by ProtonAOSP.

the class WidgetsBottomSheet method onWidgetsBound.

@Override
public void onWidgetsBound() {
    List<WidgetItem> widgets = mActivityContext.getPopupDataProvider().getWidgetsForPackageUser(new PackageUserKey(mOriginalItemInfo.getTargetComponent().getPackageName(), mOriginalItemInfo.user));
    TableLayout widgetsTable = findViewById(R.id.widgets_table);
    widgetsTable.removeAllViews();
    WidgetsTableUtils.groupWidgetItemsIntoTableWithReordering(widgets, mMaxHorizontalSpan).forEach(row -> {
        TableRow tableRow = new TableRow(getContext());
        tableRow.setGravity(Gravity.TOP);
        row.forEach(widgetItem -> {
            WidgetCell widget = addItemCell(tableRow);
            widget.applyFromCellItem(widgetItem);
        });
        widgetsTable.addView(tableRow);
    });
}
Also used : TableRow(android.widget.TableRow) WidgetItem(com.android.launcher3.model.WidgetItem) PackageUserKey(com.android.launcher3.util.PackageUserKey) TableLayout(android.widget.TableLayout)

Example 88 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by ProtonAOSP.

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 89 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by ProtonAOSP.

the class WidgetsPredicationUpdateTaskTest method widgetsRecommendationRan_localFilterDisabled_shouldReturnWidgetsInPredicationOrder.

@Test
public void widgetsRecommendationRan_localFilterDisabled_shouldReturnWidgetsInPredicationOrder() throws Exception {
    if (FeatureFlags.ENABLE_LOCAL_RECOMMENDED_WIDGETS_FILTER.get()) {
        return;
    }
    // WHEN newPredicationTask is executed with 5 predicated widgets.
    AppTarget widget1 = new AppTarget(new AppTargetId("app1"), "app1", "provider1", mUserHandle);
    AppTarget widget2 = new AppTarget(new AppTargetId("app1"), "app1", "provider2", mUserHandle);
    // Not installed app
    AppTarget widget3 = new AppTarget(new AppTargetId("app2"), "app3", "provider1", mUserHandle);
    // Not installed widget
    AppTarget widget4 = new AppTarget(new AppTargetId("app4"), "app4", "provider3", mUserHandle);
    AppTarget widget5 = new AppTarget(new AppTargetId("app5"), "app5", "provider1", mUserHandle);
    mModelHelper.executeTaskForTest(newWidgetsPredicationTask(List.of(widget5, widget3, widget2, widget4, widget1))).forEach(Runnable::run);
    // THEN only 3 widgets are returned because the launcher only filters out non-exist widgets.
    List<PendingAddWidgetInfo> recommendedWidgets = mCallback.mRecommendedWidgets.items.stream().map(itemInfo -> (PendingAddWidgetInfo) itemInfo).collect(Collectors.toList());
    assertThat(recommendedWidgets).hasSize(3);
    assertWidgetInfo(recommendedWidgets.get(0).info, mApp5Provider1);
    assertWidgetInfo(recommendedWidgets.get(1).info, mApp1Provider2);
    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 90 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by ProtonAOSP.

the class WidgetsPredicationUpdateTaskTest method setup.

@Before
public void setup() throws Exception {
    mModelHelper = new LauncherModelHelper();
    MockitoAnnotations.initMocks(this);
    doAnswer(invocation -> {
        ComponentWithLabel componentWithLabel = invocation.getArgument(0);
        return componentWithLabel.getComponent().getShortClassName();
    }).when(mIconCache).getTitleNoCache(any());
    mUserHandle = myUserHandle();
    mApp1Provider1 = createAppWidgetProviderInfo(ComponentName.createRelative("app1", "provider1"));
    mApp1Provider2 = createAppWidgetProviderInfo(ComponentName.createRelative("app1", "provider2"));
    mApp2Provider1 = createAppWidgetProviderInfo(ComponentName.createRelative("app2", "provider1"));
    mApp4Provider1 = createAppWidgetProviderInfo(ComponentName.createRelative("app4", "provider1"));
    mApp4Provider2 = createAppWidgetProviderInfo(ComponentName.createRelative("app4", ".provider2"));
    mApp5Provider1 = createAppWidgetProviderInfo(ComponentName.createRelative("app5", "provider1"));
    allWidgets = Arrays.asList(mApp1Provider1, mApp1Provider2, mApp2Provider1, mApp4Provider1, mApp4Provider2, mApp5Provider1);
    AppWidgetManager manager = mModelHelper.sandboxContext.spyService(AppWidgetManager.class);
    doReturn(allWidgets).when(manager).getInstalledProviders();
    doReturn(allWidgets).when(manager).getInstalledProvidersForProfile(eq(myUserHandle()));
    doAnswer(i -> {
        String pkg = i.getArgument(0);
        Log.e("Hello", "Getting v " + pkg);
        return TextUtils.isEmpty(pkg) ? allWidgets : allWidgets.stream().filter(a -> pkg.equals(a.provider.getPackageName())).collect(Collectors.toList());
    }).when(manager).getInstalledProvidersForPackage(any(), eq(myUserHandle()));
    // 2 widgets, app4/provider1 & app5/provider1, have already been added to the workspace.
    mModelHelper.initializeData("widgets_predication_update_task_data");
    MAIN_EXECUTOR.submit(() -> mModelHelper.getModel().addCallbacks(mCallback)).get();
    MODEL_EXECUTOR.post(() -> mModelHelper.getBgDataModel().widgetsModel.update(LauncherAppState.getInstance(mModelHelper.sandboxContext), /* packageUser= */
    null));
    MODEL_EXECUTOR.submit(() -> {
    }).get();
    MAIN_EXECUTOR.submit(() -> {
    }).get();
}
Also used : LauncherModelHelper(com.android.launcher3.util.LauncherModelHelper) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentWithLabel(com.android.launcher3.icons.ComponentWithLabel) Before(org.junit.Before)

Aggregations

ArrayList (java.util.ArrayList)64 Test (org.junit.Test)64 WidgetItem (com.android.launcher3.model.WidgetItem)54 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)54 PackageUserKey (com.android.launcher3.util.PackageUserKey)50 List (java.util.List)50 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)46 SmallTest (androidx.test.filters.SmallTest)44 ComponentName (android.content.ComponentName)42 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)41 Point (android.graphics.Point)40 View (android.view.View)37 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)32 Collectors (java.util.stream.Collectors)31 Context (android.content.Context)29 IconCache (com.android.launcher3.icons.IconCache)29 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)29 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)29 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)27 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)27