Fix the Animator duration scale bug

This commit is contained in:
Jakob Nixdorf 2017-07-03 15:45:32 +02:00
parent fe9a39b808
commit 1ecd0f81c1
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
2 changed files with 55 additions and 1 deletions

View file

@ -29,11 +29,14 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
@ -60,6 +63,7 @@ import com.google.zxing.integration.android.IntentIntegrator;
import org.shadowice.flocke.andotp.ItemTouchHelper.SimpleItemTouchHelperCallback;
import java.lang.reflect.Method;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
@ -243,6 +247,40 @@ public class MainActivity extends AppCompatActivity {
.show();
}
// Try to fix the animation scale
private float fixAnimationScale() {
float durationScale = Settings.Global.getFloat(this.getContentResolver(), Settings.Global.ANIMATOR_DURATION_SCALE, 0);
if (durationScale != 1) {
try {
Class c = Class.forName("android.animation.ValueAnimator");
Method m = c.getMethod("setDurationScale", new Class[]{float.class});
m.invoke(null, new Object[]{ 1f });
durationScale = 1f;
} catch (Throwable t) {
t.printStackTrace();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!prefs.getBoolean(getString(R.string.pref_animator_warning_displayed), false)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.title_animator_duration)
.setMessage(R.string.msg_animator_duration_scale)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {}
})
.create()
.show();
prefs.edit().putBoolean(getString(R.string.pref_animator_warning_displayed), true).apply();
}
}
}
return durationScale;
}
// Initialize the main application
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -278,6 +316,9 @@ public class MainActivity extends AppCompatActivity {
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
touchHelper.attachToRecyclerView(recList);
final float durationScale = fixAnimationScale();
final long animatorDuration = (long) (1000 / durationScale);
adapter.setMoveEventCallback(new EntriesCardAdapter.ViewHolderEventCallback() {
@Override
public void onMoveEventStart() {
@ -304,7 +345,7 @@ public class MainActivity extends AppCompatActivity {
progressBar.setProgress(progress*100);
ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", (progress-1)*100);
animation.setDuration(1000);
animation.setDuration(animatorDuration);
animation.setInterpolator(new LinearInterpolator());
animation.start();

View file

@ -14,6 +14,15 @@
<string name="menu_import">Import (JSON)</string>
<string name="menu_submenu_backup">Import / Export</string>
<string name="msg_animator_duration_scale">Your devices <b>Animator duration scale</b> seems to
be set to something other than the default (<i>1.0x</i>), which will result in a not very
smooth animation of the countdown bar.
\n\nandOTP tried to apply an automatic fix to itself, but something went wrong with that.
Now it will try to compensate manually during the animation. In the case that does not work
you can either live with the jumpy countdown bar or change your devices <b>Animator duration
scale</b> in the <b>Developer options</b>.
\n\n<b>This message will not be shown again!</b>
</string>
<string name="msg_camera_permission">Camera permission not granted</string>
<string name="msg_confirm_delete">Are you sure you want do remove this account?</string>
<string name="msg_export_success">Export to external storage successful</string>
@ -29,6 +38,10 @@
<string name="msg_storage_not_accessible">External storage currently not accessible</string>
<string name="msg_storage_permissions">Storage permissions not granted</string>
<string name="title_animator_duration">Animator duration scale</string>
<string name="pref_animator_warning_displayed">animator_warning_displayed</string>
<!-- About dialog -->
<string name="about_description">
An open-source two-factor authentication App for Android 4.4+.