Merge "Change AlertDialogs to use button groups."
This commit is contained in:
@@ -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"
|
||||
>
|
||||
</field>
|
||||
<field name="alertDialogButtonGroupStyle"
|
||||
type="int"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
value="16843600"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
<field name="alertDialogStyle"
|
||||
type="int"
|
||||
transient="false"
|
||||
@@ -230694,6 +230705,30 @@
|
||||
<parameter name="defStyleRes" type="int">
|
||||
</parameter>
|
||||
</constructor>
|
||||
<method name="dispatchDraw"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="canvas" type="android.graphics.Canvas">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="getDividerDrawable"
|
||||
return="android.graphics.drawable.Drawable"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getShowDividers"
|
||||
return="int"
|
||||
abstract="false"
|
||||
@@ -230705,6 +230740,55 @@
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="onLayout"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="changed" type="boolean">
|
||||
</parameter>
|
||||
<parameter name="l" type="int">
|
||||
</parameter>
|
||||
<parameter name="t" type="int">
|
||||
</parameter>
|
||||
<parameter name="r" type="int">
|
||||
</parameter>
|
||||
<parameter name="b" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="onMeasure"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="widthMeasureSpec" type="int">
|
||||
</parameter>
|
||||
<parameter name="heightMeasureSpec" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setDividerDrawable"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="divider" type="android.graphics.drawable.Drawable">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="setShowDividers"
|
||||
return="void"
|
||||
abstract="false"
|
||||
|
||||
@@ -18,14 +18,21 @@ package android.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class ButtonGroup extends LinearLayout {
|
||||
private static final String LOG = "ButtonGroup";
|
||||
|
||||
private Drawable mDivider;
|
||||
private Drawable mButtonBackground;
|
||||
private int mDividerWidth;
|
||||
private int mDividerHeight;
|
||||
private int mButtonBackgroundRes;
|
||||
private int mShowDividers;
|
||||
|
||||
/**
|
||||
@@ -45,6 +52,8 @@ public class ButtonGroup extends LinearLayout {
|
||||
*/
|
||||
public static final int SHOW_DIVIDER_END = 4;
|
||||
|
||||
private final Rect mTempRect = new Rect();
|
||||
|
||||
public ButtonGroup(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -59,11 +68,11 @@ public class ButtonGroup extends LinearLayout {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
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);
|
||||
setDividerDrawable(a.getDrawable(com.android.internal.R.styleable.ButtonGroup_divider));
|
||||
mButtonBackgroundRes = a.getResourceId(
|
||||
com.android.internal.R.styleable.ButtonGroup_buttonBackground, 0);
|
||||
setShowDividers(a.getInt(com.android.internal.R.styleable.ButtonGroup_showDividers,
|
||||
SHOW_DIVIDER_MIDDLE));
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@@ -75,6 +84,9 @@ public class ButtonGroup extends LinearLayout {
|
||||
* or {@link #SHOW_DIVIDER_NONE} to show no dividers.
|
||||
*/
|
||||
public void setShowDividers(int showDividers) {
|
||||
if (showDividers != mShowDividers) {
|
||||
requestLayout();
|
||||
}
|
||||
mShowDividers = showDividers;
|
||||
}
|
||||
|
||||
@@ -86,60 +98,148 @@ public class ButtonGroup extends LinearLayout {
|
||||
return mShowDividers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a drawable to be used as a divider between items.
|
||||
* @param divider Drawable that will divide each item.
|
||||
*/
|
||||
public void setDividerDrawable(Drawable divider) {
|
||||
if (divider == mDivider) {
|
||||
return;
|
||||
}
|
||||
mDivider = divider;
|
||||
mDividerWidth = divider.getIntrinsicWidth();
|
||||
mDividerHeight = divider.getIntrinsicHeight();
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the drawable used to draw dividers between items.
|
||||
* @return The divider drawable
|
||||
*/
|
||||
public Drawable getDividerDrawable() {
|
||||
return mDivider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addView(View child, int index, ViewGroup.LayoutParams params) {
|
||||
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++;
|
||||
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);
|
||||
}
|
||||
|
||||
super.addView(child, index, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
// 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 ((mShowDividers & SHOW_DIVIDER_BEGINNING) == SHOW_DIVIDER_BEGINNING) {
|
||||
dividerCount++;
|
||||
}
|
||||
if ((mShowDividers & SHOW_DIVIDER_END) == SHOW_DIVIDER_END) {
|
||||
dividerCount++;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 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);
|
||||
}
|
||||
@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;
|
||||
|
||||
private class DividerView extends ImageView {
|
||||
public DividerView(Context context) {
|
||||
super(context);
|
||||
setImageDrawable(mDivider);
|
||||
setScaleType(ImageView.ScaleType.FIT_XY);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 176 B |
Binary file not shown.
|
After Width: | Height: | Size: 182 B |
Binary file not shown.
|
After Width: | Height: | Size: 176 B |
Binary file not shown.
|
After Width: | Height: | Size: 182 B |
@@ -107,7 +107,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="54dip"
|
||||
android:orientation="vertical" >
|
||||
<LinearLayout
|
||||
<ButtonGroup
|
||||
style="?android:attr/alertDialogButtonGroupStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
@@ -145,6 +146,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</ButtonGroup>
|
||||
</LinearLayout>
|
||||
</com.android.internal.widget.WeightedLinearLayout>
|
||||
|
||||
@@ -106,7 +106,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="54dip"
|
||||
android:orientation="vertical" >
|
||||
<LinearLayout
|
||||
<ButtonGroup
|
||||
style="?android:attr/alertDialogButtonGroupStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
@@ -144,6 +145,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</ButtonGroup>
|
||||
</LinearLayout>
|
||||
</com.android.internal.widget.WeightedLinearLayout>
|
||||
|
||||
@@ -347,6 +347,7 @@
|
||||
<!-- ============ -->
|
||||
<eat-comment />
|
||||
<attr name="alertDialogStyle" format="reference" />
|
||||
<attr name="alertDialogButtonGroupStyle" format="reference" />
|
||||
|
||||
<!-- ============ -->
|
||||
<!-- Panel styles -->
|
||||
|
||||
@@ -1369,6 +1369,7 @@
|
||||
<public type="attr" name="textLineHeight" />
|
||||
<public type="attr" name="dividerVertical" />
|
||||
<public type="attr" name="buttonGroupStyle" />
|
||||
<public type="attr" name="alertDialogButtonGroupStyle" />
|
||||
|
||||
<public type="anim" name="animator_fade_in" />
|
||||
<public type="anim" name="animator_fade_out" />
|
||||
|
||||
@@ -994,9 +994,8 @@
|
||||
</style>
|
||||
|
||||
<style name="Widget.ButtonGroup">
|
||||
<item name="divider">?android:attr/dividerVertical</item>
|
||||
<item name="buttonBackground">?android:attr/groupButtonBackground</item>
|
||||
<item name="showDividers">middle</item>
|
||||
<item name="showDividers"></item>
|
||||
</style>
|
||||
|
||||
<!-- Begin Holo theme styles -->
|
||||
@@ -1275,6 +1274,12 @@
|
||||
</style>
|
||||
|
||||
<style name="Widget.Holo.ButtonGroup" parent="Widget.ButtonGroup">
|
||||
<item name="divider">?android:attr/dividerVertical</item>
|
||||
<item name="showDividers">middle</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.Holo.ButtonGroup.AlertDialog">
|
||||
<item name="android:background">@android:drawable/dialog_divider_horizontal_holo_dark</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.Holo.TextView" parent="Widget.TextView">
|
||||
@@ -1540,6 +1545,10 @@
|
||||
<style name="Widget.Holo.Light.ButtonGroup" parent="Widget.Holo.ButtonGroup">
|
||||
</style>
|
||||
|
||||
<style name="Widget.Holo.Light.ButtonGroup.AlertDialog">
|
||||
<item name="android:background">@android:drawable/dialog_divider_horizontal_holo_light</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.Holo.Light.TextView" parent="Widget.TextView">
|
||||
</style>
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
|
||||
<item name="buttonStyleToggle">@android:style/Widget.Button.Toggle</item>
|
||||
|
||||
<item name="groupButtonBackground">?android:attr/listChoiceBackgroundIndicator</item>
|
||||
<item name="groupButtonBackground">@android:drawable/btn_default</item>
|
||||
|
||||
<!-- List attributes -->
|
||||
<item name="listPreferredItemHeight">64dip</item>
|
||||
@@ -141,6 +141,7 @@
|
||||
<item name="alertDialogStyle">@android:style/AlertDialog</item>
|
||||
<item name="dialogTheme">@android:style/Theme.Dialog</item>
|
||||
<item name="alertDialogTheme">@android:style/Theme.Dialog.Alert</item>
|
||||
<item name="alertDialogButtonGroupStyle">?android:attr/buttonGroupStyle</item>
|
||||
|
||||
<!-- Panel attributes -->
|
||||
<item name="panelBackground">@android:drawable/menu_background</item>
|
||||
@@ -743,6 +744,7 @@
|
||||
<item name="alertDialogStyle">@android:style/AlertDialog.Holo</item>
|
||||
<item name="dialogTheme">@android:style/Theme.Holo.Dialog</item>
|
||||
<item name="alertDialogTheme">@android:style/Theme.Holo.Dialog.Alert</item>
|
||||
<item name="alertDialogButtonGroupStyle">@android:style/Widget.Holo.ButtonGroup.AlertDialog</item>
|
||||
|
||||
<!-- Panel attributes -->
|
||||
<item name="panelBackground">@android:drawable/menu_background</item>
|
||||
@@ -972,6 +974,7 @@
|
||||
<item name="alertDialogStyle">@android:style/AlertDialog.Holo.Light</item>
|
||||
<item name="dialogTheme">@android:style/Theme.Holo.Light.Dialog</item>
|
||||
<item name="alertDialogTheme">@android:style/Theme.Holo.Light.Dialog.Alert</item>
|
||||
<item name="alertDialogButtonGroupStyle">@android:style/Widget.Holo.Light.ButtonGroup.AlertDialog</item>
|
||||
|
||||
<!-- Panel attributes -->
|
||||
<item name="panelBackground">@android:drawable/menu_background</item>
|
||||
|
||||
Reference in New Issue
Block a user