android.content.SharedPreferences#Editor ( )源码实例Demo

下面列出了android.content.SharedPreferences#Editor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: semitone   文件: PianoView.java
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();
    }
}
 
源代码2 项目: Alexa-Voice-Service   文件: MainActivity.java
@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);
}
 
源代码3 项目: kognitivo   文件: LegacyTokenHelper.java
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();
}
 
源代码4 项目: TelePlus-Android   文件: SharedConfig.java
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();
}
 
源代码5 项目: iGap-Android   文件: FragmentSettingViewModel.java
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();
    }
}
 
源代码6 项目: HaoReader   文件: BookSourceActivity.java
private void upSourceSort(int sort) {
    SharedPreferences.Editor editor = getPreferences().edit();
    editor.putInt("SourceSort", sort);
    editor.apply();
    upSortMenu();
    setDragEnable(sort);
    mPresenter.refresh();
}
 
源代码7 项目: bcm-android   文件: FragmentPrice.java
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();
    }
}
 
源代码8 项目: VIA-AI   文件: Preferences.java
@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);
}
 
源代码9 项目: PowerFileExplorer   文件: PDFFragment.java
@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();
	}
}
 
源代码10 项目: Pocket-Plays-for-Twitch   文件: Settings.java
/**
 * 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();
}
 
源代码11 项目: IslamicLibraryAndroid   文件: BookListFragment.java
@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();

}
 
源代码12 项目: prebid-mobile-android   文件: StorageUtilsTest.java
@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);
}
 
源代码13 项目: Social   文件: SharedPreferenceUtil.java
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;
}
 
源代码14 项目: Social   文件: SharedPreferenceUtil.java
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;
}
 
源代码15 项目: apkextractor   文件: AppItemSortConfigDialog.java
@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);
}
 
源代码16 项目: WandFix   文件: SPUtils.java
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();
}
 
源代码17 项目: Music-Player   文件: PreferenceUtil.java
public void setAlbumGridSizeLand(final int gridSize) {
    final SharedPreferences.Editor editor = mPreferences.edit();
    editor.putInt(ALBUM_GRID_SIZE_LAND, gridSize);
    editor.apply();
}
 
源代码18 项目: blade-player   文件: Spotify.java
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();
    }
}
 
源代码19 项目: Music-Player   文件: PreferenceUtil.java
public void setArtistGridSize(final int gridSize) {
    final SharedPreferences.Editor editor = mPreferences.edit();
    editor.putInt(ARTIST_GRID_SIZE, gridSize);
    editor.apply();
}
 
源代码20 项目: armadillo   文件: MockSharedPref.java
@Override
public SharedPreferences.Editor putInt(String s, int i) {
    putMap.put(s, i);
    return this;
}