Example usage for android.preference PreferenceManager setDefaultValues

List of usage examples for android.preference PreferenceManager setDefaultValues

Introduction

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

Prototype

public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain) 

Source Link

Document

Sets the default values from an XML preference file by reading the values defined by each Preference item's android:defaultValue attribute.

Usage

From source file:ma.wanam.xtouchwiz.XTouchWizActivity.java

public void restoreRecommendedSettings() {

    MainApplication.getSharedPreferences().edit().clear().commit();
    PreferenceManager.setDefaultValues(this, R.xml.wanam_settings, false);

    Editor editor = MainApplication.getSharedPreferences().edit();

    for (String defaultSetting : defaultSettings) {
        editor.putBoolean(defaultSetting, true).commit();
    }//from  w  w  w  .j a  v a2 s. c  om

    editor.putInt("notificationSize", MainApplication.getWindowsSize().x).commit();

    editor.putString("screenOffEffect", "0").commit();
    editor.putString("clockPosition", "Center").commit();

    Toast.makeText(this, R.string.recommended_restored, Toast.LENGTH_SHORT).show();

    XCscFeaturesManager.applyCscFeatures(MainApplication.getSharedPreferences());

    RebootNotification.notify(this, 999, false);

    recreate();

}

From source file:com.javielinux.adapters.TweetsAdapter.java

private void init(FragmentActivity activity, LoaderManager loaderManager,
        ArrayList<InfoTweet> infoTweetArrayList, long userId, String usernameColumn, int column) {
    this.activity = activity;
    listAQuery = new AQuery(activity);

    Log.d(Utils.TAG, "Numero de elementos: " + infoTweetArrayList.size());
    this.infoTweetArrayList = infoTweetArrayList;
    this.userId = userId;
    this.usernameColumn = usernameColumn;
    this.column = column;

    this.loaderManager = loaderManager;

    themeManager = new ThemeManager(activity);
    color_line = themeManager.getColor("color_tweet_no_read");

    ArrayList<Entity> colors = DataFramework.getInstance().getEntityList("colors", "type_id=2", "");
    int count = 0;
    for (Entity color : colors) {
        hashColorUsers.put(color.getString("word"),
                Color.parseColor(themeManager.getColors().get(color.getEntity("type_color_id").getInt("pos"))));
        hashColorUsersPosition.put(color.getString("word"), count);
        count++;/*  w w w . j a  va2 s  .c  o  m*/
    }

    hashThemeColors.put("list_background_row_color", themeManager.getColor("list_background_row_color"));
    hashThemeColors.put("color_tweet_text", themeManager.getColor("color_tweet_text"));
    hashThemeColors.put("color_tweet_source", themeManager.getColor("color_tweet_source"));
    hashThemeColors.put("color_tweet_retweet", themeManager.getColor("color_tweet_retweet"));
    hashThemeColors.put("color_tweet_usename", themeManager.getColor("color_tweet_usename"));
    hashThemeColors.put("color_tweet_date", themeManager.getColor("color_tweet_date"));

    PreferenceManager.setDefaultValues(activity, R.xml.preferences, false);
    preference = PreferenceManager.getDefaultSharedPreferences(activity);

}

From source file:org.gnucash.android.ui.account.AccountsActivity.java

/**
 * Loads default setting for currency and performs app first-run initialization
 */// w ww  . j a  v  a 2s  .  c  o  m
private void init() {
    PreferenceManager.setDefaultValues(this, R.xml.fragment_transaction_preferences, false);

    Locale locale = Locale.getDefault();
    //sometimes the locale en_UK is returned which causes a crash with Currency
    if (locale.getCountry().equals("UK")) {
        locale = new Locale(locale.getLanguage(), "GB");
    }

    String currencyCode;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    try { //there are some strange locales out there
        currencyCode = prefs.getString(getString(R.string.key_default_currency),
                Currency.getInstance(locale).getCurrencyCode());
    } catch (Exception e) {
        Log.e(LOG_TAG, e.getMessage());
        currencyCode = "USD";
    }

    Money.DEFAULT_CURRENCY_CODE = currencyCode;

    boolean firstRun = prefs.getBoolean(getString(R.string.key_first_run), true);
    if (firstRun) {
        createDefaultAccounts();
        //default to using double entry and save the preference explicitly
        prefs.edit().putBoolean(getString(R.string.key_use_double_entry), true).commit();
    }

    if (hasNewFeatures()) {
        showWhatsNewDialog(this);
    }

}

From source file:com.example.android.recyclingbanks.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        Log.wtf("restoring state?", "should have cam pos");
        cameraPosition = savedInstanceState.getParcelable("STATE_CAMERA_POSITION");
        //mBankLatLng = bundle.getParcelable("bankLatLng");
    } else if (savedInstanceState == null) {
        Log.wtf("onCreate", "state not restored");
    }/*from w ww  .j  a  va2  s  .co m*/

    Log.i("onCreate", "seting up variable, UI etc.");
    setContentView(R.layout.bottombar_constraint_layout);
    setTitle("Recycle Banks");

    //setContentView(R.layout.earthquake_activity);
    // TODO ask for postcode and house number on first login, tell them you can change this using [icon] later
    //DownloadTask task = new DownloadTask();
    //task.execute(REQUEST_URL);
    // load preference defaults for buttons press,
    // false means we won't ever read this again after first app boot
    PreferenceManager.setDefaultValues(this, R.xml.default_preferences, true);
    // preferences contains booleans to record click status of bottom bar
    preferences = getPreferences(MODE_PRIVATE);

    mSharedPrefs = getDefaultSharedPreferences(getBaseContext());

    // Find a reference to the {@link ListView} in the layout
    ListView earthquakeListView = (ListView) findViewById(R.id.list);

    mProgressBar = (ProgressBar) findViewById(R.id.loading_spinner);
    mSpinnerLayout = (LinearLayout) findViewById(R.id.linearLayoutSpinner);
    // WANT TO create a message if the list is empty
    mEmptyView = (TextView) findViewById(R.id.emptyView);
    // by attaching this to listView, it only shows if listView is empty

    Log.i(LOG_TAG, "!!!!! launching a new LoaderManager");

    usesGPS = mSharedPrefs.getBoolean("usesGPS", false);
    if (!usesGPS) {
        // TODO
        // setup home marker
        mUserLatitude = Double.valueOf(mSharedPrefs.getString("manualLatitude", "55.9532520"));
        mUserLongitude = Double.valueOf(mSharedPrefs.getString("manualLongitude", "-3.1882670"));

        String homeAddress = mSharedPrefs.getString("homeAddress", "Edinburgh");
        Log.w("onCreate", "manual address: " + homeAddress);
        // alert user that using saved home location
        Toast.makeText(this, homeAddress + "as home, change in settings", Toast.LENGTH_SHORT);
    }
    Log.wtf("onConnected", "all prefs: " + String.valueOf(mSharedPrefs.getAll()));
    Log.wtf("onConnected", "contain usesGPS key? " + String.valueOf(mSharedPrefs.contains("usesGPS")));
    Log.wtf("onConnected", "using gps? " + String.valueOf(usesGPS));

    // Create an instance of GoogleAPIClient.  Used for getting users location
    // also used for geocoding their location to Toast their street.
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this)
                .addApi(LocationServices.API).build();
    }
}

From source file:com.stillnojetpacks.huffr.activities.MainActivity.java

private void loadPreferences() {
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

    int newSoundpoolMaxSize = Integer.parseInt(sharedPref.getString(KEY_PREF_SOUNDPOOL_MAX_STREAMS, "4"));
    if (PREF_SOUNDPOOL_MAX_STREAMS != newSoundpoolMaxSize) {
        PREF_SOUNDPOOL_MAX_STREAMS = newSoundpoolMaxSize;
        initializeSoundPool();/*from   w  w  w. ja va 2 s  .co m*/
    }

    PREF_USE_ALTERNATE_VERTICAL_SOUNDS = sharedPref.getBoolean(KEY_PREF_USE_ALTERNATE_VERTICAL_SOUNDS, false);
    PREF_X_HORIZONTAL_SENSITIVITY_THRESHOLD = sharedPref.getInt(KEY_PREF_X_HORIZONTAL_SENSITIVITY_THRESHOLD, 50)
            / 10.0f;
    PREF_Y_VERTICAL_SENSITIVITY_THRESHOLD = sharedPref.getInt(KEY_PREF_Y_VERTICAL_SENSITIVITY_THRESHOLD, 31)
            / 10.0f;

    Log.i(TAG, "loadPreferences. PREF_SOUNDPOOL_MAX_STREAMS:" + PREF_SOUNDPOOL_MAX_STREAMS);
    Log.i(TAG, "loadPreferences. PREF_USE_ALTERNATE_VERTICAL_SOUNDS:" + PREF_USE_ALTERNATE_VERTICAL_SOUNDS);
    Log.i(TAG, "loadPreferences. PREF_X_HORIZONTAL_SENSITIVITY_THRESHOLD:"
            + PREF_X_HORIZONTAL_SENSITIVITY_THRESHOLD);
    Log.i(TAG,
            "loadPreferences. PREF_Y_VERTICAL_SENSITIVITY_THRESHOLD:" + PREF_Y_VERTICAL_SENSITIVITY_THRESHOLD);
}

From source file:com.apotheosis.acceleration.monitor.MainMenuActivity.java

@Override
public void onResume() {
    super.onResume();
    initRecorderFragment();/* w ww  .  j  a  va  2 s.  com*/
    final SharedPreferences defaultPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (!defaultPrefs.getBoolean("LICENSES_ACCEPTED", false)) {
        final AlertDialog.Builder acceptLicenses = new AlertDialog.Builder(this);
        View v = getLayoutInflater().inflate(R.layout.alertdialog_license_prompt, null);
        acceptLicenses.setView(v);

        WebView cpol = (WebView) v.findViewById(R.id.CPOL_view),
                apache = (WebView) v.findViewById(R.id.APACHE_2_0_view);
        cpol.loadUrl("file:///android_res/raw/cpol.html");
        cpol.getSettings().setLoadWithOverviewMode(true);
        cpol.getSettings().setBuiltInZoomControls(true);
        cpol.getSettings().setUseWideViewPort(true);
        apache.loadUrl("file:///android_res/raw/apache.html");
        apache.getSettings().setLoadWithOverviewMode(true);
        apache.getSettings().setBuiltInZoomControls(true);
        apache.getSettings().setUseWideViewPort(true);

        acceptLicenses.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                defaultPrefs.edit().putBoolean("LICENSES_ACCEPTED", true).apply();
                dialog.dismiss();

                PreferenceManager.setDefaultValues(MainMenuActivity.this, R.xml.data_viewer_phone_options,
                        false);
            }
        });

        acceptLicenses.setNegativeButton("Decline", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });

        acceptLicenses.setCancelable(false);
        acceptLicenses.show();
    }
}

From source file:at.tugraz.ist.akm.activities.MainActivity.java

private void fixAndroidBugIssued6641() {
    // These lines are working around an android bug:
    // https://code.google.com/p/android/issues/detail?id=6641
    PreferenceManager.setDefaultValues(this, R.xml.preferences_list, false);
    setDefaultBooleanPreferenceValue(R.string.preferences_access_restriction_key);
    setDefaultBooleanPreferenceValue(R.string.preferences_protocol_checkbox_key);
}