summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorPhilip Junker <philipjunker@google.com>2021-03-25 09:31:09 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2021-03-25 09:31:09 +0000
commit451405eb1744b07d6bbee73da4a16ff86d4104e4 (patch)
treea6f72c180c4f63e02534173ffd3cf5df72d58f24 /core/java/android
parent05dfc3d84932e4ab285470e5a19e83a5cda8211d (diff)
parentdfcb12b34c82876b31f6640a86e01cad9a989efe (diff)
Merge "Add IntDef for system sound effect constants" into sc-dev
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/view/SoundEffectConstants.java59
-rw-r--r--core/java/android/view/View.java4
-rw-r--r--core/java/android/view/ViewRootImpl.java2
3 files changed, 48 insertions, 17 deletions
diff --git a/core/java/android/view/SoundEffectConstants.java b/core/java/android/view/SoundEffectConstants.java
index f177451783dc..bd86a47f3918 100644
--- a/core/java/android/view/SoundEffectConstants.java
+++ b/core/java/android/view/SoundEffectConstants.java
@@ -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
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 7455b8bc3cf3..e573056ddbaa 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -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;
}
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index fdbec8b80361..0a246a68c56d 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -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 {