Move TEXT_HANDLE_MOVE and CLOCK_TICK to TEXTURE_TICK.

TEXTURE_TICK is a new constant that is expected to be called repeatedly
in order to simulate a texture effect when a user is interacting with
the device, like with TEXT_HANDLE_MOVE.

Bug: 111461797
Test: Manual
Change-Id: Ia21de3ce1755a908b4bd4fcbdda411864e5b9fe9
This commit is contained in:
Michael Wright
2019-03-21 21:26:05 +00:00
parent d7104fce90
commit 950bd77fb7
3 changed files with 23 additions and 5 deletions

View File

@@ -23,7 +23,7 @@ import android.annotation.TestApi;
import android.content.ContentResolver;
import android.content.Context;
import android.hardware.vibrator.V1_0.EffectStrength;
import android.hardware.vibrator.V1_2.Effect;
import android.hardware.vibrator.V1_3.Effect;
import android.net.Uri;
import android.util.MathUtils;
@@ -94,6 +94,18 @@ public abstract class VibrationEffect implements Parcelable {
*/
public static final int EFFECT_HEAVY_CLICK = Effect.HEAVY_CLICK;
/**
* A texture effect meant to replicate soft ticks.
*
* Unlike normal effects, texture effects are meant to be called repeatedly, generally in
* response to some motion, in order to replicate the feeling of some texture underneath the
* user's fingers.
*
* @see #get(int)
* @hide
*/
public static final int EFFECT_TEXTURE_TICK = Effect.TEXTURE_TICK;
/** {@hide} */
@TestApi
public static final int EFFECT_STRENGTH_LIGHT = EffectStrength.LIGHT;
@@ -746,6 +758,7 @@ public abstract class VibrationEffect implements Parcelable {
case EFFECT_CLICK:
case EFFECT_DOUBLE_CLICK:
case EFFECT_TICK:
case EFFECT_TEXTURE_TICK:
case EFFECT_THUD:
case EFFECT_POP:
case EFFECT_HEAVY_CLICK:
@@ -798,7 +811,7 @@ public abstract class VibrationEffect implements Parcelable {
out.writeInt(mEffectStrength);
}
public static final @android.annotation.NonNull Parcelable.Creator<Prebaked> CREATOR =
public static final @NonNull Parcelable.Creator<Prebaked> CREATOR =
new Parcelable.Creator<Prebaked>() {
@Override
public Prebaked createFromParcel(Parcel in) {
@@ -813,7 +826,7 @@ public abstract class VibrationEffect implements Parcelable {
};
}
public static final @android.annotation.NonNull Parcelable.Creator<VibrationEffect> CREATOR =
public static final @NonNull Parcelable.Creator<VibrationEffect> CREATOR =
new Parcelable.Creator<VibrationEffect>() {
@Override
public VibrationEffect createFromParcel(Parcel in) {

View File

@@ -5214,13 +5214,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
private VibrationEffect getVibrationEffect(int effectId) {
long[] pattern;
switch (effectId) {
case HapticFeedbackConstants.CLOCK_TICK:
case HapticFeedbackConstants.CONTEXT_CLICK:
return VibrationEffect.get(VibrationEffect.EFFECT_TICK);
case HapticFeedbackConstants.TEXT_HANDLE_MOVE:
if (!mHapticTextHandleEnabled) {
return null;
}
// fallthrough
case HapticFeedbackConstants.CLOCK_TICK:
return VibrationEffect.get(VibrationEffect.EFFECT_TEXTURE_TICK);
case HapticFeedbackConstants.KEYBOARD_RELEASE:
case HapticFeedbackConstants.VIRTUAL_KEY_RELEASE:
case HapticFeedbackConstants.ENTRY_BUMP:

View File

@@ -96,7 +96,7 @@ bool isValidEffect(jlong effect) {
}
R val = static_cast<R>(effect);
auto iter = hardware::hidl_enum_range<R>();
return val >= *iter.begin() && val < *std::prev(iter.end());
return val >= *iter.begin() && val <= *std::prev(iter.end());
}
static void vibratorInit(JNIEnv /* env */, jobject /* clazz */)
@@ -170,6 +170,9 @@ static jlong vibratorPerformEffect(JNIEnv*, jobject, jlong effect, jint strength
} else if (isValidEffect<V1_2::Effect>(effect)) {
ret = halCall(&V1_2::IVibrator::perform_1_2, static_cast<V1_2::Effect>(effect),
effectStrength, callback);
} else if (isValidEffect<V1_3::Effect>(effect)) {
ret = halCall(&V1_3::IVibrator::perform_1_3, static_cast<V1_3::Effect>(effect),
effectStrength, callback);
} else {
ALOGW("Unable to perform haptic effect, invalid effect ID (%" PRId32 ")",
static_cast<int32_t>(effect));