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

The following examples show how to use android.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: LocationTracker.java    From Android-SDK with MIT License 7 votes vote down vote up
private void saveLocationListeners()
{
  SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences( getApplicationContext() );
  SharedPreferences.Editor editor = sharedPref.edit();

  try
  {
    HashMap<String, LocationListenerInfo> modifiedListeners = getLabeledLocationListeners();
    editor.putString( LOCATION_LISTENERS, Base64.encodeToString( Serializer.toBytes( modifiedListeners, ISerializer.AMF3 ), Base64.DEFAULT ) );
  }
  catch( Throwable e )
  {
    Log.e( "Cannot save location listeners", e.getMessage() );
  }
  editor.apply();

  super.onDestroy();
}
 
Example 2
Source File: BrowserActivity.java    From Ninja with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // When video fullscreen, just control the sound
    if (fullscreenHolder != null || customView != null || videoView != null) {
        return false;
    }

    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        int vc = Integer.valueOf(sp.getString(getString(R.string.sp_volume), "1"));
        if (vc != 2) {
            return true;
        }
    }

    return false;
}
 
Example 3
Source File: USBGpsApplication.java    From UsbGps4Droid with GNU General Public License v3.0 5 votes vote down vote up
private void setupDaynightMode() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean on = preferences.getBoolean(getString(R.string.pref_daynight_theme_key), false);

    AppCompatDelegate.setDefaultNightMode(on ?
                    AppCompatDelegate.MODE_NIGHT_AUTO:
                    AppCompatDelegate.MODE_NIGHT_YES
    );
}
 
Example 4
Source File: SampleFragment.java    From preferencebinder with Apache License 2.0 5 votes vote down vote up
private void changePreferenceValues(){
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    final boolean booleanPrefValue = !prefs.getBoolean("boolean_pref_key", false);
    final int integerPrefValue = (prefs.getInt("integer_pref_key", 0) + 1) % 100;

    prefs.edit()
            .putBoolean("boolean_pref_key", booleanPrefValue)
            .putInt("integer_pref_key", integerPrefValue)
            .apply();
}
 
Example 5
Source File: UndoRedoSupportEditText.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private void init() {
    mUndoRedoHelper = new UndoRedoHelper(this);
    mUndoRedoHelper.setMaxHistorySize(mEditorSetting.getMaxHistoryEdit());

    SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    mSettings = new KeySettings(mPrefs, getContext());
    mKeyListener = new KeyListener();
    mClipboardManager = ClipboardManagerCompatFactory.newInstance(getContext());
}
 
Example 6
Source File: ObdItemAdapter.java    From AndrOBD with GNU General Public License v3.0 5 votes vote down vote up
public ObdItemAdapter(Context context, int resource, PvList pvs)
{
    super(context, resource);
    prefs = PreferenceManager.getDefaultSharedPreferences(context);
    mInflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    setPvList(pvs);
}
 
Example 7
Source File: DatabaseCleaningService.java    From bitseal with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Deletes old, no-longer-needed data from the database. 
 */
private void cleanDatabase()
{
	try
	{
		Log.d(TAG, "Running database cleaning routine");
		
		// Delete any Payloads in the database older than the time defined by PYBITMESSAGE_NEW_OBJECT_ACCEPTANCE_PERIOD
		long currentTime = System.currentTimeMillis() / 1000;
		long deletionTime = currentTime - PYBITMESSAGE_NEW_OBJECT_ACCEPTANCE_PERIOD;
		
		Log.i(TAG, "Deleting any Payloads with a time value earlier than " + deletionTime + " from the database");
		
		PayloadProvider payProv = PayloadProvider.get(getApplicationContext());
		payProv.deletePayloadsCreatedBefore(deletionTime);
		
		// Update the 'last data clean time'
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
		SharedPreferences.Editor editor = prefs.edit();
	    editor.putLong(LAST_DATABASE_CLEAN_TIME, currentTime);
	    editor.commit();
	    Log.i(TAG, "Updated last database clean time to " + currentTime);
	}
	catch (Exception e)
	{
		Log.e(TAG, "Exception occurred in DatabaseCleaningService.cleanDatabase().\n"
				+ "The exception message was: " + e.getMessage());
	}
}
 
Example 8
Source File: AppWidget41.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
/**
 * Update all active widget instances by pushing changes
 */
public void performUpdate(ApolloService service, int[] appWidgetIds) {

	Context mContext = service.getApplicationContext();
	SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
	String widget_type = sp.getString( WIDGET_STYLE, mContext.getResources().getString(R.string.widget_style_light) );

	final RemoteViews views = new RemoteViews(mContext.getPackageName(),
            (widget_type.equals(mContext.getResources().getString(R.string.widget_style_light))?R.layout.music_fourbyone_app_widget :R.layout.music_fourbyone_app_widget_dark));
    

    CharSequence titleName = service.getTrackName();
    CharSequence artistName = service.getArtistName();

    views.setTextViewText(R.id.four_by_one_title, titleName);
    views.setTextViewText(R.id.four_by_one_artist, artistName);
    // Set album art
    Bitmap bitmap = service.getAlbumBitmap();
    if (bitmap != null) {
        views.setViewVisibility(R.id.four_by_one_albumart, View.VISIBLE);
        views.setViewVisibility(R.id.four_by_one_control_prev, View.GONE);
        views.setImageViewBitmap(R.id.four_by_one_albumart, bitmap);
    } else {
        views.setViewVisibility(R.id.four_by_one_control_prev, View.VISIBLE);
        views.setViewVisibility(R.id.four_by_one_albumart, View.GONE);
    }

    // Set correct drawable and contentDescription for pause state
    final boolean playing = service.isPlaying();
    if (playing) {
        views.setImageViewResource(R.id.four_by_one_control_play,
        		(widget_type.equals(mContext.getResources().getString(R.string.widget_style_light))?R.drawable.apollo_holo_light_pause:R.drawable.apollo_holo_dark_pause));
        views.setContentDescription(R.id.four_by_one_albumart,
            service.getResources().getString(R.string.nowplaying));
    } else {
        views.setImageViewResource(R.id.four_by_one_control_play,
        		(widget_type.equals(mContext.getResources().getString(R.string.widget_style_light))?R.drawable.apollo_holo_light_play:R.drawable.apollo_holo_dark_play));
        views.setContentDescription(R.id.four_by_one_albumart,
            service.getResources().getString(R.string.app_name));
    }

    // Link actions buttons to intents
    linkButtons(service, views, playing);

    pushUpdate(service, appWidgetIds, views);
}
 
Example 9
Source File: LanguageActivity.java    From secure-quick-reliable-login with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_language);

    RecyclerView lstLanguageSelector = findViewById(R.id.lstLanguageSelector);

    List<Language> languages = new ArrayList<>();
    languages.add(new Language(R.string.language_default, ""));
    languages.add(new Language(R.string.language_arabic, "ar"));
    languages.add(new Language(R.string.language_catalan, "ca"));
    languages.add(new Language(R.string.language_chinese, "zh"));
    languages.add(new Language(R.string.language_czech, "cs"));
    languages.add(new Language(R.string.language_dutch, "nl"));
    languages.add(new Language(R.string.language_english, "en"));
    languages.add(new Language(R.string.language_finnish, "fi"));
    languages.add(new Language(R.string.language_french, "fr"));
    languages.add(new Language(R.string.language_german, "de"));
    languages.add(new Language(R.string.language_hebrew, "he"));
    languages.add(new Language(R.string.language_hindi, "hi"));
    languages.add(new Language(R.string.language_hungarian, "hu"));
    languages.add(new Language(R.string.language_indonesian, "id"));
    languages.add(new Language(R.string.language_italian, "it"));
    languages.add(new Language(R.string.language_japanese, "ja"));
    languages.add(new Language(R.string.language_korean, "ko"));
    languages.add(new Language(R.string.language_norwegian, "no"));
    languages.add(new Language(R.string.language_polish, "pl"));
    languages.add(new Language(R.string.language_portuguese, "pt-br"));
    languages.add(new Language(R.string.language_russian, "ru"));
    languages.add(new Language(R.string.language_slovenian, "sl"));
    languages.add(new Language(R.string.language_spanish, "es"));
    languages.add(new Language(R.string.language_swedish, "sv"));

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
    String prefLanguage = sharedPreferences.getString("language", "");

    int i = 0;
    for(Language lang : languages) {
        if(prefLanguage.equals(lang.getCode())) break;
        i++;
    }

    LanguageAdapter adapter = new LanguageAdapter(languages, i);
    // Attach the adapter to the recyclerview to populate items
    lstLanguageSelector.setAdapter(adapter);
    // Set layout manager to position the items
    lstLanguageSelector.setLayoutManager(new LinearLayoutManager(this));

    ImageView moreIndicator = findViewById(R.id.more_indicator);
    lstLanguageSelector.getViewTreeObserver().addOnScrollChangedListener(() -> {
        if(!lstLanguageSelector.canScrollVertically(1)) {
            moreIndicator.setVisibility(View.INVISIBLE);
        } else {
            moreIndicator.setVisibility(View.VISIBLE);
        }
    });
}
 
Example 10
Source File: SettingActivity.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public static String getRenderName(Context context) {
	SharedPreferences prefs = PreferenceManager
			.getDefaultSharedPreferences(context);
	return prefs.getString("player_name",
			context.getString(R.string.player_name_local));
}
 
Example 11
Source File: SharedPreferenceStore.java    From Jockey with Apache License 2.0 4 votes vote down vote up
public SharedPreferenceStore(Context context) {
    this(context, PreferenceManager.getDefaultSharedPreferences(context));
}
 
Example 12
Source File: ClementineWidgetProvider.java    From Android-Remote with GNU General Public License v3.0 4 votes vote down vote up
private void updateViewsOnConnectionStatusChange(Context context, RemoteViews views) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean canConnect = prefs.contains(SharedPreferencesKeys.SP_KEY_IP);

    views.setBoolean(R.id.widget_btn_play_pause, "setEnabled", false);
    views.setBoolean(R.id.widget_btn_next, "setEnabled", false);

    switch (mCurrentConnectionStatus) {
        case IDLE:
        case DISCONNECTED:
            // Reset play button
            views.setImageViewResource(R.id.widget_btn_play_pause,
                    R.drawable.ab_media_play);

            if (canConnect) {
                // Textviews
                views.setTextViewText(R.id.widget_subtitle, prefs.getString(
                        SharedPreferencesKeys.SP_KEY_IP, ""));
                views.setTextViewText(R.id.widget_title,
                        context.getString(R.string.widget_connect_to));

                // Start an intent to connect to Clemetine
                Intent intentConnect = new Intent(context, ClementineBroadcastReceiver.class);
                intentConnect.setAction(ClementineBroadcastReceiver.CONNECT);
                views.setOnClickPendingIntent(R.id.widget_layout, PendingIntent
                        .getBroadcast(context, 0, intentConnect, PendingIntent.FLAG_ONE_SHOT));
            } else {
                // Textviews
                views.setTextViewText(R.id.widget_subtitle,
                        context.getString(R.string.widget_open_clementine));
                views.setTextViewText(R.id.widget_title,
                        context.getString(R.string.widget_not_connected));

                // Start Clementine Remote
                views.setOnClickPendingIntent(R.id.widget_layout,
                        Utilities.getClementineRemotePendingIntent(context));
            }
            break;
        case CONNECTING:
            views.setTextViewText(R.id.widget_subtitle, "");
            views.setTextViewText(R.id.widget_title,
                    context.getString(R.string.connectdialog_connecting));
            break;
        case NO_CONNECTION:
            views.setTextViewText(R.id.widget_subtitle,
                    context.getString(R.string.widget_open_clementine));
            views.setTextViewText(R.id.widget_title,
                    context.getString(R.string.widget_couldnt_connect));
            // Start Clementine Remote
            views.setOnClickPendingIntent(R.id.widget_layout,
                    Utilities.getClementineRemotePendingIntent(context));
            break;
        case CONNECTED:
            views.setBoolean(R.id.widget_btn_play_pause, "setEnabled", true);
            views.setBoolean(R.id.widget_btn_next, "setEnabled", true);
            break;
    }
}
 
Example 13
Source File: App.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
public SharedPreferences getPreferences() {
    if (preferences == null)
        preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    return preferences;
}
 
Example 14
Source File: SharedPreferencesUtils.java    From ZhihuDaily with Apache License 2.0 4 votes vote down vote up
public static Map<String, ?> getAll(Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    return sharedPreferences.getAll();
}
 
Example 15
Source File: PreferenceUtils.java    From SwipeBackLayout with Apache License 2.0 4 votes vote down vote up
public static void setPrefInt(Context context, final String key, final int value) {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    settings.edit().putInt(key, value).commit();
}
 
Example 16
Source File: DialtactsActivity.java    From coursera-android with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    final Intent intent = getIntent();
    fixIntent(intent);

    setContentView(R.layout.dialtacts_activity);

    mContactListFilterController = ContactListFilterController.getInstance(this);
    mContactListFilterController.addListener(mContactListFilterListener);

    findViewById(R.id.dialtacts_frame).addOnLayoutChangeListener(mFirstLayoutListener);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(new ViewPagerAdapter(getFragmentManager()));
    mViewPager.setOnPageChangeListener(mPageChangeListener);
    mViewPager.setOffscreenPageLimit(2);

    // Do same width calculation as ActionBar does
    DisplayMetrics dm = getResources().getDisplayMetrics();
    int minCellSize = getResources().getDimensionPixelSize(R.dimen.fake_menu_button_min_width);
    int cellCount = dm.widthPixels / minCellSize;
    int fakeMenuItemWidth = dm.widthPixels / cellCount;
    if (DEBUG) Log.d(TAG, "The size of fake menu buttons (in pixel): " + fakeMenuItemWidth);

    // Soft menu button should appear only when there's no hardware menu button.
    mMenuButton = findViewById(R.id.overflow_menu);
    if (mMenuButton != null) {
        mMenuButton.setMinimumWidth(fakeMenuItemWidth);
        if (ViewConfiguration.get(this).hasPermanentMenuKey()) {
            // This is required for dialpad button's layout, so must not use GONE here.
            mMenuButton.setVisibility(View.INVISIBLE);
        } else {
            mMenuButton.setOnClickListener(this);
        }
    }
    mSearchButton = findViewById(R.id.searchButton);
    if (mSearchButton != null) {
        mSearchButton.setMinimumWidth(fakeMenuItemWidth);
        mSearchButton.setOnClickListener(this);
    }

    // Setup the ActionBar tabs (the order matches the tab-index contants TAB_INDEX_*)
    setupDialer();
    setupCallLog();
    setupFavorites();
    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    getActionBar().setDisplayShowTitleEnabled(false);
    getActionBar().setDisplayShowHomeEnabled(false);

    // Load the last manually loaded tab
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mLastManuallySelectedFragment = mPrefs.getInt(PREF_LAST_MANUALLY_SELECTED_TAB,
            PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT);
    if (mLastManuallySelectedFragment >= TAB_INDEX_COUNT) {
        // Stored value may have exceeded the number of current tabs. Reset it.
        mLastManuallySelectedFragment = PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT;
    }

    setCurrentTab(intent);

    if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction())
            && icicle == null) {
        setupFilterText(intent);
    }
}
 
Example 17
Source File: DefaultHXSDKModel.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String getPwd() {
    // TODO Auto-generated method stub
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    return preferences.getString(PREF_PWD, null);
}
 
Example 18
Source File: PGPClipperSettingsActivity.java    From PGPClipper with Apache License 2.0 4 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    final ListPreference themePref = (ListPreference) fragment.findPreference("themeSelection");

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    final CheckBoxPreference fingerprintCheckboxPreference = (CheckBoxPreference) fragment.findPreference("enableFingerprintAuth");
    final CheckBoxPreference pgpClipperEnabledCheckbox = (CheckBoxPreference) fragment.findPreference("pgpClipperEnabledCheckbox");

    themePref.setEntryValues(R.array.themes_values);
    themePref.setEntries(R.array.themes);

    String currentVal = sharedPreferences.getString("themeSelection", "dark");
    if (currentVal != null) {
        switch (currentVal) {
            case "dark":
                themePref.setSummary(getResources().getString(R.string.darkText));
                break;
            case "light":
                themePref.setSummary(getResources().getString(R.string.lightText));
                break;
        }
    }

    String providerApp = sharedPreferences.getString("pgpServiceProviderApp", null);
    if (providerApp == null || "".equals(providerApp)) {
        pgpClipperEnabledCheckbox.setEnabled(false);
        pgpClipperEnabledCheckbox.setChecked(false);
        stopService(new Intent(PGPClipperSettingsActivity.this, PGPClipperService.class));
    } else {
        if (pgpClipperEnabledCheckbox.isChecked()) {
            startService(new Intent(PGPClipperSettingsActivity.this, PGPClipperService.class));
        }
        pgpClipperEnabledCheckbox.setEnabled(true);
    }

    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) // Fingerprint API not supported below M
        fingerprintCheckboxPreference.setEnabled(false);
    else {
        fingerprintCheckboxPreference.setEnabled(true);
        }


}
 
Example 19
Source File: PlansHelpActivity.java    From timecat with Apache License 2.0 4 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    prefs.edit().putBoolean("PREFERENCE_NOTES_HELP_SHOWN", true).apply();
}
 
Example 20
Source File: Utils.java    From android with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieves a String value from preference manager. If no such key exists, it will return
 * <code>null</code>.
 *
 * @param context
 * @param key
 * @return
 */
public static String getStringFromPreference(Context context, String key) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    return pref.getString(key, null);
}