summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorClara Bayarri <clarabayarri@google.com>2015-02-05 16:58:00 +0000
committerClara Bayarri <clarabayarri@google.com>2015-02-19 22:40:31 +0000
commited2a54cfd336bb935f281c04509ecd48c8cf116d (patch)
treef82b6e2c066e85a8e151e334d8931f92e543d152 /core/java/android
parent421d6ad191563308d31594f53fee804c3d4d1f84 (diff)
Floating Toolbars: Wrap the ActionMode creation in DecorView
This change will allow us to create ActionMode representations on the fly after onCreateActionMode by using the Decorator pattern. The new ActionModeWrapper will be responsible for the creating the appropriate ActionMode depending on the type chosen by the client, and setting it up. Things pending that are NOT addressed by this CL: - ActionModes created by callback.onWindowStartingActionMode(). This includes all current usages in an existing ActionBar, as it is handled by Activity. This requires some additional refactoring. - Representing the floating type - Moving the view creation code specific to StandaloneActionMode from DecorView to ActionModeWrapper, decoupling DecorView from StandaloneActionMode completely - Supporting two ActionModes in parallel in DecorView, one of each type Change-Id: I1a8db711f53b771eac74f0e6496106acf1ca2727
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/view/PhoneWindow.java130
1 files changed, 69 insertions, 61 deletions
diff --git a/core/java/android/view/PhoneWindow.java b/core/java/android/view/PhoneWindow.java
index 5f4d201e0f46..c8b2ee8f7bdb 100644
--- a/core/java/android/view/PhoneWindow.java
+++ b/core/java/android/view/PhoneWindow.java
@@ -25,7 +25,9 @@ import static android.view.WindowManager.LayoutParams.*;
import android.app.ActivityManagerNative;
import android.app.SearchManager;
import android.os.UserHandle;
+
import com.android.internal.R;
+import com.android.internal.view.ActionModeWrapper;
import com.android.internal.view.RootViewSurfaceTaker;
import com.android.internal.view.StandaloneActionMode;
import com.android.internal.view.menu.ContextMenuBuilder;
@@ -2689,72 +2691,78 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
if (mode != null) {
mActionMode = mode;
} else {
- if (mActionModeView == null) {
- if (isFloating()) {
- // Use the action bar theme.
- final TypedValue outValue = new TypedValue();
- final Theme baseTheme = mContext.getTheme();
- baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);
-
- final Context actionBarContext;
- if (outValue.resourceId != 0) {
- final Theme actionBarTheme = mContext.getResources().newTheme();
- actionBarTheme.setTo(baseTheme);
- actionBarTheme.applyStyle(outValue.resourceId, true);
-
- actionBarContext = new ContextThemeWrapper(mContext, 0);
- actionBarContext.getTheme().setTo(actionBarTheme);
- } else {
- actionBarContext = mContext;
- }
+ if (mActionModeView != null) {
+ mActionModeView.killMode();
+ }
+ ActionModeWrapper wrapperMode =
+ new ActionModeWrapper(mContext, wrappedCallback);
+ if (callback.onCreateActionMode(wrapperMode, wrapperMode.getMenu())) {
+ if (wrapperMode.getType() == ActionMode.TYPE_PRIMARY) {
+ if (mActionModeView == null) {
+ if (isFloating()) {
+ // Use the action bar theme.
+ final TypedValue outValue = new TypedValue();
+ final Theme baseTheme = mContext.getTheme();
+ baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);
+
+ final Context actionBarContext;
+ if (outValue.resourceId != 0) {
+ final Theme actionBarTheme = mContext.getResources().newTheme();
+ actionBarTheme.setTo(baseTheme);
+ actionBarTheme.applyStyle(outValue.resourceId, true);
+
+ actionBarContext = new ContextThemeWrapper(mContext, 0);
+ actionBarContext.getTheme().setTo(actionBarTheme);
+ } else {
+ actionBarContext = mContext;
+ }
- mActionModeView = new ActionBarContextView(actionBarContext);
- mActionModePopup = new PopupWindow(actionBarContext, null,
- R.attr.actionModePopupWindowStyle);
- mActionModePopup.setWindowLayoutType(
- WindowManager.LayoutParams.TYPE_APPLICATION);
- mActionModePopup.setContentView(mActionModeView);
- mActionModePopup.setWidth(MATCH_PARENT);
-
- actionBarContext.getTheme().resolveAttribute(
- R.attr.actionBarSize, outValue, true);
- final int height = TypedValue.complexToDimensionPixelSize(outValue.data,
- actionBarContext.getResources().getDisplayMetrics());
- mActionModeView.setContentHeight(height);
- mActionModePopup.setHeight(WRAP_CONTENT);
- mShowActionModePopup = new Runnable() {
- public void run() {
- mActionModePopup.showAtLocation(
- mActionModeView.getApplicationWindowToken(),
- Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
+ mActionModeView = new ActionBarContextView(actionBarContext);
+ mActionModePopup = new PopupWindow(actionBarContext, null,
+ R.attr.actionModePopupWindowStyle);
+ mActionModePopup.setWindowLayoutType(
+ WindowManager.LayoutParams.TYPE_APPLICATION);
+ mActionModePopup.setContentView(mActionModeView);
+ mActionModePopup.setWidth(MATCH_PARENT);
+
+ actionBarContext.getTheme().resolveAttribute(
+ R.attr.actionBarSize, outValue, true);
+ final int height = TypedValue.complexToDimensionPixelSize(outValue.data,
+ actionBarContext.getResources().getDisplayMetrics());
+ mActionModeView.setContentHeight(height);
+ mActionModePopup.setHeight(WRAP_CONTENT);
+ mShowActionModePopup = new Runnable() {
+ public void run() {
+ mActionModePopup.showAtLocation(
+ mActionModeView.getApplicationWindowToken(),
+ Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
+ }
+ };
+ } else {
+ ViewStub stub = (ViewStub) findViewById(
+ R.id.action_mode_bar_stub);
+ if (stub != null) {
+ mActionModeView = (ActionBarContextView) stub.inflate();
+ }
}
- };
- } else {
- ViewStub stub = (ViewStub) findViewById(
- R.id.action_mode_bar_stub);
- if (stub != null) {
- mActionModeView = (ActionBarContextView) stub.inflate();
}
- }
- }
-
- if (mActionModeView != null) {
- mActionModeView.killMode();
- mode = new StandaloneActionMode(mActionModeView.getContext(), mActionModeView,
- wrappedCallback, mActionModePopup == null);
- if (callback.onCreateActionMode(mode, mode.getMenu())) {
- mode.invalidate();
- mActionModeView.initForMode(mode);
- mActionModeView.setVisibility(View.VISIBLE);
- mActionMode = mode;
- if (mActionModePopup != null) {
- post(mShowActionModePopup);
+ if (mActionModeView != null) {
+ wrapperMode.setActionModeView(mActionModeView);
+ wrapperMode.setFocusable(mActionModePopup == null);
+ wrapperMode.lockType();
+ wrapperMode.invalidate();
+ mActionModeView.initForMode(wrapperMode);
+ mActionModeView.setVisibility(View.VISIBLE);
+ mActionMode = wrapperMode;
+ if (mActionModePopup != null) {
+ post(mShowActionModePopup);
+ }
+ mActionModeView.sendAccessibilityEvent(
+ AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
}
- mActionModeView.sendAccessibilityEvent(
- AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
- } else {
- mActionMode = null;
}
+ } else {
+ mActionMode = null;
}
}
if (mActionMode != null && getCallback() != null && !isDestroyed()) {