Merge "Add plumbing for volume mute key."

This commit is contained in:
Jeff Brown
2010-11-02 17:38:18 -07:00
committed by Android (Google) Code Review
15 changed files with 98 additions and 34 deletions

View File

@@ -196846,6 +196846,17 @@
visibility="public"
>
</field>
<field name="KEYCODE_VOLUME_MUTE"
type="int"
transient="false"
volatile="false"
value="164"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="KEYCODE_VOLUME_UP"
type="int"
transient="false"
@@ -245598,7 +245609,7 @@
deprecated="not deprecated"
visibility="public"
>
<parameter name="t" type="T">
<parameter name="arg0" type="T">
</parameter>
</method>
</interface>

View File

@@ -92,6 +92,11 @@ public class VolumePreference extends SeekBarPreference implements
mSeekBarVolumizer.changeVolumeBy(1);
}
return true;
case KeyEvent.KEYCODE_VOLUME_MUTE:
if (isdown) {
mSeekBarVolumizer.muteVolume();
}
return true;
default:
return false;
}
@@ -225,6 +230,7 @@ public class VolumePreference extends SeekBarPreference implements
private int mLastProgress = -1;
private SeekBar mSeekBar;
private int mVolumeBeforeMute = -1;
private ContentObserver mVolumeObserver = new ContentObserver(mHandler) {
@Override
@@ -336,6 +342,21 @@ public class VolumePreference extends SeekBarPreference implements
sample();
}
postSetVolume(mSeekBar.getProgress());
mVolumeBeforeMute = -1;
}
public void muteVolume() {
if (mVolumeBeforeMute != -1) {
mSeekBar.setProgress(mVolumeBeforeMute);
sample();
postSetVolume(mVolumeBeforeMute);
mVolumeBeforeMute = -1;
} else {
mVolumeBeforeMute = mSeekBar.getProgress();
mSeekBar.setProgress(0);
stopSample();
postSetVolume(0);
}
}
public void onSaveInstanceState(VolumeStore volumeStore) {

View File

@@ -125,9 +125,11 @@ public class KeyEvent extends InputEvent implements Parcelable {
/** Key code constant: Directional Pad Center key.
* May also be synthesized from trackball motions. */
public static final int KEYCODE_DPAD_CENTER = 23;
/** Key code constant: Volume Up key. */
/** Key code constant: Volume Up key.
* Adjusts the speaker volume up. */
public static final int KEYCODE_VOLUME_UP = 24;
/** Key code constant: Volume Down key. */
/** Key code constant: Volume Down key.
* Adjusts the speaker volume down. */
public static final int KEYCODE_VOLUME_DOWN = 25;
/** Key code constant: Power key. */
public static final int KEYCODE_POWER = 26;
@@ -269,7 +271,8 @@ public class KeyEvent extends InputEvent implements Parcelable {
public static final int KEYCODE_MEDIA_REWIND = 89;
/** Key code constant: Fast Forward media key. */
public static final int KEYCODE_MEDIA_FAST_FORWARD = 90;
/** Key code constant: Mute key. */
/** Key code constant: Mute key.
* Mutes the microphone, unlike {@link #KEYCODE_VOLUME_MUTE}. */
public static final int KEYCODE_MUTE = 91;
/** Key code constant: Page Up key. */
public static final int KEYCODE_PAGE_UP = 92;
@@ -455,8 +458,13 @@ public class KeyEvent extends InputEvent implements Parcelable {
public static final int KEYCODE_NUMPAD_LEFT_PAREN = 162;
/** Key code constant: Numeric keypad ')' key. */
public static final int KEYCODE_NUMPAD_RIGHT_PAREN = 163;
/** Key code constant: Volume Mute key.
* Mutes the speaker, unlike {@link #KEYCODE_MUTE}.
* This key should normally be implemented as a toggle such that the first press
* mutes the speaker and the second press restores the original volume. */
public static final int KEYCODE_VOLUME_MUTE = 164;
private static final int LAST_KEYCODE = KEYCODE_NUMPAD_RIGHT_PAREN;
private static final int LAST_KEYCODE = KEYCODE_VOLUME_MUTE;
// NOTE: If you add a new keycode here you must also add it to:
// isSystem()
@@ -640,6 +648,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
"KEYCODE_NUMPAD_EQUALS",
"KEYCODE_NUMPAD_LEFT_PAREN",
"KEYCODE_NUMPAD_RIGHT_PAREN",
"KEYCODE_VOLUME_MUTE",
};
// Symbolic names of all metakeys in bit order from least significant to most significant.

View File

@@ -442,7 +442,8 @@ public class MediaController extends FrameLayout {
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
|| keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|| keyCode == KeyEvent.KEYCODE_VOLUME_UP
|| keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
// don't show the controls for volume adjustment
return super.dispatchKeyEvent(event);
} else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) {

View File

@@ -515,6 +515,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK &&
keyCode != KeyEvent.KEYCODE_VOLUME_UP &&
keyCode != KeyEvent.KEYCODE_VOLUME_DOWN &&
keyCode != KeyEvent.KEYCODE_VOLUME_MUTE &&
keyCode != KeyEvent.KEYCODE_MENU &&
keyCode != KeyEvent.KEYCODE_CALL &&
keyCode != KeyEvent.KEYCODE_ENDCALL;

View File

@@ -1145,27 +1145,28 @@
<enum name="KEYCODE_F10" value="140" />
<enum name="KEYCODE_F11" value="141" />
<enum name="KEYCODE_F12" value="142" />
<enum name="NUM_LOCK" value="143" />
<enum name="NUMPAD_0" value="144" />
<enum name="NUMPAD_1" value="145" />
<enum name="NUMPAD_2" value="146" />
<enum name="NUMPAD_3" value="147" />
<enum name="NUMPAD_4" value="148" />
<enum name="NUMPAD_5" value="149" />
<enum name="NUMPAD_6" value="150" />
<enum name="NUMPAD_7" value="151" />
<enum name="NUMPAD_8" value="152" />
<enum name="NUMPAD_9" value="153" />
<enum name="NUMPAD_DIVIDE" value="154" />
<enum name="NUMPAD_MULTIPLY" value="155" />
<enum name="NUMPAD_SUBTRACT" value="156" />
<enum name="NUMPAD_ADD" value="157" />
<enum name="NUMPAD_DOT" value="158" />
<enum name="NUMPAD_COMMA" value="159" />
<enum name="NUMPAD_ENTER" value="160" />
<enum name="NUMPAD_EQUALS" value="161" />
<enum name="NUMPAD_LEFT_PAREN" value="162" />
<enum name="NUMPAD_RIGHT_PAREN" value="163" />
<enum name="KEYCODE_NUM_LOCK" value="143" />
<enum name="KEYCODE_NUMPAD_0" value="144" />
<enum name="KEYCODE_NUMPAD_1" value="145" />
<enum name="KEYCODE_NUMPAD_2" value="146" />
<enum name="KEYCODE_NUMPAD_3" value="147" />
<enum name="KEYCODE_NUMPAD_4" value="148" />
<enum name="KEYCODE_NUMPAD_5" value="149" />
<enum name="KEYCODE_NUMPAD_6" value="150" />
<enum name="KEYCODE_NUMPAD_7" value="151" />
<enum name="KEYCODE_NUMPAD_8" value="152" />
<enum name="KEYCODE_NUMPAD_9" value="153" />
<enum name="KEYCODE_NUMPAD_DIVIDE" value="154" />
<enum name="KEYCODE_NUMPAD_MULTIPLY" value="155" />
<enum name="KEYCODE_NUMPAD_SUBTRACT" value="156" />
<enum name="KEYCODE_NUMPAD_ADD" value="157" />
<enum name="KEYCODE_NUMPAD_DOT" value="158" />
<enum name="KEYCODE_NUMPAD_COMMA" value="159" />
<enum name="KEYCODE_NUMPAD_ENTER" value="160" />
<enum name="KEYCODE_NUMPAD_EQUALS" value="161" />
<enum name="KEYCODE_NUMPAD_LEFT_PAREN" value="162" />
<enum name="KEYCODE_NUMPAD_RIGHT_PAREN" value="163" />
<enum name="KEYCODE_VOLUME_MUTE" value="164" />
</attr>
<!-- ***************************************************************** -->

View File

@@ -132,7 +132,7 @@ key 109 PAGE_DOWN
key 110 INSERT
key 111 FORWARD_DEL
# key 112 "KEY_MACRO"
key 113 MUTE
key 113 VOLUME_MUTE
key 114 VOLUME_DOWN
key 115 VOLUME_UP
key 116 POWER WAKE

View File

@@ -83,9 +83,10 @@ key 103 DPAD_UP
key 105 DPAD_LEFT
key 106 DPAD_RIGHT
key 107 MOVE_END
key 108 DPAD_DOWN
key 110 INSERT
key 111 FORWARD_DEL
key 113 MUTE
key 113 VOLUME_MUTE
key 114 VOLUME_DOWN
key 115 VOLUME_UP
key 125 MENU

View File

@@ -188,6 +188,7 @@ static const KeycodeLabel KEYCODES[] = {
{ "NUMPAD_EQUALS", 161 },
{ "NUMPAD_LEFT_PAREN", 162 },
{ "NUMPAD_RIGHT_PAREN", 163 },
{ "VOLUME_MUTE", 164 },
// NOTE: If you add a new keycode here you must also add it to several other files.
// Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.

View File

@@ -33,6 +33,7 @@ bool KeyEvent::hasDefaultAction(int32_t keyCode) {
case AKEYCODE_ENDCALL:
case AKEYCODE_VOLUME_UP:
case AKEYCODE_VOLUME_DOWN:
case AKEYCODE_VOLUME_MUTE:
case AKEYCODE_POWER:
case AKEYCODE_CAMERA:
case AKEYCODE_HEADSETHOOK:
@@ -40,11 +41,14 @@ bool KeyEvent::hasDefaultAction(int32_t keyCode) {
case AKEYCODE_NOTIFICATION:
case AKEYCODE_FOCUS:
case AKEYCODE_SEARCH:
case AKEYCODE_MEDIA_PLAY:
case AKEYCODE_MEDIA_PAUSE:
case AKEYCODE_MEDIA_PLAY_PAUSE:
case AKEYCODE_MEDIA_STOP:
case AKEYCODE_MEDIA_NEXT:
case AKEYCODE_MEDIA_PREVIOUS:
case AKEYCODE_MEDIA_REWIND:
case AKEYCODE_MEDIA_RECORD:
case AKEYCODE_MEDIA_FAST_FORWARD:
case AKEYCODE_MUTE:
return true;
@@ -67,14 +71,18 @@ bool KeyEvent::isSystemKey(int32_t keyCode) {
case AKEYCODE_ENDCALL:
case AKEYCODE_VOLUME_UP:
case AKEYCODE_VOLUME_DOWN:
case AKEYCODE_VOLUME_MUTE:
case AKEYCODE_MUTE:
case AKEYCODE_POWER:
case AKEYCODE_HEADSETHOOK:
case AKEYCODE_MEDIA_PLAY:
case AKEYCODE_MEDIA_PAUSE:
case AKEYCODE_MEDIA_PLAY_PAUSE:
case AKEYCODE_MEDIA_STOP:
case AKEYCODE_MEDIA_NEXT:
case AKEYCODE_MEDIA_PREVIOUS:
case AKEYCODE_MEDIA_REWIND:
case AKEYCODE_MEDIA_RECORD:
case AKEYCODE_MEDIA_FAST_FORWARD:
case AKEYCODE_CAMERA:
case AKEYCODE_FOCUS:

View File

@@ -207,7 +207,7 @@ enum {
AKEYCODE_NUMPAD_EQUALS = 161,
AKEYCODE_NUMPAD_LEFT_PAREN = 162,
AKEYCODE_NUMPAD_RIGHT_PAREN = 163,
AKEYCODE_VOLUME_MUTE = 164,
// NOTE: If you add a new keycode here you must also add it to several other files.
// Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.

View File

@@ -170,7 +170,8 @@ public abstract class KeyguardViewBase extends FrameLayout {
}
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN: {
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_MUTE: {
synchronized (this) {
if (mAudioManager == null) {
mAudioManager = (AudioManager) getContext().getSystemService(
@@ -179,6 +180,7 @@ public abstract class KeyguardViewBase extends FrameLayout {
}
// Volume buttons should only function for music.
if (mAudioManager.isMusicActive()) {
// TODO: Actually handle MUTE.
mAudioManager.adjustStreamVolume(
AudioManager.STREAM_MUSIC,
keyCode == KeyEvent.KEYCODE_VOLUME_UP

View File

@@ -786,6 +786,7 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_MUTE:
case KeyEvent.KEYCODE_MUTE:
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MEDIA_PLAY:

View File

@@ -1230,7 +1230,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN: {
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_MUTE: {
AudioManager audioManager = (AudioManager) getContext().getSystemService(
Context.AUDIO_SERVICE);
if (audioManager != null) {
@@ -1238,6 +1239,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
* Adjust the volume in on key down since it is more
* responsive to the user.
*/
// TODO: Actually handle MUTE.
audioManager.adjustSuggestedStreamVolume(
keyCode == KeyEvent.KEYCODE_VOLUME_UP
? AudioManager.ADJUST_RAISE
@@ -1405,7 +1407,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN: {
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_MUTE: {
if (!event.isCanceled()) {
AudioManager audioManager = (AudioManager) getContext().getSystemService(
Context.AUDIO_SERVICE);
@@ -1414,6 +1417,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
* 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.
*/
// TODO: Actually handle MUTE.
audioManager.adjustSuggestedStreamVolume(
AudioManager.ADJUST_SAME,
mVolumeControlStreamType,
@@ -1720,6 +1724,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
* 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()) {
/*

View File

@@ -1877,6 +1877,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// since audio is playing, we shouldn't have to hold a wake lock
// during the call, but we do it as a precaution for the rare possibility
// that the music stops right before we call this
// TODO: Actually handle MUTE.
mBroadcastWakeLock.acquire();
audioService.adjustStreamVolume(stream,
keycode == KeyEvent.KEYCODE_VOLUME_UP
@@ -1949,7 +1950,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// Handle special keys.
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_UP: {
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_MUTE: {
if (down) {
ITelephony telephonyService = getTelephonyService();
if (telephonyService != null) {