Search in sources :

Example 1 with PopupContainerWithArrow

use of com.android.launcher3.popup.PopupContainerWithArrow in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherAccessibilityDelegate method getSupportedActions.

/**
 * Returns all the accessibility actions that can be handled by the host.
 */
public static List<LauncherAction> getSupportedActions(Launcher launcher, View host) {
    if (host == null || !(host.getTag() instanceof ItemInfo)) {
        return Collections.emptyList();
    }
    PopupContainerWithArrow container = PopupContainerWithArrow.getOpen(launcher);
    LauncherAccessibilityDelegate delegate = container != null ? container.getAccessibilityDelegate() : launcher.getAccessibilityDelegate();
    List<LauncherAction> result = new ArrayList<>();
    delegate.getSupportedActions(host, (ItemInfo) host.getTag(), result);
    return result;
}
Also used : PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow)

Example 2 with PopupContainerWithArrow

use of com.android.launcher3.popup.PopupContainerWithArrow in project android_packages_apps_Launcher3 by crdroidandroid.

the class PopupContainerWithArrow method showForIcon.

/**
 * Shows the notifications and deep shortcuts associated with {@param icon}.
 * @return the container if shown or null.
 */
public static PopupContainerWithArrow showForIcon(BubbleTextView icon) {
    Launcher launcher = Launcher.getLauncher(icon.getContext());
    if (getOpen(launcher) != null) {
        // There is already an items container open, so don't open this one.
        icon.clearFocus();
        return null;
    }
    ItemInfo item = (ItemInfo) icon.getTag();
    if (!canShow(icon, item)) {
        return null;
    }
    final PopupContainerWithArrow container = (PopupContainerWithArrow) launcher.getLayoutInflater().inflate(R.layout.popup_container, launcher.getDragLayer(), false);
    container.configureForLauncher(launcher);
    PopupDataProvider popupDataProvider = launcher.getPopupDataProvider();
    container.populateAndShow(icon, popupDataProvider.getShortcutCountForItem(item), popupDataProvider.getNotificationKeysForItem(item), launcher.getSupportedShortcuts().map(s -> s.getShortcut(launcher, item)).filter(Objects::nonNull).collect(Collectors.toList()));
    launcher.refreshAndBindWidgetsForPackageUser(PackageUserKey.fromItemInfo(item));
    container.requestFocus();
    return container;
}
Also used : Rect(android.graphics.Rect) PointF(android.graphics.PointF) Arrays(java.util.Arrays) ImageView(android.widget.ImageView) DraggableView(com.android.launcher3.dragndrop.DraggableView) BubbleTextView(com.android.launcher3.BubbleTextView) LayoutTransition(android.animation.LayoutTransition) AttributeSet(android.util.AttributeSet) Handler(android.os.Handler) Looper(android.os.Looper) Map(java.util.Map) View(android.view.View) TargetApi(android.annotation.TargetApi) MAX_SHORTCUTS_IF_NOTIFICATIONS(com.android.launcher3.popup.PopupPopulator.MAX_SHORTCUTS_IF_NOTIFICATIONS) Utilities(com.android.launcher3.Utilities) ShortcutMenuAccessibilityDelegate(com.android.launcher3.accessibility.ShortcutMenuAccessibilityDelegate) Launcher(com.android.launcher3.Launcher) ShortcutDragPreviewProvider(com.android.launcher3.shortcuts.ShortcutDragPreviewProvider) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) ViewGroup(android.view.ViewGroup) LauncherAccessibilityDelegate(com.android.launcher3.accessibility.LauncherAccessibilityDelegate) NotificationInfo(com.android.launcher3.notification.NotificationInfo) DragOptions(com.android.launcher3.dragndrop.DragOptions) Objects(java.util.Objects) List(java.util.List) ShortcutUtil(com.android.launcher3.util.ShortcutUtil) Context(android.content.Context) MODEL_EXECUTOR(com.android.launcher3.util.Executors.MODEL_EXECUTOR) ItemInfo(com.android.launcher3.model.data.ItemInfo) Utilities.squaredTouchSlop(com.android.launcher3.Utilities.squaredTouchSlop) NotificationKeyData(com.android.launcher3.notification.NotificationKeyData) ArrayList(java.util.ArrayList) BaseDragLayer(com.android.launcher3.views.BaseDragLayer) NotificationContainer(com.android.launcher3.notification.NotificationContainer) ItemLongClickListener(com.android.launcher3.touch.ItemLongClickListener) Utilities.squaredHypot(com.android.launcher3.Utilities.squaredHypot) MAX_SHORTCUTS(com.android.launcher3.popup.PopupPopulator.MAX_SHORTCUTS) MotionEvent(android.view.MotionEvent) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) DragObject(com.android.launcher3.DropTarget.DragObject) AnimatorSet(android.animation.AnimatorSet) Build(android.os.Build) DragSource(com.android.launcher3.DragSource) DropTarget(com.android.launcher3.DropTarget) PopupDataChangeListener(com.android.launcher3.popup.PopupDataProvider.PopupDataChangeListener) CONTAINER_SHORTCUTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS) DragController(com.android.launcher3.dragndrop.DragController) StatefulActivity(com.android.launcher3.statemanager.StatefulActivity) PackageUserKey(com.android.launcher3.util.PackageUserKey) Point(android.graphics.Point) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) BaseDraggingActivity(com.android.launcher3.BaseDraggingActivity) LauncherState(com.android.launcher3.LauncherState) R(com.android.launcher3.R) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) DragView(com.android.launcher3.dragndrop.DragView) DotInfo(com.android.launcher3.dot.DotInfo) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Objects(java.util.Objects) Launcher(com.android.launcher3.Launcher)

Example 3 with PopupContainerWithArrow

use of com.android.launcher3.popup.PopupContainerWithArrow in project android_packages_apps_Launcher3 by crdroidandroid.

the class PopupPopulator method createUpdateRunnable.

/**
 * Returns a runnable to update the provided shortcuts and notifications
 */
public static Runnable createUpdateRunnable(final BaseDraggingActivity launcher, final ItemInfo originalInfo, final Handler uiHandler, final PopupContainerWithArrow container, final List<DeepShortcutView> shortcutViews, final List<NotificationKeyData> notificationKeys) {
    final ComponentName activity = originalInfo.getTargetComponent();
    final UserHandle user = originalInfo.user;
    return () -> {
        if (!notificationKeys.isEmpty()) {
            NotificationListener notificationListener = NotificationListener.getInstanceIfConnected();
            final List<NotificationInfo> infos;
            if (notificationListener == null) {
                infos = Collections.emptyList();
            } else {
                infos = notificationListener.getNotificationsForKeys(notificationKeys).stream().map(sbn -> new NotificationInfo(launcher, sbn, originalInfo)).collect(Collectors.toList());
            }
            uiHandler.post(() -> container.applyNotificationInfos(infos));
        }
        List<ShortcutInfo> shortcuts = new ShortcutRequest(launcher, user).withContainer(activity).query(ShortcutRequest.PUBLISHED);
        String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null : notificationKeys.get(0).shortcutId;
        shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe);
        IconCache cache = LauncherAppState.getInstance(launcher).getIconCache();
        for (int i = 0; i < shortcuts.size() && i < shortcutViews.size(); i++) {
            final ShortcutInfo shortcut = shortcuts.get(i);
            final WorkspaceItemInfo si = new WorkspaceItemInfo(shortcut, launcher);
            cache.getUnbadgedShortcutIcon(si, shortcut);
            si.rank = i;
            si.container = CONTAINER_SHORTCUTS;
            final DeepShortcutView view = shortcutViews.get(i);
            uiHandler.post(() -> view.applyShortcutInfo(si, shortcut, container));
        }
    };
}
Also used : Iterator(java.util.Iterator) ComponentName(android.content.ComponentName) ShortcutInfo(android.content.pm.ShortcutInfo) CONTAINER_SHORTCUTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS) LauncherAppState(com.android.launcher3.LauncherAppState) ItemInfo(com.android.launcher3.model.data.ItemInfo) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) BaseDraggingActivity(com.android.launcher3.BaseDraggingActivity) IconCache(com.android.launcher3.icons.IconCache) Collectors(java.util.stream.Collectors) NotificationInfo(com.android.launcher3.notification.NotificationInfo) NotificationKeyData(com.android.launcher3.notification.NotificationKeyData) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(androidx.annotation.Nullable) NotificationListener(com.android.launcher3.notification.NotificationListener) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Handler(android.os.Handler) UserHandle(android.os.UserHandle) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) Comparator(java.util.Comparator) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) NotificationInfo(com.android.launcher3.notification.NotificationInfo) ShortcutInfo(android.content.pm.ShortcutInfo) UserHandle(android.os.UserHandle) IconCache(com.android.launcher3.icons.IconCache) ComponentName(android.content.ComponentName) ArrayList(java.util.ArrayList) List(java.util.List) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) NotificationListener(com.android.launcher3.notification.NotificationListener) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 4 with PopupContainerWithArrow

use of com.android.launcher3.popup.PopupContainerWithArrow in project android_packages_apps_Launcher3 by crdroidandroid.

the class SecondaryDragLayer method onIconLongClicked.

private boolean onIconLongClicked(View v) {
    if (!(v instanceof BubbleTextView)) {
        return false;
    }
    if (PopupContainerWithArrow.getOpen(mActivity) != null) {
        // There is already an items container open, so don't open this one.
        v.clearFocus();
        return false;
    }
    ItemInfo item = (ItemInfo) v.getTag();
    if (!ShortcutUtil.supportsShortcuts(item)) {
        return false;
    }
    final PopupContainerWithArrow container = (PopupContainerWithArrow) mActivity.getLayoutInflater().inflate(R.layout.popup_container, mActivity.getDragLayer(), false);
    container.populateAndShow((BubbleTextView) v, mActivity.getPopupDataProvider().getShortcutCountForItem(item), Collections.emptyList(), Arrays.asList(mPinnedAppsAdapter.getSystemShortcut(item), APP_INFO.getShortcut(mActivity, item)));
    v.getParent().requestDisallowInterceptTouchEvent(true);
    return true;
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) BubbleTextView(com.android.launcher3.BubbleTextView)

Example 5 with PopupContainerWithArrow

use of com.android.launcher3.popup.PopupContainerWithArrow in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method beginDragShared.

/**
 * Core functionality for beginning a drag operation for an item that will be dropped within
 * the workspace
 */
public DragView beginDragShared(View child, DraggableView draggableView, DragSource source, ItemInfo dragObject, DragPreviewProvider previewProvider, DragOptions dragOptions) {
    float iconScale = 1f;
    if (child instanceof BubbleTextView) {
        Drawable icon = ((BubbleTextView) child).getIcon();
        if (icon instanceof FastBitmapDrawable) {
            iconScale = ((FastBitmapDrawable) icon).getAnimatedScale();
        }
    }
    // Clear the pressed state if necessary
    child.clearFocus();
    child.setPressed(false);
    if (child instanceof BubbleTextView) {
        BubbleTextView icon = (BubbleTextView) child;
        icon.clearPressedBackground();
    }
    mOutlineProvider = previewProvider;
    if (draggableView == null && child instanceof DraggableView) {
        draggableView = (DraggableView) child;
    }
    final View contentView = previewProvider.getContentView();
    final float scale;
    // The draggable drawable follows the touch point around on the screen
    final Drawable drawable;
    if (contentView == null) {
        drawable = previewProvider.createDrawable();
        scale = previewProvider.getScaleAndPosition(drawable, mTempXY);
    } else {
        drawable = null;
        scale = previewProvider.getScaleAndPosition(contentView, mTempXY);
    }
    int halfPadding = previewProvider.previewPadding / 2;
    int dragLayerX = mTempXY[0];
    int dragLayerY = mTempXY[1];
    Point dragVisualizeOffset = null;
    Rect dragRect = new Rect();
    if (draggableView != null) {
        draggableView.getSourceVisualDragBounds(dragRect);
        dragLayerY += dragRect.top;
        dragVisualizeOffset = new Point(-halfPadding, halfPadding);
    }
    if (child.getParent() instanceof ShortcutAndWidgetContainer) {
        mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();
    }
    if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) {
        PopupContainerWithArrow popupContainer = PopupContainerWithArrow.showForIcon((BubbleTextView) child);
        if (popupContainer != null) {
            dragOptions.preDragCondition = popupContainer.createPreDragCondition();
        }
    }
    final DragView dv;
    if (contentView instanceof View) {
        if (contentView instanceof LauncherAppWidgetHostView) {
            mDragController.addDragListener(new AppWidgetHostViewDragListener(mLauncher));
        }
        dv = mDragController.startDrag(contentView, draggableView, dragLayerX, dragLayerY, source, dragObject, dragVisualizeOffset, dragRect, scale * iconScale, scale, dragOptions);
    } else {
        dv = mDragController.startDrag(drawable, draggableView, dragLayerX, dragLayerY, source, dragObject, dragVisualizeOffset, dragRect, scale * iconScale, scale, dragOptions);
    }
    return dv;
}
Also used : Rect(android.graphics.Rect) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) DragView(com.android.launcher3.dragndrop.DragView) Point(android.graphics.Point) DraggableView(com.android.launcher3.dragndrop.DraggableView) 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) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) AppWidgetHostViewDragListener(com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView)

Aggregations

ItemInfo (com.android.launcher3.model.data.ItemInfo)4 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)3 ArrayList (java.util.ArrayList)3 Point (android.graphics.Point)2 Rect (android.graphics.Rect)2 Handler (android.os.Handler)2 View (android.view.View)2 BaseDraggingActivity (com.android.launcher3.BaseDraggingActivity)2 BubbleTextView (com.android.launcher3.BubbleTextView)2 CONTAINER_SHORTCUTS (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS)2 NotificationInfo (com.android.launcher3.notification.NotificationInfo)2 NotificationKeyData (com.android.launcher3.notification.NotificationKeyData)2 PopupContainerWithArrow (com.android.launcher3.popup.PopupContainerWithArrow)2 DeepShortcutView (com.android.launcher3.shortcuts.DeepShortcutView)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 AnimatorSet (android.animation.AnimatorSet)1 LayoutTransition (android.animation.LayoutTransition)1 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1