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;
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;
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;
return null;
}
ItemInfo itemInfo = (ItemInfo) icon.getTag();
+ if (!DeepShortcutManager.supportsShortcuts(itemInfo)) {
+ return null;
+ }
+
List<String> shortcutIds = launcher.getPopupDataProvider().getShortcutIdsForItem(itemInfo);
List<NotificationKeyData> notificationKeys = launcher.getPopupDataProvider()
.getNotificationKeysForItem(itemInfo);
- if (shortcutIds.size() > 0 || notificationKeys.size() > 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 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
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.
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,
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) {
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;
}
}
// 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;
} 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());
}
}
/**
- * 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.
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);
}
}
badgeInfo.getNotificationKeys()));
}
+ @Override
+ protected void onWidgetsBound() {
+ enableWidgets();
+ }
+
+ public boolean enableWidgets() {
+ return mShortcutsItemView != null && mShortcutsItemView.enableWidgets(
+ (ItemInfo) mOriginalIcon.getTag());
+ }
+
private ObjectAnimator createArrowScaleAnim(float scale) {
return LauncherAnimUtils.ofPropertyValuesHolder(
mArrow, new PropertyListBuilder().scale(scale).build());