Java Code Examples for android.support.v7.preference.PreferenceManager#getDefaultSharedPreferences()

The following examples show how to use android.support.v7.preference.PreferenceManager#getDefaultSharedPreferences() . 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: EarthquakeListFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);

  // Retrieve the Earthquake View Model for the parent Activity.
  earthquakeViewModel = ViewModelProviders.of(getActivity())
                          .get(EarthquakeViewModel.class);

  // Get the data from the View Model, and observe any changes.
  earthquakeViewModel.getEarthquakes()
    .observe(this, new Observer<List<Earthquake>>() {
      @Override
      public void onChanged(@Nullable List<Earthquake> earthquakes) {
        // When the View Model changes, update the List
        if (earthquakes != null)
          setEarthquakes(earthquakes);
      }
    });

  // Register an OnSharedPreferenceChangeListener
  SharedPreferences prefs =
    PreferenceManager.getDefaultSharedPreferences(getContext());
  prefs.registerOnSharedPreferenceChangeListener(mPrefListener);
}
 
Example 2
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    Boolean switchPref = sharedPref.getBoolean(SettingsActivity.KEY_PREF_EXAMPLE_SWITCH, false);
    Toast.makeText(this, switchPref.toString(), Toast.LENGTH_SHORT).show();
}
 
Example 3
Source File: RootDetectedDialog.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialogInterface, int which) {
    switch (which) {
        case AlertDialog.BUTTON_NEGATIVE:
            getActivity().finish();
            break;
        case AlertDialog.BUTTON_NEUTRAL:
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
            prefs.edit().putBoolean(Constants.PREFERENCE_RUN_WITH_ROOT, true).apply();
            getDialog().dismiss();
            break;
    }
}
 
Example 4
Source File: VisualizerActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
private void setupSharedPreferences() {
    // Get all of the values from shared preferences to set it up
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    // COMPLETED (4) Use resources here instead of the hard coded string and boolean
    mVisualizerView.setShowBass(sharedPreferences.getBoolean(getString(R.string.pref_show_bass_key),
            getResources().getBoolean(R.bool.pref_show_bass_default)));
    mVisualizerView.setShowMid(true);
    mVisualizerView.setShowTreble(true);
    mVisualizerView.setMinSizeScale(1);
    mVisualizerView.setColor(getString(R.string.pref_color_red_value));
}
 
Example 5
Source File: ForgotPasswordDialog.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialogInterface, int which) {
    switch (which) {
        case AlertDialog.BUTTON_POSITIVE:
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
            prefs.edit().remove(Constants.PREFERENCE_ENC_SEED).apply();
            getDialog().dismiss();
            Intent intent = new Intent(getActivity().getIntent());
            getActivity().startActivityForResult(intent, Constants.REQUEST_CODE_LOGIN);
    }
}
 
Example 6
Source File: FragmentSettings.java    From GPSLogger with GNU General Public License v3.0 5 votes vote down vote up
public void PrefEGM96SetToTrue() {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor1 = settings.edit();
    editor1.putBoolean("prefEGM96AltitudeCorrection", true);
    editor1.commit();
    SwitchPreferenceCompat EGM96 = (SwitchPreferenceCompat) super.findPreference("prefEGM96AltitudeCorrection");
    EGM96.setChecked(true);
}
 
Example 7
Source File: InitActivity.java    From TwrpBuilder with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public String doInBackground(String... voids) {

    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    String name = preferences.getString("recoveryPath", "");
    if (name.equals("")) {
        String output = Shell.SU.run("find /dev/block/platform -type d -name by-name ").toString().replace("[", "").replace("]", "");
        if (output.isEmpty()) {
            output = Shell.SU.run("ls /dev/recovery").toString().replace("[", "").replace("]", "");
            if (!output.isEmpty()) {
                isOldMtk = true;
                SharedPreferences.Editor editor = preferences.edit();
                editor.putBoolean("isOldMtk", true);
                editor.apply();
                SharedP.putRecoveryString(getBaseContext(), output, true);
            }
        } else {
            for (String f : file) {
                String o = Shell.SU.run("ls " + output + File.separator + f).toString().replace("[", "").replace("]", "");
                if (!o.isEmpty()) {
                    SharedP.putRecoveryString(getBaseContext(), o, true);
                    break;
                }
            }

        }
    }
    isOldMtk = preferences.getBoolean("isOldMtk", false);
    IS_SUPPORTED = preferences.getBoolean("isSupport", false);
    return name;
}
 
Example 8
Source File: Preferences.java    From ShaderEditor with MIT License 5 votes vote down vote up
public void init(Context context) {
	systemBarColor = ContextCompat.getColor(
			context,
			R.color.primary_dark_translucent);

	PreferenceManager.setDefaultValues(
			context,
			R.xml.preferences,
			false);

	preferences = PreferenceManager.getDefaultSharedPreferences(
			context);

	update();
}
 
Example 9
Source File: ReadingActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onZoomChangedByPinch(int value) {
    SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    DisplayPreferenceUtilities.setDisplayPreference(SettingsFragment.KEY_DISPLAY_TEXT_SIZE,
            value, defaultSharedPreferences
            , mUserDataDBHelper);
    zoomUpdatedByValue(value);
}
 
Example 10
Source File: AccountsSetManager.java    From fingen with Apache License 2.0 5 votes vote down vote up
public void writeAccountsSet(AccountsSet accountsSet, Context context, IOnComplete onComplete) {
    try {
        accountsSet.setAccountsSetRef((AccountsSetRef) AccountsSetsRefDAO.getInstance(context).createModel(accountsSet.getAccountsSetRef()));
        AccountsSetsLogDAO.getInstance(context).createAccountsSet(accountsSet);
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        preferences.edit().putLong(FgConst.PREF_CURRENT_ACCOUNT_SET, accountsSet.getAccountsSetRef().getID()).apply();
    } catch (Exception e) {
        Toast.makeText(context, context.getString(R.string.msg_error_on_write_to_db), Toast.LENGTH_SHORT).show();
    }
    onComplete.onComplete();
}
 
Example 11
Source File: VisualizerActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
private void setupSharedPreferences() {
    // Get all of the values from shared preferences to set it up
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mVisualizerView.setShowBass(sharedPreferences.getBoolean(getString(R.string.pref_show_bass_key),
            getResources().getBoolean(R.bool.pref_show_bass_default)));
    mVisualizerView.setShowMid(true);
    mVisualizerView.setShowTreble(true);
    mVisualizerView.setMinSizeScale(1);
    mVisualizerView.setColor(getString(R.string.pref_color_red_value));

    // COMPLETED (3) Register the listener
    sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}
 
Example 12
Source File: ItemResultAdapter.java    From CineLog with GNU General Public License v3.0 4 votes vote down vote up
private void populateRatingBar(ItemViewHolder holder) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    String defaultMaxRateValue = prefs.getString("default_max_rate_value", "5");
    int maxRating = Integer.parseInt(defaultMaxRateValue);
    holder.getRatingBar().setNumStars(maxRating);
}
 
Example 13
Source File: EarthquakeListFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 4 votes vote down vote up
private void updateFromPreferences() {
  SharedPreferences prefs =
    PreferenceManager.getDefaultSharedPreferences(getContext());
  mMinimumMagnitude = Integer.parseInt(
    prefs.getString(PreferencesActivity.PREF_MIN_MAG, "3"));
}
 
Example 14
Source File: FragmentTrEditConstructorDialog.java    From fingen with Apache License 2.0 4 votes vote down vote up
private void loadData() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    adapter.setList(PrefUtils.getTrEditorLayout(preferences, getActivity()));
    adapter.notifyDataSetChanged();
}
 
Example 15
Source File: WalrusApplication.java    From Walrus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String toast;
    long[] timings;
    int[] amplitudes;
    long singleTiming;

    if (intent.getBooleanExtra(CardDeviceManager.EXTRA_DEVICE_WAS_ADDED, false)) {
        CardDevice cardDevice = CardDeviceManager.INSTANCE.getCardDevices().get(
                intent.getIntExtra(CardDeviceManager.EXTRA_DEVICE_ID, -1));
        if (cardDevice == null) {
            return;
        }

        toast = getString(R.string.device_connected,
                cardDevice.getClass().getAnnotation(UsbCardDevice.Metadata.class).name());

        timings = new long[]{200, 200, 200, 200, 200};
        amplitudes = new int[]{255, 0, 255, 0, 255};
        singleTiming = 300;
    } else {
        toast = getString(R.string.device_disconnected,
                intent.getStringExtra(CardDeviceManager.EXTRA_DEVICE_NAME));

        timings = new long[]{500, 200, 500, 200, 500};
        amplitudes = new int[]{255, 0, 255, 0, 255};
        singleTiming = 900;
    }

    Toast.makeText(context, toast, Toast.LENGTH_LONG).show();

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
    if (sharedPref.getBoolean("pref_key_on_device_connected_vibrate", true)) {
        Vibrator vibrator = (Vibrator) context.getSystemService(VIBRATOR_SERVICE);
        if (vibrator != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, -1));
            } else {
                vibrator.vibrate(singleTiming);
            }
        }
    }
}
 
Example 16
Source File: StorageUtils.java    From IslamicLibraryAndroid with GNU General Public License v3.0 4 votes vote down vote up
public static boolean didPresentSdcardPermissionsDialog(@NonNull Activity activity) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
    return sharedPreferences.getBoolean(PREF_SDCARDPERMESSION_DIALOG_DISPLAYED, false);
}
 
Example 17
Source File: SettingsUtil.java    From WheelLogAndroid with GNU General Public License v3.0 4 votes vote down vote up
private static SharedPreferences getSharedPreferences(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context);
}
 
Example 18
Source File: EarthquakeListFragment.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 4 votes vote down vote up
private void updateFromPreferences() {
  SharedPreferences prefs =
    PreferenceManager.getDefaultSharedPreferences(getContext());
  mMinimumMagnitude = Integer.parseInt(
    prefs.getString(PreferencesActivity.PREF_MIN_MAG, "3"));
}
 
Example 19
Source File: GPSActivity.java    From GPSLogger with GNU General Public License v3.0 4 votes vote down vote up
private void LoadPreferences() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    prefKeepScreenOn = preferences.getBoolean("prefKeepScreenOn", true);
    if (prefKeepScreenOn) getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    else getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
 
Example 20
Source File: PreferencesManager.java    From RememBirthday with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Return true if buttons for inactive features are hidden
 * @param context Context to call
 * @return Hidden buttons
 */
public static boolean isButtonsForInactiveFeaturesHidden(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    return prefs.getBoolean(context.getString(R.string.pref_hide_inactive_features_key), false);
}