diff options
author | Clara Bayarri <clarabayarri@google.com> | 2015-05-13 15:12:12 +0100 |
---|---|---|
committer | Clara Bayarri <clarabayarri@google.com> | 2015-05-13 16:03:14 +0100 |
commit | 0d7d4ef56083543d58ef5835ec594865a547347c (patch) | |
tree | 316269d80d27af2023ce5477c93bb1016ea1a220 | |
parent | d9c7f2456957a5610cbbca1b2e31aa7b3574c50d (diff) | |
download | frameworks_base-0d7d4ef56083543d58ef5835ec594865a547347c.zip frameworks_base-0d7d4ef56083543d58ef5835ec594865a547347c.tar.gz frameworks_base-0d7d4ef56083543d58ef5835ec594865a547347c.tar.bz2 |
Fix Floating Toolbar appearing after ActionMode was cancelled
The Views created for the Toolbar were not cleaned up properly when the
mode was cancelled by the client in onCreateActionMode, leading to the
toolbar appearing over other views when it shouldn't due to
onWindowFocusChanged showing the Toolbar if it exists.
We don't actually need the views if we don't know whether they are
going to be shown yet, so moved view creation to after onCreateActionMode
Bug: 20713912
Change-Id: Ic0c31d1634e1e96d9981a77b2c769306a8bf1a8d
-rw-r--r-- | core/java/com/android/internal/policy/PhoneWindow.java | 7 | ||||
-rw-r--r-- | core/java/com/android/internal/view/FloatingActionMode.java | 24 |
2 files changed, 19 insertions, 12 deletions
diff --git a/core/java/com/android/internal/policy/PhoneWindow.java b/core/java/com/android/internal/policy/PhoneWindow.java index a578a6e..bc64373 100644 --- a/core/java/com/android/internal/policy/PhoneWindow.java +++ b/core/java/com/android/internal/policy/PhoneWindow.java @@ -3376,9 +3376,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { mFloatingActionMode.finish(); } cleanupFloatingActionModeViews(); - mFloatingToolbar = new FloatingToolbar(mContext, PhoneWindow.this); - final FloatingActionMode mode = new FloatingActionMode( - mContext, callback, originatingView, mFloatingToolbar); + final FloatingActionMode mode = + new FloatingActionMode(mContext, callback, originatingView); mFloatingActionModeOriginatingView = originatingView; mFloatingToolbarPreDrawListener = new OnPreDrawListener() { @@ -3393,6 +3392,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { private void setHandledFloatingActionMode(ActionMode mode) { mFloatingActionMode = mode; + mFloatingToolbar = new FloatingToolbar(mContext, PhoneWindow.this); + ((FloatingActionMode) mFloatingActionMode).setFloatingToolbar(mFloatingToolbar); mFloatingActionMode.invalidate(); mFloatingToolbar.show(); mFloatingActionModeOriginatingView.getViewTreeObserver() diff --git a/core/java/com/android/internal/view/FloatingActionMode.java b/core/java/com/android/internal/view/FloatingActionMode.java index aacdb34..c3f4da7 100644 --- a/core/java/com/android/internal/view/FloatingActionMode.java +++ b/core/java/com/android/internal/view/FloatingActionMode.java @@ -24,6 +24,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import com.android.internal.util.Preconditions; import com.android.internal.view.menu.MenuBuilder; import com.android.internal.widget.FloatingToolbar; @@ -32,20 +33,28 @@ public class FloatingActionMode extends ActionMode { private final Context mContext; private final ActionMode.Callback2 mCallback; private final MenuBuilder mMenu; - private final FloatingToolbar mFloatingToolbar; private final Rect mContentRect; private final Rect mContentRectOnWindow; private final Rect mPreviousContentRectOnWindow; private final int[] mViewPosition; private final View mOriginatingView; + private FloatingToolbar mFloatingToolbar; public FloatingActionMode( - Context context, ActionMode.Callback2 callback, View originatingView, - FloatingToolbar floatingToolbar) { + Context context, ActionMode.Callback2 callback, View originatingView) { mContext = context; mCallback = callback; mMenu = new MenuBuilder(context).setDefaultShowAsAction( MenuItem.SHOW_AS_ACTION_IF_ROOM); + setType(ActionMode.TYPE_FLOATING); + mContentRect = new Rect(); + mContentRectOnWindow = new Rect(); + mPreviousContentRectOnWindow = new Rect(); + mViewPosition = new int[2]; + mOriginatingView = originatingView; + } + + public void setFloatingToolbar(FloatingToolbar floatingToolbar) { mFloatingToolbar = floatingToolbar .setMenu(mMenu) .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @@ -54,12 +63,6 @@ public class FloatingActionMode extends ActionMode { return mCallback.onActionItemClicked(FloatingActionMode.this, item); } }); - setType(ActionMode.TYPE_FLOATING); - mContentRect = new Rect(); - mContentRectOnWindow = new Rect(); - mPreviousContentRectOnWindow = new Rect(); - mViewPosition = new int[2]; - mOriginatingView = originatingView; } @Override @@ -79,6 +82,7 @@ public class FloatingActionMode extends ActionMode { @Override public void invalidate() { + Preconditions.checkNotNull(mFloatingToolbar); mCallback.onPrepareActionMode(this, mMenu); mFloatingToolbar.updateLayout(); invalidateContentRect(); @@ -86,11 +90,13 @@ public class FloatingActionMode extends ActionMode { @Override public void invalidateContentRect() { + Preconditions.checkNotNull(mFloatingToolbar); mCallback.onGetContentRect(this, mOriginatingView, mContentRect); repositionToolbar(); } public void updateViewLocationInWindow() { + Preconditions.checkNotNull(mFloatingToolbar); mOriginatingView.getLocationInWindow(mViewPosition); repositionToolbar(); } |