Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.gecko;
7 import org.mozilla.gecko.widget.GeckoPopupMenu;
9 import android.view.Menu;
10 import android.view.MenuItem;
11 import android.view.View;
13 class ActionModeCompat implements GeckoPopupMenu.OnMenuItemClickListener,
14 View.OnClickListener {
15 private final String LOGTAG = "GeckoActionModeCompat";
17 private Callback mCallback;
18 private ActionModeCompatView mView;
19 private Presenter mPresenter;
21 /* A set of callbacks to be called during this ActionMode's lifecycle. These will control the
22 * creation, interaction with, and destruction of menuitems for the view */
23 public static interface Callback {
24 /* Called when action mode is first created. Implementors should use this to inflate menu resources. */
25 public boolean onCreateActionMode(ActionModeCompat mode, Menu menu);
27 /* Called to refresh an action mode's action menu. Called whenever the mode is invalidated. Implementors
28 * should use this to enable/disable/show/hide menu items. */
29 public boolean onPrepareActionMode(ActionModeCompat mode, Menu menu);
31 /* Called to report a user click on an action button. */
32 public boolean onActionItemClicked(ActionModeCompat mode, MenuItem item);
34 /* Called when an action mode is about to be exited and destroyed. */
35 public void onDestroyActionMode(ActionModeCompat mode);
36 }
38 /* Presenters handle the actual showing/hiding of the action mode UI in the app. Its their responsibility
39 * to create an action mode, and assign it Callbacks and ActionModeCompatView's. */
40 public static interface Presenter {
41 /* Called when an action mode should be shown */
42 public void startActionModeCompat(final Callback callback);
44 /* Called when whatever action mode is showing should be hidden */
45 public void endActionModeCompat();
46 }
48 public ActionModeCompat(Presenter presenter, Callback callback, ActionModeCompatView view) {
49 mPresenter = presenter;
50 mCallback = callback;
52 mView = view;
53 mView.initForMode(this);
54 }
56 public void finish() {
57 // Clearing the menu will also clear the ActionItemBar
58 mView.getMenu().clear();
59 if (mCallback != null) {
60 mCallback.onDestroyActionMode(this);
61 }
62 }
64 public CharSequence getTitle() {
65 return mView.getTitle();
66 }
68 public void setTitle(CharSequence title) {
69 mView.setTitle(title);
70 }
72 public void setTitle(int resId) {
73 mView.setTitle(resId);
74 }
76 public Menu getMenu() {
77 return mView.getMenu();
78 }
80 public void invalidate() {
81 if (mCallback != null) {
82 mCallback.onPrepareActionMode(this, mView.getMenu());
83 }
84 mView.invalidate();
85 }
87 /* GeckoPopupMenu.OnMenuItemClickListener */
88 @Override
89 public boolean onMenuItemClick(MenuItem item) {
90 if (mCallback != null) {
91 return mCallback.onActionItemClicked(this, item);
92 }
93 return false;
94 }
96 /* View.OnClickListener*/
97 @Override
98 public void onClick(View v) {
99 mPresenter.endActionModeCompat();
100 }
101 }