diff --git a/build/sdk.atree b/build/sdk.atree
index df1512650..ca51ec531 100644
--- a/build/sdk.atree
+++ b/build/sdk.atree
@@ -153,6 +153,7 @@ development/samples/source.properties samples/${PLATFORM_NAME}/source.pro
#
development/samples/AccessibilityService samples/${PLATFORM_NAME}/AccessibilityService
development/samples/AccelerometerPlay samples/${PLATFORM_NAME}/AccelerometerPlay
+development/samples/ActionBarCompat samples/${PLATFORM_NAME}/ActionBarCompat
development/samples/AndroidBeam samples/${PLATFORM_NAME}/AndroidBeam
development/samples/ApiDemos samples/${PLATFORM_NAME}/ApiDemos
development/samples/BackupRestore samples/${PLATFORM_NAME}/BackupRestore
diff --git a/samples/ActionBarCompat/Android.mk b/samples/ActionBarCompat/Android.mk
new file mode 100644
index 000000000..d9da54a7f
--- /dev/null
+++ b/samples/ActionBarCompat/Android.mk
@@ -0,0 +1,16 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := samples
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := ActionBarCompat
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/samples/ActionBarCompat/AndroidManifest.xml b/samples/ActionBarCompat/AndroidManifest.xml
new file mode 100644
index 000000000..1a48274a8
--- /dev/null
+++ b/samples/ActionBarCompat/AndroidManifest.xml
@@ -0,0 +1,34 @@
+
+
+
This sample shows how to use the action bar design pattern on pre-API 11 devices and the built-in
+ActionBar on devices supporting API
+11 or greater. The example 'compatible' action bar, instantiated on pre-Android 3.0 devices,
+uses the same menu resource-based
+action item definition mechanism as the new framework API, even supporting the
+android:showAsAction attribute to a limited extent.
+
diff --git a/samples/ActionBarCompat/res/drawable-hdpi/actionbar_shadow.9.png b/samples/ActionBarCompat/res/drawable-hdpi/actionbar_shadow.9.png
new file mode 100644
index 000000000..3c80a3fca
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-hdpi/actionbar_shadow.9.png differ
diff --git a/samples/ActionBarCompat/res/drawable-hdpi/ic_action_refresh.png b/samples/ActionBarCompat/res/drawable-hdpi/ic_action_refresh.png
new file mode 100644
index 000000000..efe99e092
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-hdpi/ic_action_refresh.png differ
diff --git a/samples/ActionBarCompat/res/drawable-hdpi/ic_action_search.png b/samples/ActionBarCompat/res/drawable-hdpi/ic_action_search.png
new file mode 100644
index 000000000..f6719d228
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-hdpi/ic_action_search.png differ
diff --git a/samples/ActionBarCompat/res/drawable-hdpi/ic_action_share.png b/samples/ActionBarCompat/res/drawable-hdpi/ic_action_share.png
new file mode 100644
index 000000000..7d0b8720c
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-hdpi/ic_action_share.png differ
diff --git a/samples/ActionBarCompat/res/drawable-hdpi/ic_home.png b/samples/ActionBarCompat/res/drawable-hdpi/ic_home.png
new file mode 100644
index 000000000..7e52ff595
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-hdpi/ic_home.png differ
diff --git a/samples/ActionBarCompat/res/drawable-hdpi/ic_launcher.png b/samples/ActionBarCompat/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 000000000..e4b0492c6
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/ActionBarCompat/res/drawable-hdpi/ic_menu_share.png b/samples/ActionBarCompat/res/drawable-hdpi/ic_menu_share.png
new file mode 100755
index 000000000..a78bf7a4d
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-hdpi/ic_menu_share.png differ
diff --git a/samples/ActionBarCompat/res/drawable-mdpi/actionbar_shadow.9.png b/samples/ActionBarCompat/res/drawable-mdpi/actionbar_shadow.9.png
new file mode 100644
index 000000000..cae1778f4
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-mdpi/actionbar_shadow.9.png differ
diff --git a/samples/ActionBarCompat/res/drawable-mdpi/ic_action_refresh.png b/samples/ActionBarCompat/res/drawable-mdpi/ic_action_refresh.png
new file mode 100644
index 000000000..a85eee381
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-mdpi/ic_action_refresh.png differ
diff --git a/samples/ActionBarCompat/res/drawable-mdpi/ic_action_search.png b/samples/ActionBarCompat/res/drawable-mdpi/ic_action_search.png
new file mode 100755
index 000000000..45d2398ae
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-mdpi/ic_action_search.png differ
diff --git a/samples/ActionBarCompat/res/drawable-mdpi/ic_action_share.png b/samples/ActionBarCompat/res/drawable-mdpi/ic_action_share.png
new file mode 100644
index 000000000..26a39bdff
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-mdpi/ic_action_share.png differ
diff --git a/samples/ActionBarCompat/res/drawable-mdpi/ic_home.png b/samples/ActionBarCompat/res/drawable-mdpi/ic_home.png
new file mode 100644
index 000000000..949b4aa9a
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-mdpi/ic_home.png differ
diff --git a/samples/ActionBarCompat/res/drawable-mdpi/ic_launcher.png b/samples/ActionBarCompat/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 000000000..78d0e29f5
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/ActionBarCompat/res/drawable-mdpi/ic_menu_share.png b/samples/ActionBarCompat/res/drawable-mdpi/ic_menu_share.png
new file mode 100755
index 000000000..3329b6b0a
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-mdpi/ic_menu_share.png differ
diff --git a/samples/ActionBarCompat/res/drawable-xhdpi/actionbar_shadow.9.png b/samples/ActionBarCompat/res/drawable-xhdpi/actionbar_shadow.9.png
new file mode 100644
index 000000000..30778e3f8
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-xhdpi/actionbar_shadow.9.png differ
diff --git a/samples/ActionBarCompat/res/drawable-xhdpi/ic_action_refresh.png b/samples/ActionBarCompat/res/drawable-xhdpi/ic_action_refresh.png
new file mode 100644
index 000000000..6ce93766c
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-xhdpi/ic_action_refresh.png differ
diff --git a/samples/ActionBarCompat/res/drawable-xhdpi/ic_action_search.png b/samples/ActionBarCompat/res/drawable-xhdpi/ic_action_search.png
new file mode 100644
index 000000000..f89c4e960
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-xhdpi/ic_action_search.png differ
diff --git a/samples/ActionBarCompat/res/drawable-xhdpi/ic_action_share.png b/samples/ActionBarCompat/res/drawable-xhdpi/ic_action_share.png
new file mode 100644
index 000000000..47b27d1f9
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-xhdpi/ic_action_share.png differ
diff --git a/samples/ActionBarCompat/res/drawable-xhdpi/ic_home.png b/samples/ActionBarCompat/res/drawable-xhdpi/ic_home.png
new file mode 100644
index 000000000..03eb53d65
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-xhdpi/ic_home.png differ
diff --git a/samples/ActionBarCompat/res/drawable-xhdpi/ic_launcher.png b/samples/ActionBarCompat/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 000000000..485f7be75
Binary files /dev/null and b/samples/ActionBarCompat/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/ActionBarCompat/res/drawable/actionbar_compat_item.xml b/samples/ActionBarCompat/res/drawable/actionbar_compat_item.xml
new file mode 100644
index 000000000..4b3960cf4
--- /dev/null
+++ b/samples/ActionBarCompat/res/drawable/actionbar_compat_item.xml
@@ -0,0 +1,23 @@
+
+
+menu_refresh, the menu item's
+ * state can be changed to show a loading spinner using
+ * {@link com.example.android.actionbarcompat.ActionBarHelperBase#setRefreshActionItemState(boolean)}.
+ */
+ private View addActionItemCompatFromMenuItem(final MenuItem item) {
+ final int itemId = item.getItemId();
+
+ final ViewGroup actionBar = getActionBarCompat();
+ if (actionBar == null) {
+ return null;
+ }
+
+ // Create the button
+ ImageButton actionButton = new ImageButton(mActivity, null,
+ itemId == android.R.id.home
+ ? R.attr.actionbarCompatItemHomeStyle
+ : R.attr.actionbarCompatItemStyle);
+ actionButton.setLayoutParams(new ViewGroup.LayoutParams(
+ (int) mActivity.getResources().getDimension(
+ itemId == android.R.id.home
+ ? R.dimen.actionbar_compat_button_home_width
+ : R.dimen.actionbar_compat_button_width),
+ ViewGroup.LayoutParams.FILL_PARENT));
+ if (itemId == R.id.menu_refresh) {
+ actionButton.setId(R.id.actionbar_compat_item_refresh);
+ }
+ actionButton.setImageDrawable(item.getIcon());
+ actionButton.setScaleType(ImageView.ScaleType.CENTER);
+ actionButton.setContentDescription(item.getTitle());
+ actionButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View view) {
+ mActivity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item);
+ }
+ });
+
+ actionBar.addView(actionButton);
+
+ if (item.getItemId() == R.id.menu_refresh) {
+ // Refresh buttons should be stateful, and allow for indeterminate progress indicators,
+ // so add those.
+ ProgressBar indicator = new ProgressBar(mActivity, null,
+ R.attr.actionbarCompatProgressIndicatorStyle);
+
+ final int buttonWidth = mActivity.getResources().getDimensionPixelSize(
+ R.dimen.actionbar_compat_button_width);
+ final int buttonHeight = mActivity.getResources().getDimensionPixelSize(
+ R.dimen.actionbar_compat_height);
+ final int progressIndicatorWidth = buttonWidth / 2;
+
+ LinearLayout.LayoutParams indicatorLayoutParams = new LinearLayout.LayoutParams(
+ progressIndicatorWidth, progressIndicatorWidth);
+ indicatorLayoutParams.setMargins(
+ (buttonWidth - progressIndicatorWidth) / 2,
+ (buttonHeight - progressIndicatorWidth) / 2,
+ (buttonWidth - progressIndicatorWidth) / 2,
+ 0);
+ indicator.setLayoutParams(indicatorLayoutParams);
+ indicator.setVisibility(View.GONE);
+ indicator.setId(R.id.actionbar_compat_item_refresh_progress);
+ actionBar.addView(indicator);
+ }
+
+ return actionButton;
+ }
+
+ /**
+ * A {@link android.view.MenuInflater} that reads action bar metadata.
+ */
+ private class WrappedMenuInflater extends MenuInflater {
+ MenuInflater mInflater;
+
+ public WrappedMenuInflater(Context context, MenuInflater inflater) {
+ super(context);
+ mInflater = inflater;
+ }
+
+ @Override
+ public void inflate(int menuRes, Menu menu) {
+ loadActionBarMetadata(menuRes);
+ mInflater.inflate(menuRes, menu);
+ }
+
+ /**
+ * Loads action bar metadata from a menu resource, storing a list of menu item IDs that
+ * should be shown on-screen (i.e. those with showAsAction set to always or ifRoom).
+ * @param menuResId
+ */
+ private void loadActionBarMetadata(int menuResId) {
+ XmlResourceParser parser = null;
+ try {
+ parser = mActivity.getResources().getXml(menuResId);
+
+ int eventType = parser.getEventType();
+ int itemId;
+ int showAsAction;
+
+ boolean eof = false;
+ while (!eof) {
+ switch (eventType) {
+ case XmlPullParser.START_TAG:
+ if (!parser.getName().equals("item")) {
+ break;
+ }
+
+ itemId = parser.getAttributeResourceValue(MENU_RES_NAMESPACE,
+ MENU_ATTR_ID, 0);
+ if (itemId == 0) {
+ break;
+ }
+
+ showAsAction = parser.getAttributeIntValue(MENU_RES_NAMESPACE,
+ MENU_ATTR_SHOW_AS_ACTION, -1);
+ if (showAsAction == MenuItem.SHOW_AS_ACTION_ALWAYS ||
+ showAsAction == MenuItem.SHOW_AS_ACTION_IF_ROOM) {
+ mActionItemIds.add(itemId);
+ }
+ break;
+
+ case XmlPullParser.END_DOCUMENT:
+ eof = true;
+ break;
+ }
+
+ eventType = parser.next();
+ }
+ } catch (XmlPullParserException e) {
+ throw new InflateException("Error inflating menu XML", e);
+ } catch (IOException e) {
+ throw new InflateException("Error inflating menu XML", e);
+ } finally {
+ if (parser != null) {
+ parser.close();
+ }
+ }
+ }
+
+ }
+}
diff --git a/samples/ActionBarCompat/src/com/example/android/actionbarcompat/ActionBarHelperHoneycomb.java b/samples/ActionBarCompat/src/com/example/android/actionbarcompat/ActionBarHelperHoneycomb.java
new file mode 100644
index 000000000..16fba696d
--- /dev/null
+++ b/samples/ActionBarCompat/src/com/example/android/actionbarcompat/ActionBarHelperHoneycomb.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2011 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.example.android.actionbarcompat;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+
+/**
+ * An extension of {@link ActionBarHelper} that provides Android 3.0-specific functionality for
+ * Honeycomb tablets. It thus requires API level 11.
+ */
+public class ActionBarHelperHoneycomb extends ActionBarHelper {
+ private Menu mOptionsMenu;
+ private View mRefreshIndeterminateProgressView = null;
+
+ protected ActionBarHelperHoneycomb(Activity activity) {
+ super(activity);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ mOptionsMenu = menu;
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public void setRefreshActionItemState(boolean refreshing) {
+ // On Honeycomb, we can set the state of the refresh button by giving it a custom
+ // action view.
+ if (mOptionsMenu == null) {
+ return;
+ }
+
+ final MenuItem refreshItem = mOptionsMenu.findItem(R.id.menu_refresh);
+ if (refreshItem != null) {
+ if (refreshing) {
+ if (mRefreshIndeterminateProgressView == null) {
+ LayoutInflater inflater = (LayoutInflater)
+ getActionBarThemedContext().getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+ mRefreshIndeterminateProgressView = inflater.inflate(
+ R.layout.actionbar_indeterminate_progress, null);
+ }
+
+ refreshItem.setActionView(mRefreshIndeterminateProgressView);
+ } else {
+ refreshItem.setActionView(null);
+ }
+ }
+ }
+
+ /**
+ * Returns a {@link Context} suitable for inflating layouts for the action bar. The
+ * implementation for this method in {@link ActionBarHelperICS} asks the action bar for a
+ * themed context.
+ */
+ protected Context getActionBarThemedContext() {
+ return mActivity;
+ }
+}
diff --git a/samples/ActionBarCompat/src/com/example/android/actionbarcompat/ActionBarHelperICS.java b/samples/ActionBarCompat/src/com/example/android/actionbarcompat/ActionBarHelperICS.java
new file mode 100644
index 000000000..d2239db96
--- /dev/null
+++ b/samples/ActionBarCompat/src/com/example/android/actionbarcompat/ActionBarHelperICS.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2011 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.example.android.actionbarcompat;
+
+import android.app.Activity;
+import android.content.Context;
+import android.view.Menu;
+import android.view.MenuItem;
+
+/**
+ * An extension of {@link com.example.android.actionbarcompat.ActionBarHelper} that provides Android
+ * 4.0-specific functionality for IceCreamSandwich devices. It thus requires API level 14.
+ */
+public class ActionBarHelperICS extends ActionBarHelperHoneycomb {
+ protected ActionBarHelperICS(Activity activity) {
+ super(activity);
+ }
+
+ @Override
+ protected Context getActionBarThemedContext() {
+ return mActivity.getActionBar().getThemedContext();
+ }
+}
diff --git a/samples/ActionBarCompat/src/com/example/android/actionbarcompat/MainActivity.java b/samples/ActionBarCompat/src/com/example/android/actionbarcompat/MainActivity.java
new file mode 100644
index 000000000..facf1ae9c
--- /dev/null
+++ b/samples/ActionBarCompat/src/com/example/android/actionbarcompat/MainActivity.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2011 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.example.android.actionbarcompat;
+
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.Toast;
+
+public class MainActivity extends ActionBarActivity {
+ private boolean mAlternateTitle = false;
+
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ findViewById(R.id.toggle_title).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (mAlternateTitle) {
+ setTitle(R.string.app_name);
+ } else {
+ setTitle(R.string.alternate_title);
+ }
+ mAlternateTitle = !mAlternateTitle;
+ }
+ });
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater menuInflater = getMenuInflater();
+ menuInflater.inflate(R.menu.main, menu);
+
+ // Calling super after populating the menu is necessary here to ensure that the
+ // action bar helpers have a chance to handle this event.
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ Toast.makeText(this, "Tapped home", Toast.LENGTH_SHORT).show();
+ break;
+
+ case R.id.menu_refresh:
+ Toast.makeText(this, "Fake refreshing...", Toast.LENGTH_SHORT).show();
+ getActionBarHelper().setRefreshActionItemState(true);
+ getWindow().getDecorView().postDelayed(
+ new Runnable() {
+ @Override
+ public void run() {
+ getActionBarHelper().setRefreshActionItemState(false);
+ }
+ }, 1000);
+ break;
+
+ case R.id.menu_search:
+ Toast.makeText(this, "Tapped search", Toast.LENGTH_SHORT).show();
+ break;
+
+ case R.id.menu_share:
+ Toast.makeText(this, "Tapped share", Toast.LENGTH_SHORT).show();
+ break;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/samples/ActionBarCompat/src/com/example/android/actionbarcompat/SimpleMenu.java b/samples/ActionBarCompat/src/com/example/android/actionbarcompat/SimpleMenu.java
new file mode 100644
index 000000000..8b694d0a6
--- /dev/null
+++ b/samples/ActionBarCompat/src/com/example/android/actionbarcompat/SimpleMenu.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2011 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.example.android.actionbarcompat;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.SubMenu;
+
+import java.util.ArrayList;
+
+/**
+ * A really dumb implementation of the {@link android.view.Menu} interface, that's only
+ * useful for our actionbar-compat purposes. See
+ * com.android.internal.view.menu.MenuBuilder in AOSP for a more complete
+ * implementation.
+ */
+public class SimpleMenu implements Menu {
+
+ private Context mContext;
+ private Resources mResources;
+
+ private ArrayListcom.android.internal.view.menu.MenuItemImpl in AOSP for a more complete
+ * implementation.
+ */
+public class SimpleMenuItem implements MenuItem {
+
+ private SimpleMenu mMenu;
+
+ private final int mId;
+ private final int mOrder;
+ private CharSequence mTitle;
+ private CharSequence mTitleCondensed;
+ private Drawable mIconDrawable;
+ private int mIconResId = 0;
+ private boolean mEnabled = true;
+
+ public SimpleMenuItem(SimpleMenu menu, int id, int order, CharSequence title) {
+ mMenu = menu;
+ mId = id;
+ mOrder = order;
+ mTitle = title;
+ }
+
+ public int getItemId() {
+ return mId;
+ }
+
+ public int getOrder() {
+ return mOrder;
+ }
+
+ public MenuItem setTitle(CharSequence title) {
+ mTitle = title;
+ return this;
+ }
+
+ public MenuItem setTitle(int titleRes) {
+ return setTitle(mMenu.getContext().getString(titleRes));
+ }
+
+ public CharSequence getTitle() {
+ return mTitle;
+ }
+
+ public MenuItem setTitleCondensed(CharSequence title) {
+ mTitleCondensed = title;
+ return this;
+ }
+
+ public CharSequence getTitleCondensed() {
+ return mTitleCondensed != null ? mTitleCondensed : mTitle;
+ }
+
+ public MenuItem setIcon(Drawable icon) {
+ mIconResId = 0;
+ mIconDrawable = icon;
+ return this;
+ }
+
+ public MenuItem setIcon(int iconResId) {
+ mIconDrawable = null;
+ mIconResId = iconResId;
+ return this;
+ }
+
+ public Drawable getIcon() {
+ if (mIconDrawable != null) {
+ return mIconDrawable;
+ }
+
+ if (mIconResId != 0) {
+ return mMenu.getResources().getDrawable(mIconResId);
+ }
+
+ return null;
+ }
+
+ public MenuItem setEnabled(boolean enabled) {
+ mEnabled = enabled;
+ return this;
+ }
+
+ public boolean isEnabled() {
+ return mEnabled;
+ }
+
+ // No-op operations. We use no-ops to allow inflation from menu XML.
+
+ public int getGroupId() {
+ // Noop
+ return 0;
+ }
+
+ public View getActionView() {
+ // Noop
+ return null;
+ }
+
+ public MenuItem setActionProvider(ActionProvider actionProvider) {
+ // Noop
+ return this;
+ }
+
+ public ActionProvider getActionProvider() {
+ // Noop
+ return null;
+ }
+
+ public boolean expandActionView() {
+ // Noop
+ return false;
+ }
+
+ public boolean collapseActionView() {
+ // Noop
+ return false;
+ }
+
+ public boolean isActionViewExpanded() {
+ // Noop
+ return false;
+ }
+
+ @Override
+ public MenuItem setOnActionExpandListener(OnActionExpandListener onActionExpandListener) {
+ // Noop
+ return this;
+ }
+
+ public MenuItem setIntent(Intent intent) {
+ // Noop
+ return this;
+ }
+
+ public Intent getIntent() {
+ // Noop
+ return null;
+ }
+
+ public MenuItem setShortcut(char c, char c1) {
+ // Noop
+ return this;
+ }
+
+ public MenuItem setNumericShortcut(char c) {
+ // Noop
+ return this;
+ }
+
+ public char getNumericShortcut() {
+ // Noop
+ return 0;
+ }
+
+ public MenuItem setAlphabeticShortcut(char c) {
+ // Noop
+ return this;
+ }
+
+ public char getAlphabeticShortcut() {
+ // Noop
+ return 0;
+ }
+
+ public MenuItem setCheckable(boolean b) {
+ // Noop
+ return this;
+ }
+
+ public boolean isCheckable() {
+ // Noop
+ return false;
+ }
+
+ public MenuItem setChecked(boolean b) {
+ // Noop
+ return this;
+ }
+
+ public boolean isChecked() {
+ // Noop
+ return false;
+ }
+
+ public MenuItem setVisible(boolean b) {
+ // Noop
+ return this;
+ }
+
+ public boolean isVisible() {
+ // Noop
+ return true;
+ }
+
+ public boolean hasSubMenu() {
+ // Noop
+ return false;
+ }
+
+ public SubMenu getSubMenu() {
+ // Noop
+ return null;
+ }
+
+ public MenuItem setOnMenuItemClickListener(OnMenuItemClickListener onMenuItemClickListener) {
+ // Noop
+ return this;
+ }
+
+ public ContextMenu.ContextMenuInfo getMenuInfo() {
+ // Noop
+ return null;
+ }
+
+ public void setShowAsAction(int i) {
+ // Noop
+ }
+
+ public MenuItem setShowAsActionFlags(int i) {
+ // Noop
+ return null;
+ }
+
+ public MenuItem setActionView(View view) {
+ // Noop
+ return this;
+ }
+
+ public MenuItem setActionView(int i) {
+ // Noop
+ return this;
+ }
+}