Search in sources :

Example 46 with Widget

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

the class Launcher method startBinding.

/**
 * Refreshes the shortcuts shown on the workspace.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 */
public void startBinding() {
    Object traceToken = TraceHelper.INSTANCE.beginSection("startBinding");
    // Floating panels (except the full widget sheet) are associated with individual icons. If
    // we are starting a fresh bind, close all such panels as all the icons are about
    // to go away.
    AbstractFloatingView.closeOpenViews(this, true, TYPE_ALL & ~TYPE_REBIND_SAFE);
    setWorkspaceLoading(true);
    // Clear the workspace because it's going to be rebound
    mDragController.cancelDrag();
    mWorkspace.clearDropTargets();
    mWorkspace.removeAllWorkspaceScreens();
    mAppWidgetHost.clearViews();
    if (mHotseat != null) {
        mHotseat.resetLayout(getDeviceProfile().isVerticalBarLayout());
    }
    TraceHelper.INSTANCE.endSection(traceToken);
}
Also used : DragObject(com.android.launcher3.DropTarget.DragObject)

Example 47 with Widget

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

the class ShortcutAndWidgetContainer method layoutChild.

/**
 * Core logic to layout a child for this ViewGroup.
 */
public void layoutChild(View child) {
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
    if (child instanceof NavigableAppWidgetHostView) {
        NavigableAppWidgetHostView nahv = (NavigableAppWidgetHostView) child;
        // Scale and center the widget to fit within its cells.
        DeviceProfile profile = mActivity.getDeviceProfile();
        float scaleX = profile.appWidgetScale.x;
        float scaleY = profile.appWidgetScale.y;
        nahv.setScaleToFit(Math.min(scaleX, scaleY));
        nahv.setTranslationForCentering(-(lp.width - (lp.width * scaleX)) / 2.0f, -(lp.height - (lp.height * scaleY)) / 2.0f);
    }
    int childLeft = lp.x;
    int childTop = lp.y;
    child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
    if (lp.dropped) {
        lp.dropped = false;
        final int[] cellXY = mTmpCellXY;
        getLocationOnScreen(cellXY);
        mWallpaperManager.sendWallpaperCommand(getWindowToken(), WallpaperManager.COMMAND_DROP, cellXY[0] + childLeft + lp.width / 2, cellXY[1] + childTop + lp.height / 2, 0, null);
    }
}
Also used : NavigableAppWidgetHostView(com.android.launcher3.widget.NavigableAppWidgetHostView) Point(android.graphics.Point)

Example 48 with Widget

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

the class DefaultLayoutProviderTest method testCustomProfileLoaded_with_widget.

@Test
public void testCustomProfileLoaded_with_widget() throws Exception {
    String pendingAppPkg = "com.test.pending";
    // Add a placeholder session info so that the widget exists
    SessionParams params = new SessionParams(SessionParams.MODE_FULL_INSTALL);
    params.setAppPackageName(pendingAppPkg);
    params.setAppIcon(BitmapInfo.LOW_RES_ICON);
    PackageInstaller installer = mTargetContext.getPackageManager().getPackageInstaller();
    installer.createSession(params);
    writeLayoutAndLoad(new LauncherLayoutBuilder().atWorkspace(0, 1, 0).putWidget(pendingAppPkg, "PlaceholderWidget", 2, 2));
    // Verify widget
    assertEquals(1, mModelHelper.getBgDataModel().appWidgets.size());
    ItemInfo info = mModelHelper.getBgDataModel().appWidgets.get(0);
    assertEquals(LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET, info.itemType);
    assertEquals(2, info.spanX);
    assertEquals(2, info.spanY);
}
Also used : SessionParams(android.content.pm.PackageInstaller.SessionParams) LauncherLayoutBuilder(com.android.launcher3.util.LauncherLayoutBuilder) ItemInfo(com.android.launcher3.model.data.ItemInfo) PackageInstaller(android.content.pm.PackageInstaller) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 49 with Widget

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

the class WidgetsRecommendationTableLayout method addItemCell.

private WidgetCell addItemCell(ViewGroup parent) {
    WidgetCell widget = (WidgetCell) LayoutInflater.from(getContext()).inflate(R.layout.widget_cell, parent, false);
    View previewContainer = widget.findViewById(R.id.widget_preview_container);
    previewContainer.setOnClickListener(mWidgetCellOnClickListener);
    previewContainer.setOnLongClickListener(mWidgetCellOnLongClickListener);
    widget.setAnimatePreview(false);
    widget.setSourceContainer(CONTAINER_WIDGETS_PREDICTION);
    parent.addView(widget);
    return widget;
}
Also used : WidgetCell(com.android.launcher3.widget.WidgetCell) View(android.view.View)

Example 50 with Widget

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

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)

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