Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert line endings from `CRLF` to `LF`.

  • Loading branch information...
commit 74ca759a2fa5bdc10a38ad42645c64884d636804 1 parent b70b857
@johnjohndoe johnjohndoe authored
View
1,600 actionbarsherlock/src/com/actionbarsherlock/ActionBarSherlock.java
@@ -1,800 +1,800 @@
-package com.actionbarsherlock;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.res.Configuration;
-import android.os.Build;
-import android.os.Bundle;
-import android.util.DisplayMetrics;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.Window;
-import com.actionbarsherlock.app.ActionBar;
-import com.actionbarsherlock.internal.ActionBarSherlockCompat;
-import com.actionbarsherlock.internal.ActionBarSherlockNative;
-import com.actionbarsherlock.view.ActionMode;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
-
-/**
- * <p>Helper for implementing the action bar design pattern across all versions
- * of Android.</p>
- *
- * <p>This class will manage interaction with a custom action bar based on the
- * Android 4.0 source code. The exposed API mirrors that of its native
- * counterpart and you should refer to its documentation for instruction.</p>
- *
- * @author Jake Wharton <jakewharton@gmail.com>
- */
-public abstract class ActionBarSherlock {
- protected static final String TAG = "ActionBarSherlock";
- public static final boolean DEBUG = false;
-
- private static final Class<?>[] CONSTRUCTOR_ARGS = new Class[] { Activity.class, int.class };
- private static final HashMap<Implementation, Class<? extends ActionBarSherlock>> IMPLEMENTATIONS =
- new HashMap<Implementation, Class<? extends ActionBarSherlock>>();
-
- static {
- //Register our two built-in implementations
- registerImplementation(ActionBarSherlockCompat.class);
- registerImplementation(ActionBarSherlockNative.class);
- }
-
-
- /**
- * <p>Denotes an implementation of ActionBarSherlock which provides an
- * action bar-enhanced experience.</p>
- */
- @Target(ElementType.TYPE)
- @Retention(RetentionPolicy.RUNTIME)
- public @interface Implementation {
- static final int DEFAULT_API = -1;
- static final int DEFAULT_DPI = -1;
-
- int api() default DEFAULT_API;
- int dpi() default DEFAULT_DPI;
- }
-
-
- /** Activity interface for menu creation callback. */
- public interface OnCreatePanelMenuListener {
- public boolean onCreatePanelMenu(int featureId, Menu menu);
- }
- /** Activity interface for menu creation callback. */
- public interface OnCreateOptionsMenuListener {
- public boolean onCreateOptionsMenu(Menu menu);
- }
- /** Activity interface for menu item selection callback. */
- public interface OnMenuItemSelectedListener {
- public boolean onMenuItemSelected(int featureId, MenuItem item);
- }
- /** Activity interface for menu item selection callback. */
- public interface OnOptionsItemSelectedListener {
- public boolean onOptionsItemSelected(MenuItem item);
- }
- /** Activity interface for menu preparation callback. */
- public interface OnPreparePanelListener {
- public boolean onPreparePanel(int featureId, View view, Menu menu);
- }
- /** Activity interface for menu preparation callback. */
- public interface OnPrepareOptionsMenuListener {
- public boolean onPrepareOptionsMenu(Menu menu);
- }
- /** Activity interface for action mode finished callback. */
- public interface OnActionModeFinishedListener {
- public void onActionModeFinished(ActionMode mode);
- }
- /** Activity interface for action mode started callback. */
- public interface OnActionModeStartedListener {
- public void onActionModeStarted(ActionMode mode);
- }
-
-
- /**
- * If set, the logic in these classes will assume that an {@link Activity}
- * is dispatching all of the required events to the class. This flag should
- * only be used internally or if you are creating your own base activity
- * modeled after one of the included types (e.g., {@code SherlockActivity}).
- */
- public static final int FLAG_DELEGATE = 1;
-
-
- /**
- * Register an ActionBarSherlock implementation.
- *
- * @param implementationClass Target implementation class which extends
- * {@link ActionBarSherlock}. This class must also be annotated with
- * {@link Implementation}.
- */
- public static void registerImplementation(Class<? extends ActionBarSherlock> implementationClass) {
- if (!implementationClass.isAnnotationPresent(Implementation.class)) {
- throw new IllegalArgumentException("Class " + implementationClass.getSimpleName() + " is not annotated with @Implementation");
- } else if (IMPLEMENTATIONS.containsValue(implementationClass)) {
- if (DEBUG) Log.w(TAG, "Class " + implementationClass.getSimpleName() + " already registered");
- return;
- }
-
- Implementation impl = implementationClass.getAnnotation(Implementation.class);
- if (DEBUG) Log.i(TAG, "Registering " + implementationClass.getSimpleName() + " with qualifier " + impl);
- IMPLEMENTATIONS.put(impl, implementationClass);
- }
-
- /**
- * Unregister an ActionBarSherlock implementation. <strong>This should be
- * considered very volatile and you should only use it if you know what
- * you are doing.</strong> You have been warned.
- *
- * @param implementationClass Target implementation class.
- * @return Boolean indicating whether the class was removed.
- */
- public static boolean unregisterImplementation(Class<? extends ActionBarSherlock> implementationClass) {
- return IMPLEMENTATIONS.values().remove(implementationClass);
- }
-
- /**
- * Wrap an activity with an action bar abstraction which will enable the
- * use of a custom implementation on platforms where a native version does
- * not exist.
- *
- * @param activity Activity to wrap.
- * @return Instance to interact with the action bar.
- */
- public static ActionBarSherlock wrap(Activity activity) {
- return wrap(activity, 0);
- }
-
- /**
- * Wrap an activity with an action bar abstraction which will enable the
- * use of a custom implementation on platforms where a native version does
- * not exist.
- *
- * @param activity Owning activity.
- * @param flags Option flags to control behavior.
- * @return Instance to interact with the action bar.
- */
- public static ActionBarSherlock wrap(Activity activity, int flags) {
- //Create a local implementation map we can modify
- HashMap<Implementation, Class<? extends ActionBarSherlock>> impls =
- new HashMap<Implementation, Class<? extends ActionBarSherlock>>(IMPLEMENTATIONS);
- boolean hasQualfier;
-
- /* DPI FILTERING */
- hasQualfier = false;
- for (Implementation key : impls.keySet()) {
- //Only honor TVDPI as a specific qualifier
- if (key.dpi() == DisplayMetrics.DENSITY_TV) {
- hasQualfier = true;
- break;
- }
- }
- if (hasQualfier) {
- final boolean isTvDpi = activity.getResources().getDisplayMetrics().densityDpi == DisplayMetrics.DENSITY_TV;
- for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext(); ) {
- int keyDpi = keys.next().dpi();
- if ((isTvDpi && keyDpi != DisplayMetrics.DENSITY_TV)
- || (!isTvDpi && keyDpi == DisplayMetrics.DENSITY_TV)) {
- keys.remove();
- }
- }
- }
-
- /* API FILTERING */
- hasQualfier = false;
- for (Implementation key : impls.keySet()) {
- if (key.api() != Implementation.DEFAULT_API) {
- hasQualfier = true;
- break;
- }
- }
- if (hasQualfier) {
- final int runtimeApi = Build.VERSION.SDK_INT;
- int bestApi = 0;
- for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext(); ) {
- int keyApi = keys.next().api();
- if (keyApi > runtimeApi) {
- keys.remove();
- } else if (keyApi > bestApi) {
- bestApi = keyApi;
- }
- }
- for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext(); ) {
- if (keys.next().api() != bestApi) {
- keys.remove();
- }
- }
- }
-
- if (impls.size() > 1) {
- throw new IllegalStateException("More than one implementation matches configuration.");
- }
- if (impls.isEmpty()) {
- throw new IllegalStateException("No implementations match configuration.");
- }
- Class<? extends ActionBarSherlock> impl = impls.values().iterator().next();
- if (DEBUG) Log.i(TAG, "Using implementation: " + impl.getSimpleName());
-
- try {
- Constructor<? extends ActionBarSherlock> ctor = impl.getConstructor(CONSTRUCTOR_ARGS);
- return ctor.newInstance(activity, flags);
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- } catch (IllegalArgumentException e) {
- throw new RuntimeException(e);
- } catch (InstantiationException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
-
-
- /** Activity which is displaying the action bar. Also used for context. */
- protected final Activity mActivity;
- /** Whether delegating actions for the activity or managing ourselves. */
- protected final boolean mIsDelegate;
-
- /** Reference to our custom menu inflater which supports action items. */
- protected MenuInflater mMenuInflater;
-
-
-
- protected ActionBarSherlock(Activity activity, int flags) {
- if (DEBUG) Log.d(TAG, "[<ctor>] activity: " + activity + ", flags: " + flags);
-
- mActivity = activity;
- mIsDelegate = (flags & FLAG_DELEGATE) != 0;
- }
-
-
- /**
- * Get the current action bar instance.
- *
- * @return Action bar instance.
- */
- public abstract ActionBar getActionBar();
-
-
- ///////////////////////////////////////////////////////////////////////////
- // Lifecycle and interaction callbacks when delegating
- ///////////////////////////////////////////////////////////////////////////
-
- /**
- * Notify action bar of a configuration change event. Should be dispatched
- * after the call to the superclass implementation.
- *
- * <blockquote><pre>
- * @Override
- * public void onConfigurationChanged(Configuration newConfig) {
- * super.onConfigurationChanged(newConfig);
- * mSherlock.dispatchConfigurationChanged(newConfig);
- * }
- * </pre></blockquote>
- *
- * @param newConfig The new device configuration.
- */
- public void dispatchConfigurationChanged(Configuration newConfig) {}
-
- /**
- * Notify the action bar that the activity has finished its resuming. This
- * should be dispatched after the call to the superclass implementation.
- *
- * <blockquote><pre>
- * @Override
- * protected void onPostResume() {
- * super.onPostResume();
- * mSherlock.dispatchPostResume();
- * }
- * </pre></blockquote>
- */
- public void dispatchPostResume() {}
-
- /**
- * Notify the action bar that the activity is pausing. This should be
- * dispatched before the call to the superclass implementation.
- *
- * <blockquote><pre>
- * @Override
- * protected void onPause() {
- * mSherlock.dispatchPause();
- * super.onPause();
- * }
- * </pre></blockquote>
- */
- public void dispatchPause() {}
-
- /**
- * Notify the action bar that the activity is stopping. This should be
- * called before the superclass implementation.
- *
- * <blockquote><p>
- * @Override
- * protected void onStop() {
- * mSherlock.dispatchStop();
- * super.onStop();
- * }
- * </p></blockquote>
- */
- public void dispatchStop() {}
-
- /**
- * Indicate that the menu should be recreated by calling
- * {@link OnCreateOptionsMenuListener#onCreateOptionsMenu(com.actionbarsherlock.view.Menu)}.
- */
- public abstract void dispatchInvalidateOptionsMenu();
-
- /**
- * Notify the action bar that it should display its overflow menu if it is
- * appropriate for the device. The implementation should conditionally
- * call the superclass method only if this method returns {@code false}.
- *
- * <blockquote><p>
- * @Override
- * public void openOptionsMenu() {
- * if (!mSherlock.dispatchOpenOptionsMenu()) {
- * super.openOptionsMenu();
- * }
- * }
- * </p></blockquote>
- *
- * @return {@code true} if the opening of the menu was handled internally.
- */
- public boolean dispatchOpenOptionsMenu() {
- return false;
- }
-
- /**
- * Notify the action bar that it should close its overflow menu if it is
- * appropriate for the device. This implementation should conditionally
- * call the superclass method only if this method returns {@code false}.
- *
- * <blockquote><pre>
- * @Override
- * public void closeOptionsMenu() {
- * if (!mSherlock.dispatchCloseOptionsMenu()) {
- * super.closeOptionsMenu();
- * }
- * }
- * </pre></blockquote>
- *
- * @return {@code true} if the closing of the menu was handled internally.
- */
- public boolean dispatchCloseOptionsMenu() {
- return false;
- }
-
- /**
- * Notify the class that the activity has finished its creation. This
- * should be called after the superclass implementation.
- *
- * <blockquote><pre>
- * @Override
- * protected void onPostCreate(Bundle savedInstanceState) {
- * mSherlock.dispatchPostCreate(savedInstanceState);
- * super.onPostCreate(savedInstanceState);
- * }
- * </pre></blockquote>
- *
- * @param savedInstanceState If the activity is being re-initialized after
- * previously being shut down then this Bundle
- * contains the data it most recently supplied in
- * {@link Activity#}onSaveInstanceState(Bundle)}.
- * <strong>Note: Otherwise it is null.</strong>
- */
- public void dispatchPostCreate(Bundle savedInstanceState) {}
-
- /**
- * Notify the action bar that the title has changed and the action bar
- * should be updated to reflect the change. This should be called before
- * the superclass implementation.
- *
- * <blockquote><pre>
- * @Override
- * protected void onTitleChanged(CharSequence title, int color) {
- * mSherlock.dispatchTitleChanged(title, color);
- * super.onTitleChanged(title, color);
- * }
- * </pre></blockquote>
- *
- * @param title New activity title.
- * @param color New activity color.
- */
- public void dispatchTitleChanged(CharSequence title, int color) {}
-
- /**
- * Notify the action bar the user has created a key event. This is used to
- * toggle the display of the overflow action item with the menu key and to
- * close the action mode or expanded action item with the back key.
- *
- * <blockquote><pre>
- * @Override
- * public boolean dispatchKeyEvent(KeyEvent event) {
- * if (mSherlock.dispatchKeyEvent(event)) {
- * return true;
- * }
- * return super.dispatchKeyEvent(event);
- * }
- * </pre></blockquote>
- *
- * @param event Description of the key event.
- * @return {@code true} if the event was handled.
- */
- public boolean dispatchKeyEvent(KeyEvent event) {
- return false;
- }
-
- /**
- * Notify the action bar that the Activity has triggered a menu creation
- * which should happen on the conclusion of {@link Activity#onCreate}. This
- * will be used to gain a reference to the native menu for native and
- * overflow binding as well as to indicate when compatibility create should
- * occur for the first time.
- *
- * @param menu Activity native menu.
- * @return {@code true} since we always want to say that we have a native
- */
- public abstract boolean dispatchCreateOptionsMenu(android.view.Menu menu);
-
- /**
- * Notify the action bar that the Activity has triggered a menu preparation
- * which usually means that the user has requested the overflow menu via a
- * hardware menu key. You should return the result of this method call and
- * not call the superclass implementation.
- *
- * <blockquote><p>
- * @Override
- * public final boolean onPrepareOptionsMenu(android.view.Menu menu) {
- * return mSherlock.dispatchPrepareOptionsMenu(menu);
- * }
- * </p></blockquote>
- *
- * @param menu Activity native menu.
- * @return {@code true} if menu display should proceed.
- */
- public abstract boolean dispatchPrepareOptionsMenu(android.view.Menu menu);
-
- /**
- * Notify the action bar that a native options menu item has been selected.
- * The implementation should return the result of this method call.
- *
- * <blockquote><p>
- * @Override
- * public final boolean onOptionsItemSelected(android.view.MenuItem item) {
- * return mSherlock.dispatchOptionsItemSelected(item);
- * }
- * </p></blockquote>
- *
- * @param item Options menu item.
- * @return @{code true} if the selection was handled.
- */
- public abstract boolean dispatchOptionsItemSelected(android.view.MenuItem item);
-
- /**
- * Notify the action bar that the overflow menu has been opened. The
- * implementation should conditionally return {@code true} if this method
- * returns {@code true}, otherwise return the result of the superclass
- * method.
- *
- * <blockquote><p>
- * @Override
- * public final boolean onMenuOpened(int featureId, android.view.Menu menu) {
- * if (mSherlock.dispatchMenuOpened(featureId, menu)) {
- * return true;
- * }
- * return super.onMenuOpened(featureId, menu);
- * }
- * </p></blockquote>
- *
- * @param featureId Window feature which triggered the event.
- * @param menu Activity native menu.
- * @return {@code true} if the event was handled by this method.
- */
- public boolean dispatchMenuOpened(int featureId, android.view.Menu menu) {
- return false;
- }
-
- /**
- * Notify the action bar that the overflow menu has been closed. This
- * method should be called before the superclass implementation.
- *
- * <blockquote><p>
- * @Override
- * public void onPanelClosed(int featureId, android.view.Menu menu) {
- * mSherlock.dispatchPanelClosed(featureId, menu);
- * super.onPanelClosed(featureId, menu);
- * }
- * </p></blockquote>
- *
- * @param featureId
- * @param menu
- */
- public void dispatchPanelClosed(int featureId, android.view.Menu menu) {}
-
- /**
- * Notify the action bar that the activity has been destroyed. This method
- * should be called before the superclass implementation.
- *
- * <blockquote><p>
- * @Override
- * public void onDestroy() {
- * mSherlock.dispatchDestroy();
- * super.onDestroy();
- * }
- * </p></blockquote>
- */
- public void dispatchDestroy() {}
-
- public void dispatchSaveInstanceState(Bundle outState) {}
-
- public void dispatchRestoreInstanceState(Bundle savedInstanceState) {}
-
- ///////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////
-
-
- /**
- * Internal method to trigger the menu creation process.
- *
- * @return {@code true} if menu creation should proceed.
- */
- protected final boolean callbackCreateOptionsMenu(Menu menu) {
- if (DEBUG) Log.d(TAG, "[callbackCreateOptionsMenu] menu: " + menu);
-
- boolean result = true;
- if (mActivity instanceof OnCreatePanelMenuListener) {
- OnCreatePanelMenuListener listener = (OnCreatePanelMenuListener)mActivity;
- result = listener.onCreatePanelMenu(Window.FEATURE_OPTIONS_PANEL, menu);
- } else if (mActivity instanceof OnCreateOptionsMenuListener) {
- OnCreateOptionsMenuListener listener = (OnCreateOptionsMenuListener)mActivity;
- result = listener.onCreateOptionsMenu(menu);
- }
-
- if (DEBUG) Log.d(TAG, "[callbackCreateOptionsMenu] returning " + result);
- return result;
- }
-
- /**
- * Internal method to trigger the menu preparation process.
- *
- * @return {@code true} if menu preparation should proceed.
- */
- protected final boolean callbackPrepareOptionsMenu(Menu menu) {
- if (DEBUG) Log.d(TAG, "[callbackPrepareOptionsMenu] menu: " + menu);
-
- boolean result = true;
- if (mActivity instanceof OnPreparePanelListener) {
- OnPreparePanelListener listener = (OnPreparePanelListener)mActivity;
- result = listener.onPreparePanel(Window.FEATURE_OPTIONS_PANEL, null, menu);
- } else if (mActivity instanceof OnPrepareOptionsMenuListener) {
- OnPrepareOptionsMenuListener listener = (OnPrepareOptionsMenuListener)mActivity;
- result = listener.onPrepareOptionsMenu(menu);
- }
-
- if (DEBUG) Log.d(TAG, "[callbackPrepareOptionsMenu] returning " + result);
- return result;
- }
-
- /**
- * Internal method for dispatching options menu selection to the owning
- * activity callback.
- *
- * @param item Selected options menu item.
- * @return {@code true} if the item selection was handled in the callback.
- */
- protected final boolean callbackOptionsItemSelected(MenuItem item) {
- if (DEBUG) Log.d(TAG, "[callbackOptionsItemSelected] item: " + item.getTitleCondensed());
-
- boolean result = false;
- if (mActivity instanceof OnMenuItemSelectedListener) {
- OnMenuItemSelectedListener listener = (OnMenuItemSelectedListener)mActivity;
- result = listener.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item);
- } else if (mActivity instanceof OnOptionsItemSelectedListener) {
- OnOptionsItemSelectedListener listener = (OnOptionsItemSelectedListener)mActivity;
- result = listener.onOptionsItemSelected(item);
- }
-
- if (DEBUG) Log.d(TAG, "[callbackOptionsItemSelected] returning " + result);
- return result;
- }
-
-
- ///////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////
-
-
- /**
- * Query for the availability of a certain feature.
- *
- * @param featureId The feature ID to check.
- * @return {@code true} if feature is enabled, {@code false} otherwise.
- */
- public abstract boolean hasFeature(int featureId);
-
- /**
- * Enable extended screen features. This must be called before
- * {@code setContentView()}. May be called as many times as desired as long
- * as it is before {@code setContentView()}. If not called, no extended
- * features will be available. You can not turn off a feature once it is
- * requested.
- *
- * @param featureId The desired features, defined as constants by Window.
- * @return Returns true if the requested feature is supported and now
- * enabled.
- */
- public abstract boolean requestFeature(int featureId);
-
- /**
- * Set extra options that will influence the UI for this window.
- *
- * @param uiOptions Flags specifying extra options for this window.
- */
- public abstract void setUiOptions(int uiOptions);
-
- /**
- * Set extra options that will influence the UI for this window. Only the
- * bits filtered by mask will be modified.
- *
- * @param uiOptions Flags specifying extra options for this window.
- * @param mask Flags specifying which options should be modified. Others
- * will remain unchanged.
- */
- public abstract void setUiOptions(int uiOptions, int mask);
-
- /**
- * Set the content of the activity inside the action bar.
- *
- * @param layoutResId Layout resource ID.
- */
- public abstract void setContentView(int layoutResId);
-
- /**
- * Set the content of the activity inside the action bar.
- *
- * @param view The desired content to display.
- */
- public void setContentView(View view) {
- if (DEBUG) Log.d(TAG, "[setContentView] view: " + view);
-
- setContentView(view, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
- }
-
- /**
- * Set the content of the activity inside the action bar.
- *
- * @param view The desired content to display.
- * @param params Layout parameters to apply to the view.
- */
- public abstract void setContentView(View view, ViewGroup.LayoutParams params);
-
- /**
- * Variation on {@link #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)}
- * to add an additional content view to the screen. Added after any
- * existing ones on the screen -- existing views are NOT removed.
- *
- * @param view The desired content to display.
- * @param params Layout parameters for the view.
- */
- public abstract void addContentView(View view, ViewGroup.LayoutParams params);
-
- /**
- * Change the title associated with this activity.
- */
- public abstract void setTitle(CharSequence title);
-
- /**
- * Change the title associated with this activity.
- */
- public void setTitle(int resId) {
- if (DEBUG) Log.d(TAG, "[setTitle] resId: " + resId);
-
- setTitle(mActivity.getString(resId));
- }
-
- /**
- * Sets the visibility of the progress bar in the title.
- * <p>
- * In order for the progress bar to be shown, the feature must be requested
- * via {@link #requestWindowFeature(int)}.
- *
- * @param visible Whether to show the progress bars in the title.
- */
- public abstract void setProgressBarVisibility(boolean visible);
-
- /**
- * Sets the visibility of the indeterminate progress bar in the title.
- * <p>
- * In order for the progress bar to be shown, the feature must be requested
- * via {@link #requestWindowFeature(int)}.
- *
- * @param visible Whether to show the progress bars in the title.
- */
- public abstract void setProgressBarIndeterminateVisibility(boolean visible);
-
- /**
- * Sets whether the horizontal progress bar in the title should be indeterminate (the circular
- * is always indeterminate).
- * <p>
- * In order for the progress bar to be shown, the feature must be requested
- * via {@link #requestWindowFeature(int)}.
- *
- * @param indeterminate Whether the horizontal progress bar should be indeterminate.
- */
- public abstract void setProgressBarIndeterminate(boolean indeterminate);
-
- /**
- * Sets the progress for the progress bars in the title.
- * <p>
- * In order for the progress bar to be shown, the feature must be requested
- * via {@link #requestWindowFeature(int)}.
- *
- * @param progress The progress for the progress bar. Valid ranges are from
- * 0 to 10000 (both inclusive). If 10000 is given, the progress
- * bar will be completely filled and will fade out.
- */
- public abstract void setProgress(int progress);
-
- /**
- * Sets the secondary progress for the progress bar in the title. This
- * progress is drawn between the primary progress (set via
- * {@link #setProgress(int)} and the background. It can be ideal for media
- * scenarios such as showing the buffering progress while the default
- * progress shows the play progress.
- * <p>
- * In order for the progress bar to be shown, the feature must be requested
- * via {@link #requestWindowFeature(int)}.
- *
- * @param secondaryProgress The secondary progress for the progress bar. Valid ranges are from
- * 0 to 10000 (both inclusive).
- */
- public abstract void setSecondaryProgress(int secondaryProgress);
-
- /**
- * Get a menu inflater instance which supports the newer menu attributes.
- *
- * @return Menu inflater instance.
- */
- public MenuInflater getMenuInflater() {
- if (DEBUG) Log.d(TAG, "[getMenuInflater]");
-
- // Make sure that action views can get an appropriate theme.
- if (mMenuInflater == null) {
- if (getActionBar() != null) {
- mMenuInflater = new MenuInflater(getThemedContext(), mActivity);
- } else {
- mMenuInflater = new MenuInflater(mActivity);
- }
- }
- return mMenuInflater;
- }
-
- protected abstract Context getThemedContext();
-
- /**
- * Start an action mode.
- *
- * @param callback Callback that will manage lifecycle events for this
- * context mode.
- * @return The ContextMode that was started, or null if it was canceled.
- * @see ActionMode
- */
- public abstract ActionMode startActionMode(ActionMode.Callback callback);
-
- /**
- * Ensure that the action bar is attached.
- */
- public void ensureActionBar() {}
-}
+package com.actionbarsherlock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.os.Build;
+import android.os.Bundle;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.internal.ActionBarSherlockCompat;
+import com.actionbarsherlock.internal.ActionBarSherlockNative;
+import com.actionbarsherlock.view.ActionMode;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
+
+/**
+ * <p>Helper for implementing the action bar design pattern across all versions
+ * of Android.</p>
+ *
+ * <p>This class will manage interaction with a custom action bar based on the
+ * Android 4.0 source code. The exposed API mirrors that of its native
+ * counterpart and you should refer to its documentation for instruction.</p>
+ *
+ * @author Jake Wharton <jakewharton@gmail.com>
+ */
+public abstract class ActionBarSherlock {
+ protected static final String TAG = "ActionBarSherlock";
+ public static final boolean DEBUG = false;
+
+ private static final Class<?>[] CONSTRUCTOR_ARGS = new Class[] { Activity.class, int.class };
+ private static final HashMap<Implementation, Class<? extends ActionBarSherlock>> IMPLEMENTATIONS =
+ new HashMap<Implementation, Class<? extends ActionBarSherlock>>();
+
+ static {
+ //Register our two built-in implementations
+ registerImplementation(ActionBarSherlockCompat.class);
+ registerImplementation(ActionBarSherlockNative.class);
+ }
+
+
+ /**
+ * <p>Denotes an implementation of ActionBarSherlock which provides an
+ * action bar-enhanced experience.</p>
+ */
+ @Target(ElementType.TYPE)
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface Implementation {
+ static final int DEFAULT_API = -1;
+ static final int DEFAULT_DPI = -1;
+
+ int api() default DEFAULT_API;
+ int dpi() default DEFAULT_DPI;
+ }
+
+
+ /** Activity interface for menu creation callback. */
+ public interface OnCreatePanelMenuListener {
+ public boolean onCreatePanelMenu(int featureId, Menu menu);
+ }
+ /** Activity interface for menu creation callback. */
+ public interface OnCreateOptionsMenuListener {
+ public boolean onCreateOptionsMenu(Menu menu);
+ }
+ /** Activity interface for menu item selection callback. */
+ public interface OnMenuItemSelectedListener {
+ public boolean onMenuItemSelected(int featureId, MenuItem item);
+ }
+ /** Activity interface for menu item selection callback. */
+ public interface OnOptionsItemSelectedListener {
+ public boolean onOptionsItemSelected(MenuItem item);
+ }
+ /** Activity interface for menu preparation callback. */
+ public interface OnPreparePanelListener {
+ public boolean onPreparePanel(int featureId, View view, Menu menu);
+ }
+ /** Activity interface for menu preparation callback. */
+ public interface OnPrepareOptionsMenuListener {
+ public boolean onPrepareOptionsMenu(Menu menu);
+ }
+ /** Activity interface for action mode finished callback. */
+ public interface OnActionModeFinishedListener {
+ public void onActionModeFinished(ActionMode mode);
+ }
+ /** Activity interface for action mode started callback. */
+ public interface OnActionModeStartedListener {
+ public void onActionModeStarted(ActionMode mode);
+ }
+
+
+ /**
+ * If set, the logic in these classes will assume that an {@link Activity}
+ * is dispatching all of the required events to the class. This flag should
+ * only be used internally or if you are creating your own base activity
+ * modeled after one of the included types (e.g., {@code SherlockActivity}).
+ */
+ public static final int FLAG_DELEGATE = 1;
+
+
+ /**
+ * Register an ActionBarSherlock implementation.
+ *
+ * @param implementationClass Target implementation class which extends
+ * {@link ActionBarSherlock}. This class must also be annotated with
+ * {@link Implementation}.
+ */
+ public static void registerImplementation(Class<? extends ActionBarSherlock> implementationClass) {
+ if (!implementationClass.isAnnotationPresent(Implementation.class)) {
+ throw new IllegalArgumentException("Class " + implementationClass.getSimpleName() + " is not annotated with @Implementation");
+ } else if (IMPLEMENTATIONS.containsValue(implementationClass)) {
+ if (DEBUG) Log.w(TAG, "Class " + implementationClass.getSimpleName() + " already registered");
+ return;
+ }
+
+ Implementation impl = implementationClass.getAnnotation(Implementation.class);
+ if (DEBUG) Log.i(TAG, "Registering " + implementationClass.getSimpleName() + " with qualifier " + impl);
+ IMPLEMENTATIONS.put(impl, implementationClass);
+ }
+
+ /**
+ * Unregister an ActionBarSherlock implementation. <strong>This should be
+ * considered very volatile and you should only use it if you know what
+ * you are doing.</strong> You have been warned.
+ *
+ * @param implementationClass Target implementation class.
+ * @return Boolean indicating whether the class was removed.
+ */
+ public static boolean unregisterImplementation(Class<? extends ActionBarSherlock> implementationClass) {
+ return IMPLEMENTATIONS.values().remove(implementationClass);
+ }
+
+ /**
+ * Wrap an activity with an action bar abstraction which will enable the
+ * use of a custom implementation on platforms where a native version does
+ * not exist.
+ *
+ * @param activity Activity to wrap.
+ * @return Instance to interact with the action bar.
+ */
+ public static ActionBarSherlock wrap(Activity activity) {
+ return wrap(activity, 0);
+ }
+
+ /**
+ * Wrap an activity with an action bar abstraction which will enable the
+ * use of a custom implementation on platforms where a native version does
+ * not exist.
+ *
+ * @param activity Owning activity.
+ * @param flags Option flags to control behavior.
+ * @return Instance to interact with the action bar.
+ */
+ public static ActionBarSherlock wrap(Activity activity, int flags) {
+ //Create a local implementation map we can modify
+ HashMap<Implementation, Class<? extends ActionBarSherlock>> impls =
+ new HashMap<Implementation, Class<? extends ActionBarSherlock>>(IMPLEMENTATIONS);
+ boolean hasQualfier;
+
+ /* DPI FILTERING */
+ hasQualfier = false;
+ for (Implementation key : impls.keySet()) {
+ //Only honor TVDPI as a specific qualifier
+ if (key.dpi() == DisplayMetrics.DENSITY_TV) {
+ hasQualfier = true;
+ break;
+ }
+ }
+ if (hasQualfier) {
+ final boolean isTvDpi = activity.getResources().getDisplayMetrics().densityDpi == DisplayMetrics.DENSITY_TV;
+ for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext(); ) {
+ int keyDpi = keys.next().dpi();
+ if ((isTvDpi && keyDpi != DisplayMetrics.DENSITY_TV)
+ || (!isTvDpi && keyDpi == DisplayMetrics.DENSITY_TV)) {
+ keys.remove();
+ }
+ }
+ }
+
+ /* API FILTERING */
+ hasQualfier = false;
+ for (Implementation key : impls.keySet()) {
+ if (key.api() != Implementation.DEFAULT_API) {
+ hasQualfier = true;
+ break;
+ }
+ }
+ if (hasQualfier) {
+ final int runtimeApi = Build.VERSION.SDK_INT;
+ int bestApi = 0;
+ for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext(); ) {
+ int keyApi = keys.next().api();
+ if (keyApi > runtimeApi) {
+ keys.remove();
+ } else if (keyApi > bestApi) {
+ bestApi = keyApi;
+ }
+ }
+ for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext(); ) {
+ if (keys.next().api() != bestApi) {
+ keys.remove();
+ }
+ }
+ }
+
+ if (impls.size() > 1) {
+ throw new IllegalStateException("More than one implementation matches configuration.");
+ }
+ if (impls.isEmpty()) {
+ throw new IllegalStateException("No implementations match configuration.");
+ }
+ Class<? extends ActionBarSherlock> impl = impls.values().iterator().next();
+ if (DEBUG) Log.i(TAG, "Using implementation: " + impl.getSimpleName());
+
+ try {
+ Constructor<? extends ActionBarSherlock> ctor = impl.getConstructor(CONSTRUCTOR_ARGS);
+ return ctor.newInstance(activity, flags);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalArgumentException e) {
+ throw new RuntimeException(e);
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ /** Activity which is displaying the action bar. Also used for context. */
+ protected final Activity mActivity;
+ /** Whether delegating actions for the activity or managing ourselves. */
+ protected final boolean mIsDelegate;
+
+ /** Reference to our custom menu inflater which supports action items. */
+ protected MenuInflater mMenuInflater;
+
+
+
+ protected ActionBarSherlock(Activity activity, int flags) {
+ if (DEBUG) Log.d(TAG, "[<ctor>] activity: " + activity + ", flags: " + flags);
+
+ mActivity = activity;
+ mIsDelegate = (flags & FLAG_DELEGATE) != 0;
+ }
+
+
+ /**
+ * Get the current action bar instance.
+ *
+ * @return Action bar instance.
+ */
+ public abstract ActionBar getActionBar();
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Lifecycle and interaction callbacks when delegating
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Notify action bar of a configuration change event. Should be dispatched
+ * after the call to the superclass implementation.
+ *
+ * <blockquote><pre>
+ * @Override
+ * public void onConfigurationChanged(Configuration newConfig) {
+ * super.onConfigurationChanged(newConfig);
+ * mSherlock.dispatchConfigurationChanged(newConfig);
+ * }
+ * </pre></blockquote>
+ *
+ * @param newConfig The new device configuration.
+ */
+ public void dispatchConfigurationChanged(Configuration newConfig) {}
+
+ /**
+ * Notify the action bar that the activity has finished its resuming. This
+ * should be dispatched after the call to the superclass implementation.
+ *
+ * <blockquote><pre>
+ * @Override
+ * protected void onPostResume() {
+ * super.onPostResume();
+ * mSherlock.dispatchPostResume();
+ * }
+ * </pre></blockquote>
+ */
+ public void dispatchPostResume() {}
+
+ /**
+ * Notify the action bar that the activity is pausing. This should be
+ * dispatched before the call to the superclass implementation.
+ *
+ * <blockquote><pre>
+ * @Override
+ * protected void onPause() {
+ * mSherlock.dispatchPause();
+ * super.onPause();
+ * }
+ * </pre></blockquote>
+ */
+ public void dispatchPause() {}
+
+ /**
+ * Notify the action bar that the activity is stopping. This should be
+ * called before the superclass implementation.
+ *
+ * <blockquote><p>
+ * @Override
+ * protected void onStop() {
+ * mSherlock.dispatchStop();
+ * super.onStop();
+ * }
+ * </p></blockquote>
+ */
+ public void dispatchStop() {}
+
+ /**
+ * Indicate that the menu should be recreated by calling
+ * {@link OnCreateOptionsMenuListener#onCreateOptionsMenu(com.actionbarsherlock.view.Menu)}.
+ */
+ public abstract void dispatchInvalidateOptionsMenu();
+
+ /**
+ * Notify the action bar that it should display its overflow menu if it is
+ * appropriate for the device. The implementation should conditionally
+ * call the superclass method only if this method returns {@code false}.
+ *
+ * <blockquote><p>
+ * @Override
+ * public void openOptionsMenu() {
+ * if (!mSherlock.dispatchOpenOptionsMenu()) {
+ * super.openOptionsMenu();
+ * }
+ * }
+ * </p></blockquote>
+ *
+ * @return {@code true} if the opening of the menu was handled internally.
+ */
+ public boolean dispatchOpenOptionsMenu() {
+ return false;
+ }
+
+ /**
+ * Notify the action bar that it should close its overflow menu if it is
+ * appropriate for the device. This implementation should conditionally
+ * call the superclass method only if this method returns {@code false}.
+ *
+ * <blockquote><pre>
+ * @Override
+ * public void closeOptionsMenu() {
+ * if (!mSherlock.dispatchCloseOptionsMenu()) {
+ * super.closeOptionsMenu();
+ * }
+ * }
+ * </pre></blockquote>
+ *
+ * @return {@code true} if the closing of the menu was handled internally.
+ */
+ public boolean dispatchCloseOptionsMenu() {
+ return false;
+ }
+
+ /**
+ * Notify the class that the activity has finished its creation. This
+ * should be called after the superclass implementation.
+ *
+ * <blockquote><pre>
+ * @Override
+ * protected void onPostCreate(Bundle savedInstanceState) {
+ * mSherlock.dispatchPostCreate(savedInstanceState);
+ * super.onPostCreate(savedInstanceState);
+ * }
+ * </pre></blockquote>
+ *
+ * @param savedInstanceState If the activity is being re-initialized after
+ * previously being shut down then this Bundle
+ * contains the data it most recently supplied in
+ * {@link Activity#}onSaveInstanceState(Bundle)}.
+ * <strong>Note: Otherwise it is null.</strong>
+ */
+ public void dispatchPostCreate(Bundle savedInstanceState) {}
+
+ /**
+ * Notify the action bar that the title has changed and the action bar
+ * should be updated to reflect the change. This should be called before
+ * the superclass implementation.
+ *
+ * <blockquote><pre>
+ * @Override
+ * protected void onTitleChanged(CharSequence title, int color) {
+ * mSherlock.dispatchTitleChanged(title, color);
+ * super.onTitleChanged(title, color);
+ * }
+ * </pre></blockquote>
+ *
+ * @param title New activity title.
+ * @param color New activity color.
+ */
+ public void dispatchTitleChanged(CharSequence title, int color) {}
+
+ /**
+ * Notify the action bar the user has created a key event. This is used to
+ * toggle the display of the overflow action item with the menu key and to
+ * close the action mode or expanded action item with the back key.
+ *
+ * <blockquote><pre>
+ * @Override
+ * public boolean dispatchKeyEvent(KeyEvent event) {
+ * if (mSherlock.dispatchKeyEvent(event)) {
+ * return true;
+ * }
+ * return super.dispatchKeyEvent(event);
+ * }
+ * </pre></blockquote>
+ *
+ * @param event Description of the key event.
+ * @return {@code true} if the event was handled.
+ */
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ return false;
+ }
+
+ /**
+ * Notify the action bar that the Activity has triggered a menu creation
+ * which should happen on the conclusion of {@link Activity#onCreate}. This
+ * will be used to gain a reference to the native menu for native and
+ * overflow binding as well as to indicate when compatibility create should
+ * occur for the first time.
+ *
+ * @param menu Activity native menu.
+ * @return {@code true} since we always want to say that we have a native
+ */
+ public abstract boolean dispatchCreateOptionsMenu(android.view.Menu menu);
+
+ /**
+ * Notify the action bar that the Activity has triggered a menu preparation
+ * which usually means that the user has requested the overflow menu via a
+ * hardware menu key. You should return the result of this method call and
+ * not call the superclass implementation.
+ *
+ * <blockquote><p>
+ * @Override
+ * public final boolean onPrepareOptionsMenu(android.view.Menu menu) {
+ * return mSherlock.dispatchPrepareOptionsMenu(menu);
+ * }
+ * </p></blockquote>
+ *
+ * @param menu Activity native menu.
+ * @return {@code true} if menu display should proceed.
+ */
+ public abstract boolean dispatchPrepareOptionsMenu(android.view.Menu menu);
+
+ /**
+ * Notify the action bar that a native options menu item has been selected.
+ * The implementation should return the result of this method call.
+ *
+ * <blockquote><p>
+ * @Override
+ * public final boolean onOptionsItemSelected(android.view.MenuItem item) {
+ * return mSherlock.dispatchOptionsItemSelected(item);
+ * }
+ * </p></blockquote>
+ *
+ * @param item Options menu item.
+ * @return @{code true} if the selection was handled.
+ */
+ public abstract boolean dispatchOptionsItemSelected(android.view.MenuItem item);
+
+ /**
+ * Notify the action bar that the overflow menu has been opened. The
+ * implementation should conditionally return {@code true} if this method
+ * returns {@code true}, otherwise return the result of the superclass
+ * method.
+ *
+ * <blockquote><p>
+ * @Override
+ * public final boolean onMenuOpened(int featureId, android.view.Menu menu) {
+ * if (mSherlock.dispatchMenuOpened(featureId, menu)) {
+ * return true;
+ * }
+ * return super.onMenuOpened(featureId, menu);
+ * }
+ * </p></blockquote>
+ *
+ * @param featureId Window feature which triggered the event.
+ * @param menu Activity native menu.
+ * @return {@code true} if the event was handled by this method.
+ */
+ public boolean dispatchMenuOpened(int featureId, android.view.Menu menu) {
+ return false;
+ }
+
+ /**
+ * Notify the action bar that the overflow menu has been closed. This
+ * method should be called before the superclass implementation.
+ *
+ * <blockquote><p>
+ * @Override
+ * public void onPanelClosed(int featureId, android.view.Menu menu) {
+ * mSherlock.dispatchPanelClosed(featureId, menu);
+ * super.onPanelClosed(featureId, menu);
+ * }
+ * </p></blockquote>
+ *
+ * @param featureId
+ * @param menu
+ */
+ public void dispatchPanelClosed(int featureId, android.view.Menu menu) {}
+
+ /**
+ * Notify the action bar that the activity has been destroyed. This method
+ * should be called before the superclass implementation.
+ *
+ * <blockquote><p>
+ * @Override
+ * public void onDestroy() {
+ * mSherlock.dispatchDestroy();
+ * super.onDestroy();
+ * }
+ * </p></blockquote>
+ */
+ public void dispatchDestroy() {}
+
+ public void dispatchSaveInstanceState(Bundle outState) {}
+
+ public void dispatchRestoreInstanceState(Bundle savedInstanceState) {}
+
+ ///////////////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////////////
+
+
+ /**
+ * Internal method to trigger the menu creation process.
+ *
+ * @return {@code true} if menu creation should proceed.
+ */
+ protected final boolean callbackCreateOptionsMenu(Menu menu) {
+ if (DEBUG) Log.d(TAG, "[callbackCreateOptionsMenu] menu: " + menu);
+
+ boolean result = true;
+ if (mActivity instanceof OnCreatePanelMenuListener) {
+ OnCreatePanelMenuListener listener = (OnCreatePanelMenuListener)mActivity;
+ result = listener.onCreatePanelMenu(Window.FEATURE_OPTIONS_PANEL, menu);
+ } else if (mActivity instanceof OnCreateOptionsMenuListener) {
+ OnCreateOptionsMenuListener listener = (OnCreateOptionsMenuListener)mActivity;
+ result = listener.onCreateOptionsMenu(menu);
+ }
+
+ if (DEBUG) Log.d(TAG, "[callbackCreateOptionsMenu] returning " + result);
+ return result;
+ }
+
+ /**
+ * Internal method to trigger the menu preparation process.
+ *
+ * @return {@code true} if menu preparation should proceed.
+ */
+ protected final boolean callbackPrepareOptionsMenu(Menu menu) {
+ if (DEBUG) Log.d(TAG, "[callbackPrepareOptionsMenu] menu: " + menu);
+
+ boolean result = true;
+ if (mActivity instanceof OnPreparePanelListener) {
+ OnPreparePanelListener listener = (OnPreparePanelListener)mActivity;
+ result = listener.onPreparePanel(Window.FEATURE_OPTIONS_PANEL, null, menu);
+ } else if (mActivity instanceof OnPrepareOptionsMenuListener) {
+ OnPrepareOptionsMenuListener listener = (OnPrepareOptionsMenuListener)mActivity;
+ result = listener.onPrepareOptionsMenu(menu);
+ }
+
+ if (DEBUG) Log.d(TAG, "[callbackPrepareOptionsMenu] returning " + result);
+ return result;
+ }
+
+ /**
+ * Internal method for dispatching options menu selection to the owning
+ * activity callback.
+ *
+ * @param item Selected options menu item.
+ * @return {@code true} if the item selection was handled in the callback.
+ */
+ protected final boolean callbackOptionsItemSelected(MenuItem item) {
+ if (DEBUG) Log.d(TAG, "[callbackOptionsItemSelected] item: " + item.getTitleCondensed());
+
+ boolean result = false;
+ if (mActivity instanceof OnMenuItemSelectedListener) {
+ OnMenuItemSelectedListener listener = (OnMenuItemSelectedListener)mActivity;
+ result = listener.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item);
+ } else if (mActivity instanceof OnOptionsItemSelectedListener) {
+ OnOptionsItemSelectedListener listener = (OnOptionsItemSelectedListener)mActivity;
+ result = listener.onOptionsItemSelected(item);
+ }
+
+ if (DEBUG) Log.d(TAG, "[callbackOptionsItemSelected] returning " + result);
+ return result;
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////////////
+
+
+ /**
+ * Query for the availability of a certain feature.
+ *
+ * @param featureId The feature ID to check.
+ * @return {@code true} if feature is enabled, {@code false} otherwise.
+ */
+ public abstract boolean hasFeature(int featureId);
+
+ /**
+ * Enable extended screen features. This must be called before
+ * {@code setContentView()}. May be called as many times as desired as long
+ * as it is before {@code setContentView()}. If not called, no extended
+ * features will be available. You can not turn off a feature once it is
+ * requested.
+ *
+ * @param featureId The desired features, defined as constants by Window.
+ * @return Returns true if the requested feature is supported and now
+ * enabled.
+ */
+ public abstract boolean requestFeature(int featureId);
+
+ /**
+ * Set extra options that will influence the UI for this window.
+ *
+ * @param uiOptions Flags specifying extra options for this window.
+ */
+ public abstract void setUiOptions(int uiOptions);
+
+ /**
+ * Set extra options that will influence the UI for this window. Only the
+ * bits filtered by mask will be modified.
+ *
+ * @param uiOptions Flags specifying extra options for this window.
+ * @param mask Flags specifying which options should be modified. Others
+ * will remain unchanged.
+ */
+ public abstract void setUiOptions(int uiOptions, int mask);
+
+ /**
+ * Set the content of the activity inside the action bar.
+ *
+ * @param layoutResId Layout resource ID.
+ */
+ public abstract void setContentView(int layoutResId);
+
+ /**
+ * Set the content of the activity inside the action bar.
+ *
+ * @param view The desired content to display.
+ */
+ public void setContentView(View view) {
+ if (DEBUG) Log.d(TAG, "[setContentView] view: " + view);
+
+ setContentView(view, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
+ }
+
+ /**
+ * Set the content of the activity inside the action bar.
+ *
+ * @param view The desired content to display.
+ * @param params Layout parameters to apply to the view.
+ */
+ public abstract void setContentView(View view, ViewGroup.LayoutParams params);
+
+ /**
+ * Variation on {@link #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)}
+ * to add an additional content view to the screen. Added after any
+ * existing ones on the screen -- existing views are NOT removed.
+ *
+ * @param view The desired content to display.
+ * @param params Layout parameters for the view.
+ */
+ public abstract void addContentView(View view, ViewGroup.LayoutParams params);
+
+ /**
+ * Change the title associated with this activity.
+ */
+ public abstract void setTitle(CharSequence title);
+
+ /**
+ * Change the title associated with this activity.
+ */
+ public void setTitle(int resId) {
+ if (DEBUG) Log.d(TAG, "[setTitle] resId: " + resId);
+
+ setTitle(mActivity.getString(resId));
+ }
+
+ /**
+ * Sets the visibility of the progress bar in the title.
+ * <p>
+ * In order for the progress bar to be shown, the feature must be requested
+ * via {@link #requestWindowFeature(int)}.
+ *
+ * @param visible Whether to show the progress bars in the title.
+ */
+ public abstract void setProgressBarVisibility(boolean visible);
+
+ /**
+ * Sets the visibility of the indeterminate progress bar in the title.
+ * <p>
+ * In order for the progress bar to be shown, the feature must be requested
+ * via {@link #requestWindowFeature(int)}.
+ *
+ * @param visible Whether to show the progress bars in the title.
+ */
+ public abstract void setProgressBarIndeterminateVisibility(boolean visible);
+
+ /**
+ * Sets whether the horizontal progress bar in the title should be indeterminate (the circular
+ * is always indeterminate).
+ * <p>
+ * In order for the progress bar to be shown, the feature must be requested
+ * via {@link #requestWindowFeature(int)}.
+ *
+ * @param indeterminate Whether the horizontal progress bar should be indeterminate.
+ */
+ public abstract void setProgressBarIndeterminate(boolean indeterminate);
+
+ /**
+ * Sets the progress for the progress bars in the title.
+ * <p>
+ * In order for the progress bar to be shown, the feature must be requested
+ * via {@link #requestWindowFeature(int)}.
+ *
+ * @param progress The progress for the progress bar. Valid ranges are from
+ * 0 to 10000 (both inclusive). If 10000 is given, the progress
+ * bar will be completely filled and will fade out.
+ */
+ public abstract void setProgress(int progress);
+
+ /**
+ * Sets the secondary progress for the progress bar in the title. This
+ * progress is drawn between the primary progress (set via
+ * {@link #setProgress(int)} and the background. It can be ideal for media
+ * scenarios such as showing the buffering progress while the default
+ * progress shows the play progress.
+ * <p>
+ * In order for the progress bar to be shown, the feature must be requested
+ * via {@link #requestWindowFeature(int)}.
+ *
+ * @param secondaryProgress The secondary progress for the progress bar. Valid ranges are from
+ * 0 to 10000 (both inclusive).
+ */
+ public abstract void setSecondaryProgress(int secondaryProgress);
+
+ /**
+ * Get a menu inflater instance which supports the newer menu attributes.
+ *
+ * @return Menu inflater instance.
+ */
+ public MenuInflater getMenuInflater() {
+ if (DEBUG) Log.d(TAG, "[getMenuInflater]");
+
+ // Make sure that action views can get an appropriate theme.
+ if (mMenuInflater == null) {
+ if (getActionBar() != null) {
+ mMenuInflater = new MenuInflater(getThemedContext(), mActivity);
+ } else {
+ mMenuInflater = new MenuInflater(mActivity);
+ }
+ }
+ return mMenuInflater;
+ }
+
+ protected abstract Context getThemedContext();
+
+ /**
+ * Start an action mode.
+ *
+ * @param callback Callback that will manage lifecycle events for this
+ * context mode.
+ * @return The ContextMode that was started, or null if it was canceled.
+ * @see ActionMode
+ */
+ public abstract ActionMode startActionMode(ActionMode.Callback callback);
+
+ /**
+ * Ensure that the action bar is attached.
+ */
+ public void ensureActionBar() {}
+}
View
1,912 actionbarsherlock/src/com/actionbarsherlock/app/ActionBar.java
@@ -1,956 +1,956 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.actionbarsherlock.app;
-
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.support.v4.app.FragmentTransaction;
-import android.util.AttributeSet;
-import android.view.Gravity;
-import android.view.View;
-import android.view.ViewDebug;
-import android.view.ViewGroup;
-import android.view.ViewGroup.MarginLayoutParams;
-import android.widget.SpinnerAdapter;
-
-/**
- * A window feature at the top of the activity that may display the activity title, navigation
- * modes, and other interactive items.
- * <p>Beginning with Android 3.0 (API level 11), the action bar appears at the top of an
- * activity's window when the activity uses the system's {@link
- * android.R.style#Theme_Holo Holo} theme (or one of its descendant themes), which is the default.
- * You may otherwise add the action bar by calling {@link
- * android.view.Window#requestFeature requestFeature(FEATURE_ACTION_BAR)} or by declaring it in a
- * custom theme with the {@link android.R.styleable#Theme_windowActionBar windowActionBar} property.
- * <p>By default, the action bar shows the application icon on
- * the left, followed by the activity title. If your activity has an options menu, you can make
- * select items accessible directly from the action bar as "action items". You can also
- * modify various characteristics of the action bar or remove it completely.</p>
- * <p>From your activity, you can retrieve an instance of {@link ActionBar} by calling {@link
- * android.app.Activity#getActionBar getActionBar()}.</p>
- * <p>In some cases, the action bar may be overlayed by another bar that enables contextual actions,
- * using an {@link android.view.ActionMode}. For example, when the user selects one or more items in
- * your activity, you can enable an action mode that offers actions specific to the selected
- * items, with a UI that temporarily replaces the action bar. Although the UI may occupy the
- * same space, the {@link android.view.ActionMode} APIs are distinct and independent from those for
- * {@link ActionBar}.
- * <div class="special reference">
- * <h3>Developer Guides</h3>
- * <p>For information about how to use the action bar, including how to add action items, navigation
- * modes and more, read the <a href="{@docRoot}guide/topics/ui/actionbar.html">Action
- * Bar</a> developer guide.</p>
- * </div>
- */
-public abstract class ActionBar {
- /**
- * Standard navigation mode. Consists of either a logo or icon
- * and title text with an optional subtitle. Clicking any of these elements
- * will dispatch onOptionsItemSelected to the host Activity with
- * a MenuItem with item ID android.R.id.home.
- */
- public static final int NAVIGATION_MODE_STANDARD = android.app.ActionBar.NAVIGATION_MODE_STANDARD;
-
- /**
- * List navigation mode. Instead of static title text this mode
- * presents a list menu for navigation within the activity.
- * e.g. this might be presented to the user as a dropdown list.
- */
- public static final int NAVIGATION_MODE_LIST = android.app.ActionBar.NAVIGATION_MODE_LIST;
-
- /**
- * Tab navigation mode. Instead of static title text this mode
- * presents a series of tabs for navigation within the activity.
- */
- public static final int NAVIGATION_MODE_TABS = android.app.ActionBar.NAVIGATION_MODE_TABS;
-
- /**
- * Use logo instead of icon if available. This flag will cause appropriate
- * navigation modes to use a wider logo in place of the standard icon.
- *
- * @see #setDisplayOptions(int)
- * @see #setDisplayOptions(int, int)
- */
- public static final int DISPLAY_USE_LOGO = android.app.ActionBar.DISPLAY_USE_LOGO;
-
- /**
- * Show 'home' elements in this action bar, leaving more space for other
- * navigation elements. This includes logo and icon.
- *
- * @see #setDisplayOptions(int)
- * @see #setDisplayOptions(int, int)
- */
- public static final int DISPLAY_SHOW_HOME = android.app.ActionBar.DISPLAY_SHOW_HOME;
-
- /**
- * Display the 'home' element such that it appears as an 'up' affordance.
- * e.g. show an arrow to the left indicating the action that will be taken.
- *
- * Set this flag if selecting the 'home' button in the action bar to return
- * up by a single level in your UI rather than back to the top level or front page.
- *
- * <p>Setting this option will implicitly enable interaction with the home/up
- * button. See {@link #setHomeButtonEnabled(boolean)}.
- *
- * @see #setDisplayOptions(int)
- * @see #setDisplayOptions(int, int)
- */
- public static final int DISPLAY_HOME_AS_UP = android.app.ActionBar.DISPLAY_HOME_AS_UP;
-
- /**
- * Show the activity title and subtitle, if present.
- *
- * @see #setTitle(CharSequence)
- * @see #setTitle(int)
- * @see #setSubtitle(CharSequence)
- * @see #setSubtitle(int)
- * @see #setDisplayOptions(int)
- * @see #setDisplayOptions(int, int)
- */
- public static final int DISPLAY_SHOW_TITLE = android.app.ActionBar.DISPLAY_SHOW_TITLE;
-
- /**
- * Show the custom view if one has been set.
- * @see #setCustomView(View)
- * @see #setDisplayOptions(int)
- * @see #setDisplayOptions(int, int)
- */
- public static final int DISPLAY_SHOW_CUSTOM = android.app.ActionBar.DISPLAY_SHOW_CUSTOM;
-
- /**
- * Set the action bar into custom navigation mode, supplying a view
- * for custom navigation.
- *
- * Custom navigation views appear between the application icon and
- * any action buttons and may use any space available there. Common
- * use cases for custom navigation views might include an auto-suggesting
- * address bar for a browser or other navigation mechanisms that do not
- * translate well to provided navigation modes.
- *
- * @param view Custom navigation view to place in the ActionBar.
- */
- public abstract void setCustomView(View view);
-
- /**
- * Set the action bar into custom navigation mode, supplying a view
- * for custom navigation.
- *
- * <p>Custom navigation views appear between the application icon and
- * any action buttons and may use any space available there. Common
- * use cases for custom navigation views might include an auto-suggesting
- * address bar for a browser or other navigation mechanisms that do not
- * translate well to provided navigation modes.</p>
- *
- * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
- * the custom view to be displayed.</p>
- *
- * @param view Custom navigation view to place in the ActionBar.
- * @param layoutParams How this custom view should layout in the bar.
- *
- * @see #setDisplayOptions(int, int)
- */
- public abstract void setCustomView(View view, LayoutParams layoutParams);
-
- /**
- * Set the action bar into custom navigation mode, supplying a view
- * for custom navigation.
- *
- * <p>Custom navigation views appear between the application icon and
- * any action buttons and may use any space available there. Common
- * use cases for custom navigation views might include an auto-suggesting
- * address bar for a browser or other navigation mechanisms that do not
- * translate well to provided navigation modes.</p>
- *
- * <p>The display option {@link #DISPLAY_SHOW_CUSTOM} must be set for
- * the custom view to be displayed.</p>
- *
- * @param resId Resource ID of a layout to inflate into the ActionBar.
- *
- * @see #setDisplayOptions(int, int)
- */
- public abstract void setCustomView(int resId);
-
- /**
- * Set the icon to display in the 'home' section of the action bar.
- * The action bar will use an icon specified by its style or the
- * activity icon by default.
- *
- * Whether the home section shows an icon or logo is controlled
- * by the display option {@link #DISPLAY_USE_LOGO}.
- *
- * @param resId Resource ID of a drawable to show as an icon.
- *
- * @see #setDisplayUseLogoEnabled(boolean)
- * @see #setDisplayShowHomeEnabled(boolean)
- */
- public abstract void setIcon(int resId);
-
- /**
- * Set the icon to display in the 'home' section of the action bar.
- * The action bar will use an icon specified by its style or the
- * activity icon by default.
- *
- * Whether the home section shows an icon or logo is controlled
- * by the display option {@link #DISPLAY_USE_LOGO}.
- *
- * @param icon Drawable to show as an icon.
- *
- * @see #setDisplayUseLogoEnabled(boolean)
- * @see #setDisplayShowHomeEnabled(boolean)
- */
- public abstract void setIcon(Drawable icon);
-
- /**
- * Set the logo to display in the 'home' section of the action bar.
- * The action bar will use a logo specified by its style or the
- * activity logo by default.
- *
- * Whether the home section shows an icon or logo is controlled
- * by the display option {@link #DISPLAY_USE_LOGO}.
- *
- * @param resId Resource ID of a drawable to show as a logo.
- *
- * @see #setDisplayUseLogoEnabled(boolean)
- * @see #setDisplayShowHomeEnabled(boolean)
- */
- public abstract void setLogo(int resId);
-
- /**
- * Set the logo to display in the 'home' section of the action bar.
- * The action bar will use a logo specified by its style or the
- * activity logo by default.
- *
- * Whether the home section shows an icon or logo is controlled
- * by the display option {@link #DISPLAY_USE_LOGO}.
- *
- * @param logo Drawable to show as a logo.
- *
- * @see #setDisplayUseLogoEnabled(boolean)
- * @see #setDisplayShowHomeEnabled(boolean)
- */
- public abstract void setLogo(Drawable logo);
-
- /**
- * Set the adapter and navigation callback for list navigation mode.
- *
- * The supplied adapter will provide views for the expanded list as well as
- * the currently selected item. (These may be displayed differently.)
- *
- * The supplied OnNavigationListener will alert the application when the user
- * changes the current list selection.
- *
- * @param adapter An adapter that will provide views both to display
- * the current navigation selection and populate views
- * within the dropdown navigation menu.
- * @param callback An OnNavigationListener that will receive events when the user
- * selects a navigation item.
- */
- public abstract void setListNavigationCallbacks(SpinnerAdapter adapter,
- OnNavigationListener callback);
-
- /**
- * Set the selected navigation item in list or tabbed navigation modes.
- *
- * @param position Position of the item to select.
- */
- public abstract void setSelectedNavigationItem(int position);
-
- /**
- * Get the position of the selected navigation item in list or tabbed navigation modes.
- *
- * @return Position of the selected item.
- */
- public abstract int getSelectedNavigationIndex();
-
- /**
- * Get the number of navigation items present in the current navigation mode.
- *
- * @return Number of navigation items.
- */
- public abstract int getNavigationItemCount();
-
- /**
- * Set the action bar's title. This will only be displayed if
- * {@link #DISPLAY_SHOW_TITLE} is set.
- *
- * @param title Title to set
- *
- * @see #setTitle(int)
- * @see #setDisplayOptions(int, int)
- */
- public abstract void setTitle(CharSequence title);
-
- /**
- * Set the action bar's title. This will only be displayed if
- * {@link #DISPLAY_SHOW_TITLE} is set.
- *
- * @param resId Resource ID of title string to set
- *
- * @see #setTitle(CharSequence)
- * @see #setDisplayOptions(int, int)
- */
- public abstract void setTitle(int resId);
-
- /**
- * Set the action bar's subtitle. This will only be displayed if
- * {@link #DISPLAY_SHOW_TITLE} is set. Set to null to disable the
- * subtitle entirely.
- *
- * @param subtitle Subtitle to set
- *
- * @see #setSubtitle(int)
- * @see #setDisplayOptions(int, int)
- */
- public abstract void setSubtitle(CharSequence subtitle);
-
- /**
- * Set the action bar's subtitle. This will only be displayed if
- * {@link #DISPLAY_SHOW_TITLE} is set.
- *
- * @param resId Resource ID of subtitle string to set
- *
- * @see #setSubtitle(CharSequence)
- * @see #setDisplayOptions(int, int)
- */
- public abstract void setSubtitle(int resId);
-
- /**
- * Set display options. This changes all display option bits at once. To change
- * a limited subset of display options, see {@link #setDisplayOptions(int, int)}.
- *
- * @param options A combination of the bits defined by the DISPLAY_ constants
- * defined in ActionBar.
- */
- public abstract void setDisplayOptions(int options);
-
- /**
- * Set selected display options. Only the options specified by mask will be changed.
- * To change all display option bits at once, see {@link #setDisplayOptions(int)}.
- *
- * <p>Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
- * {@link #DISPLAY_SHOW_HOME} option.
- * setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO)
- * will enable {@link #DISPLAY_SHOW_HOME} and disable {@link #DISPLAY_USE_LOGO}.
- *
- * @param options A combination of the bits defined by the DISPLAY_ constants
- * defined in ActionBar.
- * @param mask A bit mask declaring which display options should be changed.
- */
- public abstract void setDisplayOptions(int options, int mask);
-
- /**
- * Set whether to display the activity logo rather than the activity icon.
- * A logo is often a wider, more detailed image.
- *
- * <p>To set several display options at once, see the setDisplayOptions methods.
- *
- * @param useLogo true to use the activity logo, false to use the activity icon.
- *
- * @see #setDisplayOptions(int)
- * @see #setDisplayOptions(int, int)
- */
- public abstract void setDisplayUseLogoEnabled(boolean useLogo);
-
- /**
- * Set whether to include the application home affordance in the action bar.
- * Home is presented as either an activity icon or logo.
- *
- * <p>To set several display options at once, see the setDisplayOptions methods.
- *
- * @param showHome true to show home, false otherwise.
- *
- * @see #setDisplayOptions(int)
- * @see #setDisplayOptions(int, int)
- */
- public abstract void setDisplayShowHomeEnabled(boolean showHome);
-
- /**
- * Set whether home should be displayed as an "up" affordance.
- * Set this to true if selecting "home" returns up by a single level in your UI
- * rather than back to the top level or front page.
- *
- * <p>To set several display options at once, see the setDisplayOptions methods.
- *
- * @param showHomeAsUp true to show the user that selecting home will return one
- * level up rather than to the top level of the app.
- *
- * @see #setDisplayOptions(int)
- * @see #setDisplayOptions(int, int)
- */
- public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);
-
- /**
- * Set whether an activity title/subtitle should be displayed.
- *
- * <p>To set several display options at once, see the setDisplayOptions methods.
- *
- * @param showTitle true to display a title/subtitle if present.
- *
- * @see #setDisplayOptions(int)
- * @see #setDisplayOptions(int, int)
- */
- public abstract void setDisplayShowTitleEnabled(boolean showTitle);
-
- /**
- * Set whether a custom view should be displayed, if set.
- *
- * <p>To set several display options at once, see the setDisplayOptions methods.
- *
- * @param showCustom true if the currently set custom view should be displayed, false otherwise.
- *
- * @see #setDisplayOptions(int)
- * @see #setDisplayOptions(int, int)
- */
- public abstract void setDisplayShowCustomEnabled(boolean showCustom);
-
- /**
- * Set the ActionBar's background. This will be used for the primary
- * action bar.
- *
- * @param d Background drawable
- * @see #setStackedBackgroundDrawable(Drawable)
- * @see #setSplitBackgroundDrawable(Drawable)
- */
- public abstract void setBackgroundDrawable(Drawable d);
-
- /**
- * Set the ActionBar's stacked background. This will appear
- * in the second row/stacked bar on some devices and configurations.
- *
- * @param d Background drawable for the stacked row
- */
- public void setStackedBackgroundDrawable(Drawable d) { }
-
- /**
- * Set the ActionBar's split background. This will appear in
- * the split action bar containing menu-provided action buttons
- * on some devices and configurations.
- * <p>You can enable split action bar with {@link android.R.attr#uiOptions}
- *
- * @param d Background drawable for the split bar
- */
- public void setSplitBackgroundDrawable(Drawable d) { }
-
- /**
- * @return The current custom view.
- */
- public abstract View getCustomView();
-
- /**
- * Returns the current ActionBar title in standard mode.
- * Returns null if {@link #getNavigationMode()} would not return
- * {@link #NAVIGATION_MODE_STANDARD}.
- *
- * @return The current ActionBar title or null.
- */
- public abstract CharSequence getTitle();
-
- /**
- * Returns the current ActionBar subtitle in standard mode.
- * Returns null if {@link #getNavigationMode()} would not return
- * {@link #NAVIGATION_MODE_STANDARD}.
- *
- * @return The current ActionBar subtitle or null.
- */
- public abstract CharSequence getSubtitle();
-
- /**
- * Returns the current navigation mode. The result will be one of:
- * <ul>
- * <li>{@link #NAVIGATION_MODE_STANDARD}</li>
- * <li>{@link #NAVIGATION_MODE_LIST}</li>
- * <li>{@link #NAVIGATION_MODE_TABS}</li>
- * </ul>
- *
- * @return The current navigation mode.
- */
- public abstract int getNavigationMode();
-
- /**
- * Set the current navigation mode.
- *
- * @param mode The new mode to set.
- * @see #NAVIGATION_MODE_STANDARD
- * @see #NAVIGATION_MODE_LIST
- * @see #NAVIGATION_MODE_TABS
- */
- public abstract void setNavigationMode(int mode);
-
- /**
- * @return The current set of display options.
- */
- public abstract int getDisplayOptions();
-
- /**
- * Create and return a new {@link Tab}.
- * This tab will not be included in the action bar until it is added.
- *
- * <p>Very often tabs will be used to switch between {@link Fragment}
- * objects. Here is a typical implementation of such tabs:</p>
- *
- * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.java
- * complete}
- *
- * @return A new Tab
- *
- * @see #addTab(Tab)
- */
- public abstract Tab newTab();
-
- /**
- * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
- * If this is the first tab to be added it will become the selected tab.
- *
- * @param tab Tab to add
- */
- public abstract void addTab(Tab tab);
-
- /**
- * Add a tab for use in tabbed navigation mode. The tab will be added at the end of the list.
- *
- * @param tab Tab to add
- * @param setSelected True if the added tab should become the selected tab.
- */
- public abstract void addTab(Tab tab, boolean setSelected);
-
- /**
- * Add a tab for use in tabbed navigation mode. The tab will be inserted at
- * <code>position</code>. If this is the first tab to be added it will become
- * the selected tab.
- *
- * @param tab The tab to add
- * @param position The new position of the tab
- */
- public abstract void addTab(Tab tab, int position);
-
- /**
- * Add a tab for use in tabbed navigation mode. The tab will be insterted at
- * <code>position</code>.
- *
- * @param tab The tab to add
- * @param position The new position of the tab
- * @param setSelected True if the added tab should become the selected tab.
- */
- public abstract void addTab(Tab tab, int position, boolean setSelected);
-
- /**
- * Remove a tab from the action bar. If the removed tab was selected it will be deselected
- * and another tab will be selected if present.
- *
- * @param tab The tab to remove
- */
- public abstract void removeTab(Tab tab);
-
- /**
- * Remove a tab from the action bar. If the removed tab was selected it will be deselected
- * and another tab will be selected if present.
- *
- * @param position Position of the tab to remove
- */
- public abstract void removeTabAt(int position);
-
- /**
- * Remove all tabs from the action bar and deselect the current tab.
- */
- public abstract void removeAllTabs();
-
- /**
- * Select the specified tab. If it is not a child of this action bar it will be added.
- *
- * <p>Note: If you want to select by index, use {@link #setSelectedNavigationItem(int)}.</p>
- *
- * @param tab Tab to select
- */
- public abstract void selectTab(Tab tab);
-
- /**
- * Returns the currently selected tab if in tabbed navigation mode and there is at least
- * one tab present.
- *
- * @return The currently selected tab or null
- */
- public abstract Tab getSelectedTab();
-
- /**
- * Returns the tab at the specified index.
- *
- * @param index Index value in the range 0-get
- * @return
- */
- public abstract Tab getTabAt(int index);
-
- /**
- * Returns the number of tabs currently registered with the action bar.
- * @return Tab count
- */
- public abstract int getTabCount();
-
- /**
- * Retrieve the current height of the ActionBar.
- *
- * @return The ActionBar's height
- */
- public abstract int getHeight();
-
- /**
- * Show the ActionBar if it is not currently showing.
- * If the window hosting the ActionBar does not have the feature
- * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
- * content to fit the new space available.
- */
- public abstract void show();
-
- /**
- * Hide the ActionBar if it is currently showing.
- * If the window hosting the ActionBar does not have the feature
- * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application
- * content to fit the new space available.
- */
- public abstract void hide();
-
- /**
- * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise.
- */
- public abstract boolean isShowing();
-
- /**
- * Add a listener that will respond to menu visibility change events.
- *
- * @param listener The new listener to add
- */
- public abstract void addOnMenuVisibilityListener(OnMenuVisibilityListener listener);
-
- /**
- * Remove a menu visibility listener. This listener will no longer receive menu
- * visibility change events.
- *
- * @param listener A listener to remove that was previously added
- */
- public abstract void removeOnMenuVisibilityListener(OnMenuVisibilityListener listener);
-
- /**
- * Enable or disable the "home" button in the corner of the action bar. (Note that this
- * is the application home/up affordance on the action bar, not the systemwide home
- * button.)
- *
- * <p>This defaults to true for packages targeting &lt; API 14. For packages targeting
- * API 14 or greater, the application should call this method to enable interaction
- * with the home/up affordance.
- *
- * <p>Setting the {@link #DISPLAY_HOME_AS_UP} display option will automatically enable
- * the home button.
- *
- * @param enabled true to enable the home button, false to disable the home button.
- */
- public void setHomeButtonEnabled(boolean enabled) { }
-
- /**
- * Returns a {@link Context} with an appropriate theme for creating views that
- * will appear in the action bar. If you are inflating or instantiating custom views
- * that will appear in an action bar, you should use the Context returned by this method.
- * (This includes adapters used for list navigation mode.)
- * This will ensure that views contrast properly against the action bar.
- *
- * @return A themed Context for creating views
- */
- public Context getThemedContext() { return null; }
-
- /**
- * Listener interface for ActionBar navigation events.
- */
- public interface OnNavigationListener {
- /**
- * This method is called whenever a navigation item in your action bar
- * is selected.
- *
- * @param itemPosition Position of the item clicked.
- * @param itemId ID of the item clicked.
- * @return True if the event was handled, false otherwise.
- */
- public boolean onNavigationItemSelected(int itemPosition, long itemId);
- }
-
- /**
- * Listener for receiving events when action bar menus are shown or hidden.
- */
- public interface OnMenuVisibilityListener {
- /**
- * Called when an action bar menu is shown or hidden. Applications may want to use
- * this to tune auto-hiding behavior for the action bar or pause/resume video playback,
- * gameplay, or other activity within the main content area.
- *
- * @param isVisible True if an action bar menu is now visible, false if no action bar
- * menus are visible.
- */
- public void onMenuVisibilityChanged(boolean isVisible);
- }
-
- /**
- * A tab in the action bar.
- *
- * <p>Tabs manage the hiding and showing of {@link Fragment}s.
- */
- public static abstract class Tab {
- /**
- * An invalid position for a tab.
- *
- * @see #getPosition()
- */
- public static final int INVALID_POSITION = -1;
-
- /**
- * Return the current position of this tab in the action bar.
- *
- * @return Current position, or {@link #INVALID_POSITION} if this tab is not currently in
- * the action bar.
- */
- public abstract int getPosition();
-
- /**
- * Return the icon associated with this tab.
- *
- * @return The tab's icon
- */
- public abstract Drawable getIcon();
-
- /**
- * Return the text of this tab.
- *
- * @return The tab's text
- */
- public abstract CharSequence getText();
-
- /**
- * Set the icon displayed on this tab.
- *
- * @param icon The drawable to use as an icon
- * @return The current instance for call chaining
- */
- public abstract Tab setIcon(Drawable icon);
-
- /**
- * Set the icon displayed on this tab.
- *
- * @param resId Resource ID referring to the drawable to use as an icon
- * @return The current instance for call chaining
- */
- public abstract Tab setIcon(int resId);
-
- /**
- * Set the text displayed on this tab. Text may be truncated if there is not
- * room to display the entire string.
- *
- * @param text The text to display
- * @return The current instance for call chaining
- */
- public abstract Tab setText(CharSequence text);
-
- /**
- * Set the text displayed on this tab. Text may be truncated if there is not
- * room to display the entire string.
- *
- * @param resId A resource ID referring to the text that should be displayed
- * @return The current instance for call chaining
- */
- public abstract Tab setText(int resId);
-
- /**
- * Set a custom view to be used for this tab. This overrides values set by
- * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
- *
- * @param view Custom view to be used as a tab.
- * @return The current instance for call chaining
- */
- public abstract Tab setCustomView(View view);
-
- /**
- * Set a custom view to be used for this tab. This overrides values set by
- * {@link #setText(CharSequence)} and {@link #setIcon(Drawable)}.
- *
- * @param layoutResId A layout resource to inflate and use as a custom tab view
- * @return The current instance for call chaining
- */
- public abstract Tab setCustomView(int layoutResId);
-
- /**
- * Retrieve a previously set custom view for this tab.
- *
- * @return The custom view set by {@link #setCustomView(View)}.
- */
- public abstract View getCustomView();
-
- /**
- * Give this Tab an arbitrary object to hold for later use.
- *
- * @param obj Object to store
- * @return The current instance for call chaining
- */
- public abstract Tab setTag(Object obj);
-
- /**
- * @return This Tab's tag object.
- */
- public abstract Object getTag();
-
- /**
- * Set the {@link TabListener} that will handle switching to and from this tab.
- * All tabs must have a TabListener set before being added to the ActionBar.
- *
- * @param listener Listener to handle tab selection events
- * @return The current instance for call chaining
- */
- public abstract Tab setTabListener(TabListener listener);
-
- /**
- * Select this tab. Only valid if the tab has been added to the action bar.
- */
- public abstract void select();
-
- /**
- * Set a description of this tab's content for use in accessibility support.
- * If no content description is provided the title will be used.
- *
- * @param resId A resource ID referring to the description text
- * @return The current instance for call chaining
- * @see #setContentDescription(CharSequence)
- * @see #getContentDescription()
- */
- public abstract Tab setContentDescription(int resId);
-
- /**
- * Set a description of this tab's content for use in accessibility support.
- * If no content description is provided the title will be used.
- *
- * @param contentDesc Description of this tab's content
- * @return The current instance for call chaining
- * @see #setContentDescription(int)
- * @see #getContentDescription()
- */
- public abstract Tab setContentDescription(CharSequence contentDesc);
-
- /**
- * Gets a brief description of this tab's content for use in accessibility support.
- *
- * @return Description of this tab's content
- * @see #setContentDescription(CharSequence)
- * @see #setContentDescription(int)