Java Code Examples for android.content.SharedPreferences#Editor

The following examples show how to use android.content.SharedPreferences#Editor . 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: PianoView.java    From semitone with GNU General Public License v3.0 6 votes vote down vote up
public void updateParams(boolean inval) {
    pitches = new int[rows][keys];

    int p = 0;
    for (int i = 0; i < pitch; ++i) p += hasBlackRight(p) ? 2 : 1;
    for (int row = 0; row < rows; ++row) {
        for (int key = 0; key < keys; ++key) {
            pitches[row][key] = p;
            p += hasBlackRight(p) ? 2 : 1;
        }
    }


    if (inval) {
        SharedPreferences.Editor editor =
            PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
        editor.putInt("piano_rows", rows);
        editor.putInt("piano_keys", keys);
        editor.putInt("piano_pitch", pitch);
        editor.apply();

        invalidate();
    }
}
 
Example 2
Source File: MainActivity.java    From Alexa-Voice-Service with MIT License 6 votes vote down vote up
@Override
public void onSuccess(final AuthorizeResult authorizeResult) {
    final String authorizationCode = authorizeResult.getAuthorizationCode();
    final String redirectUri = authorizeResult.getRedirectURI();
    final String clientId = authorizeResult.getClientId();

    SharedPreferences.Editor  preferences = Util.getPrefernces(myContext).edit();
    preferences.putString("clientID",clientId);
    preferences.apply();
    RequestBody formBody = new FormBody.Builder()
            .add("grant_type", "authorization_code")
            .add("code", authorizationCode)
            .add("redirect_uri", redirectUri)
            .add("client_id", clientId)
            .add("code_verifier", codeVerifier)
            .build();

    tokenHanlder.doPostRequest(formBody,TokenHandler.FirstMainActivityDoPostRequest);
}
 
Example 3
Source File: SharedConfig.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void deleteProxy(ProxyInfo proxyInfo)
{
    if (currentProxy == proxyInfo)
    {
        currentProxy = null;
        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
        boolean enabled = preferences.getBoolean("proxy_enabled", false);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("proxy_ip", "");
        editor.putString("proxy_pass", "");
        editor.putString("proxy_user", "");
        editor.putString("proxy_secret", "");
        editor.putInt("proxy_port", 1080);
        editor.putBoolean("proxy_enabled", false);
        editor.putBoolean("proxy_enabled_calls", false);
        editor.commit();
        if (enabled)
        {
            ConnectionsManager.setProxySettings(false, "", 0, "", "", "");
        }
    }
    proxyList.remove(proxyInfo);
    saveProxyList();
}
 
Example 4
Source File: LegacyTokenHelper.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
public void save(Bundle bundle) {
    Validate.notNull(bundle, "bundle");

    SharedPreferences.Editor editor = cache.edit();

    for (String key : bundle.keySet()) {
        try {
            serializeKey(key, bundle, editor);
        } catch (JSONException e) {
            // Error in the bundle. Don't store a partial cache.
            Logger.log(
                    LoggingBehavior.CACHE,
                    Log.WARN,
                    TAG,
                    "Error processing value for key: '" + key + "' -- " + e);

            // Bypass the commit and just return. This cancels the entire edit transaction
            return;
        }
    }
    editor.apply();
}
 
Example 5
Source File: StorageUtilsTest.java    From prebid-mobile-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testGdprConsentIabUndefined() {
    //given
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity);
    SharedPreferences.Editor editor = pref.edit();
    editor.remove(StorageUtils.IABConsent_ConsentStringKey);
    editor.remove(StorageUtils.IABTCF_CONSENT_STRING);
    editor.apply();

    //when
    String gdprConsent = StorageUtils.getPbGdprConsent();

    //then
    assertEquals(null, gdprConsent);
}
 
Example 6
Source File: FragmentSettingViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public void onCheckedDefaultVideo(boolean isChecked) {
    SharedPreferences.Editor editor = sharedPreferences.edit();
    isDefaultPlayer.set(isChecked);
    if (isChecked) {
        editor.putInt(SHP_SETTING.KEY_DEFAULT_PLAYER, 1);
        editor.apply();
    } else {
        editor.putInt(SHP_SETTING.KEY_DEFAULT_PLAYER, 0);
        editor.apply();
    }
}
 
Example 7
Source File: BookSourceActivity.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private void upSourceSort(int sort) {
    SharedPreferences.Editor editor = getPreferences().edit();
    editor.putInt("SourceSort", sort);
    editor.apply();
    upSortMenu();
    setDragEnable(sort);
    mPresenter.refresh();
}
 
Example 8
Source File: FragmentPrice.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private void general() {
    priceChart.setVisibility(View.INVISIBLE);
    chartTitle.setText(TITLE_TEXTS[displayType]);
    colorPadding.setBackgroundColor(getResources().getColor(R.color.colorPrimaryLittleDarker));
    if (ac != null && ac.getPreferences() != null) {
        SharedPreferences.Editor editor = ac.getPreferences().edit();
        editor.putInt("displaytype_chart", displayType);
        editor.apply();
    }
}
 
Example 9
Source File: BookListFragment.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void sortMethodSelected(int which) {
    mCurrentSortIndex = which;
    boolean downloadedOnly = mListener.shouldDisplayDownloadedOnly();
    Cursor bookListCursor = getCursor(downloadedOnly);
    bookListRecyclerViewAdapter.changeCursor(bookListCursor);

    SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putInt(KEY_BOOKK_LIST_SORT_INDEX_ONLY, which);
    editor.apply();

}
 
Example 10
Source File: Settings.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Notification - Should notifications be pushed while in quiet hours
 */

public void setNotificationsShowInQuietHours(boolean showInQuietHours) {
	SharedPreferences.Editor editor = getEditor();
	editor.putBoolean(this.NOTIFICATIONS_SHOW_IN_QUIET_HOURS, showInQuietHours);
	editor.commit();
}
 
Example 11
Source File: Preferences.java    From VIA-AI with MIT License 5 votes vote down vote up
@Override
public void save(Context context, SharedPreferences.Editor editor) {
    Resources resources = context.getResources();

    editor.putBoolean(resources.getString(R.string.prefKey_ADAS_FCW_DetectorStatus), mEnable);
    editor.putBoolean(resources.getString(R.string.prefKey_ADAS_FCW_WarningAudio), mEnableWarningAudio);
    editor.putBoolean(resources.getString(R.string.prefKey_ADAS_FCW_DetectorMode), mIsDeepLearningMode);
}
 
Example 12
Source File: PDFFragment.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPause() {
	super.onPause();

	if (mSearchTask != null)
		mSearchTask.stop();

	if (mFileName != null && mDocView != null) {
		SharedPreferences prefs = fragActivity.getPreferences(Context.MODE_PRIVATE);
		SharedPreferences.Editor edit = prefs.edit();
		edit.putInt("page" + mFileName, mDocView.getDisplayedViewIndex());
		edit.apply();
	}
}
 
Example 13
Source File: PreferenceUtil.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
public void setAlbumGridSizeLand(final int gridSize) {
    final SharedPreferences.Editor editor = mPreferences.edit();
    editor.putInt(ALBUM_GRID_SIZE_LAND, gridSize);
    editor.apply();
}
 
Example 14
Source File: MockSharedPref.java    From armadillo with Apache License 2.0 4 votes vote down vote up
@Override
public SharedPreferences.Editor putInt(String s, int i) {
    putMap.put(s, i);
    return this;
}
 
Example 15
Source File: PreferenceUtil.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
public void setArtistGridSize(final int gridSize) {
    final SharedPreferences.Editor editor = mPreferences.edit();
    editor.putInt(ARTIST_GRID_SIZE, gridSize);
    editor.apply();
}
 
Example 16
Source File: Spotify.java    From blade-player with GNU General Public License v3.0 4 votes vote down vote up
private void refreshSpotifyToken()
{
    try
    {
        URL apiUrl = new URL("https://accounts.spotify.com/api/token");
        HttpsURLConnection urlConnection = (HttpsURLConnection) apiUrl.openConnection();
        urlConnection.setDoInput(true);
        urlConnection.setDoOutput(true);
        urlConnection.setRequestMethod("POST");

        //write POST parameters
        OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
        BufferedWriter writer = new BufferedWriter (new OutputStreamWriter(out, "UTF-8"));
        writer.write("grant_type=refresh_token&");
        writer.write("refresh_token=" + SPOTIFY_REFRESH_TOKEN + "&");
        writer.write("client_id=" + SPOTIFY_CLIENT_ID + "&");
        writer.write("client_secret=" + "3166d3b40ff74582b03cb23d6701c297");
        writer.flush();
        writer.close();
        out.close();

        urlConnection.connect();

        System.out.println("[BLADE] [AUTH-REFRESH] Result : " + urlConnection.getResponseCode() + " " + urlConnection.getResponseMessage());

        BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
        String result = reader.readLine();
        reader.close();
        result = result.substring(1);
        result = result.substring(0, result.length()-1);
        String[] results = result.split(",");
        for(String param : results)
        {
            if(param.startsWith("\"access_token\":\""))
            {
                param = param.replaceFirst("\"access_token\":\"", "");
                param = param.replaceFirst("\"", "");
                SPOTIFY_USER_TOKEN = param;
                spotifyApi.setAccessToken(SPOTIFY_USER_TOKEN);
                SharedPreferences pref = LibraryService.appContext.getSharedPreferences(SettingsActivity.PREFERENCES_ACCOUNT_FILE_NAME, Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = pref.edit();
                editor.putString("spotify_token", SPOTIFY_USER_TOKEN);
                editor.commit();
            }
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}
 
Example 17
Source File: SharedPreferenceUtil.java    From Social with Apache License 2.0 4 votes vote down vote up
public static boolean setSelectedNearbyUserMinage(String min_age){
    SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences("selected_nearby_user", Context.MODE_PRIVATE).edit();
    if(checkNull(min_age)) editor.putString("min_age",min_age);
    editor.commit();
    return true;
}
 
Example 18
Source File: SPUtils.java    From WandFix with MIT License 4 votes vote down vote up
public static void put(Context context, String key, String value) {
    SharedPreferences preferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(key, value);
    editor.apply();
}
 
Example 19
Source File: AppItemSortConfigDialog.java    From apkextractor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onClick(View v) {
    int sort_config=0;
    SharedPreferences.Editor editor=settings.edit();
    switch (v.getId()){
        default:break;
        case R.id.sort_ra_default:{
            sort_config=0;
        }
        break;
        case R.id.sort_ra_ascending_appname:{
            sort_config=1;
        }
        break;
        case R.id.sort_ra_descending_appname:{
            sort_config=2;
        }
        break;
        case R.id.sort_ra_ascending_appsize:{
            sort_config=3;
        }
        break;
        case R.id.sort_ra_descending_appsize:{
            sort_config=4;
        }
        break;
        case R.id.sort_ra_ascending_date:{
            sort_config=5;
        }
        break;
        case R.id.sort_ra_descending_date:{
            sort_config=6;
        }
        break;
        case R.id.sort_ra_ascending_install_date:{
            sort_config=7;
        }
        break;
        case R.id.sort_ra_descending_install_date:{
            sort_config=8;
        }
        break;
        case R.id.sort_ra_ascending_package_name:{
            sort_config=9;
        }
        break;
        case R.id.sort_ra_descending_package_name:{
            sort_config=10;
        }
        break;
    }
    editor.putInt(Constants.PREFERENCE_SORT_CONFIG,sort_config);
    editor.apply();
    cancel();
    if(callback!=null)callback.onOptionSelected(sort_config);
}
 
Example 20
Source File: SharedPreferenceUtil.java    From Social with Apache License 2.0 4 votes vote down vote up
public static boolean setNickname(String nickname){
    SharedPreferences.Editor editor = MyApplication.getContext().getSharedPreferences("user", Context.MODE_PRIVATE).edit();
    if(checkNull(nickname)) editor.putString("nickname",nickname);
    editor.commit();
    return true;
}