diff options
| author | Abodunrinwa Toki <toki@google.com> | 2015-05-19 14:06:44 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-19 14:06:46 +0000 |
| commit | 1f21d2a8b15d088ab50a62cbc389e88c09d141c1 (patch) | |
| tree | 1a7f9c281467eefeded5555ace362e03a266ea62 /core/java/android | |
| parent | 7597dc7c4dfe49ba7c5d0e7568873521b90c6682 (diff) | |
| parent | fd3a3a1163c5096821cef351309fcdd9a4f48002 (diff) | |
Merge "Hide floating toolbar when user interacts with screen." into mnc-dev
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/ActionMode.java | 19 | ||||
| -rw-r--r-- | core/java/android/view/ViewConfiguration.java | 12 | ||||
| -rw-r--r-- | core/java/android/widget/Editor.java | 56 |
3 files changed, 87 insertions, 0 deletions
diff --git a/core/java/android/view/ActionMode.java b/core/java/android/view/ActionMode.java index 9f202a952479..9f00455172ea 100644 --- a/core/java/android/view/ActionMode.java +++ b/core/java/android/view/ActionMode.java @@ -44,6 +44,12 @@ public abstract class ActionMode { */ public static final int TYPE_FLOATING = 1; + /** + * Default snooze time. + */ + public static final int SNOOZE_TIME_DEFAULT = + ViewConfiguration.getDefaultActionModeSnoozeTime(); + private Object mTag; private boolean mTitleOptionalHint; private int mType = TYPE_PRIMARY; @@ -207,6 +213,19 @@ public abstract class ActionMode { public void invalidateContentRect() {} /** + * Hide the action mode view from obstructing the content below for a short period. + * This only makes sense for action modes that support dynamic positioning on the screen. + * If this method is called again before the snooze time expires, the later snooze will + * cancel the former and then take effect. + * NOTE that there is an internal limit to how long the mode can be snoozed for. It's typically + * about a few seconds. + * + * @param snoozeTime The number of milliseconds to snooze for. + * @see #SNOOZE_TIME_DEFAULT + */ + public void snooze(int snoozeTime) {} + + /** * Finish and close this action mode. The action mode's {@link ActionMode.Callback} will * have its {@link Callback#onDestroyActionMode(ActionMode)} method called. */ diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index 4e91ad4db977..8c6fa3ff006d 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -213,6 +213,11 @@ public class ViewConfiguration { private static final int OVERFLING_DISTANCE = 6; /** + * Default time to snooze an action mode for. + */ + private static final int ACTION_MODE_SNOOZE_TIME_DEFAULT = 2000; + + /** * Configuration values for overriding {@link #hasPermanentMenuKey()} behavior. * These constants must match the definition in res/values/config.xml. */ @@ -732,6 +737,13 @@ public class ViewConfiguration { } /** + * @return the default duration in milliseconds for {@link ActionMode#snooze(int)}. + */ + public static int getDefaultActionModeSnoozeTime() { + return ACTION_MODE_SNOOZE_TIME_DEFAULT; + } + + /** * Report if the device has a permanent menu key available to the user. * * <p>As of Android 3.0, devices may not have a permanent menu key available. diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index c829783e685d..d558c7bc7725 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -233,6 +233,24 @@ public class Editor { final CursorAnchorInfoNotifier mCursorAnchorInfoNotifier = new CursorAnchorInfoNotifier(); + private final Runnable mHideFloatingToolbar = new Runnable() { + @Override + public void run() { + if (mSelectionActionMode != null) { + mSelectionActionMode.snooze(ActionMode.SNOOZE_TIME_DEFAULT); + } + } + }; + + private final Runnable mShowFloatingToolbar = new Runnable() { + @Override + public void run() { + if (mSelectionActionMode != null) { + mSelectionActionMode.snooze(0); // snooze off. + } + } + }; + Editor(TextView textView) { mTextView = textView; // Synchronize the filter list, which places the undo input filter at the end. @@ -358,6 +376,9 @@ public class Editor { mTextView.removeCallbacks(mSelectionModeWithoutSelectionRunnable); } + mTextView.removeCallbacks(mHideFloatingToolbar); + mTextView.removeCallbacks(mShowFloatingToolbar); + destroyDisplayListsData(); if (mSpellChecker != null) { @@ -1169,6 +1190,8 @@ public class Editor { } void onTouchEvent(MotionEvent event) { + updateFloatingToolbarVisibility(event); + if (hasSelectionController()) { getSelectionController().onTouchEvent(event); } @@ -1189,6 +1212,37 @@ public class Editor { } } + private void updateFloatingToolbarVisibility(MotionEvent event) { + if (mSelectionActionMode != null) { + switch (event.getActionMasked()) { + case MotionEvent.ACTION_MOVE: + hideFloatingToolbar(); + break; + case MotionEvent.ACTION_UP: // fall through + case MotionEvent.ACTION_CANCEL: + showFloatingToolbar(); + } + } + } + + private void hideFloatingToolbar() { + if (mSelectionActionMode != null) { + mTextView.removeCallbacks(mShowFloatingToolbar); + // Delay the "hide" a little bit just in case a "show" will happen almost immediately. + mTextView.postDelayed(mHideFloatingToolbar, 100); + } + } + + private void showFloatingToolbar() { + if (mSelectionActionMode != null) { + mTextView.removeCallbacks(mHideFloatingToolbar); + // Delay "show" so it doesn't interfere with click confirmations + // or double-clicks that could "dismiss" the floating toolbar. + int delay = ViewConfiguration.getDoubleTapTimeout(); + mTextView.postDelayed(mShowFloatingToolbar, delay); + } + } + public void beginBatchEdit() { mInBatchEditControllers = true; final InputMethodState ims = mInputMethodState; @@ -3661,6 +3715,8 @@ public class Editor { @Override public boolean onTouchEvent(MotionEvent ev) { + updateFloatingToolbarVisibility(ev); + switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: { startTouchUpFilter(getCurrentCursorOffset()); |
