summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorJoe Onorato <joeo@google.com>2010-11-08 10:59:27 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-11-08 10:59:27 -0800
commit51387974f0914a12dcf758938bbd4ffe120bdab4 (patch)
treef7faf54592578cf034731b4f2bdd79d45a7a7e62 /media
parentbc4119a390754505327fd2b51187d69353b239f1 (diff)
parent86f6786032b1a0380cf089aeeceef7e9d8982ef8 (diff)
downloadframeworks_base-51387974f0914a12dcf758938bbd4ffe120bdab4.zip
frameworks_base-51387974f0914a12dcf758938bbd4ffe120bdab4.tar.gz
frameworks_base-51387974f0914a12dcf758938bbd4ffe120bdab4.tar.bz2
Merge "Move the volume, media, call, camera and search key handling from PhoneWindow to a new PhoneFallbackEventHandler class that is used for all windows, not just ones with decors."
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/AudioManager.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index b23dcde..b84a2c2 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -27,10 +27,12 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
+import android.os.SystemClock;
import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.KeyEvent;
+import android.view.VolumePanel;
import java.util.Iterator;
import java.util.HashMap;
@@ -45,6 +47,7 @@ public class AudioManager {
private final Context mContext;
private final Handler mHandler;
+ private long mVolumeKeyUpTime;
private static String TAG = "AudioManager";
private static boolean DEBUG = false;
@@ -358,6 +361,71 @@ public class AudioManager {
}
/**
+ * @hide
+ */
+ public void preDispatchKeyEvent(int keyCode, int stream) {
+ /*
+ * If the user hits another key within the play sound delay, then
+ * cancel the sound
+ */
+ if (keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_UP
+ && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
+ && mVolumeKeyUpTime + VolumePanel.PLAY_SOUND_DELAY
+ > SystemClock.uptimeMillis()) {
+ /*
+ * The user has hit another key during the delay (e.g., 300ms)
+ * since the last volume key up, so cancel any sounds.
+ */
+ adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME,
+ stream, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
+ }
+ }
+
+ /**
+ * @hide
+ */
+ public void handleKeyDown(int keyCode, int stream) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_VOLUME_UP:
+ case KeyEvent.KEYCODE_VOLUME_DOWN:
+ /*
+ * Adjust the volume in on key down since it is more
+ * responsive to the user.
+ */
+ adjustSuggestedStreamVolume(
+ keyCode == KeyEvent.KEYCODE_VOLUME_UP
+ ? AudioManager.ADJUST_RAISE
+ : AudioManager.ADJUST_LOWER,
+ stream,
+ AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE);
+ break;
+ case KeyEvent.KEYCODE_VOLUME_MUTE:
+ // TODO: Actually handle MUTE.
+ break;
+ }
+ }
+
+ /**
+ * @hide
+ */
+ public void handleKeyUp(int keyCode, int stream) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_VOLUME_UP:
+ case KeyEvent.KEYCODE_VOLUME_DOWN:
+ /*
+ * Play a sound. This is done on key up since we don't want the
+ * sound to play when a user holds down volume down to mute.
+ */
+ adjustSuggestedStreamVolume(ADJUST_SAME, stream, FLAG_PLAY_SOUND);
+ mVolumeKeyUpTime = SystemClock.uptimeMillis();
+ break;
+ case KeyEvent.KEYCODE_VOLUME_MUTE:
+ // TODO: Actually handle MUTE.
+ break;
+ }
+ }
+
+ /**
* Adjusts the volume of a particular stream by one step in a direction.
* <p>
* This method should only be used by applications that replace the platform-wide