Skip to content

Commit

Permalink
show shake animation only if animations are enabled as a system setting
Browse files Browse the repository at this point in the history
  • Loading branch information
CampelloManuel committed Jul 23, 2023
1 parent 31dcf65 commit a80873d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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

import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
Expand Down Expand Up @@ -103,4 +104,28 @@ public static boolean isPasswordSet(@NonNull Context context) {
return !Prefs(context).getString(PasswordPrefs.KEY_PASSWORD, "").isEmpty();
}

/**
* @return TRUE if animations are enabled in the system settings. Used to choose if animations
* should be displayed in the app
*/
public static boolean areAnimationsEnabled(@NonNull Context context) {

// there are 3 redundant system settings that control animations
String[] sysSettingsToCheck = new String[] {
Settings.Global.ANIMATOR_DURATION_SCALE,
Settings.Global.TRANSITION_ANIMATION_SCALE,
Settings.Global.WINDOW_ANIMATION_SCALE
};

// if at least 1 of those is set to "0x", which means "disable animations",
// we assume that the user wants to disable all animations, also in this app
for (String option : sysSettingsToCheck) {
float f = Settings.Global.getFloat(context.getContentResolver(), option, 1.0f);
if (f == 0) return false;
}

// if none of the 3 settings is "0x", we assume that animations are enabled
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import androidx.fragment.app.DialogFragment;
import androidx.preference.PreferenceManager;

import com.nononsenseapps.helpers.PreferencesHelper;
import com.nononsenseapps.notepad.R;
import com.nononsenseapps.notepad.databinding.FragmentDialogPasswordBinding;
import com.nononsenseapps.notepad.prefs.PasswordPrefs;
Expand Down Expand Up @@ -116,9 +117,11 @@ private void checkPassword(final String enteredPassword, final String currentPas
}
dismiss();
} else {
Animation shake = AnimationUtils.loadAnimation(getActivity(),
R.anim.shake);
mBinding.passwordField.startAnimation(shake);
if (PreferencesHelper.areAnimationsEnabled(this.getContext())) {
// shake the dialog to show that the password is wrong
Animation shake = AnimationUtils.loadAnimation(getActivity(), R.anim.shake);
mBinding.passwordField.startAnimation(shake);
}
Toast.makeText(getActivity(), getText(R.string.password_incorrect),
Toast.LENGTH_SHORT).show();
}
Expand All @@ -135,8 +138,11 @@ private void setPassword(final String pass1, final String pass2) {
}
dismiss();
} else {
Animation shake = AnimationUtils.loadAnimation(getActivity(), R.anim.shake);
mBinding.passwordVerificationField.startAnimation(shake);
if (PreferencesHelper.areAnimationsEnabled(this.getContext())) {
// shake the dialog to show that the password is wrong
Animation shake = AnimationUtils.loadAnimation(getActivity(), R.anim.shake);
mBinding.passwordVerificationField.startAnimation(shake);
}
Toast.makeText(getActivity(), getText(R.string.passwords_dont_match),
Toast.LENGTH_SHORT).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import androidx.fragment.app.DialogFragment;
import androidx.preference.PreferenceManager;

import com.nononsenseapps.helpers.PreferencesHelper;
import com.nononsenseapps.notepad.R;
import com.nononsenseapps.notepad.databinding.FragmentDialogPasswordBinding;
import com.nononsenseapps.notepad.fragments.DialogPassword.PasswordConfirmedListener;
Expand Down Expand Up @@ -98,8 +99,11 @@ private void checkPassword(String enteredPassword, String currentPassword) {
}
dismiss();
} else {
Animation shake = AnimationUtils.loadAnimation(getActivity(), R.anim.shake);
mBinding.passwordField.startAnimation(shake);
if (PreferencesHelper.areAnimationsEnabled(this.getContext())) {
// shake the dialog to show that the password is wrong
Animation shake = AnimationUtils.loadAnimation(getActivity(), R.anim.shake);
mBinding.passwordField.startAnimation(shake);
}
Toast.makeText(getActivity(), getText(R.string.password_incorrect),
Toast.LENGTH_SHORT).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;

import com.nononsenseapps.helpers.PreferencesHelper;
import com.nononsenseapps.notepad.R;
import com.nononsenseapps.notepad.databinding.AppPrefPasswordLayoutBinding;
import com.nononsenseapps.notepad.fragments.DialogPasswordV11;
Expand Down Expand Up @@ -83,9 +84,12 @@ private void applyPassword() {
showPasswordDialog(passw1);
}
} else {
if (PreferencesHelper.areAnimationsEnabled(this.getContext())) {
// shake the dialog to show that the password is wrong
Animation shake = AnimationUtils.loadAnimation(this.getContext(), R.anim.shake);
mBinding.tempPassword2.startAnimation(shake);
}
// Show a toast so the user knows he did something wrong
Animation shake = AnimationUtils.loadAnimation(this.getContext(), R.anim.shake);
mBinding.tempPassword2.startAnimation(shake);
Toast.makeText(this.getContext(), getText(R.string.passwords_dont_match),
Toast.LENGTH_SHORT).show();
}
Expand Down

0 comments on commit a80873d

Please sign in to comment.