Fix bug 3245465 - Themed dialog icons

Added light/dark versions of holo dialog icons. Apps using
AlertDialogs that wish to use the system dialog icon should use
setIconAttribute(android.R.attr.alertDialogIcon) instead of
setIcon(android.R.drawable.ic_alert_dialog).

Change-Id: I40793a3164478be5ffa045ededfcab8210753a4b
This commit is contained in:
Adam Powell
2011-01-07 22:30:48 -08:00
parent 4d46ecb075
commit 947f782411
15 changed files with 83 additions and 9 deletions

View File

@@ -2116,6 +2116,17 @@
visibility="public"
>
</field>
<field name="alertDialogIcon"
type="int"
transient="false"
volatile="false"
value="16843607"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="alertDialogStyle"
type="int"
transient="false"
@@ -26610,6 +26621,19 @@
<parameter name="icon" type="android.graphics.drawable.Drawable">
</parameter>
</method>
<method name="setIconAttribute"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="attrId" type="int">
</parameter>
</method>
<method name="setInverseBackgroundForced"
return="void"
abstract="false"
@@ -26807,6 +26831,19 @@
<parameter name="icon" type="android.graphics.drawable.Drawable">
</parameter>
</method>
<method name="setIconAttribute"
return="android.app.AlertDialog.Builder"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="attrId" type="int">
</parameter>
</method>
<method name="setInverseBackgroundForced"
return="android.app.AlertDialog.Builder"
abstract="false"

View File

@@ -270,6 +270,17 @@ public class AlertDialog extends Dialog implements DialogInterface {
mAlert.setIcon(icon);
}
/**
* Set an icon as supplied by a theme attribute. e.g. android.R.attr.alertDialogIcon
*
* @param attrId ID of a theme attribute that points to a drawable resource.
*/
public void setIconAttribute(int attrId) {
TypedValue out = new TypedValue();
mContext.getTheme().resolveAttribute(attrId, out, true);
mAlert.setIcon(out.resourceId);
}
public void setInverseBackgroundForced(boolean forceInverseBackground) {
mAlert.setInverseBackgroundForced(forceInverseBackground);
}
@@ -399,7 +410,19 @@ public class AlertDialog extends Dialog implements DialogInterface {
P.mIcon = icon;
return this;
}
/**
* Set an icon as supplied by a theme attribute. e.g. android.R.attr.alertDialogIcon
*
* @param attrId ID of a theme attribute that points to a drawable resource.
*/
public Builder setIconAttribute(int attrId) {
TypedValue out = new TypedValue();
P.mContext.getTheme().resolveAttribute(attrId, out, true);
P.mIconId = out.resourceId;
return this;
}
/**
* Set a listener to be invoked when the positive button of the dialog is pressed.
* @param textId The resource id of the text to display in the positive button

View File

@@ -28,6 +28,7 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
@@ -84,8 +85,10 @@ public class HeavyWeightSwitcherActivity extends Activity {
button = findViewById((R.id.cancel));
button.setOnClickListener(mCancelListener);
TypedValue out = new TypedValue();
getTheme().resolveAttribute(android.R.attr.alertDialogIcon, out, true);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
android.R.drawable.ic_dialog_alert);
out.resourceId);
}
void setText(int id, CharSequence text) {

View File

@@ -109,7 +109,7 @@ public final class ShutdownThread extends Thread {
if (confirm) {
final CloseDialogReceiver closer = new CloseDialogReceiver(context);
final AlertDialog dialog = new AlertDialog.Builder(context)
.setIcon(android.R.drawable.ic_dialog_alert)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(com.android.internal.R.string.power_off)
.setMessage(resourceId)
.setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 930 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1018 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 770 B

View File

@@ -636,6 +636,8 @@
<attr name="dialogTheme" format="reference" />
<!-- Theme to use for alert dialogs spawned from this theme. -->
<attr name="alertDialogTheme" format="reference" />
<!-- Icon drawable to use for alerts -->
<attr name="alertDialogIcon" format="reference" />
<!-- Drawable to use for generic vertical dividers. -->
<attr name="dividerVertical" format="reference" />

View File

@@ -1421,6 +1421,7 @@
<public type="attr" name="editTextBackground" />
<public type="attr" name="horizontalScrollViewStyle" />
<public type="attr" name="layerType" />
<public type="attr" name="alertDialogIcon" />
<!-- A simple fade-in animation. -->
<public type="animator" name="fade_in" id="0x010b0000" />

View File

@@ -2152,7 +2152,8 @@
<!-- Preference framework strings. -->
<string name="no">Cancel</string>
<!-- This is the generic "attention" string to be used in attention dialogs. Typically
combined with setIcon(android.R.drawable.ic_dialog_alert) -->
combined with setIconAttribute(android.R.attr.alertDialogIcon)
(or setIcon(android.R.drawable.ic_dialog_alert) on legacy versions of the platform) -->
<string name="dialog_alert_title">Attention</string>
<!-- Text shown by list fragment when waiting for data to display. -->

View File

@@ -144,6 +144,7 @@
<item name="dialogTheme">@android:style/Theme.Dialog</item>
<item name="alertDialogTheme">@android:style/Theme.Dialog.Alert</item>
<item name="alertDialogCenterButtons">true</item>
<item name="alertDialogIcon">@android:drawable/ic_dialog_alert</item>
<!-- Panel attributes -->
<item name="panelBackground">@android:drawable/menu_background</item>
@@ -808,6 +809,7 @@
<item name="dialogTheme">@android:style/Theme.Holo.Dialog</item>
<item name="alertDialogTheme">@android:style/Theme.Holo.Dialog.Alert</item>
<item name="alertDialogCenterButtons">false</item>
<item name="alertDialogIcon">@android:drawable/ic_dialog_alert_holo_dark</item>
<!-- Panel attributes -->
<item name="panelBackground">@android:drawable/menu_background</item>
@@ -1064,6 +1066,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="alertDialogIcon">@android:drawable/ic_dialog_alert_holo_light</item>
<!-- Panel attributes -->
<item name="panelBackground">@android:drawable/menu_background</item>

View File

@@ -186,7 +186,7 @@ public class PowerUI extends SystemUI {
b.setCancelable(true);
b.setTitle(R.string.battery_low_title);
b.setView(v);
b.setIcon(android.R.drawable.ic_dialog_alert);
b.setIconAttribute(android.R.attr.alertDialogIcon);
b.setPositiveButton(android.R.string.ok, null);
final Intent intent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
@@ -249,7 +249,7 @@ if (false) { // getRingtone ANRs
AlertDialog.Builder b = new AlertDialog.Builder(mContext);
b.setCancelable(true);
b.setMessage(R.string.invalid_charger);
b.setIcon(android.R.drawable.ic_dialog_alert);
b.setIconAttribute(android.R.attr.alertDialogIcon);
b.setPositiveButton(android.R.string.ok, null);
AlertDialog d = b.create();

View File

@@ -34,7 +34,7 @@ class BaseErrorDialog extends AlertDialog {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
getWindow().setTitle("Error Dialog");
setIcon(R.drawable.ic_dialog_alert);
setIconAttribute(R.attr.alertDialogIcon);
}
public void onStart() {

View File

@@ -4,6 +4,7 @@ import com.android.internal.R;
import android.app.Dialog;
import android.content.Context;
import android.util.TypedValue;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
@@ -20,8 +21,11 @@ public class LaunchWarningWindow extends Dialog {
setContentView(R.layout.launch_warning);
setTitle(context.getText(R.string.launch_warning_title));
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
R.drawable.ic_dialog_alert);
TypedValue out = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.alertDialogIcon, out, true);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, out.resourceId);
ImageView icon = (ImageView)findViewById(R.id.replace_app_icon);
icon.setImageDrawable(next.info.applicationInfo.loadIcon(context.getPackageManager()));
TextView text = (TextView)findViewById(R.id.replace_message);