diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/java/com/android/internal/view/menu/ListMenuItemView.java | 147 | ||||
-rw-r--r-- | core/res/res/layout/list_menu_item_checkbox.xml | 9 | ||||
-rw-r--r-- | core/res/res/layout/list_menu_item_icon.xml | 11 | ||||
-rw-r--r-- | core/res/res/layout/list_menu_item_layout.xml | 68 | ||||
-rw-r--r-- | core/res/res/layout/list_menu_item_radio.xml | 7 | ||||
-rw-r--r-- | core/res/res/layout/popup_menu_item_layout.xml | 68 |
6 files changed, 157 insertions, 153 deletions
diff --git a/core/java/com/android/internal/view/menu/ListMenuItemView.java b/core/java/com/android/internal/view/menu/ListMenuItemView.java index 35b76dd..df579c6 100644 --- a/core/java/com/android/internal/view/menu/ListMenuItemView.java +++ b/core/java/com/android/internal/view/menu/ListMenuItemView.java @@ -26,41 +26,48 @@ 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 RelativeLayout implements MenuView.ItemView { - private final Drawable mBackground; - private final int mTextAppearance; - - private MenuItemImpl mItemData; - +public class ListMenuItemView extends LinearLayout implements MenuView.ItemView { + private static final String TAG = "ListMenuItemView"; + 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); - - final TypedArray a = context.obtainStyledAttributes( + + 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, 0); + mTextAppearance = a.getResourceId(com.android.internal.R.styleable. + MenuView_itemTextAppearance, -1); mPreserveIconSpacing = a.getBoolean( com.android.internal.R.styleable.MenuView_preserveIconSpacing, false); - + mTextAppearanceContext = context; + a.recycle(); } @@ -71,22 +78,24 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie @Override protected void onFinishInflate() { super.onFinishInflate(); - - setBackground(mBackground); - + + setBackgroundDrawable(mBackground); + mTitleView = (TextView) findViewById(com.android.internal.R.id.title); - if (mTextAppearance != 0) { - mTitleView.setTextAppearance(mContext, mTextAppearance); + if (mTextAppearance != -1) { + mTitleView.setTextAppearance(mTextAppearanceContext, + 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()); @@ -98,36 +107,29 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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) { @@ -142,36 +144,28 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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(); @@ -183,13 +177,13 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie } 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()); @@ -199,22 +193,21 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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); @@ -225,55 +218,51 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie mIconView.setVisibility(GONE); } } - + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mIconView != null && mPreserveIconSpacing) { // Enforce minimum icon spacing - final ViewGroup.LayoutParams lp = getLayoutParams(); - final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams(); + ViewGroup.LayoutParams lp = getLayoutParams(); + LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams(); if (lp.height > 0 && iconLp.width <= 0) { iconLp.width = lp.height; } } - super.onMeasure(widthMeasureSpec, heightMeasureSpec); } private void insertIconView() { - mIconView = (ImageView) getInflater() - .inflate(com.android.internal.R.layout.list_menu_item_icon, this, false); - addView(mIconView); + LayoutInflater inflater = getInflater(); + mIconView = (ImageView) inflater.inflate(com.android.internal.R.layout.list_menu_item_icon, + this, false); + addView(mIconView, 0); } - + private void insertRadioButton() { - mRadioButton = (RadioButton) getInflater() - .inflate(com.android.internal.R.layout.list_menu_item_radio, this, false); + LayoutInflater inflater = getInflater(); + mRadioButton = + (RadioButton) inflater.inflate(com.android.internal.R.layout.list_menu_item_radio, + this, false); addView(mRadioButton); } - + private void insertCheckBox() { - mCheckBox = (CheckBox) getInflater() - .inflate(com.android.internal.R.layout.list_menu_item_checkbox, this, false); + LayoutInflater inflater = getInflater(); + mCheckBox = + (CheckBox) inflater.inflate(com.android.internal.R.layout.list_menu_item_checkbox, + this, false); addView(mCheckBox); } - 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 02febc4..dc02a1e 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,8 +18,9 @@ android:id="@+id/checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentEnd="true" - android:layout_centerVertical="true" + android:layout_gravity="center_vertical" 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 89b6b09..a30be6a 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,12 +18,11 @@ android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_centerVertical="true" - android:layout_alignParentStart="true" + android:layout_gravity="center_vertical" android:layout_marginStart="8dip" android:layout_marginEnd="-8dip" android:layout_marginTop="8dip" android:layout_marginBottom="8dip" android:scaleType="centerInside" - android:duplicateParentState="true" - android:contentDescription="@null" /> + android:duplicateParentState="true" /> + diff --git a/core/res/res/layout/list_menu_item_layout.xml b/core/res/res/layout/list_menu_item_layout.xml index 3130215..e8d4983 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,38 +16,46 @@ <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:gravity="start|center_vertical"> - + android:layout_height="?android:attr/listPreferredItemHeightSmall"> + <!-- Icon will be inserted here. --> - - <TextView - android:id="@+id/title" - android:layout_width="wrap_content" + + <!-- 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" android:layout_height="wrap_content" - android:layout_alignWithParentIfMissing="true" + android:layout_gravity="center_vertical" android:layout_marginStart="?android:attr/listPreferredItemPaddingStart" android:layout_marginEnd="?android:attr/listPreferredItemPaddingEnd" - 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" /> + 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> <!-- 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 74564ad..ac4459e 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,8 +18,7 @@ android:id="@+id/radio" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentEnd="true" - android:layout_centerVertical="true" + android:layout_gravity="center_vertical" 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 aff3779..452f85d 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,37 +18,45 @@ android:layout_width="match_parent" android:layout_height="?android:attr/dropdownListPreferredItemHeight" android:minWidth="196dip" - android:paddingEnd="16dip" - android:gravity="start|center_vertical"> - + android:paddingEnd="16dip"> + <!-- Icon will be inserted here. --> - - <TextView - android:id="@+id/title" - android:layout_width="wrap_content" + + <!-- 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" android:layout_height="wrap_content" - android:layout_alignWithParentIfMissing="true" + android:layout_gravity="center_vertical" android:layout_marginStart="16dip" - 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" /> + 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> <!-- Checkbox, and/or radio button will be inserted here. --> - + </com.android.internal.view.menu.ListMenuItemView> |