summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2010-08-03 11:26:07 -0700
committerAdam Powell <adamp@google.com>2010-08-03 15:01:31 -0700
commit1f9c7afc5a06576e327a4b1c12688202f53d9462 (patch)
tree1abbcf5a78694b7176487b69e6228b0739550219 /core
parentc619d8279695f2bb44c11e6523333d1613feb678 (diff)
downloadframeworks_base-1f9c7afc5a06576e327a4b1c12688202f53d9462.zip
frameworks_base-1f9c7afc5a06576e327a4b1c12688202f53d9462.tar.gz
frameworks_base-1f9c7afc5a06576e327a4b1c12688202f53d9462.tar.bz2
Add support for action buttons without an icon.
Change-Id: I026bb7463e7a73419dbaf79950d579ba05d04ea8
Diffstat (limited to 'core')
-rw-r--r--core/java/com/android/internal/view/menu/ActionMenuItemView.java48
-rw-r--r--core/res/res/layout/action_menu_item_layout.xml13
-rw-r--r--core/res/res/values/styles.xml1
3 files changed, 43 insertions, 19 deletions
diff --git a/core/java/com/android/internal/view/menu/ActionMenuItemView.java b/core/java/com/android/internal/view/menu/ActionMenuItemView.java
index c379505..a221faf 100644
--- a/core/java/com/android/internal/view/menu/ActionMenuItemView.java
+++ b/core/java/com/android/internal/view/menu/ActionMenuItemView.java
@@ -19,20 +19,25 @@ package com.android.internal.view.menu;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
-import android.view.SoundEffectConstants;
import android.view.View;
+import android.widget.Button;
+import android.widget.FrameLayout;
import android.widget.ImageButton;
/**
* @hide
*/
-public class ActionMenuItemView extends ImageButton implements MenuView.ItemView {
+public class ActionMenuItemView extends FrameLayout
+ implements MenuView.ItemView, View.OnClickListener {
private static final String TAG = "ActionMenuItemView";
private MenuItemImpl mItemData;
private CharSequence mTitle;
private MenuBuilder.ItemInvoker mItemInvoker;
+ private ImageButton mImageButton;
+ private Button mTextButton;
+
public ActionMenuItemView(Context context) {
this(context, null);
}
@@ -45,6 +50,14 @@ public class ActionMenuItemView extends ImageButton implements MenuView.ItemView
super(context, attrs, defStyle);
}
+ @Override
+ public void onFinishInflate() {
+ mImageButton = (ImageButton) findViewById(com.android.internal.R.id.imageButton);
+ mTextButton = (Button) findViewById(com.android.internal.R.id.textButton);
+ mImageButton.setOnClickListener(this);
+ mTextButton.setOnClickListener(this);
+ }
+
public MenuItemImpl getItemData() {
return mItemData;
}
@@ -54,26 +67,17 @@ public class ActionMenuItemView extends ImageButton implements MenuView.ItemView
setClickable(true);
setFocusable(true);
- setTitle(itemData.getTitle());
setIcon(itemData.getIcon());
+ setTitle(itemData.getTitle()); // Title only takes effect if there is no icon
setId(itemData.getItemId());
setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE);
setEnabled(itemData.isEnabled());
}
- @Override
- public boolean performClick() {
- // Let the view's listener have top priority
- if (super.performClick()) {
- return true;
- }
-
- if (mItemInvoker != null && mItemInvoker.invokeItem(mItemData)) {
- playSoundEffect(SoundEffectConstants.CLICK);
- return true;
- } else {
- return false;
+ public void onClick(View v) {
+ if (mItemInvoker != null) {
+ mItemInvoker.invokeItem(mItemData);
}
}
@@ -94,7 +98,13 @@ public class ActionMenuItemView extends ImageButton implements MenuView.ItemView
}
public void setIcon(Drawable icon) {
- setImageDrawable(icon);
+ mImageButton.setImageDrawable(icon);
+ if (icon != null) {
+ mImageButton.setVisibility(VISIBLE);
+ mTextButton.setVisibility(GONE);
+ } else {
+ mImageButton.setVisibility(GONE);
+ }
}
public void setShortcut(boolean showShortcut, char shortcutKey) {
@@ -106,10 +116,14 @@ public class ActionMenuItemView extends ImageButton implements MenuView.ItemView
// populate accessibility description with title
setContentDescription(title);
+
+ if (mImageButton.getDrawable() == null) {
+ mTextButton.setText(mTitle);
+ mTextButton.setVisibility(VISIBLE);
+ }
}
public boolean showsIcon() {
return true;
}
-
}
diff --git a/core/res/res/layout/action_menu_item_layout.xml b/core/res/res/layout/action_menu_item_layout.xml
index 3f06251..0d3cce5 100644
--- a/core/res/res/layout/action_menu_item_layout.xml
+++ b/core/res/res/layout/action_menu_item_layout.xml
@@ -16,5 +16,14 @@
<com.android.internal.view.menu.ActionMenuItemView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- />
+ android:layout_height="wrap_content" >
+ <ImageButton android:id="@+id/imageButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:visibility="gone"
+ style="?attr/actionButtonStyle" />
+ <Button android:id="@+id/textButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:visibility="gone" />
+</com.android.internal.view.menu.ActionMenuItemView>
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index 3c09a89..993048d 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -882,5 +882,6 @@
</style>
<style name="Widget.ActionButton">
+ <item name="android:background">@null</item>
</style>
</resources>