1 package com
.actionbarsherlock
.app
;
3 import android
.app
.Activity
;
4 import android
.content
.res
.Configuration
;
5 import android
.os
.Bundle
;
6 import android
.view
.KeyEvent
;
7 import android
.view
.View
;
8 import android
.view
.Window
;
9 import android
.view
.ViewGroup
.LayoutParams
;
10 import com
.actionbarsherlock
.ActionBarSherlock
;
11 import com
.actionbarsherlock
.ActionBarSherlock
.OnActionModeFinishedListener
;
12 import com
.actionbarsherlock
.ActionBarSherlock
.OnActionModeStartedListener
;
13 import com
.actionbarsherlock
.ActionBarSherlock
.OnCreatePanelMenuListener
;
14 import com
.actionbarsherlock
.ActionBarSherlock
.OnMenuItemSelectedListener
;
15 import com
.actionbarsherlock
.ActionBarSherlock
.OnPreparePanelListener
;
16 import com
.actionbarsherlock
.view
.ActionMode
;
17 import com
.actionbarsherlock
.view
.Menu
;
18 import com
.actionbarsherlock
.view
.MenuInflater
;
19 import com
.actionbarsherlock
.view
.MenuItem
;
21 public abstract class SherlockActivity
extends Activity
implements OnCreatePanelMenuListener
, OnPreparePanelListener
, OnMenuItemSelectedListener
, OnActionModeStartedListener
, OnActionModeFinishedListener
{
22 private ActionBarSherlock mSherlock
;
24 protected final ActionBarSherlock
getSherlock() {
25 if (mSherlock
== null
) {
26 mSherlock
= ActionBarSherlock
.wrap(this, ActionBarSherlock
.FLAG_DELEGATE
);
32 ///////////////////////////////////////////////////////////////////////////
33 // Action bar and mode
34 ///////////////////////////////////////////////////////////////////////////
36 public ActionBar
getSupportActionBar() {
37 return getSherlock().getActionBar();
40 public ActionMode
startActionMode(ActionMode
.Callback callback
) {
41 return getSherlock().startActionMode(callback
);
45 public void onActionModeStarted(ActionMode mode
) {}
48 public void onActionModeFinished(ActionMode mode
) {}
51 ///////////////////////////////////////////////////////////////////////////
52 // General lifecycle/callback dispatching
53 ///////////////////////////////////////////////////////////////////////////
56 public void onConfigurationChanged(Configuration newConfig
) {
57 super.onConfigurationChanged(newConfig
);
58 getSherlock().dispatchConfigurationChanged(newConfig
);
62 protected void onPostResume() {
64 getSherlock().dispatchPostResume();
68 protected void onPause() {
69 getSherlock().dispatchPause();
74 protected void onStop() {
75 getSherlock().dispatchStop();
80 protected void onDestroy() {
81 getSherlock().dispatchDestroy();
86 protected void onPostCreate(Bundle savedInstanceState
) {
87 getSherlock().dispatchPostCreate(savedInstanceState
);
88 super.onPostCreate(savedInstanceState
);
92 protected void onTitleChanged(CharSequence title
, int color
) {
93 getSherlock().dispatchTitleChanged(title
, color
);
94 super.onTitleChanged(title
, color
);
98 public final boolean onMenuOpened(int featureId
, android
.view
.Menu menu
) {
99 if (getSherlock().dispatchMenuOpened(featureId
, menu
)) {
102 return super.onMenuOpened(featureId
, menu
);
106 public void onPanelClosed(int featureId
, android
.view
.Menu menu
) {
107 getSherlock().dispatchPanelClosed(featureId
, menu
);
108 super.onPanelClosed(featureId
, menu
);
112 public boolean dispatchKeyEvent(KeyEvent event
) {
113 if (getSherlock().dispatchKeyEvent(event
)) {
116 return super.dispatchKeyEvent(event
);
120 protected void onSaveInstanceState(Bundle outState
) {
121 super.onSaveInstanceState(outState
);
122 getSherlock().dispatchSaveInstanceState(outState
);
126 protected void onRestoreInstanceState(Bundle savedInstanceState
) {
127 super.onRestoreInstanceState(savedInstanceState
);
128 getSherlock().dispatchRestoreInstanceState(savedInstanceState
);
131 ///////////////////////////////////////////////////////////////////////////
132 // Native menu handling
133 ///////////////////////////////////////////////////////////////////////////
135 public MenuInflater
getSupportMenuInflater() {
136 return getSherlock().getMenuInflater();
139 public void invalidateOptionsMenu() {
140 getSherlock().dispatchInvalidateOptionsMenu();
143 public void supportInvalidateOptionsMenu() {
144 invalidateOptionsMenu();
148 public final boolean onCreateOptionsMenu(android
.view
.Menu menu
) {
149 return getSherlock().dispatchCreateOptionsMenu(menu
);
153 public final boolean onPrepareOptionsMenu(android
.view
.Menu menu
) {
154 return getSherlock().dispatchPrepareOptionsMenu(menu
);
158 public final boolean onOptionsItemSelected(android
.view
.MenuItem item
) {
159 return getSherlock().dispatchOptionsItemSelected(item
);
163 public void openOptionsMenu() {
164 if (!getSherlock().dispatchOpenOptionsMenu()) {
165 super.openOptionsMenu();
170 public void closeOptionsMenu() {
171 if (!getSherlock().dispatchCloseOptionsMenu()) {
172 super.closeOptionsMenu();
177 ///////////////////////////////////////////////////////////////////////////
178 // Sherlock menu handling
179 ///////////////////////////////////////////////////////////////////////////
182 public boolean onCreatePanelMenu(int featureId
, Menu menu
) {
183 if (featureId
== Window
.FEATURE_OPTIONS_PANEL
) {
184 return onCreateOptionsMenu(menu
);
189 public boolean onCreateOptionsMenu(Menu menu
) {
194 public boolean onPreparePanel(int featureId
, View view
, Menu menu
) {
195 if (featureId
== Window
.FEATURE_OPTIONS_PANEL
) {
196 return onPrepareOptionsMenu(menu
);
201 public boolean onPrepareOptionsMenu(Menu menu
) {
206 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
207 if (featureId
== Window
.FEATURE_OPTIONS_PANEL
) {
208 return onOptionsItemSelected(item
);
213 public boolean onOptionsItemSelected(MenuItem item
) {
218 ///////////////////////////////////////////////////////////////////////////
220 ///////////////////////////////////////////////////////////////////////////
223 public void addContentView(View view
, LayoutParams params
) {
224 getSherlock().addContentView(view
, params
);
228 public void setContentView(int layoutResId
) {
229 getSherlock().setContentView(layoutResId
);
233 public void setContentView(View view
, LayoutParams params
) {
234 getSherlock().setContentView(view
, params
);
238 public void setContentView(View view
) {
239 getSherlock().setContentView(view
);
242 public void requestWindowFeature(long featureId
) {
243 getSherlock().requestFeature((int)featureId
);
247 ///////////////////////////////////////////////////////////////////////////
248 // Progress Indication
249 ///////////////////////////////////////////////////////////////////////////
251 public void setSupportProgress(int progress
) {
252 getSherlock().setProgress(progress
);
255 public void setSupportProgressBarIndeterminate(boolean indeterminate
) {
256 getSherlock().setProgressBarIndeterminate(indeterminate
);
259 public void setSupportProgressBarIndeterminateVisibility(boolean visible
) {
260 getSherlock().setProgressBarIndeterminateVisibility(visible
);
263 public void setSupportProgressBarVisibility(boolean visible
) {
264 getSherlock().setProgressBarVisibility(visible
);
267 public void setSupportSecondaryProgress(int secondaryProgress
) {
268 getSherlock().setSecondaryProgress(secondaryProgress
);