Example usage for android.preference PreferenceManager KEY_HAS_SET_DEFAULT_VALUES

List of usage examples for android.preference PreferenceManager KEY_HAS_SET_DEFAULT_VALUES

Introduction

In this page you can find the example usage for android.preference PreferenceManager KEY_HAS_SET_DEFAULT_VALUES.

Prototype

String KEY_HAS_SET_DEFAULT_VALUES

To view the source code for android.preference PreferenceManager KEY_HAS_SET_DEFAULT_VALUES.

Click Source Link

Usage

From source file:com.readystatesoftware.ghostlog.GhostLogSettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.mContext = this.getActivity();

    //        Switch mainSwitch = new Switch(mContext);
    //        mainSwitch.setChecked(LogService.isRunning());
    //        mainSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    //            @Override
    //            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
    //                Intent intent = new Intent(mContext, LogService.class);
    //                if (b) {
    //                    if (!LogService.isRunning()) {
    //                        mContext.startService(intent);
    //                    }
    //                } else {
    //                    mContext.stopService(intent);
    //                }
    //            }
    //        });
    //// w ww  . j a v a  2s  .c  om
    //        final ActionBar bar = mContext.getActionBar();
    //        final ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    //        lp.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
    //        lp.rightMargin = getResources().getDimensionPixelSize(R.dimen.main_switch_margin_right);
    //        bar.setCustomView(mainSwitch, lp);
    //        bar.setDisplayShowCustomEnabled(true);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    if (!mPrefs.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) {
        PreferenceManager.setDefaultValues(mContext, R.xml.pref_filters, true);
        PreferenceManager.setDefaultValues(mContext, R.xml.pref_appearance, true);
        SharedPreferences.Editor edit = mPrefs.edit();
        edit.putBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, true);
        edit.apply();
    }

    setupSimplePreferencesScreen();
}

From source file:com.readystatesoftware.ghostlog.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Switch mainSwitch = new Switch(this);
    mainSwitch.setChecked(LogService.isRunning());
    mainSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override//  w w  w .j av  a  2s .co m
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            Intent intent = new Intent(MainActivity.this, LogService.class);
            if (b) {
                if (!LogService.isRunning()) {
                    startService(intent);
                }
            } else {
                stopService(intent);
            }
        }
    });

    final ActionBar bar = getActionBar();
    final ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
    lp.rightMargin = getResources().getDimensionPixelSize(R.dimen.main_switch_margin_right);
    bar.setCustomView(mainSwitch, lp);
    bar.setDisplayShowCustomEnabled(true);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (!mPrefs.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) {
        PreferenceManager.setDefaultValues(this, R.xml.pref_filters, true);
        PreferenceManager.setDefaultValues(this, R.xml.pref_appearance, true);
        SharedPreferences.Editor edit = mPrefs.edit();
        edit.putBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, true);
        edit.apply();
    }

}

From source file:com.xorcode.andtweet.PreferencesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences);
    // Default values for the preferences will be set only once
    // and in one place: here
    MyPreferences.setDefaultValues(R.xml.preferences, false);
    if (!MyPreferences.getSharedPreferences(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, MODE_PRIVATE)
            .getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) {
        Log.e(TAG, "Default values were not set?!");
    }//from ww w . j a  v a 2  s .c o  m

    mNotificationRingtone = (RingtonePreference) findPreference(MyPreferences.KEY_RINGTONE_PREFERENCE);
    mOAuth = (CheckBoxPreference) findPreference(MyPreferences.KEY_OAUTH);
    mEditTextUsername = (EditTextPreference) findPreference(MyPreferences.KEY_TWITTER_USERNAME_NEW);
    mEditTextPassword = (EditTextPreference) findPreference(MyPreferences.KEY_TWITTER_PASSWORD);
    mVerifyCredentials = (Preference) findPreference(MyPreferences.KEY_VERIFY_CREDENTIALS);

    mNotificationRingtone.setOnPreferenceChangeListener(this);

    /*
     * mUseExternalStorage = (CheckBoxPreference)
     * getPreferenceScreen().findPreference(KEY_EXTERNAL_STORAGE); if
     * (!Environment
     * .getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
     * mUseExternalStorage.setEnabled(false);
     * mUseExternalStorage.setChecked(false); }
     */
}