diff options
| author | Clara Bayarri <clarabayarri@google.com> | 2015-02-25 14:44:34 +0000 |
|---|---|---|
| committer | Clara Bayarri <clarabayarri@google.com> | 2015-03-17 01:07:14 +0000 |
| commit | cba5fc22d17eafd755d9a248841bc9b69fb34763 (patch) | |
| tree | a082589b0801ac00caaf200e4b852bc03f91269f /core/java/android | |
| parent | 2fbea7ff90018fb75db871bdc9545d0aba676ac9 (diff) | |
Floating toolbars: Add content rect related methods to API
This CL adds the ActionMode.Callback2 abstract class and the rect
invalidate method needed to add the content rect API for Floating
Toolbars. It also extends the existing ActionModeCallbackWrapper in
DecorView to handle the case when ActionMode.Callback is provided
instead of Callback2, falling back to a default implementation.
Change-Id: Ia918ddfcfdf73d0e4cafd24c4a0573245d497cfe
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/ActionMode.java | 39 | ||||
| -rw-r--r-- | core/java/android/view/PhoneWindow.java | 23 |
2 files changed, 50 insertions, 12 deletions
diff --git a/core/java/android/view/ActionMode.java b/core/java/android/view/ActionMode.java index a018138d44ff..9f202a952479 100644 --- a/core/java/android/view/ActionMode.java +++ b/core/java/android/view/ActionMode.java @@ -18,6 +18,7 @@ package android.view; import android.annotation.StringRes; +import android.graphics.Rect; /** * Represents a contextual mode of the user interface. Action modes can be used to provide @@ -197,6 +198,15 @@ public abstract class ActionMode { public abstract void invalidate(); /** + * Invalidate the content rect associated to this ActionMode. This only makes sense for + * action modes that support dynamic positioning on the screen, and provides a more efficient + * way to reposition it without invalidating the whole action mode. + * + * @see Callback2#onGetContentRect(ActionMode, View, Rect) . + */ + public void invalidateContentRect() {} + + /** * Finish and close this action mode. The action mode's {@link ActionMode.Callback} will * have its {@link Callback#onDestroyActionMode(ActionMode)} method called. */ @@ -298,4 +308,31 @@ public abstract class ActionMode { */ public void onDestroyActionMode(ActionMode mode); } -}
\ No newline at end of file + + /** + * Extension of {@link ActionMode.Callback} to provide content rect information. This is + * required for ActionModes with dynamic positioning such as the ones with type + * {@link ActionMode#TYPE_FLOATING} to ensure the positioning doesn't obscure app content. If + * an app fails to provide a subclass of this class, a default implementation will be used. + */ + public static abstract class Callback2 implements ActionMode.Callback { + + /** + * Called when an ActionMode needs to be positioned on screen, potentially occluding view + * content. Note this may be called on a per-frame basis. + * + * @param mode The ActionMode that requires positioning. + * @param view The View that originated the ActionMode, in whose coordinates the Rect should + * be provided. + * @param outRect The Rect to be populated with the content position. + */ + public void onGetContentRect(ActionMode mode, View view, Rect outRect) { + if (view != null) { + outRect.set(0, 0, view.getWidth(), view.getHeight()); + } else { + outRect.set(0, 0, 0, 0); + } + } + + } +} diff --git a/core/java/android/view/PhoneWindow.java b/core/java/android/view/PhoneWindow.java index b30d59a2033e..bc3573c52732 100644 --- a/core/java/android/view/PhoneWindow.java +++ b/core/java/android/view/PhoneWindow.java @@ -2669,17 +2669,13 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { @Override public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { - // originalView can be used here to be sure that we don't obscure - // relevant content with the context mode UI. - return startActionMode(callback); + return startActionModeForChild(originalView, callback, ActionMode.TYPE_PRIMARY); } @Override public ActionMode startActionModeForChild( View child, ActionMode.Callback callback, int type) { - // originalView can be used here to be sure that we don't obscure - // relevant content with the context mode UI. - return startActionMode(callback, type); + return startActionMode(child, callback, type); } @Override @@ -2689,7 +2685,12 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { @Override public ActionMode startActionMode(ActionMode.Callback callback, int type) { - ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback); + return startActionMode(this, callback, type); + } + + private ActionMode startActionMode( + View originatingView, ActionMode.Callback callback, int type) { + ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback); ActionMode mode = null; if (getCallback() != null && !isDestroyed()) { try { @@ -3291,12 +3292,12 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } /** - * Clears out internal reference when the action mode is destroyed. + * Clears out internal references when the action mode is destroyed. */ - private class ActionModeCallbackWrapper implements ActionMode.Callback { - private ActionMode.Callback mWrapped; + private class ActionModeCallback2Wrapper extends ActionMode.Callback2 { + private final ActionMode.Callback mWrapped; - public ActionModeCallbackWrapper(ActionMode.Callback wrapped) { + public ActionModeCallback2Wrapper(ActionMode.Callback wrapped) { mWrapped = wrapped; } |
