Example usage for android.content SharedPreferences getInt

List of usage examples for android.content SharedPreferences getInt

Introduction

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

Prototype

int getInt(String key, int defValue);

Source Link

Document

Retrieve an int value from the preferences.

Usage

From source file:org.ietf.ietfsched.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    if (debbug)/* w  w  w .j av  a  2  s  .c  o m*/
        Log.d(TAG, "Receiver is = " + receiver);
    if (receiver != null)
        receiver.send(STATUS_RUNNING, Bundle.EMPTY);
    final Context context = this;
    final SharedPreferences prefs = getSharedPreferences(Prefs.IETFSCHED_SYNC, Context.MODE_PRIVATE);
    final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION, VERSION_NONE);
    //      final int lastLength = prefs.getInt(Prefs.LAST_LENGTH, VERSION_NONE);
    final String lastEtag = prefs.getString(Prefs.LAST_ETAG, "");
    //      final long startLocal = System.currentTimeMillis();

    //boolean localParse = localVersion < VERSION_CURRENT;
    boolean localParse = false;
    Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT);
    boolean remoteParse = true;
    //      int remoteLength = -1;
    String remoteEtag = "";

    try {
        String htmlURL = BASE_URL + "agenda.csv";
        if (debbug)
            Log.d(TAG, "HEAD " + htmlURL);
        remoteEtag = mRemoteExecutor.executeHead(htmlURL);
        if (debbug)
            Log.d(TAG, "HEAD " + htmlURL + " " + remoteEtag);
        if (remoteEtag == null) {
            Log.d(TAG, "Error connection, cannot retrieve any information from" + htmlURL);
            remoteParse = false;
        } else {
            remoteParse = !remoteEtag.equals(lastEtag);
        }
    } catch (Exception e) {
        remoteParse = false;
        e.printStackTrace();
    }

    // HACK FOR TESTS PURPOSES. TO REMOVE 
    //      Log.w(TAG, "For tests purposes, only the local parsing is activated");
    //      remoteParse = false;
    //      localParse = true;
    // HACK FIN.   

    if (!remoteParse && !localParse) {
        Log.d(TAG, "Already synchronized");
        if (receiver != null)
            receiver.send(STATUS_FINISHED, Bundle.EMPTY);
        return;
    }

    if (remoteParse) {
        String csvURL = BASE_URL + "agenda.csv";
        try {
            if (debbug)
                Log.d(TAG, csvURL);
            InputStream agenda = mRemoteExecutor.executeGet(csvURL);
            mLocalExecutor.execute(agenda);
            prefs.edit().putString(Prefs.LAST_ETAG, remoteEtag).commit();
            prefs.edit().putInt(Prefs.LOCAL_VERSION, VERSION_CURRENT).commit();
            localParse = false;
            Log.d(TAG, "remote sync finished");
            if (receiver != null)
                receiver.send(STATUS_FINISHED, Bundle.EMPTY);
        } catch (Exception e) {
            Log.e(TAG, "Error HTTP request " + csvURL, e);
            if (!localParse) {
                final Bundle bundle = new Bundle();
                bundle.putString(Intent.EXTRA_TEXT, "Connection error. No updates.");
                if (receiver != null) {
                    receiver.send(STATUS_ERROR, bundle);
                }
            }
        }
    }

    if (localParse) {
        try {
            mLocalExecutor.execute(context, "agenda-83.csv");
            Log.d(TAG, "local sync finished");
            prefs.edit().putInt(Prefs.LOCAL_VERSION, VERSION_CURRENT).commit();
            if (receiver != null)
                receiver.send(STATUS_FINISHED, Bundle.EMPTY);
        } catch (Exception e) {
            e.printStackTrace();
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            if (receiver != null) {
                receiver.send(STATUS_ERROR, bundle);
            }
        }
    }
}

From source file:com.adguard.android.contentblocker.preferences.PreferenceDb.java

private void refreshItems() {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    for (PreferenceItem item : itemsList) {
        if (item.value instanceof Boolean) {
            item.value = prefs.getBoolean(item.name, (Boolean) item.value);
        } else if (item.value instanceof Integer) {
            item.value = prefs.getInt(item.name, (Integer) item.value);
        } else if (item.value instanceof String) {
            item.value = prefs.getString(item.name, (String) item.value);
        } else if (item.value instanceof String[]) {
            item.value = StringUtils.split(prefs.getString(item.name, (String) item.value),
                    System.lineSeparator());
        }/*w  ww .ja  va 2s .  c  om*/
    }
}

From source file:com.dubsar_dictionary.Dubsar.FAQActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from   w ww  .  j  a  v a 2s  .  c  o  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.faq);

    mWebView = (WebView) findViewById(R.id.faq_web_view);
    mWebView.getSettings().setJavaScriptEnabled(true);

    SharedPreferences preferences = getSharedPreferences(PreferencesActivity.DUBSAR_PREFERENCES, MODE_PRIVATE);
    String host = preferences.getString(PreferencesActivity.HTTP_PROXY_HOST, null);
    int port = preferences.getInt(PreferencesActivity.HTTP_PROXY_PORT, 0);

    if (host != null && port != 0) {
        mProxyFailed = !setProxy(mWebView, host, port);

        if (mProxyFailed) {
            String html = "<html><body style=\"background-color: #e0e0ff;\"><h1 style=\"color: #1c94c4; text-align: center; margin-top: 2ex; font: bold 18pt sans-serif\">"
                    + getString(R.string.proxy_fail) + " " + host + ":" + port + "</h1></body></html>";
            mWebView.loadData(html, "text/html", "utf-8");
            return;
        }
    }

    if (savedInstanceState != null) {
        mWebView.restoreState(savedInstanceState);
    } else {
        String html = "<html><body style=\"background-color: #e0e0ff;\"><h1 style=\"color: #1c94c4; text-align: center; margin-top: 2ex; font: bold 18pt sans-serif\">"
                + getString(R.string.loading_faq) + "</h1></body></html>";
        mWebView.loadData(html, "text/html", "utf-8");
        // Log.i(getString(R.string.app_name), "Initial FAQ HTML: " + html);
    }

    mWebView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        public void onPageFinished(WebView view, String url) {
            String faqUrl = getString(R.string.faq_url);
            if (!mProxyFailed && (url == null || !url.equals(faqUrl))) {
                mWebView.loadUrl(faqUrl);
            }
        }
    });
}

From source file:pffy.mobile.flax.FlaxActivity.java

private void getPrefs() {

    SharedPreferences shpref = this.getPreferences(Context.MODE_PRIVATE);

    this.mFoodCatId = shpref.getInt(getString(R.string.prefkey_int_foodcatid), 0);
    this.mFoodItemId = shpref.getInt(getString(R.string.prefkey_int_fooditemid), 0);

    this.setOutputNames(shpref.getString(getString(R.string.prefkey_str_foodnames),
            getResources().getStringArray(R.array.bsandwiches)[0]));
    this.setOutputFacts(shpref.getString(getString(R.string.prefkey_str_foodfacts),
            getResources().getStringArray(R.array.bsandwiches_details)[0]));

    // Refreshes drop down menus
    this.mSpinnerFoodCat.setSelection(this.mFoodCatId);
    this.mSpinnerFoodItem.setSelection(this.mFoodItemId);

}

From source file:de.j4velin.wifiAutoOff.Locations.java

@Override
protected void onResume() {
    super.onResume();
    SharedPreferences prefs = getSharedPreferences(getPackageName() + "_preferences",
            Context.MODE_MULTI_PROCESS);
    findViewById(R.id.timeoutwarning).setVisibility(prefs.getBoolean("off_no_network", true)
            && prefs.getInt("no_network_timeout", Receiver.TIMEOUT_NO_NETWORK) < 5 ? View.VISIBLE : View.GONE);
}

From source file:cn.sharesdk.analysis.util.PreferencesHelper.java

/**
 * Get the current send model/*from   ww  w . j a  va  2 s .  c o m*/
 */
public int getReportPolicy() {
    SharedPreferences localSharedPreferences = context
            .getSharedPreferences("mobclick_agent_online_setting_" + packageName, 0);
    int policy = localSharedPreferences.getInt("policy", WIFI_SEND_POLICY);
    return policy;
}

From source file:net.pmarks.chromadoze.PhononMutable.java

public boolean loadFromLegacyPrefs(SharedPreferences pref) {
    if (pref.getFloat("barHeight0", -1) < 0) {
        return false;
    }/* w  w  w .jav  a  2 s. c  o m*/
    for (int i = 0; i < BAND_COUNT; i++) {
        setBar(i, pref.getFloat("barHeight" + i, .5f));
    }
    setMinVol(pref.getInt("minVol", 100));
    setPeriod(pref.getInt("period", 18));
    cleanMe();
    return true;
}

From source file:cn.sharesdk.analysis.util.PreferencesHelper.java

/**
 * Get the time of report delay millseconds
 *///w w w  .j  a v  a2 s .  c o m
public int getReportDelay() {
    SharedPreferences localSharedPreferences = context
            .getSharedPreferences("mobclick_agent_online_setting_" + packageName, 0);
    int duration = localSharedPreferences.getInt("delay", 10 * 1000);
    return duration;
}

From source file:in.animeshpathak.nextbus.NextBusMain.java

@Override
protected void onResume() {
    super.onResume();
    Log.d(LOG_TAG, "entering onResume()");
    // at this time, the UI elements have been created. Need to read
    // It is best not to reuse references to views after pause (Android
    // seems to create new objects)

    lineSpinner = (Spinner) findViewById(R.id.line_spinner);
    stopSpinner = (Spinner) findViewById(R.id.stop_spinner);
    // the shared preferences, and store them in local variables.
    SharedPreferences prefs = getPreferences(MODE_PRIVATE);
    int selectedLineID = prefs.getInt(Constants.SELECTED_LINE, 0);
    int selectedStopID = prefs.getInt(Constants.SELECTED_STOP, 0);

    List<BusLine> theLines = busNet.getLines();

    if (selectedLineID < 0 || theLines.size() <= selectedLineID) {
        selectedLineID = 0;/*from ww  w .  j  av a2 s.c o m*/
        Log.w(LOG_TAG, "onResume() selectedLineID is out of bounds: " + selectedLineID);
    }

    BusLine bl = theLines.get(selectedLineID);
    List<BusStop> lineStops = bl.getStops();

    if (selectedStopID < 0 || lineStops.size() <= selectedStopID) {
        selectedStopID = 0;
        Log.w(LOG_TAG, "onResume() selectedStopID is out of bounds: " + selectedStopID);
    }

    BusStop bs = lineStops.get(selectedStopID);
    updateSpinners(bl, bs);

    // Show notification on the first run
    if (!prefs.getBoolean(getString(R.string.version_name), false)) {
        try {
            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean(getString(R.string.version_name), true);
            showVersionInfoDialog();
            editor.commit();
        } catch (UnsupportedEncodingException e) {
            Log.e(LOG_TAG, "onResume() problem in versioninfo file encoding.", e);
        } catch (IOException e) {
            Log.e(LOG_TAG, "onResume() problem in versioninfo file encoding.", e);
        }
    }

    // Show red button if Phebus posted new alerts
    new PhebusNewsLoader(null, NextBusMain.this).execute();
    Analytics.getInstance().setContext(this.getApplicationContext());
}

From source file:com.jean.farCam.SettingsActivity.java

public void showPreference(boolean setListeners) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
    SharedPreferences.Editor editor = settings.edit();

    // x resolution
    String key = getString(R.string.settings_key_x_resolution);
    EditIntPreference eip = (EditIntPreference) findPreference(key);
    int setting = settings.getInt(key, -1);
    if (setting < 0) {
        editor.putInt(key, DEFAULT_X_RESOLUTION);
        setting = DEFAULT_X_RESOLUTION;//from   w w  w .ja v  a  2 s.com
    }
    eip.setSummary(setting + "");
    if (setListeners)
        eip.setOnPreferenceChangeListener(onResolutionPreferenceChangedListener);

    // y resolution
    key = getString(R.string.settings_key_y_resolution);
    eip = (EditIntPreference) findPreference(key);
    setting = settings.getInt(key, -1);
    if (setting < 0) {
        editor.putInt(key, DEFAULT_Y_RESOLUTION);
        setting = DEFAULT_Y_RESOLUTION;
    }
    eip.setSummary(setting + "");
    if (setListeners)
        eip.setOnPreferenceChangeListener(onResolutionPreferenceChangedListener);

    // port
    key = getString(R.string.settings_key_port);
    eip = (EditIntPreference) findPreference(key);
    setting = settings.getInt(key, -1);
    if (setting < 0) {
        editor.putInt(key, DEFAULT_PORT);
        setting = DEFAULT_PORT;
    }
    eip.setSummary(setting + "");
    if (setListeners)
        eip.setOnPreferenceChangeListener(onResolutionPreferenceChangedListener);

    if (setListeners) {
        key = getString(R.string.settings_key_ip);
        ipPref = (Preference) findPreference(key);
        ipPref.setTitle("IP: " + getIPAddress());
        ipPref.setOnPreferenceClickListener(onIpClickListener);
    }

    //...

    // Write default value to preference
    editor.commit();
}