Search in sources :

Example 1 with CheckBox

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);
    }
}
Also used : Preference(android.preference.Preference) CheckBox(com.amaze.filemanager.ui.views.preference.CheckBox) FingerprintManager(android.hardware.fingerprint.FingerprintManager) KeyguardManager(android.app.KeyguardManager)

Aggregations

KeyguardManager (android.app.KeyguardManager)1 FingerprintManager (android.hardware.fingerprint.FingerprintManager)1 Preference (android.preference.Preference)1 CheckBox (com.amaze.filemanager.ui.views.preference.CheckBox)1