diff options
| -rw-r--r-- | api/current.xml | 68 | ||||
| -rw-r--r-- | core/java/android/widget/ButtonGroup.java | 95 | ||||
| -rw-r--r-- | core/java/com/android/internal/view/menu/ActionMenuView.java | 2 | ||||
| -rw-r--r-- | core/java/com/android/internal/widget/ActionBarContextView.java | 36 | ||||
| -rw-r--r-- | core/res/res/drawable/group_button_background_holo_dark.xml | 28 | ||||
| -rw-r--r-- | core/res/res/drawable/group_button_background_holo_light.xml | 28 | ||||
| -rw-r--r-- | core/res/res/drawable/list_selector_holo_dark.xml | 3 | ||||
| -rw-r--r-- | core/res/res/drawable/list_selector_holo_light.xml | 2 | ||||
| -rw-r--r-- | core/res/res/layout/action_menu_item_layout.xml | 6 | ||||
| -rw-r--r-- | core/res/res/layout/action_mode_close_item.xml | 30 | ||||
| -rwxr-xr-x | core/res/res/values/attrs.xml | 9 | ||||
| -rw-r--r-- | core/res/res/values/colors.xml | 7 | ||||
| -rwxr-xr-x | core/res/res/values/strings.xml | 2 | ||||
| -rw-r--r-- | core/res/res/values/styles.xml | 3 | ||||
| -rw-r--r-- | core/res/res/values/themes.xml | 8 |
15 files changed, 293 insertions, 34 deletions
diff --git a/api/current.xml b/api/current.xml index 1fe149861b9f..2b70dcf9f3d6 100644 --- a/api/current.xml +++ b/api/current.xml @@ -228812,6 +228812,74 @@ <parameter name="defStyleRes" type="int"> </parameter> </constructor> +<method name="getShowDividers" + return="int" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> +<method name="setShowDividers" + return="void" + abstract="false" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +<parameter name="showDividers" type="int"> +</parameter> +</method> +<field name="SHOW_DIVIDER_BEGINNING" + type="int" + transient="false" + volatile="false" + value="1" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="SHOW_DIVIDER_END" + type="int" + transient="false" + volatile="false" + value="4" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="SHOW_DIVIDER_MIDDLE" + type="int" + transient="false" + volatile="false" + value="2" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> +<field name="SHOW_DIVIDER_NONE" + type="int" + transient="false" + volatile="false" + value="0" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> </class> <class name="CheckBox" extends="android.widget.CompoundButton" diff --git a/core/java/android/widget/ButtonGroup.java b/core/java/android/widget/ButtonGroup.java index a23ea07a9bb0..5fda40894483 100644 --- a/core/java/android/widget/ButtonGroup.java +++ b/core/java/android/widget/ButtonGroup.java @@ -26,6 +26,24 @@ import android.view.ViewGroup; public class ButtonGroup extends LinearLayout { private Drawable mDivider; private Drawable mButtonBackground; + private int mShowDividers; + + /** + * Don't show any dividers. + */ + public static final int SHOW_DIVIDER_NONE = 0; + /** + * Show a divider at the beginning of the group. + */ + public static final int SHOW_DIVIDER_BEGINNING = 1; + /** + * Show dividers between each item in the group. + */ + public static final int SHOW_DIVIDER_MIDDLE = 2; + /** + * Show a divider at the end of the group. + */ + public static final int SHOW_DIVIDER_END = 4; public ButtonGroup(Context context) { this(context, null); @@ -39,34 +57,89 @@ public class ButtonGroup extends LinearLayout { super(context, attrs, defStyleRes); TypedArray a = context.obtainStyledAttributes(attrs, - com.android.internal.R.styleable.ButtonGroup); + com.android.internal.R.styleable.ButtonGroup, defStyleRes, 0); mDivider = a.getDrawable(com.android.internal.R.styleable.ButtonGroup_divider); mButtonBackground = a.getDrawable( com.android.internal.R.styleable.ButtonGroup_buttonBackground); + mShowDividers = a.getInt(com.android.internal.R.styleable.ButtonGroup_showDividers, + SHOW_DIVIDER_MIDDLE); a.recycle(); } - + + /** + * Set how dividers should be shown between items in this button group. + * + * @param showDividers One or more of {@link #SHOW_DIVIDER_BEGINNING}, + * {@link #SHOW_DIVIDER_MIDDLE}, or {@link #SHOW_DIVIDER_END}, + * or {@link #SHOW_DIVIDER_NONE} to show no dividers. + */ + public void setShowDividers(int showDividers) { + mShowDividers = showDividers; + } + + /** + * @return A flag set indicating how dividers should be shown around items. + * @see #setShowDividers(int) + */ + public int getShowDividers() { + return mShowDividers; + } + @Override public void addView(View child, int index, ViewGroup.LayoutParams params) { - if (getChildCount() > 0) { - super.addView(makeDividerView(), index, makeDividerLayoutParams()); - if (index >= 0) { - index++; + if (!hasDividerBefore(index)) { + if (((getChildCount() > 0 + && (mShowDividers & SHOW_DIVIDER_MIDDLE) == SHOW_DIVIDER_MIDDLE) + || (mShowDividers & SHOW_DIVIDER_BEGINNING) == SHOW_DIVIDER_BEGINNING)) { + super.addView(new DividerView(mContext), index, makeDividerLayoutParams()); + if (index >= 0) { + index++; + } } } + + // Preserve original padding as we change the background + final int paddingLeft = child.getPaddingLeft(); + final int paddingRight = child.getPaddingRight(); + final int paddingTop = child.getPaddingTop(); + final int paddingBottom = child.getPaddingBottom(); child.setBackgroundDrawable(mButtonBackground); + child.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + + final boolean isLast = index < 0 || index == getChildCount(); super.addView(child, index, params); + + if (index >= 0) { + index++; + } + if ((isLast && (mShowDividers & SHOW_DIVIDER_END) == SHOW_DIVIDER_END) || + ((mShowDividers & SHOW_DIVIDER_MIDDLE) == SHOW_DIVIDER_MIDDLE && + !(getChildAt(index) instanceof DividerView))) { + super.addView(new DividerView(mContext), index, makeDividerLayoutParams()); + } } - private ImageView makeDividerView() { - ImageView result = new ImageView(mContext); - result.setImageDrawable(mDivider); - result.setScaleType(ImageView.ScaleType.FIT_XY); - return result; + private boolean hasDividerBefore(int index) { + if (index == -1) { + index = getChildCount(); + } + index--; + if (index < 0) { + return false; + } + return getChildAt(index) instanceof DividerView; } private LayoutParams makeDividerLayoutParams() { return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); } + + private class DividerView extends ImageView { + public DividerView(Context context) { + super(context); + setImageDrawable(mDivider); + setScaleType(ImageView.ScaleType.FIT_XY); + } + } } diff --git a/core/java/com/android/internal/view/menu/ActionMenuView.java b/core/java/com/android/internal/view/menu/ActionMenuView.java index 3b34b7e7b4a8..2888074607af 100644 --- a/core/java/com/android/internal/view/menu/ActionMenuView.java +++ b/core/java/com/android/internal/view/menu/ActionMenuView.java @@ -94,6 +94,8 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo a.recycle(); mDividerPadding = DIVIDER_PADDING * res.getDisplayMetrics().density; + + setBaselineAligned(false); } @Override diff --git a/core/java/com/android/internal/widget/ActionBarContextView.java b/core/java/com/android/internal/widget/ActionBarContextView.java index a824e926f87c..5d663725cbcd 100644 --- a/core/java/com/android/internal/widget/ActionBarContextView.java +++ b/core/java/com/android/internal/widget/ActionBarContextView.java @@ -21,13 +21,13 @@ import com.android.internal.view.menu.MenuBuilder; import android.content.Context; import android.content.res.TypedArray; -import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.ActionMode; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.View.MeasureSpec; +import android.widget.Button; +import android.widget.ButtonGroup; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; @@ -40,8 +40,8 @@ public class ActionBarContextView extends ViewGroup { private CharSequence mTitle; private CharSequence mSubtitle; - - private ImageButton mCloseButton; + + private View mClose; private View mCustomView; private LinearLayout mTitleLayout; private TextView mTitleView; @@ -120,7 +120,8 @@ public class ActionBarContextView extends ViewGroup { private void initTitle() { if (mTitleLayout == null) { LayoutInflater inflater = LayoutInflater.from(getContext()); - mTitleLayout = (LinearLayout) inflater.inflate(R.layout.action_bar_title_item, null); + inflater.inflate(R.layout.action_bar_title_item, this); + mTitleLayout = (LinearLayout) getChildAt(getChildCount() - 1); mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title); mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle); if (mTitle != null) { @@ -136,7 +137,6 @@ public class ActionBarContextView extends ViewGroup { } mSubtitleView.setVisibility(VISIBLE); } - addView(mTitleLayout); } else { mTitleView.setText(mTitle); mSubtitleView.setText(mSubtitle); @@ -148,16 +148,20 @@ public class ActionBarContextView extends ViewGroup { } public void initForMode(final ActionMode mode) { - if (mCloseButton == null) { - mCloseButton = new ImageButton(getContext(), null, - com.android.internal.R.attr.actionModeCloseButtonStyle); + if (mClose == null) { + LayoutInflater inflater = LayoutInflater.from(mContext); + inflater.inflate(R.layout.action_mode_close_item, this); + mClose = getChildAt(getChildCount() - 1); + } else { + addView(mClose); } - mCloseButton.setOnClickListener(new OnClickListener() { + + View closeButton = mClose.findViewById(R.id.action_mode_close_button); + closeButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mode.finish(); } }); - addView(mCloseButton); final MenuBuilder menu = (MenuBuilder) mode.getMenu(); mMenuView = (ActionMenuView) menu.getMenuView(MenuBuilder.TYPE_ACTION_BUTTON, this); @@ -224,8 +228,8 @@ public class ActionBarContextView extends ViewGroup { final int height = maxHeight - verticalPadding; final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST); - if (mCloseButton != null) { - availableWidth = measureChildView(mCloseButton, availableWidth, childSpecHeight, 0); + if (mClose != null) { + availableWidth = measureChildView(mClose, availableWidth, childSpecHeight, 0); } if (mTitleLayout != null && mCustomView == null) { @@ -235,7 +239,7 @@ public class ActionBarContextView extends ViewGroup { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); - if (child == mCloseButton || child == mTitleLayout || child == mCustomView) { + if (child == mClose || child == mTitleLayout || child == mCustomView) { continue; } @@ -278,8 +282,8 @@ public class ActionBarContextView extends ViewGroup { final int y = getPaddingTop(); final int contentHeight = b - t - getPaddingTop() - getPaddingBottom(); - if (mCloseButton != null && mCloseButton.getVisibility() != GONE) { - x += positionChild(mCloseButton, x, y, contentHeight); + if (mClose != null && mClose.getVisibility() != GONE) { + x += positionChild(mClose, x, y, contentHeight); } if (mTitleLayout != null && mCustomView == null) { diff --git a/core/res/res/drawable/group_button_background_holo_dark.xml b/core/res/res/drawable/group_button_background_holo_dark.xml new file mode 100644 index 000000000000..8e6675a0f5c4 --- /dev/null +++ b/core/res/res/drawable/group_button_background_holo_dark.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + 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. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + + <item android:state_window_focused="false" android:drawable="@color/transparent" /> + + <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. --> + <item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@color/group_button_background_pressed_holo_dark" /> + <item android:state_focused="true" android:state_enabled="false" android:drawable="@color/group_button_background_focused_holo_dark" /> + <item android:state_focused="true" android:state_pressed="true" android:drawable="@color/group_button_background_pressed_holo_dark" /> + <item android:state_focused="false" android:state_pressed="true" android:drawable="@color/group_button_background_pressed_holo_dark" /> + <item android:state_focused="true" android:drawable="@color/group_button_background_focused_holo_dark" /> + <item android:drawable="@color/transparent" /> +</selector> diff --git a/core/res/res/drawable/group_button_background_holo_light.xml b/core/res/res/drawable/group_button_background_holo_light.xml new file mode 100644 index 000000000000..94b3b5a4b2a0 --- /dev/null +++ b/core/res/res/drawable/group_button_background_holo_light.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + 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. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + + <item android:state_window_focused="false" android:drawable="@color/transparent" /> + + <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. --> + <item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@color/group_button_background_pressed_holo_light" /> + <item android:state_focused="true" android:state_enabled="false" android:drawable="@color/group_button_background_focused_holo_light" /> + <item android:state_focused="true" android:state_pressed="true" android:drawable="@color/group_button_background_pressed_holo_light" /> + <item android:state_focused="false" android:state_pressed="true" android:drawable="@color/group_button_background_pressed_holo_light" /> + <item android:state_focused="true" android:drawable="@color/group_button_background_focused_holo_light" /> + <item android:drawable="@color/transparent" /> +</selector> diff --git a/core/res/res/drawable/list_selector_holo_dark.xml b/core/res/res/drawable/list_selector_holo_dark.xml index a046831fb592..3456e1e5b5ac 100644 --- a/core/res/res/drawable/list_selector_holo_dark.xml +++ b/core/res/res/drawable/list_selector_holo_dark.xml @@ -24,6 +24,5 @@ <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" /> <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" /> <item android:state_focused="true" android:drawable="@drawable/list_selector_focused_holo_dark" /> - <item android:drawable="@color/transparent" /> - + <item android:drawable="@drawable/list_selector_focused_holo_dark" /> </selector> diff --git a/core/res/res/drawable/list_selector_holo_light.xml b/core/res/res/drawable/list_selector_holo_light.xml index e0a3bec6f0e1..2dc39f6059ad 100644 --- a/core/res/res/drawable/list_selector_holo_light.xml +++ b/core/res/res/drawable/list_selector_holo_light.xml @@ -24,6 +24,6 @@ <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" /> <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" /> <item android:state_focused="true" android:drawable="@drawable/list_selector_focused_holo_light" /> - <item android:drawable="@color/transparent" /> + <item android:drawable="@drawable/list_selector_focused_holo_light" /> </selector> diff --git a/core/res/res/layout/action_menu_item_layout.xml b/core/res/res/layout/action_menu_item_layout.xml index e7b8a25020da..5e89f52ff0ce 100644 --- a/core/res/res/layout/action_menu_item_layout.xml +++ b/core/res/res/layout/action_menu_item_layout.xml @@ -16,7 +16,8 @@ <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" + android:layout_gravity="center"> <ImageButton android:id="@+id/imageButton" android:layout_width="wrap_content" android:layout_height="wrap_content" @@ -28,5 +29,6 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:visibility="gone" - android:background="?attr/listChoiceBackgroundIndicator" /> + android:background="?attr/groupButtonBackground" + style="?attr/buttonStyleSmall" /> </com.android.internal.view.menu.ActionMenuItemView> diff --git a/core/res/res/layout/action_mode_close_item.xml b/core/res/res/layout/action_mode_close_item.xml new file mode 100644 index 000000000000..0505f18087a2 --- /dev/null +++ b/core/res/res/layout/action_mode_close_item.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + 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. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<ButtonGroup xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="12dip" + android:layout_marginBottom="12dip" + android:gravity="center" + android:showDividers="end"> + <Button android:id="@+id/action_mode_close_button" + android:text="@string/action_mode_done" + android:paddingLeft="16dip" + android:paddingRight="16dip" + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> +</ButtonGroup> diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 461fb5f087fc..62479cee561a 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -559,6 +559,9 @@ <!-- Style for button groups --> <attr name="buttonGroupStyle" format="reference" /> + + <!-- Drawable for group button backgrounds --> + <attr name="groupButtonBackground" format="reference" /> </declare-styleable> <!-- **************************************************************** --> @@ -4202,5 +4205,11 @@ <attr name="divider" /> <!-- Drawable to use as a background for buttons added to this group. --> <attr name="buttonBackground" format="reference" /> + <!-- Setting for which dividers to show. --> + <attr name="showDividers"> + <flag name="beginning" value="1" /> + <flag name="middle" value="2" /> + <flag name="end" value="4" /> + </attr> </declare-styleable> </resources> diff --git a/core/res/res/values/colors.xml b/core/res/res/values/colors.xml index 623368df02b6..774c02d3ea2a 100644 --- a/core/res/res/values/colors.xml +++ b/core/res/res/values/colors.xml @@ -130,5 +130,12 @@ <color name="highlighted_text_holo_light">#ccd2e461</color> <color name="link_text_holo_dark">#5c5cff</color> <color name="link_text_holo_light">#0000ee</color> + + <!-- Group buttons --> + <color name="group_button_background_pressed_holo_dark">#46c5c1ff</color> + <color name="group_button_background_focused_holo_dark">#2699cc00</color> + + <color name="group_button_background_pressed_holo_light">#ffffffff</color> + <color name="group_button_background_focused_holo_light">#4699cc00</color> </resources> diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 8feb2d60d845..472a9707c989 100755 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -2402,4 +2402,6 @@ <!-- Label for selecting the input method to use --> <string name="ime_enabler_subtype_title">Select inputmethods in <xliff:g id="ime_application_name">%1$s</xliff:g></string> + <!-- Label for the "Done" button on the far left of action mode toolbars. --> + <string name="action_mode_done">Done</string> </resources> diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index fdc8c47f1181..0b223b39365c 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -995,7 +995,8 @@ <style name="Widget.ButtonGroup"> <item name="divider">?android:attr/dividerVertical</item> - <item name="buttonBackground">?android:attr/listChoiceBackgroundIndicator</item> + <item name="buttonBackground">?android:attr/groupButtonBackground</item> + <item name="showDividers">middle</item> </style> <!-- Begin Holo theme styles --> diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml index 5948a5b105f5..981c67354cff 100644 --- a/core/res/res/values/themes.xml +++ b/core/res/res/values/themes.xml @@ -89,6 +89,8 @@ <item name="buttonStyleToggle">@android:style/Widget.Button.Toggle</item> + <item name="groupButtonBackground">?android:attr/listChoiceBackgroundIndicator</item> + <!-- List attributes --> <item name="listPreferredItemHeight">64dip</item> <!-- @hide --> @@ -683,6 +685,8 @@ <item name="buttonStyleToggle">@android:style/Widget.Holo.Button.Toggle</item> + <item name="groupButtonBackground">@android:drawable/group_button_background_holo_dark</item> + <!-- List attributes --> <item name="listPreferredItemHeight">64dip</item> <!-- @hide --> @@ -910,6 +914,8 @@ <item name="buttonStyleToggle">@android:style/Widget.Holo.Light.Button.Toggle</item> + <item name="groupButtonBackground">@android:drawable/group_button_background_holo_light</item> + <!-- List attributes --> <item name="listPreferredItemHeight">64dip</item> <!-- @hide --> @@ -1016,7 +1022,7 @@ <item name="scrollViewStyle">@android:style/Widget.Holo.ScrollView</item> <item name="horizontalScrollViewStyle">@android:style/Widget.Holo.HorizontalScrollView</item> <item name="spinnerStyle">?android:attr/dropDownSpinnerStyle</item> - <item name="dropDownSpinnerStyle">@android:style/Widget.Holo.Spinner.DropDown</item> + <item name="dropDownSpinnerStyle">@android:style/Widget.Holo.Light.Spinner.DropDown</item> <item name="starStyle">@android:style/Widget.Holo.CompoundButton.Star</item> <item name="tabWidgetStyle">@android:style/Widget.Holo.TabWidget</item> <item name="textViewStyle">@android:style/Widget.Holo.TextView</item> |