Search in sources :

Example 86 with Widget

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

the class ItemClickHandler method onClickPendingWidget.

/**
 * Event handler for the app widget view which has not fully restored.
 */
private static void onClickPendingWidget(PendingAppWidgetHostView v, Launcher launcher) {
    if (launcher.getPackageManager().isSafeMode()) {
        Toast.makeText(launcher, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
        return;
    }
    final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
    if (v.isReadyForClickSetup()) {
        LauncherAppWidgetProviderInfo appWidgetInfo = new WidgetManagerHelper(launcher).findProvider(info.providerName, info.user);
        if (appWidgetInfo == null) {
            return;
        }
        WidgetAddFlowHandler addFlowHandler = new WidgetAddFlowHandler(appWidgetInfo);
        if (info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
            if (!info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
                // This should not happen, as we make sure that an Id is allocated during bind.
                return;
            }
            addFlowHandler.startBindFlow(launcher, info.appWidgetId, info, REQUEST_BIND_PENDING_APPWIDGET);
        } else {
            addFlowHandler.startConfigActivity(launcher, info, REQUEST_RECONFIGURE_APPWIDGET);
        }
    } else {
        final String packageName = info.providerName.getPackageName();
        onClickPendingAppItem(v, launcher, packageName, info.installProgress >= 0);
    }
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) WidgetAddFlowHandler(com.android.launcher3.widget.WidgetAddFlowHandler)

Example 87 with Widget

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

the class WidgetsListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(WidgetsRowViewHolder holder, int pos) {
    WidgetListRowEntry entry = mEntries.get(pos);
    List<WidgetItem> infoList = entry.widgets;
    ViewGroup row = holder.cellContainer;
    if (DEBUG) {
        Log.d(TAG, String.format("onBindViewHolder [pos=%d, widget#=%d, row.getChildCount=%d]", pos, infoList.size(), row.getChildCount()));
    }
    // Add more views.
    // if there are too many, hide them.
    int expectedChildCount = infoList.size() + Math.max(0, infoList.size() - 1);
    int childCount = row.getChildCount();
    if (expectedChildCount > childCount) {
        for (int i = childCount; i < expectedChildCount; i++) {
            if ((i & 1) == 1) {
                // Add a divider for odd index
                mLayoutInflater.inflate(R.layout.widget_list_divider, row);
            } else {
                // Add cell for even index
                WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(R.layout.widget_cell, row, false);
                // set up touch.
                widget.setOnClickListener(mIconClickListener);
                widget.setOnLongClickListener(mIconLongClickListener);
                row.addView(widget);
            }
        }
    } else if (expectedChildCount < childCount) {
        for (int i = expectedChildCount; i < childCount; i++) {
            row.getChildAt(i).setVisibility(View.GONE);
        }
    }
    // Bind the views in the application info section.
    holder.title.applyFromPackageItemInfo(entry.pkgItem);
    // Bind the view in the widget horizontal tray region.
    for (int i = 0; i < infoList.size(); i++) {
        WidgetCell widget = (WidgetCell) row.getChildAt(2 * i);
        widget.applyFromCellItem(infoList.get(i), mWidgetPreviewLoader);
        widget.setApplyBitmapDeferred(mApplyBitmapDeferred);
        widget.ensurePreview();
        widget.setVisibility(View.VISIBLE);
        if (i > 0) {
            row.getChildAt(2 * i - 1).setVisibility(View.VISIBLE);
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 88 with Widget

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

the class WidgetsModel method setWidgetsAndShortcuts.

private synchronized void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts, LauncherAppState app, @Nullable PackageUserKey packageUser) {
    if (DEBUG) {
        Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());
    }
    // Temporary list for {@link PackageItemInfos} to avoid having to go through
    // {@link mPackageItemInfos} to locate the key to be used for {@link #mWidgetsList}
    HashMap<String, PackageItemInfo> tmpPackageItemInfos = new HashMap<>();
    // clear the lists.
    if (packageUser == null) {
        mWidgetsList.clear();
    } else {
        // Only clear the widgets for the given package/user.
        PackageItemInfo packageItem = null;
        for (PackageItemInfo item : mWidgetsList.keySet()) {
            if (item.packageName.equals(packageUser.mPackageName)) {
                packageItem = item;
                break;
            }
        }
        if (packageItem != null) {
            // We want to preserve the user that was on the packageItem previously,
            // so add it to tmpPackageItemInfos here to avoid creating a new entry.
            tmpPackageItemInfos.put(packageItem.packageName, packageItem);
            Iterator<WidgetItem> widgetItemIterator = mWidgetsList.get(packageItem).iterator();
            while (widgetItemIterator.hasNext()) {
                WidgetItem nextWidget = widgetItemIterator.next();
                if (nextWidget.componentName.getPackageName().equals(packageUser.mPackageName) && nextWidget.user.equals(packageUser.mUser)) {
                    widgetItemIterator.remove();
                }
            }
        }
    }
    InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
    UserHandle myUser = Process.myUserHandle();
    // add and update.
    for (WidgetItem item : rawWidgetsShortcuts) {
        if (item.widgetInfo != null) {
            if ((item.widgetInfo.getWidgetFeatures() & WIDGET_FEATURE_HIDE_FROM_PICKER) != 0) {
                // Widget is hidden from picker
                continue;
            }
            // Ensure that all widgets we show can be added on a workspace of this size
            int minSpanX = Math.min(item.widgetInfo.spanX, item.widgetInfo.minSpanX);
            int minSpanY = Math.min(item.widgetInfo.spanY, item.widgetInfo.minSpanY);
            if (minSpanX > idp.numColumns || minSpanY > idp.numRows) {
                if (DEBUG) {
                    Log.d(TAG, String.format("Widget %s : (%d X %d) can't fit on this device", item.componentName, minSpanX, minSpanY));
                }
                continue;
            }
        }
        if (mAppFilter == null) {
            mAppFilter = AppFilter.newInstance(app.getContext());
        }
        if (!mAppFilter.shouldShowApp(item.componentName)) {
            if (DEBUG) {
                Log.d(TAG, String.format("%s is filtered and not added to the widget tray.", item.componentName));
            }
            continue;
        }
        String packageName = item.componentName.getPackageName();
        PackageItemInfo pInfo = tmpPackageItemInfos.get(packageName);
        if (pInfo == null) {
            pInfo = new PackageItemInfo(packageName);
            pInfo.user = item.user;
            tmpPackageItemInfos.put(packageName, pInfo);
        } else if (!myUser.equals(pInfo.user)) {
            // Keep updating the user, until we get the primary user.
            pInfo.user = item.user;
        }
        mWidgetsList.addToList(pInfo, item);
    }
    // Update each package entry
    IconCache iconCache = app.getIconCache();
    for (PackageItemInfo p : tmpPackageItemInfos.values()) {
        iconCache.getTitleAndIconForApp(p, true);
    }
}
Also used : HashMap(java.util.HashMap) MultiHashMap(com.android.launcher3.util.MultiHashMap) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) UserHandle(android.os.UserHandle) IconCache(com.android.launcher3.icons.IconCache) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo)

Example 89 with Widget

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

the class WidgetsModel method update.

/**
 * @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
 *                    only widgets and shortcuts associated with the package/user are.
 */
public List<ComponentWithLabelAndIcon> update(LauncherAppState app, @Nullable PackageUserKey packageUser) {
    Preconditions.assertWorkerThread();
    Context context = app.getContext();
    final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
    List<ComponentWithLabelAndIcon> updatedItems = new ArrayList<>();
    try {
        InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
        PackageManager pm = app.getContext().getPackageManager();
        // Widgets
        WidgetManagerHelper widgetManager = new WidgetManagerHelper(context);
        for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
            LauncherAppWidgetProviderInfo launcherWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
            widgetsAndShortcuts.add(new WidgetItem(launcherWidgetInfo, idp, app.getIconCache()));
            updatedItems.add(launcherWidgetInfo);
        }
        // Shortcuts
        for (ShortcutConfigActivityInfo info : queryList(context, packageUser)) {
            widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
            updatedItems.add(info);
        }
        setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
    } catch (Exception e) {
        if (!FeatureFlags.IS_STUDIO_BUILD && Utilities.isBinderSizeError(e)) {
        // the returned value may be incomplete and will not be refreshed until the next
        // time Launcher starts.
        // TODO: after figuring out a repro step, introduce a dirty bit to check when
        // onResume is called to refresh the widget provider list.
        } else {
            throw e;
        }
    }
    app.getWidgetCache().removeObsoletePreviews(widgetsAndShortcuts, packageUser);
    return updatedItems;
}
Also used : Context(android.content.Context) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ArrayList(java.util.ArrayList) PackageManager(android.content.pm.PackageManager) ComponentWithLabelAndIcon(com.android.launcher3.icons.ComponentWithLabelAndIcon) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper)

Example 90 with Widget

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

the class DragController method startDrag.

/**
 * Starts a drag.
 * When the drag is started, the UI automatically goes into spring loaded mode. On a successful
 * drop, it is the responsibility of the {@link DropTarget} to exit out of the spring loaded
 * mode. If the drop was cancelled for some reason, the UI will automatically exit out of this mode.
 *
 * @param b The bitmap to display as the drag image.  It will be re-scaled to the
 *          enlarged size.
 * @param originalView The source view (ie. icon, widget etc.) that is being dragged
 *          and which the DragView represents
 * @param dragLayerX The x position in the DragLayer of the left-top of the bitmap.
 * @param dragLayerY The y position in the DragLayer of the left-top of the bitmap.
 * @param source An object representing where the drag originated
 * @param dragInfo The data associated with the object that is being dragged
 * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
 *          Makes dragging feel more precise, e.g. you can clip out a transparent border
 */
public DragView startDrag(Bitmap b, DraggableView originalView, int dragLayerX, int dragLayerY, DragSource source, ItemInfo dragInfo, Point dragOffset, Rect dragRegion, float initialDragViewScale, float dragViewScaleOnDrop, DragOptions options) {
    if (PROFILE_DRAWING_DURING_DRAG) {
        android.os.Debug.startMethodTracing("Launcher");
    }
    mLauncher.hideKeyboard();
    AbstractFloatingView.closeOpenViews(mLauncher, false, TYPE_DISCOVERY_BOUNCE);
    mOptions = options;
    if (mOptions.simulatedDndStartPoint != null) {
        mLastTouch.x = mMotionDown.x = mOptions.simulatedDndStartPoint.x;
        mLastTouch.y = mMotionDown.y = mOptions.simulatedDndStartPoint.y;
    }
    final int registrationX = mMotionDown.x - dragLayerX;
    final int registrationY = mMotionDown.y - dragLayerY;
    final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left;
    final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top;
    mLastDropTarget = null;
    mDragObject = new DropTarget.DragObject(mLauncher.getApplicationContext());
    mDragObject.originalView = originalView;
    mIsInPreDrag = mOptions.preDragCondition != null && !mOptions.preDragCondition.shouldStartDrag(0);
    final Resources res = mLauncher.getResources();
    final float scaleDps = mIsInPreDrag ? res.getDimensionPixelSize(R.dimen.pre_drag_view_scale) : 0f;
    final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX, registrationY, initialDragViewScale, dragViewScaleOnDrop, scaleDps);
    dragView.setItemInfo(dragInfo);
    mDragObject.dragComplete = false;
    mDragObject.xOffset = mMotionDown.x - (dragLayerX + dragRegionLeft);
    mDragObject.yOffset = mMotionDown.y - (dragLayerY + dragRegionTop);
    mDragDriver = DragDriver.create(this, mOptions, mFlingToDeleteHelper::recordMotionEvent);
    if (!mOptions.isAccessibleDrag) {
        mDragObject.stateAnnouncer = DragViewStateAnnouncer.createFor(dragView);
    }
    mDragObject.dragSource = source;
    mDragObject.dragInfo = dragInfo;
    mDragObject.originalDragInfo = mDragObject.dragInfo.makeShallowCopy();
    if (dragOffset != null) {
        dragView.setDragVisualizeOffset(new Point(dragOffset));
    }
    if (dragRegion != null) {
        dragView.setDragRegion(new Rect(dragRegion));
    }
    mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    dragView.show(mLastTouch.x, mLastTouch.y);
    mDistanceSinceScroll = 0;
    if (!mIsInPreDrag) {
        callOnDragStart();
    } else if (mOptions.preDragCondition != null) {
        mOptions.preDragCondition.onPreDragStart(mDragObject);
    }
    handleMoveEvent(mLastTouch.x, mLastTouch.y);
    mLauncher.getUserEventDispatcher().resetActionDurationMillis();
    if (!mLauncher.isTouchInProgress() && options.simulatedDndStartPoint == null) {
        // If it is an internal drag and the touch is already complete, cancel immediately
        MAIN_EXECUTOR.submit(this::cancelDrag);
    }
    return dragView;
}
Also used : Rect(android.graphics.Rect) DropTarget(com.android.launcher3.DropTarget) Resources(android.content.res.Resources) Point(android.graphics.Point) Point(android.graphics.Point)

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