summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alan Viverette <alanv@google.com> 2013-06-26 17:38:17 -0700
committer Alan Viverette <alanv@google.com> 2013-06-26 17:38:17 -0700
commit8933efd49a0b2c10ddb30b23b57f5676634d0277 (patch)
tree4132815242b1941fe9f6a25ba21418f3f3a3afda
parent066bdcfe83e49ad4bfb97670521c1b7e7297ba53 (diff)
Update ListMenuItemView to use a single RelativeLayout
BUG: 9591217 Change-Id: If5d301f70ac3806ab14e309affa57c625d897c7d
-rw-r--r--core/java/com/android/internal/view/menu/ListMenuItemView.java148
-rw-r--r--core/res/res/layout/list_menu_item_checkbox.xml9
-rw-r--r--core/res/res/layout/list_menu_item_icon.xml11
-rw-r--r--core/res/res/layout/list_menu_item_layout.xml68
-rw-r--r--core/res/res/layout/list_menu_item_radio.xml7
-rw-r--r--core/res/res/layout/popup_menu_item_layout.xml68
6 files changed, 152 insertions, 159 deletions
diff --git a/core/java/com/android/internal/view/menu/ListMenuItemView.java b/core/java/com/android/internal/view/menu/ListMenuItemView.java
index df579c69637d..464ae2f5e8dd 100644
--- a/core/java/com/android/internal/view/menu/ListMenuItemView.java
+++ b/core/java/com/android/internal/view/menu/ListMenuItemView.java
@@ -26,48 +26,41 @@ import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
-import android.widget.LinearLayout;
import android.widget.RadioButton;
+import android.widget.RelativeLayout;
import android.widget.TextView;
/**
* The item view for each item in the ListView-based MenuViews.
*/
-public class ListMenuItemView extends LinearLayout implements MenuView.ItemView {
- private static final String TAG = "ListMenuItemView";
- private MenuItemImpl mItemData;
-
+public class ListMenuItemView extends RelativeLayout implements MenuView.ItemView {
+ private final Drawable mBackground;
+ private final int mTextAppearance;
+
+ private MenuItemImpl mItemData;
+
private ImageView mIconView;
private RadioButton mRadioButton;
private TextView mTitleView;
private CheckBox mCheckBox;
private TextView mShortcutView;
-
- private Drawable mBackground;
- private int mTextAppearance;
- private Context mTextAppearanceContext;
- private boolean mPreserveIconSpacing;
-
- private int mMenuType;
-
+
private LayoutInflater mInflater;
+ private boolean mPreserveIconSpacing;
private boolean mForceShowIcon;
public ListMenuItemView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs);
-
- TypedArray a =
- context.obtainStyledAttributes(
+
+ final TypedArray a = context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.MenuView, defStyle, 0);
-
mBackground = a.getDrawable(com.android.internal.R.styleable.MenuView_itemBackground);
- mTextAppearance = a.getResourceId(com.android.internal.R.styleable.
- MenuView_itemTextAppearance, -1);
+ mTextAppearance = a.getResourceId(
+ com.android.internal.R.styleable.MenuView_itemTextAppearance, 0);
mPreserveIconSpacing = a.getBoolean(
com.android.internal.R.styleable.MenuView_preserveIconSpacing, false);
- mTextAppearanceContext = context;
-
+
a.recycle();
}
@@ -78,24 +71,22 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
@Override
protected void onFinishInflate() {
super.onFinishInflate();
-
- setBackgroundDrawable(mBackground);
-
+
+ setBackground(mBackground);
+
mTitleView = (TextView) findViewById(com.android.internal.R.id.title);
- if (mTextAppearance != -1) {
- mTitleView.setTextAppearance(mTextAppearanceContext,
- mTextAppearance);
+ if (mTextAppearance != 0) {
+ mTitleView.setTextAppearance(mContext, mTextAppearance);
}
-
+
mShortcutView = (TextView) findViewById(com.android.internal.R.id.shortcut);
}
+ @Override
public void initialize(MenuItemImpl itemData, int menuType) {
mItemData = itemData;
- mMenuType = menuType;
setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE);
-
setTitle(itemData.getTitleForItemView(this));
setCheckable(itemData.isCheckable());
setShortcut(itemData.shouldShowShortcut(), itemData.getShortcut());
@@ -107,29 +98,36 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
mPreserveIconSpacing = mForceShowIcon = forceShow;
}
+ @Override
public void setTitle(CharSequence title) {
if (title != null) {
mTitleView.setText(title);
-
- if (mTitleView.getVisibility() != VISIBLE) mTitleView.setVisibility(VISIBLE);
+
+ if (mTitleView.getVisibility() != VISIBLE) {
+ mTitleView.setVisibility(VISIBLE);
+ }
} else {
- if (mTitleView.getVisibility() != GONE) mTitleView.setVisibility(GONE);
+ if (mTitleView.getVisibility() != GONE) {
+ mTitleView.setVisibility(GONE);
+ }
}
}
-
+
+ @Override
public MenuItemImpl getItemData() {
return mItemData;
}
+ @Override
public void setCheckable(boolean checkable) {
if (!checkable && mRadioButton == null && mCheckBox == null) {
return;
}
-
+
// Depending on whether its exclusive check or not, the checkbox or
// radio button will be the one in use (and the other will be otherCompoundButton)
final CompoundButton compoundButton;
- final CompoundButton otherCompoundButton;
+ final CompoundButton otherCompoundButton;
if (mItemData.isExclusiveCheckable()) {
if (mRadioButton == null) {
@@ -144,28 +142,36 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
compoundButton = mCheckBox;
otherCompoundButton = mRadioButton;
}
-
+
if (checkable) {
compoundButton.setChecked(mItemData.isChecked());
-
+
final int newVisibility = checkable ? VISIBLE : GONE;
if (compoundButton.getVisibility() != newVisibility) {
compoundButton.setVisibility(newVisibility);
}
-
+
+ // Align text to the start of the visible compound button.
+ alignTextToStartOf(compoundButton);
+
// Make sure the other compound button isn't visible
if (otherCompoundButton != null && otherCompoundButton.getVisibility() != GONE) {
otherCompoundButton.setVisibility(GONE);
}
} else {
- if (mCheckBox != null) mCheckBox.setVisibility(GONE);
- if (mRadioButton != null) mRadioButton.setVisibility(GONE);
+ if (mCheckBox != null) {
+ mCheckBox.setVisibility(GONE);
+ }
+ if (mRadioButton != null) {
+ mRadioButton.setVisibility(GONE);
+ }
}
}
-
+
+ @Override
public void setChecked(boolean checked) {
CompoundButton compoundButton;
-
+
if (mItemData.isExclusiveCheckable()) {
if (mRadioButton == null) {
insertRadioButton();
@@ -177,13 +183,13 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
}
compoundButton = mCheckBox;
}
-
+
compoundButton.setChecked(checked);
}
+ @Override
public void setShortcut(boolean showShortcut, char shortcutKey) {
- final int newVisibility = (showShortcut && mItemData.shouldShowShortcut())
- ? VISIBLE : GONE;
+ final int newVisibility = (showShortcut && mItemData.shouldShowShortcut()) ? VISIBLE : GONE;
if (newVisibility == VISIBLE) {
mShortcutView.setText(mItemData.getShortcutLabel());
@@ -193,21 +199,22 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
mShortcutView.setVisibility(newVisibility);
}
}
-
+
+ @Override
public void setIcon(Drawable icon) {
final boolean showIcon = mItemData.shouldShowIcon() || mForceShowIcon;
if (!showIcon && !mPreserveIconSpacing) {
return;
}
-
+
if (mIconView == null && icon == null && !mPreserveIconSpacing) {
return;
}
-
+
if (mIconView == null) {
insertIconView();
}
-
+
if (icon != null || mPreserveIconSpacing) {
mIconView.setImageDrawable(showIcon ? icon : null);
@@ -218,51 +225,52 @@ public class ListMenuItemView extends LinearLayout implements MenuView.ItemView
mIconView.setVisibility(GONE);
}
}
-
+
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mIconView != null && mPreserveIconSpacing) {
// Enforce minimum icon spacing
- ViewGroup.LayoutParams lp = getLayoutParams();
- LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
+ final ViewGroup.LayoutParams lp = getLayoutParams();
+ final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams();
if (lp.height > 0 && iconLp.width <= 0) {
iconLp.width = lp.height;
}
}
+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
private void insertIconView() {
- LayoutInflater inflater = getInflater();
- mIconView = (ImageView) inflater.inflate(com.android.internal.R.layout.list_menu_item_icon,
- this, false);
- addView(mIconView, 0);
+ mIconView = (ImageView) getInflater()
+ .inflate(com.android.internal.R.layout.list_menu_item_icon, this, true);
}
-
+
private void insertRadioButton() {
- LayoutInflater inflater = getInflater();
- mRadioButton =
- (RadioButton) inflater.inflate(com.android.internal.R.layout.list_menu_item_radio,
- this, false);
- addView(mRadioButton);
+ mRadioButton = (RadioButton) getInflater()
+ .inflate(com.android.internal.R.layout.list_menu_item_radio, this, true);
}
-
+
private void insertCheckBox() {
- LayoutInflater inflater = getInflater();
- mCheckBox =
- (CheckBox) inflater.inflate(com.android.internal.R.layout.list_menu_item_checkbox,
- this, false);
- addView(mCheckBox);
+ mCheckBox = (CheckBox) getInflater()
+ .inflate(com.android.internal.R.layout.list_menu_item_checkbox, this, true);
}
+ private void alignTextToStartOf(View v) {
+ final LayoutParams params = (LayoutParams) mTitleView.getLayoutParams();
+ params.addRule(RelativeLayout.START_OF, v.getId());
+ mTitleView.setLayoutParams(params);
+ }
+
+ @Override
public boolean prefersCondensedTitle() {
return false;
}
+ @Override
public boolean showsIcon() {
return mForceShowIcon;
}
-
+
private LayoutInflater getInflater() {
if (mInflater == null) {
mInflater = LayoutInflater.from(mContext);
diff --git a/core/res/res/layout/list_menu_item_checkbox.xml b/core/res/res/layout/list_menu_item_checkbox.xml
index dc02a1e5d45b..02febc49c942 100644
--- a/core/res/res/layout/list_menu_item_checkbox.xml
+++ b/core/res/res/layout/list_menu_item_checkbox.xml
@@ -4,9 +4,9 @@
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.
@@ -18,9 +18,8 @@
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
+ android:layout_alignParentEnd="true"
+ android:layout_centerVertical="true"
android:focusable="false"
android:clickable="false"
android:duplicateParentState="true" />
-
-
diff --git a/core/res/res/layout/list_menu_item_icon.xml b/core/res/res/layout/list_menu_item_icon.xml
index a30be6a13db6..89b6b09a21cf 100644
--- a/core/res/res/layout/list_menu_item_icon.xml
+++ b/core/res/res/layout/list_menu_item_icon.xml
@@ -4,9 +4,9 @@
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.
@@ -18,11 +18,12 @@
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
+ android:layout_centerVertical="true"
+ android:layout_alignParentStart="true"
android:layout_marginStart="8dip"
android:layout_marginEnd="-8dip"
android:layout_marginTop="8dip"
android:layout_marginBottom="8dip"
android:scaleType="centerInside"
- android:duplicateParentState="true" />
-
+ android:duplicateParentState="true"
+ android:contentDescription="@null" />
diff --git a/core/res/res/layout/list_menu_item_layout.xml b/core/res/res/layout/list_menu_item_layout.xml
index e8d4983416a5..3130215634ce 100644
--- a/core/res/res/layout/list_menu_item_layout.xml
+++ b/core/res/res/layout/list_menu_item_layout.xml
@@ -4,9 +4,9 @@
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.
@@ -16,46 +16,38 @@
<com.android.internal.view.menu.ListMenuItemView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
- android:layout_height="?android:attr/listPreferredItemHeightSmall">
-
+ android:layout_height="?android:attr/listPreferredItemHeightSmall"
+ android:gravity="start|center_vertical">
+
<!-- Icon will be inserted here. -->
-
- <!-- The title and summary have some gap between them, and this 'group' should be centered vertically. -->
- <RelativeLayout
- android:layout_width="0dip"
- android:layout_weight="1"
+
+ <TextView
+ android:id="@+id/title"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
+ android:layout_alignWithParentIfMissing="true"
android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
android:layout_marginEnd="?android:attr/listPreferredItemPaddingEnd"
- android:duplicateParentState="true">
-
- <TextView
- android:id="@+id/title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_alignParentStart="true"
- android:textAppearance="?android:attr/textAppearanceListItemSmall"
- android:singleLine="true"
- android:duplicateParentState="true"
- android:ellipsize="marquee"
- android:fadingEdge="horizontal"
- android:textAlignment="viewStart" />
-
- <TextView
- android:id="@+id/shortcut"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/title"
- android:layout_alignParentStart="true"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:singleLine="true"
- android:duplicateParentState="true"
- android:textAlignment="viewStart" />
-
- </RelativeLayout>
+ android:layout_toEndOf="@id/icon"
+ android:textAppearance="?android:attr/textAppearanceListItemSmall"
+ android:singleLine="true"
+ android:duplicateParentState="true"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal"
+ android:textAlignment="viewStart" />
+
+ <TextView
+ android:id="@+id/shortcut"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/title"
+ android:layout_alignStart="@id/title"
+ android:layout_alignWithParentIfMissing="true"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:singleLine="true"
+ android:duplicateParentState="true"
+ android:textAlignment="viewStart" />
<!-- Checkbox, and/or radio button will be inserted here. -->
-
+
</com.android.internal.view.menu.ListMenuItemView>
diff --git a/core/res/res/layout/list_menu_item_radio.xml b/core/res/res/layout/list_menu_item_radio.xml
index ac4459eca6a5..74564ade83db 100644
--- a/core/res/res/layout/list_menu_item_radio.xml
+++ b/core/res/res/layout/list_menu_item_radio.xml
@@ -4,9 +4,9 @@
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.
@@ -18,7 +18,8 @@
android:id="@+id/radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
+ android:layout_alignParentEnd="true"
+ android:layout_centerVertical="true"
android:focusable="false"
android:clickable="false"
android:duplicateParentState="true" />
diff --git a/core/res/res/layout/popup_menu_item_layout.xml b/core/res/res/layout/popup_menu_item_layout.xml
index 452f85d9cc0a..aff3779bac7b 100644
--- a/core/res/res/layout/popup_menu_item_layout.xml
+++ b/core/res/res/layout/popup_menu_item_layout.xml
@@ -4,9 +4,9 @@
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.
@@ -18,45 +18,37 @@
android:layout_width="match_parent"
android:layout_height="?android:attr/dropdownListPreferredItemHeight"
android:minWidth="196dip"
- android:paddingEnd="16dip">
-
+ android:paddingEnd="16dip"
+ android:gravity="start|center_vertical">
+
<!-- Icon will be inserted here. -->
-
- <!-- The title and summary have some gap between them, and this 'group' should be centered vertically. -->
- <RelativeLayout
- android:layout_width="0dip"
- android:layout_weight="1"
+
+ <TextView
+ android:id="@+id/title"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
+ android:layout_alignWithParentIfMissing="true"
android:layout_marginStart="16dip"
- android:duplicateParentState="true">
-
- <TextView
- android:id="@+id/title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_alignParentStart="true"
- android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
- android:singleLine="true"
- android:duplicateParentState="true"
- android:ellipsize="marquee"
- android:fadingEdge="horizontal"
- android:textAlignment="viewStart" />
-
- <TextView
- android:id="@+id/shortcut"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/title"
- android:layout_alignParentStart="true"
- android:textAppearance="?android:attr/textAppearanceSmallPopupMenu"
- android:singleLine="true"
- android:duplicateParentState="true"
- android:textAlignment="viewStart" />
-
- </RelativeLayout>
+ android:layout_toEndOf="@id/icon"
+ android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
+ android:singleLine="true"
+ android:duplicateParentState="true"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal"
+ android:textAlignment="viewStart" />
+
+ <TextView
+ android:id="@+id/shortcut"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/title"
+ android:layout_alignStart="@id/title"
+ android:layout_alignWithParentIfMissing="true"
+ android:textAppearance="?android:attr/textAppearanceSmallPopupMenu"
+ android:singleLine="true"
+ android:duplicateParentState="true"
+ android:textAlignment="viewStart" />
<!-- Checkbox, and/or radio button will be inserted here. -->
-
+
</com.android.internal.view.menu.ListMenuItemView>