Action buttons are now 1 view instead of 3.
Change-Id: I42afe0e4bd20c3dbe86e2c43a6bc1d776361dca9
This commit is contained in:
@@ -27,28 +27,26 @@ import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public class ActionMenuItemView extends LinearLayout
|
||||
public class ActionMenuItemView extends TextView
|
||||
implements MenuView.ItemView, View.OnClickListener, View.OnLongClickListener,
|
||||
ActionMenuView.ActionMenuChildView {
|
||||
private static final String TAG = "ActionMenuItemView";
|
||||
|
||||
private MenuItemImpl mItemData;
|
||||
private CharSequence mTitle;
|
||||
private Drawable mIcon;
|
||||
private MenuBuilder.ItemInvoker mItemInvoker;
|
||||
|
||||
private ImageButton mImageButton;
|
||||
private Button mTextButton;
|
||||
private boolean mAllowTextWithIcon;
|
||||
private boolean mExpandedFormat;
|
||||
private int mMinWidth;
|
||||
private int mSavedPaddingLeft;
|
||||
|
||||
public ActionMenuItemView(Context context) {
|
||||
this(context, null);
|
||||
@@ -68,17 +66,12 @@ public class ActionMenuItemView extends LinearLayout
|
||||
mMinWidth = a.getDimensionPixelSize(
|
||||
com.android.internal.R.styleable.ActionMenuItemView_minWidth, 0);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@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);
|
||||
mImageButton.setOnLongClickListener(this);
|
||||
setOnClickListener(this);
|
||||
setOnLongClickListener(this);
|
||||
|
||||
// Save the inflated padding for later, we'll need it.
|
||||
mSavedPaddingLeft = getPaddingLeft();
|
||||
}
|
||||
|
||||
public MenuItemImpl getItemData() {
|
||||
@@ -96,13 +89,6 @@ public class ActionMenuItemView extends LinearLayout
|
||||
setEnabled(itemData.isEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
mImageButton.setEnabled(enabled);
|
||||
mTextButton.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
if (mItemInvoker != null) {
|
||||
mItemInvoker.invokeItem(mItemData);
|
||||
@@ -135,26 +121,22 @@ public class ActionMenuItemView extends LinearLayout
|
||||
}
|
||||
|
||||
private void updateTextButtonVisibility() {
|
||||
boolean visible = !TextUtils.isEmpty(mTextButton.getText());
|
||||
visible &= mImageButton.getDrawable() == null ||
|
||||
boolean visible = !TextUtils.isEmpty(mTitle);
|
||||
visible &= mIcon == null ||
|
||||
(mItemData.showsTextAsAction() && (mAllowTextWithIcon || mExpandedFormat));
|
||||
|
||||
mTextButton.setVisibility(visible ? VISIBLE : GONE);
|
||||
setText(visible ? mTitle : null);
|
||||
}
|
||||
|
||||
public void setIcon(Drawable icon) {
|
||||
mImageButton.setImageDrawable(icon);
|
||||
if (icon != null) {
|
||||
mImageButton.setVisibility(VISIBLE);
|
||||
} else {
|
||||
mImageButton.setVisibility(GONE);
|
||||
}
|
||||
mIcon = icon;
|
||||
setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
||||
|
||||
updateTextButtonVisibility();
|
||||
}
|
||||
|
||||
public boolean hasText() {
|
||||
return mTextButton.getVisibility() != GONE;
|
||||
return !TextUtils.isEmpty(getText());
|
||||
}
|
||||
|
||||
public void setShortcut(boolean showShortcut, char shortcutKey) {
|
||||
@@ -164,8 +146,6 @@ public class ActionMenuItemView extends LinearLayout
|
||||
public void setTitle(CharSequence title) {
|
||||
mTitle = title;
|
||||
|
||||
mTextButton.setText(mTitle);
|
||||
|
||||
setContentDescription(mTitle);
|
||||
updateTextButtonVisibility();
|
||||
}
|
||||
@@ -236,12 +216,17 @@ public class ActionMenuItemView extends LinearLayout
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
final boolean textVisible = hasText();
|
||||
if (textVisible) {
|
||||
setPadding(mSavedPaddingLeft, getPaddingTop(), getPaddingRight(), getPaddingBottom());
|
||||
}
|
||||
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
final int specSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
final int oldMeasuredWidth = getMeasuredWidth();
|
||||
final int targetWidth = widthMode == MeasureSpec.AT_MOST ? Math.min(specSize, mMinWidth)
|
||||
final int targetWidth = widthMode == MeasureSpec.AT_MOST ? Math.min(widthSize, mMinWidth)
|
||||
: mMinWidth;
|
||||
|
||||
if (widthMode != MeasureSpec.EXACTLY && mMinWidth > 0 && oldMeasuredWidth < targetWidth) {
|
||||
@@ -249,5 +234,13 @@ public class ActionMenuItemView extends LinearLayout
|
||||
super.onMeasure(MeasureSpec.makeMeasureSpec(targetWidth, MeasureSpec.EXACTLY),
|
||||
heightMeasureSpec);
|
||||
}
|
||||
|
||||
if (!textVisible && mIcon != null) {
|
||||
// TextView won't center compound drawables in both dimensions without
|
||||
// a little coercion. Pad in to center the icon after we've measured.
|
||||
final int w = getMeasuredWidth();
|
||||
final int dw = mIcon.getIntrinsicWidth();
|
||||
setPadding((w - dw) / 2, getPaddingTop(), getPaddingRight(), getPaddingBottom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,13 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
|
||||
if (mFormatItems) {
|
||||
onMeasureExactFormat(widthMeasureSpec, heightMeasureSpec);
|
||||
} else {
|
||||
// Previous measurement at exact format may have set margins - reset them.
|
||||
final int childCount = getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View child = getChildAt(i);
|
||||
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
|
||||
lp.leftMargin = lp.rightMargin = 0;
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,39 +18,12 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:addStatesFromChildren="true"
|
||||
android:gravity="center"
|
||||
android:focusable="true"
|
||||
android:paddingLeft="4dip"
|
||||
android:paddingRight="4dip"
|
||||
style="?android:attr/actionButtonStyle">
|
||||
<ImageButton android:id="@+id/imageButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:visibility="gone"
|
||||
android:layout_marginTop="4dip"
|
||||
android:layout_marginBottom="4dip"
|
||||
android:layout_marginLeft="4dip"
|
||||
android:layout_marginRight="4dip"
|
||||
android:scaleType="fitCenter"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@null"
|
||||
android:focusable="false" />
|
||||
<Button android:id="@+id/textButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:visibility="gone"
|
||||
android:textAppearance="?attr/actionMenuTextAppearance"
|
||||
style="?attr/buttonStyleSmall"
|
||||
android:textColor="?attr/actionMenuTextColor"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="none"
|
||||
android:background="@null"
|
||||
android:paddingTop="4dip"
|
||||
android:paddingBottom="4dip"
|
||||
android:paddingLeft="4dip"
|
||||
android:paddingRight="4dip"
|
||||
android:focusable="false" />
|
||||
</com.android.internal.view.menu.ActionMenuItemView>
|
||||
android:paddingTop="4dip"
|
||||
android:paddingBottom="4dip"
|
||||
android:paddingLeft="8dip"
|
||||
android:paddingRight="8dip"
|
||||
android:textAppearance="?attr/actionMenuTextAppearance"
|
||||
android:textColor="?attr/actionMenuTextColor"
|
||||
style="?android:attr/actionButtonStyle" />
|
||||
|
||||
@@ -88,7 +88,6 @@
|
||||
<java-symbol type="id" name="hour" />
|
||||
<java-symbol type="id" name="icon" />
|
||||
<java-symbol type="id" name="image" />
|
||||
<java-symbol type="id" name="imageButton" />
|
||||
<java-symbol type="id" name="increment" />
|
||||
<java-symbol type="id" name="internalEmpty" />
|
||||
<java-symbol type="id" name="info" />
|
||||
@@ -173,7 +172,6 @@
|
||||
<java-symbol type="id" name="switch_old" />
|
||||
<java-symbol type="id" name="switchWidget" />
|
||||
<java-symbol type="id" name="text" />
|
||||
<java-symbol type="id" name="textButton" />
|
||||
<java-symbol type="id" name="time" />
|
||||
<java-symbol type="id" name="time_current" />
|
||||
<java-symbol type="id" name="timeDisplayBackground" />
|
||||
|
||||
Reference in New Issue
Block a user