Example usage for android.preference SwitchPreference isChecked

List of usage examples for android.preference SwitchPreference isChecked

Introduction

In this page you can find the example usage for android.preference SwitchPreference isChecked.

Prototype

public boolean isChecked() 

Source Link

Document

Returns the checked state.

Usage

From source file:org.deviceconnect.android.uiapp.fragment.profile.ConnectProfileFragment.java

/**
 * SwitchPreference????./*w w  w .j  a v a2  s. c  om*/
 * @param key 
 */
private void toggleCheckedPreference(final String key) {
    SwitchPreference pref = (SwitchPreference) findPreference(key);
    pref.setChecked(!pref.isChecked());
}

From source file:com.mantz_it.rfanalyzer.SettingsFragment.java

/**
 * Will go through each preference element and initialize/update the summary according to its value.
 * @note this will also correct invalid user inputs on EdittextPreferences!
 *//*ww  w .  j  ava  2s  .co  m*/
public void updateSummaries() {
    // Source Type
    ListPreference listPref = (ListPreference) findPreference(getString(R.string.pref_sourceType));
    listPref.setSummary(getString(R.string.pref_sourceType_summ, listPref.getEntry()));

    // Direct Sampling
    listPref = (ListPreference) findPreference(getString(R.string.pref_rtlsdr_directSamp));
    listPref.setSummary(getString(R.string.pref_rtlsdr_directSamp_summ, listPref.getEntry()));

    // Frequency display
    listPref = (ListPreference) findPreference(getString(R.string.pref_surface_unit));
    listPref.setSummary(getString(R.string.pref_surface_unit_summ, listPref.getEntry()));

    // FileSource Frequency
    EditTextPreference editTextPref = (EditTextPreference) findPreference(
            getString(R.string.pref_filesource_frequency));
    if (editTextPref.getText().length() == 0)
        editTextPref.setText(getString(R.string.pref_filesource_frequency_default));
    editTextPref.setSummary(getString(R.string.pref_filesource_frequency_summ, editTextPref.getText()));

    // FileSource Sample Rate
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_filesource_sampleRate));
    if (editTextPref.getText().length() == 0)
        editTextPref.setText(getString(R.string.pref_filesource_sampleRate_default));
    editTextPref.setSummary(getString(R.string.pref_filesource_sampleRate_summ, editTextPref.getText()));

    // FileSource File
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_filesource_file));
    editTextPref.setSummary(getString(R.string.pref_filesource_file_summ, editTextPref.getText()));

    // FileSource Format
    listPref = (ListPreference) findPreference(getString(R.string.pref_filesource_format));
    listPref.setSummary(getString(R.string.pref_filesource_format_summ, listPref.getEntry()));

    // HackRF frequency shift
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_hackrf_frequencyOffset));
    if (editTextPref.getText().length() == 0)
        editTextPref.setText("0");
    editTextPref.setSummary(getString(R.string.pref_hackrf_frequencyOffset_summ, editTextPref.getText()));

    // RTL-SDR IP
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_ip));
    editTextPref.setSummary(getString(R.string.pref_rtlsdr_ip_summ, editTextPref.getText()));

    // RTL-SDR Port
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_port));
    editTextPref.setSummary(getString(R.string.pref_rtlsdr_port_summ, editTextPref.getText()));

    // RTL-SDR frequency correction
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_frequencyCorrection));
    if (editTextPref.getText().length() == 0)
        editTextPref.setText(getString(R.string.pref_rtlsdr_frequencyCorrection_default));
    editTextPref.setSummary(getString(R.string.pref_rtlsdr_frequencyCorrection_summ, editTextPref.getText()));

    // RTL-SDR frequency shift
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_frequencyOffset));
    if (editTextPref.getText().length() == 0)
        editTextPref.setText("0");
    editTextPref.setSummary(getString(R.string.pref_rtlsdr_frequencyOffset_summ, editTextPref.getText()));

    // FFT size
    listPref = (ListPreference) findPreference(getString(R.string.pref_fftSize));
    listPref.setSummary(getString(R.string.pref_fftSize_summ, listPref.getEntry()));

    // Color map type
    listPref = (ListPreference) findPreference(getString(R.string.pref_colorMapType));
    listPref.setSummary(getString(R.string.pref_colorMapType_summ, listPref.getEntry()));

    // FFT drawing type
    listPref = (ListPreference) findPreference(getString(R.string.pref_fftDrawingType));
    listPref.setSummary(getString(R.string.pref_fftDrawingType_summ, listPref.getEntry()));

    // Averaging
    listPref = (ListPreference) findPreference(getString(R.string.pref_averaging));
    listPref.setSummary(getString(R.string.pref_averaging_summ, listPref.getEntry()));

    // Screen Orientation
    listPref = (ListPreference) findPreference(getString(R.string.pref_screenOrientation));
    listPref.setSummary(getString(R.string.pref_screenOrientation_summ, listPref.getEntry()));

    // Spectrum Waterfall Ratio
    listPref = (ListPreference) findPreference(getString(R.string.pref_spectrumWaterfallRatio));
    listPref.setSummary(getString(R.string.pref_spectrumWaterfallRatio_summ, listPref.getEntry()));

    // Font Size
    listPref = (ListPreference) findPreference(getString(R.string.pref_fontSize));
    listPref.setSummary(getString(R.string.pref_fontSize_summ, listPref.getEntry()));

    // Frame Rate
    SwitchPreference switchPref = (SwitchPreference) findPreference(getString(R.string.pref_dynamicFrameRate));
    listPref = (ListPreference) findPreference(getString(R.string.pref_frameRate));
    if (switchPref.isChecked())
        listPref.setSummary(getString(R.string.pref_frameRate_summ, "auto"));
    else
        listPref.setSummary(getString(R.string.pref_frameRate_summ, listPref.getEntry()));

    // Logfile
    editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_logfile));
    editTextPref.setSummary(getString(R.string.pref_logfile_summ, editTextPref.getText()));

    // Shared preferences updated in e.g. the onRequestPermissionResult() method are
    // not automatically updated in the preference fragment gui. do it manually:
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
    switchPref = (SwitchPreference) findPreference(getString(R.string.pref_logging));
    switchPref.setChecked(preferences.getBoolean(getString(R.string.pref_logging), false));
}

From source file:com.owncloud.android.ui.activity.Preferences.java

@SuppressWarnings("deprecation")
@Override//w w  w.  j a  v a  2  s .com
public void onCreate(Bundle savedInstanceState) {

    if (ThemeUtils.themingEnabled()) {
        setTheme(R.style.FallbackThemingTheme);
    }

    getDelegate().installViewFactory();
    getDelegate().onCreate(savedInstanceState);
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    ActionBar actionBar = getDelegate().getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    ThemeUtils.setColoredTitle(actionBar, getString(R.string.actionbar_settings));
    actionBar.setBackgroundDrawable(new ColorDrawable(ThemeUtils.primaryColor()));
    getWindow().getDecorView().setBackgroundDrawable(
            new ColorDrawable(ResourcesCompat.getColor(getResources(), R.color.background_color, null)));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(ThemeUtils.primaryDarkColor());
    }

    Drawable backArrow = getResources().getDrawable(R.drawable.ic_arrow_back);
    actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.fontColor()));

    int accentColor = ThemeUtils.primaryAccentColor();

    // retrieve user's base uri
    setupBaseUri();

    // For adding content description tag to a title field in the action bar
    int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
    View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
    if (actionBarTitleView != null) { // it's null in Android 2.x
        getWindow().getDecorView().findViewById(actionBarTitleId)
                .setContentDescription(getString(R.string.actionbar_settings));
    }
    // Load package info
    String temp;
    try {
        PackageInfo pkg = getPackageManager().getPackageInfo(getPackageName(), 0);
        temp = pkg.versionName;
    } catch (NameNotFoundException e) {
        temp = "";
        Log_OC.e(TAG, "Error while showing about dialog", e);
    }
    final String appVersion = temp;

    // Register context menu for list of preferences.
    registerForContextMenu(getListView());

    // General
    PreferenceCategory preferenceCategoryGeneral = (PreferenceCategory) findPreference("general");
    preferenceCategoryGeneral
            .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_general), accentColor));

    // Synced folders
    PreferenceCategory preferenceCategorySyncedFolders = (PreferenceCategory) findPreference(
            "synced_folders_category");
    preferenceCategorySyncedFolders
            .setTitle(ThemeUtils.getColoredTitle(getString(R.string.drawer_synced_folders), accentColor));
    PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("preference_screen");

    if (!getResources().getBoolean(R.bool.syncedFolder_light)) {
        preferenceScreen.removePreference(preferenceCategorySyncedFolders);
    } else {
        // Upload on WiFi
        final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
        final Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());

        final SwitchPreference pUploadOnWifiCheckbox = (SwitchPreference) findPreference(
                "synced_folder_on_wifi");
        pUploadOnWifiCheckbox
                .setChecked(arbitraryDataProvider.getBooleanValue(account, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI));

        pUploadOnWifiCheckbox.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                arbitraryDataProvider.storeOrUpdateKeyValue(account.name, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI,
                        String.valueOf(pUploadOnWifiCheckbox.isChecked()));

                return true;
            }
        });

        Preference pSyncedFolder = findPreference("synced_folders_configure_folders");
        if (pSyncedFolder != null) {
            if (getResources().getBoolean(R.bool.syncedFolder_light)
                    && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                pSyncedFolder.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Intent syncedFoldersIntent = new Intent(getApplicationContext(),
                                SyncedFoldersActivity.class);
                        syncedFoldersIntent.putExtra(SyncedFoldersActivity.EXTRA_SHOW_SIDEBAR, false);
                        startActivity(syncedFoldersIntent);
                        return true;
                    }
                });
            } else {
                preferenceCategorySyncedFolders.removePreference(pSyncedFolder);
            }
        }
    }

    PreferenceCategory preferenceCategoryDetails = (PreferenceCategory) findPreference("details");
    preferenceCategoryDetails
            .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_details), accentColor));

    boolean fPassCodeEnabled = getResources().getBoolean(R.bool.passcode_enabled);
    pCode = (SwitchPreference) findPreference(PassCodeActivity.PREFERENCE_SET_PASSCODE);
    if (pCode != null && fPassCodeEnabled) {
        pCode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Intent i = new Intent(getApplicationContext(), PassCodeActivity.class);
                Boolean incoming = (Boolean) newValue;

                i.setAction(incoming ? PassCodeActivity.ACTION_REQUEST_WITH_RESULT
                        : PassCodeActivity.ACTION_CHECK_WITH_RESULT);

                startActivityForResult(i, incoming ? ACTION_REQUEST_PASSCODE : ACTION_CONFIRM_PASSCODE);

                // Don't update just yet, we will decide on it in onActivityResult
                return false;
            }
        });
    } else {
        preferenceCategoryDetails.removePreference(pCode);
    }

    boolean fPrintEnabled = getResources().getBoolean(R.bool.fingerprint_enabled);
    fPrint = (SwitchPreference) findPreference(PREFERENCE_USE_FINGERPRINT);
    if (fPrint != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (FingerprintActivity.isFingerprintCapable(MainApp.getAppContext()) && fPrintEnabled) {
                fPrint.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        Boolean incoming = (Boolean) newValue;

                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            if (FingerprintActivity.isFingerprintReady(MainApp.getAppContext())) {
                                SharedPreferences appPrefs = PreferenceManager
                                        .getDefaultSharedPreferences(getApplicationContext());
                                SharedPreferences.Editor editor = appPrefs.edit();
                                editor.putBoolean("use_fingerprint", incoming);
                                editor.apply();
                                return true;
                            } else {
                                if (incoming) {
                                    Toast.makeText(MainApp.getAppContext(), R.string.prefs_fingerprint_notsetup,
                                            Toast.LENGTH_LONG).show();
                                    fPrint.setChecked(false);
                                }
                                SharedPreferences appPrefs = PreferenceManager
                                        .getDefaultSharedPreferences(getApplicationContext());
                                SharedPreferences.Editor editor = appPrefs.edit();
                                editor.putBoolean("use_fingerprint", false);
                                editor.apply();
                                return false;
                            }
                        } else {
                            return false;
                        }
                    }
                });
                if (!FingerprintActivity.isFingerprintReady(MainApp.getAppContext())) {
                    fPrint.setChecked(false);
                }

            } else {
                preferenceCategoryDetails.removePreference(fPrint);
            }
        } else {
            preferenceCategoryDetails.removePreference(fPrint);
        }
    }

    boolean fShowHiddenFilesEnabled = getResources().getBoolean(R.bool.show_hidden_files_enabled);
    mShowHiddenFiles = (SwitchPreference) findPreference("show_hidden_files");

    if (fShowHiddenFilesEnabled) {
        mShowHiddenFiles.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                SharedPreferences appPrefs = PreferenceManager
                        .getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences.Editor editor = appPrefs.edit();
                editor.putBoolean("show_hidden_files_pref", mShowHiddenFiles.isChecked());
                editor.apply();
                return true;
            }
        });
    } else {
        preferenceCategoryDetails.removePreference(mShowHiddenFiles);
    }

    mExpertMode = (SwitchPreference) findPreference(EXPERT_MODE);

    if (getResources().getBoolean(R.bool.syncedFolder_light)) {
        preferenceCategoryDetails.removePreference(mExpertMode);
    } else {
        mExpertMode = (SwitchPreference) findPreference(EXPERT_MODE);
        mExpertMode.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                SharedPreferences appPrefs = PreferenceManager
                        .getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences.Editor editor = appPrefs.edit();
                editor.putBoolean(EXPERT_MODE, mExpertMode.isChecked());
                editor.apply();

                if (mExpertMode.isChecked()) {
                    Log_OC.startLogging(getApplicationContext());
                } else {
                    if (!BuildConfig.DEBUG
                            && !getApplicationContext().getResources().getBoolean(R.bool.logger_enabled)) {
                        Log_OC.stopLogging();
                    }
                }

                return true;
            }
        });
    }

    PreferenceCategory preferenceCategoryMore = (PreferenceCategory) findPreference("more");
    preferenceCategoryMore
            .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_more), accentColor));

    boolean calendarContactsEnabled = getResources().getBoolean(R.bool.davdroid_integration_enabled);
    Preference pCalendarContacts = findPreference("calendar_contacts");
    if (pCalendarContacts != null) {
        if (calendarContactsEnabled) {
            pCalendarContacts.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    try {
                        launchDavDroidLogin();
                    } catch (Throwable t) {
                        Log_OC.e(TAG, "Base Uri for account could not be resolved to call DAVdroid!", t);
                        Toast.makeText(MainApp.getAppContext(),
                                R.string.prefs_calendar_contacts_address_resolve_error, Toast.LENGTH_SHORT)
                                .show();
                    }
                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pCalendarContacts);
        }
    }

    boolean contactsBackupEnabled = !getResources().getBoolean(R.bool.show_drawer_contacts_backup)
            && getResources().getBoolean(R.bool.contacts_backup);
    Preference pContactsBackup = findPreference("contacts");
    if (pCalendarContacts != null) {
        if (contactsBackupEnabled) {
            pContactsBackup.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Intent contactsIntent = new Intent(getApplicationContext(),
                            ContactsPreferenceActivity.class);
                    contactsIntent.putExtra(ContactsPreferenceActivity.EXTRA_SHOW_SIDEBAR, false);
                    startActivity(contactsIntent);
                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pContactsBackup);
        }
    }

    if (!fShowHiddenFilesEnabled && !fPrintEnabled && !fPassCodeEnabled) {
        preferenceScreen.removePreference(preferenceCategoryDetails);
    }

    boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
    Preference pHelp = findPreference("help");
    if (pHelp != null) {
        if (helpEnabled) {
            pHelp.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String helpWeb = getString(R.string.url_help);
                    if (helpWeb != null && helpWeb.length() > 0) {
                        Uri uriUrl = Uri.parse(helpWeb);
                        Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                        startActivity(intent);
                    }
                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pHelp);
        }
    }

    boolean recommendEnabled = getResources().getBoolean(R.bool.recommend_enabled);
    Preference pRecommend = findPreference("recommend");
    if (pRecommend != null) {
        if (recommendEnabled) {
            pRecommend.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {

                    Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                    String appName = getString(R.string.app_name);
                    String downloadUrlGooglePlayStore = getString(R.string.url_app_download);
                    String downloadUrlFDroid = getString(R.string.fdroid_link);
                    String downloadUrls = String.format(getString(R.string.recommend_urls),
                            downloadUrlGooglePlayStore, downloadUrlFDroid);

                    String recommendSubject = String.format(getString(R.string.recommend_subject), appName);
                    String recommendText = String.format(getString(R.string.recommend_text), appName,
                            downloadUrls);

                    intent.putExtra(Intent.EXTRA_SUBJECT, recommendSubject);
                    intent.putExtra(Intent.EXTRA_TEXT, recommendText);
                    startActivity(intent);

                    return true;

                }
            });
        } else {
            preferenceCategoryMore.removePreference(pRecommend);
        }
    }

    boolean feedbackEnabled = getResources().getBoolean(R.bool.feedback_enabled);
    Preference pFeedback = findPreference("feedback");
    if (pFeedback != null) {
        if (feedbackEnabled) {
            pFeedback.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String feedbackMail = getString(R.string.mail_feedback);
                    String feedback = getText(R.string.prefs_feedback) + " - android v" + appVersion;
                    Intent intent = new Intent(Intent.ACTION_SENDTO);
                    intent.setType("text/plain");
                    intent.putExtra(Intent.EXTRA_SUBJECT, feedback);

                    intent.setData(Uri.parse(feedbackMail));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);

                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pFeedback);
        }
    }

    SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG
            || appPrefs.getBoolean(EXPERT_MODE, false);
    Preference pLogger = findPreference("logger");
    if (pLogger != null) {
        if (loggerEnabled) {
            pLogger.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Intent loggerIntent = new Intent(getApplicationContext(), LogHistoryActivity.class);
                    startActivity(loggerIntent);

                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pLogger);
        }
    }

    boolean imprintEnabled = getResources().getBoolean(R.bool.imprint_enabled);
    Preference pImprint = findPreference("imprint");
    if (pImprint != null) {
        if (imprintEnabled) {
            pImprint.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String imprintWeb = getString(R.string.url_imprint);
                    if (imprintWeb != null && imprintWeb.length() > 0) {
                        Uri uriUrl = Uri.parse(imprintWeb);
                        Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                        startActivity(intent);
                    }
                    //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
                    return true;
                }
            });
        } else {
            preferenceCategoryMore.removePreference(pImprint);
        }
    }

    mPrefStoragePath = (ListPreference) findPreference(PreferenceKeys.STORAGE_PATH);
    if (mPrefStoragePath != null) {
        StoragePoint[] storageOptions = DataStorageProvider.getInstance().getAvailableStoragePoints();
        String[] entries = new String[storageOptions.length];
        String[] values = new String[storageOptions.length];
        for (int i = 0; i < storageOptions.length; ++i) {
            entries[i] = storageOptions[i].getDescription();
            values[i] = storageOptions[i].getPath();
        }
        mPrefStoragePath.setEntries(entries);
        mPrefStoragePath.setEntryValues(values);

        mPrefStoragePath.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                String newPath = (String) newValue;
                if (mStoragePath.equals(newPath)) {
                    return true;
                }

                StorageMigration storageMigration = new StorageMigration(Preferences.this, mStoragePath,
                        newPath);

                storageMigration.setStorageMigrationProgressListener(Preferences.this);

                storageMigration.migrate();

                return false;
            }
        });
    }

    // About category
    PreferenceCategory preferenceCategoryAbout = (PreferenceCategory) findPreference("about");
    preferenceCategoryAbout
            .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_about), accentColor));

    /* About App */
    pAboutApp = findPreference("about_app");
    if (pAboutApp != null) {
        pAboutApp.setTitle(String.format(getString(R.string.about_android), getString(R.string.app_name)));
        pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion));
    }

    // source code
    boolean sourcecodeEnabled = getResources().getBoolean(R.bool.sourcecode_enabled);
    Preference sourcecodePreference = findPreference("sourcecode");
    if (sourcecodePreference != null) {
        String sourcecodeUrl = getString(R.string.sourcecode_url);

        if (sourcecodeEnabled && !sourcecodeUrl.isEmpty()) {
            sourcecodePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Uri uriUrl = Uri.parse(sourcecodeUrl);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                    startActivity(intent);
                    return true;
                }
            });
        } else {
            preferenceCategoryAbout.removePreference(sourcecodePreference);
        }
    }

    // license
    boolean licenseEnabled = getResources().getBoolean(R.bool.license_enabled);
    Preference licensePreference = findPreference("license");
    if (licensePreference != null) {
        String licenseUrl = getString(R.string.license_url);

        if (licenseEnabled && !licenseUrl.isEmpty()) {
            licensePreference.setSummary(R.string.prefs_gpl_v2);
            licensePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Uri uriUrl = Uri.parse(licenseUrl);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                    startActivity(intent);
                    return true;
                }
            });
        } else {
            preferenceCategoryAbout.removePreference(licensePreference);
        }
    }

    // privacy
    boolean privacyEnabled = getResources().getBoolean(R.bool.privacy_enabled);
    Preference privacyPreference = findPreference("privacy");
    if (privacyPreference != null) {
        if (privacyEnabled) {
            privacyPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String privacyUrl = getString(R.string.privacy_url);
                    if (privacyUrl.length() > 0) {
                        Intent externalWebViewIntent = new Intent(getApplicationContext(),
                                ExternalSiteWebView.class);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE,
                                getResources().getString(R.string.privacy));
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, privacyUrl);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false);
                        externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, -1);
                        startActivity(externalWebViewIntent);
                    }
                    return true;
                }
            });
        } else {
            preferenceCategoryAbout.removePreference(privacyPreference);
        }
    }

    loadExternalSettingLinks(preferenceCategoryMore);

    loadStoragePath();
}

From source file:mx.klozz.xperience.tweaker.fragments.MemSettings.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);//w  w w .  j  a  va 2s .  c om

    mPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mPreferences.registerOnSharedPreferenceChangeListener(this);
    addPreferencesFromResource(R.layout.mem_settings);

    //Fix the nullpointer
    if (new File(MINFREE_PATH).canRead()) {
        values = Helpers.LeerUnaLinea(MINFREE_PATH).split(",");
    } else {
        values = Helpers.LeerUnaLinea(MINFREE_PATH_OFF).split(",");
    }

    mForegroundApp = findPreference(OOM_FOREGROUND_APP);
    mVisibleApp = findPreference(OOM_VISIBLE_APP);
    mSecondaryServer = findPreference(OOM_SECONDARY_SERVER);
    mHiddenApp = findPreference(OOM_HIDDEN_APP);
    mContentProviders = findPreference(OOM_CONTENT_PROVIDERS);
    mEmptyApp = findPreference(OOM_EMPTY_APP);

    mPresets = (ListPreference) findPreference("oom_presets");

    Map<String, String> oom = new LinkedHashMap<String, String>();
    final String s = mPreferences.getString(MINFREE_DEFAULT, "");
    if (!s.equals("")) {
        oom.put(getResources().getString(R.string.oom_default), s);
    }

    for (int i = 0; i < getResources().getStringArray(R.array.oom_values).length; i++) {
        oom.put(getResources().getStringArray(R.array.oom_values)[i], ventries[i].toString());
    }
    mPresets.setEntryValues(oom.values().toArray(new CharSequence[oom.size()]));
    mPresets.setEntries(oom.keySet().toArray(new CharSequence[oom.size()]));
    mPresets.setValue(Helpers.LeerUnaLinea(MINFREE_PATH));

    updateOOM(values);

    mUserON = (SwitchPreference) findPreference(PREF_USER_PROC);
    mSysON = (SwitchPreference) findPreference(PREF_SYS_PROC);
    mUserNames = findPreference(PREF_USER_NAMES);
    mSysNames = findPreference(PREF_SYS_NAMES);

    mKSM = (SwitchPreference) findPreference(PREF_RUN_KSM);
    mKSMsettings = findPreference("ksm_settings");

    mZRAMsettings = findPreference("zram_settings");
    SwitchPreference mZRAMboot = (SwitchPreference) findPreference("zram_boot");

    String names = "";
    if (!new File(USER_PROC_PATH).exists()) {
        PreferenceCategory hideCat = (PreferenceCategory) findPreference("notkill_user_proc");
        getPreferenceScreen().removePreference(hideCat);
    } else {
        mUserON.setChecked(Helpers.LeerUnaLinea(USER_PROC_PATH).equals("1"));
        names = Helpers.LeerUnaLinea(USER_PROC_NAMES_PATH);
        if (names == null)
            names = "";
        mPreferences.edit().putString(PREF_USER_NAMES, names).apply();
    }
    if (!new File(SYS_PROC_PATH).exists()) {
        PreferenceCategory hideCat = (PreferenceCategory) findPreference("notkill_sys_proc");
        getPreferenceScreen().removePreference(hideCat);
    } else {
        mSysON.setChecked(Helpers.LeerUnaLinea(SYS_PROC_PATH).equals("1"));
        names = Helpers.LeerUnaLinea(USER_SYS_NAMES_PATH);
        if (names == null)
            names = "";
        mPreferences.edit().putString(PREF_SYS_NAMES, names).apply();
    }
    if (!new File(UKSM_RUN_PATH + "/run").exists() && !new File(KSM_RUN_PATH + "/run").exists()) {
        PreferenceCategory hideCat = (PreferenceCategory) findPreference("ksm");
        getPreferenceScreen().removePreference(hideCat);
    } else {
        if (new File(UKSM_RUN_PATH + "/run").exists()) {
            ksm = 1;
            ksmpath = UKSM_RUN_PATH;
            mKSMsettings.setSummary(R.string.uksm);
        } else {
            ksm = 0;
            ksmpath = KSM_RUN_PATH;
            mKSMsettings.setSummary(null);
        }
        mKSM.setChecked(Helpers.LeerUnaLinea(ksmpath + "/run").equals("1"));

    }
    ispm = (Helpers.BinExist("pm") != null);

    if (!Helpers.isZRAM()) {
        PreferenceCategory hideCat = (PreferenceCategory) findPreference("zram");
        getPreferenceScreen().removePreference(hideCat);
    } else {
        int percent = 0;
        if (swap > 0) {
            percent = Math.round(swap * 100 / maxdisk);
            curdisk = Math.round(maxdisk * percent / 100);
            if (mZRAMboot.isChecked())
                mPreferences.edit().putInt(PREF_ZRAM, curdisk).apply();
        } else {
            curdisk = mPreferences.getInt(PREF_ZRAM, Math.round(maxdisk * 18 / 100));
            percent = Math.round(curdisk * 100 / maxdisk);
        }
        mZRAMsettings.setSummary(getString(R.string.ps_zram) + " | "
                + getString(R.string.zram_disk_size, Helpers.ReadableByteCount(curdisk * 1024 * 1024)) + " ("
                + String.valueOf(percent) + "%)");
    }
}

From source file:nl.hnogames.domoticz.Preference.Preference.java

private void setPreferences() {
    final android.preference.SwitchPreference MultiServerPreference = (android.preference.SwitchPreference) findPreference(
            "enableMultiServers");
    android.preference.Preference ServerSettings = findPreference("server_settings");
    android.preference.Preference PermissionsSettings = findPreference("permissionssettings");
    android.preference.Preference NotificationLogged = findPreference("notification_show_logs");
    android.preference.Preference fetchServerConfig = findPreference("server_force_fetch_config");
    android.preference.Preference resetApplication = findPreference("reset_settings");
    android.preference.ListPreference displayLanguage = (ListPreference) findPreference("displayLanguage");
    final android.preference.Preference registrationId = findPreference("notification_registration_id");
    android.preference.Preference GeoSettings = findPreference("geo_settings");
    android.preference.SwitchPreference WearPreference = (android.preference.SwitchPreference) findPreference(
            "enableWearItems");
    android.preference.Preference NFCPreference = findPreference("nfc_settings");
    android.preference.Preference QRCodePreference = findPreference("qrcode_settings");
    android.preference.Preference SpeechPreference = findPreference("speech_settings");
    android.preference.SwitchPreference EnableNFCPreference = (android.preference.SwitchPreference) findPreference(
            "enableNFC");
    android.preference.SwitchPreference EnableQRCodePreference = (android.preference.SwitchPreference) findPreference(
            "enableQRCode");
    android.preference.SwitchPreference EnableSpeechPreference = (android.preference.SwitchPreference) findPreference(
            "enableSpeech");
    android.preference.SwitchPreference EnableTalkBackPreference = (android.preference.SwitchPreference) findPreference(
            "talkBack");
    MultiSelectListPreference drawerItems = (MultiSelectListPreference) findPreference("enable_menu_items");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.SwitchPreference AlwaysOnPreference = (android.preference.SwitchPreference) findPreference(
            "alwayson");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.PreferenceScreen preferenceScreen = (android.preference.PreferenceScreen) findPreference(
            "settingsscreen");
    android.preference.PreferenceCategory premiumCategory = (android.preference.PreferenceCategory) findPreference(
            "premium_category");
    android.preference.Preference premiumPreference = findPreference("premium_settings");
    NotificationsMultiSelectListPreference notificationsMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "suppressNotifications");
    NotificationsMultiSelectListPreference alarmMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "alarmNotifications");
    android.preference.SwitchPreference ThemePreference = (android.preference.SwitchPreference) findPreference(
            "darkTheme");
    android.preference.Preference FingerPrintSettingsPreference = findPreference("SecuritySettings");
    android.preference.SwitchPreference FingerPrintPreference = (android.preference.SwitchPreference) findPreference(
            "enableSecurity");

    if (!BuildConfig.DEBUG) {
        PreferenceCategory oAndroidAutoCategory = (android.preference.PreferenceCategory) findPreference(
                "androidautocategory");
        PreferenceScreen oNotificationScreen = (android.preference.PreferenceScreen) findPreference(
                "notificationscreen");
        oNotificationScreen.removePreference(oAndroidAutoCategory);
    }//from   w  ww .j  ava  2 s.c o  m

    List<String> notifications = mSharedPrefs.getReceivedNotifications();
    if (notifications == null || notifications.size() <= 0) {
        notificationsMultiSelectListPreference.setEnabled(false);
        alarmMultiSelectListPreference.setEnabled(false);
    } else {
        notificationsMultiSelectListPreference.setEnabled(true);
        alarmMultiSelectListPreference.setEnabled(true);
    }

    PermissionsSettings
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    permissionHelper.openSettingsScreen();
                    return true;
                }
            });

    drawerItems.setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
            try {
                final HashSet selectedDrawerItems = (HashSet) newValue;
                if (selectedDrawerItems.size() < 1) {
                    showSnackbar(mContext.getString(R.string.error_atLeastOneItemInDrawer));
                    return false;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                return false;
            }
            return true;
        }
    });

    ThemePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_theme));
                        return false;
                    } else {
                        ((SettingsActivity) getActivity()).reloadSettings();
                        return true;
                    }
                }
            });

    MultiServerPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.multi_server));
                        return false;
                    }
                    return true;
                }
            });

    ServerSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (!MultiServerPreference.isChecked()) {
                Intent intent = new Intent(mContext, ServerSettingsActivity.class);
                startActivity(intent);
            } else {
                Intent intent = new Intent(mContext, ServerListSettingsActivity.class);
                startActivity(intent);
            }
            return true;
        }
    });

    FingerPrintSettingsPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    mContext.startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
                    return true;
                }
            });

    fetchServerConfig
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    UsefulBits.getServerConfigForActiveServer(mContext, true, new ConfigReceiver() {
                        @Override
                        public void onReceiveConfig(ConfigInfo settings) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_success));
                        }

                        @Override
                        public void onError(Exception error) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_failed));
                        }
                    }, null);
                    return true;
                }
            });

    displayLanguage
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    showRestartMessage();
                    return true;
                }
            });

    registrationId.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!PermissionsUtil.canAccessDeviceState(mContext)) {
                    permissionHelper.request(PermissionsUtil.INITIAL_DEVICE_PERMS);
                } else {
                    pushGCMRegistrationIds();
                }
            } else {
                pushGCMRegistrationIds();
            }
            return true;
        }
    });

    GeoSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.geofence));
                return false;
            } else {
                Intent intent = new Intent(mContext, GeoSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    EnableNFCPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_nfc));
                        return false;
                    }

                    if (NfcAdapter.getDefaultAdapter(mContext) == null) {
                        showSnackbar(mContext.getString(R.string.nfc_not_supported));
                        return false;
                    }
                    return true;
                }
            });

    EnableQRCodePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    }

                    return true;
                }
            });

    EnableSpeechPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    }
                    return true;
                }
            });

    EnableTalkBackPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_talk_back));
                        return false;
                    }
                    return true;
                }
            });

    NFCPreference.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.category_nfc));
                return false;
            } else {
                Intent intent = new Intent(mContext, NFCSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    QRCodePreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, QRCodeSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    SpeechPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, SpeechSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    WearPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_wear));
                        return false;
                    }
                    return true;
                }
            });

    AlwaysOnPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.always_on_title));
                        return false;
                    }
                    return true;
                }
            });

    NotificationLogged
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    //show dialog
                    List<String> logs = mSharedPrefs.getLoggedNotifications();
                    if (logs != null && logs.size() > 0) {
                        Collections.reverse(logs);
                        new MaterialDialog.Builder(mContext)
                                .title(mContext.getString(R.string.notification_show_title))
                                .items((CharSequence[]) logs.toArray(new String[0])).show();
                    } else
                        UsefulBits.showSimpleToast(mContext, getString(R.string.notification_show_nothing),
                                Toast.LENGTH_LONG);
                    return true;
                }
            });

    //noinspection PointlessBooleanExpression
    if (!BuildConfig.LITE_VERSION) {
        preferenceScreen.removePreference(premiumCategory);
    } else {
        premiumPreference
                .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(android.preference.Preference preference) {
                        String packageID = mContext.getPackageName() + ".premium";
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("market://details?id=" + packageID)));
                        } catch (android.content.ActivityNotFoundException ignored) {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("https://play.google.com/store/apps/details?id=" + packageID)));
                        }

                        return true;
                    }
                });
    }

    resetApplication
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        new MaterialDialog.Builder(mContext).title(R.string.category_Reset)
                                .content(R.string.are_you_sure).positiveText(R.string.ok)
                                .negativeText(R.string.cancel)
                                .onPositive(new MaterialDialog.SingleButtonCallback() {
                                    @SuppressLint("NewApi")
                                    @Override
                                    public void onClick(@NonNull MaterialDialog dialog,
                                            @NonNull DialogAction which) {
                                        ((ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE))
                                                .clearApplicationUserData();
                                    }
                                }).show();
                    } else {
                        startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
                    }
                    return true;
                }
            });

    FingerPrintPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @SuppressLint("NewApi")
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object o) {
                    if (mSharedPrefs.isStartupSecurityEnabled())
                        return true;
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_startup_security));
                        return false;
                    } else {
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                            UsefulBits.showSimpleToast(mContext, getString(R.string.fingerprint_not_supported),
                                    Toast.LENGTH_LONG);
                            return false;
                        }
                        if (!PermissionsUtil.canAccessFingerprint(mContext)) {
                            permissionHelper.request(PermissionsUtil.INITIAL_FINGERPRINT_PERMS);
                        } else {
                            FingerprintManager fingerprintManager = (FingerprintManager) mContext
                                    .getSystemService(Context.FINGERPRINT_SERVICE);
                            if (ActivityCompat.checkSelfPermission(mContext,
                                    Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
                                return false;
                            }
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                if (!fingerprintManager.isHardwareDetected()) {
                                    return false;
                                } else if (!fingerprintManager.hasEnrolledFingerprints()) {
                                    UsefulBits.showSimpleToast(mContext,
                                            getString(R.string.fingerprint_not_setup_in_android),
                                            Toast.LENGTH_LONG);
                                    return false;
                                } else {
                                    new MaterialDialog.Builder(mContext)
                                            .title(R.string.category_startup_security)
                                            .content(R.string.fingerprint_sure).positiveText(R.string.ok)
                                            .negativeText(R.string.cancel)
                                            .onPositive(new MaterialDialog.SingleButtonCallback() {
                                                @Override
                                                public void onClick(@NonNull MaterialDialog dialog,
                                                        @NonNull DialogAction which) {
                                                    mSharedPrefs.setStartupSecurityEnabled(true);
                                                    ((SettingsActivity) getActivity()).reloadSettings();
                                                }
                                            }).show();

                                    return false;
                                }
                            }
                        }
                    }
                    return false;
                }
            });
}