9595import de .cotech .hw .fido .FidoSecurityKeyConnectionMode ;
9696import de .cotech .hw .fido .R ;
9797import de .cotech .hw .fido .exceptions .FidoWrongKeyHandleException ;
98+ import de .cotech .hw .fido .internal .AnimatedVectorDrawableHelper ;
9899import de .cotech .hw .util .NfcStatusObserver ;
99100import de .cotech .sweetspot .NfcSweetspotData ;
100101import timber .log .Timber ;
@@ -234,12 +235,14 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
234235 coordinator = bottomSheetDialog .findViewById (com .google .android .material .R .id .coordinator );
235236 bottomSheet = bottomSheetDialog .findViewById (com .google .android .material .R .id .design_bottom_sheet );
236237
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" );
242240 }
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 );
243246 });
244247
245248 return dialog ;
@@ -302,11 +305,6 @@ private void initTimeout(long timeoutSeconds) {
302305 final Handler handler = new Handler ();
303306 handler .postDelayed (() -> {
304307 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- }
310308
311309 textError .setText (R .string .hwsecurity_error_timeout );
312310 gotoState (State .ERROR );
@@ -315,6 +313,12 @@ private void initTimeout(long timeoutSeconds) {
315313 return ;
316314 }
317315 dismiss ();
316+
317+ if (fidoAuthenticateRequest != null ) {
318+ fidoAuthenticateCallback .onFidoAuthenticateTimeout (fidoAuthenticateRequest );
319+ } else if (fidoRegisterRequest != null ) {
320+ fidoRegisterCallback .onFidoRegisterTimeout (fidoRegisterRequest );
321+ }
318322 }, TIME_DELAYED_STATE_CHANGE );
319323 }, timeoutSeconds * 1000 );
320324 }
@@ -630,14 +634,7 @@ public void onAnimationEnd(Drawable drawable) {
630634 }
631635 };
632636
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 );
641638 }
642639
643640 private void fadeToNfcSweetSpot () {
@@ -713,7 +710,7 @@ private void showNfcSweetSpot() {
713710 textError .setVisibility (View .GONE );
714711 });
715712
716- startAndLoopAnimation (sweetspotIndicator , R .drawable .nfc_sweet_spot_a );
713+ AnimatedVectorDrawableHelper . startAndLoopAnimation (getActivity (), sweetspotIndicator , R .drawable .nfc_sweet_spot_a );
717714 }
718715
719716 private void animateSelectUsb () {
@@ -726,7 +723,7 @@ public void onTransitionStart(@NonNull Transition transition) {
726723
727724 @ Override
728725 public void onTransitionEnd (@ NonNull Transition transition ) {
729- startAndLoopAnimation (imageUsb , R .drawable .usb_handling_a );
726+ AnimatedVectorDrawableHelper . startAndLoopAnimation (getActivity (), imageUsb , R .drawable .usb_handling_a );
730727 }
731728
732729 @ Override
@@ -764,7 +761,7 @@ public void onTransitionStart(@NonNull Transition transition) {
764761
765762 @ Override
766763 public void onTransitionEnd (@ NonNull Transition transition ) {
767- startAndLoopAnimation (imageUsb , R .drawable .usb_handling_b );
764+ AnimatedVectorDrawableHelper . startAndLoopAnimation (getActivity (), imageUsb , R .drawable .usb_handling_b );
768765 }
769766
770767 @ Override
@@ -795,7 +792,7 @@ public void onTransitionResume(@NonNull Transition transition) {
795792 private void animateUsbPressButton () {
796793 TransitionManager .beginDelayedTransition (innerBottomSheet );
797794 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 );
799796 }
800797
801798 private void animateError () {
@@ -813,59 +810,7 @@ private void animateError() {
813810 textError .setVisibility (View .VISIBLE );
814811 imageError .setVisibility (View .VISIBLE );
815812
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 );
869814 }
870815
871816 @ UiThread
0 commit comments