From 84321b2bed38753665adfda0ac14a508173362e0 Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Thu, 14 Oct 2010 17:54:40 -0700 Subject: Change AlertDialogs to use button groups. Ditch dumb prototype implementation of ButtonGroup. Change-Id: I803ef51b0bf4059936ddeb9145ca37ee53cd24b9 --- api/current.xml | 90 +++++++++- core/java/android/widget/ButtonGroup.java | 192 ++++++++++++++++----- .../dialog_divider_horizontal_holo_dark.9.png | Bin 0 -> 176 bytes .../dialog_divider_horizontal_holo_light.9.png | Bin 0 -> 182 bytes .../dialog_divider_horizontal_holo_dark.9.png | Bin 0 -> 176 bytes .../dialog_divider_horizontal_holo_light.9.png | Bin 0 -> 182 bytes core/res/res/layout-xlarge/alert_dialog.xml | 5 +- core/res/res/layout/alert_dialog.xml | 5 +- core/res/res/values/attrs.xml | 1 + core/res/res/values/public.xml | 1 + core/res/res/values/styles.xml | 13 +- core/res/res/values/themes.xml | 5 +- 12 files changed, 256 insertions(+), 56 deletions(-) create mode 100644 core/res/res/drawable-hdpi/dialog_divider_horizontal_holo_dark.9.png create mode 100644 core/res/res/drawable-hdpi/dialog_divider_horizontal_holo_light.9.png create mode 100644 core/res/res/drawable-mdpi/dialog_divider_horizontal_holo_dark.9.png create mode 100644 core/res/res/drawable-mdpi/dialog_divider_horizontal_holo_light.9.png diff --git a/api/current.xml b/api/current.xml index 914dc26d6d2a..b1f8f4500cd5 100644 --- a/api/current.xml +++ b/api/current.xml @@ -2235,7 +2235,7 @@ type="int" transient="false" volatile="false" - value="16843601" + value="16843602" static="true" final="true" deprecated="not deprecated" @@ -2246,7 +2246,7 @@ type="int" transient="false" volatile="false" - value="16843600" + value="16843601" static="true" final="true" deprecated="not deprecated" @@ -2257,7 +2257,7 @@ type="int" transient="false" volatile="false" - value="16843602" + value="16843603" static="true" final="true" deprecated="not deprecated" @@ -2374,6 +2374,17 @@ visibility="public" > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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++; - } - } + if (mButtonBackgroundRes != 0) { + // 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.setBackgroundResource(mButtonBackgroundRes); + child.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); } - // 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); + } + + @Override + public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); - if (index >= 0) { - index++; + // Add the extra size that dividers contribute. + int dividerCount = 0; + if ((mShowDividers & SHOW_DIVIDER_MIDDLE) == SHOW_DIVIDER_MIDDLE) { + final int childCount = getChildCount(); + for (int i = 0; i < childCount; i++) { + if (getChildAt(i).getVisibility() != GONE) { + dividerCount++; + } + } + dividerCount = Math.max(0, dividerCount); } - 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()); + if ((mShowDividers & SHOW_DIVIDER_BEGINNING) == SHOW_DIVIDER_BEGINNING) { + dividerCount++; } - } - - private boolean hasDividerBefore(int index) { - if (index == -1) { - index = getChildCount(); + if ((mShowDividers & SHOW_DIVIDER_END) == SHOW_DIVIDER_END) { + dividerCount++; } - index--; - if (index < 0) { - return false; + + if (getOrientation() == VERTICAL) { + final int dividerSize = mDividerHeight * dividerCount; + setMeasuredDimension(getMeasuredWidth(), + resolveSize(getMeasuredHeight() + dividerSize, heightMeasureSpec)); + } else { + final int dividerSize = mDividerWidth * dividerCount; + setMeasuredDimension(resolveSize(getMeasuredWidth() + dividerSize, widthMeasureSpec), + getMeasuredHeight()); } - return getChildAt(index) instanceof DividerView; } - private LayoutParams makeDividerLayoutParams() { - return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); + @Override + public void onLayout(boolean changed, int l, int t, int r, int b) { + super.onLayout(changed, l, t, r, b); + + final boolean begin = (mShowDividers & SHOW_DIVIDER_BEGINNING) == SHOW_DIVIDER_BEGINNING; + final boolean middle = (mShowDividers & SHOW_DIVIDER_MIDDLE) == SHOW_DIVIDER_MIDDLE; + + // Offset children to leave space for dividers. + if (getOrientation() == VERTICAL) { + int offset = begin ? mDividerHeight : 0; + final int childCount = getChildCount(); + for (int i = 0; i < childCount; i++) { + View child = getChildAt(i); + child.offsetTopAndBottom(offset); + if (middle && child.getVisibility() != GONE) { + offset += mDividerHeight; + } + } + } else { + int offset = begin ? mDividerWidth : 0; + final int childCount = getChildCount(); + for (int i = 0; i < childCount; i++) { + View child = getChildAt(i); + child.offsetLeftAndRight(offset); + if (middle && child.getVisibility() != GONE) { + offset += mDividerWidth; + } + } + } } - private class DividerView extends ImageView { - public DividerView(Context context) { - super(context); - setImageDrawable(mDivider); - setScaleType(ImageView.ScaleType.FIT_XY); + @Override + public void dispatchDraw(Canvas canvas) { + final boolean begin = (mShowDividers & SHOW_DIVIDER_BEGINNING) == SHOW_DIVIDER_BEGINNING; + final boolean middle = (mShowDividers & SHOW_DIVIDER_MIDDLE) == SHOW_DIVIDER_MIDDLE; + final boolean end = (mShowDividers & SHOW_DIVIDER_END) == SHOW_DIVIDER_END; + final boolean vertical = getOrientation() == VERTICAL; + + final Rect bounds = mTempRect; + bounds.left = mPaddingLeft; + bounds.right = mRight - mLeft - mPaddingRight; + bounds.top = mPaddingTop; + bounds.bottom = mBottom - mTop - mPaddingBottom; + + if (begin) { + if (vertical) { + bounds.bottom = bounds.top + mDividerHeight; + } else { + bounds.right = bounds.left + mDividerWidth; + } + mDivider.setBounds(bounds); + mDivider.draw(canvas); + } + + final int childCount = getChildCount(); + int i = 0; + while (i < childCount) { + final View child = getChildAt(i); + i++; + if ((middle && i < childCount && child.getVisibility() != GONE) || end) { + if (vertical) { + bounds.top = child.getBottom(); + bounds.bottom = bounds.top + mDividerHeight; + } else { + bounds.left = child.getRight(); + bounds.right = bounds.left + mDividerWidth; + } + mDivider.setBounds(bounds); + mDivider.draw(canvas); + } } + + super.dispatchDraw(canvas); } } diff --git a/core/res/res/drawable-hdpi/dialog_divider_horizontal_holo_dark.9.png b/core/res/res/drawable-hdpi/dialog_divider_horizontal_holo_dark.9.png new file mode 100644 index 000000000000..77b0999850e3 Binary files /dev/null and b/core/res/res/drawable-hdpi/dialog_divider_horizontal_holo_dark.9.png differ diff --git a/core/res/res/drawable-hdpi/dialog_divider_horizontal_holo_light.9.png b/core/res/res/drawable-hdpi/dialog_divider_horizontal_holo_light.9.png new file mode 100644 index 000000000000..3fde76e3421a Binary files /dev/null and b/core/res/res/drawable-hdpi/dialog_divider_horizontal_holo_light.9.png differ diff --git a/core/res/res/drawable-mdpi/dialog_divider_horizontal_holo_dark.9.png b/core/res/res/drawable-mdpi/dialog_divider_horizontal_holo_dark.9.png new file mode 100644 index 000000000000..77b0999850e3 Binary files /dev/null and b/core/res/res/drawable-mdpi/dialog_divider_horizontal_holo_dark.9.png differ diff --git a/core/res/res/drawable-mdpi/dialog_divider_horizontal_holo_light.9.png b/core/res/res/drawable-mdpi/dialog_divider_horizontal_holo_light.9.png new file mode 100644 index 000000000000..3fde76e3421a Binary files /dev/null and b/core/res/res/drawable-mdpi/dialog_divider_horizontal_holo_light.9.png differ diff --git a/core/res/res/layout-xlarge/alert_dialog.xml b/core/res/res/layout-xlarge/alert_dialog.xml index 5291e9dc44fb..82b450957f53 100644 --- a/core/res/res/layout-xlarge/alert_dialog.xml +++ b/core/res/res/layout-xlarge/alert_dialog.xml @@ -107,7 +107,8 @@ android:layout_height="wrap_content" android:minHeight="54dip" android:orientation="vertical" > - - + diff --git a/core/res/res/layout/alert_dialog.xml b/core/res/res/layout/alert_dialog.xml index 541d84d62edb..3982ed9c159b 100644 --- a/core/res/res/layout/alert_dialog.xml +++ b/core/res/res/layout/alert_dialog.xml @@ -106,7 +106,8 @@ android:layout_height="wrap_content" android:minHeight="54dip" android:orientation="vertical" > - - + diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 578191a1fdb1..b419a91ea418 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -347,6 +347,7 @@ + diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index da068dc0927f..2490c0fc1265 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -1369,6 +1369,7 @@ + diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index 4deb97dc2bfc..2ecb4d0c3e98 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -994,9 +994,8 @@ @@ -1275,6 +1274,12 @@ + + + + diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml index 9dbb1deb5ac6..06c502b8f404 100644 --- a/core/res/res/values/themes.xml +++ b/core/res/res/values/themes.xml @@ -89,7 +89,7 @@ @android:style/Widget.Button.Toggle - ?android:attr/listChoiceBackgroundIndicator + @android:drawable/btn_default 64dip @@ -141,6 +141,7 @@ @android:style/AlertDialog @android:style/Theme.Dialog @android:style/Theme.Dialog.Alert + ?android:attr/buttonGroupStyle @android:drawable/menu_background @@ -743,6 +744,7 @@ @android:style/AlertDialog.Holo @android:style/Theme.Holo.Dialog @android:style/Theme.Holo.Dialog.Alert + @android:style/Widget.Holo.ButtonGroup.AlertDialog @android:drawable/menu_background @@ -972,6 +974,7 @@ @android:style/AlertDialog.Holo.Light @android:style/Theme.Holo.Light.Dialog @android:style/Theme.Holo.Light.Dialog.Alert + @android:style/Widget.Holo.Light.ButtonGroup.AlertDialog @android:drawable/menu_background -- cgit v1.2.3-59-g8ed1b