use of com.amaze.filemanager.ui.views.preference.CheckBox in project AmazeFileManager by TeamAmaze.
the class PrefFrag method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
utilsProvider = ((BasicActivity) getActivity()).getUtilsProvider();
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
for (String PREFERENCE_KEY : PREFERENCE_KEYS) {
findPreference(PREFERENCE_KEY).setOnPreferenceClickListener(this);
}
// crypt master password
final Preference masterPasswordPreference = findPreference(PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 || sharedPref.getBoolean(PreferencesConstants.PREFERENCE_CRYPT_FINGERPRINT, false)) {
// encryption feature not available
masterPasswordPreference.setEnabled(false);
}
masterPasswordPreference.setOnPreferenceClickListener(this);
CheckBox checkBoxFingerprint = (CheckBox) findPreference(PreferencesConstants.PREFERENCE_CRYPT_FINGERPRINT);
try {
// finger print sensor
final FingerprintManager fingerprintManager = (FingerprintManager) getActivity().getSystemService(Context.FINGERPRINT_SERVICE);
final KeyguardManager keyguardManager = (KeyguardManager) getActivity().getSystemService(Context.KEYGUARD_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && fingerprintManager.isHardwareDetected()) {
checkBoxFingerprint.setEnabled(true);
}
checkBoxFingerprint.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_no_permission), Toast.LENGTH_LONG).show();
return false;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !fingerprintManager.hasEnrolledFingerprints()) {
Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_not_enrolled), Toast.LENGTH_LONG).show();
return false;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !keyguardManager.isKeyguardSecure()) {
Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_no_security), Toast.LENGTH_LONG).show();
return false;
}
masterPasswordPreference.setEnabled(false);
return true;
}
});
} catch (NoClassDefFoundError error) {
error.printStackTrace();
// fingerprint manager class not defined in the framework
checkBoxFingerprint.setEnabled(false);
}
}
Aggregations