Package org.robolectric.shadows
Class ShadowVibrator
java.lang.Object
org.robolectric.shadows.ShadowVibrator
- Direct Known Subclasses:
ShadowSystemVibrator
@Implements(android.os.Vibrator.class) public class ShadowVibrator extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ShadowVibrator.PrimitiveEffect
A data class for exposingVibrationEffect.Composition$PrimitiveEffect
, which is a hidden non TestApi class introduced in Android R. -
Field Summary
Fields Modifier and Type Field Description protected static AudioAttributes
audioAttributesFromLastVibration
protected static long[]
pattern
protected static List<ShadowVibrator.PrimitiveEffect>
primitiveEffects
protected static List<Integer>
supportedPrimitives
protected static VibrationAttributes
vibrationAttributesFromLastVibration
protected static List<android.os.vibrator.VibrationEffectSegment>
vibrationEffectSegments
-
Constructor Summary
Constructors Constructor Description ShadowVibrator()
-
Method Summary
Modifier and Type Method Description protected boolean
areAllPrimitivesSupported(int... primitiveIds)
AudioAttributes
getAudioAttributesFromLastVibration()
Returns theAudioAttributes
from the last vibration.int
getEffectId()
Returns the last vibration effect ID of aVibrationEffect#Prebaked
(e.g.long
getMilliseconds()
Returns the last vibration duration in MS.long[]
getPattern()
Returns the last vibration pattern.List<ShadowVibrator.PrimitiveEffect>
getPrimitiveEffects()
Returns the last list ofShadowVibrator.PrimitiveEffect
.List<ShadowVibrator.PrimitiveEffect>
getPrimitiveSegmentsInPrimitiveEffects()
Returns the last list ofPrimitiveSegment
vibrations inShadowVibrator.PrimitiveEffect
.int
getRepeat()
Returns the last vibration repeat times.VibrationAttributes
getVibrationAttributesFromLastVibration()
Returns theVibrationAttributes
from the last vibration.List<android.os.vibrator.VibrationEffectSegment>
getVibrationEffectSegments()
Returns the last list ofVibrationEffectSegment
.boolean
isCancelled()
Returns true if the Vibrator has been cancelled.boolean
isVibrating()
Returns true if the Vibrator is currently vibrating as controlled byVibrator.vibrate(long)
static void
reset()
void
setHasAmplitudeControl(boolean hasAmplitudeControl)
Controls the return value ofVibrator.hasAmplitudeControl()
the default is false.void
setHasVibrator(boolean hasVibrator)
Controls the return value ofVibrator.hasVibrator()
the default is true.void
setSupportedPrimitives(Collection<Integer> primitives)
Adds supported vibration primitives.
-
Field Details
-
pattern
protected static long[] pattern -
vibrationEffectSegments
-
primitiveEffects
-
supportedPrimitives
-
vibrationAttributesFromLastVibration
-
audioAttributesFromLastVibration
-
-
Constructor Details
-
ShadowVibrator
public ShadowVibrator()
-
-
Method Details
-
setHasVibrator
public void setHasVibrator(boolean hasVibrator)Controls the return value ofVibrator.hasVibrator()
the default is true. -
setHasAmplitudeControl
public void setHasAmplitudeControl(boolean hasAmplitudeControl)Controls the return value ofVibrator.hasAmplitudeControl()
the default is false. -
isVibrating
Returns true if the Vibrator is currently vibrating as controlled byVibrator.vibrate(long)
-
isCancelled
public boolean isCancelled()Returns true if the Vibrator has been cancelled. -
getMilliseconds
public long getMilliseconds()Returns the last vibration duration in MS. -
getPattern
public long[] getPattern()Returns the last vibration pattern. -
getEffectId
public int getEffectId()Returns the last vibration effect ID of aVibrationEffect#Prebaked
(e.g.VibrationEffect.EFFECT_CLICK
).This field is non-zero only if a
VibrationEffect#Prebaked
was ever requested. -
getRepeat
public int getRepeat()Returns the last vibration repeat times. -
getVibrationEffectSegments
Returns the last list ofVibrationEffectSegment
. -
getPrimitiveSegmentsInPrimitiveEffects
Returns the last list ofPrimitiveSegment
vibrations inShadowVibrator.PrimitiveEffect
. -
getPrimitiveEffects
Returns the last list ofShadowVibrator.PrimitiveEffect
. -
areAllPrimitivesSupported
-
setSupportedPrimitives
Adds supported vibration primitives. -
getVibrationAttributesFromLastVibration
Returns theVibrationAttributes
from the last vibration. -
getAudioAttributesFromLastVibration
Returns theAudioAttributes
from the last vibration. -
reset
-