6
6
import android .content .Context ;
7
7
import android .content .pm .PackageManager ;
8
8
import android .content .res .Configuration ;
9
+ import android .graphics .drawable .AnimatedVectorDrawable ;
9
10
import android .graphics .drawable .ClipDrawable ;
10
11
import android .graphics .drawable .Drawable ;
11
12
import android .graphics .drawable .LayerDrawable ;
12
13
import android .os .Bundle ;
14
+ import android .os .Handler ;
15
+ import android .os .Looper ;
13
16
import android .util .AttributeSet ;
14
17
import android .util .Log ;
15
18
import android .view .Gravity ;
16
19
import android .view .LayoutInflater ;
17
- import android .view .animation .Animation ;
18
- import android .view .animation .LinearInterpolator ;
19
- import android .view .animation .RotateAnimation ;
20
20
21
21
import androidx .core .app .ActivityCompat ;
22
22
import androidx .databinding .DataBindingUtil ;
@@ -61,7 +61,7 @@ public interface VoiceSearchDelegate {
61
61
private MozillaSpeechService mMozillaSpeechService ;
62
62
private VoiceSearchDelegate mDelegate ;
63
63
private ClipDrawable mVoiceInputClipDrawable ;
64
- private RotateAnimation mSearchingAnimation ;
64
+ private AnimatedVectorDrawable mSearchingAnimation ;
65
65
private boolean mIsSpeechRecognitionRunning = false ;
66
66
private boolean mWasSpeechRecognitionRunning = false ;
67
67
@@ -81,6 +81,9 @@ public VoiceSearchWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) {
81
81
}
82
82
83
83
private void initialize (Context aContext ) {
84
+ // AnimatedVectorDrawable doesn't work with a Hardware Accelerated canvas, we disable it for this view.
85
+ setIsHardwareAccelerationEnabled (false );
86
+
84
87
updateUI ();
85
88
86
89
mWidgetManager .addPermissionListener (this );
@@ -89,13 +92,7 @@ private void initialize(Context aContext) {
89
92
mMozillaSpeechService .setGeckoWebExecutor (EngineProvider .INSTANCE .createGeckoWebExecutor (getContext ()));
90
93
mMozillaSpeechService .setProductTag (getContext ().getString (R .string .voice_app_id ));
91
94
92
- mSearchingAnimation = new RotateAnimation (0 , 360f ,
93
- Animation .RELATIVE_TO_SELF , 0.5f ,
94
- Animation .RELATIVE_TO_SELF , 0.5f );
95
-
96
- mSearchingAnimation .setInterpolator (new LinearInterpolator ());
97
- mSearchingAnimation .setDuration (ANIMATION_DURATION );
98
- mSearchingAnimation .setRepeatCount (Animation .INFINITE );
95
+ mSearchingAnimation = (AnimatedVectorDrawable ) mBinding .voiceSearchAnimationSearching .getDrawable ();
99
96
100
97
mMozillaSpeechService .addListener (mVoiceSearchListener );
101
98
((Application )aContext .getApplicationContext ()).registerActivityLifecycleCallbacks (this );
@@ -297,11 +294,9 @@ public void show(@ShowFlags int aShowFlags) {
297
294
if (index == PromptDialogWidget .POSITIVE ) {
298
295
SettingsStore .getInstance (getContext ()).setSpeechDataCollectionEnabled (true );
299
296
}
300
- post (() -> show (aShowFlags ));
297
+ new Handler ( Looper . getMainLooper ()). post (() -> show (aShowFlags ));
301
298
},
302
- () -> {
303
- mWidgetManager .openNewTabForeground (getResources ().getString (R .string .private_policy_url ));
304
- });
299
+ () -> mWidgetManager .openNewTabForeground (getResources ().getString (R .string .private_policy_url )));
305
300
}
306
301
}
307
302
@@ -315,13 +310,13 @@ public void hide(@HideFlags int aHideFlags) {
315
310
316
311
private void setStartListeningState () {
317
312
mBinding .setState (State .LISTENING );
318
- mBinding . voiceSearchAnimationSearching . clearAnimation ();
313
+ mSearchingAnimation . stop ();
319
314
mBinding .executePendingBindings ();
320
315
}
321
316
322
317
private void setDecodingState () {
323
318
mBinding .setState (State .SEARCHING );
324
- mBinding . voiceSearchAnimationSearching . startAnimation ( mSearchingAnimation );
319
+ mSearchingAnimation . start ( );
325
320
mBinding .executePendingBindings ();
326
321
}
327
322
@@ -330,7 +325,7 @@ private void setResultState() {
330
325
331
326
postDelayed (() -> {
332
327
mBinding .setState (State .ERROR );
333
- mBinding . voiceSearchAnimationSearching . clearAnimation ();
328
+ mSearchingAnimation . stop ();
334
329
mBinding .executePendingBindings ();
335
330
336
331
startVoiceSearch ();
@@ -339,7 +334,7 @@ private void setResultState() {
339
334
340
335
private void setPermissionNotGranted () {
341
336
mBinding .setState (State .PERMISSIONS );
342
- mBinding . voiceSearchAnimationSearching . clearAnimation ();
337
+ mSearchingAnimation . stop ();
343
338
mBinding .executePendingBindings ();
344
339
}
345
340
0 commit comments