Java Code Examples for android.content.SharedPreferences.Editor#putBoolean()

The following examples show how to use android.content.SharedPreferences.Editor#putBoolean() . 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: SPUtil.java    From FastLib with Apache License 2.0 6 votes vote down vote up
/**
 * 存放object
 *
 * @param context
 * @param fileName
 * @param key
 * @param object
 * @return
 */
public static boolean put(Context context, String fileName, String key, Object object) {
    SharedPreferences sp = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    Editor editor = sp.edit();
    if (object instanceof String) {
        editor.putString(key, (String) object);
    } else if (object instanceof Integer) {
        editor.putInt(key, ((Integer) object).intValue());
    } else if (object instanceof Boolean) {
        editor.putBoolean(key, ((Boolean) object).booleanValue());
    } else if (object instanceof Float) {
        editor.putFloat(key, ((Float) object).floatValue());
    } else if (object instanceof Long) {
        editor.putLong(key, ((Long) object).longValue());
    } else if (object instanceof Set) {
        editor.putStringSet(key, (Set<String>) object);
    } else {
        editor.putStringSet(key, (Set<String>) object);
    }
    return editor.commit();
}
 
Example 2
Source File: SharedPreUtils.java    From JianDan with Apache License 2.0 5 votes vote down vote up
public static void setBoolean(Context context, String key, boolean value) {
	SharedPreferences sp = context.getSharedPreferences(
			SHARED_PREFERANCE_NAME, Context.MODE_PRIVATE);
	Editor editor = sp.edit();
	editor.putBoolean(key, value);
	editor.commit();
}
 
Example 3
Source File: EventPreferencesSMS.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
void loadSharedPreferences(SharedPreferences preferences)
{
    Editor editor = preferences.edit();
    editor.putBoolean(PREF_EVENT_SMS_ENABLED, _enabled);
    //editor.putString(PREF_EVENT_SMS_EVENT, String.valueOf(this._smsEvent));
    editor.putString(PREF_EVENT_SMS_CONTACTS, this._contacts);
    editor.putString(PREF_EVENT_SMS_CONTACT_GROUPS, this._contactGroups);
    editor.putString(PREF_EVENT_SMS_CONTACT_LIST_TYPE, String.valueOf(this._contactListType));
    editor.putBoolean(PREF_EVENT_SMS_PERMANENT_RUN, this._permanentRun);
    editor.putString(PREF_EVENT_SMS_DURATION, String.valueOf(this._duration));
    editor.apply();
}
 
Example 4
Source File: AlarmClockService.java    From AlarmOn with Apache License 2.0 5 votes vote down vote up
public void fixPersistentSettings() {
  final String badDebugName = "DEBUG_MODE\"";
  final String badNotificationName = "NOTFICATION_ICON";
  final String badLockScreenName = "LOCK_SCREEN\"";
  final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
  Map<String, ?> prefNames = prefs.getAll();
  // Don't do anything if the bad preferences have already been fixed.
  if (!prefNames.containsKey(badDebugName) &&
      !prefNames.containsKey(badNotificationName) &&
      !prefNames.containsKey(badLockScreenName)) {
    return;
  }
  Editor editor = prefs.edit();
  if (prefNames.containsKey(badDebugName)) {
    editor.putString(AppSettings.DEBUG_MODE, prefs.getString(badDebugName, null));
    editor.remove(badDebugName);
  }
  if (prefNames.containsKey(badNotificationName)){
    editor.putBoolean(AppSettings.NOTIFICATION_ICON, prefs.getBoolean(badNotificationName, true));
    editor.remove(badNotificationName);
  }
  if (prefNames.containsKey(badLockScreenName)) {
    editor.putString(AppSettings.LOCK_SCREEN, prefs.getString(badLockScreenName, null));
    editor.remove(badLockScreenName);
  }
  editor.apply();
}
 
Example 5
Source File: SharedPreUtils.java    From JianDan_OkHttpWithVolley with Apache License 2.0 5 votes vote down vote up
public static void setBoolean(Context context, String key, boolean value) {
	SharedPreferences sp = context.getSharedPreferences(
			SHARED_PREFERANCE_NAME, Context.MODE_PRIVATE);
	Editor editor = sp.edit();
	editor.putBoolean(key, value);
	editor.commit();
}
 
Example 6
Source File: PreferencesUtil.java    From ViewDebugHelper with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** 设置Key对应的boolean值 */
public static boolean setBoolValue(Context context,String key, boolean value) {
	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
	Editor editor = prefs.edit();
	editor.putBoolean(key, value);
	return editor.commit();
}
 
Example 7
Source File: Preference.java    From product-emm with Apache License 2.0 5 votes vote down vote up
/**
 * Put boolean data to shared preferences in private mode.
 * @param context - The context of activity which is requesting to put data.
 * @param key     - Used to identify the value.
 * @param value   - The actual value to be saved.
 */
public static void putBoolean(Context context, String key, boolean value) {
	SharedPreferences mainPref =
			context.getSharedPreferences(context.getResources()
					                             .getString(R.string.shared_pref_package),
			                             Context.MODE_PRIVATE
			);
	Editor editor = mainPref.edit();
	editor.putBoolean(key, value);
	editor.commit();
}
 
Example 8
Source File: PreferencesManager.java    From letv with Apache License 2.0 5 votes vote down vote up
public void setGameShow(boolean isShow) {
    Editor editor = context.getSharedPreferences(SETTINGS, 4).edit();
    editor.putBoolean("isGameShow", isShow);
    if (LetvUtils.isSpecialChannel()) {
        editor.putBoolean("isGameShow", false);
    }
    editor.commit();
}
 
Example 9
Source File: Prefs.java    From PS4-Payload-Sender-Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param key   The name of the preference to modify.
 * @param value The new value for the preference.
 * @see Editor#putBoolean(String, boolean)
 */
public static void putBoolean(final String key, final boolean value) {
    final Editor editor = getPreferences().edit();
    editor.putBoolean(key, value);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
        editor.commit();
    } else {
        editor.apply();
    }
}
 
Example 10
Source File: PreferenceUtil.java    From HeroVideo-master with Apache License 2.0 5 votes vote down vote up
public static void putBoolean(String key, boolean value)
{

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(HeroVideoApp.getInstance());
    Editor editor = sharedPreferences.edit();
    editor.putBoolean(key, value);
    editor.apply();
}
 
Example 11
Source File: NetworkConnectedReceiver.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

    Log.d(TAG, "Entered OnReceive in NetworkConnectedReceiver");

    //Skipping non admin users
    if (ActivityManager.getCurrentUser() != 0) {
        Log.i(TAG, "The user serial number is " + ActivityManager.getCurrentUser());
    } else {
        Log.i(TAG, "The user is admin");
        SharedPreferences prefs = context.getSharedPreferences(EMM_PREFERENCES, Context.MODE_PRIVATE);
        Boolean isAgentCalled = prefs.getBoolean(EMM_AGENT_HAS_BEEN_CALLED, false);

        if (!isAgentCalled) {
            //Check network connected
            if (isConnected(context)) {
                Intent agentLauncherIntent = new Intent();
                agentLauncherIntent.setComponent(new ComponentName(Constants.AGENT_APP_PACKAGE_NAME,
                                                                   Constants.AGENT_APP_PACKAGE_NAME + Constants.AGENT_APP_LAUNCH_ACTIVITY));
                agentLauncherIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                agentLauncherIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(agentLauncherIntent);

                Editor editor = prefs.edit();
                editor.putBoolean(EMM_AGENT_HAS_BEEN_CALLED, true);
                editor.apply();
                Log.i(TAG, "EMM agent has been called");
            }
        }
    }
}
 
Example 12
Source File: PreferenceUtil.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
public void setColoredAppShortcuts(final boolean value) {
    final Editor editor = mPreferences.edit();
    editor.putBoolean(COLORED_APP_SHORTCUTS, value);
    editor.apply();
}
 
Example 13
Source File: AlbumVideoController.java    From letv with Apache License 2.0 4 votes vote down vote up
private void setPreferenceValue(Context context, int type, boolean value) {
    Editor editor = context.getSharedPreferences("gesture", 0).edit();
    editor.putBoolean(type == 0 ? "isFirstPush" : "isFirstDownload", false);
    editor.commit();
}
 
Example 14
Source File: kbili.java    From styT with Apache License 2.0 4 votes vote down vote up
public static void a(Context context, String str, boolean z) {
    Editor edit = a(context).edit();
    edit.putBoolean(str, z);
    edit.apply();
}
 
Example 15
Source File: PreferencesManager.java    From letv with Apache License 2.0 4 votes vote down vote up
public void setChannelShow(boolean isShow) {
    Editor editor = context.getSharedPreferences(SETTINGS, 4).edit();
    editor.putBoolean("isChannelShow", isShow);
    editor.commit();
}
 
Example 16
Source File: BooleanPreferenceProvider.java    From TowerCollector with Mozilla Public License 2.0 4 votes vote down vote up
@Override
void setPreferenceValue(Editor editor, @StringRes int valueKey, Boolean value) {
    String key = context.getString(valueKey);
    editor.putBoolean(key, value);
}
 
Example 17
Source File: PreferenceHelper.java    From java-n-IDE-for-Android with Apache License 2.0 3 votes vote down vote up
public static void setWidgetExistsPreference(Context context, int[] appWidgetIds) {

        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

        Editor editor = sharedPrefs.edit();

        for (int appWidgetId : appWidgetIds) {
            String widgetExists = WIDGET_EXISTS_PREFIX.concat(Integer.toString(appWidgetId));
            editor.putBoolean(widgetExists, true);
        }

        editor.commit();


    }
 
Example 18
Source File: PreferenceHelper.java    From matlog with GNU General Public License v3.0 3 votes vote down vote up
public static void setWidgetExistsPreference(Context context, int[] appWidgetIds) {

        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

        Editor editor = sharedPrefs.edit();

        for (int appWidgetId : appWidgetIds) {
            String widgetExists = WIDGET_EXISTS_PREFIX.concat(Integer.toString(appWidgetId));
            editor.putBoolean(widgetExists, true);
        }

        editor.apply();

    }
 
Example 19
Source File: SharePreUtil.java    From Aria with Apache License 2.0 3 votes vote down vote up
/**
 * 存储Boolean值到配置文件
 *
 * @param preName 配置文件名
 * @param key 键值
 * @param value 需要存储的boolean值
 */
public static Boolean putBoolean(String preName, Context context, String key, Boolean value) {
  SharedPreferences pre = context.getSharedPreferences(preName, Context.MODE_PRIVATE);
  Editor editor = pre.edit();
  editor.putBoolean(key, value);
  return editor.commit();
}
 
Example 20
Source File: PreferenceHelper.java    From javaide with GNU General Public License v3.0 3 votes vote down vote up
public static void setWidgetExistsPreference(Context context, int[] appWidgetIds) {

        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

        Editor editor = sharedPrefs.edit();

        for (int appWidgetId : appWidgetIds) {
            String widgetExists = WIDGET_EXISTS_PREFIX.concat(Integer.toString(appWidgetId));
            editor.putBoolean(widgetExists, true);
        }

        editor.commit();


    }