Skip to content

Commit

Permalink
Respect system animation setting
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelschattgen committed Aug 20, 2023
1 parent 6009c09 commit 25f6720
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.beemdevelopment.aegis.helpers;

import android.content.Context;
import android.provider.Settings;

public class SettingsHelper {
private SettingsHelper() {

}

public static boolean areAnimationsEnabled(Context context) {
try {
return !(Settings.Global.getFloat(context.getContentResolver(), Settings.Global.ANIMATOR_DURATION_SCALE) == 0f
&& Settings.Global.getFloat(context.getContentResolver(), Settings.Global.TRANSITION_ANIMATION_SCALE) == 0f
&& Settings.Global.getFloat(context.getContentResolver(), Settings.Global.WINDOW_ANIMATION_SCALE) == 0f);
} catch (Settings.SettingNotFoundException e) {
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.beemdevelopment.aegis.helpers.EditTextHelper;
import com.beemdevelopment.aegis.helpers.IconViewHelper;
import com.beemdevelopment.aegis.helpers.SafHelper;
import com.beemdevelopment.aegis.helpers.SettingsHelper;
import com.beemdevelopment.aegis.helpers.SimpleAnimationEndListener;
import com.beemdevelopment.aegis.helpers.SimpleTextWatcher;
import com.beemdevelopment.aegis.helpers.TextDrawableHelper;
Expand Down Expand Up @@ -374,14 +375,15 @@ private void setGroup(String groupName) {
}

private void openAdvancedSettings() {
boolean animate = SettingsHelper.areAnimationsEnabled(this);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(220);
fadeOut.setDuration(animate ? 220 : 0);
_advancedSettingsHeader.startAnimation(fadeOut);

Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new AccelerateInterpolator());
fadeIn.setDuration(250);
fadeIn.setDuration(animate ? 250 : 0);

fadeOut.setAnimationListener(new SimpleAnimationEndListener((a) -> {
_advancedSettingsHeader.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;

import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.helpers.SettingsHelper;
import com.beemdevelopment.aegis.ui.fragments.preferences.MainPreferencesFragment;
import com.beemdevelopment.aegis.ui.fragments.preferences.PreferencesFragment;

Expand Down Expand Up @@ -95,9 +97,13 @@ public boolean onPreferenceStartFragment(@NonNull PreferenceFragmentCompat calle
}

private void showFragment(Fragment fragment) {
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right)
.replace(R.id.content, fragment)
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

if (SettingsHelper.areAnimationsEnabled(this)) {
transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right);
}

transaction.replace(R.id.content, fragment)
.addToBackStack(null)
.commit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.helpers.IconViewHelper;
import com.beemdevelopment.aegis.helpers.SettingsHelper;
import com.beemdevelopment.aegis.helpers.TextDrawableHelper;
import com.beemdevelopment.aegis.helpers.ThemeHelper;
import com.beemdevelopment.aegis.helpers.UiRefresher;
Expand Down Expand Up @@ -92,6 +93,11 @@ public EntryHolder(final View view) {
_scaleIn = AnimationUtils.loadAnimation(view.getContext(), R.anim.item_scale_in);
_scaleOut = AnimationUtils.loadAnimation(view.getContext(), R.anim.item_scale_out);

if (!SettingsHelper.areAnimationsEnabled(view.getContext())) {
_scaleIn.setDuration(0);
_scaleOut.setDuration(0);
}

_refresher = new UiRefresher(new UiRefresher.Listener() {
@Override
public void onRefresh() {
Expand Down Expand Up @@ -375,6 +381,13 @@ public void animateCopyText() {
Animation fadeOut = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.fade_out);
Animation fadeIn = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.fade_in);

if (!SettingsHelper.areAnimationsEnabled(itemView.getContext())) {
slideDownFadeIn.setDuration(0);
slideDownFadeOut.setDuration(0);
fadeOut.setDuration(0);
fadeIn.setDuration(0);
}

_profileCopied.startAnimation(slideDownFadeIn);

View fadeOutView = (_accountNamePosition == AccountNamePosition.BELOW) ? _profileName : _description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.beemdevelopment.aegis.SortCategory;
import com.beemdevelopment.aegis.ViewMode;
import com.beemdevelopment.aegis.helpers.MetricsHelper;
import com.beemdevelopment.aegis.helpers.SettingsHelper;
import com.beemdevelopment.aegis.helpers.SimpleItemTouchHelperCallback;
import com.beemdevelopment.aegis.helpers.ThemeHelper;
import com.beemdevelopment.aegis.helpers.UiRefresher;
Expand Down Expand Up @@ -99,6 +100,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

// set up the recycler view
_recyclerView = view.findViewById(R.id.rvKeyProfiles);
_recyclerView.setItemAnimator(null);
_recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
Expand Down Expand Up @@ -129,9 +131,11 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
_touchHelper.attachToRecyclerView(_recyclerView);
_recyclerView.setAdapter(_adapter);

int resId = R.anim.layout_animation_fall_down;
LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(requireContext(), resId);
_recyclerView.setLayoutAnimation(animation);
if (SettingsHelper.areAnimationsEnabled(_recyclerView.getContext())) {
int resId = R.anim.layout_animation_fall_down;
LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(requireContext(), resId);
_recyclerView.setLayoutAnimation(animation);
}

_refresher = new UiRefresher(new UiRefresher.Listener() {
@Override
Expand Down Expand Up @@ -421,6 +425,10 @@ public void replaceEntry(UUID uuid, VaultEntry newEntry) {
}

public void runEntriesAnimation() {
if (!SettingsHelper.areAnimationsEnabled(getContext())) {
return;
}

final LayoutAnimationController controller =
AnimationUtils.loadLayoutAnimation(requireContext(), R.anim.layout_animation_fall_down);

Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_entry_list_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
android:layout_height="0dp"
android:scrollbars="vertical"
android:id="@+id/rvKeyProfiles"
android:layoutAnimation="@anim/layout_animation_fall_down"
android:layout_weight="1"/>

<LinearLayout
Expand Down

0 comments on commit 25f6720

Please sign in to comment.