summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android/systemui/volume/SafetyWarningDialog.java
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2015-04-03 20:07:31 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-04-03 20:07:31 +0000
commit33350cf90cfc90882f5e75d0f93eea3d770929e6 (patch)
treeff21ea180fa0d78f0151e69dc5da1fa7c611c58b /packages/SystemUI/src/com/android/systemui/volume/SafetyWarningDialog.java
parentdbcec13d64d7e6e8d4e5a867c1ca8b78951ed217 (diff)
parent76b52b3f9b0dde7d7800508271cf5851d92b25d5 (diff)
downloadframeworks_base-33350cf90cfc90882f5e75d0f93eea3d770929e6.zip
frameworks_base-33350cf90cfc90882f5e75d0f93eea3d770929e6.tar.gz
frameworks_base-33350cf90cfc90882f5e75d0f93eea3d770929e6.tar.bz2
Merge "Volume: Port safety warning over to new dialog."
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/volume/SafetyWarningDialog.java')
-rw-r--r--packages/SystemUI/src/com/android/systemui/volume/SafetyWarningDialog.java109
1 files changed, 109 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/volume/SafetyWarningDialog.java b/packages/SystemUI/src/com/android/systemui/volume/SafetyWarningDialog.java
new file mode 100644
index 0000000..04640a2
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/volume/SafetyWarningDialog.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2015 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.
+ */
+
+package com.android.systemui.volume;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.media.AudioManager;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.WindowManager;
+
+import com.android.systemui.statusbar.phone.SystemUIDialog;
+
+abstract public class SafetyWarningDialog extends SystemUIDialog
+ implements DialogInterface.OnDismissListener, DialogInterface.OnClickListener {
+
+ private static final String TAG = Util.logTag(SafetyWarningDialog.class);
+
+ private static final int KEY_CONFIRM_ALLOWED_AFTER = 1000; // milliseconds
+
+ private final Context mContext;
+ private final AudioManager mAudioManager;
+
+ private long mShowTime;
+ private boolean mNewVolumeUp;
+
+ public SafetyWarningDialog(Context context, AudioManager audioManager) {
+ super(context);
+ mContext = context;
+ mAudioManager = audioManager;
+
+ getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
+ setMessage(mContext.getString(com.android.internal.R.string.safe_media_volume_warning));
+ setButton(DialogInterface.BUTTON_POSITIVE,
+ mContext.getString(com.android.internal.R.string.yes), this);
+ setButton(DialogInterface.BUTTON_NEGATIVE,
+ mContext.getString(com.android.internal.R.string.no), (OnClickListener) null);
+ setOnDismissListener(this);
+
+ final IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
+ context.registerReceiver(mReceiver, filter);
+ }
+
+ abstract protected void cleanUp();
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && event.getRepeatCount() == 0) {
+ mNewVolumeUp = true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
+ @Override
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && mNewVolumeUp
+ && (System.currentTimeMillis() - mShowTime) > KEY_CONFIRM_ALLOWED_AFTER) {
+ if (D.BUG) Log.d(TAG, "Confirmed warning via VOLUME_UP");
+ mAudioManager.disableSafeMediaVolume();
+ dismiss();
+ }
+ return super.onKeyUp(keyCode, event);
+ }
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mAudioManager.disableSafeMediaVolume();
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mShowTime = System.currentTimeMillis();
+ }
+
+ @Override
+ public void onDismiss(DialogInterface unused) {
+ mContext.unregisterReceiver(mReceiver);
+ cleanUp();
+ }
+
+ private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
+ if (D.BUG) Log.d(TAG, "Received ACTION_CLOSE_SYSTEM_DIALOGS");
+ cancel();
+ cleanUp();
+ }
+ }
+ };
+} \ No newline at end of file