Search in sources :

Example 71 with Widget

use of com.android.launcher3.tapl.Widget in project android_packages_apps_Trebuchet by LineageOS.

the class Workspace method removeAllWorkspaceScreens.

public void removeAllWorkspaceScreens() {
    // Disable all layout transitions before removing all pages to ensure that we don't get the
    // transition animations competing with us changing the scroll when we add pages
    disableLayoutTransitions();
    // Recycle the QSB widget
    View qsb = findViewById(R.id.search_container_workspace);
    if (qsb != null) {
        ((ViewGroup) qsb.getParent()).removeView(qsb);
    }
    // Remove the pages and clear the screen models
    removeFolderListeners();
    removeAllViews();
    mScreenOrder.clear();
    mWorkspaceScreens.clear();
    // Remove any deferred refresh callbacks
    mLauncher.mHandler.removeCallbacksAndMessages(DeferredWidgetRefresh.class);
    // Ensure that the first page is always present
    bindAndInitFirstWorkspaceScreen(qsb);
    // Re-enable the layout transitions
    enableLayoutTransitions();
}
Also used : ViewGroup(android.view.ViewGroup) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView)

Example 72 with Widget

use of com.android.launcher3.tapl.Widget in project android_packages_apps_Trebuchet by LineageOS.

the class WorkspaceAccessibilityHelper method intersectsValidDropTarget.

/**
 * Find the virtual view id corresponding to the top left corner of any drop region by which
 * the passed id is contained. For an icon, this is simply
 */
@Override
protected int intersectsValidDropTarget(int id) {
    int mCountX = mView.getCountX();
    int mCountY = mView.getCountY();
    int x = id % mCountX;
    int y = id / mCountX;
    LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo();
    if (dragInfo.dragType == DragType.WIDGET && !mView.acceptsWidget()) {
        return INVALID_POSITION;
    }
    if (dragInfo.dragType == DragType.WIDGET) {
        // For a widget, every cell must be vacant. In addition, we will return any valid
        // drop target by which the passed id is contained.
        boolean fits = false;
        // These represent the amount that we can back off if we hit a problem. They
        // get consumed as we move up and to the right, trying new regions.
        int spanX = dragInfo.info.spanX;
        int spanY = dragInfo.info.spanY;
        for (int m = 0; m < spanX; m++) {
            for (int n = 0; n < spanY; n++) {
                fits = true;
                int x0 = x - m;
                int y0 = y - n;
                if (x0 < 0 || y0 < 0)
                    continue;
                for (int i = x0; i < x0 + spanX; i++) {
                    if (!fits)
                        break;
                    for (int j = y0; j < y0 + spanY; j++) {
                        if (i >= mCountX || j >= mCountY || mView.isOccupied(i, j)) {
                            fits = false;
                            break;
                        }
                    }
                }
                if (fits) {
                    return x0 + mCountX * y0;
                }
            }
        }
        return INVALID_POSITION;
    } else {
        // For an icon, we simply check the view directly below
        View child = mView.getChildAt(x, y);
        if (child == null || child == dragInfo.item) {
            // Empty cell. Good for an icon or folder.
            return id;
        } else if (dragInfo.dragType != DragType.FOLDER) {
            // For icons, we can consider cells that have another icon or a folder.
            ItemInfo info = (ItemInfo) child.getTag();
            if (info instanceof AppInfo || info instanceof FolderInfo || info instanceof WorkspaceItemInfo) {
                return id;
            }
        }
        return INVALID_POSITION;
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) View(android.view.View) FolderInfo(com.android.launcher3.model.data.FolderInfo) AppInfo(com.android.launcher3.model.data.AppInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 73 with Widget

use of com.android.launcher3.tapl.Widget in project android_packages_apps_Trebuchet by LineageOS.

the class LauncherAppWidgetHost method createView.

public AppWidgetHostView createView(Context context, int appWidgetId, LauncherAppWidgetProviderInfo appWidget) {
    if (appWidget.isCustomWidget()) {
        LauncherAppWidgetHostView lahv = new LauncherAppWidgetHostView(context);
        lahv.setAppWidget(0, appWidget);
        CustomWidgetManager.INSTANCE.get(context).onViewCreated(lahv);
        return lahv;
    } else if ((mFlags & FLAG_LISTENING) == 0) {
        DeferredAppWidgetHostView view = new DeferredAppWidgetHostView(context);
        view.setAppWidget(appWidgetId, appWidget);
        mViews.put(appWidgetId, view);
        return view;
    } else {
        try {
            return super.createView(context, appWidgetId, appWidget);
        } catch (Exception e) {
            if (!Utilities.isBinderSizeError(e)) {
                throw new RuntimeException(e);
            }
            // If the exception was thrown while fetching the remote views, let the view stay.
            // This will ensure that if the widget posts a valid update later, the view
            // will update.
            LauncherAppWidgetHostView view = mViews.get(appWidgetId);
            if (view == null) {
                view = onCreateView(mContext, appWidgetId, appWidget);
            }
            view.setAppWidget(appWidgetId, appWidget);
            view.switchToErrorView();
            return view;
        }
    }
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) DeferredAppWidgetHostView(com.android.launcher3.widget.DeferredAppWidgetHostView) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 74 with Widget

use of com.android.launcher3.tapl.Widget in project android_packages_apps_Trebuchet by LineageOS.

the class AddConfigWidgetTest method runTest.

/**
 * @param acceptConfig accept the config activity
 */
private void runTest(boolean acceptConfig) throws Throwable {
    clearHomescreen();
    mDevice.pressHome();
    final Widgets widgets = mLauncher.getWorkspace().openAllWidgets();
    // Drag widget to homescreen
    WidgetConfigStartupMonitor monitor = new WidgetConfigStartupMonitor();
    widgets.getWidget(mWidgetInfo.getLabel(mTargetContext.getPackageManager())).dragToWorkspace(true, false);
    // Widget id for which the config activity was opened
    mWidgetId = monitor.getWidgetId();
    // Verify that the widget id is valid and bound
    assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
    setResult(acceptConfig);
    if (acceptConfig) {
        Wait.atMost("", new WidgetSearchCondition(), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
        assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
    } else {
        // Verify that the widget id is deleted.
        Wait.atMost("", () -> mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null, DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
    }
}
Also used : Widgets(com.android.launcher3.tapl.Widgets)

Example 75 with Widget

use of com.android.launcher3.tapl.Widget in project android_packages_apps_Trebuchet by LineageOS.

the class BindWidgetTest method verifyWidgetPresent.

private void verifyWidgetPresent(LauncherAppWidgetProviderInfo info) {
    final Widget widget = mLauncher.getWorkspace().tryGetWidget(info.label, DEFAULT_UI_TIMEOUT);
    assertTrue("Widget is not present", widget != null);
}
Also used : Widget(com.android.launcher3.tapl.Widget)

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