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

The following examples show how to use android.preference.CheckBoxPreference#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: SettingsActivity.java    From mosmetro-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Generate random User-Agent if it is unset
    new Randomizer(getActivity()).cached_useragent();

    setTitle(getString(R.string.pref_category_connection));
    addPreferencesFromResource(R.xml.pref_conn);

    PreferenceScreen screen = getPreferenceScreen();

    final CheckBoxPreference pref_mainet = (CheckBoxPreference)
            screen.findPreference("pref_mainet");
    final LoginFormPreference pref_mainet_creds = (LoginFormPreference)
            screen.findPreference("pref_mainet_credentials");
    pref_mainet_creds.setEnabled(pref_mainet.isChecked());
    pref_mainet.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            pref_mainet_creds.setEnabled((Boolean) newValue);
            return true;
        }
    });
}
 
Example 2
Source File: CustomRestrictionsFragment.java    From android-AppRestrictions with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.custom_prefs);

    // This sample app uses shared preferences to maintain app restriction settings.  Your app
    // can use other methods to maintain the settings.
    mBooleanPref = (CheckBoxPreference) findPreference(KEY_BOOLEAN_PREF);
    mChoicePref = (ListPreference) findPreference(KEY_CHOICE_PREF);
    mMultiPref = (MultiSelectListPreference) findPreference(KEY_MULTI_PREF);

    mBooleanPref.setOnPreferenceChangeListener(this);
    mChoicePref.setOnPreferenceChangeListener(this);
    mMultiPref.setOnPreferenceChangeListener(this);

    setRetainInstance(true);
}
 
Example 3
Source File: FloatDisplaySettingActivity.java    From Float-Bar with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.prefs_list_content);
	addPreferencesFromResource(R.xml.float_display_preference);

	prefs = new Prefs(this);

	colorList = (MyListPreference) findPreference("color");
	colorList.setOnPreferenceChangeListener(this);

	alphaSb = (MySeekBarPreference) findPreference("alpha");// 找到preference
	alphaSb.setDefaultProgressValue(prefs.getAlpha());// 设置起始时的进度
	alphaSb.setMax(255);// 设置最大的数值,不超过10000。如果超过了请在seekbarPreference源码中进行修改max值
	alphaSb.setOnSeekBarPrefsChangeListener(this);// 设置监听器

	rightCBox = (CheckBoxPreference) findPreference("rightMode");
	rightCBox.setOnPreferenceChangeListener(this);

	widthSb = (MySeekBarPreference) findPreference("width");
	widthSb.setMax(80);
	widthSb.setDefaultProgressValue(prefs.getWidth());
	widthSb.setOnSeekBarPrefsChangeListener(this);

	heightSb = (MySeekBarPreference) findPreference("height");
	heightSb.setMax(1000);
	heightSb.setDefaultProgressValue(prefs.getHeight());
	heightSb.setOnSeekBarPrefsChangeListener(this);

	distanceSb = (MySeekBarPreference) findPreference("distance");
	distanceSb.setMax(1000);
	distanceSb.setDefaultProgressValue(prefs.getDistance());
	distanceSb.setOnSeekBarPrefsChangeListener(this);
}
 
Example 4
Source File: SettingFragment.java    From JianDanRxJava with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    clearCache = findPreference(CLEAR_CACHE);
    aboutApp = findPreference(ABOUT_APP);
    appVersion = findPreference(APP_VERSION);
    enableSister = (CheckBoxPreference) findPreference(ENABLE_SISTER);
    enableBig = (CheckBoxPreference) findPreference(ENABLE_FRESH_BIG);

    appVersion.setTitle(AppInfoUtil.getVersionName(getActivity()));

    File cacheFile = ImageLoader.getInstance().getDiskCache().getDirectory();
    DecimalFormat decimalFormat = new DecimalFormat("#0.00");
    clearCache.setSummary(getString(R.string.cache_size) + decimalFormat.format(FileUtil.getDirSize(cacheFile)) + "M");

    enableSister.setOnPreferenceChangeListener((preference, newValue) -> {
        ToastHelper.Short(((Boolean) newValue) ? getString(R.string.open_sister_mode) : getString(R.string.close_sister_mode));
        return true;
    });

    enableBig.setOnPreferenceChangeListener((preference, newValue) -> {
        ToastHelper.Short(((Boolean) newValue) ? getString(R.string.picture_mode_big) : getString(R.string.picture_mode_small));
        return true;
    });

    clearCache.setOnPreferenceClickListener(this);
    aboutApp.setOnPreferenceClickListener(this);
}
 
Example 5
Source File: SettingsActivity.java    From mosmetro-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(getString(R.string.pref_category_notifications));
    addPreferencesFromResource(R.xml.pref_notify);

    PreferenceScreen screen = getPreferenceScreen();

    // Link pref_notify_foreground and pref_notify_success_lock
    final CheckBoxPreference foreground = (CheckBoxPreference)
            screen.findPreference("pref_notify_foreground");
    final CheckBoxPreference success = (CheckBoxPreference)
            screen.findPreference("pref_notify_success");
    final CheckBoxPreference success_lock = (CheckBoxPreference)
            screen.findPreference("pref_notify_success_lock");
    foreground.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            success.setEnabled(!((Boolean) newValue));
            success_lock.setEnabled(!((Boolean) newValue));
            return true;
        }
    });
    foreground
            .getOnPreferenceChangeListener()
            .onPreferenceChange(foreground, foreground.isChecked());
}
 
Example 6
Source File: PreferencesOther.java    From habpanelviewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences_other);

    mDPM = (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);

    // add validation to the device admin
    CheckBoxPreference adminPreference = (CheckBoxPreference) findPreference(Constants.PREF_DEVICE_ADMIN);
    adminPreference.setOnPreferenceChangeListener(new AdminValidatingListener());
}
 
Example 7
Source File: DeviceAdminSample.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.device_admin_encryption);

    mEncryptionCategory = (PreferenceCategory) findPreference(KEY_CATEGORY_ENCRYPTION);
    mRequireEncryption = (CheckBoxPreference) findPreference(KEY_REQUIRE_ENCRYPTION);
    mActivateEncryption = (PreferenceScreen) findPreference(KEY_ACTIVATE_ENCRYPTION);

    mRequireEncryption.setOnPreferenceChangeListener(this);
    mActivateEncryption.setOnPreferenceClickListener(this);
}
 
Example 8
Source File: PreferencesMotion.java    From habpanelviewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences_motion);

    CheckBoxPreference cbPref = (CheckBoxPreference) findPreference(Constants.PREF_MOTION_DETECTION_ENABLED);
    cbPref.setOnPreferenceChangeListener(this);
}
 
Example 9
Source File: SettingsFragment.java    From Jager with GNU General Public License v3.0 5 votes vote down vote up
private void setupCrashDataPref () {
	CheckBoxPreference crashData = (CheckBoxPreference)
			getPreferenceScreen ().findPreference (
					SettingsActivity.KEY_CRASH_DATA);
	crashData.setOnPreferenceChangeListener ((preference, newValue) -> {
		if (newValue instanceof Boolean) {
			boolean bool = (boolean) newValue;
			setCrashDataPref (bool);
		}
		return true;
	});
}
 
Example 10
Source File: FloatDisplaySettingActivity.java    From Float-Bar with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.prefs_list_content);
	addPreferencesFromResource(R.xml.float_display_preference);

	prefs = new Prefs(this);

	colorList = (MyListPreference) findPreference("color");
	colorList.setOnPreferenceChangeListener(this);

	alphaSb = (MySeekBarPreference) findPreference("alpha");// 找到preference
	alphaSb.setDefaultProgressValue(prefs.getAlpha());// 设置起始时的进度
	alphaSb.setMax(255);// 设置最大的数值,不超过10000。如果超过了请在seekbarPreference源码中进行修改max值
	alphaSb.setOnSeekBarPrefsChangeListener(this);// 设置监听器

	rightCBox = (CheckBoxPreference) findPreference("rightMode");
	rightCBox.setOnPreferenceChangeListener(this);

	widthSb = (MySeekBarPreference) findPreference("width");
	widthSb.setMax(80);
	widthSb.setDefaultProgressValue(prefs.getWidth());
	widthSb.setOnSeekBarPrefsChangeListener(this);

	heightSb = (MySeekBarPreference) findPreference("height");
	heightSb.setMax(1000);
	heightSb.setDefaultProgressValue(prefs.getHeight());
	heightSb.setOnSeekBarPrefsChangeListener(this);

	distanceSb = (MySeekBarPreference) findPreference("distance");
	distanceSb.setMax(1000);
	distanceSb.setDefaultProgressValue(prefs.getDistance());
	distanceSb.setOnSeekBarPrefsChangeListener(this);
}
 
Example 11
Source File: SettingsFragment.java    From CineLog with GNU General Public License v3.0 5 votes vote down vote up
private void configureThemePreference() {
    CheckBoxPreference listcheckBoxPreference = (CheckBoxPreference) findPreference("theme");
    listcheckBoxPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Toast.makeText(getActivity().getBaseContext(), getResources().getString(R.string.change_theme), Toast.LENGTH_LONG).show();
            return true;
        }
    });
}
 
Example 12
Source File: SettingsFragment.java    From android-kernel-tweaker 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.pref_settings);
	mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
	mEnable = (CheckBoxPreference) findPreference(KEY_ENABLE_GLOBAL);
	mPersonal = (CheckBoxPreference) findPreference(KEY_ENABLE_PERSONAL);
	mTheme = (CheckBoxPreference) findPreference(KEY_THEME);
	mColor = (ColorPickerPreference) findPreference(KEY_GLOBAL_COLOR);
	mStats = (ColorPickerPreference) findPreference(KEY_STAT);
	mInfo = (ColorPickerPreference) findPreference(KEY_INFO);
	mCpu = (ColorPickerPreference) findPreference(KEY_CPU);
	mGpu = (ColorPickerPreference) findPreference(KEY_GPU);
	mUv = (ColorPickerPreference) findPreference(KEY_UV);
	mKernel = (ColorPickerPreference) findPreference(KEY_KERNEL);
	mLmk = (ColorPickerPreference) findPreference(KEY_LMK);
	mVm = (ColorPickerPreference) findPreference(KEY_VM);
	mReview = (ColorPickerPreference) findPreference(KEY_REVIEW);
	mFile = (ColorPickerPreference) findPreference(KEY_FILE);
	mBak = (ColorPickerPreference) findPreference(KEY_BAK);
	mRecovery = (ColorPickerPreference) findPreference(KEY_RECOVERY);

	mProp = (ColorPickerPreference) findPreference(KEY_PROP);
	mInit = (ColorPickerPreference) findPreference(KEY_INIT);
	mBlur = (ColorPickerPreference) findPreference(KEY_BLUR);

	mPersonalCat = (PreferenceCategory) findPreference(KEY_PERSONAL_CAT);

	mLog = (Preference) findPreference(KEY_SLOG);
	mRunLog = (Preference) findPreference(KEY_RUNLOG);


	boolean enabled = mPrefs.getBoolean(KEY_ENABLE_GLOBAL, false);
	mColor.setEnabled(enabled);

	mEnable.setOnPreferenceChangeListener(this);
	mTheme.setOnPreferenceChangeListener(this);
	mColor.setOnPreferenceChangeListener(this);
	mPersonal.setOnPreferenceChangeListener(this);
	mStats.setOnPreferenceChangeListener(this);;
	mInfo.setOnPreferenceChangeListener(this);
	mCpu.setOnPreferenceChangeListener(this);
	mGpu.setOnPreferenceChangeListener(this);
	mUv.setOnPreferenceChangeListener(this);
	mKernel.setOnPreferenceChangeListener(this);
	mLmk.setOnPreferenceChangeListener(this);
	mVm.setOnPreferenceChangeListener(this);
	mReview.setOnPreferenceChangeListener(this);
	mFile.setOnPreferenceChangeListener(this);
	mBak.setOnPreferenceChangeListener(this);
	mRecovery.setOnPreferenceChangeListener(this);
	mProp.setOnPreferenceChangeListener(this);
	mInit.setOnPreferenceChangeListener(this);
	mBlur.setOnPreferenceChangeListener(this);
	mLog.setOnPreferenceClickListener(this);
	mRunLog.setOnPreferenceClickListener(this);

	if(MainActivity.menu.isMenuShowing()) {
		MainActivity.menu.toggle(true);
	}

	if(!mPrefs.getBoolean(KEY_ENABLE_PERSONAL, false)) {
		this.getPreferenceScreen().removePreference(mPersonalCat);
	}


}
 
Example 13
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 14
Source File: AdvancedSettingsFragment.java    From Xndroid with GNU General Public License v3.0 4 votes vote down vote up
private void initPrefs() {

        renderingmode = findPreference(SETTINGS_RENDERINGMODE);
        textEncoding = findPreference(SETTINGS_TEXTENCODING);
        urlcontent = findPreference(SETTINGS_URLCONTENT);
        cbAllowPopups = (CheckBoxPreference) findPreference(SETTINGS_NEWWINDOW);
        cbenablecookies = (CheckBoxPreference) findPreference(SETTINGS_ENABLECOOKIES);
        cbcookiesInkognito = (CheckBoxPreference) findPreference(SETTINGS_COOKIESINKOGNITO);
        cbrestoreTabs = (CheckBoxPreference) findPreference(SETTINGS_RESTORETABS);

        renderingmode.setOnPreferenceClickListener(this);
        textEncoding.setOnPreferenceClickListener(this);
        urlcontent.setOnPreferenceClickListener(this);
        cbAllowPopups.setOnPreferenceChangeListener(this);
        cbenablecookies.setOnPreferenceChangeListener(this);
        cbcookiesInkognito.setOnPreferenceChangeListener(this);
        cbrestoreTabs.setOnPreferenceChangeListener(this);

        switch (mPreferenceManager.getRenderingMode()) {
            case 0:
                renderingmode.setSummary(getString(R.string.name_normal));
                break;
            case 1:
                renderingmode.setSummary(getString(R.string.name_inverted));
                break;
            case 2:
                renderingmode.setSummary(getString(R.string.name_grayscale));
                break;
            case 3:
                renderingmode.setSummary(getString(R.string.name_inverted_grayscale));
                break;
            case 4:
                renderingmode.setSummary(getString(R.string.name_increase_contrast));
                break;
        }

        textEncoding.setSummary(mPreferenceManager.getTextEncoding());

        mUrlOptions = getResources().getStringArray(R.array.url_content_array);
        int option = mPreferenceManager.getUrlBoxContentChoice();
        urlcontent.setSummary(mUrlOptions[option]);

        cbAllowPopups.setChecked(mPreferenceManager.getPopupsEnabled());
        cbenablecookies.setChecked(mPreferenceManager.getCookiesEnabled());
        cbcookiesInkognito.setChecked(mPreferenceManager.getIncognitoCookiesEnabled());
        cbrestoreTabs.setChecked(mPreferenceManager.getRestoreLostTabsEnabled());
    }
 
Example 15
Source File: SettingsActivity.java    From BlackLight with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
   @Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	addPreferencesFromResource(R.xml.settings);

	if (hasSmartBar()) {
		getListView().setFitsSystemWindows(true);
		Utility.enableTint(this);
	}

	mSettings = Settings.getInstance(this);

	// Action Bar
	getActionBar().setDisplayHomeAsUpEnabled(true);
	getActionBar().setHomeButtonEnabled(true);
	getActionBar().setDisplayUseLogoEnabled(false);
	getActionBar().setDisplayShowHomeEnabled(false);

	// Init
	mPrefLicense = findPreference(LICENSE);
	mPrefVersion = findPreference(VERSION);
	mPrefSourceCode = findPreference(SOURCE_CODE);
	mPrefFastScroll = (CheckBoxPreference) findPreference(Settings.FAST_SCROLL);
	mPrefRightHanded = (CheckBoxPreference) findPreference(Settings.RIGHT_HANDED);
	mPrefLog = findPreference(DEBUG_LOG);
	mPrefCrash = findPreference(DEBUG_CRASH);
	mPrefNotificationSound = (CheckBoxPreference) findPreference(Settings.NOTIFICATION_SOUND);
	mPrefNotificationVibrate = (CheckBoxPreference) findPreference(Settings.NOTIFICATION_VIBRATE);
	mPrefDevelopers = findPreference(DEVELOPERS);
	mPrefInterval = findPreference(Settings.NOTIFICATION_INTERVAL);
	
	// Data
	String version = "Unknown";
	try {
		version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
	} catch (Exception e) {
		// Keep the default value
	}
	mPrefVersion.setSummary(version);
	mPrefFastScroll.setChecked(mSettings.getBoolean(Settings.FAST_SCROLL,
			false));
	mPrefRightHanded.setChecked(mSettings.getBoolean(
			Settings.RIGHT_HANDED, false));
	mPrefNotificationSound.setChecked(mSettings.getBoolean(
			Settings.NOTIFICATION_SOUND, true));
	mPrefNotificationVibrate.setChecked(mSettings.getBoolean(
			Settings.NOTIFICATION_VIBRATE, true));
	mPrefLog.setSummary(CrashHandler.CRASH_LOG);
	mPrefInterval.setSummary(
			this.getResources()
			.getStringArray(R.array.interval_name) [mSettings.getInt(Settings.NOTIFICATION_INTERVAL, 1)]
					);
	
	// Set
	mPrefLicense.setOnPreferenceClickListener(this);
	mPrefSourceCode.setOnPreferenceClickListener(this);
	mPrefFastScroll.setOnPreferenceChangeListener(this);
	mPrefRightHanded.setOnPreferenceChangeListener(this);
	mPrefNotificationSound.setOnPreferenceChangeListener(this);
	mPrefNotificationVibrate.setOnPreferenceChangeListener(this);
	mPrefCrash.setOnPreferenceClickListener(this);
	mPrefDevelopers.setOnPreferenceClickListener(this);
	mPrefInterval.setOnPreferenceClickListener(this);
}
 
Example 16
Source File: NotificationSettingsActivity.java    From android-demo-xmpp-androidpn with Apache License 2.0 4 votes vote down vote up
private PreferenceScreen createPreferenceHierarchy() {
    Log.d(LOGTAG, "createSettingsPreferenceScreen()...");

    PreferenceManager preferenceManager = getPreferenceManager();
    preferenceManager
            .setSharedPreferencesName(Constants.SHARED_PREFERENCE_NAME);
    preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE);

    PreferenceScreen root = preferenceManager.createPreferenceScreen(this);

    //        PreferenceCategory prefCat = new PreferenceCategory(this);
    //        // inlinePrefCat.setTitle("");
    //        root.addPreference(prefCat);

    CheckBoxPreference notifyPref = new CheckBoxPreference(this);
    notifyPref.setKey(Constants.SETTINGS_NOTIFICATION_ENABLED);
    notifyPref.setTitle("Notifications Enabled");
    notifyPref.setSummaryOn("Receive push messages");
    notifyPref.setSummaryOff("Do not receive push messages");
    notifyPref.setDefaultValue(Boolean.TRUE);
    notifyPref
            .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    boolean checked = Boolean.valueOf(newValue.toString());
                    if (checked) {
                        preference.setTitle("Notifications Enabled");
                    } else {
                        preference.setTitle("Notifications Disabled");
                    }
                    return true;
                }
            });

    CheckBoxPreference soundPref = new CheckBoxPreference(this);
    soundPref.setKey(Constants.SETTINGS_SOUND_ENABLED);
    soundPref.setTitle("Sound");
    soundPref.setSummary("Play a sound for notifications");
    soundPref.setDefaultValue(Boolean.TRUE);
    // soundPref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED);

    CheckBoxPreference vibratePref = new CheckBoxPreference(this);
    vibratePref.setKey(Constants.SETTINGS_VIBRATE_ENABLED);
    vibratePref.setTitle("Vibrate");
    vibratePref.setSummary("Vibrate the phone for notifications");
    vibratePref.setDefaultValue(Boolean.TRUE);
    // vibratePref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED);

    root.addPreference(notifyPref);
    root.addPreference(soundPref);
    root.addPreference(vibratePref);

    //        prefCat.addPreference(notifyPref);
    //        prefCat.addPreference(soundPref);
    //        prefCat.addPreference(vibratePref);
    //        root.addPreference(prefCat);

    return root;
}
 
Example 17
Source File: NotificationSettingsActivity.java    From AndroidPNClient with Apache License 2.0 4 votes vote down vote up
private PreferenceScreen createPreferenceHierarchy() {
    Log.d(LOGTAG, "createSettingsPreferenceScreen()...");

    PreferenceManager preferenceManager = getPreferenceManager();
    preferenceManager
            .setSharedPreferencesName(Constants.SHARED_PREFERENCE_NAME);
    preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE);

    PreferenceScreen root = preferenceManager.createPreferenceScreen(this);

    CheckBoxPreference notifyPref = new CheckBoxPreference(this);
    notifyPref.setKey(Constants.SETTINGS_NOTIFICATION_ENABLED);
    notifyPref.setTitle("Notifications Enabled");
    notifyPref.setSummaryOn("Receive push messages");
    notifyPref.setSummaryOff("Do not receive push messages");
    notifyPref.setDefaultValue(Boolean.TRUE);
    notifyPref
            .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    boolean checked = Boolean.valueOf(newValue.toString());
                    if (checked) {
                        preference.setTitle("Notifications Enabled");
                    } else {
                        preference.setTitle("Notifications Disabled");
                    }
                    return true;
                }
            });

    CheckBoxPreference soundPref = new CheckBoxPreference(this);
    soundPref.setKey(Constants.SETTINGS_SOUND_ENABLED);
    soundPref.setTitle("Sound");
    soundPref.setSummary("Play a sound for notifications");
    soundPref.setDefaultValue(Boolean.TRUE);

    CheckBoxPreference vibratePref = new CheckBoxPreference(this);
    vibratePref.setKey(Constants.SETTINGS_VIBRATE_ENABLED);
    vibratePref.setTitle("Vibrate");
    vibratePref.setSummary("Vibrate the phone for notifications");
    vibratePref.setDefaultValue(Boolean.TRUE);

    root.addPreference(notifyPref);
    root.addPreference(soundPref);
    root.addPreference(vibratePref);


    return root;
}
 
Example 18
Source File: AdvancedSettingsFragment.java    From JumpGo with Mozilla Public License 2.0 4 votes vote down vote up
private void initPrefs() {

        renderingmode = findPreference(SETTINGS_RENDERINGMODE);
        textEncoding = findPreference(SETTINGS_TEXTENCODING);
        urlcontent = findPreference(SETTINGS_URLCONTENT);
        cbAllowPopups = (CheckBoxPreference) findPreference(SETTINGS_NEWWINDOW);
        cbenablecookies = (CheckBoxPreference) findPreference(SETTINGS_ENABLECOOKIES);
        cbcookiesInkognito = (CheckBoxPreference) findPreference(SETTINGS_COOKIESINKOGNITO);
        cbrestoreTabs = (CheckBoxPreference) findPreference(SETTINGS_RESTORETABS);

        renderingmode.setOnPreferenceClickListener(this);
        textEncoding.setOnPreferenceClickListener(this);
        urlcontent.setOnPreferenceClickListener(this);
        cbAllowPopups.setOnPreferenceChangeListener(this);
        cbenablecookies.setOnPreferenceChangeListener(this);
        cbcookiesInkognito.setOnPreferenceChangeListener(this);
        cbrestoreTabs.setOnPreferenceChangeListener(this);

        switch (mPreferenceManager.getRenderingMode()) {
            case 0:
                renderingmode.setSummary(getString(R.string.name_normal));
                break;
            case 1:
                renderingmode.setSummary(getString(R.string.name_inverted));
                break;
            case 2:
                renderingmode.setSummary(getString(R.string.name_grayscale));
                break;
            case 3:
                renderingmode.setSummary(getString(R.string.name_inverted_grayscale));
                break;
            case 4:
                renderingmode.setSummary(getString(R.string.name_increase_contrast));
                break;
        }

        textEncoding.setSummary(mPreferenceManager.getTextEncoding());

        mUrlOptions = getResources().getStringArray(R.array.url_content_array);
        int option = mPreferenceManager.getUrlBoxContentChoice();
        urlcontent.setSummary(mUrlOptions[option]);

        cbAllowPopups.setChecked(mPreferenceManager.getPopupsEnabled());
        cbenablecookies.setChecked(mPreferenceManager.getCookiesEnabled());
        cbcookiesInkognito.setChecked(mPreferenceManager.getIncognitoCookiesEnabled());
        cbrestoreTabs.setChecked(mPreferenceManager.getRestoreLostTabsEnabled());
    }
 
Example 19
Source File: SettingsActivity.java    From mytracks with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
  super.onCreate(bundle);

  Object retained = getLastNonConfigurationInstance();
  if (retained instanceof CheckPermissionAsyncTask) {
    syncDriveAsyncTask = (CheckPermissionAsyncTask) retained;
    syncDriveAsyncTask.setActivity(this);
  }

  addPreferencesFromResource(R.xml.settings);

  syncDrivePreference = (CheckBoxPreference) findPreference(getString(R.string.drive_sync_key));
  syncDrivePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
      @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
      if ((Boolean) newValue) {
        Account[] accounts = AccountManager.get(SettingsActivity.this)
            .getAccountsByType(Constants.ACCOUNT_TYPE);
        if (accounts.length == 0) {
          PreferencesUtils.setString(SettingsActivity.this, R.string.google_account_key,
              PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
          handleSync(false);
          showDialog(DIALOG_NO_ACCOUNT);
        } else if (accounts.length == 1) {
          PreferencesUtils.setString(
              SettingsActivity.this, R.string.google_account_key, accounts[0].name);
          showDialog(DIALOG_CONFIRM_DRIVE_SYNC_ON);
        } else {
          showDialog(DIALOG_CHOOSE_ACCOUNT);
        }
      } else {
        PreferencesUtils.setString(SettingsActivity.this, R.string.google_account_key,
            PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
        handleSync(false);
      }
      return false;
    }
  });
  updateSyncDriveSummary();

  configPreference(R.string.settings_map_key, MapSettingsActivity.class);
  configPreference(R.string.settings_chart_key, ChartSettingsActivity.class);
  configPreference(R.string.settings_stats_key, StatsSettingsActivity.class);
  configPreference(R.string.settings_recording_key, RecordingSettingsActivity.class);
  configPreference(R.string.settings_sensor_key, SensorSettingsActivity.class);
  configPreference(R.string.settings_advanced_key, AdvancedSettingsActivity.class);
}
 
Example 20
Source File: PrivacySettingsFragment.java    From JumpGo with Mozilla Public License 2.0 4 votes vote down vote up
private void initPrefs() {
    Preference clearcache = findPreference(SETTINGS_CLEARCACHE);
    Preference clearhistory = findPreference(SETTINGS_CLEARHISTORY);
    Preference clearcookies = findPreference(SETTINGS_CLEARCOOKIES);
    Preference clearwebstorage = findPreference(SETTINGS_CLEARWEBSTORAGE);

    CheckBoxPreference cblocation = (CheckBoxPreference) findPreference(SETTINGS_LOCATION);
    CheckBoxPreference cb3cookies = (CheckBoxPreference) findPreference(SETTINGS_THIRDPCOOKIES);
    CheckBoxPreference cbsavepasswords = (CheckBoxPreference) findPreference(SETTINGS_SAVEPASSWORD);
    CheckBoxPreference cbcacheexit = (CheckBoxPreference) findPreference(SETTINGS_CACHEEXIT);
    CheckBoxPreference cbhistoryexit = (CheckBoxPreference) findPreference(SETTINGS_HISTORYEXIT);
    CheckBoxPreference cbcookiesexit = (CheckBoxPreference) findPreference(SETTINGS_COOKIEEXIT);
    CheckBoxPreference cbwebstorageexit = (CheckBoxPreference) findPreference(SETTINGS_WEBSTORAGEEXIT);
    CheckBoxPreference cbDoNotTrack = (CheckBoxPreference) findPreference(SETTINGS_DONOTTRACK);
    CheckBoxPreference cbIdentifyingHeaders = (CheckBoxPreference) findPreference(SETTINGS_IDENTIFYINGHEADERS);

    clearcache.setOnPreferenceClickListener(this);
    clearhistory.setOnPreferenceClickListener(this);
    clearcookies.setOnPreferenceClickListener(this);
    clearwebstorage.setOnPreferenceClickListener(this);

    cblocation.setOnPreferenceChangeListener(this);
    cb3cookies.setOnPreferenceChangeListener(this);
    cbsavepasswords.setOnPreferenceChangeListener(this);
    cbcacheexit.setOnPreferenceChangeListener(this);
    cbhistoryexit.setOnPreferenceChangeListener(this);
    cbcookiesexit.setOnPreferenceChangeListener(this);
    cbwebstorageexit.setOnPreferenceChangeListener(this);
    cbDoNotTrack.setOnPreferenceChangeListener(this);
    cbIdentifyingHeaders.setOnPreferenceChangeListener(this);

    cblocation.setChecked(mPreferenceManager.getLocationEnabled());
    cbsavepasswords.setChecked(mPreferenceManager.getSavePasswordsEnabled());
    cbcacheexit.setChecked(mPreferenceManager.getClearCacheExit());
    cbhistoryexit.setChecked(mPreferenceManager.getClearHistoryExitEnabled());
    cbcookiesexit.setChecked(mPreferenceManager.getClearCookiesExitEnabled());
    cb3cookies.setChecked(mPreferenceManager.getBlockThirdPartyCookiesEnabled());
    cbwebstorageexit.setChecked(mPreferenceManager.getClearWebStorageExitEnabled());
    cbDoNotTrack.setChecked(mPreferenceManager.getDoNotTrackEnabled() && Utils.doesSupportHeaders());
    cbIdentifyingHeaders.setChecked(mPreferenceManager.getRemoveIdentifyingHeadersEnabled() && Utils.doesSupportHeaders());

    cbDoNotTrack.setEnabled(Utils.doesSupportHeaders());
    cbIdentifyingHeaders.setEnabled(Utils.doesSupportHeaders());

    String identifyingHeadersSummary = LightningView.HEADER_REQUESTED_WITH + ", " + LightningView.HEADER_WAP_PROFILE;
    cbIdentifyingHeaders.setSummary(identifyingHeadersSummary);

    cb3cookies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);

}