2 * Copyright 2011 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package net.sf.openrocket.android.actionbarcompat;
19 import net.sf.openrocket.R;
20 import android.app.Activity;
21 import android.os.Build;
22 import android.os.Bundle;
23 import android.view.Menu;
24 import android.view.MenuInflater;
27 * An abstract class that handles some common action bar-related functionality in the app. This
28 * class provides functionality useful for both phones and tablets, and does not require any Android
29 * 3.0-specific features, although it uses them if available.
31 * Two implementations of this class are {@link ActionBarHelperBase} for a pre-Honeycomb version of
32 * the action bar, and {@link ActionBarHelperHoneycomb}, which uses the built-in ActionBar features
33 * in Android 3.0 and later.
35 public abstract class ActionBarHelper {
36 protected Activity mActivity;
39 * Factory method for creating {@link ActionBarHelper} objects for a
40 * given activity. Depending on which device the app is running, either a basic helper or
41 * Honeycomb-specific helper will be returned.
43 public static ActionBarHelper createInstance(Activity activity) {
44 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
45 return new ActionBarHelperICS(activity);
46 } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
47 return new ActionBarHelperHoneycomb(activity);
49 return new ActionBarHelperBase(activity);
53 protected ActionBarHelper(Activity activity) {
58 * Action bar helper code to be run in {@link Activity#onCreate(android.os.Bundle)}.
60 public void onCreate(Bundle savedInstanceState) {
64 * Action bar helper code to be run in {@link Activity#onPostCreate(android.os.Bundle)}.
66 public void onPostCreate(Bundle savedInstanceState) {
70 * Action bar helper code to be run in {@link Activity#onCreateOptionsMenu(android.view.Menu)}.
72 * NOTE: Setting the visibility of menu items in <em>menu</em> is not currently supported.
74 public boolean onCreateOptionsMenu(Menu menu) {
79 * Action bar helper code to be run in {@link Activity#onTitleChanged(CharSequence, int)}.
81 protected void onTitleChanged(CharSequence title, int color) {
85 * Sets the indeterminate loading state of the item with ID {@link R.id.menu_refresh}.
86 * (where the item ID was menu_refresh).
88 public abstract void setRefreshActionItemState(boolean refreshing);
91 * Returns a {@link MenuInflater} for use when inflating menus. The implementation of this
92 * method in {@link ActionBarHelperBase} returns a wrapped menu inflater that can read
93 * action bar metadata from a menu resource pre-Honeycomb.
95 public MenuInflater getMenuInflater(MenuInflater superMenuInflater) {
96 return superMenuInflater;
99 public abstract void setDisplayHomeAsUpEnabled( boolean enabled );
101 public abstract void hide();