diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-02-09 16:36:13 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-02-09 16:36:13 +0000 |
| commit | 4f07fa4e748c4f259a7ae9c06f89e44a9c69acff (patch) | |
| tree | 1b380c52228590276da54e5e0a33f2decdef8171 /core/java/android | |
| parent | 9eb34faac701c5f3890a84e7e12ecf253687e5ea (diff) | |
| parent | f268bf573f671fdc051bf4485dc0ea972406ea38 (diff) | |
Merge "Add support for vibrator HAL 1.2 effects."
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/os/VibrationEffect.java | 103 |
1 files changed, 96 insertions, 7 deletions
diff --git a/core/java/android/os/VibrationEffect.java b/core/java/android/os/VibrationEffect.java index b6f16a7b9ff8..e9b48535a34e 100644 --- a/core/java/android/os/VibrationEffect.java +++ b/core/java/android/os/VibrationEffect.java @@ -16,10 +16,15 @@ package android.os; -import android.hardware.vibrator.V1_0.Constants.EffectStrength; -import android.hardware.vibrator.V1_1.Constants.Effect_1_1; +import android.annotation.Nullable; +import android.content.Context; +import android.hardware.vibrator.V1_0.EffectStrength; +import android.hardware.vibrator.V1_2.Effect; +import android.net.Uri; import android.util.MathUtils; +import com.android.internal.annotations.VisibleForTesting; + import java.util.Arrays; /** @@ -49,7 +54,7 @@ public abstract class VibrationEffect implements Parcelable { * @see #get(int) * @hide */ - public static final int EFFECT_CLICK = Effect_1_1.CLICK; + public static final int EFFECT_CLICK = Effect.CLICK; /** * A double click effect. @@ -57,14 +62,62 @@ public abstract class VibrationEffect implements Parcelable { * @see #get(int) * @hide */ - public static final int EFFECT_DOUBLE_CLICK = Effect_1_1.DOUBLE_CLICK; + public static final int EFFECT_DOUBLE_CLICK = Effect.DOUBLE_CLICK; /** * A tick effect. * @see #get(int) * @hide */ - public static final int EFFECT_TICK = Effect_1_1.TICK; + public static final int EFFECT_TICK = Effect.TICK; + + /** + * A thud effect. + * @see #get(int) + * @hide + */ + public static final int EFFECT_THUD = Effect.THUD; + + /** + * A pop effect. + * @see #get(int) + * @hide + */ + public static final int EFFECT_POP = Effect.POP; + + /** + * A heavy click effect. + * @see #get(int) + * @hide + */ + public static final int EFFECT_HEAVY_CLICK = Effect.HEAVY_CLICK; + + + /** + * Ringtone patterns. They may correspond with the device's ringtone audio, or may just be a + * pattern that can be played as a ringtone with any audio, depending on the device. + * + * @see #get(Uri, Context) + * @hide + */ + @VisibleForTesting + public static final int[] RINGTONES = { + Effect.RINGTONE_1, + Effect.RINGTONE_2, + Effect.RINGTONE_3, + Effect.RINGTONE_4, + Effect.RINGTONE_5, + Effect.RINGTONE_6, + Effect.RINGTONE_7, + Effect.RINGTONE_8, + Effect.RINGTONE_9, + Effect.RINGTONE_10, + Effect.RINGTONE_11, + Effect.RINGTONE_12, + Effect.RINGTONE_13, + Effect.RINGTONE_14, + Effect.RINGTONE_15 + }; /** @hide to prevent subclassing from outside of the framework */ public VibrationEffect() { } @@ -198,6 +251,37 @@ public abstract class VibrationEffect implements Parcelable { return effect; } + /** + * Get a predefined vibration effect associated with a given URI. + * + * Predefined effects are a set of common vibration effects that should be identical, regardless + * of the app they come from, in order to provide a cohesive experience for users across + * the entire device. They also may be custom tailored to the device hardware in order to + * provide a better experience than you could otherwise build using the generic building + * blocks. + * + * @param uri The URI associated with the haptic effect. + * @param context The context used to get the URI to haptic effect association. + * + * @return The desired effect, or {@code null} if there's no associated effect. + * + * @hide + */ + @Nullable + public static VibrationEffect get(Uri uri, Context context) { + String[] uris = context.getResources().getStringArray( + com.android.internal.R.array.config_ringtoneEffectUris); + for (int i = 0; i < uris.length && i < RINGTONES.length; i++) { + if (uris[i] == null) { + continue; + } + if (Uri.parse(uris[i]).equals(uri)) { + return get(RINGTONES[i]); + } + } + return null; + } + @Override public int describeContents() { return 0; @@ -548,10 +632,15 @@ public abstract class VibrationEffect implements Parcelable { case EFFECT_CLICK: case EFFECT_DOUBLE_CLICK: case EFFECT_TICK: + case EFFECT_THUD: + case EFFECT_POP: + case EFFECT_HEAVY_CLICK: break; default: - throw new IllegalArgumentException( - "Unknown prebaked effect type (value=" + mEffectId + ")"); + if (mEffectId < RINGTONES[0] || mEffectId > RINGTONES[RINGTONES.length - 1]) { + throw new IllegalArgumentException( + "Unknown prebaked effect type (value=" + mEffectId + ")"); + } } if (!isValidEffectStrength(mEffectStrength)) { throw new IllegalArgumentException( |
