diff --git a/app/src/main/java/eu/faircode/email/FragmentAccounts.java b/app/src/main/java/eu/faircode/email/FragmentAccounts.java index 160d267996..de0e685c9f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccounts.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccounts.java @@ -22,7 +22,6 @@ package eu.faircode.email; import static androidx.recyclerview.widget.RecyclerView.NO_POSITION; import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -46,7 +45,6 @@ import androidx.appcompat.widget.PopupMenu; import androidx.constraintlayout.widget.Group; import androidx.core.view.MenuCompat; import androidx.fragment.app.FragmentTransaction; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Observer; import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.DividerItemDecoration; @@ -276,18 +274,7 @@ public class FragmentAccounts extends FragmentBase { } }); - animator = ObjectAnimator.ofFloat(fab, "alpha", 0.5f, 1.0f); - animator.setDuration(750L); - animator.setRepeatCount(ValueAnimator.INFINITE); - animator.setRepeatMode(ValueAnimator.REVERSE); - animator.addUpdateListener(new ObjectAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) - return; - fab.setAlpha((float) animation.getAnimatedValue()); - } - }); + animator = Helper.getFabAnimator(fab, this); // Initialize FragmentDialogTheme.setBackground(getContext(), view, false); diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentities.java b/app/src/main/java/eu/faircode/email/FragmentIdentities.java index 3b1a81f4a7..7162af8bb5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentities.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentities.java @@ -22,7 +22,6 @@ package eu.faircode.email; import static androidx.recyclerview.widget.RecyclerView.NO_POSITION; import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; import android.content.Context; import android.content.SharedPreferences; import android.graphics.Canvas; @@ -37,7 +36,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.Group; import androidx.fragment.app.FragmentTransaction; -import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Observer; import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.DividerItemDecoration; @@ -176,18 +174,7 @@ public class FragmentIdentities extends FragmentBase { } }); - animator = ObjectAnimator.ofFloat(fab, "alpha", 0.5f, 1.0f); - animator.setDuration(750L); - animator.setRepeatCount(ValueAnimator.INFINITE); - animator.setRepeatMode(ValueAnimator.REVERSE); - animator.addUpdateListener(new ObjectAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) - return; - fab.setAlpha((float) animation.getAnimatedValue()); - } - }); + animator = Helper.getFabAnimator(fab, this); // Initialize FragmentDialogTheme.setBackground(getContext(), view, false); diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 07186ccc39..2bd96ad198 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -23,6 +23,8 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND; import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION; import android.Manifest; +import android.animation.ObjectAnimator; +import android.animation.ValueAnimator; import android.app.Activity; import android.app.ActivityManager; import android.app.KeyguardManager; @@ -631,6 +633,22 @@ public class Helper { return context.getResources().getDimensionPixelSize(resid); } + static ObjectAnimator getFabAnimator(View fab, LifecycleOwner owner) { + ObjectAnimator animator = ObjectAnimator.ofFloat(fab, "alpha", 0.5f, 1.0f); + animator.setDuration(750L); + animator.setRepeatCount(ValueAnimator.INFINITE); + animator.setRepeatMode(ValueAnimator.REVERSE); + animator.addUpdateListener(new ObjectAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + if (!owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) + return; + fab.setAlpha((float) animation.getAnimatedValue()); + } + }); + return animator; + } + static Intent getChooser(Context context, Intent intent) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { PackageManager pm = context.getPackageManager();