OSDN Git Service

Merge "Slightly round corners of popup arrow" into ub-launcher3-dorval
[android-x86/packages-apps-Launcher3.git] / src / com / android / launcher3 / popup / PopupContainerWithArrow.java
index 1eac076..5891085 100644 (file)
@@ -22,11 +22,12 @@ import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
 import android.animation.TimeInterpolator;
 import android.animation.ValueAnimator;
-import android.annotation.SuppressLint;
 import android.annotation.TargetApi;
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Color;
+import android.graphics.CornerPathEffect;
+import android.graphics.Paint;
 import android.graphics.PointF;
 import android.graphics.Rect;
 import android.graphics.drawable.ShapeDrawable;
@@ -47,6 +48,7 @@ import com.android.launcher3.AbstractFloatingView;
 import com.android.launcher3.BubbleTextView;
 import com.android.launcher3.DragSource;
 import com.android.launcher3.DropTarget;
+import com.android.launcher3.FastBitmapDrawable;
 import com.android.launcher3.ItemInfo;
 import com.android.launcher3.Launcher;
 import com.android.launcher3.LauncherAnimUtils;
@@ -63,8 +65,11 @@ import com.android.launcher3.badge.BadgeInfo;
 import com.android.launcher3.dragndrop.DragController;
 import com.android.launcher3.dragndrop.DragLayer;
 import com.android.launcher3.dragndrop.DragOptions;
+import com.android.launcher3.graphics.IconPalette;
 import com.android.launcher3.graphics.TriangleShape;
 import com.android.launcher3.notification.NotificationItemView;
+import com.android.launcher3.notification.NotificationKeyData;
+import com.android.launcher3.shortcuts.DeepShortcutManager;
 import com.android.launcher3.shortcuts.DeepShortcutView;
 import com.android.launcher3.shortcuts.ShortcutsItemView;
 import com.android.launcher3.util.PackageUserKey;
@@ -137,35 +142,37 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
             return null;
         }
         ItemInfo itemInfo = (ItemInfo) icon.getTag();
+        if (!DeepShortcutManager.supportsShortcuts(itemInfo)) {
+            return null;
+        }
+
         List<String> shortcutIds = launcher.getPopupDataProvider().getShortcutIdsForItem(itemInfo);
-        String[] notificationKeys = launcher.getPopupDataProvider()
+        List<NotificationKeyData> notificationKeys = launcher.getPopupDataProvider()
                 .getNotificationKeysForItem(itemInfo);
-        if (shortcutIds.size() > 0 || notificationKeys.length > 0) {
-            final PopupContainerWithArrow container =
-                    (PopupContainerWithArrow) launcher.getLayoutInflater().inflate(
-                            R.layout.popup_container, launcher.getDragLayer(), false);
-            container.setVisibility(View.INVISIBLE);
-            launcher.getDragLayer().addView(container);
-            container.populateAndShow(icon, shortcutIds, notificationKeys);
-            return container;
-        }
-        return null;
+
+        final PopupContainerWithArrow container =
+                (PopupContainerWithArrow) launcher.getLayoutInflater().inflate(
+                        R.layout.popup_container, launcher.getDragLayer(), false);
+        container.setVisibility(View.INVISIBLE);
+        launcher.getDragLayer().addView(container);
+        container.populateAndShow(icon, shortcutIds, notificationKeys);
+        return container;
     }
 
     public void populateAndShow(final BubbleTextView originalIcon, final List<String> shortcutIds,
-            final String[] notificationKeys) {
+            final List<NotificationKeyData> notificationKeys) {
         final Resources resources = getResources();
-        final int arrowWidth = resources.getDimensionPixelSize(R.dimen.deep_shortcuts_arrow_width);
-        final int arrowHeight = resources.getDimensionPixelSize(R.dimen.deep_shortcuts_arrow_height);
+        final int arrowWidth = resources.getDimensionPixelSize(R.dimen.popup_arrow_width);
+        final int arrowHeight = resources.getDimensionPixelSize(R.dimen.popup_arrow_height);
         final int arrowHorizontalOffset = resources.getDimensionPixelSize(
-                R.dimen.deep_shortcuts_arrow_horizontal_offset);
+                R.dimen.popup_arrow_horizontal_offset);
         final int arrowVerticalOffset = resources.getDimensionPixelSize(
-                R.dimen.deep_shortcuts_arrow_vertical_offset);
+                R.dimen.popup_arrow_vertical_offset);
 
         // Add dummy views first, and populate with real info when ready.
         PopupPopulator.Item[] itemsToPopulate = PopupPopulator
                 .getItemsToPopulate(shortcutIds, notificationKeys);
-        addDummyViews(originalIcon, itemsToPopulate, notificationKeys.length > 1);
+        addDummyViews(originalIcon, itemsToPopulate, notificationKeys.size() > 1);
 
         measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
         orientAboutIcon(originalIcon, arrowHeight + arrowVerticalOffset);
@@ -176,7 +183,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
             mNotificationItemView = null;
             mShortcutsItemView = null;
             itemsToPopulate = PopupPopulator.reverseItems(itemsToPopulate);
-            addDummyViews(originalIcon, itemsToPopulate, notificationKeys.length > 1);
+            addDummyViews(originalIcon, itemsToPopulate, notificationKeys.size() > 1);
 
             measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
             orientAboutIcon(originalIcon, arrowHeight + arrowVerticalOffset);
@@ -186,10 +193,13 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
         List<DeepShortcutView> shortcutViews = mShortcutsItemView == null
                 ? Collections.EMPTY_LIST
                 : mShortcutsItemView.getDeepShortcutViews(reverseOrder);
+        List<View> systemShortcutViews = mShortcutsItemView == null
+                ? Collections.EMPTY_LIST
+                : mShortcutsItemView.getSystemShortcutViews(reverseOrder);
         if (mNotificationItemView != null) {
             BadgeInfo badgeInfo = mLauncher.getPopupDataProvider()
                     .getBadgeInfoForItem(originalItemInfo);
-            updateNotificationHeader(badgeInfo);
+            updateNotificationHeader(badgeInfo, originalIcon);
         }
 
         // Add the arrow.
@@ -207,7 +217,8 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
         final Looper workerLooper = LauncherModel.getWorkerLooper();
         new Handler(workerLooper).postAtFrontOfQueue(PopupPopulator.createUpdateRunnable(
                 mLauncher, originalItemInfo, new Handler(Looper.getMainLooper()),
-                this, shortcutIds, shortcutViews, notificationKeys, mNotificationItemView));
+                this, shortcutIds, shortcutViews, notificationKeys, mNotificationItemView,
+                systemShortcutViews));
     }
 
     private void addDummyViews(BubbleTextView originalIcon,
@@ -215,9 +226,12 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
         final Resources res = getResources();
         final int spacing = res.getDimensionPixelSize(R.dimen.popup_items_spacing);
         final LayoutInflater inflater = mLauncher.getLayoutInflater();
+
         int numItems = itemTypesToPopulate.length;
         for (int i = 0; i < numItems; i++) {
             PopupPopulator.Item itemTypeToPopulate = itemTypesToPopulate[i];
+            PopupPopulator.Item nextItemTypeToPopulate =
+                    i < numItems - 1 ? itemTypesToPopulate[i + 1] : null;
             final View item = inflater.inflate(itemTypeToPopulate.layoutId, this, false);
 
             if (itemTypeToPopulate == PopupPopulator.Item.NOTIFICATION) {
@@ -227,23 +241,23 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
                 item.findViewById(R.id.footer).getLayoutParams().height = footerHeight;
             }
 
-            boolean itemIsFollowedByDifferentType = i < numItems - 1
-                    && itemTypesToPopulate[i + 1] != itemTypeToPopulate;
+            boolean shouldAddBottomMargin = nextItemTypeToPopulate != null
+                    && itemTypeToPopulate.isShortcut ^ nextItemTypeToPopulate.isShortcut;
 
             item.setAccessibilityDelegate(mAccessibilityDelegate);
-            if (itemTypeToPopulate == PopupPopulator.Item.SHORTCUT) {
+            if (itemTypeToPopulate.isShortcut) {
                 if (mShortcutsItemView == null) {
                     mShortcutsItemView = (ShortcutsItemView) inflater.inflate(
                             R.layout.shortcuts_item, this, false);
                     addView(mShortcutsItemView);
                 }
-                mShortcutsItemView.addDeepShortcutView((DeepShortcutView) item);
-                if (itemIsFollowedByDifferentType) {
+                mShortcutsItemView.addShortcutView(item, itemTypeToPopulate);
+                if (shouldAddBottomMargin) {
                     ((LayoutParams) mShortcutsItemView.getLayoutParams()).bottomMargin = spacing;
                 }
             } else {
                 addView(item);
-                if (itemIsFollowedByDifferentType) {
+                if (shouldAddBottomMargin) {
                     ((LayoutParams) item.getLayoutParams()).bottomMargin = spacing;
                 }
             }
@@ -374,14 +388,14 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
             // Aligning with the shortcut icon.
             int shortcutIconWidth = resources.getDimensionPixelSize(R.dimen.deep_shortcut_icon_size);
             int shortcutPaddingStart = resources.getDimensionPixelSize(
-                    R.dimen.deep_shortcut_padding_start);
+                    R.dimen.popup_padding_start);
             xOffset = iconWidth / 2 - shortcutIconWidth / 2 - shortcutPaddingStart;
         } else {
             // Aligning with the drag handle.
             int shortcutDragHandleWidth = resources.getDimensionPixelSize(
                     R.dimen.deep_shortcut_drag_handle_size);
             int shortcutPaddingEnd = resources.getDimensionPixelSize(
-                    R.dimen.deep_shortcut_padding_end);
+                    R.dimen.popup_padding_end);
             xOffset = iconWidth / 2 - shortcutDragHandleWidth / 2 - shortcutPaddingEnd;
         }
         x += mIsLeftAligned ? xOffset : -xOffset;
@@ -474,7 +488,11 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
         } else {
             ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
                     width, height, !mIsAboveIcon));
-            arrowDrawable.getPaint().setColor(Color.WHITE);
+            Paint arrowPaint = arrowDrawable.getPaint();
+            arrowPaint.setColor(Color.WHITE);
+            // The corner path effect won't be reflected in the shadow, but shouldn't be noticeable.
+            int radius = getResources().getDimensionPixelSize(R.dimen.popup_arrow_corner_radius);
+            arrowPaint.setPathEffect(new CornerPathEffect(radius));
             arrowView.setBackground(arrowDrawable);
             arrowView.setElevation(getElevation());
         }
@@ -530,15 +548,6 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
     }
 
     /**
-     * We need to handle touch events to prevent them from falling through to the workspace below.
-     */
-    @SuppressLint("ClickableViewAccessibility")
-    @Override
-    public boolean onTouchEvent(MotionEvent ev) {
-        return true;
-    }
-
-    /**
      * Updates the notification header to reflect the badge info. Since this can be called
      * for any badge info (not necessarily the one associated with this app), we first
      * check that the ItemInfo matches the one of this popup.
@@ -547,12 +556,15 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
         if (originalItemInfo != mOriginalIcon.getTag()) {
             return;
         }
-        updateNotificationHeader(badgeInfo);
+        updateNotificationHeader(badgeInfo, mOriginalIcon);
     }
 
-    private void updateNotificationHeader(BadgeInfo badgeInfo) {
+    private void updateNotificationHeader(BadgeInfo badgeInfo, BubbleTextView originalIcon) {
         if (mNotificationItemView != null && badgeInfo != null) {
-            mNotificationItemView.updateHeader(badgeInfo.getNotificationCount());
+            IconPalette palette = originalIcon.getIcon() instanceof FastBitmapDrawable
+                    ? ((FastBitmapDrawable) originalIcon.getIcon()).getIconPalette()
+                    : null;
+            mNotificationItemView.updateHeader(badgeInfo.getNotificationCount(), palette);
         }
     }
 
@@ -606,7 +618,18 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
             removeNotification.start();
             return;
         }
-        mNotificationItemView.trimNotifications(badgeInfo.getNotificationKeys());
+        mNotificationItemView.trimNotifications(NotificationKeyData.extractKeysOnly(
+                badgeInfo.getNotificationKeys()));
+    }
+
+    @Override
+    protected void onWidgetsBound() {
+        enableWidgets();
+    }
+
+    public boolean enableWidgets() {
+        return mShortcutsItemView != null && mShortcutsItemView.enableWidgets(
+                (ItemInfo) mOriginalIcon.getTag());
     }
 
     private ObjectAnimator createArrowScaleAnim(float scale) {