summaryrefslogtreecommitdiffstats
path: root/policy
diff options
context:
space:
mode:
authorRicardo Cerqueira <cyanogenmod@cerqueira.org>2012-05-28 02:11:47 +0100
committerRicardo Cerqueira <cyanogenmod@cerqueira.org>2012-05-28 17:33:33 +0100
commitfe65f7515d5a5fe7249b56f0eaf6b2ba5c3bdee2 (patch)
tree8b700ef60c074151b6998696419228e27a062a8c /policy
parent6cb233458e1a48e8e9bf874fa829b6aa8ac34d0d (diff)
downloadframeworks_base-fe65f7515d5a5fe7249b56f0eaf6b2ba5c3bdee2.zip
frameworks_base-fe65f7515d5a5fe7249b56f0eaf6b2ba5c3bdee2.tar.gz
frameworks_base-fe65f7515d5a5fe7249b56f0eaf6b2ba5c3bdee2.tar.bz2
Bind VolUp+VolDown to toggle the ringer
Add a keyboard chord to toggle the state of the ringer, respecting the user's vibration settings. This is using the pre-existing debouncing variables and logic from the screenshot chord, and renamed some variables to make them a bit more generic Change-Id: Ia30364eb28a41642c245fa2222be46fb1a781a90
Diffstat (limited to 'policy')
-rwxr-xr-xpolicy/src/com/android/internal/policy/impl/PhoneWindowManager.java87
1 files changed, 76 insertions, 11 deletions
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 61c6fce..7a76728 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2006 The Android Open Source Project
+ * Copyright (C) 2012 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,6 +61,7 @@ import android.provider.Settings;
import com.android.internal.R;
import com.android.internal.app.ShutdownThread;
+import com.android.internal.app.ThemeUtils;
import com.android.internal.os.DeviceKeyHandler;
import com.android.internal.policy.PolicyManager;
import com.android.internal.statusbar.IStatusBarService;
@@ -138,8 +140,11 @@ import android.view.KeyCharacterMap.FallbackAction;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
+import android.view.VolumePanel;
+
import android.widget.Toast;
import android.media.IAudioService;
+import android.media.AudioService;
import android.media.AudioManager;
import java.io.File;
@@ -463,10 +468,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// Screenshot trigger states
// Time to volume and power must be pressed within this interval of each other.
- private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
+ private static final long ACTION_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
private boolean mVolumeDownKeyTriggered;
private long mVolumeDownKeyTime;
- private boolean mVolumeDownKeyConsumedByScreenshotChord;
+ private long mVolumeUpKeyTime;
+ private boolean mVolumeDownKeyConsumedByChord;
+ private boolean mVolumeUpKeyConsumedByChord;
private boolean mVolumeUpKeyTriggered;
private boolean mPowerKeyTriggered;
private long mPowerKeyTime;
@@ -686,9 +693,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
private void interceptScreenshotChord() {
if (mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
final long now = SystemClock.uptimeMillis();
- if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
- && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
- mVolumeDownKeyConsumedByScreenshotChord = true;
+ if (now <= mVolumeDownKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS
+ && now <= mPowerKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS) {
+ mVolumeDownKeyConsumedByChord = true;
cancelPendingPowerKeyAction();
mHandler.postDelayed(mScreenshotChordLongPress,
@@ -701,6 +708,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mHandler.removeCallbacks(mScreenshotChordLongPress);
}
+ private void interceptRingerChord() {
+ if (mVolumeDownKeyTriggered && !mPowerKeyTriggered && mVolumeUpKeyTriggered) {
+ final long now = SystemClock.uptimeMillis();
+ if (now <= mVolumeDownKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS
+ && now <= mVolumeUpKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS) {
+ mVolumeDownKeyConsumedByChord = true;
+ mVolumeUpKeyConsumedByChord = true;
+
+ mHandler.postDelayed(mRingerChordLongPress,
+ ViewConfiguration.getGlobalActionKeyTimeout());
+ }
+ }
+ }
+
+ private void cancelPendingRingerChordAction() {
+ mHandler.removeCallbacks(mRingerChordLongPress);
+ }
+
private final Runnable mPowerLongPress = new Runnable() {
public void run() {
// The context isn't read
@@ -733,6 +758,26 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
};
+ private final Runnable mRingerChordLongPress = new Runnable() {
+ public void run() {
+ // Do the switch
+ final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
+ final int ringerMode = am.getRingerMode();
+ final VolumePanel volumePanel = new VolumePanel(ThemeUtils.createUiContext(mContext),
+ (AudioService) getAudioService());
+ if (ringerMode == AudioManager.RINGER_MODE_NORMAL) {
+ boolean vibrateSetting = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER)
+ == AudioManager.VIBRATE_SETTING_ON;
+ am.setRingerMode(vibrateSetting ? AudioManager.RINGER_MODE_VIBRATE :
+ AudioManager.RINGER_MODE_SILENT);
+ } else {
+ am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
+ }
+ volumePanel.postVolumeChanged(AudioManager.STREAM_RING,AudioManager.FLAG_SHOW_UI
+ | AudioManager.FLAG_VIBRATE);
+ }
+ };
+
Runnable mBackLongPress = new Runnable() {
public void run() {
try {
@@ -1633,21 +1678,34 @@ public class PhoneWindowManager implements WindowManagerPolicy {
+ repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed);
}
- // If we think we might have a volume down & power key chord on the way
+ // If we think we might have a volume down & power/volume-up key chord on the way
// but we're not sure, then tell the dispatcher to wait a little while and
// try again later before dispatching.
if ((flags & KeyEvent.FLAG_FALLBACK) == 0) {
- if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
+ if (mVolumeDownKeyTriggered && !mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
+ final long now = SystemClock.uptimeMillis();
+ final long timeoutTime = mVolumeDownKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS;
+ if (now < timeoutTime) {
+ return timeoutTime - now;
+ }
+ } else if (mVolumeUpKeyTriggered && !mVolumeDownKeyTriggered) {
final long now = SystemClock.uptimeMillis();
- final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
+ final long timeoutTime = mVolumeUpKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS;
if (now < timeoutTime) {
return timeoutTime - now;
}
}
+
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
- && mVolumeDownKeyConsumedByScreenshotChord) {
+ && mVolumeDownKeyConsumedByChord) {
+ if (!down) {
+ mVolumeDownKeyConsumedByChord = false;
+ }
+ return -1;
+ } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
+ && mVolumeUpKeyConsumedByChord) {
if (!down) {
- mVolumeDownKeyConsumedByScreenshotChord = false;
+ mVolumeUpKeyConsumedByChord = false;
}
return -1;
}
@@ -2989,25 +3047,31 @@ public class PhoneWindowManager implements WindowManagerPolicy {
&& (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
mVolumeDownKeyTriggered = true;
mVolumeDownKeyTime = event.getDownTime();
- mVolumeDownKeyConsumedByScreenshotChord = false;
+ mVolumeDownKeyConsumedByChord = false;
cancelPendingPowerKeyAction();
interceptScreenshotChord();
+ interceptRingerChord();
}
} else {
mVolumeDownKeyTriggered = false;
cancelPendingScreenshotChordAction();
+ cancelPendingRingerChordAction();
}
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
if (down) {
if (isScreenOn && !mVolumeUpKeyTriggered
&& (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
mVolumeUpKeyTriggered = true;
+ mVolumeUpKeyTime = event.getDownTime();
+ mVolumeUpKeyConsumedByChord = false;
cancelPendingPowerKeyAction();
cancelPendingScreenshotChordAction();
+ interceptRingerChord();
}
} else {
mVolumeUpKeyTriggered = false;
cancelPendingScreenshotChordAction();
+ cancelPendingRingerChordAction();
}
}
if (down) {
@@ -3084,6 +3148,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
&& (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
mPowerKeyTriggered = true;
mPowerKeyTime = event.getDownTime();
+ cancelPendingRingerChordAction();
interceptScreenshotChord();
}