2012-01-21 06:56:53 -05:00
|
|
|
package com.actionbarsherlock.app;
|
|
|
|
|
|
|
|
import android.app.ListActivity;
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.Window;
|
|
|
|
import android.view.ViewGroup.LayoutParams;
|
|
|
|
import com.actionbarsherlock.ActionBarSherlock;
|
|
|
|
import com.actionbarsherlock.ActionBarSherlock.OnActionModeFinishedListener;
|
|
|
|
import com.actionbarsherlock.ActionBarSherlock.OnActionModeStartedListener;
|
|
|
|
import com.actionbarsherlock.ActionBarSherlock.OnCreatePanelMenuListener;
|
|
|
|
import com.actionbarsherlock.ActionBarSherlock.OnMenuItemSelectedListener;
|
|
|
|
import com.actionbarsherlock.ActionBarSherlock.OnPreparePanelListener;
|
|
|
|
import com.actionbarsherlock.view.ActionMode;
|
|
|
|
import com.actionbarsherlock.view.Menu;
|
|
|
|
import com.actionbarsherlock.view.MenuInflater;
|
|
|
|
import com.actionbarsherlock.view.MenuItem;
|
|
|
|
|
2012-04-04 15:24:57 -04:00
|
|
|
public abstract class SherlockListActivity extends ListActivity implements OnCreatePanelMenuListener, OnPreparePanelListener, OnMenuItemSelectedListener, OnActionModeStartedListener, OnActionModeFinishedListener {
|
|
|
|
private ActionBarSherlock mSherlock;
|
|
|
|
|
|
|
|
protected final ActionBarSherlock getSherlock() {
|
|
|
|
if (mSherlock == null) {
|
|
|
|
mSherlock = ActionBarSherlock.wrap(this, ActionBarSherlock.FLAG_DELEGATE);
|
|
|
|
}
|
|
|
|
return mSherlock;
|
|
|
|
}
|
2012-01-21 06:56:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Action bar and mode
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
public ActionBar getSupportActionBar() {
|
2012-04-04 15:24:57 -04:00
|
|
|
return getSherlock().getActionBar();
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public ActionMode startActionMode(ActionMode.Callback callback) {
|
2012-04-04 15:24:57 -04:00
|
|
|
return getSherlock().startActionMode(callback);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-04-04 15:24:57 -04:00
|
|
|
public void onActionModeStarted(ActionMode mode) {}
|
2012-01-21 06:56:53 -05:00
|
|
|
|
|
|
|
@Override
|
2012-04-04 15:24:57 -04:00
|
|
|
public void onActionModeFinished(ActionMode mode) {}
|
2012-01-21 06:56:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// General lifecycle/callback dispatching
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().dispatchConfigurationChanged(newConfig);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostResume() {
|
|
|
|
super.onPostResume();
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().dispatchPostResume();
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().dispatchPause();
|
2012-01-21 06:56:53 -05:00
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().dispatchStop();
|
2012-01-21 06:56:53 -05:00
|
|
|
super.onStop();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostCreate(Bundle savedInstanceState) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().dispatchPostCreate(savedInstanceState);
|
2012-01-21 06:56:53 -05:00
|
|
|
super.onPostCreate(savedInstanceState);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onTitleChanged(CharSequence title, int color) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().dispatchTitleChanged(title, color);
|
2012-01-21 06:56:53 -05:00
|
|
|
super.onTitleChanged(title, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final boolean onMenuOpened(int featureId, android.view.Menu menu) {
|
2012-04-04 15:24:57 -04:00
|
|
|
if (getSherlock().dispatchMenuOpened(featureId, menu)) {
|
2012-01-21 06:56:53 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onMenuOpened(featureId, menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPanelClosed(int featureId, android.view.Menu menu) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().dispatchPanelClosed(featureId, menu);
|
2012-01-21 06:56:53 -05:00
|
|
|
super.onPanelClosed(featureId, menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-04-04 15:24:57 -04:00
|
|
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
|
|
|
if (getSherlock().dispatchKeyEvent(event)) {
|
2012-01-21 06:56:53 -05:00
|
|
|
return true;
|
|
|
|
}
|
2012-04-04 15:24:57 -04:00
|
|
|
return super.dispatchKeyEvent(event);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2012-04-04 15:24:57 -04:00
|
|
|
// Native menu handling
|
2012-01-21 06:56:53 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
public MenuInflater getSupportMenuInflater() {
|
2012-04-04 15:24:57 -04:00
|
|
|
return getSherlock().getMenuInflater();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void invalidateOptionsMenu() {
|
|
|
|
getSherlock().dispatchInvalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void supportInvalidateOptionsMenu() {
|
|
|
|
invalidateOptionsMenu();
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final boolean onCreateOptionsMenu(android.view.Menu menu) {
|
2012-04-04 15:24:57 -04:00
|
|
|
return getSherlock().dispatchCreateOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final boolean onPrepareOptionsMenu(android.view.Menu menu) {
|
|
|
|
return getSherlock().dispatchPrepareOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final boolean onOptionsItemSelected(android.view.MenuItem item) {
|
|
|
|
return getSherlock().dispatchOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openOptionsMenu() {
|
|
|
|
if (!getSherlock().dispatchOpenOptionsMenu()) {
|
|
|
|
super.openOptionsMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void closeOptionsMenu() {
|
|
|
|
if (!getSherlock().dispatchCloseOptionsMenu()) {
|
|
|
|
super.closeOptionsMenu();
|
|
|
|
}
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
2012-04-04 15:24:57 -04:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Sherlock menu handling
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-01-21 06:56:53 -05:00
|
|
|
@Override
|
|
|
|
public boolean onCreatePanelMenu(int featureId, Menu menu) {
|
|
|
|
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
|
|
|
|
return onCreateOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreparePanel(int featureId, View view, Menu menu) {
|
|
|
|
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
|
|
|
|
return onPrepareOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
|
|
|
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
|
|
|
|
return onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Content
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addContentView(View view, LayoutParams params) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().addContentView(view, params);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setContentView(int layoutResId) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().setContentView(layoutResId);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setContentView(View view, LayoutParams params) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().setContentView(view, params);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setContentView(View view) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().setContentView(view);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void requestWindowFeature(long featureId) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().requestFeature((int)featureId);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Progress Indication
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
public void setSupportProgress(int progress) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().setProgress(progress);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setSupportProgressBarIndeterminate(boolean indeterminate) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().setProgressBarIndeterminate(indeterminate);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setSupportProgressBarIndeterminateVisibility(boolean visible) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().setProgressBarIndeterminateVisibility(visible);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setSupportProgressBarVisibility(boolean visible) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().setProgressBarVisibility(visible);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setSupportSecondaryProgress(int secondaryProgress) {
|
2012-04-04 15:24:57 -04:00
|
|
|
getSherlock().setSecondaryProgress(secondaryProgress);
|
2012-01-21 06:56:53 -05:00
|
|
|
}
|
|
|
|
}
|