diff options
author | Adam Powell <adamp@google.com> | 2010-07-27 16:34:07 -0700 |
---|---|---|
committer | Adam Powell <adamp@google.com> | 2010-07-27 21:04:52 -0700 |
commit | 5d27977f9da482627ceb19317a2cd70467aff046 (patch) | |
tree | a96b2c2a9aeba5f2e3b92a256949677880063d35 /core/java | |
parent | 85d8daa889db113b51c5d98929245e80f7277388 (diff) | |
download | frameworks_base-5d27977f9da482627ceb19317a2cd70467aff046.zip frameworks_base-5d27977f9da482627ceb19317a2cd70467aff046.tar.gz frameworks_base-5d27977f9da482627ceb19317a2cd70467aff046.tar.bz2 |
Action modes without action bar
Change-Id: I0367ab35e598a17980bd373b30828175f6283acc
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/app/Activity.java | 4 | ||||
-rw-r--r-- | core/java/android/view/MenuInflater.java | 4 | ||||
-rw-r--r-- | core/java/android/view/Window.java | 7 | ||||
-rw-r--r-- | core/java/com/android/internal/app/ActionBarImpl.java | 22 | ||||
-rw-r--r-- | core/java/com/android/internal/view/StandaloneActionMode.java | 123 | ||||
-rw-r--r-- | core/java/com/android/internal/widget/ActionBarContextView.java | 4 |
6 files changed, 148 insertions, 16 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 142c325..9beaec0 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -4080,13 +4080,13 @@ public class Activity extends ContextThemeWrapper * * @see ActionMode */ - public ActionMode startContextMode(ActionMode.Callback callback) { + public ActionMode startActionMode(ActionMode.Callback callback) { return mWindow.getDecorView().startActionMode(callback); } public ActionMode onStartActionMode(ActionMode.Callback callback) { if (mActionBar != null) { - return mActionBar.startContextMode(callback); + return mActionBar.startActionMode(callback); } return null; } diff --git a/core/java/android/view/MenuInflater.java b/core/java/android/view/MenuInflater.java index 4a966b5..a959e0d 100644 --- a/core/java/android/view/MenuInflater.java +++ b/core/java/android/view/MenuInflater.java @@ -350,6 +350,10 @@ public class MenuInflater { .setShowAsAction(itemShowAsAction); if (itemListenerMethodName != null) { + if (mContext.isRestricted()) { + throw new IllegalStateException("The android:onClick attribute cannot " + + "be used within a restricted context"); + } item.setOnMenuItemClickListener( new InflatedOnMenuItemClickListener(mContext, itemListenerMethodName)); } diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index b077b56..0d4e84b 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -62,7 +62,12 @@ public abstract class Window { * replaces the title bar and provides an alternate location * for an on-screen menu button on some devices. */ - public static final int FEATURE_ACTION_BAR = 9; + public static final int FEATURE_ACTION_BAR = 8; + /** + * Flag for specifying the behavior of action modes when an Action Bar is not present. + * If overlay is enabled, the action mode UI will be allowed to cover existing window content. + */ + public static final int FEATURE_ACTION_MODE_OVERLAY = 9; /** Flag for setting the progress bar's visibility to VISIBLE */ public static final int PROGRESS_VISIBILITY_ON = -1; /** Flag for setting the progress bar's visibility to GONE */ diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java index 6515f25..e457701 100644 --- a/core/java/com/android/internal/app/ActionBarImpl.java +++ b/core/java/com/android/internal/app/ActionBarImpl.java @@ -66,7 +66,7 @@ public class ActionBarImpl extends ActionBar { private TabImpl mSelectedTab; private int mTabSwitchMode = TAB_SWITCH_ADD_REMOVE; - private ActionMode mContextMode; + private ActionMode mActionMode; private static final int CONTEXT_DISPLAY_NORMAL = 0; private static final int CONTEXT_DISPLAY_SPLIT = 1; @@ -229,9 +229,9 @@ public class ActionBarImpl extends ActionBar { return mActionView.getDisplayOptions(); } - public ActionMode startContextMode(ActionMode.Callback callback) { - if (mContextMode != null) { - mContextMode.finish(); + public ActionMode startActionMode(ActionMode.Callback callback) { + if (mActionMode != null) { + mActionMode.finish(); } // Don't wait for the close context mode animation to finish. @@ -241,7 +241,7 @@ public class ActionBarImpl extends ActionBar { mCloseContext.run(); } - ActionMode mode = new ContextModeImpl(callback); + ActionMode mode = new ActionModeImpl(callback); if (callback.onCreateActionMode(mode, mode.getMenu())) { mode.invalidate(); mUpperContextView.initForMode(mode); @@ -250,7 +250,7 @@ public class ActionBarImpl extends ActionBar { // TODO animate this mLowerContextView.setVisibility(View.VISIBLE); } - mContextMode = mode; + mActionMode = mode; return mode; } return null; @@ -361,12 +361,12 @@ public class ActionBarImpl extends ActionBar { /** * @hide */ - public class ContextModeImpl extends ActionMode implements MenuBuilder.Callback { + public class ActionModeImpl extends ActionMode implements MenuBuilder.Callback { private ActionMode.Callback mCallback; private MenuBuilder mMenu; private WeakReference<View> mCustomView; - public ContextModeImpl(ActionMode.Callback callback) { + public ActionModeImpl(ActionMode.Callback callback) { mCallback = callback; mMenu = new MenuBuilder(mActionView.getContext()); mMenu.setCallback(this); @@ -379,8 +379,8 @@ public class ActionBarImpl extends ActionBar { @Override public void finish() { - if (mContextMode != this) { - // Not the active context mode - no-op + if (mActionMode != this) { + // Not the active action mode - no-op return; } @@ -395,7 +395,7 @@ public class ActionBarImpl extends ActionBar { // TODO Animate this mLowerContextView.setVisibility(View.GONE); } - mContextMode = null; + mActionMode = null; } @Override diff --git a/core/java/com/android/internal/view/StandaloneActionMode.java b/core/java/com/android/internal/view/StandaloneActionMode.java new file mode 100644 index 0000000..13eda10 --- /dev/null +++ b/core/java/com/android/internal/view/StandaloneActionMode.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.internal.view; + +import com.android.internal.view.menu.MenuBuilder; +import com.android.internal.view.menu.MenuPopupHelper; +import com.android.internal.view.menu.SubMenuBuilder; +import com.android.internal.widget.ActionBarContextView; + +import android.content.Context; +import android.view.ActionMode; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; + +import java.lang.ref.WeakReference; + +public class StandaloneActionMode extends ActionMode implements MenuBuilder.Callback { + private Context mContext; + private ActionBarContextView mContextView; + private ActionMode.Callback mCallback; + private WeakReference<View> mCustomView; + private boolean mFinished; + + private MenuBuilder mMenu; + + public StandaloneActionMode(Context context, ActionBarContextView view, + ActionMode.Callback callback) { + mContext = context; + mContextView = view; + mCallback = callback; + + mMenu = new MenuBuilder(context); + mMenu.setCallback(this); + } + + @Override + public void setTitle(CharSequence title) { + mContextView.setTitle(title); + } + + @Override + public void setSubtitle(CharSequence subtitle) { + mContextView.setSubtitle(subtitle); + } + + @Override + public void setCustomView(View view) { + mContextView.setCustomView(view); + mCustomView = view != null ? new WeakReference<View>(view) : null; + } + + @Override + public void invalidate() { + mCallback.onPrepareActionMode(this, mMenu); + } + + @Override + public void finish() { + if (mFinished) { + return; + } + mFinished = true; + + mCallback.onDestroyActionMode(this); + mContextView.setVisibility(View.GONE); + } + + @Override + public Menu getMenu() { + return mMenu; + } + + @Override + public CharSequence getTitle() { + return mContextView.getTitle(); + } + + @Override + public CharSequence getSubtitle() { + return mContextView.getSubtitle(); + } + + @Override + public View getCustomView() { + return mCustomView != null ? mCustomView.get() : null; + } + + public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { + return mCallback.onActionItemClicked(this, item); + } + + public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { + } + + public boolean onSubMenuSelected(SubMenuBuilder subMenu) { + if (!subMenu.hasVisibleItems()) { + return true; + } + + new MenuPopupHelper(mContext, subMenu).show(); + return true; + } + + public void onCloseSubMenu(SubMenuBuilder menu) { + } + + public void onMenuModeChange(MenuBuilder menu) { + } +} diff --git a/core/java/com/android/internal/widget/ActionBarContextView.java b/core/java/com/android/internal/widget/ActionBarContextView.java index a185e21..0bedc4e 100644 --- a/core/java/com/android/internal/widget/ActionBarContextView.java +++ b/core/java/com/android/internal/widget/ActionBarContextView.java @@ -70,9 +70,9 @@ public class ActionBarContextView extends ViewGroup { mItemPadding = a.getDimensionPixelOffset( com.android.internal.R.styleable.Theme_actionButtonPadding, 0); setBackgroundDrawable(a.getDrawable( - com.android.internal.R.styleable.Theme_actionBarContextBackground)); + com.android.internal.R.styleable.Theme_actionModeBackground)); mCloseDrawable = a.getDrawable( - com.android.internal.R.styleable.Theme_actionBarCloseContextDrawable); + com.android.internal.R.styleable.Theme_actionModeCloseDrawable); mItemMargin = mItemPadding / 2; mContentHeight = |