summaryrefslogtreecommitdiffstats
path: root/policy
diff options
context:
space:
mode:
authorDanesh M <daneshm90@gmail.com>2012-02-29 22:27:01 -0500
committerDanesh M <daneshm90@gmail.com>2012-03-10 16:04:29 -0500
commitfa0c6a58a44fd884d758d47eaa750c9c6476af1a (patch)
tree51e8d02f8258f6cbee6e2e66ffec01a4163ab7b5 /policy
parentbcab1a93e45a667eec405dec396c442f2acf16ad (diff)
downloadframeworks_base-fa0c6a58a44fd884d758d47eaa750c9c6476af1a.zip
frameworks_base-fa0c6a58a44fd884d758d47eaa750c9c6476af1a.tar.gz
frameworks_base-fa0c6a58a44fd884d758d47eaa750c9c6476af1a.tar.bz2
Lockscreen : Vol long press skip tracks (1/2)
Straight port from cm7 Credit : Kmobs,Sven,Cvps..and all who've refined it Patchset 2 : Minor fixes Patchset 3 : Fix misplaced closing bracket Patchset 4 : Rework the conditional logic Patchset 5 : Rebase Patchset 6 : Fix vol change for wake screen Patchset 7 : Cleanup Change-Id: I74584932772ddabbd203acb4d6a65270fd6b20c2
Diffstat (limited to 'policy')
-rwxr-xr-xpolicy/src/com/android/internal/policy/impl/PhoneWindowManager.java145
1 files changed, 105 insertions, 40 deletions
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index f9b80b5..efe928e 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -40,7 +40,6 @@ import android.database.ContentObserver;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.RectF;
-import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -356,6 +355,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// Behavior of volume wake
boolean mVolumeWakeScreen;
+ // Behavior of volbtn music controls
+ boolean mVolBtnMusicControls;
+ boolean mIsLongPress;
+
private final InputHandler mPointerLocationInputHandler = new BaseInputHandler() {
@Override
public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
@@ -485,6 +488,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.VOLUME_WAKE_SCREEN), false, this);
resolver.registerContentObserver(Settings.System.getUriFor(
+ Settings.System.VOLBTN_MUSIC_CONTROLS), false, this);
+ resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.ACCELEROMETER_ROTATION), false, this);
resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.USER_ROTATION), false, this);
@@ -622,6 +627,53 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
}
+ /**
+ * When a volumeup-key longpress expires, skip songs based on key press
+ */
+ Runnable mVolumeUpLongPress = new Runnable() {
+ public void run() {
+ // set the long press flag to true
+ mIsLongPress = true;
+
+ // Shamelessly copied from Kmobs LockScreen controls, works for Pandora, etc...
+ sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_NEXT);
+ };
+ };
+
+ /**
+ * When a volumedown-key longpress expires, skip songs based on key press
+ */
+ Runnable mVolumeDownLongPress = new Runnable() {
+ public void run() {
+ // set the long press flag to true
+ mIsLongPress = true;
+
+ // Shamelessly copied from Kmobs LockScreen controls, works for Pandora, etc...
+ sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_PREVIOUS);
+ };
+ };
+
+ private void sendMediaButtonEvent(int code) {
+ long eventtime = SystemClock.uptimeMillis();
+ Intent keyIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
+ KeyEvent keyEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, code, 0);
+ keyIntent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
+ mContext.sendOrderedBroadcast(keyIntent, null);
+ keyEvent = KeyEvent.changeAction(keyEvent, KeyEvent.ACTION_UP);
+ keyIntent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
+ mContext.sendOrderedBroadcast(keyIntent, null);
+ }
+
+ void handleVolumeLongPress(int keycode) {
+ mHandler.postDelayed(keycode == KeyEvent.KEYCODE_VOLUME_UP ? mVolumeUpLongPress :
+ mVolumeDownLongPress, ViewConfiguration.getLongPressTimeout());
+ }
+
+ void handleVolumeLongPressAbort() {
+ mHandler.removeCallbacks(mVolumeUpLongPress);
+ mHandler.removeCallbacks(mVolumeDownLongPress);
+ }
+
private void interceptScreenshotChord() {
if (mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
final long now = SystemClock.uptimeMillis();
@@ -959,6 +1011,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT);
mVolumeWakeScreen = (Settings.System.getInt(resolver,
Settings.System.VOLUME_WAKE_SCREEN, 0) == 1);
+ mVolBtnMusicControls = (Settings.System.getInt(resolver,
+ Settings.System.VOLBTN_MUSIC_CONTROLS, 1) == 1);
int accelerometerDefault = Settings.System.getInt(resolver,
Settings.System.ACCELEROMETER_ROTATION, DEFAULT_ACCELEROMETER_ROTATION);
@@ -2803,13 +2857,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
final boolean isWakeKey = (policyFlags
& (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0
- || ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) && mVolumeWakeScreen)
- || ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) && mVolumeWakeScreen);
-
- // make sure keyevent get's handled as power key on volume-wake
- if(!isScreenOn && mVolumeWakeScreen && isWakeKey && ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)
- || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)))
- keyCode=KeyEvent.KEYCODE_POWER;
+ || (((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN))
+ && mVolumeWakeScreen && !isScreenOn);
if (down && isWakeKey) {
if (keyguardActive) {
@@ -2825,6 +2874,36 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// Handle special keys.
switch (keyCode) {
+ case KeyEvent.KEYCODE_ENDCALL: {
+ result &= ~ACTION_PASS_TO_USER;
+ if (down) {
+ ITelephony telephonyService = getTelephonyService();
+ boolean hungUp = false;
+ if (telephonyService != null) {
+ try {
+ hungUp = telephonyService.endCall();
+ } catch (RemoteException ex) {
+ Log.w(TAG, "ITelephony threw RemoteException", ex);
+ }
+ }
+ interceptPowerKeyDown(!isScreenOn || hungUp);
+ } else {
+ if (interceptPowerKeyUp(canceled)) {
+ if ((mEndcallBehavior
+ & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
+ if (goHome()) {
+ break;
+ }
+ }
+ if ((mEndcallBehavior
+ & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
+ result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP;
+ }
+ }
+ }
+ break;
+ }
+
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_MUTE: {
@@ -2889,45 +2968,31 @@ public class PhoneWindowManager implements WindowManagerPolicy {
Log.w(TAG, "ITelephony threw RemoteException", ex);
}
}
-
- if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
- // If music is playing but we decided not to pass the key to the
- // application, handle the volume change here.
- handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
- break;
- }
}
- break;
- }
-
- case KeyEvent.KEYCODE_ENDCALL: {
- result &= ~ACTION_PASS_TO_USER;
- if (down) {
- ITelephony telephonyService = getTelephonyService();
- boolean hungUp = false;
- if (telephonyService != null) {
- try {
- hungUp = telephonyService.endCall();
- } catch (RemoteException ex) {
- Log.w(TAG, "ITelephony threw RemoteException", ex);
- }
- }
- interceptPowerKeyDown(!isScreenOn || hungUp);
- } else {
- if (interceptPowerKeyUp(canceled)) {
- if ((mEndcallBehavior
- & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
- if (goHome()) {
+ if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
+ if (mVolBtnMusicControls && down && (keyCode != KeyEvent.KEYCODE_VOLUME_MUTE)) {
+ mIsLongPress = false;
+ handleVolumeLongPress(keyCode);
+ break;
+ } else {
+ if (mVolBtnMusicControls && !down) {
+ handleVolumeLongPressAbort();
+ if (mIsLongPress) {
break;
}
}
- if ((mEndcallBehavior
- & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
- result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP;
+ if (!isScreenOn && !mVolumeWakeScreen) {
+ handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
}
}
}
- break;
+ if (isScreenOn || !mVolumeWakeScreen) {
+ break;
+ } else if (keyguardActive) {
+ keyCode = KeyEvent.KEYCODE_POWER;
+ mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode,
+ mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED);
+ }
}
case KeyEvent.KEYCODE_POWER: {