Merge "Add IntDef for system sound effect constants" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
451405eb17
@@ -16,11 +16,14 @@
|
||||
|
||||
package android.view;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.media.AudioManager;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.annotations.VisibleForTesting.Visibility;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
@@ -34,25 +37,55 @@ public class SoundEffectConstants {
|
||||
|
||||
public static final int CLICK = 0;
|
||||
|
||||
/** Effect id for a navigation left */
|
||||
public static final int NAVIGATION_LEFT = 1;
|
||||
/** Effect id for a navigation up */
|
||||
public static final int NAVIGATION_UP = 2;
|
||||
/** Effect id for a navigation right */
|
||||
public static final int NAVIGATION_RIGHT = 3;
|
||||
/** Effect id for a navigation down */
|
||||
public static final int NAVIGATION_DOWN = 4;
|
||||
/** Sound effect for a repeatedly triggered navigation, e.g. due to long pressing a button */
|
||||
/** Effect id for a repeatedly triggered navigation left, e.g. due to long pressing a button */
|
||||
public static final int NAVIGATION_REPEAT_LEFT = 5;
|
||||
/** @see #NAVIGATION_REPEAT_LEFT */
|
||||
/** Effect id for a repeatedly triggered navigation up, e.g. due to long pressing a button */
|
||||
public static final int NAVIGATION_REPEAT_UP = 6;
|
||||
/** @see #NAVIGATION_REPEAT_LEFT */
|
||||
/** Effect id for a repeatedly triggered navigation right, e.g. due to long pressing a button */
|
||||
public static final int NAVIGATION_REPEAT_RIGHT = 7;
|
||||
/** @see #NAVIGATION_REPEAT_LEFT */
|
||||
/** Effect id for a repeatedly triggered navigation down, e.g. due to long pressing a button */
|
||||
public static final int NAVIGATION_REPEAT_DOWN = 8;
|
||||
|
||||
/** @hide */
|
||||
@IntDef(value = {
|
||||
CLICK,
|
||||
NAVIGATION_LEFT,
|
||||
NAVIGATION_UP,
|
||||
NAVIGATION_RIGHT,
|
||||
NAVIGATION_DOWN,
|
||||
NAVIGATION_REPEAT_LEFT,
|
||||
NAVIGATION_REPEAT_UP,
|
||||
NAVIGATION_REPEAT_RIGHT,
|
||||
NAVIGATION_REPEAT_DOWN
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface SoundEffect {}
|
||||
|
||||
/** @hide */
|
||||
@IntDef(prefix = { "NAVIGATION_" }, value = {
|
||||
NAVIGATION_LEFT,
|
||||
NAVIGATION_UP,
|
||||
NAVIGATION_RIGHT,
|
||||
NAVIGATION_DOWN,
|
||||
NAVIGATION_REPEAT_LEFT,
|
||||
NAVIGATION_REPEAT_UP,
|
||||
NAVIGATION_REPEAT_RIGHT,
|
||||
NAVIGATION_REPEAT_DOWN
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface NavigationSoundEffect {}
|
||||
|
||||
/**
|
||||
* Get the sonification constant for the focus directions.
|
||||
* @param direction One of {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN},
|
||||
* {@link View#FOCUS_LEFT}, {@link View#FOCUS_RIGHT}, {@link View#FOCUS_FORWARD}
|
||||
* or {@link View#FOCUS_BACKWARD}
|
||||
|
||||
* @param direction The direction of the focus.
|
||||
* @return The appropriate sonification constant.
|
||||
* @throws {@link IllegalArgumentException} when the passed direction is not one of the
|
||||
* documented values.
|
||||
@@ -76,16 +109,14 @@ public class SoundEffectConstants {
|
||||
|
||||
/**
|
||||
* Get the sonification constant for the focus directions
|
||||
* @param direction One of {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN},
|
||||
* {@link View#FOCUS_LEFT}, {@link View#FOCUS_RIGHT}, {@link View#FOCUS_FORWARD}
|
||||
* or {@link View#FOCUS_BACKWARD}
|
||||
* @param direction The direction of the focus.
|
||||
* @param repeating True if the user long-presses a direction
|
||||
* @return The appropriate sonification constant
|
||||
* @throws IllegalArgumentException when the passed direction is not one of the
|
||||
* documented values.
|
||||
*/
|
||||
public static int getConstantForFocusDirection(@View.FocusDirection int direction,
|
||||
boolean repeating) {
|
||||
public static @NavigationSoundEffect int getConstantForFocusDirection(
|
||||
@View.FocusDirection int direction, boolean repeating) {
|
||||
if (repeating) {
|
||||
switch (direction) {
|
||||
case View.FOCUS_RIGHT:
|
||||
@@ -112,7 +143,7 @@ public class SoundEffectConstants {
|
||||
* @hide
|
||||
*/
|
||||
@VisibleForTesting(visibility = Visibility.PACKAGE)
|
||||
public static boolean isNavigationRepeat(int effectId) {
|
||||
public static boolean isNavigationRepeat(@NavigationSoundEffect int effectId) {
|
||||
return effectId == SoundEffectConstants.NAVIGATION_REPEAT_DOWN
|
||||
|| effectId == SoundEffectConstants.NAVIGATION_REPEAT_LEFT
|
||||
|| effectId == SoundEffectConstants.NAVIGATION_REPEAT_RIGHT
|
||||
|
||||
@@ -26136,9 +26136,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
* <p>The sound effect will only be played if sound effects are enabled by the user, and
|
||||
* {@link #isSoundEffectsEnabled()} is true.
|
||||
*
|
||||
* @param soundConstant One of the constants defined in {@link SoundEffectConstants}
|
||||
* @param soundConstant One of the constants defined in {@link SoundEffectConstants}.
|
||||
*/
|
||||
public void playSoundEffect(int soundConstant) {
|
||||
public void playSoundEffect(@SoundEffectConstants.SoundEffect int soundConstant) {
|
||||
if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7754,7 +7754,7 @@ public final class ViewRootImpl implements ViewParent,
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void playSoundEffect(int effectId) {
|
||||
public void playSoundEffect(@SoundEffectConstants.SoundEffect int effectId) {
|
||||
checkThread();
|
||||
|
||||
try {
|
||||
|
||||
@@ -3221,6 +3221,23 @@ public class AudioManager {
|
||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
|
||||
public static final int NUM_SOUND_EFFECTS = 16;
|
||||
|
||||
/** @hide */
|
||||
@IntDef(prefix = { "FX_" }, value = {
|
||||
FX_KEY_CLICK,
|
||||
FX_FOCUS_NAVIGATION_UP,
|
||||
FX_FOCUS_NAVIGATION_DOWN,
|
||||
FX_FOCUS_NAVIGATION_LEFT,
|
||||
FX_FOCUS_NAVIGATION_RIGHT,
|
||||
FX_KEYPRESS_STANDARD,
|
||||
FX_KEYPRESS_SPACEBAR,
|
||||
FX_KEYPRESS_DELETE,
|
||||
FX_KEYPRESS_RETURN,
|
||||
FX_KEYPRESS_INVALID,
|
||||
FX_BACK
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface SystemSoundEffect {}
|
||||
|
||||
/**
|
||||
* @hide Number of FX_FOCUS_NAVIGATION_REPEAT_* sound effects
|
||||
*/
|
||||
@@ -3296,22 +3313,11 @@ public class AudioManager {
|
||||
|
||||
/**
|
||||
* Plays a sound effect (Key clicks, lid open/close...)
|
||||
* @param effectType The type of sound effect. One of
|
||||
* {@link #FX_KEY_CLICK},
|
||||
* {@link #FX_FOCUS_NAVIGATION_UP},
|
||||
* {@link #FX_FOCUS_NAVIGATION_DOWN},
|
||||
* {@link #FX_FOCUS_NAVIGATION_LEFT},
|
||||
* {@link #FX_FOCUS_NAVIGATION_RIGHT},
|
||||
* {@link #FX_KEYPRESS_STANDARD},
|
||||
* {@link #FX_KEYPRESS_SPACEBAR},
|
||||
* {@link #FX_KEYPRESS_DELETE},
|
||||
* {@link #FX_KEYPRESS_RETURN},
|
||||
* {@link #FX_KEYPRESS_INVALID},
|
||||
* {@link #FX_BACK},
|
||||
* @param effectType The type of sound effect.
|
||||
* NOTE: This version uses the UI settings to determine
|
||||
* whether sounds are heard or not.
|
||||
*/
|
||||
public void playSoundEffect(int effectType) {
|
||||
public void playSoundEffect(@SystemSoundEffect int effectType) {
|
||||
if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) {
|
||||
return;
|
||||
}
|
||||
@@ -3330,24 +3336,13 @@ public class AudioManager {
|
||||
|
||||
/**
|
||||
* Plays a sound effect (Key clicks, lid open/close...)
|
||||
* @param effectType The type of sound effect. One of
|
||||
* {@link #FX_KEY_CLICK},
|
||||
* {@link #FX_FOCUS_NAVIGATION_UP},
|
||||
* {@link #FX_FOCUS_NAVIGATION_DOWN},
|
||||
* {@link #FX_FOCUS_NAVIGATION_LEFT},
|
||||
* {@link #FX_FOCUS_NAVIGATION_RIGHT},
|
||||
* {@link #FX_KEYPRESS_STANDARD},
|
||||
* {@link #FX_KEYPRESS_SPACEBAR},
|
||||
* {@link #FX_KEYPRESS_DELETE},
|
||||
* {@link #FX_KEYPRESS_RETURN},
|
||||
* {@link #FX_KEYPRESS_INVALID},
|
||||
* {@link #FX_BACK},
|
||||
* @param effectType The type of sound effect.
|
||||
* @param userId The current user to pull sound settings from
|
||||
* NOTE: This version uses the UI settings to determine
|
||||
* whether sounds are heard or not.
|
||||
* @hide
|
||||
*/
|
||||
public void playSoundEffect(int effectType, int userId) {
|
||||
public void playSoundEffect(@SystemSoundEffect int effectType, int userId) {
|
||||
if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) {
|
||||
return;
|
||||
}
|
||||
@@ -3366,25 +3361,14 @@ public class AudioManager {
|
||||
|
||||
/**
|
||||
* Plays a sound effect (Key clicks, lid open/close...)
|
||||
* @param effectType The type of sound effect. One of
|
||||
* {@link #FX_KEY_CLICK},
|
||||
* {@link #FX_FOCUS_NAVIGATION_UP},
|
||||
* {@link #FX_FOCUS_NAVIGATION_DOWN},
|
||||
* {@link #FX_FOCUS_NAVIGATION_LEFT},
|
||||
* {@link #FX_FOCUS_NAVIGATION_RIGHT},
|
||||
* {@link #FX_KEYPRESS_STANDARD},
|
||||
* {@link #FX_KEYPRESS_SPACEBAR},
|
||||
* {@link #FX_KEYPRESS_DELETE},
|
||||
* {@link #FX_KEYPRESS_RETURN},
|
||||
* {@link #FX_KEYPRESS_INVALID},
|
||||
* {@link #FX_BACK},
|
||||
* @param effectType The type of sound effect.
|
||||
* @param volume Sound effect volume.
|
||||
* The volume value is a raw scalar so UI controls should be scaled logarithmically.
|
||||
* If a volume of -1 is specified, the AudioManager.STREAM_MUSIC stream volume minus 3dB will be used.
|
||||
* NOTE: This version is for applications that have their own
|
||||
* settings panel for enabling and controlling volume.
|
||||
*/
|
||||
public void playSoundEffect(int effectType, float volume) {
|
||||
public void playSoundEffect(@SystemSoundEffect int effectType, float volume) {
|
||||
if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user