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

@@ -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;