Search in sources :

Example 1 with DeepShortcutView

use of com.android.launcher3.shortcuts.DeepShortcutView in project android_packages_apps_Launcher3 by crdroidandroid.

the class PopupContainerWithArrow method initializeSystemShortcut.

private void initializeSystemShortcut(int resId, ViewGroup container, SystemShortcut info) {
    View view = inflateAndAdd(resId, container, getInsertIndexForSystemShortcut(container, info));
    if (view instanceof DeepShortcutView) {
        // Expanded system shortcut, with both icon and text shown on white background.
        final DeepShortcutView shortcutView = (DeepShortcutView) view;
        info.setIconAndLabelFor(shortcutView.getIconView(), shortcutView.getBubbleText());
    } else if (view instanceof ImageView) {
        // Only the system shortcut icon shows on a gray background header.
        info.setIconAndContentDescriptionFor((ImageView) view);
        view.setTooltipText(view.getContentDescription());
    }
    view.setTag(info);
    view.setOnClickListener(info);
}
Also used : ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) DraggableView(com.android.launcher3.dragndrop.DraggableView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) DragView(com.android.launcher3.dragndrop.DragView) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView)

Example 2 with DeepShortcutView

use of com.android.launcher3.shortcuts.DeepShortcutView 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 3 with DeepShortcutView

use of com.android.launcher3.shortcuts.DeepShortcutView in project android_packages_apps_Launcher3 by crdroidandroid.

the class OptionsPopupView method show.

public static OptionsPopupView show(Launcher launcher, RectF targetRect, List<OptionItem> items, boolean shouldAddArrow, int width) {
    OptionsPopupView popup = (OptionsPopupView) launcher.getLayoutInflater().inflate(R.layout.longpress_options_menu, launcher.getDragLayer(), false);
    popup.mTargetRect = targetRect;
    popup.setShouldAddArrow(shouldAddArrow);
    for (OptionItem item : items) {
        DeepShortcutView view = (DeepShortcutView) popup.inflateAndAdd(R.layout.system_shortcut, popup);
        if (width > 0) {
            view.getLayoutParams().width = width;
        }
        view.getIconView().setBackgroundDrawable(item.icon);
        view.getBubbleText().setText(item.label);
        view.setOnClickListener(popup);
        view.setOnLongClickListener(popup);
        popup.mItemMap.put(view, item);
    }
    popup.addPreDrawForColorExtraction(launcher);
    popup.show();
    return popup;
}
Also used : DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView)

Example 4 with DeepShortcutView

use of com.android.launcher3.shortcuts.DeepShortcutView in project android_packages_apps_Launcher3 by crdroidandroid.

the class ArrowPopup method assignMarginsAndBackgrounds.

/**
 * @param backgroundColor When Color.TRANSPARENT, we get color from {@link #mColors}.
 *                        Otherwise, we will use this color for all child views.
 */
private void assignMarginsAndBackgrounds(ViewGroup viewGroup, int backgroundColor) {
    final boolean getColorFromColorArray = backgroundColor == Color.TRANSPARENT;
    int count = viewGroup.getChildCount();
    int totalVisibleShortcuts = 0;
    for (int i = 0; i < count; i++) {
        View view = viewGroup.getChildAt(i);
        if (view.getVisibility() == VISIBLE && view instanceof DeepShortcutView) {
            totalVisibleShortcuts++;
        }
    }
    int numVisibleChild = 0;
    int numVisibleShortcut = 0;
    View lastView = null;
    AnimatorSet colorAnimator = new AnimatorSet();
    for (int i = 0; i < count; i++) {
        View view = viewGroup.getChildAt(i);
        if (view.getVisibility() == VISIBLE) {
            if (lastView != null) {
                MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams();
                mlp.bottomMargin = mMargin;
            }
            lastView = view;
            MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams();
            mlp.bottomMargin = 0;
            if (getColorFromColorArray) {
                backgroundColor = mColors[numVisibleChild % mColors.length];
            }
            if (view instanceof ViewGroup && mIterateChildrenTag.equals(view.getTag())) {
                assignMarginsAndBackgrounds((ViewGroup) view, backgroundColor);
                numVisibleChild++;
                continue;
            }
            if (view instanceof DeepShortcutView) {
                if (totalVisibleShortcuts == 1) {
                    view.setBackgroundResource(R.drawable.single_item_primary);
                } else if (totalVisibleShortcuts > 1) {
                    if (numVisibleShortcut == 0) {
                        view.setBackground(mRoundedTop.getConstantState().newDrawable());
                    } else if (numVisibleShortcut == (totalVisibleShortcuts - 1)) {
                        view.setBackground(mRoundedBottom.getConstantState().newDrawable());
                    } else {
                        view.setBackgroundResource(R.drawable.middle_item_primary);
                    }
                    numVisibleShortcut++;
                }
            }
            if (!ENABLE_LOCAL_COLOR_POPUPS.get()) {
                setChildColor(view, backgroundColor, colorAnimator);
                // Arrow color matches the first child or the last child.
                if (!mIsAboveIcon && numVisibleChild == 0) {
                    mArrowColor = backgroundColor;
                } else if (mIsAboveIcon) {
                    mArrowColor = backgroundColor;
                }
            }
            numVisibleChild++;
        }
    }
    colorAnimator.setDuration(0).start();
    measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
}
Also used : ViewGroup(android.view.ViewGroup) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView)

Example 5 with DeepShortcutView

use of com.android.launcher3.shortcuts.DeepShortcutView in project android_packages_apps_Launcher3 by crdroidandroid.

the class PopupContainerWithArrow method updateHiddenShortcuts.

private void updateHiddenShortcuts() {
    int allowedCount = mNotificationContainer != null ? MAX_SHORTCUTS_IF_NOTIFICATIONS : MAX_SHORTCUTS;
    int total = mShortcuts.size();
    for (int i = 0; i < total; i++) {
        DeepShortcutView view = mShortcuts.get(i);
        view.setVisibility(i >= allowedCount ? GONE : VISIBLE);
    }
}
Also used : Point(android.graphics.Point) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView)

Aggregations

DeepShortcutView (com.android.launcher3.shortcuts.DeepShortcutView)8 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)3 Point (android.graphics.Point)2 Handler (android.os.Handler)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)2 BubbleTextView (com.android.launcher3.BubbleTextView)2 ItemInfo (com.android.launcher3.model.data.ItemInfo)2 AnimatorSet (android.animation.AnimatorSet)1 LayoutTransition (android.animation.LayoutTransition)1 TargetApi (android.annotation.TargetApi)1 ComponentName (android.content.ComponentName)1 ShortcutInfo (android.content.pm.ShortcutInfo)1 AdaptiveIconDrawable (android.graphics.drawable.AdaptiveIconDrawable)1 Drawable (android.graphics.drawable.Drawable)1 UserHandle (android.os.UserHandle)1 ViewGroup (android.view.ViewGroup)1 Nullable (androidx.annotation.Nullable)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1