Skip to content

Commit

Permalink
UI: Display token code when animations are disabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
justin-stephenson committed Jan 5, 2023
1 parent e4fd3bb commit 135a7c0
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions mobile/src/main/java/org/fedorahosted/freeotp/main/ViewHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,6 +54,7 @@ interface EventListener {

private EventListener mEventListener;
private ObjectAnimator mCountdown;
private Handler mHandler;

private ProgressBar mProgress;
private ImageButton mShare;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 135a7c0

Please sign in to comment.