Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c2879ba authored by Philip Junker's avatar Philip Junker Committed by Automerger Merge Worker
Browse files

Merge "Add IntDef for system sound effect constants" into sc-dev am: 451405eb

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13901314

Change-Id: I7ae738845095fda803ea78155e7dea70ec5343e9
parents 328c0f98 451405eb
Loading
Loading
Loading
Loading
+45 −14
Original line number Original line Diff line number Diff line
@@ -16,11 +16,14 @@


package android.view;
package android.view;


import android.annotation.IntDef;
import android.media.AudioManager;
import android.media.AudioManager;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting.Visibility;
import com.android.internal.annotations.VisibleForTesting.Visibility;


import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Random;
import java.util.Random;


/**
/**
@@ -34,25 +37,55 @@ public class SoundEffectConstants {


    public static final int CLICK = 0;
    public static final int CLICK = 0;


    /** Effect id for a navigation left */
    public static final int NAVIGATION_LEFT = 1;
    public static final int NAVIGATION_LEFT = 1;
    /** Effect id for a navigation up */
    public static final int NAVIGATION_UP = 2;
    public static final int NAVIGATION_UP = 2;
    /** Effect id for a navigation right */
    public static final int NAVIGATION_RIGHT = 3;
    public static final int NAVIGATION_RIGHT = 3;
    /** Effect id for a navigation down */
    public static final int NAVIGATION_DOWN = 4;
    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;
    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;
    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;
    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;
    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.
     * Get the sonification constant for the focus directions.
     * @param direction One of {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN},
     * @param direction The direction of the focus.
     *     {@link View#FOCUS_LEFT}, {@link View#FOCUS_RIGHT}, {@link View#FOCUS_FORWARD}
     *     or {@link View#FOCUS_BACKWARD}

     * @return The appropriate sonification constant.
     * @return The appropriate sonification constant.
     * @throws {@link IllegalArgumentException} when the passed direction is not one of the
     * @throws {@link IllegalArgumentException} when the passed direction is not one of the
     *     documented values.
     *     documented values.
@@ -76,16 +109,14 @@ public class SoundEffectConstants {


    /**
    /**
     * Get the sonification constant for the focus directions
     * Get the sonification constant for the focus directions
     * @param direction One of {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN},
     * @param direction The direction of the focus.
     *     {@link View#FOCUS_LEFT}, {@link View#FOCUS_RIGHT}, {@link View#FOCUS_FORWARD}
     *     or {@link View#FOCUS_BACKWARD}
     * @param repeating True if the user long-presses a direction
     * @param repeating True if the user long-presses a direction
     * @return The appropriate sonification constant
     * @return The appropriate sonification constant
     * @throws IllegalArgumentException when the passed direction is not one of the
     * @throws IllegalArgumentException when the passed direction is not one of the
     *      documented values.
     *      documented values.
     */
     */
    public static int getConstantForFocusDirection(@View.FocusDirection int direction,
    public static @NavigationSoundEffect int getConstantForFocusDirection(
            boolean repeating) {
            @View.FocusDirection int direction, boolean repeating) {
        if (repeating) {
        if (repeating) {
            switch (direction) {
            switch (direction) {
                case View.FOCUS_RIGHT:
                case View.FOCUS_RIGHT:
@@ -112,7 +143,7 @@ public class SoundEffectConstants {
     * @hide
     * @hide
     */
     */
    @VisibleForTesting(visibility = Visibility.PACKAGE)
    @VisibleForTesting(visibility = Visibility.PACKAGE)
    public static boolean isNavigationRepeat(int effectId) {
    public static boolean isNavigationRepeat(@NavigationSoundEffect int effectId) {
        return effectId == SoundEffectConstants.NAVIGATION_REPEAT_DOWN
        return effectId == SoundEffectConstants.NAVIGATION_REPEAT_DOWN
                || effectId == SoundEffectConstants.NAVIGATION_REPEAT_LEFT
                || effectId == SoundEffectConstants.NAVIGATION_REPEAT_LEFT
                || effectId == SoundEffectConstants.NAVIGATION_REPEAT_RIGHT
                || effectId == SoundEffectConstants.NAVIGATION_REPEAT_RIGHT
+2 −2
Original line number Original line Diff line number Diff line
@@ -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
     * <p>The sound effect will only be played if sound effects are enabled by the user, and
     * {@link #isSoundEffectsEnabled()} is true.
     * {@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()) {
        if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) {
            return;
            return;
        }
        }
+1 −1
Original line number Original line Diff line number Diff line
@@ -7754,7 +7754,7 @@ public final class ViewRootImpl implements ViewParent,
     * {@inheritDoc}
     * {@inheritDoc}
     */
     */
    @Override
    @Override
    public void playSoundEffect(int effectId) {
    public void playSoundEffect(@SoundEffectConstants.SoundEffect int effectId) {
        checkThread();
        checkThread();


        try {
        try {
+23 −39
Original line number Original line Diff line number Diff line
@@ -3221,6 +3221,23 @@ public class AudioManager {
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public static final int NUM_SOUND_EFFECTS = 16;
    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
     * @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...)
     * Plays a sound effect (Key clicks, lid open/close...)
     * @param effectType The type of sound effect. One of
     * @param effectType The type of sound effect.
     *            {@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},
     * NOTE: This version uses the UI settings to determine
     * NOTE: This version uses the UI settings to determine
     * whether sounds are heard or not.
     * whether sounds are heard or not.
     */
     */
    public void playSoundEffect(int effectType) {
    public void playSoundEffect(@SystemSoundEffect int effectType) {
        if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) {
        if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) {
            return;
            return;
        }
        }
@@ -3330,24 +3336,13 @@ public class AudioManager {


    /**
    /**
     * Plays a sound effect (Key clicks, lid open/close...)
     * Plays a sound effect (Key clicks, lid open/close...)
     * @param effectType The type of sound effect. One of
     * @param effectType The type of sound effect.
     *            {@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 userId The current user to pull sound settings from
     * @param userId The current user to pull sound settings from
     * NOTE: This version uses the UI settings to determine
     * NOTE: This version uses the UI settings to determine
     * whether sounds are heard or not.
     * whether sounds are heard or not.
     * @hide
     * @hide
     */
     */
    public void  playSoundEffect(int effectType, int userId) {
    public void  playSoundEffect(@SystemSoundEffect int effectType, int userId) {
        if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) {
        if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) {
            return;
            return;
        }
        }
@@ -3366,25 +3361,14 @@ public class AudioManager {


    /**
    /**
     * Plays a sound effect (Key clicks, lid open/close...)
     * Plays a sound effect (Key clicks, lid open/close...)
     * @param effectType The type of sound effect. One of
     * @param effectType The type of sound effect.
     *            {@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 volume Sound effect volume.
     * @param volume Sound effect volume.
     * The volume value is a raw scalar so UI controls should be scaled logarithmically.
     * 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.
     * 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
     * NOTE: This version is for applications that have their own
     * settings panel for enabling and controlling volume.
     * 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) {
        if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) {
            return;
            return;
        }
        }