Class ShadowSpeechRecognizerImpl
Prior to Android V, SpeechRecognizer contained all functionality within one class. The ShadowSpeechRecognizer
shadow would work correctly to shadow both static and instance functions
of the class. With Android V, the instance of SpeechRecognizer
returned from SpeechRecognizer.createSpeechRecognizer(Context)
is an instance of SpeechRecognizerProxy
which delegates all calls to SpeechRecognizerImpl
. We need this shadow in order to intercept function calls
correctly and to ensure that the functionality of ShadowSpeechRecognizer
still works in
tests prior to Android V and on Android V+.
Customizations for this implementation:
- Intercept of all needed functions in SpeechRecognizerImpl
- Direct access to functions/variables in SpeechRecognizerImpl via
getDirectAccessors()
- Parent shadow class' state is used for state (no custom state)
-
Nested Class Summary
Nested classes/interfaces inherited from class org.robolectric.shadows.ShadowSpeechRecognizer
ShadowSpeechRecognizer.ShadowSpeechRecognizerDirectAccessors, ShadowSpeechRecognizer.ShadowSpeechRecognizerState
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkRecognitionSupport
(Intent recognizerIntent, Executor executor, Object supportListener) protected void
destroy()
Returns theShadowSpeechRecognizer.ShadowSpeechRecognizerDirectAccessors
implementation that can handle direct access to functions/variables of a realSpeechRecognizer
.protected void
handleChangeListener
(RecognitionListener listener) Handles changing the listener and allows access to the internal listener to trigger events.protected void
startListening
(Intent recognizerIntent) protected void
triggerModelDownload
(Intent recognizerIntent) Methods inherited from class org.robolectric.shadows.ShadowSpeechRecognizer
createOnDeviceSpeechRecognizer, createSpeechRecognizer, getLastRecognizerIntent, getLatestModelDownloadIntent, getLatestSpeechRecognizer, getState, isDestroyed, isOnDeviceRecognitionAvailable, reset, setIsOnDeviceRecognitionAvailable, triggerOnEndOfSpeech, triggerOnError, triggerOnPartialResults, triggerOnReadyForSpeech, triggerOnResults, triggerOnRmsChanged, triggerSupportError, triggerSupportResult
-
Field Details
-
CLASS_NAME
- See Also:
-
-
Constructor Details
-
ShadowSpeechRecognizerImpl
public ShadowSpeechRecognizerImpl()
-
-
Method Details
-
getDirectAccessors
Description copied from class:ShadowSpeechRecognizer
Returns theShadowSpeechRecognizer.ShadowSpeechRecognizerDirectAccessors
implementation that can handle direct access to functions/variables of a realSpeechRecognizer
.Subclasses may override this function to customize access in case they are shadowing a subclass of
SpeechRecognizer
that functions differently than the parent class.- Overrides:
getDirectAccessors
in classShadowSpeechRecognizer
-
destroy
- Overrides:
destroy
in classShadowSpeechRecognizer
-
startListening
- Overrides:
startListening
in classShadowSpeechRecognizer
-
handleChangeListener
Description copied from class:ShadowSpeechRecognizer
Handles changing the listener and allows access to the internal listener to trigger events.- Overrides:
handleChangeListener
in classShadowSpeechRecognizer
-
checkRecognitionSupport
@RequiresApi(api=33) @Implementation(minSdk=33) protected void checkRecognitionSupport(Intent recognizerIntent, Executor executor, Object supportListener) - Overrides:
checkRecognitionSupport
in classShadowSpeechRecognizer
-
triggerModelDownload
- Overrides:
triggerModelDownload
in classShadowSpeechRecognizer
-