Java tutorial
/* 50AH-code ========= 50 Android Hacks (http://manning.com/sessa/) book source code Copyright (c) 2012 Manning Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.actionbarsherlock.app; import android.app.ExpandableListActivity; import android.content.res.Configuration; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.view.Window; 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; public abstract class SherlockExpandableListActivity extends ExpandableListActivity 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; } /////////////////////////////////////////////////////////////////////////// // Action bar and mode /////////////////////////////////////////////////////////////////////////// public ActionBar getSupportActionBar() { return getSherlock().getActionBar(); } public ActionMode startActionMode(ActionMode.Callback callback) { return getSherlock().startActionMode(callback); } @Override public void onActionModeStarted(ActionMode mode) { } @Override public void onActionModeFinished(ActionMode mode) { } /////////////////////////////////////////////////////////////////////////// // General lifecycle/callback dispatching /////////////////////////////////////////////////////////////////////////// @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); getSherlock().dispatchConfigurationChanged(newConfig); } @Override protected void onPostResume() { super.onPostResume(); getSherlock().dispatchPostResume(); } @Override protected void onPause() { getSherlock().dispatchPause(); super.onPause(); } @Override protected void onStop() { getSherlock().dispatchStop(); super.onStop(); } @Override protected void onDestroy() { getSherlock().dispatchDestroy(); super.onDestroy(); } @Override protected void onPostCreate(Bundle savedInstanceState) { getSherlock().dispatchPostCreate(savedInstanceState); super.onPostCreate(savedInstanceState); } @Override protected void onTitleChanged(CharSequence title, int color) { getSherlock().dispatchTitleChanged(title, color); super.onTitleChanged(title, color); } @Override public final boolean onMenuOpened(int featureId, android.view.Menu menu) { if (getSherlock().dispatchMenuOpened(featureId, menu)) { return true; } return super.onMenuOpened(featureId, menu); } @Override public void onPanelClosed(int featureId, android.view.Menu menu) { getSherlock().dispatchPanelClosed(featureId, menu); super.onPanelClosed(featureId, menu); } @Override public boolean dispatchKeyEvent(KeyEvent event) { if (getSherlock().dispatchKeyEvent(event)) { return true; } return super.dispatchKeyEvent(event); } /////////////////////////////////////////////////////////////////////////// // Native menu handling /////////////////////////////////////////////////////////////////////////// public MenuInflater getSupportMenuInflater() { return getSherlock().getMenuInflater(); } public void invalidateOptionsMenu() { getSherlock().dispatchInvalidateOptionsMenu(); } public void supportInvalidateOptionsMenu() { invalidateOptionsMenu(); } @Override public final boolean onCreateOptionsMenu(android.view.Menu menu) { 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(); } } /////////////////////////////////////////////////////////////////////////// // Sherlock menu handling /////////////////////////////////////////////////////////////////////////// @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) { getSherlock().addContentView(view, params); } @Override public void setContentView(int layoutResId) { getSherlock().setContentView(layoutResId); } @Override public void setContentView(View view, LayoutParams params) { getSherlock().setContentView(view, params); } @Override public void setContentView(View view) { getSherlock().setContentView(view); } public void requestWindowFeature(long featureId) { getSherlock().requestFeature((int) featureId); } /////////////////////////////////////////////////////////////////////////// // Progress Indication /////////////////////////////////////////////////////////////////////////// public void setSupportProgress(int progress) { getSherlock().setProgress(progress); } public void setSupportProgressBarIndeterminate(boolean indeterminate) { getSherlock().setProgressBarIndeterminate(indeterminate); } public void setSupportProgressBarIndeterminateVisibility(boolean visible) { getSherlock().setProgressBarIndeterminateVisibility(visible); } public void setSupportProgressBarVisibility(boolean visible) { getSherlock().setProgressBarVisibility(visible); } public void setSupportSecondaryProgress(int secondaryProgress) { getSherlock().setSecondaryProgress(secondaryProgress); } }