1 package com.actionbarsherlock.app;
\r
3 import android.app.Activity;
\r
4 import android.content.res.Configuration;
\r
5 import android.os.Bundle;
\r
6 import android.view.KeyEvent;
\r
7 import android.view.View;
\r
8 import android.view.Window;
\r
9 import android.view.ViewGroup.LayoutParams;
\r
10 import com.actionbarsherlock.ActionBarSherlock;
\r
11 import com.actionbarsherlock.ActionBarSherlock.OnActionModeFinishedListener;
\r
12 import com.actionbarsherlock.ActionBarSherlock.OnActionModeStartedListener;
\r
13 import com.actionbarsherlock.ActionBarSherlock.OnCreatePanelMenuListener;
\r
14 import com.actionbarsherlock.ActionBarSherlock.OnMenuItemSelectedListener;
\r
15 import com.actionbarsherlock.ActionBarSherlock.OnPreparePanelListener;
\r
16 import com.actionbarsherlock.view.ActionMode;
\r
17 import com.actionbarsherlock.view.Menu;
\r
18 import com.actionbarsherlock.view.MenuInflater;
\r
19 import com.actionbarsherlock.view.MenuItem;
\r
21 public abstract class SherlockActivity extends Activity implements OnCreatePanelMenuListener, OnPreparePanelListener, OnMenuItemSelectedListener, OnActionModeStartedListener, OnActionModeFinishedListener {
\r
22 private ActionBarSherlock mSherlock;
\r
24 protected final ActionBarSherlock getSherlock() {
\r
25 if (mSherlock == null) {
\r
26 mSherlock = ActionBarSherlock.wrap(this, ActionBarSherlock.FLAG_DELEGATE);
\r
32 ///////////////////////////////////////////////////////////////////////////
\r
33 // Action bar and mode
\r
34 ///////////////////////////////////////////////////////////////////////////
\r
36 public ActionBar getSupportActionBar() {
\r
37 return getSherlock().getActionBar();
\r
40 public ActionMode startActionMode(ActionMode.Callback callback) {
\r
41 return getSherlock().startActionMode(callback);
\r
45 public void onActionModeStarted(ActionMode mode) {}
\r
48 public void onActionModeFinished(ActionMode mode) {}
\r
51 ///////////////////////////////////////////////////////////////////////////
\r
52 // General lifecycle/callback dispatching
\r
53 ///////////////////////////////////////////////////////////////////////////
\r
56 public void onConfigurationChanged(Configuration newConfig) {
\r
57 super.onConfigurationChanged(newConfig);
\r
58 getSherlock().dispatchConfigurationChanged(newConfig);
\r
62 protected void onPostResume() {
\r
63 super.onPostResume();
\r
64 getSherlock().dispatchPostResume();
\r
68 protected void onPause() {
\r
69 getSherlock().dispatchPause();
\r
74 protected void onStop() {
\r
75 getSherlock().dispatchStop();
\r
80 protected void onPostCreate(Bundle savedInstanceState) {
\r
81 getSherlock().dispatchPostCreate(savedInstanceState);
\r
82 super.onPostCreate(savedInstanceState);
\r
86 protected void onTitleChanged(CharSequence title, int color) {
\r
87 getSherlock().dispatchTitleChanged(title, color);
\r
88 super.onTitleChanged(title, color);
\r
92 public final boolean onMenuOpened(int featureId, android.view.Menu menu) {
\r
93 if (getSherlock().dispatchMenuOpened(featureId, menu)) {
\r
96 return super.onMenuOpened(featureId, menu);
\r
100 public void onPanelClosed(int featureId, android.view.Menu menu) {
\r
101 getSherlock().dispatchPanelClosed(featureId, menu);
\r
102 super.onPanelClosed(featureId, menu);
\r
106 public boolean dispatchKeyEvent(KeyEvent event) {
\r
107 if (getSherlock().dispatchKeyEvent(event)) {
\r
110 return super.dispatchKeyEvent(event);
\r
114 ///////////////////////////////////////////////////////////////////////////
\r
115 // Native menu handling
\r
116 ///////////////////////////////////////////////////////////////////////////
\r
118 public MenuInflater getSupportMenuInflater() {
\r
119 return getSherlock().getMenuInflater();
\r
122 public void invalidateOptionsMenu() {
\r
123 getSherlock().dispatchInvalidateOptionsMenu();
\r
126 public void supportInvalidateOptionsMenu() {
\r
127 invalidateOptionsMenu();
\r
131 public final boolean onCreateOptionsMenu(android.view.Menu menu) {
\r
132 return getSherlock().dispatchCreateOptionsMenu(menu);
\r
136 public final boolean onPrepareOptionsMenu(android.view.Menu menu) {
\r
137 return getSherlock().dispatchPrepareOptionsMenu(menu);
\r
141 public final boolean onOptionsItemSelected(android.view.MenuItem item) {
\r
142 return getSherlock().dispatchOptionsItemSelected(item);
\r
146 public void openOptionsMenu() {
\r
147 if (!getSherlock().dispatchOpenOptionsMenu()) {
\r
148 super.openOptionsMenu();
\r
153 public void closeOptionsMenu() {
\r
154 if (!getSherlock().dispatchCloseOptionsMenu()) {
\r
155 super.closeOptionsMenu();
\r
160 ///////////////////////////////////////////////////////////////////////////
\r
161 // Sherlock menu handling
\r
162 ///////////////////////////////////////////////////////////////////////////
\r
165 public boolean onCreatePanelMenu(int featureId, Menu menu) {
\r
166 if (featureId == Window.FEATURE_OPTIONS_PANEL) {
\r
167 return onCreateOptionsMenu(menu);
\r
172 public boolean onCreateOptionsMenu(Menu menu) {
\r
177 public boolean onPreparePanel(int featureId, View view, Menu menu) {
\r
178 if (featureId == Window.FEATURE_OPTIONS_PANEL) {
\r
179 return onPrepareOptionsMenu(menu);
\r
184 public boolean onPrepareOptionsMenu(Menu menu) {
\r
189 public boolean onMenuItemSelected(int featureId, MenuItem item) {
\r
190 if (featureId == Window.FEATURE_OPTIONS_PANEL) {
\r
191 return onOptionsItemSelected(item);
\r
196 public boolean onOptionsItemSelected(MenuItem item) {
\r
201 ///////////////////////////////////////////////////////////////////////////
\r
203 ///////////////////////////////////////////////////////////////////////////
\r
206 public void addContentView(View view, LayoutParams params) {
\r
207 getSherlock().addContentView(view, params);
\r
211 public void setContentView(int layoutResId) {
\r
212 getSherlock().setContentView(layoutResId);
\r
216 public void setContentView(View view, LayoutParams params) {
\r
217 getSherlock().setContentView(view, params);
\r
221 public void setContentView(View view) {
\r
222 getSherlock().setContentView(view);
\r
225 public void requestWindowFeature(long featureId) {
\r
226 getSherlock().requestFeature((int)featureId);
\r
230 ///////////////////////////////////////////////////////////////////////////
\r
231 // Progress Indication
\r
232 ///////////////////////////////////////////////////////////////////////////
\r
234 public void setSupportProgress(int progress) {
\r
235 getSherlock().setProgress(progress);
\r
238 public void setSupportProgressBarIndeterminate(boolean indeterminate) {
\r
239 getSherlock().setProgressBarIndeterminate(indeterminate);
\r
242 public void setSupportProgressBarIndeterminateVisibility(boolean visible) {
\r
243 getSherlock().setProgressBarIndeterminateVisibility(visible);
\r
246 public void setSupportProgressBarVisibility(boolean visible) {
\r
247 getSherlock().setProgressBarVisibility(visible);
\r
250 public void setSupportSecondaryProgress(int secondaryProgress) {
\r
251 getSherlock().setSecondaryProgress(secondaryProgress);
\r