2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.actionbarsherlock
.internal
.view
;
18 import android
.content
.Context
;
19 import android
.view
.View
;
20 import android
.view
.accessibility
.AccessibilityEvent
;
22 import java
.lang
.ref
.WeakReference
;
24 import com
.actionbarsherlock
.internal
.view
.menu
.MenuBuilder
;
25 import com
.actionbarsherlock
.internal
.view
.menu
.MenuPopupHelper
;
26 import com
.actionbarsherlock
.internal
.view
.menu
.SubMenuBuilder
;
27 import com
.actionbarsherlock
.internal
.widget
.ActionBarContextView
;
28 import com
.actionbarsherlock
.view
.ActionMode
;
29 import com
.actionbarsherlock
.view
.Menu
;
30 import com
.actionbarsherlock
.view
.MenuInflater
;
31 import com
.actionbarsherlock
.view
.MenuItem
;
33 public class StandaloneActionMode
extends ActionMode
implements MenuBuilder
.Callback
{
34 private Context mContext
;
35 private ActionBarContextView mContextView
;
36 private ActionMode
.Callback mCallback
;
37 private WeakReference
<View
> mCustomView
;
38 private boolean mFinished
;
39 private boolean mFocusable
;
41 private MenuBuilder mMenu
;
43 public StandaloneActionMode(Context context
, ActionBarContextView view
,
44 ActionMode
.Callback callback
, boolean isFocusable
) {
49 mMenu
= new MenuBuilder(context
).setDefaultShowAsAction(MenuItem
.SHOW_AS_ACTION_IF_ROOM
);
50 mMenu
.setCallback(this);
51 mFocusable
= isFocusable
;
55 public void setTitle(CharSequence title
) {
56 mContextView
.setTitle(title
);
60 public void setSubtitle(CharSequence subtitle
) {
61 mContextView
.setSubtitle(subtitle
);
65 public void setTitle(int resId
) {
66 setTitle(mContext
.getString(resId
));
70 public void setSubtitle(int resId
) {
71 setSubtitle(mContext
.getString(resId
));
75 public void setCustomView(View view
) {
76 mContextView
.setCustomView(view
);
77 mCustomView
= view
!= null ?
new WeakReference
<View
>(view
) : null
;
81 public void invalidate() {
82 mCallback
.onPrepareActionMode(this, mMenu
);
86 public void finish() {
92 mContextView
.sendAccessibilityEvent(AccessibilityEvent
.TYPE_WINDOW_STATE_CHANGED
);
93 mCallback
.onDestroyActionMode(this);
97 public Menu
getMenu() {
102 public CharSequence
getTitle() {
103 return mContextView
.getTitle();
107 public CharSequence
getSubtitle() {
108 return mContextView
.getSubtitle();
112 public View
getCustomView() {
113 return mCustomView
!= null ? mCustomView
.get() : null
;
117 public MenuInflater
getMenuInflater() {
118 return new MenuInflater(mContext
);
121 public boolean onMenuItemSelected(MenuBuilder menu
, MenuItem item
) {
122 return mCallback
.onActionItemClicked(this, item
);
125 public void onCloseMenu(MenuBuilder menu
, boolean allMenusAreClosing
) {
128 public boolean onSubMenuSelected(SubMenuBuilder subMenu
) {
129 if (!subMenu
.hasVisibleItems()) {
133 new MenuPopupHelper(mContext
, subMenu
).show();
137 public void onCloseSubMenu(SubMenuBuilder menu
) {
140 public void onMenuModeChange(MenuBuilder menu
) {
142 mContextView
.showOverflowMenu();
145 public boolean isUiFocusable() {