diff options
Diffstat (limited to 'src/com/android/launcher3/shortcuts')
-rw-r--r-- | src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java | 37 | ||||
-rw-r--r-- | src/com/android/launcher3/shortcuts/ShortcutsContainerListener.java | 36 |
2 files changed, 41 insertions, 32 deletions
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java index c9eee81e4..fdc0bd22f 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java @@ -30,6 +30,7 @@ import android.os.Handler; import android.os.Looper; import android.text.TextUtils; import android.util.AttributeSet; +import android.view.HapticFeedbackConstants; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -48,6 +49,7 @@ import com.android.launcher3.R; import com.android.launcher3.ShortcutInfo; import com.android.launcher3.Utilities; import com.android.launcher3.Workspace; +import com.android.launcher3.accessibility.ShortcutMenuAccessibilityDelegate; import com.android.launcher3.compat.UserHandleCompat; import com.android.launcher3.dragndrop.DragController; import com.android.launcher3.dragndrop.DragLayer; @@ -70,10 +72,12 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC UserEventDispatcher.LaunchSourceProvider { private static final String TAG = "ShortcutsContainer"; - private Launcher mLauncher; - private DeepShortcutManager mDeepShortcutsManager; + private final Launcher mLauncher; + private final DeepShortcutManager mDeepShortcutsManager; private final int mDragDeadzone; private final int mStartDragThreshold; + private final ShortcutMenuAccessibilityDelegate mAccessibilityDelegate; + private BubbleTextView mDeferredDragIcon; private int mActivePointerId; private int[] mTouchDown = null; @@ -115,6 +119,7 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC mDragDeadzone = ViewConfiguration.get(context).getScaledTouchSlop(); mStartDragThreshold = getResources().getDimensionPixelSize( R.dimen.deep_shortcuts_start_drag_threshold); + mAccessibilityDelegate = new ShortcutMenuAccessibilityDelegate(mLauncher); } public DeepShortcutsContainer(Context context, AttributeSet attrs) { @@ -128,12 +133,14 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC public void populateAndShow(final BubbleTextView originalIcon, final List<String> ids) { // Add dummy views first, and populate with real shortcut info when ready. final int spacing = getResources().getDimensionPixelSize(R.dimen.deep_shortcuts_spacing); - final LayoutInflater inflator = mLauncher.getLayoutInflater(); + final LayoutInflater inflater = mLauncher.getLayoutInflater(); for (int i = 0; i < ids.size(); i++) { - final View shortcut = inflator.inflate(R.layout.deep_shortcut, this, false); + final DeepShortcutView shortcut = + (DeepShortcutView) inflater.inflate(R.layout.deep_shortcut, this, false); if (i < ids.size() - 1) { ((LayoutParams) shortcut.getLayoutParams()).bottomMargin = spacing; } + shortcut.getBubbleText().setAccessibilityDelegate(mAccessibilityDelegate); addView(shortcut); } @@ -501,4 +508,26 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC // TODO: add target.rank targetParent.containerType = LauncherLogProto.DEEPSHORTCUTS; } + + /** + * Shows the shortcuts container for {@param icon} + * @return the container if shown or null. + */ + public static DeepShortcutsContainer showForIcon(BubbleTextView icon) { + Launcher launcher = Launcher.getLauncher(icon.getContext()); + List<String> ids = launcher.getShortcutIdsForItem((ItemInfo) icon.getTag()); + if (!ids.isEmpty()) { + // There are shortcuts associated with the app, so defer its drag. + final DeepShortcutsContainer container = + (DeepShortcutsContainer) launcher.getLayoutInflater().inflate( + R.layout.deep_shortcuts_container, launcher.getDragLayer(), false); + container.setVisibility(View.INVISIBLE); + launcher.getDragLayer().addView(container); + container.populateAndShow(icon, ids); + icon.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, + HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); + return container; + } + return null; + } } diff --git a/src/com/android/launcher3/shortcuts/ShortcutsContainerListener.java b/src/com/android/launcher3/shortcuts/ShortcutsContainerListener.java index f3b0d0402..f94595b54 100644 --- a/src/com/android/launcher3/shortcuts/ShortcutsContainerListener.java +++ b/src/com/android/launcher3/shortcuts/ShortcutsContainerListener.java @@ -1,9 +1,6 @@ package com.android.launcher3.shortcuts; -import android.content.Context; import android.os.SystemClock; -import android.view.HapticFeedbackConstants; -import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; @@ -11,14 +8,10 @@ import android.view.ViewParent; import com.android.launcher3.BubbleTextView; import com.android.launcher3.CheckLongPressHelper; -import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; -import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.dragndrop.DragLayer; -import java.util.List; - /** * A {@link android.view.View.OnTouchListener} that creates a {@link DeepShortcutsContainer} and * forwards touch events to it. This listener should be put on any icon that supports shortcuts. @@ -58,6 +51,7 @@ public class ShortcutsContainerListener implements View.OnTouchListener, /** If true, the gesture is not handled. The value is reset when next gesture starts. */ private boolean mIgnoreCurrentGesture; + private DeepShortcutsContainer mShortcutsContainer; public ShortcutsContainerListener(BubbleTextView icon) { mSrcIcon = icon; @@ -78,8 +72,7 @@ public class ShortcutsContainerListener implements View.OnTouchListener, if (event.getAction() == MotionEvent.ACTION_DOWN) { // There are no shortcuts associated with this item, // so return to normal touch handling. - mIgnoreCurrentGesture = - (mLauncher.getShortcutIdsForItem((ItemInfo) v.getTag())).isEmpty(); + mIgnoreCurrentGesture = !mSrcIcon.hasDeepShortcuts(); mTouchDown[0] = (int) event.getX(); mTouchDown[1] = (int) event.getY(); @@ -134,21 +127,8 @@ public class ShortcutsContainerListener implements View.OnTouchListener, * @return true to start forwarding, false otherwise */ protected boolean onForwardingStarted() { - List<String> ids = mLauncher.getShortcutIdsForItem((ItemInfo) mSrcIcon.getTag()); - if (!ids.isEmpty()) { - // There are shortcuts associated with the app, so defer its drag. - LayoutInflater layoutInflater = (LayoutInflater) mLauncher.getSystemService - (Context.LAYOUT_INFLATER_SERVICE); - final DeepShortcutsContainer deepShortcutsContainer = (DeepShortcutsContainer) - layoutInflater.inflate(R.layout.deep_shortcuts_container, mDragLayer, false); - deepShortcutsContainer.setVisibility(View.INVISIBLE); - mDragLayer.addView(deepShortcutsContainer); - deepShortcutsContainer.populateAndShow(mSrcIcon, ids); - mSrcIcon.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, - HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); - return true; - } - return false; + mShortcutsContainer = DeepShortcutsContainer.showForIcon(mSrcIcon); + return mShortcutsContainer != null; } /** @@ -157,6 +137,7 @@ public class ShortcutsContainerListener implements View.OnTouchListener, * @return true to stop forwarding, false otherwise */ protected boolean onForwardingStopped() { + mShortcutsContainer = null; return true; } @@ -223,8 +204,8 @@ public class ShortcutsContainerListener implements View.OnTouchListener, private void onLongPress() { clearCallbacks(); - final View src = mSrcIcon; - if (!src.isEnabled() || mLauncher.getShortcutIdsForItem((ItemInfo) src.getTag()).isEmpty()) { + final BubbleTextView src = mSrcIcon; + if (!src.isEnabled() || !src.hasDeepShortcuts()) { // Ignore long-press if the view is disabled or doesn't have shortcuts. return; } @@ -254,8 +235,7 @@ public class ShortcutsContainerListener implements View.OnTouchListener, */ private boolean onTouchForwarded(MotionEvent srcEvent) { final View src = mSrcIcon; - - final DeepShortcutsContainer dst = mLauncher.getOpenShortcutsContainer(); + final DeepShortcutsContainer dst = mShortcutsContainer; if (dst == null) { return false; } |