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:au.id.micolous.frogjump.LoginActivity.java

private void setupUI() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    int last_group = sharedPreferences.getInt(ApplicationPreferences.GROUP_ID, 0);
    if (last_group != 0) {
        txtGroupId.setText(String.format("%1$09d", last_group));
    }//from  w w w.j a va2 s  .co  m

    lblStatus.setText("");

}

From source file:com.adamkruger.myipaddressinfo.ProxySettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_proxy_settings, container, false);
    mProxySettingsRadioGroup = (RadioGroup) rootView.findViewById(R.id.proxySettingsRadioGroup);
    mProxySettingsRadioGroup.setOnCheckedChangeListener(this);
    mCustomProxyPort = (TextView) rootView.findViewById(R.id.proxySettingsCustomPort);
    mCustomProxyPort.addTextChangedListener(onCustomPortChanged);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    boolean useProxy = preferences.getBoolean(getResources().getString(R.string.PREFERENCE_USE_PROXY), false);
    int proxyPort = preferences.getInt(getResources().getString(R.string.PREFERENCE_PROXY_PORT),
            HTTP_PROXY_PORT_INVALID);/*from ww  w . j ava 2 s  .c o m*/
    ((RadioButton) rootView.findViewById(R.id.proxySettingsRadioNone)).setChecked(!useProxy);
    ((RadioButton) rootView.findViewById(R.id.proxySettingsRadioTor))
            .setChecked(useProxy && (proxyPort == HTTP_PROXY_PORT_TOR));
    ((RadioButton) rootView.findViewById(R.id.proxySettingsRadioPsiphon))
            .setChecked(useProxy && (proxyPort == HTTP_PROXY_PORT_PSIPHON));
    ((RadioButton) rootView.findViewById(R.id.proxySettingsRadioCustom)).setChecked(
            useProxy && (proxyPort != HTTP_PROXY_PORT_TOR) && (proxyPort != HTTP_PROXY_PORT_PSIPHON));
    if (proxyPort != HTTP_PROXY_PORT_INVALID && proxyPort != HTTP_PROXY_PORT_TOR
            && proxyPort != HTTP_PROXY_PORT_PSIPHON) {
        mCustomProxyPort.setText(Integer.toString(proxyPort));
    }

    enableCustomPortEdit();

    return rootView;
}

From source file:de.luhmer.owncloudnewsreader.services.OwnCloudSyncService.java

private void finishedSync() {
    TeslaUnreadManager.PublishUnreadCount(this);
    WidgetProvider.UpdateWidget(this);

    syncRunning = false;//from  ww w .ja v  a2 s . c o  m
    syncStopWatch.stop();
    Log.v(TAG, "Time needed (synchronization): " + syncStopWatch.toString());

    SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(OwnCloudSyncService.this);
    int newItemsCount = mPrefs.getInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, 0);
    if (newItemsCount > 0) {
        ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> runningTaskInfo = am.getRunningTasks(1);

        ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
        if (!componentInfo.getPackageName().equals("de.luhmer.owncloudnewsreader")) {
            Resources res = getResources();
            String tickerText = res.getQuantityString(R.plurals.notification_new_items_ticker, newItemsCount,
                    newItemsCount);
            String contentText = res.getQuantityString(R.plurals.notification_new_items_text, newItemsCount,
                    newItemsCount);
            String title = getString(R.string.app_name);

            if (mPrefs.getBoolean(SettingsActivity.CB_SHOW_NOTIFICATION_NEW_ARTICLES_STRING, true))//Default is true
                NotificationManagerNewsReader.getInstance(OwnCloudSyncService.this).ShowMessage(title,
                        tickerText, contentText);
        }
    }

    List<IOwnCloudSyncServiceCallback> callbackList = getCallBackItemsAndBeginBroadcast();
    for (IOwnCloudSyncServiceCallback icb : callbackList) {
        try {
            icb.finishedSync();
            //icb.finishedSyncOfItems();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
    callbacks.finishBroadcast();
}

From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java

public static int getActiveServer(Context context) {
    SharedPreferences prefs = getPreferences(context);
    return prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
}

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

public static String getRestUrl(Context context, String method, boolean allowAltAddress) {
    SharedPreferences prefs = getPreferences(context);
    int instance = prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
    return getRestUrl(context, method, prefs, instance, allowAltAddress);
}

From source file:com.bellman.bible.android.control.readingplan.ReadingPlanControl.java

public int getCurrentPlanDay() {
    String planCode = getCurrentPlanCode();
    SharedPreferences prefs = CommonUtils.getSharedPreferences();
    int day = prefs.getInt(planCode + READING_PLAN_DAY_EXT, 1);
    return day;//from  w  ww . j  a  v  a  2  s. c  o m
}

From source file:net.bible.android.BibleApplication.java

private void upgradePersistentData() {
    SharedPreferences prefs = CommonUtils.getSharedPreferences();
    int prevInstalledVersion = prefs.getInt("version", -1);
    if (prevInstalledVersion < CommonUtils.getApplicationVersionNumber() && prevInstalledVersion > -1) {
        Editor editor = prefs.edit();//from   w  ww . j  av a  2 s .  c o m

        // ver 16 and 17 needed text size pref to be changed to int from string
        if (prevInstalledVersion < 16) {
            Log.d(TAG, "Upgrading preference");
            String textSize = "16";
            if (prefs.contains(TEXT_SIZE_PREF)) {
                Log.d(TAG, "text size pref exists");
                try {
                    textSize = prefs.getString(TEXT_SIZE_PREF, "16");
                } catch (Exception e) {
                    // maybe the conversion has already taken place e.g. in debug environment
                    textSize = Integer.toString(prefs.getInt(TEXT_SIZE_PREF, 16));
                }
                Log.d(TAG, "existing value:" + textSize);
                editor.remove(TEXT_SIZE_PREF);
            }

            int textSizeInt = Integer.parseInt(textSize);
            editor.putInt(TEXT_SIZE_PREF, textSizeInt);

            Log.d(TAG, "Finished Upgrading preference");
        }

        // there was a problematic Chinese index architecture before ver 24 so delete any old indexes
        if (prevInstalledVersion < 24) {
            Log.d(TAG, "Deleting old Chinese indexes");
            Language CHINESE = new Language("zh");

            List<Book> books = SwordDocumentFacade.getInstance().getDocuments();
            for (Book book : books) {
                if (CHINESE.equals(book.getLanguage())) {
                    try {
                        BookIndexer bookIndexer = new BookIndexer(book);
                        // Delete the book, if present
                        if (bookIndexer.isIndexed()) {
                            Log.d(TAG, "Deleting index for " + book.getInitials());
                            bookIndexer.deleteIndex();
                        }
                    } catch (Exception e) {
                        Log.e(TAG, "Error deleting index", e);
                    }
                }
            }
        }
        // add new  
        if (prevInstalledVersion < 61) {
            if (prefs.contains(ScreenSettings.NIGHT_MODE_PREF_NO_SENSOR)) {
                String pref2Val = prefs.getBoolean(ScreenSettings.NIGHT_MODE_PREF_NO_SENSOR, false) ? "true"
                        : "false";
                Log.d(TAG, "Setting new night mode pref list value:" + pref2Val);
                editor.putString(ScreenSettings.NIGHT_MODE_PREF_WITH_SENSOR, pref2Val);
            }
        }

        // add new  
        if (prevInstalledVersion < 89) {
            if (!prefs.contains(ScreenTimeoutSettings.SCREEN_TIMEOUT_PREF)) {
                Log.d(TAG, "Adding default screen timeout setting");
                editor.putString(ScreenTimeoutSettings.SCREEN_TIMEOUT_PREF,
                        Integer.toString(ScreenTimeoutSettings.DEFAULT_VALUE));
            }
        }

        editor.putInt("version", CommonUtils.getApplicationVersionNumber());
        editor.commit();
        Log.d(TAG, "Finished all Upgrading");
    }
}

From source file:com.goliathonline.android.kegbot.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")");

    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    if (receiver != null)
        receiver.send(STATUS_RUNNING, Bundle.EMPTY);

    final Context context = this;
    final SharedPreferences prefs = getSharedPreferences(Prefs.IOSCHED_SYNC, Context.MODE_PRIVATE);
    final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION, VERSION_NONE);

    try {/*from  w  ww .  j  a  v a 2  s .  co m*/
        // Bulk of sync work, performed by executing several fetches from
        // local and online sources.

        final long startLocal = System.currentTimeMillis();
        final boolean localParse = localVersion < VERSION_CURRENT;
        Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT);
        if (localParse) {

            // Parse values from local cache first, since spreadsheet copy
            // or network might be down.
            //mLocalExecutor.execute(context, "cache-drinks.json", new RemoteDrinksHandler());
            //mLocalExecutor.execute(context, "cache-speakers.xml", new RemoteSpeakersHandler());
            //mLocalExecutor.execute(context, "cache-vendors.xml", new RemoteVendorsHandler());

            // Save local parsed version
            prefs.edit().putInt(Prefs.LOCAL_VERSION, VERSION_CURRENT).commit();
        }
        Log.d(TAG, "local sync took " + (System.currentTimeMillis() - startLocal) + "ms");

        // Always hit remote spreadsheet for any updates
        final long startRemote = System.currentTimeMillis();
        mRemoteExecutor.executeGet(PrefsHelper.getAPIUrl(getBaseContext()) + "/events",
                new RemoteJsonHandler(mRemoteExecutor));
        Log.d(TAG, "remote sync took " + (System.currentTimeMillis() - startRemote) + "ms");

    } catch (Exception e) {
        Log.e(TAG, "Problem while syncing", e);

        if (receiver != null) {
            // Pass back error to surface listener
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    }

    // Announce success to any surface listener
    Log.d(TAG, "sync finished");
    if (receiver != null)
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
}

From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java

public static String getRestUrl(Context context, String method) {
    StringBuilder builder = new StringBuilder();

    SharedPreferences prefs = getPreferences(context);

    int instance = prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
    String serverUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null);
    String username = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);
    String password = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null);

    // Slightly obfuscate password
    password = "enc:" + Util.utf8HexEncode(password);

    builder.append(serverUrl);//from w  w  w  .j a  va2 s .c  om
    if (builder.charAt(builder.length() - 1) != '/') {
        builder.append("/");
    }
    builder.append("rest/").append(method).append(".view");
    builder.append("?u=").append(username);
    builder.append("&p=").append(password);
    builder.append("&v=").append(Constants.REST_PROTOCOL_VERSION);
    builder.append("&c=").append(Constants.REST_CLIENT_ID);

    return builder.toString();
}