Example usage for android.content SharedPreferences getBoolean

List of usage examples for android.content SharedPreferences getBoolean

Introduction

In this page you can find the example usage for android.content SharedPreferences getBoolean.

Prototype

boolean getBoolean(String key, boolean defValue);

Source Link

Document

Retrieve a boolean value from the preferences.

Usage

From source file:pj.rozkladWKD.C2DMReceiver.java

public void showNotification(String ticker, String contentTitle, String contentText, PendingIntent intent,
        int number) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    int icon = R.drawable.ic_launcher_wkd;
    CharSequence tickerText = ticker;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    Context context = getApplicationContext();
    notification.number = Prefs.getNotificationMessageNextNumber(context);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    SharedPreferences prefs = Prefs.get(context);
    if (prefs.getBoolean(Prefs.NOTIFICATION_SOUND, true))
        notification.defaults |= Notification.DEFAULT_SOUND;
    if (prefs.getBoolean(Prefs.NOTIFICATION_VIBRATION, true))
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_LIGHTS;

    notification.setLatestEventInfo(context, contentTitle, contentText, intent);

    mNotificationManager.notify(NOTIFICATION_ID, notification);

}

From source file:fiskinfoo.no.sintef.fiskinfoo.Baseclasses.ToolsGeoJson.java

@SuppressWarnings("unused")
public ToolsGeoJson(Context mContext) {
    //check if exists
    SharedPreferences prefs = mContext.getSharedPreferences("no.barentswatch.fiskinfo", Context.MODE_PRIVATE);
    Boolean informationExists = prefs.getBoolean("geoJson", false);
    if (informationExists) {
        versionNumber = prefs.getString("toolsVersionNumber", null);
        String tmp = prefs.getString("toolsGeoJson", null);
        if (versionNumber == null || tmp == null) {
            tools = null;// w ww.ja va2  s  . c o  m
            versionNumber = INVALID_VERSION;
        }
    } else {
        versionNumber = INVALID_VERSION;
    }
}

From source file:com.farmerbb.secondscreen.util.U.java

public static boolean runDensityCommand(Context context, String requestedDpi) {
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display disp = wm.getDefaultDisplay();
    disp.getRealMetrics(metrics);//from www. j a  va2  s .c  om

    SharedPreferences prefMain = getPrefMain(context);
    String currentDpi;
    String nativeDpi = Integer
            .toString(SystemProperties.getInt("ro.sf.lcd_density", prefMain.getInt("density", 0)));

    if (prefMain.getBoolean("debug_mode", false)) {
        SharedPreferences prefCurrent = getPrefCurrent(context);
        currentDpi = prefCurrent.getString("density", "reset");

        if ("reset".equals(currentDpi))
            currentDpi = nativeDpi;
    } else
        currentDpi = Integer.toString(metrics.densityDpi);

    if (requestedDpi.equals("reset"))
        requestedDpi = nativeDpi;

    return !requestedDpi.equals(currentDpi);
}

From source file:de.geeksfactory.opacclient.reminder.SyncAccountService.java

@Override
protected void doWakefulWork(Intent intent) {
    if (BuildConfig.DEBUG)
        Log.i(NAME, "SyncAccountService started");

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);

    if (!sp.getBoolean(SyncAccountAlarmListener.PREF_SYNC_SERVICE, false)) {
        if (BuildConfig.DEBUG)
            Log.i(NAME, "notifications are disabled");
        return;//from ww  w .  ja  v a 2  s  . c om
    }

    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null) {
        if (!sp.getBoolean("notification_service_wifionly", false)
                || networkInfo.getType() == ConnectivityManager.TYPE_WIFI
                || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
            syncAccounts();
        } else {
            failed = true;
        }
    } else {
        failed = true;
    }

    if (BuildConfig.DEBUG) {
        Log.i(NAME, "SyncAccountService finished " + (failed ? " with errors" : " " + "successfully"));
    }

    long previousPeriod = sp.getLong(SyncAccountAlarmListener.PREF_SYNC_INTERVAL, 0);
    long newPeriod = failed ? AlarmManager.INTERVAL_HOUR : AlarmManager.INTERVAL_HALF_DAY;
    if (previousPeriod != newPeriod) {
        sp.edit().putLong(SyncAccountAlarmListener.PREF_SYNC_INTERVAL, newPeriod).apply();
        WakefulIntentService.cancelAlarms(this);
        WakefulIntentService.scheduleAlarms(SyncAccountAlarmListener.withOnePeriodBeforeStart(), this);
    }
}

From source file:github.daneren2005.dsub.util.Util.java

public static boolean isOffline(Context context) {
    SharedPreferences prefs = getPreferences(context);
    return prefs.getBoolean(Constants.PREFERENCES_KEY_OFFLINE, false);
}

From source file:github.daneren2005.dsub.util.Util.java

public static boolean isScrobblingEnabled(Context context) {
    SharedPreferences prefs = getPreferences(context);
    return prefs.getBoolean(Constants.PREFERENCES_KEY_SCROBBLE, false);
}

From source file:github.daneren2005.dsub.util.Util.java

public static boolean getDisplayTrack(Context context) {
    SharedPreferences prefs = getPreferences(context);
    return prefs.getBoolean(Constants.PREFERENCES_KEY_DISPLAY_TRACK, false);
}

From source file:com.onesignal.OSSubscriptionState.java

OSSubscriptionState(boolean asFrom, boolean permissionAccepted) {
    observable = new OSObservable<>("changed", false);

    if (asFrom) {
        final SharedPreferences prefs = getGcmPreferences(appContext);
        userSubscriptionSetting = prefs.getBoolean("ONESIGNAL_SUBSCRIPTION_LAST", false);
        userId = prefs.getString("ONESIGNAL_PLAYER_ID_LAST", null);
        pushToken = prefs.getString("ONESIGNAL_PUSH_TOKEN_LAST", null);
        accepted = prefs.getBoolean("ONESIGNAL_PERMISSION_ACCEPTED_LAST", false);
    } else {// w  ww . j  ava  2 s.c  o  m
        userSubscriptionSetting = OneSignalStateSynchronizer.getUserSubscribePreference();
        userId = OneSignal.getUserId();
        pushToken = OneSignalStateSynchronizer.getRegistrationId();
        accepted = permissionAccepted;
    }
}

From source file:sg.macbuntu.android.pushcontacts.SmsReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();/* w  w w. j a v a 2s . c o m*/
    SmsMessage[] msgs = null;

    String contact = "";
    String sender = "";
    String body = "";
    String account = "";

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean pushPreference = prefs.getBoolean("cbPush", true);

    if (pushPreference) {
        if (bundle != null && accountExist(context)) {
            Object[] pdus = (Object[]) bundle.get("pdus");

            msgs = new SmsMessage[pdus.length];
            msgs[0] = SmsMessage.createFromPdu((byte[]) pdus[0]);

            contact = msgs[0].getOriginatingAddress();
            body = msgs[0].getMessageBody().toString();
            account = getAccount(context);
            sender = getNameFromPhoneNumber(context, contact);

            Toast.makeText(context, R.string.toast_push, Toast.LENGTH_LONG).show();
            postData(account, contact, body, sender);
        }
    }
}

From source file:be.benvd.mvforandroid.SettingsActivity.java

private void updateUsagePreference(SharedPreferences sharedPreferences) {
    boolean autoUsage = sharedPreferences.getBoolean("auto_usage", false);
    autoUsagePreference.setSummary(autoUsage ? getString(R.string.settings_auto_usage_enabled)
            : getString(R.string.settings_auto_usage_disabled));
}