/** * Init single Preference */ protected void initPrefsSummary(SharedPreferences sharedPreferences, Preference p) { if (p instanceof PreferenceCategory) { PreferenceCategory pCat = (PreferenceCategory) p; int pcCatCount = pCat.getPreferenceCount(); for (int i = 0; i < pcCatCount; i++) { initPrefsSummary(sharedPreferences, pCat.getPreference(i)); } } else { updatePrefsSummary(sharedPreferences, p); if (p instanceof RingtonePreference) { p.setOnPreferenceChangeListener(new RingToneOnPreferenceChangeListener()); mRingtonePreference = (RingtonePreference) p; } } }
@Override public void onCreatePreferences(Bundle bundle, String s) { super.onCreatePreferences(bundle, s); // Get our screen which is created in Skin SettingsFragment PreferenceScreen screen = getPreferenceScreen(); // Get profile preference PreferenceCategory category = (PreferenceCategory) screen.findPreference(KEY_PROFILE); // If category exists, we should add mole mapper specific things. If not, that means we // are not consented so we have no data to set. if(category != null) { // Example Preference Preference checkBoxPref = new Preference(screen.getContext()); checkBoxPref.setKey(KEY_EXAMPLE); checkBoxPref.setTitle("Example Title"); checkBoxPref.setSummary("You need to extend your settings fragment from Skin's " + "Settings fragment and then modify any preferences that you'd like"); category.addPreference(checkBoxPref); } }
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { getPreferenceManager().setSharedPreferencesName(Constants.PREF_NAME); addPreferencesFromResource(R.xml.monitor); suVersion = Tools.SuVersion(getActivity()); isCMSU = Tools.SuVersionBool(suVersion); mMonitor = (PreferenceCategory) findPreference("monitor_su"); mPerAppDontCare = (Preference) findPreference("per_app_dontcare"); mPerAppActive = (Preference) findPreference("per_app_active"); mAutoRestartSU = (SwitchPreference) findPreference("auto_restart_su"); mAutoRestartISU = (SwitchPreference) findPreference("auto_restart_isu"); mPerAppDeactive = (Preference) findPreference("per_app_deactive"); mMonitorView = (Preference) findPreference("per_app_view"); mMonitorWarning = (Preference) findPreference("per_app_warning"); mAutoRestartSU.setOnPreferenceChangeListener(this); mAutoRestartISU.setOnPreferenceChangeListener(this); }
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { switch(key) { case KEY_APP_MOLE_NAMING: String defaultNamingConvention = Integer.toString(MoleNameHelper.Gender.RANDOM.ordinal()); String currentNamingConvInt = sharedPreferences.getString(key, defaultNamingConvention); int currentNamingOrdinal = Integer.parseInt(currentNamingConvInt); // Get App Category PreferenceCategory categoryNaming = (PreferenceCategory) getPreferenceScreen().findPreference( KEY_APP); // Get naming pref and change summary string Preference namingConventionPref = categoryNaming.findPreference(KEY_APP_MOLE_NAMING); namingConventionPref.setSummary(MoleNameHelper.Gender.values()[currentNamingOrdinal] .getNameResourceId()); break; default: super.onSharedPreferenceChanged(sharedPreferences, key); break; } }
private void testDynamicPrefs() { final Context ctx = getPreferenceManager().getContext(); // this is the material styled context final PreferenceCategory dynamicCategory = (PreferenceCategory) findPreference("pref_categ"); Preference prefAdd = findPreference("pref_add"); if (prefAdd != null) { prefAdd.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { private int n = 0; @Override public boolean onPreferenceClick(Preference preference) { Preference newPreference = new Preference(ctx); newPreference.setTitle("New preference " + n++); newPreference.setSummary(Long.toString(System.currentTimeMillis())); if (dynamicCategory != null) { dynamicCategory.addPreference(newPreference); } return true; } }); } }
@Override public void onCreatePreferences(Bundle bundle, String s) { super.addPreferencesFromResource(R.xml.rss_settings); // Get our screen which is created in Skin SettingsFragment PreferenceScreen screen = getPreferenceScreen(); screen.getSharedPreferences().registerOnSharedPreferenceChangeListener(this); profileCategory = (PreferenceCategory) screen.findPreference(KEY_PROFILE); privacyCategory = (PreferenceCategory) screen.findPreference(KEY_PRIVACY); sharingScope = privacyCategory.findPreference(KEY_SHARING_OPTIONS); generalCategory = (PreferenceCategory) screen.findPreference(KEY_GENERAL); leaveStudy = generalCategory.findPreference(KEY_LEAVE_STUDY); joinStudy = generalCategory.findPreference(KEY_JOIN_STUDY); // Set version string screen.findPreference(KEY_VERSION).setSummary(getVersionString()); }
private void setMax(AudioManager audioManager, int catID, int key, int index) { PreferenceCategory cat = (PreferenceCategory)findPreference(getString(catID)); ((SeekBarPreference)cat.findPreference(getString(key))).setMax(audioManager.getStreamMaxVolume(index)); }
@SuppressWarnings("ConstantConditions") private void configureDisplayStatuses() { PreferenceCategory displayCategory = (PreferenceCategory) findPreference(PREF_ACCOUNT_DISPLAY_CATEGORY); Preference displayStatuses = findPreference(PREF_ACCOUNT_DISPLAY_STATUSES); boolean supportAccountStatus = ModelHelper.getGerritApi(getActivity()).supportsFeature( Features.ACCOUNT_STATUS, mAccount.mServerVersion); if (!supportAccountStatus) { displayCategory.removePreference(displayStatuses); } }
private void configureToggleTagged() { PreferenceCategory messagesCategory = (PreferenceCategory) findPreference(PREF_ACCOUNT_MESSAGES_CATEGORY); Preference toggleTagged = findPreference(PREF_ACCOUNT_TOGGLE_TAGGED_MESSAGES); if (toggleTagged != null) { final GerritApi api = ModelHelper.getGerritApi(getActivity()); boolean supportTaggedMessages = api != null && api.supportsFeature(Features.TAGGED_MESSAGES); if (!supportTaggedMessages) { messagesCategory.removePreference(toggleTagged); } } }
private void configureToggleCI() { PreferenceCategory messagesCategory = (PreferenceCategory) findPreference(PREF_ACCOUNT_MESSAGES_CATEGORY); Preference toggleCI = findPreference(PREF_ACCOUNT_TOGGLE_CI_MESSAGES); if (toggleCI != null) { Repository repository = ModelHelper.findRepositoryForAccount(getContext(), mAccount); if (repository == null || TextUtils.isEmpty(repository.mCiAccounts)) { messagesCategory.removePreference(toggleCI); } } }
private void configureNotifications() { // Fetch or join current loader if (mNotificationsSupportLoader == null) { RxLoaderManager loaderManager = RxLoaderManagerCompat.get(this); mNotificationsSupportLoader = loaderManager.create( checkNotificationsSupport(), mNotificationsSupportObserver); } mNotificationsCategory = (PreferenceCategory) findPreference(PREF_ACCOUNT_NOTIFICATIONS_CATEGORY); mNotificationsAdvise = findPreference(PREF_ACCOUNT_NOTIFICATIONS_ADVISE); mNotificationsAdvise.setOnPreferenceClickListener(this); mNotificationsEnabled = findPreference(Constants.PREF_ACCOUNT_NOTIFICATIONS); mNotificationsEvents = findPreference(Constants.PREF_ACCOUNT_NOTIFICATIONS_EVENTS); if (!mAccount.hasAuthenticatedAccessMode()) { if (mNotificationsCategory != null) { getPreferenceScreen().removePreference(mNotificationsCategory); mNotificationsCategory = null; } } else if (mAccount.hasNotificationsSupport()) { enableNotificationsSupport(); } else { // Check notification support to server mNotificationsSupportLoader.restart(); } }
private void configureHandleLinks() { PreferenceCategory category = (PreferenceCategory) findPreference(PREF_ACCOUNT_EXTERNAL_CATEGORY); mHandleLinks = (TwoStatePreference) findPreference(PREF_ACCOUNT_HANDLE_LINKS); if (!ModelHelper.canAccountHandleUrls(getContext(), mAccount)) { if (mHandleLinks != null) { category.removePreference(mHandleLinks); mHandleLinks = null; } } else { mHandleLinks.setChecked(Preferences.isAccountHandleLinks(getContext(), mAccount) && ModelHelper.isAccountUrlHandlingEnabled(getContext(), mAccount)); mHandleLinks.setOnPreferenceChangeListener(this); } }
private void configureAttachments() { PreferenceCategory category = (PreferenceCategory) findPreference(PREF_ACCOUNT_ATTACHMENTS_CATEGORY); if (category != null && AttachmentsProviderFactory.getAllAvailableAttachmentProviders().size() == 0) { getPreferenceScreen().removePreference(category); } }
private void configureContinuousIntegration() { PreferenceCategory category = (PreferenceCategory) findPreference(PREF_ACCOUNT_CI_CATEGORY); if (category != null) { Repository repository = ModelHelper.findRepositoryForAccount(getActivity(), mAccount); if (repository == null || TextUtils.isEmpty(repository.mCiAccounts)) { getPreferenceScreen().removePreference(category); } } }
private void loadConnectionPreferences(){ this.rootPref = getPreferenceScreen(); this.usbPrefs = (PreferenceCategory) findPreference("pref_usb"); this.tcpPrefs = (PreferenceCategory) findPreference("pref_server"); this.udpPrefs = (PreferenceCategory) findPreference("pref_server_udp"); this.bluetoothPrefs = (PreferenceCategory) findPreference("pref_bluetooth"); }
/** * Adds libraries to its PreferenceCategory programmatically. */ private void setupLibrariesPreference(PreferenceScreen preferenceScreen) { PreferenceCategory preferenceCategory = (PreferenceCategory) preferenceScreen.findPreference(getString(R.string.pref_key_libraries)); Context context = preferenceCategory.getContext(); for (@Size(2) String[] libraryInfos : getLibrariesInfos()) { Preference preference = new Preference(context); preference.setTitle(libraryInfos[0]); preference.setPersistent(false); // put this library's license path to extra preference.getExtras().putString(EXTRAS_LIBRARY_OR_FILE_OPEN_SOURCE_LICENSE_FILE_PATH, ASSET_PATH_OPEN_SOURCE_LICENSES_LIBRARY + libraryInfos[1]); preferenceCategory.addPreference(preference); } }
/** * Adds files to its PreferenceCategory programmatically. */ private void setupFilesPreference(PreferenceScreen preferenceScreen) { PreferenceCategory preferenceCategory = (PreferenceCategory) preferenceScreen.findPreference(getString(R.string.pref_key_files)); Context context = preferenceCategory.getContext(); for (@Size(2) String[] fileInfos : getFilesInfo()) { Preference preference = new Preference(context); preference.setTitle(fileInfos[0]); preference.setPersistent(false); // put this file's license path to extra preference.getExtras().putString(EXTRAS_LIBRARY_OR_FILE_OPEN_SOURCE_LICENSE_FILE_PATH, ASSET_PATH_OPEN_SOURCE_LICENSES_FILE + fileInfos[1]); preferenceCategory.addPreference(preference); } }
@Override public void onDataReady() { super.onDataReady(); // Get profile category PreferenceCategory profileCat = (PreferenceCategory) getPreferenceScreen().findPreference( KEY_PROFILE); // If exists, load users occupation if(profileCat != null) { Preference professionPref = profileCat.findPreference(KEY_PROFILE_PROFESSION); Observable.defer(() -> Observable.just(StorageAccess.getInstance() .getAppDatabase() .loadStepResults(MoleMapperInitialTask.PROFESSION))) .compose(ObservableUtils.applyDefault()) .filter(list -> list != null && ! list.isEmpty()) .subscribe(steps -> { StepResult<String> occupationResult = steps.get(0); if(occupationResult != null && ! TextUtils.isEmpty(occupationResult.getResult())) { StringBuilder occupation = new StringBuilder(occupationResult.getResult()); occupation.setCharAt(0, Character.toUpperCase(occupation.charAt(0))); professionPref.setSummary(occupation.toString()); } }); } }
@Override public void onCreatePreferences(Bundle bundle, String s) { Injector.obtain(getContext()).inject(this); addPreferencesFromResource(R.xml.pref_general); bindPreferenceSummaryToValue( findPreference(R.string.pref_key_rotate_interval), rotateIntervalPref); muzeiPref = (IntegrationPreference) findPreference(R.string.pref_key_muzei_integration); muzeiPref.setPersistent(true); integrationsCategory = (PreferenceCategory) findPreference(R.string.pref_key_category_integrations); }
@Override public void onCreatePreferences(Bundle bundle, String s) { // dependency injection ((RingApplication) getActivity().getApplication()).getRingInjectionComponent().inject(this); super.onCreatePreferences(bundle, s); addPreferencesFromResource(R.xml.account_security_prefs); credentialsCategory = (PreferenceCategory) findPreference("Account.credentials"); credentialsCategory.findPreference("Add.credentials").setOnPreferenceChangeListener(addCredentialListener); tlsCategory = (PreferenceCategory) findPreference("TLS.category"); presenter.init(getArguments().getString(AccountEditionActivity.ACCOUNT_ID_KEY)); }
public void fillAccountPreferences( PreferenceGroup screen, final Account account) { final IGISApplication appContext = (IGISApplication) mStyledContext.getApplicationContext(); // add sync settings group PreferenceCategory syncCategory = new PreferenceCategory(mStyledContext); syncCategory.setTitle(R.string.sync); screen.addPreference(syncCategory); // add auto sync property addAutoSyncProperty(appContext, account, syncCategory); // add time for periodic sync addPeriodicSyncTime(appContext, account, syncCategory); // add account layers addAccountLayers(screen, appContext, account); // add actions group PreferenceCategory actionCategory = new PreferenceCategory(mStyledContext); actionCategory.setTitle(R.string.actions); screen.addPreference(actionCategory); // add "Edit account" action addEditAccountAction(appContext, account, actionCategory); // add delete account action addDeleteAccountAction(appContext, account, actionCategory); // TODO: for isMultiPane() change title of Settings fragment, not of Activity // if (mChangeTitle && !NGPreferenceActivity.isMultiPane(mActivity)) { if (mChangeTitle) { ActionBar ab = mActivity.getSupportActionBar(); if (null != ab) { ab.setTitle(account.name); } } }
private void updateContent() { PreferenceScreen root = getPreferenceScreen(); if (McsService.isConnected()) { root.findPreference(PREF_GCM_STATUS).setSummary(getString(R.string.gcm_state_connected, DateUtils.getRelativeTimeSpanString(McsService.getStartTimestamp(), System.currentTimeMillis(), 0))); } else { root.findPreference(PREF_GCM_STATUS).setSummary(getString(R.string.gcm_state_disconnected)); } PreferenceCategory appList = (PreferenceCategory) root.findPreference(PREF_GCM_APPS); appList.removeAll(); List<GcmDatabase.App> list = database.getAppList(); if (!list.isEmpty()) { List<Preference> appListPrefs = new ArrayList<>(); PackageManager pm = getContext().getPackageManager(); for (GcmDatabase.App app : list) { try { pm.getApplicationInfo(app.packageName, 0); appListPrefs.add(new GcmAppPreference(getPreferenceManager().getContext(), app)); } catch (PackageManager.NameNotFoundException e) { final List<GcmDatabase.Registration> registrations = database.getRegistrationsByApp(app.packageName); if (registrations.isEmpty()) { database.removeApp(app.packageName); } else { appListPrefs.add(new GcmAppPreference(getPreferenceManager().getContext(), app)); } } } addPreferencesSorted(appListPrefs, appList); } else { // If there's no item to display, add a "None" item. Preference banner = new Preference(getPreferenceManager().getContext()); banner.setLayoutResource(R.layout.list_no_item); banner.setTitle(R.string.list_no_item_none); banner.setSelectable(false); appList.addPreference(banner); } }
private void setUpCookies(@NonNull PreferenceCategory cat) { List<String> domains = Prefs.getCookieDomainsAsList(); for (String domain : domains) { String key = Prefs.getCookiesForDomainKey(domain); Preference pref = newDataStringPref(key, domain); cat.addPreference(pref); } }
private void populateNewsSources() { PreferenceCategory newsSourcesPreference = (PreferenceCategory) findPreference("card_news_sources"); NewsManager newsManager = new NewsManager(mContext); List<NewsSources> newsSources = newsManager.getNewsSources(); final NetUtils net = new NetUtils(mContext); for (NewsSources newsSource: newsSources) { final CheckBoxPreference pref = new CheckBoxPreference(mContext); pref.setKey("card_news_source_" + newsSource.getId()); pref.setDefaultValue(true); // Load news source icon in background and set it final String url = newsSource.getIcon(); if (url != null) { // Skip News that do not have a image new Thread(() -> { final Optional<Bitmap> bmp = net.downloadImageToBitmap(url); mContext.runOnUiThread(() -> { if (bmp.isPresent()) { pref.setIcon(new BitmapDrawable(getResources(), bmp.get())); } }); }).start(); } pref.setTitle(newsSource.getTitle()); if(newsSourcesPreference!=null) { newsSourcesPreference.addPreference(pref); } } }
private void initSummary(Preference pref) { if (pref instanceof PreferenceScreen) { final PreferenceScreen screen = (PreferenceScreen) pref; for (int i = 0; i < screen.getPreferenceCount(); i++) initSummary(screen.getPreference(i)); } else if (pref instanceof PreferenceCategory) { final PreferenceCategory category = (PreferenceCategory) pref; for (int i = 0; i < category.getPreferenceCount(); i++) initSummary(category.getPreference(i)); } else updatePrefSummary(pref); }
private void init() { addPreferencesFromResource(R.xml.settings); if (Utils.DONATED) { getPreferenceScreen().removePreference(findPreference(KEY_AD_VIEW)); } SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH); if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) { getPreferenceScreen().removePreference(forceEnglish); } else { forceEnglish.setOnPreferenceChangeListener(this); } /* if (Utils.hideStartActivity()) { ((PreferenceCategory) findPreference(KEY_USER_INTERFACE)) .removePreference(findPreference(KEY_MATERIAL_ICON)); } else { findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this); } */ findPreference(KEY_RESET_DATA).setOnPreferenceClickListener(this); findPreference(KEY_UPDATE_NOTIFICATION).setOnPreferenceChangeListener(this); findPreference(KEY_CHECK_UPDATE).setOnPreferenceClickListener(this); findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this); findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this); findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this); findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this); findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this); findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this); findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this); if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) { findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this); } else { ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference( findPreference(KEY_LAST_KMSG)); } findPreference(KEY_DMESG).setOnPreferenceClickListener(this); findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this); findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) { ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference( findPreference(KEY_FINGERPRINT)); } else { mFingerprint = findPreference(KEY_FINGERPRINT); mFingerprint.setEnabled(!Prefs.getString("password", "", getActivity()).isEmpty()); } PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS); for (NavigationActivity.NavigationFragment navigationFragment : NavigationActivity.sFragments) { Fragment fragment = navigationFragment.mFragment; int id = navigationFragment.mId; if (fragment != null && fragment.getClass() != SettingsFragment.class) { SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat( new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material)); switchPreference.setSummary(getString(id)); switchPreference.setKey(fragment.getClass().getSimpleName() + "_enabled"); switchPreference.setChecked(Prefs.getBoolean(fragment.getClass().getSimpleName() + "_enabled", true, getActivity())); switchPreference.setOnPreferenceChangeListener(this); switchPreference.setPersistent(false); sectionsCategory.addPreference(switchPreference); } } }
private void init() { addPreferencesFromResource(R.xml.settings); if (Utils.DONATED) { getPreferenceScreen().removePreference(findPreference(KEY_AD_VIEW)); } SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH); if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) { getPreferenceScreen().removePreference(forceEnglish); } else { forceEnglish.setOnPreferenceChangeListener(this); } if (Utils.hideStartActivity()) { ((PreferenceCategory) findPreference(KEY_USER_INTERFACE)) .removePreference(findPreference(KEY_MATERIAL_ICON)); } else { findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this); } findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this); findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this); findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this); findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this); findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this); findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this); findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this); if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) { findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this); } else { ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference( findPreference(KEY_LAST_KMSG)); } findPreference(KEY_DMESG).setOnPreferenceClickListener(this); findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this); findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) { ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference( findPreference(KEY_FINGERPRINT)); } else { mFingerprint = findPreference(KEY_FINGERPRINT); mFingerprint.setEnabled(!Prefs.getString("password", "", getActivity()).isEmpty()); } PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS); for (NavigationActivity.NavigationFragment navigationFragment : NavigationActivity.sFragments) { Fragment fragment = navigationFragment.mFragment; int id = navigationFragment.mId; if (fragment != null && fragment.getClass() != SettingsFragment.class) { SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat( new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material)); switchPreference.setSummary(getString(id)); switchPreference.setKey(fragment.getClass().getSimpleName() + "_enabled"); switchPreference.setChecked(Prefs.getBoolean(fragment.getClass().getSimpleName() + "_enabled", true, getActivity())); switchPreference.setOnPreferenceChangeListener(this); switchPreference.setPersistent(false); sectionsCategory.addPreference(switchPreference); } } }
private void configureDashboard() { if (mAccount == null || !mAccount.hasAuthenticatedAccessMode()) { PreferenceCategory dashboardCategory = (PreferenceCategory) findPreference(PREF_ACCOUNT_DASHBOARD_CATEGORY); getPreferenceScreen().removePreference(dashboardCategory); } }
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { getPreferenceManager().setSharedPreferencesName(Constants.PREF_NAME); addPreferencesFromResource(R.xml.controls); suVersion = Tools.SuVersion(getActivity()); isCMSU = Tools.SuVersionBool(suVersion); rootAccess = Tools.rootAccess(getActivity()); mControls = (PreferenceCategory) findPreference("controls_su"); mSuSwitch = (SwitchPreference) findPreference("su_switch"); mSuSwitch.setOnPreferenceChangeListener(this); mSelSwitch = (SwitchPreference) findPreference("selinux_switch"); mSelSwitch.setOnPreferenceChangeListener(this); mFakeSelSwitch = (SwitchPreference) findPreference("fake_selinux_switch"); mFakeSelSwitch.setOnPreferenceChangeListener(this); mDebug = (SwitchPreference) findPreference("android_debug"); mDebug.setOnPreferenceChangeListener(this); mDebugRoot = (SwitchPreference) findPreference("android_debug_root"); mDebugRoot.setOnPreferenceChangeListener(this); mControlsView = (Preference) findPreference("controls_view"); mTasker = (Preference) findPreference("tasker"); mTasker.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { String options = Constants.TASKER_SU_ON + "\n" + Constants.TASKER_SU_OFF + "\n" + Constants.TASKER_SU_INV + "\n\n" + Constants.TASKER_SELINUX_ON + "\n" + Constants.TASKER_SELINUX_OFF + "\n" + Constants.TASKER_SELINUX_INV + "\n\n" + Constants.TASKER_DEBUG_ON + "\n" + Constants.TASKER_DEBUG_OFF + "\n" + Constants.TASKER_DEBUG_INV + "\n\n" + getString(R.string.tasker_help_extra_description) + "su = " + getString(R.string.su_switch) + "\n" + "selinux = " + getString(R.string.selinux_switch) + "\n" + "debug = " + getString(R.string.anddebug_change) + "\n\n" + "on = " + String.format(getString(R.string.tasker_help_extra_state), getString(R.string.activated)) + "off = " + String.format(getString(R.string.tasker_help_extra_state), getString(R.string.deactivated)) + "inverse = " + getString(R.string.tasker_help_inv); Tools.SimpleDialog(String.format(getString(R.string.tasker_help), options), getActivity()); return true; } }); }
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { getPreferenceManager().setSharedPreferencesName(Constants.PREF_NAME); addPreferencesFromResource(R.xml.settings); mSettingsPref = (PreferenceCategory) findPreference("settings_pref"); mSettingsView = (Preference) findPreference("settings_view"); mSettingsForceEnglish = (SwitchPreference) findPreference("forceenglish"); mSettingsForceEnglish.setOnPreferenceChangeListener(this); mSettingsSU = (PreferenceCategory) findPreference("su_settings_pref"); mSettingsMonitor = (PreferenceCategory) findPreference("monitor_settings"); mSettingsNotifications = (PreferenceCategory) findPreference("notifications_settings_pref"); mSettingsSelinux = (PreferenceCategory) findPreference("selinux_settings_pref"); mSettingsDebug = (PreferenceCategory) findPreference("anddebug_settings_pref"); mSettingsProps = (PreferenceCategory) findPreference("props_settings_pref"); mApplySuDelay = (ListPreference) findPreference("apply_su_delay"); mApplyMonitorDelay = (ListPreference) findPreference("allow_delay"); CharSequence[] entriesSuDelay = new CharSequence[6]; CharSequence[] entryValuesSuDelay = new CharSequence[6]; for (int i = 0; i < 6; i++) { entriesSuDelay[i] = (String.format(getString(R.string.apply_su_delay_summary), ((i + 1) * 10))); entryValuesSuDelay[i] = String.valueOf((i + 1) * 10000); } mApplySuDelay.setEntries(entriesSuDelay); mApplySuDelay.setEntryValues(entryValuesSuDelay); CharSequence[] entriesMonitorDelay = new CharSequence[7]; CharSequence[] entryValuesMonitorDelay = new CharSequence[7]; for (int i = 0; i < 7; i++) { if (i == 0) { entriesMonitorDelay[i] = getString(R.string.disable); entryValuesMonitorDelay[i] = String.valueOf(i); } else { entriesMonitorDelay[i] = (String.format(getString(R.string.apply_su_delay_summary), ((i) * 5))); entryValuesMonitorDelay[i] = String.valueOf((i) * 5000); } } mApplyMonitorDelay.setEntries(entriesMonitorDelay); mApplyMonitorDelay.setEntryValues(entryValuesMonitorDelay); suVersion = Tools.SuVersion(getActivity()); isCMSU = Tools.SuVersionBool(suVersion); if (!isCMSU) { mSettingsSU.setEnabled(false); mSettingsMonitor.setEnabled(false); mSettingsNotifications.setEnabled(false); mSettingsSelinux.setEnabled(false); mSettingsDebug.setEnabled(false); if (!Tools.rootAccess(getActivity())) { mSettingsView.setSummary(getString(R.string.device_not_root)); mSettingsProps.setEnabled(false); } } else mSettingsPref.removePreference(mSettingsView); }
@Override public void onCreatePreferences(Bundle bundle, String s) { super.onCreatePreferences(bundle, s); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences( getContext()); // Get our screen which is created in Skin SettingsFragment PreferenceScreen screen = getPreferenceScreen(); // Get profile preference PreferenceCategory category = (PreferenceCategory) screen.findPreference(KEY_PROFILE); // If category exists, we should add mole mapper specific things. If not, that means we // are not consented so we have no data to set. if(category != null) { // Occupation Preference Preference checkBoxPref = new Preference(screen.getContext()); checkBoxPref.setKey(KEY_PROFILE_PROFESSION); checkBoxPref.setTitle(R.string.profession); checkBoxPref.setSummary(R.string.profession_unknown); // Set to prevent a "jump" when first entering the screen category.addPreference(checkBoxPref); } // Create the app category to place out two rpefs PreferenceCategory appCategory = new PreferenceCategory(screen.getContext()); appCategory.setKey(KEY_APP); appCategory.setTitle(R.string.settings_app); appCategory.setOrder(1); screen.addPreference(appCategory); // Generate values for the mole naming convention pref MoleNameHelper.Gender[] values = MoleNameHelper.Gender.values(); String[] entries = new String[values.length]; String[] entryValues = new String[values.length]; for(int i = 0; i < values.length; i++) { MoleNameHelper.Gender gender = values[i]; entries[i] = getString(gender.getNameResourceId()); entryValues[i] = Integer.toString(i); } // Create ListPreference and add to "App" category String defaultNamingConvention = Integer.toString(MoleNameHelper.Gender.RANDOM.ordinal()); ListPreference namingConventionPref = new ListPreference(screen.getContext()); namingConventionPref.setTitle(R.string.settings_app_mole_name_scheme); namingConventionPref.setKey(KEY_APP_MOLE_NAMING); namingConventionPref.setDefaultValue(defaultNamingConvention); namingConventionPref.setEntries(entries); namingConventionPref.setEntryValues(entryValues); namingConventionPref.setDialogTitle(R.string.settings_app_mole_name_scheme); String currentNamingConvInt = sharedPreferences.getString(KEY_APP_MOLE_NAMING, defaultNamingConvention); int currentNamingOrdinal = Integer.parseInt(currentNamingConvInt); namingConventionPref.setSummary(values[currentNamingOrdinal].getNameResourceId()); appCategory.addPreference(namingConventionPref); }
@Override public void onCreatePreferences(Bundle bundle, String s) { addPreferencesFromResource(R.xml.settings); if (Utils.DONATED) { getPreferenceScreen().removePreference(findPreference(KEY_AD_VIEW)); } SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH); if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) { getPreferenceScreen().removePreference(forceEnglish); } else { forceEnglish.setOnPreferenceChangeListener(this); } if (Utils.hideStartActivity()) { ((PreferenceCategory) findPreference(KEY_USER_INTERFACE)) .removePreference(findPreference(KEY_MATERIAL_ICON)); } else { findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this); } findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this); findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this); findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this); findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this); findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this); findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this); findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this); if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) { findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this); } else { ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference( findPreference(KEY_LAST_KMSG)); } findPreference(KEY_DMESG).setOnPreferenceClickListener(this); findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this); findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) { ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference( findPreference(KEY_FINGERPRINT)); } else { mFingerprint = findPreference(KEY_FINGERPRINT); mFingerprint.setEnabled(!Prefs.getString("password", "", getActivity()).isEmpty()); } NavigationActivity activity = (NavigationActivity) getActivity(); PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS); for (NavigationActivity.NavigationFragment navigationFragment : activity.getFragments()) { Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass; int id = navigationFragment.mId; if (fragmentClass != null && fragmentClass != SettingsFragment.class) { SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat( new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material)); switchPreference.setSummary(getString(id)); switchPreference.setKey(fragmentClass.getSimpleName() + "_enabled"); switchPreference.setChecked(Prefs.getBoolean(fragmentClass.getSimpleName() + "_enabled", true, getActivity())); switchPreference.setOnPreferenceChangeListener(this); switchPreference.setPersistent(false); sectionsCategory.addPreference(switchPreference); } } }