diff options
| author | 2012-09-19 11:53:03 -0700 | |
|---|---|---|
| committer | 2012-09-20 16:48:44 -0700 | |
| commit | 0516a9ecb0d4d76acd2f1c4c2521f44c696789a8 (patch) | |
| tree | 5e9ad1e89ea1dfe53f1633960a8d409ac9210908 | |
| parent | 4dd3c3797060b35c8e6ebbbdd164c17c6db7b5ec (diff) | |
Fix safe volume warning message flickering
Do not display a new warning message when one is already showing.
Bug 7064975.
Change-Id: I920656c6d742a969c29e8f42a438ecbc794d1114
| -rw-r--r-- | core/java/android/view/VolumePanel.java | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/core/java/android/view/VolumePanel.java b/core/java/android/view/VolumePanel.java index d6f63a7cec0c..8315bd768461 100644 --- a/core/java/android/view/VolumePanel.java +++ b/core/java/android/view/VolumePanel.java @@ -214,6 +214,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie private Vibrator mVibrator; private static AlertDialog sConfirmSafeVolumeDialog; + private static Object sConfirmSafeVolumeLock = new Object(); private static class WarningDialogReceiver extends BroadcastReceiver implements DialogInterface.OnDismissListener { @@ -230,10 +231,16 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie @Override public void onReceive(Context context, Intent intent) { mDialog.cancel(); + synchronized (sConfirmSafeVolumeLock) { + sConfirmSafeVolumeDialog = null; + } } public void onDismiss(DialogInterface unused) { mContext.unregisterReceiver(this); + synchronized (sConfirmSafeVolumeLock) { + sConfirmSafeVolumeDialog = null; + } } } @@ -556,6 +563,7 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie } public void postDisplaySafeVolumeWarning() { + if (hasMessages(MSG_DISPLAY_SAFE_VOLUME_WARNING)) return; obtainMessage(MSG_DISPLAY_SAFE_VOLUME_WARNING, 0, 0).sendToTarget(); } @@ -828,28 +836,29 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie } protected void onDisplaySafeVolumeWarning() { - if (sConfirmSafeVolumeDialog != null) { - sConfirmSafeVolumeDialog.dismiss(); - } - sConfirmSafeVolumeDialog = new AlertDialog.Builder(mContext) - .setMessage(com.android.internal.R.string.safe_media_volume_warning) - .setPositiveButton(com.android.internal.R.string.yes, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - mAudioService.disableSafeMediaVolume(); - } - }) - .setNegativeButton(com.android.internal.R.string.no, null) - .setIconAttribute(android.R.attr.alertDialogIcon) - .create(); - - final WarningDialogReceiver warning = new WarningDialogReceiver(mContext, - sConfirmSafeVolumeDialog); - - sConfirmSafeVolumeDialog.setOnDismissListener(warning); - sConfirmSafeVolumeDialog.getWindow().setType( - WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); - sConfirmSafeVolumeDialog.show(); + synchronized (sConfirmSafeVolumeLock) { + if (sConfirmSafeVolumeDialog != null) { + return; + } + sConfirmSafeVolumeDialog = new AlertDialog.Builder(mContext) + .setMessage(com.android.internal.R.string.safe_media_volume_warning) + .setPositiveButton(com.android.internal.R.string.yes, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + mAudioService.disableSafeMediaVolume(); + } + }) + .setNegativeButton(com.android.internal.R.string.no, null) + .setIconAttribute(android.R.attr.alertDialogIcon) + .create(); + final WarningDialogReceiver warning = new WarningDialogReceiver(mContext, + sConfirmSafeVolumeDialog); + + sConfirmSafeVolumeDialog.setOnDismissListener(warning); + sConfirmSafeVolumeDialog.getWindow().setType( + WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); + sConfirmSafeVolumeDialog.show(); + } } /** |