Loading core/java/com/android/internal/view/menu/ListMenuItemView.java +68 −79 Original line number Diff line number Diff line Loading @@ -26,17 +26,15 @@ 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; public class ListMenuItemView extends LinearLayout implements MenuView.ItemView { private static final String TAG = "ListMenuItemView"; private MenuItemImpl mItemData; private ImageView mIconView; Loading @@ -45,21 +43,30 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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(); } Loading @@ -72,21 +79,23 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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()); Loading @@ -98,27 +107,20 @@ 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; Loading Loading @@ -151,24 +153,16 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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; Loading @@ -187,9 +181,9 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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()); Loading @@ -200,7 +194,6 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie } } @Override public void setIcon(Drawable icon) { final boolean showIcon = mItemData.shouldShowIcon() || mForceShowIcon; if (!showIcon && !mPreserveIconSpacing) { Loading Loading @@ -230,46 +223,42 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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; } Loading core/res/res/layout/list_menu_item_checkbox.xml +5 −4 Original line number Diff line number Diff line Loading @@ -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" /> core/res/res/layout/list_menu_item_icon.xml +5 −6 Original line number Diff line number Diff line Loading @@ -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" /> core/res/res/layout/list_menu_item_layout.xml +38 −30 Original line number Diff line number Diff line Loading @@ -16,19 +16,26 @@ <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: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" Loading @@ -41,13 +48,14 @@ 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: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> core/res/res/layout/list_menu_item_radio.xml +3 −4 Original line number Diff line number Diff line Loading @@ -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" /> Loading
core/java/com/android/internal/view/menu/ListMenuItemView.java +68 −79 Original line number Diff line number Diff line Loading @@ -26,17 +26,15 @@ 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; public class ListMenuItemView extends LinearLayout implements MenuView.ItemView { private static final String TAG = "ListMenuItemView"; private MenuItemImpl mItemData; private ImageView mIconView; Loading @@ -45,21 +43,30 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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(); } Loading @@ -72,21 +79,23 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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()); Loading @@ -98,27 +107,20 @@ 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; Loading Loading @@ -151,24 +153,16 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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; Loading @@ -187,9 +181,9 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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()); Loading @@ -200,7 +194,6 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie } } @Override public void setIcon(Drawable icon) { final boolean showIcon = mItemData.shouldShowIcon() || mForceShowIcon; if (!showIcon && !mPreserveIconSpacing) { Loading Loading @@ -230,46 +223,42 @@ public class ListMenuItemView extends RelativeLayout implements MenuView.ItemVie 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; } Loading
core/res/res/layout/list_menu_item_checkbox.xml +5 −4 Original line number Diff line number Diff line Loading @@ -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" />
core/res/res/layout/list_menu_item_icon.xml +5 −6 Original line number Diff line number Diff line Loading @@ -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" />
core/res/res/layout/list_menu_item_layout.xml +38 −30 Original line number Diff line number Diff line Loading @@ -16,19 +16,26 @@ <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: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" Loading @@ -41,13 +48,14 @@ 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: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>
core/res/res/layout/list_menu_item_radio.xml +3 −4 Original line number Diff line number Diff line Loading @@ -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" />