enc-backup: use ValueAnimator rather than ObjectAnimator for compatibility

This commit is contained in:
Vincent Breitmoser
2015-09-25 03:59:13 +02:00
parent 35ef837286
commit 7e175ac673

View File

@@ -25,12 +25,11 @@ import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.Random; import java.util.Random;
import android.animation.ObjectAnimator; import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@@ -45,7 +44,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
@@ -63,7 +61,6 @@ public class BackupCodeEntryFragment extends Fragment implements OnBackStackChan
private ExportHelper mExportHelper; private ExportHelper mExportHelper;
private EditText[] mCodeEditText; private EditText[] mCodeEditText;
private TextView[] mCodeDisplayText;
private ViewAnimator mStatusAnimator, mTitleAnimator, mCodeFieldsAnimator; private ViewAnimator mStatusAnimator, mTitleAnimator, mCodeFieldsAnimator;
private int mBackStackLevel; private int mBackStackLevel;
@@ -127,9 +124,7 @@ public class BackupCodeEntryFragment extends Fragment implements OnBackStackChan
// we know all fields are filled, so if it's not the *right* one it's a *wrong* one! // we know all fields are filled, so if it's not the *right* one it's a *wrong* one!
@ColorInt int black = mCodeEditText[0].getCurrentTextColor(); @ColorInt int black = mCodeEditText[0].getCurrentTextColor();
@ColorInt int red = getResources().getColor(R.color.android_red_dark); @ColorInt int red = getResources().getColor(R.color.android_red_dark);
for (EditText editText : mCodeEditText) { animateFlashText(mCodeEditText, black, red, false);
animateFlashText(editText, black, red, false);
}
break; break;
} }
@@ -144,8 +139,8 @@ public class BackupCodeEntryFragment extends Fragment implements OnBackStackChan
@ColorInt int green = getResources().getColor(R.color.android_green_dark); @ColorInt int green = getResources().getColor(R.color.android_green_dark);
for (EditText editText : mCodeEditText) { for (EditText editText : mCodeEditText) {
editText.setEnabled(false); editText.setEnabled(false);
animateFlashText(editText, black, green, true);
} }
animateFlashText(mCodeEditText, black, green, true);
popFromBackStackNoAction(); popFromBackStackNoAction();
@@ -170,21 +165,21 @@ public class BackupCodeEntryFragment extends Fragment implements OnBackStackChan
mCodeEditText[2] = (EditText) view.findViewById(R.id.backup_code_3); mCodeEditText[2] = (EditText) view.findViewById(R.id.backup_code_3);
mCodeEditText[3] = (EditText) view.findViewById(R.id.backup_code_4); mCodeEditText[3] = (EditText) view.findViewById(R.id.backup_code_4);
mCodeDisplayText = new TextView[4]; {
mCodeDisplayText[0] = (TextView) view.findViewById(R.id.backup_code_display_1); TextView[] codeDisplayText = new TextView[4];
mCodeDisplayText[1] = (TextView) view.findViewById(R.id.backup_code_display_2); codeDisplayText[0] = (TextView) view.findViewById(R.id.backup_code_display_1);
mCodeDisplayText[2] = (TextView) view.findViewById(R.id.backup_code_display_3); codeDisplayText[1] = (TextView) view.findViewById(R.id.backup_code_display_2);
mCodeDisplayText[3] = (TextView) view.findViewById(R.id.backup_code_display_4); codeDisplayText[2] = (TextView) view.findViewById(R.id.backup_code_display_3);
codeDisplayText[3] = (TextView) view.findViewById(R.id.backup_code_display_4);
{ // set backup code in code TextViews // set backup code in code TextViews
char[] backupCode = mBackupCode.toCharArray(); char[] backupCode = mBackupCode.toCharArray();
for (int i = 0; i < mCodeDisplayText.length; i++) { for (int i = 0; i < codeDisplayText.length; i++) {
mCodeDisplayText[i].setText(backupCode, i * 7, 6); codeDisplayText[i].setText(backupCode, i * 7, 6);
} }
}
{ // set background to null in TextViews - this will retain padding from EditText style! // set background to null in TextViews - this will retain padding from EditText style!
for (TextView textView : mCodeDisplayText) { for (TextView textView : codeDisplayText) {
// noinspection deprecation, setBackground(Drawable) is API level >=16 // noinspection deprecation, setBackground(Drawable) is API level >=16
textView.setBackgroundDrawable(null); textView.setBackgroundDrawable(null);
} }
@@ -287,21 +282,22 @@ public class BackupCodeEntryFragment extends Fragment implements OnBackStackChan
} }
private void animateFlashText(EditText editText, int color1, int color2, boolean staySecondColor) { private void animateFlashText(final TextView[] textViews, int color1, int color2, boolean staySecondColor) {
ObjectAnimator anim; ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), color1, color2);
if (staySecondColor) { anim.addUpdateListener(new AnimatorUpdateListener() {
anim = ObjectAnimator.ofArgb(editText, "textColor", @Override
color1, color2, color1, color2, color1, color2); public void onAnimationUpdate(ValueAnimator animator) {
} else { for (TextView textView : textViews) {
anim = ObjectAnimator.ofArgb(editText, "textColor", textView.setTextColor((Integer) animator.getAnimatedValue());
color1, color2, color1, color2, color1); }
} }
});
anim.setDuration(1000); anim.setRepeatMode(ValueAnimator.REVERSE);
anim.setStartDelay(200); anim.setRepeatCount(staySecondColor ? 4 : 5);
anim.setInterpolator(new LinearInterpolator()); anim.setDuration(180);
anim.start(); anim.start();
} }
private void setupEditTextFocusNext(final EditText[] backupCodes) { private void setupEditTextFocusNext(final EditText[] backupCodes) {