本文整理汇总了Java中android.content.SharedPreferences.getBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java SharedPreferences.getBoolean方法的具体用法?Java SharedPreferences.getBoolean怎么用?Java SharedPreferences.getBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.SharedPreferences
的用法示例。
在下文中一共展示了SharedPreferences.getBoolean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSubsonicApiClient
import android.content.SharedPreferences; //导入方法依赖的package包/类
private static SubsonicAPIClient createSubsonicApiClient(final Context context) {
final SharedPreferences preferences = Util.getPreferences(context);
int instance = preferences.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
String serverUrl = preferences.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null);
String username = preferences.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);
String password = preferences.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null);
boolean allowSelfSignedCertificate = preferences
.getBoolean(Constants.PREFERENCES_KEY_ALLOW_SELF_SIGNED_CERTIFICATE + instance, false);
if (serverUrl == null ||
username == null ||
password == null) {
Log.i("MusicServiceFactory", "Server credentials is not available");
return new SubsonicAPIClient("http://localhost", "", "",
SubsonicAPIVersions.fromApiVersion(Constants.REST_PROTOCOL_VERSION),
Constants.REST_CLIENT_ID, allowSelfSignedCertificate, BuildConfig.DEBUG);
}
return new SubsonicAPIClient(serverUrl, username, password,
SubsonicAPIVersions.fromApiVersion(Constants.REST_PROTOCOL_VERSION),
Constants.REST_CLIENT_ID, allowSelfSignedCertificate, BuildConfig.DEBUG);
}
示例2: setDarkTheme
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static void setDarkTheme(Context context) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean darkTheme = sharedPrefs.getBoolean(context.getString(R.string.key_themes_pref), false);
if (darkTheme) {
context.setTheme(R.style.AppThemeDark);
} else {
context.setTheme(R.style.AppThemeLight);
}
}
示例3: get
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* 获取存放object
* @param context
* @param fileName
* @param key
* @param def
* @return
*/
public static Object get(Context context, String fileName, String key, Object def) {
SharedPreferences sp = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
if (def instanceof String) {
return sp.getString(key, def.toString());
} else if (def instanceof Integer) {
return sp.getInt(key, ((Integer) def).intValue());
} else if (def instanceof Boolean) {
return sp.getBoolean(key, ((Boolean) def).booleanValue());
} else if (def instanceof Float) {
return sp.getFloat(key, ((Float) def).floatValue());
} else if (def instanceof Long) {
return sp.getLong(key, ((Long) def).longValue());
} else if (def instanceof Set) {
return sp.getStringSet(key, (Set<String>) def);
}
return def;
}
示例4: onResume
import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
protected void onResume() {
super.onResume();
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
doBuildInfo = prefs.getBoolean("doBuildInfo", doBuildInfo);
doMemoryInfo = prefs.getBoolean("doMemoryInfo", doMemoryInfo);
doPreferredApplications = prefs.getBoolean("doPreferredApplications",
doPreferredApplications);
doNonSystemApps = prefs.getBoolean("doNonSystemApps", doNonSystemApps);
doSystemApps = prefs.getBoolean("doSystemApps", doSystemApps);
refresh();
}
示例5: handlePermissions
import android.content.SharedPreferences; //导入方法依赖的package包/类
private void handlePermissions() {
SharedPreferences permissionStatus = this.getSharedPreferences("permissionStatus",
this.MODE_PRIVATE);
if (ActivityCompat.checkSelfPermission(this, permissionsRequired[0]) != PackageManager
.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(this, permissionsRequired[1]) !=
PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permissionsRequired[0])
|| ActivityCompat.shouldShowRequestPermissionRationale(this,
permissionsRequired[1])) {
//true means user not allowed the permission but may we can convince him/her
//false have two meaning: 1-user not asked for permission 2-user denied and check
// 'Don't Ask Again'
//so we had to Show Information about why you need the permission
ActivityCompat.requestPermissions(this, permissionsRequired,
PERMISSION_CALLBACK_CONSTANT);
} else if (permissionStatus.getBoolean(permissionsRequired[0], false)) {
//Previously Permission Request was cancelled with 'Dont Ask Again',
// Redirect to Settings after showing Information about why you need the permission
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", this.getPackageName(), null);
intent.setData(uri);
this.startActivityForResult(intent, REQUEST_PERMISSION_SETTING);
Toast.makeText(this, "Go to Permissions to Grant Sms", Toast.LENGTH_LONG)
.show();
} else {
//just request the permission
ActivityCompat.requestPermissions(this, permissionsRequired,
PERMISSION_CALLBACK_CONSTANT);
}
SharedPreferences.Editor editor = permissionStatus.edit();
editor.putBoolean(permissionsRequired[0], true).apply();
} else {
proceedAfterPermission();
}
}
示例6: start
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void start(Context c) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
if (prefs.getBoolean("notifications_new_message", true) && WalletStorage.getInstance(c).get().size() >= 1) {
service = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(c, NotificationService.class);
pintent = PendingIntent.getService(c, 23, i, 0);
int syncInt = Integer.parseInt(prefs.getString("sync_frequency", "4"));
service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(), AlarmManager.INTERVAL_HOUR * syncInt, pintent);
}
}
示例7: getBoolean
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static Boolean getBoolean(Context context, String strKey,
Boolean strDefault) {
SharedPreferences setPreferences = context.getSharedPreferences(
spFileName, Context.MODE_PRIVATE);
Boolean result = setPreferences.getBoolean(strKey, strDefault);
return result;
}
示例8: onIncomingCallStarted
import android.content.SharedPreferences; //导入方法依赖的package包/类
protected void onIncomingCallStarted(Context context, String number)
{
try
{
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean isPreferencesFiltersActivated = sharedPreferences.getBoolean("preferences_filters_activate",false);
if((isPreferencesFiltersActivated == false) || ((isPreferencesFiltersActivated == true) && (isRecordableContact == 1)))
{
RecordServiceManager recordServiceManager = new RecordServiceManager();
recordServiceManager.startService(context.getApplicationContext(), 0, number);
}
else
{
if((isPreferencesFiltersActivated == true) && (isRecordableContact != 0))
{
ShakeDetectorServiceManager shakeDetectorServiceManager = new ShakeDetectorServiceManager();
shakeDetectorServiceManager.startService(context.getApplicationContext(), 0, number);
}
}
}
catch (Exception e)
{
Log.e("TelephoneCallReceiver", "onIncomingCallStarted : " + context.getApplicationContext().getString(R.string.log_telephone_call_receiver_error_incoming_call_started) + " : " + number + " : " + e);
databaseManager.insertLog(context.getApplicationContext(), "" + context.getApplicationContext().getString(R.string.log_telephone_call_receiver_error_incoming_call_started) + " : " + number, new Date().getTime(), 1, false);
}
}
示例9: onResume
import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void onResume() {
super.onResume();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) {
aboutField.requestFocus();
AndroidUtilities.showKeyboard(aboutField);
}
updateTheme();
}
示例10: DecodeThread
import android.content.SharedPreferences; //导入方法依赖的package包/类
DecodeThread(CaptureActivity activity, Vector<BarcodeFormat> decodeFormats, String characterSet,
ResultPointCallback resultPointCallback)
{
this.activity = activity;
handlerInitLatch = new CountDownLatch(1);
hints = new Hashtable<DecodeHintType, Object>(3);
// The prefs can't change while the thread is running, so pick them up once here.
if (decodeFormats == null || decodeFormats.isEmpty())
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
decodeFormats = new Vector<BarcodeFormat>();
if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_1D, true))
{
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
}
if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_QR, true))
{
decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
}
if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_DATA_MATRIX, true))
{
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
}
}
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
if (characterSet != null)
{
hints.put(DecodeHintType.CHARACTER_SET, characterSet);
}
hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
}
示例11: getBoolean
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static boolean getBoolean(Context context, String key) {
SharedPreferences sp = getSP(context);
return sp.getBoolean(key, false);
}
示例12: readShowsLanguageSwitchKey
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static boolean readShowsLanguageSwitchKey(final SharedPreferences prefs) {
return !prefs.getBoolean(PREF_HIDE_LANGUAGE_SWITCH_KEY, false);
}
示例13: getShouldSendBluetoothAlbumArt
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static boolean getShouldSendBluetoothAlbumArt(Context context)
{
SharedPreferences preferences = getPreferences(context);
return preferences.getBoolean(Constants.PREFERENCES_KEY_SEND_BLUETOOTH_ALBUM_ART, true);
}
示例14: setPlayProfileAnimation
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void setPlayProfileAnimation(boolean value) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
if (!AndroidUtilities.isTablet() && preferences.getBoolean("view_animations", true)) {
playProfileAnimation = value;
}
}
示例15: getBoolean
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static boolean getBoolean(Context context, int key, boolean defValue) {
SharedPreferences
pref = PreferenceManager
.getDefaultSharedPreferences(context);
return pref.getBoolean(context.getString(key), defValue);
}