return new OneShot(mDuration, newAmplitude);
}
+ /**
+ * Resolve default values into integer amplitude numbers.
+ *
+ * @param defaultAmplitude the default amplitude to apply, must be between 0 and
+ * MAX_AMPLITUDE
+ * @return A {@link OneShot} effect with same physical meaning but explicitly set amplitude
+ *
+ * @hide
+ */
+ public OneShot resolve(int defaultAmplitude) {
+ if (defaultAmplitude > MAX_AMPLITUDE || defaultAmplitude < 0) {
+ throw new IllegalArgumentException(
+ "Amplitude is negative or greater than MAX_AMPLITUDE");
+ }
+ if (mAmplitude == DEFAULT_AMPLITUDE) {
+ return new OneShot(mDuration, defaultAmplitude);
+ }
+ return this;
+ }
+
@Override
public void validate() {
if (mAmplitude < -1 || mAmplitude == 0 || mAmplitude > 255) {
return new Waveform(mTimings, scaledAmplitudes, mRepeat);
}
+ /**
+ * Resolve default values into integer amplitude numbers.
+ *
+ * @param defaultAmplitude the default amplitude to apply, must be between 0 and
+ * MAX_AMPLITUDE
+ * @return A {@link Waveform} effect with same physical meaning but explicitly set
+ * amplitude
+ *
+ * @hide
+ */
+ public Waveform resolve(int defaultAmplitude) {
+ if (defaultAmplitude > MAX_AMPLITUDE || defaultAmplitude < 0) {
+ throw new IllegalArgumentException(
+ "Amplitude is negative or greater than MAX_AMPLITUDE");
+ }
+ int[] resolvedAmplitudes = Arrays.copyOf(mAmplitudes, mAmplitudes.length);
+ for (int i = 0; i < resolvedAmplitudes.length; i++) {
+ if (resolvedAmplitudes[i] == DEFAULT_AMPLITUDE) {
+ resolvedAmplitudes[i] = defaultAmplitude;
+ }
+ }
+ return new Waveform(mTimings, resolvedAmplitudes, mRepeat);
+ }
+
@Override
public void validate() {
if (mTimings.length != mAmplitudes.length) {
VibrationEffect scaledEffect = null;
if (vib.effect instanceof VibrationEffect.OneShot) {
VibrationEffect.OneShot oneShot = (VibrationEffect.OneShot) vib.effect;
+ oneShot = oneShot.resolve(mDefaultVibrationAmplitude);
scaledEffect = oneShot.scale(gamma, maxAmplitude);
} else if (vib.effect instanceof VibrationEffect.Waveform) {
VibrationEffect.Waveform waveform = (VibrationEffect.Waveform) vib.effect;
+ waveform = waveform.resolve(mDefaultVibrationAmplitude);
scaledEffect = waveform.scale(gamma, maxAmplitude);
} else {
Slog.w(TAG, "Unable to apply intensity scaling, unknown VibrationEffect type");