From 399b51397b98f9e225410adf11b80c8b9c4b1a91 Mon Sep 17 00:00:00 2001 From: Clara Bayarri Date: Tue, 17 Feb 2015 15:31:50 +0000 Subject: Floating toolbars: Encapsulate StandaloneActionMode view creation. This CL defines a new interface to be used by ActionModeWrapper. This allows each client to inject a different primary ActionMode to the wrapper and keep view creation code next to ActionMode creation. The interface method is only called when the wrapper actually knows that will be the used type, avoinding unnecessary view creations. Things pending after this CL: - Correct handling of ActionModes created by callback.onWindowStartingActionMode(). This includes all current usages in an existing ActionBar, as it is handled by Activity. In the current state, we do not intercept these ActionModes and hence cannot change the representation. - Representing the floating type - Supporting two ActionModes in parallel in DecorView, one of each type Change-Id: Ic38e209877c3876161d8dd56902e25b51fbe40b6 --- .../android/internal/view/ActionModeWrapper.java | 39 ++++++++++++---------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'core/java/com') diff --git a/core/java/com/android/internal/view/ActionModeWrapper.java b/core/java/com/android/internal/view/ActionModeWrapper.java index ef1981a..72066b9 100644 --- a/core/java/com/android/internal/view/ActionModeWrapper.java +++ b/core/java/com/android/internal/view/ActionModeWrapper.java @@ -24,7 +24,6 @@ import android.view.MenuItem; import android.view.View; import com.android.internal.view.menu.MenuBuilder; -import com.android.internal.widget.ActionBarContextView; /** * ActionMode implementation that wraps several actions modes and creates them on the fly depending @@ -32,6 +31,22 @@ import com.android.internal.widget.ActionBarContextView; */ public class ActionModeWrapper extends ActionMode { + /** + * Interface to defer the ActionMode creation until the type is chosen. + */ + public interface ActionModeProvider { + /** + * Create the desired ActionMode, that will immediately be used as the current active mode + * in the decorator. + * + * @param callback The {@link ActionMode.Callback} to be used. + * @param menuBuilder The {@link MenuBuilder} that should be used by the created + * {@link ActionMode}. This will already have been populated. + * @return A new {@link ActionMode} ready to be used that uses menuBuilder as its menu. + */ + ActionMode createActionMode(ActionMode.Callback callback, MenuBuilder menuBuilder); + } + private ActionMode mActionMode; private final Context mContext; private MenuBuilder mMenu; @@ -41,16 +56,16 @@ public class ActionModeWrapper extends ActionMode { private CharSequence mTitle; private CharSequence mSubtitle; private View mCustomView; + + private final ActionModeProvider mActionModeProvider; - // Fields for StandaloneActionMode - private ActionBarContextView mActionModeView; - private boolean mIsFocusable; - - public ActionModeWrapper(Context context, ActionMode.Callback callback) { + public ActionModeWrapper( + Context context, ActionMode.Callback callback, ActionModeProvider actionModeProvider) { mContext = context; mMenu = new MenuBuilder(context).setDefaultShowAsAction( MenuItem.SHOW_AS_ACTION_IF_ROOM); mCallback = callback; + mActionModeProvider = actionModeProvider; } @Override @@ -107,9 +122,7 @@ public class ActionModeWrapper extends ActionMode { switch (getType()) { case ActionMode.TYPE_PRIMARY: default: - mActionMode = new StandaloneActionMode( - mActionModeView.getContext(), - mActionModeView, mCallback, mIsFocusable, mMenu); + mActionMode = mActionModeProvider.createActionMode(mCallback, mMenu); break; case ActionMode.TYPE_FLOATING: // Not implemented yet. @@ -189,12 +202,4 @@ public class ActionModeWrapper extends ActionMode { return new MenuInflater(mContext); } - public void setActionModeView(ActionBarContextView actionModeView) { - mActionModeView = actionModeView; - } - - public void setFocusable(boolean focusable) { - mIsFocusable = focusable; - } - } -- cgit v1.1