Java Code Examples for android.preference.ListPreference#setOnPreferenceChangeListener()

The following examples show how to use android.preference.ListPreference#setOnPreferenceChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DobroModule.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
private void addRatingPreference(PreferenceGroup group) {
    Context context = group.getContext();
    Preference.OnPreferenceChangeListener updateRatingListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals(getSharedKey(PREF_KEY_MAX_RATING))) {
                setMaxRating((String) newValue);
                return true;
            }
            return false;
        }
    };
    ListPreference ratingPref = new LazyPreferences.ListPreference(context);
    ratingPref.setTitle(R.string.dobrochan_prefs_max_rating);
    ratingPref.setSummary(preferences.getString(getSharedKey(PREF_KEY_MAX_RATING), "R-15"));
    ratingPref.setEntries(RATINGS);
    ratingPref.setEntryValues(RATINGS);
    ratingPref.setDefaultValue("R-15");
    ratingPref.setKey(getSharedKey(PREF_KEY_MAX_RATING));
    ratingPref.setOnPreferenceChangeListener(updateRatingListener);
    group.addPreference(ratingPref);
}
 
Example 2
Source File: SettingsFragment.java    From SimpleExplorer with GNU General Public License v3.0 6 votes vote down vote up
private void init() {
    final ListPreference theme = (ListPreference) findPreference("preference_theme");
    theme.setEntryValues(THEMES_VALUES);
    theme.setValue(String.valueOf(Settings.getDefaultTheme()));
    theme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final int chosenTheme = Integer.parseInt((String) newValue);
            if (chosenTheme != Settings.getDefaultTheme()) {
                Settings.setDefaultTheme(chosenTheme);
                ((SettingsActivity) getActivity()).proxyRestart();
                return true;
            }
            return false;
        }
    });
}
 
Example 3
Source File: SettingFragment.java    From SmileEssence with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.setting);
    EditTextPreference textSizePreference = (EditTextPreference) findPreference(R.string.key_setting_text_size);
    textSizePreference.setSummary(textSizePreference.getText());
    textSizePreference.setOnPreferenceChangeListener(this);
    ListPreference themePreference = (ListPreference) findPreference(R.string.key_setting_theme);
    themePreference.setSummary(themePreference.getEntry());
    themePreference.setOnPreferenceChangeListener(this);
    ListPreference namestylePreference = (ListPreference) findPreference(R.string.key_setting_namestyle);
    namestylePreference.setSummary(namestylePreference.getEntry());
    EditTextPreference timelinesPreference = (EditTextPreference) findPreference(R.string.key_setting_timelines);
    timelinesPreference.setSummary(String.format(getString(R.string.setting_timelines_summary_format), timelinesPreference.getText()));
    timelinesPreference.setOnPreferenceChangeListener(this);
    Preference appInfoPreference = findPreference(R.string.key_setting_application_information);
    appInfoPreference.setOnPreferenceClickListener(this);
    Preference clearAccount = findPreference(R.string.key_setting_clear_account);
    clearAccount.setOnPreferenceClickListener(this);
    Preference license = findPreference(R.string.key_setting_licenses);
    license.setOnPreferenceClickListener(this);
    Preference clearConsumer = findPreference(R.string.key_setting_clear_consumer);
    clearConsumer.setOnPreferenceClickListener(this);
    appPreferenceHelper = new AppPreferenceHelper(this.getActivity());
}
 
Example 4
Source File: Preferences.java    From Plumble with GNU General Public License v3.0 6 votes vote down vote up
private static void configureAudioPreferences(final PreferenceScreen screen) {
    ListPreference inputPreference = (ListPreference) screen.findPreference(Settings.PREF_INPUT_METHOD);
    inputPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            updateAudioDependents(screen, (String) newValue);
            return true;
        }
    });

    // Scan each bitrate and determine if the device supports it
    ListPreference inputQualityPreference = (ListPreference) screen.findPreference(Settings.PREF_INPUT_RATE);
    String[] bitrateNames = new String[inputQualityPreference.getEntryValues().length];
    for(int x=0;x<bitrateNames.length;x++) {
        int bitrate = Integer.parseInt(inputQualityPreference.getEntryValues()[x].toString());
        boolean supported = AudioRecord.getMinBufferSize(bitrate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT) > 0;
        bitrateNames[x] = bitrate+"Hz" + (supported ? "" : " (unsupported)");
    }
    inputQualityPreference.setEntries(bitrateNames);

    updateAudioDependents(screen, inputPreference.getValue());
}
 
Example 5
Source File: SettingFragment.java    From BetterWay with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    useDefault = (SwitchPreference) findPreference("use_default_image");
    useLocal = (SwitchPreference) findPreference("use_local_image");
    useOnline = (SwitchPreference) findPreference("update_image_online");
    imageLocation = findPreference("local_image_location");
    warnDuration = (ListPreference) findPreference("warning_time");
    updateDuration = (ListPreference) findPreference("update_duration");
    useDefault.setOnPreferenceClickListener(this);
    useLocal.setOnPreferenceClickListener(this);
    useOnline.setOnPreferenceClickListener(this);
    imageLocation.setOnPreferenceClickListener(this);
    warnDuration.setOnPreferenceChangeListener(this);
    updateDuration.setOnPreferenceChangeListener(this);
    warnDuration.setSummary(warnDuration.getEntry());
    updateDuration.setSummary(updateDuration.getEntry());
    SettingFragmentComponent settingFragmentComponent = DaggerSettingFragmentComponent.builder()
            .settingFragmentModule(new SettingFragmentModule(this))
            .build();
    settingFragmentComponent.inject(this);
    mSettingPresenterImpel = settingFragmentComponent.getSettingPresenterImpel();
    initData();
}
 
Example 6
Source File: UiPrefFragment.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private void addLocalePref () {
	final ListPreference pref = new ComboPreference(getActivity());
	pref.setKey(KEY_LOCALE);
	pref.setTitle("Locale"); //ES
	pref.setEntries(SupportedLocales.prefEntries());
	pref.setEntryValues(SupportedLocales.prefEntryValues());
	pref.setDefaultValue(SupportedLocales.DEFAULT.getValue());
	pref.setOnPreferenceChangeListener(this.onLocaleChangeListener);
	getPreferenceScreen().addPreference(pref);
}
 
Example 7
Source File: SettingsMusicLibraryFragment.java    From Rey-MusicPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle onSavedInstanceState) {
    mRootView = super.onCreateView(inflater, container, onSavedInstanceState);
    mContext = getActivity().getApplicationContext();
    mApp = (Common) mContext;
    mListView = (ListView) mRootView.findViewById(android.R.id.list);
    mScanFrequencyPreference=(ListPreference)getPreferenceManager().findPreference("preference_key_scan_frequency");
    mScanFrequencyPreference.setOnPreferenceChangeListener((preference, newValue) -> {
        Logger.log(""+newValue);
        return true;
    });


    mRebuildMusicLibrary = getPreferenceManager().findPreference("preference_key_rebuild_music_library");
    mRebuildMusicLibrary.setOnPreferenceClickListener(preference -> {
        PreferencesHelper.getInstance().put(PreferencesHelper.Key.FIRST_LAUNCH, true);
        //Restart the app.
        Intent i = getActivity().getBaseContext().getPackageManager().getLaunchIntentForPackage(getActivity().getBaseContext().getPackageName());
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        getActivity().finish();
        startActivity(i);
        return false;
    });
    ((SettingActivity) getActivity()).setToolbarTitle(getString(R.string.music_library));

    return mRootView;
}
 
Example 8
Source File: Proxy.java    From YalpStore with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void draw() {
    ListPreference proxyType = (ListPreference) activity.findPreference(PreferenceUtil.PREFERENCE_PROXY_TYPE);
    proxyType.setOnPreferenceChangeListener(new SummaryOnChangeListener());
    refreshSummary(proxyType);
    EditTextPreference proxyHost = (EditTextPreference) activity.findPreference(PreferenceUtil.PREFERENCE_PROXY_HOST);
    proxyHost.setOnPreferenceChangeListener(new SummaryOnChangeListener());
    refreshSummary(proxyHost);
    EditTextPreference proxyPort = (EditTextPreference) activity.findPreference(PreferenceUtil.PREFERENCE_PROXY_PORT);
    proxyPort.setOnPreferenceChangeListener(new SummaryOnChangeListener());
    proxyPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    refreshSummary(proxyPort);
}
 
Example 9
Source File: ThemeSettingsActivity.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	getPreferenceManager().setSharedPreferencesName(SettingsProvider.SETTINGS_KEY);
	addPreferencesFromResource(R.xml.theme_settings);
			
	SharedPreferences sp = getPreferenceManager().getSharedPreferences();
	final String themePackage = sp.getString("themePackageName",
			Launcher.THEME_DEFAULT);
	ListPreference lp = (ListPreference) findPreference("themePackageName");
	lp.setOnPreferenceChangeListener(this);
	Intent intent = new Intent("com.phonemetra.turbo.launcher.THEMES");
	intent.addCategory("android.intent.category.DEFAULT");
	PackageManager pm = getPackageManager();
	List<ResolveInfo> themes = pm.queryIntentActivities(intent, 0);
	String[] entries = new String[themes.size() + 1];
	String[] values = new String[themes.size() + 1];
	entries[0] = Launcher.THEME_DEFAULT;
	values[0] = Launcher.THEME_DEFAULT;
	for (int i = 0; i < themes.size(); i++) {
		String appPackageName = (themes.get(i)).activityInfo.packageName
				.toString();
		String themeName = (themes.get(i)).loadLabel(pm).toString();
		entries[i + 1] = themeName;
		values[i + 1] = appPackageName;
	}
	lp.setEntries(entries);
	lp.setEntryValues(values);
	ThemePreference themePreview = (ThemePreference) findPreference("themePreview");
	themePreview.setTheme(themePackage);
}
 
Example 10
Source File: SettingsFragment.java    From meatspace-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ListPreference urlPreference = (ListPreference) findPreference(getString(R.string.settings_url_key));
    if (urlPreference.getValue() == null) {
        urlPreference.setValue(getString(BuildConfig.MEATSPACE_BASE_URL));
    }
    urlPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            getActivity().sendBroadcast(new Intent(Constants.FILTER_CHAT_CLOSE));
            return true;
        }
    });
}
 
Example 11
Source File: CameraPrefsActivity.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setCameraNumbersForScreen(int screenWidth) {
    int maxCamerasPerRow = 3;
    if (screenWidth != 0) {
        maxCamerasPerRow = screenWidth / 350;
    }
    if (maxCamerasPerRow == 0) {
        maxCamerasPerRow = 1;
    }
    ArrayList<String> cameraNumberArrayList = new ArrayList<String>();
    for (int index = 1; index <= maxCamerasPerRow; index++) {
        cameraNumberArrayList.add(String.valueOf(index));
    }
    CharSequence[] charNumberValues = cameraNumberArrayList.toArray(new
            CharSequence[cameraNumberArrayList.size()]);
    final ListPreference interfaceList = (ListPreference)
            getPreferenceManager().findPreference(PrefsManager.KEY_CAMERA_PER_ROW);
    interfaceList.setEntries(charNumberValues);
    interfaceList.setEntryValues(charNumberValues);
    interfaceList.setSummary(interfaceList.getValue());
    interfaceList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            interfaceList.setSummary(newValue.toString());
            return true;
        }
    });
}
 
Example 12
Source File: Preferences.java    From LauncherTV with Apache License 2.0 5 votes vote down vote up
private void bindSummary(String key, final int resId) {
	final ListPreference p = (ListPreference) findPreference(key);
	setPreferenceSummaryValue(p, resId, p.getValue());
	p.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
		@Override
		public boolean onPreferenceChange(Preference preference, Object newValue) {
			setPreferenceSummaryValue(p, resId, (String) newValue);
			return true;
		}
	});
}
 
Example 13
Source File: SettingsActivity.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.display_settings);

    Resources resources = getResources();

    mPrettyTime = (FixedSwitchPreference) findPreference(Settings.KEY_PRETTY_TIME);
    mTextFormat = findPreference(KEY_TEXT_FORMAT);
    mDynamicComments = findPreference(Settings.KEY_DYNAMIC_COMMENTS);
    mImageLoadingStrategy = (ListPreference) findPreference(Settings.KEY_IMAGE_LOADING_STRATEGY);
    mImageLoadingStrategy2 = (FixedSwitchPreference) findPreference(Settings.KEY_IMAGE_LOADING_STRATEGY_2);
    mFastScroller = (FixedSwitchPreference) findPreference(Settings.KEY_FAST_SCROLLER);
    mColorStatusBar = (FixedSwitchPreference) findPreference(Settings.KEY_COLOR_STATUS_BAR);
    mFixEmojiDisplay = (FixedSwitchPreference) findPreference(Settings.KEY_FIX_EMOJI_DISPLAY);

    mPrettyTime.setOnPreferenceChangeListener(this);
    mDynamicComments.setOnPreferenceChangeListener(this);
    mImageLoadingStrategy.setOnPreferenceChangeListener(this);
    mImageLoadingStrategy2.setOnPreferenceChangeListener(this);
    mFastScroller.setOnPreferenceChangeListener(this);
    mColorStatusBar.setOnPreferenceChangeListener(this);
    mFixEmojiDisplay.setOnPreferenceChangeListener(this);

    mTextFormat.setOnPreferenceClickListener(this);

    long time = System.currentTimeMillis() - 3 * ReadableTime.HOUR_MILLIS;
    String plain = ReadableTime.getPlainTime(time);
    String timeAgo = ReadableTime.getTimeAgo(time);
    mPrettyTime.setSummaryOn(resources.getString(R.string.main_pretty_time_summary, timeAgo, plain));
    mPrettyTime.setSummaryOff(resources.getString(R.string.main_pretty_time_summary, plain, timeAgo));

    updateTextFormatSummary();

    if (Build.VERSION.SDK_INT != Build.VERSION_CODES.KITKAT) {
        mColorStatusBar.setEnabled(false);
        mColorStatusBar.setSummaryOn(R.string.main_color_status_bar_summary_disable);
        mColorStatusBar.setSummaryOff(R.string.main_color_status_bar_summary_disable);
    }
}
 
Example 14
Source File: CameraPrefsActivity.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setUpSleepTime() {
    final ListPreference sleepListPrefs = (ListPreference)
            getPreferenceManager().findPreference(PrefsManager.KEY_AWAKE_TIME);
    sleepListPrefs.setSummary(getSummary(sleepListPrefs.getEntry() + ""));
    sleepListPrefs.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            int index = sleepListPrefs.findIndexOfValue(newValue.toString());
            String entry = sleepListPrefs.getEntries()[index].toString();
            sleepListPrefs.setSummary(getSummary(entry));
            return true;
        }
    });
}
 
Example 15
Source File: SettingsActivity.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private void setUpPreferences() {

            displayLimitPreference = (EditTextPreference) findPreference(getString(R.string.pref_display_limit));

            int displayLimitValue = PreferenceHelper.getDisplayLimitPreference(getActivity());

            displayLimitPreference.setSummary(getString(R.string.pref_display_limit_summary,
                    displayLimitValue, getString(R.string.pref_display_limit_default)));

            displayLimitPreference.setOnPreferenceChangeListener(this);

            logLinePeriodPreference = (EditTextPreference) findPreference(getString(R.string.pref_log_line_period));

            int logLinePrefValue = PreferenceHelper.getLogLinePeriodPreference(getActivity());

            logLinePeriodPreference.setSummary(getString(R.string.pref_log_line_period_summary,
                    logLinePrefValue, getString(R.string.pref_log_line_period_default)));

            logLinePeriodPreference.setOnPreferenceChangeListener(this);

            textSizePreference = (ListPreference) findPreference(getString(R.string.pref_text_size));
            textSizePreference.setSummary(textSizePreference.getEntry());
            textSizePreference.setOnPreferenceChangeListener(this);

            defaultLevelPreference = (ListPreference) findPreference(getString(R.string.pref_default_log_level));
            defaultLevelPreference.setOnPreferenceChangeListener(this);
            setDefaultLevelPreferenceSummary(defaultLevelPreference.getEntry());


            bufferPreference = (MultipleChoicePreference) findPreference(getString(R.string.pref_buffer));
            bufferPreference.setOnPreferenceChangeListener(this);
            setBufferPreferenceSummary(bufferPreference.getValue());

            scrubberPreference = (SwitchPreference) getPreferenceScreen().findPreference("scrubber");
            scrubberPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    LogLine.isScrubberEnabled = (boolean) newValue;
                    return true;
                }
            });
        }
 
Example 16
Source File: MaxLockPreferenceFragment.java    From MaxLock with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("WorldReadableFiles")
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle paramBundle) {
    super.onCreate(paramBundle);
    if (getArguments() != null) {
        screen = Screen.valueOf(getArguments().getString(Screen.KEY, Screen.MAIN.toString()));
    } else {
        screen = Screen.MAIN;
    }
    prefs = MLPreferences.getPreferences(getActivity());
    setTitle();
    if (screen == Screen.IMOD) {
        getPreferenceManager().setSharedPreferencesName(Common.PREFS_APPS);
    }
    addPreferencesFromResource(screen.preferenceXML);
    switch (screen) {
        case MAIN:
            updateImplementationStatus();
            PreferenceCategory catAppUI = (PreferenceCategory) findPreference(Common.CATEGORY_APPLICATION_UI);
            CheckBoxPreference useDark = (CheckBoxPreference) findPreference(Common.USE_DARK_STYLE);
            if (!useDark.isChecked()) {
                catAppUI.removePreference(findPreference(Common.USE_AMOLED_BLACK));
            }
            if (SDK_INT >= Build.VERSION_CODES.O) {
                catAppUI.removePreference(findPreference(Common.NEW_APP_NOTIFICATION));
            }
            break;
        case TYPE:
            FingerprintManagerCompat fpm = FingerprintManagerCompat.from(getActivity());
            if (!fpm.isHardwareDetected()) {
                getPreferenceScreen().removePreference(findPreference(Common.SHADOW_FINGERPRINT));
                getPreferenceScreen().removePreference(findPreference(Common.CATEGORY_FINGERPRINT));
            } else {
                CheckBoxPreference disableFP = (CheckBoxPreference) findPreference(Common.DISABLE_FINGERPRINT);
                if (!fpm.hasEnrolledFingerprints() && !disableFP.isChecked()) {
                    disableFP.setSummary(disableFP.getSummary() + getResources().getString(R.string.pref_fingerprint_summary_non_enrolled));
                }
            }
            break;
        case UI:
            ListPreference lp = (ListPreference) findPreference(Common.BACKGROUND);
            findPreference(Common.BACKGROUND_COLOR).setEnabled(lp.getValue().equals("color"));
            lp.setOnPreferenceChangeListener((preference, newValue) -> {
                if (preference.getKey().equals(Common.BACKGROUND)) {
                    if (newValue.toString().equals("custom")) {
                        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                        intent.setType("image/*");
                        startActivityForResult(intent, WALLPAPER_REQUEST_CODE);
                    } else
                        FileUtils.deleteQuietly(new File(getActivity().getFilesDir(), "background"));
                    findPreference(Common.BACKGROUND_COLOR).setEnabled(newValue.toString().equals("color"));
                }
                return true;
            });
            break;
        case OPTIONS:
            Preference el = findPreference(Common.ENABLE_LOGGING);
            el.setEnabled(prefs.getBoolean(Common.ENABLE_PRO, false));
            if (!prefs.getBoolean(Common.ENABLE_PRO, false)) {
                el.setSummary(R.string.toast_pro_required);
            }
            if (MLImplementation.getImplementation(prefs) != MLImplementation.DEFAULT) {
                PreferenceCategory catOther = (PreferenceCategory) findPreference(Common.CATEGORY_OTHER);
                catOther.removePreference(findPreference(Common.HIDE_RECENTS_THUMBNAILS));
            }
            break;
        case IMOD:
            // I.Mod - Pro setup
            Preference iModDelayGlobal = findPreference(Common.ENABLE_DELAY_GENERAL);
            Preference iModDelayPerApp = findPreference(Common.ENABLE_DELAY_PER_APP);
            iModDelayGlobal.setEnabled(prefs.getBoolean(Common.ENABLE_PRO, false));
            iModDelayPerApp.setEnabled(prefs.getBoolean(Common.ENABLE_PRO, false));
            if (!prefs.getBoolean(Common.ENABLE_PRO, false)) {
                iModDelayGlobal.setTitle(R.string.pref_delay_needpro);
                iModDelayPerApp.setTitle(R.string.pref_delay_needpro);
            }
            break;
    }
}
 
Example 17
Source File: GeneralSettingsFragment.java    From NotificationPeekPort with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences);

    // Appearance settings entrance.
    Preference appearancePref = findPreference(PreferenceKeys.PREF_APPEARANCE);
    appearancePref.setOnPreferenceClickListener(this);

    // Clock preference.
    CheckBoxPreference clockPref =
            (CheckBoxPreference) findPreference(PreferenceKeys.PREF_CLOCK);
    clockPref.setOnPreferenceChangeListener(this);



    // Always show content preference.
    CheckBoxPreference alwaysShowContentPref =
            (CheckBoxPreference) findPreference(PreferenceKeys.PREF_ALWAYS_SHOW_CONTENT);
    alwaysShowContentPref.setOnPreferenceChangeListener(this);

    // Notification Peek timeout preference.
    ListPreference peekTimeoutPref =
            (ListPreference) findPreference(PreferenceKeys.PREF_PEEK_TIMEOUT);
    peekTimeoutPref.setOnPreferenceChangeListener(this);
    bindPreferenceSummaryToValue(peekTimeoutPref);

    // Listen forever preference.
    ListPreference sensorTimeoutPref =
            (ListPreference) findPreference(PreferenceKeys.PREF_SENSOR_TIMEOUT);
    sensorTimeoutPref.setOnPreferenceChangeListener(this);
    bindPreferenceSummaryToValue(sensorTimeoutPref);

    // Gyroscope sensor enable/disable preference.
    CheckBoxPreference gyroPref =
            (CheckBoxPreference) findPreference(PreferenceKeys.PREF_GYRO_SENSOR);
    if (!SensorHelper.checkSensorStatus(getActivity(), SensorHelper.SENSOR_GYRO, false)) {
        // No gyroscope sensor found.
        gyroPref.setEnabled(false);
    } else {
        gyroPref.setEnabled(true);
        gyroPref.setOnPreferenceChangeListener(this);
    }


    // Proximity/Light sensor enable/disable preference.
    CheckBoxPreference proxPref =
            (CheckBoxPreference) findPreference(PreferenceKeys.PREF_PROX_LIGHT_SENSOR);
    if (!SensorHelper
            .checkSensorStatus(getActivity(), SensorHelper.SENSOR_PROXIMITY_LIGHT, false)) {
        // No proximity or light sensor found.
        proxPref.setEnabled(false);
    } else {
        proxPref.setEnabled(true);
        proxPref.setOnPreferenceChangeListener(this);
    }

}
 
Example 18
Source File: SettingsActivity.java    From matlog with GNU General Public License v3.0 4 votes vote down vote up
private void setUpPreferences() {
    setCurrentValue("ui.theme");
    setCurrentValue("theme");

    displayLimitPreference = (EditTextPreference) findPreference(getString(R.string.pref_display_limit));

    int displayLimitValue = PreferenceHelper.getDisplayLimitPreference(getActivity());

    displayLimitPreference.setSummary(getString(R.string.pref_display_limit_summary,
            displayLimitValue, getString(R.string.pref_display_limit_default)));
    displayLimitPreference.setOnPreferenceChangeListener(this);

    filterPatternPreference = (EditTextPreference) findPreference(getString(R.string.pref_filter_pattern));
    filterPatternPreference.setSummary(getString(R.string.pref_filter_pattern_summary));
    filterPatternPreference.setOnPreferenceChangeListener(this);

    logLinePeriodPreference = (EditTextPreference) findPreference(getString(R.string.pref_log_line_period));

    int logLinePrefValue = PreferenceHelper.getLogLinePeriodPreference(getActivity());

    logLinePeriodPreference.setSummary(getString(R.string.pref_log_line_period_summary,
            logLinePrefValue, getString(R.string.pref_log_line_period_default)));

    logLinePeriodPreference.setOnPreferenceChangeListener(this);

    textSizePreference = (ListPreference) findPreference(getString(R.string.pref_text_size));
    textSizePreference.setSummary(textSizePreference.getEntry());
    textSizePreference.setOnPreferenceChangeListener(this);

    defaultLevelPreference = (ListPreference) findPreference(getString(R.string.pref_default_log_level));
    defaultLevelPreference.setOnPreferenceChangeListener(this);
    setDefaultLevelPreferenceSummary(defaultLevelPreference.getEntry());

    mThemePreference = findPreference("ui.theme");
    mThemePreference.setOnPreferenceChangeListener(this);

    bufferPreference = (MultipleChoicePreference) findPreference(getString(R.string.pref_buffer));
    bufferPreference.setOnPreferenceChangeListener(this);
    setBufferPreferenceSummary(bufferPreference.getValue());

    mThemePreference.setOnPreferenceChangeListener(this);

    mAboutPreference = findPreference(getString(R.string.pref_about));
    mAboutPreference.setOnPreferenceClickListener(preference -> {
        // launch about activity
        Intent intent = new Intent(getActivity(), AboutDialogActivity.class);
        startActivity(intent);
        return true;
    });
    mAboutPreference.setSummary(getString(R.string.version, PackageHelper.getVersionName(getActivity())));

    scrubberPreference = (SwitchPreference) getPreferenceScreen().findPreference("scrubber");
    scrubberPreference.setOnPreferenceChangeListener((preference, newValue) -> {
        LogLine.isScrubberEnabled = (boolean) newValue;
        return true;
    });
}
 
Example 19
Source File: SettingsActivity.java    From android-app with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences);

    settings = new Settings(App.getInstance());

    setOnClickListener(R.string.pref_key_connection_wizard);
    setOnClickListener(R.string.pref_key_connection_autofill);
    setOnClickListener(R.string.pref_key_sync_syncTypes_description);
    setOnClickListener(R.string.pref_key_ui_disableTouch_keyCode);
    setOnClickListener(R.string.pref_key_misc_wipeDB);
    setOnClickListener(R.string.pref_key_misc_localQueue_dumpToFile);
    setOnClickListener(R.string.pref_key_misc_localQueue_removeFirstItem);
    setOnClickListener(R.string.pref_key_misc_logging_logcatToFile);

    ListPreference themeListPreference = (ListPreference)findPreference(
            getString(R.string.pref_key_ui_theme));
    if(themeListPreference != null) {
        Themes.Theme[] themes = Themes.Theme.values();
        String[] themeEntries = new String[themes.length];
        String[] themeEntryValues = new String[themes.length];
        for(int i = 0; i < themes.length; i++) {
            themeEntries[i] = getString(themes[i].getNameId());
            themeEntryValues[i] = themes[i].toString();
        }

        themeListPreference.setEntries(themeEntries);
        themeListPreference.setEntryValues(themeEntryValues);
    }

    ListPreference autoSyncIntervalListPreference = (ListPreference)findPreference(
            getString(R.string.pref_key_autoSync_interval));
    if(autoSyncIntervalListPreference != null) {
        // may set arbitrary values on Android API 19+
        autoSyncIntervalListPreference.setEntries(new String[] {
                getString(R.string.pref_option_autoSync_interval_15m),
                getString(R.string.pref_option_autoSync_interval_30m),
                getString(R.string.pref_option_autoSync_interval_1h),
                getString(R.string.pref_option_autoSync_interval_12h),
                getString(R.string.pref_option_autoSync_interval_24h)
        });
        autoSyncIntervalListPreference.setEntryValues(new String[] {
                String.valueOf(AlarmManager.INTERVAL_FIFTEEN_MINUTES),
                String.valueOf(AlarmManager.INTERVAL_HALF_HOUR),
                String.valueOf(AlarmManager.INTERVAL_HOUR),
                String.valueOf(AlarmManager.INTERVAL_HALF_DAY),
                String.valueOf(AlarmManager.INTERVAL_DAY)
        });
    }

    CheckBoxPreference handleHttpSchemePreference = (CheckBoxPreference) findPreference(
            getString(R.string.pref_key_misc_handleHttpScheme));
    if (handleHttpSchemePreference != null) {
        handleHttpSchemePreference.setChecked(settings.isHandlingHttpScheme());
        handleHttpSchemePreference.setOnPreferenceChangeListener(this);
    }

    ListPreference dbPathListPreference = (ListPreference)findPreference(
            getString(R.string.pref_key_storage_dbPath));
    if(dbPathListPreference != null) {
        List<String> entriesList = new ArrayList<>(2);
        List<String> entryValuesList = new ArrayList<>(2);

        entriesList.add(getString(R.string.pref_name_storage_dbPath_internalStorage));
        entryValuesList.add("");

        if(StorageHelper.isExternalStorageWritable()) {
            entriesList.add(getString(R.string.pref_name_storage_dbPath_externalStorage));
            entryValuesList.add(StorageHelper.getExternalStoragePath());
        }

        dbPathListPreference.setEntries(entriesList.toArray(new String[0]));
        dbPathListPreference.setEntryValues(entryValuesList.toArray(new String[0]));

        dbPathListPreference.setOnPreferenceChangeListener(this);
    }

    for(int keyID: SUMMARIES_TO_INITIATE) {
        updateSummary(keyID);
    }
}
 
Example 20
Source File: IconShapeOverride.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
public static void handlePreferenceUi(ListPreference preference) {
    Context context = preference.getContext();
    preference.setValue(getAppliedValue(context));
    preference.setOnPreferenceChangeListener(new PreferenceChangeHandler(context));
}