From 135a7c0a4946991e0b8939029240c898731d08e5 Mon Sep 17 00:00:00 2001 From: Justin Stephenson Date: Fri, 16 Dec 2022 12:39:14 -0500 Subject: [PATCH] UI: Display token code when animations are disabled When animation options(Window/Transition/Animator scale) are disabled in device settings, onAnimationEnd() is called immediately after onAnimationStart() causing the token code to never display properly. This change sets up a handler to fade out the code when the time ends, instead of relying on the onAnimationEnd() animation callback. --- .../fedorahosted/freeotp/main/ViewHolder.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/mobile/src/main/java/org/fedorahosted/freeotp/main/ViewHolder.java b/mobile/src/main/java/org/fedorahosted/freeotp/main/ViewHolder.java index 0444121d..a8894625 100644 --- a/mobile/src/main/java/org/fedorahosted/freeotp/main/ViewHolder.java +++ b/mobile/src/main/java/org/fedorahosted/freeotp/main/ViewHolder.java @@ -23,6 +23,7 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; +import android.os.Handler; import android.util.Log; import android.view.View; import android.view.ViewGroup; @@ -53,6 +54,7 @@ interface EventListener { private EventListener mEventListener; private ObjectAnimator mCountdown; + private Handler mHandler; private ProgressBar mProgress; private ImageButton mShare; @@ -152,20 +154,34 @@ private void displayCode(Code code, Token.Type type, int animationDuration) { mCountdown.cancel(); mCode.setText(text); + Long timeLeft; if (type == Token.Type.HOTP) { - mCountdown.setDuration(code.timeLeft()); + timeLeft = code.timeLeft(); + mCountdown.setDuration(timeLeft); } else { - mCountdown.setDuration(code.timeRemaining() * 1000); + timeLeft = code.timeRemaining() * 1000; + mCountdown.setDuration(timeLeft); } + + mHandler.removeCallbacksAndMessages(null); + mHandler.postDelayed(() -> fadeOut(), timeLeft); + mCountdown.setIntValues(code.getProgress(mProgress.getMax()), 0); mCountdown.start(); } + void fadeOut() { + /* Fade out */ + fade(mPassive, true, 500); + fade(mActive, false, 500); + + } ViewHolder(View itemView, EventListener listener) { super(itemView); mEventListener = listener; mCountdown = new ObjectAnimator(); + mHandler = new Handler(); mProgress = itemView.findViewById(R.id.progress_linear); mPassive = itemView.findViewById(R.id.passive); mActive = itemView.findViewById(R.id.active); @@ -200,14 +216,6 @@ public void onAnimationStart(Animator animation) { fade(mPassive, false, 500); fade(mActive, true, 500); } - - @Override - public void onAnimationEnd(Animator animation) { - Log.i(LOGTAG, String.format("onAnimationEnd: fade")); - /* Fade out */ - fade(mPassive, true, 500); - fade(mActive, false, 500); - } }); mIcons.setOnClickListener(mSelectClick);