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:com.dopecoin.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
    int provider = Integer.parseInt(sp.getString(Constants.PREFS_KEY_EXCHANGE_PROVIDER, "0"));
    boolean forceRefresh = sp.getBoolean(Constants.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false);
    if (forceRefresh)
        sp.edit().putBoolean(Constants.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false).commit();

    if (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) {
        float newDogeBtcConversion = -1;
        if ((leafBtcConversion == -1 && newDogeBtcConversion == -1) || forceRefresh)
            newDogeBtcConversion = requestDogeBtcConversion(provider);

        if (newDogeBtcConversion != -1)
            leafBtcConversion = newDogeBtcConversion;

        if (leafBtcConversion == -1)
            return null;

        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, leafBtcConversion, userAgent,
                    BITCOINAVERAGE_FIELDS);
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, leafBtcConversion, userAgent,
                    BLOCKCHAININFO_FIELDS);

        if (newExchangeRates != null) {
            String providerUrl;/*  ww  w . ja v a2 s  . c  o m*/
            switch (provider) {
            case 0:
                providerUrl = "http://www.cryptsy.com";
                break;
            case 1:
                providerUrl = "http://www.vircurex.com";
                break;
            default:
                providerUrl = "";
                break;
            }
            float mBTCRate = leafBtcConversion * 1000;
            String strmBTCRate = String.format("%.5f", mBTCRate).replace(',', '.');
            newExchangeRates.put("mBTC", new ExchangeRate("mBTC",
                    new BigDecimal(GenericUtils.toNanoCoins(strmBTCRate, 0)).toBigInteger(), providerUrl));
            exchangeRates = newExchangeRates;
            lastUpdated = now;

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null || leafBtcConversion == -1)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final ExchangeRate rate = bestExchangeRate(selectionArgs[0]);
        if (rate != null)
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
    }

    return cursor;
}

From source file:com.dwdesign.tweetings.app.TweetingsApplication.java

public void getSync(String timeline, long account_id, String screen_name) {
    final SharedPreferences preferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final String username = screen_name;
    final String syncTimeline = timeline;
    if (preferences.getBoolean(PREFERENCE_KEY_SYNC_ENABLED, false)) {
        Runnable runnable = new Runnable() {
            @Override/*  ww w  . j  a  v  a  2 s  . c o  m*/
            public void run() {
                String syncUrl = "";
                try {
                    if (preferences.getString(PREFERENCE_KEY_SYNC_TYPE, "tweetmarker").equals("tweetmarker")) {

                        syncUrl = "https://api.tweetmarker.net/v1/lastread?collection=" + syncTimeline
                                + "&username=" + username + "&api_key=" + TWEETMARKER_API_KEY;
                        HttpClient httpClient = new DefaultHttpClient();
                        HttpResponse response = httpClient.execute(new HttpGet(syncUrl));

                        BufferedReader reader = new BufferedReader(
                                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
                        String sResponse;
                        StringBuilder s = new StringBuilder();

                        while ((sResponse = reader.readLine()) != null) {
                            s = s.append(sResponse);
                        }
                        //Log.i("TweetMarker Retrieve", syncTimeline + " " + s.toString());

                        Intent broadcast = new Intent();
                        broadcast.putExtra(PARAM_SYNC_TYPE, syncTimeline);
                        broadcast.putExtra(PARAM_SYNC_ID, s.toString());

                        broadcast.setAction(BROADCAST_SYNC_ACTION);
                        sendBroadcast(broadcast);

                    } else {
                        String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

                        syncUrl = TWEETINGS_SYNC_GET_URL + "?did=" + deviceId + "&android=1&u=" + username
                                + "&tl=" + syncTimeline;
                        HttpClient httpClient = new DefaultHttpClient();
                        HttpResponse response = httpClient.execute(new HttpGet(syncUrl));

                        BufferedReader reader = new BufferedReader(
                                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
                        String sResponse;
                        StringBuilder s = new StringBuilder();

                        while ((sResponse = reader.readLine()) != null) {
                            s = s.append(sResponse);
                        }
                        //Log.i("Tweetings Sync Retrieve", syncUrl + syncTimeline + " " + s.toString());

                        Intent broadcast = new Intent();
                        broadcast.putExtra(PARAM_SYNC_TYPE, syncTimeline);
                        broadcast.putExtra(PARAM_SYNC_ID, s.toString());

                        broadcast.setAction(BROADCAST_SYNC_ACTION);
                        sendBroadcast(broadcast);
                    }
                } catch (Exception e) {
                    Log.e("Sync", e.getMessage());
                    //Toast.makeText(getApplicationContext(), "Network exception" + e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }
        };
        new Thread(runnable).start();
    }
}

From source file:com.etime.ETimeActivity.java

/**
 * Callback for pressing the back button. Used to prevent the app
 * from destroying it self if the back button is pressed to go to
 * previous app/homescreen./*from  w  ww.  jav  a 2 s .  c  o m*/
 */
@Override
public void onBackPressed() {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity);
    if (pref.getBoolean(getString(R.string.keepInBackground), true)) {
        Intent setIntent = new Intent(Intent.ACTION_MAIN);
        setIntent.addCategory(Intent.CATEGORY_HOME);
        setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(setIntent);
    } else {
        super.onBackPressed();
    }
}

From source file:com.intel.xdk.camera.Camera.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            imageSelected(data);/* ww w  .ja v  a2  s  .  c o m*/
        } else {
            //get info from shared prefs
            SharedPreferences prefs = activity.getSharedPreferences(cameraPrefsKey, 0);
            String outputFile = prefs.getString(cameraPrefsFileName, "");
            boolean isPNG = prefs.getBoolean(cameraPrefsIsPNG, false);
            int quality = prefs.getInt(cameraPrefsQuality, 100);
            savePicture(outputFile, quality, isPNG);
        }
    } else {
        pictureCancelled();
    }
}

From source file:de.jdellay.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
    int provider = Integer.parseInt(sp.getString(Configuration.PREFS_KEY_EXCHANGE_PROVIDER, "0"));
    boolean forceRefresh = sp.getBoolean(Configuration.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false);
    if (forceRefresh)
        sp.edit().putBoolean(Configuration.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false).commit();

    if (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) {
        float newCcnBtcConversion = -1;
        if ((ccnBtcConversion == -1 && newCcnBtcConversion == -1) || forceRefresh)
            newCcnBtcConversion = requestCcnBtcConversion(provider);

        if (newCcnBtcConversion != -1)
            ccnBtcConversion = newCcnBtcConversion;

        if (CCNBtcConversion == -1)
            return null;

        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, ccnBtcConversion, userAgent,
                    BITCOINAVERAGE_SOURCE, BITCOINAVERAGE_FIELDS);
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, ccnBtcConversion, userAgent,
                    BLOCKCHAININFO_SOURCE, BLOCKCHAININFO_FIELDS);

        if (newExchangeRates != null) {
            String providerUrl;//from www . j  ava  2  s .c o  m
            switch (provider) {
            case 0:
                providerUrl = "http://www.cryptsy.com";
                break;
            case 1:
                providerUrl = "http://www.vircurex.com";
                break;
            default:
                providerUrl = "";
                break;
            }
            float mBTCRate = ccnBtcConversion * 1000;
            String strmBTCRate = String.format(Locale.US, "%.5f", mBTCRate).replace(',', '.');
            newExchangeRates.put("mBTC", new ExchangeRate("mBTC",
                    new BigDecimal(GenericUtils.toNanoCoins(strmBTCRate, 0)).toBigInteger(), providerUrl));
            newExchangeRates.put("CCN",
                    new ExchangeRate("CCN", BigInteger.valueOf(100000000), "priceofccn.com"));
            exchangeRates = newExchangeRates;
            lastUpdated = now;

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null || ccnBtcConversion == -1)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final ExchangeRate rate = bestExchangeRate(selectionArgs[0]);
        if (rate != null)
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
    }

    return cursor;
}

From source file:com.cssweb.android.base.BaseActivity.java

private String[] getCustMenus() {
    String[] menus;//from   w w w  . j av  a 2s.co  m
    ArrayList<String> menuList = new ArrayList<String>();

    SharedPreferences sharedPreferences = getSharedPreferences("customsetting", Context.MODE_PRIVATE);

    Boolean saveFlag = sharedPreferences.getBoolean("saveFlag", false);
    if (!saveFlag) {
        String[] defaultSetting = getResources().getStringArray(R.array.njzq_default_setting);

        for (String defaultStr : defaultSetting) {
            addMenuItem(menuList, defaultStr);
        }

    } else {
        String baojia = sharedPreferences.getString("baojia", "");
        String hudong = sharedPreferences.getString("hudong", "");
        String yyting = sharedPreferences.getString("yyting", "");
        String fengcai = sharedPreferences.getString("fengcai", "");

        String shangcheng = sharedPreferences.getString("shangcheng", "");
        String luopang = sharedPreferences.getString("luopang", "");
        String baodian = sharedPreferences.getString("baodian", "");

        addMenuItem(menuList, baojia);
        addMenuItem(menuList, hudong);
        addMenuItem(menuList, yyting);
        addMenuItem(menuList, fengcai);

        addMenuItem(menuList, shangcheng);
        addMenuItem(menuList, luopang);
        addMenuItem(menuList, baodian);
    }
    int size = menuList.size();
    if (size <= 10) {
        for (int i = 0; i < (10 - size); i++) {
            menuList.add(" ");
        }
    }
    menus = new String[menuList.size()];
    for (int i = 0; i < menuList.size(); i++) {
        menus[i] = menuList.get(i);
    }

    return menus;
}

From source file:com.dwdesign.tweetings.app.TweetingsApplication.java

@Override
public void onSharedPreferenceChanged(final SharedPreferences preferences, final String key) {
    if (mServiceInterface != null
            && (PREFERENCE_KEY_AUTO_REFRESH.equals(key) || PREFERENCE_KEY_REFRESH_INTERVAL.equals(key))) {
        mServiceInterface.stopAutoRefresh();
        if (preferences.getBoolean(PREFERENCE_KEY_AUTO_REFRESH, false)) {
            mServiceInterface.startAutoRefresh();
        }/*from w ww.  j a va  2 s  . c  om*/
    } else if (PREFERENCE_KEY_ENABLE_PROXY.equals(key)) {
        reloadConnectivitySettings();
    }
    registerPush();
    if (backupManager == null) {
        backupManager = new BackupManager(this);
    }
    backupManager.dataChanged();
}