95
95
import de .cotech .hw .fido .FidoSecurityKeyConnectionMode ;
96
96
import de .cotech .hw .fido .R ;
97
97
import de .cotech .hw .fido .exceptions .FidoWrongKeyHandleException ;
98
+ import de .cotech .hw .fido .internal .AnimatedVectorDrawableHelper ;
98
99
import de .cotech .hw .util .NfcStatusObserver ;
99
100
import de .cotech .sweetspot .NfcSweetspotData ;
100
101
import timber .log .Timber ;
@@ -234,12 +235,14 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
234
235
coordinator = bottomSheetDialog .findViewById (com .google .android .material .R .id .coordinator );
235
236
bottomSheet = bottomSheetDialog .findViewById (com .google .android .material .R .id .design_bottom_sheet );
236
237
237
- // never just "peek", always fully expand the bottom sheet
238
- if (bottomSheet != null ) {
239
- BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior .from (bottomSheet );
240
- bottomSheetBehavior .setSkipCollapsed (true );
241
- bottomSheetBehavior .setState (BottomSheetBehavior .STATE_EXPANDED );
238
+ if (bottomSheet == null ) {
239
+ throw new IllegalStateException ("bottomSheet is null" );
242
240
}
241
+
242
+ // never just "peek", always fully expand the bottom sheet
243
+ BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior .from (bottomSheet );
244
+ bottomSheetBehavior .setSkipCollapsed (true );
245
+ bottomSheetBehavior .setState (BottomSheetBehavior .STATE_EXPANDED );
243
246
});
244
247
245
248
return dialog ;
@@ -302,11 +305,6 @@ private void initTimeout(long timeoutSeconds) {
302
305
final Handler handler = new Handler ();
303
306
handler .postDelayed (() -> {
304
307
Timber .d ("Timeout after %s seconds." , timeoutSeconds );
305
- if (fidoAuthenticateRequest != null ) {
306
- fidoAuthenticateCallback .onFidoAuthenticateTimeout (fidoAuthenticateRequest );
307
- } else if (fidoRegisterRequest != null ) {
308
- fidoRegisterCallback .onFidoRegisterTimeout (fidoRegisterRequest );
309
- }
310
308
311
309
textError .setText (R .string .hwsecurity_error_timeout );
312
310
gotoState (State .ERROR );
@@ -315,6 +313,12 @@ private void initTimeout(long timeoutSeconds) {
315
313
return ;
316
314
}
317
315
dismiss ();
316
+
317
+ if (fidoAuthenticateRequest != null ) {
318
+ fidoAuthenticateCallback .onFidoAuthenticateTimeout (fidoAuthenticateRequest );
319
+ } else if (fidoRegisterRequest != null ) {
320
+ fidoRegisterCallback .onFidoRegisterTimeout (fidoRegisterRequest );
321
+ }
318
322
}, TIME_DELAYED_STATE_CHANGE );
319
323
}, timeoutSeconds * 1000 );
320
324
}
@@ -630,14 +634,7 @@ public void onAnimationEnd(Drawable drawable) {
630
634
}
631
635
};
632
636
633
- if (Build .VERSION .SDK_INT <= 24 ) {
634
- AnimatedVectorDrawableCompat avdCompat = setAndStartAnimatedVectorDrawableSdk24 (imageNfcFullscreen , R .drawable .nfc_handling );
635
- avdCompat .registerAnimationCallback (animationCallback );
636
- } else {
637
- AnimatedVectorDrawableCompat .registerAnimationCallback (imageNfcFullscreen .getDrawable (), animationCallback );
638
- Animatable animatable = (Animatable ) imageNfcFullscreen .getDrawable ();
639
- animatable .start ();
640
- }
637
+ AnimatedVectorDrawableHelper .startAnimation (getActivity (), imageNfcFullscreen , R .drawable .nfc_handling , animationCallback );
641
638
}
642
639
643
640
private void fadeToNfcSweetSpot () {
@@ -713,7 +710,7 @@ private void showNfcSweetSpot() {
713
710
textError .setVisibility (View .GONE );
714
711
});
715
712
716
- startAndLoopAnimation (sweetspotIndicator , R .drawable .nfc_sweet_spot_a );
713
+ AnimatedVectorDrawableHelper . startAndLoopAnimation (getActivity (), sweetspotIndicator , R .drawable .nfc_sweet_spot_a );
717
714
}
718
715
719
716
private void animateSelectUsb () {
@@ -726,7 +723,7 @@ public void onTransitionStart(@NonNull Transition transition) {
726
723
727
724
@ Override
728
725
public void onTransitionEnd (@ NonNull Transition transition ) {
729
- startAndLoopAnimation (imageUsb , R .drawable .usb_handling_a );
726
+ AnimatedVectorDrawableHelper . startAndLoopAnimation (getActivity (), imageUsb , R .drawable .usb_handling_a );
730
727
}
731
728
732
729
@ Override
@@ -764,7 +761,7 @@ public void onTransitionStart(@NonNull Transition transition) {
764
761
765
762
@ Override
766
763
public void onTransitionEnd (@ NonNull Transition transition ) {
767
- startAndLoopAnimation (imageUsb , R .drawable .usb_handling_b );
764
+ AnimatedVectorDrawableHelper . startAndLoopAnimation (getActivity (), imageUsb , R .drawable .usb_handling_b );
768
765
}
769
766
770
767
@ Override
@@ -795,7 +792,7 @@ public void onTransitionResume(@NonNull Transition transition) {
795
792
private void animateUsbPressButton () {
796
793
TransitionManager .beginDelayedTransition (innerBottomSheet );
797
794
textTitle .setText (R .string .hwsecurity_title_usb_button );
798
- startAndLoopAnimation (imageUsb , R .drawable .usb_handling_b );
795
+ AnimatedVectorDrawableHelper . startAndLoopAnimation (getActivity (), imageUsb , R .drawable .usb_handling_b );
799
796
}
800
797
801
798
private void animateError () {
@@ -813,59 +810,7 @@ private void animateError() {
813
810
textError .setVisibility (View .VISIBLE );
814
811
imageError .setVisibility (View .VISIBLE );
815
812
816
- if (Build .VERSION .SDK_INT <= 24 ) {
817
- setAndStartAnimatedVectorDrawableSdk24 (imageError , R .drawable .error );
818
- } else {
819
- Animatable animatable = (Animatable ) imageError .getDrawable ();
820
- animatable .start ();
821
- }
822
- }
823
-
824
- private void startAndLoopAnimation (ImageView imageView , int resId ) {
825
- Animatable2Compat .AnimationCallback animationCallback = new Animatable2Compat .AnimationCallback () {
826
- @ NonNull
827
- private final Handler fHandler = new Handler (Looper .getMainLooper ());
828
-
829
- @ Override
830
- public void onAnimationEnd (@ NonNull Drawable drawable ) {
831
- if (!ViewCompat .isAttachedToWindow (imageView )) {
832
- return ;
833
- }
834
-
835
- fHandler .post (() -> {
836
- if (Build .VERSION .SDK_INT <= 24 ) {
837
- AnimatedVectorDrawableCompat avdCompat = setAndStartAnimatedVectorDrawableSdk24 (imageView , resId );
838
- avdCompat .registerAnimationCallback (this );
839
- } else {
840
- ((Animatable ) drawable ).start ();
841
- }
842
- });
843
- }
844
- };
845
-
846
- if (Build .VERSION .SDK_INT <= 24 ) {
847
- AnimatedVectorDrawableCompat avdCompat = setAndStartAnimatedVectorDrawableSdk24 (imageView , resId );
848
- avdCompat .registerAnimationCallback (animationCallback );
849
- } else {
850
- imageView .setImageResource (resId );
851
- AnimatedVectorDrawableCompat .registerAnimationCallback (imageView .getDrawable (), animationCallback );
852
- Animatable animatable = (Animatable ) imageView .getDrawable ();
853
- animatable .start ();
854
- }
855
- }
856
-
857
- private AnimatedVectorDrawableCompat setAndStartAnimatedVectorDrawableSdk24 (ImageView imageView , int resId ) {
858
- AnimatedVectorDrawableCompat avdCompat = AnimatedVectorDrawableCompat .create (getContext (), resId );
859
-
860
- // on SDK <= 24, the alphaFill values are not resetted properly to their initial state
861
- // The states of AnimatedVectorDrawables are stored centrally per resource.
862
- // Thus, making the drawable mutate allows it to have a completely new state
863
- avdCompat .mutate ();
864
-
865
- imageView .setImageDrawable (avdCompat );
866
- avdCompat .start ();
867
-
868
- return avdCompat ;
813
+ AnimatedVectorDrawableHelper .startAnimation (getActivity (), imageError , R .drawable .error );
869
814
}
870
815
871
816
@ UiThread
0 commit comments