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:com.teinproductions.tein.papyrosprogress.MainActivity.java

private void restoreAppWidgetStuff() {
    if (Build.VERSION.SDK_INT < 16)
        return;//from  w ww  .  j av a 2s .c o m

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    }
    if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
        adapter.setTextSize(pref.getInt(Constants.TEXT_SIZE_PREFERENCE + appWidgetId, 24));
        adapter.setWidgetMilestoneTitle(
                pref.getString(Constants.MILESTONE_WIDGET_PREFERENCE + appWidgetId, null));
    } else {
        adapter.setTextSize(PapyrosRecyclerAdapter.DONT_SHOW_TEXT_SIZE_TILE);
    }
}

From source file:com.google.android.apps.iosched.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 ww  w. j  a v  a2s  . com*/
        // 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) {
            // Load static local data
            mLocalExecutor.execute(R.xml.blocks, new LocalBlocksHandler());
            mLocalExecutor.execute(R.xml.rooms, new LocalRoomsHandler());
            mLocalExecutor.execute(R.xml.tracks, new LocalTracksHandler());
            mLocalExecutor.execute(R.xml.search_suggest, new LocalSearchSuggestHandler());
            mLocalExecutor.execute(R.xml.sessions, new LocalSessionsHandler());

            // Parse values from local cache first, since spreadsheet copy
            // or network might be down.
            mLocalExecutor.execute(context, "cache-sessions.xml", new RemoteSessionsHandler());
            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(WORKSHEETS_URL, new RemoteWorksheetsHandler(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 int getActiveServers(Context context) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    return settings.getInt(Constants.PREFERENCES_KEY_ACTIVE_SERVERS, 3);
}

From source file:edu.nd.darts.cimon.NDroidAdmin.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.administrator);
    // Toast.makeText(getBaseContext(), "This is",
    // Toast.LENGTH_LONG).show();

    startService(new Intent(this, NDroidService.class));

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost(); // The activity TabHost
    TabHost.TabSpec spec; // Reusable TabSpec for each tab
    Intent intent; // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    // intent = new Intent().setClass(this, NDroidSystem.class);
    intent = new Intent().setClass(this, CimonListView.class);
    intent.putExtra("key", Metrics.TYPE_SYSTEM);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("system").setIndicator("System", res.getDrawable(R.drawable.icon_system))
            .setContent(intent);// w  ww .  j  a va  2  s.c om
    tabHost.addTab(spec);

    // Do the same for the other tabs
    // intent = new Intent().setClass(this, NDroidSensor.class);
    intent = new Intent().setClass(this, CimonListView.class);
    intent.putExtra("key", Metrics.TYPE_SENSOR);
    spec = tabHost.newTabSpec("sensors").setIndicator("Sensors", res.getDrawable(R.drawable.icon_sensor))
            .setContent(intent);
    tabHost.addTab(spec);

    // intent = new Intent().setClass(this, NDroidUser.class);
    intent = new Intent().setClass(this, CimonListView.class);
    intent.putExtra("key", Metrics.TYPE_USER);
    spec = tabHost.newTabSpec("user").setIndicator("User Activity", res.getDrawable(R.drawable.icon_user))
            .setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);

    SharedPreferences appPrefs = getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);

    int storedVersion = appPrefs.getInt(PREF_VERSION, -1);

    int appVersion = -1;

    try {
        appVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if (DebugLog.DEBUG)
        Log.d(TAG, "NDroidAdmin.onCreate - appVersion:" + appVersion + " storedVersion:" + storedVersion);

    if (appVersion > storedVersion) {

        new Thread(new Runnable() {
            public void run() {
                List<MetricService<?>> serviceList;
                serviceList = MetricService.getServices(Metrics.TYPE_SYSTEM);
                for (MetricService<?> mService : serviceList) {
                    mService.insertDatabaseEntries();
                }
                serviceList.clear();
                serviceList = MetricService.getServices(Metrics.TYPE_SENSOR);
                for (MetricService<?> mService : serviceList) {
                    mService.insertDatabaseEntries();
                }
                serviceList.clear();
                serviceList = MetricService.getServices(Metrics.TYPE_USER);
                for (MetricService<?> mService : serviceList) {
                    mService.insertDatabaseEntries();
                }
                serviceList.clear();
            }
        }).start();

        SharedPreferences.Editor editor = appPrefs.edit();
        editor.putInt(PREF_VERSION, appVersion);
        editor.commit();
    }
}

From source file:com.amagi82.kerbalspaceapp.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE);
    if (prefs.getInt("language", 0) != 0)
        Settings.language = Settings.langCode[prefs.getInt("language", 0)];

    dataList = new ArrayList<NavigationDrawerItem>();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // Set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // Set up the drawer's list view with items and click listener
    dataList.add(new NavigationDrawerItem(this.getString(R.string.utilities))); // adding a header to the list
    dataList.add(new NavigationDrawerItem(this.getString(R.string.title_activity_mission_planner),
            R.drawable.ic_action_event));
    // dataList.add(new NavigationDrawerItem("Aerocapture Calculator", R.drawable.ic_action_cloud)); - not implemented yet
    dataList.add(new NavigationDrawerItem(this.getString(R.string.title_activity_settings),
            R.drawable.ic_action_settings));

    dataList.add(new NavigationDrawerItem("")); // adding a header to the list
    dataList.add(new NavigationDrawerItem(this.getString(R.string.feedback), R.drawable.ic_action_paste));
    dataList.add(new NavigationDrawerItem(this.getString(R.string.about), R.drawable.ic_action_about));

    adapter = new NavigationDrawerAdapter(this, R.layout.navigation_drawer_item, dataList);
    mDrawerList.setAdapter(adapter);// w ww .j av  a 2s  .  c  om
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // Get the app version name from the manifest for the About section
    try {
        version = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        version = "Unknown";
    }

    // Enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setTitle(R.string.app_name);

    // ActionBarDrawerToggle ties together the interactions between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {
        @Override
        public void onDrawerClosed(View view) {
            invalidateOptionsMenu(); // Creates call to onPrepareOptionsMenu()
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu(); // Creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:com.teinproductions.tein.papyrosprogress.UpdateCheckReceiver.java

private void checkBlog() {
    // The amount of blog posts that were found when last checked
    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    final int cachePostAmount = pref.getInt(Constants.CACHED_BLOG_AMOUNT, -1);

    // Load the GitHub API page containing information about the amount of blog posts
    new AsyncTask<Void, Void, Integer>() {
        @Override/*from www .  j  a  va  2  s .  com*/
        protected Integer doInBackground(Void... params) {
            try {
                MilestoneLoader.Result file = IOUtils.loadPage(Constants.PAPYROS_BLOG_API_URL);
                if (file.getError() != MilestoneLoader.Result.NO_ERROR)
                    return null;
                return new JSONArray(file.getStrData()).length();
            } catch (Exception e) {
                return null;
            }
        }

        @Override
        protected void onPostExecute(Integer newPostAmount) {
            try {
                // If there was a cachePostAmount present in storage, compare it to the new amount
                if (cachePostAmount != -1 && newPostAmount > cachePostAmount) {
                    // A blog post has been added
                    issueBlogNotification(UpdateCheckReceiver.this.context);
                }

                pref.edit().putInt(Constants.CACHED_BLOG_AMOUNT, newPostAmount).apply();
            } catch (Exception ignored) {
            }
        }
    }.execute();
}

From source file:com.kuacm.expo2013.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  ww w.j  a v  a2  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) {
            // Load static local data
            mLocalExecutor.execute(R.xml.blocks, new LocalBlocksHandler());
            mLocalExecutor.execute(R.xml.rooms, new LocalRoomsHandler());
            mLocalExecutor.execute(R.xml.tracks, new LocalTracksHandler());
            mLocalExecutor.execute(R.xml.search_suggest, new LocalSearchSuggestHandler());
            mLocalExecutor.execute(R.xml.sessions, new LocalSessionsHandler());

            // Parse values from local cache first, since spreadsheet copy
            // or network might be down.
            mLocalExecutor.execute(context, "cache-sessions.xml", new RemoteSessionsHandler());
            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(WORKSHEETS_URL, new RemoteWorksheetsHandler(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.amagi82.kerbalspaceapp.Settings.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    getActionBar().setTitle(R.string.title_activity_settings);

    SeekBar clearance = (SeekBar) findViewById(R.id.seekBarClearance);
    SeekBar margins = (SeekBar) findViewById(R.id.seekBarMargins);
    SeekBar inclination = (SeekBar) findViewById(R.id.seekBarInclination);
    mClearance = (TextView) findViewById(R.id.tvClearance);
    mMargins = (TextView) findViewById(R.id.tvMargins);
    mInclination = (TextView) findViewById(R.id.tvInclination);
    chooseLanguage = (Spinner) findViewById(R.id.spinnerLanguages);

    SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE);
    mClearanceValue = prefs.getInt("mClearanceValue", 1000);
    mMarginsValue = prefs.getInt("mMarginsValue", 10);
    mInclinationValue = prefs.getInt("mInclinationValue", 30);
    chooseLanguage.setSelection(prefs.getInt("language", 0));

    // Set up spinner
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActionBar().getThemedContext(),
            R.array.languages, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    chooseLanguage.setAdapter(adapter);/*from   w w  w  .ja va2s  . c  o  m*/
    // @formatter:off
    if (Locale.getDefault().getLanguage().equals("en"))
        chooseLanguage.setSelection(0);
    if (Locale.getDefault().getLanguage().equals("fr"))
        chooseLanguage.setSelection(1);
    if (Locale.getDefault().getLanguage().equals("de"))
        chooseLanguage.setSelection(2);
    if (Locale.getDefault().getLanguage().equals("es"))
        chooseLanguage.setSelection(3);
    if (Locale.getDefault().getLanguage().equals("ru"))
        chooseLanguage.setSelection(4);

    // Set seekbar progress
    clearance.setProgress(mClearanceValue);
    margins.setProgress(mMarginsValue);
    inclination.setProgress(mInclinationValue);

    // Display values
    mClearance.setText(mClearanceValue + "m");
    mMargins.setText(mMarginsValue + "%");
    setInclinationText();

    clearance.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            String value = NumberFormat.getNumberInstance(Locale.getDefault()).format(progress);
            mClearance.setText(value + "m");
            mClearanceValue = progress;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    margins.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mMargins.setText(progress + "%");
            mMarginsValue = progress;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    inclination.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mInclinationValue = progress;
            setInclinationText();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    chooseLanguage.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            language = langCode[chooseLanguage.getSelectedItemPosition()];
            onConfigurationChanged(getResources().getConfiguration());
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

}

From source file:com.google.android.apps.iosched2.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.SCHED_SYNC, Context.MODE_PRIVATE);
    final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION, VERSION_NONE);

    try {//from   ww  w.java 2  s .  c o 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) {
            // Load static local data
            mLocalExecutor.execute(Setup.BLOCKS_XML, new LocalBlocksHandler());
            mLocalExecutor.execute(Setup.ROOMS_XML, new LocalRoomsHandler());

            //                  mLocalExecutor.execute(R.xml.blocks, new LocalBlocksHandler());
            //                  mLocalExecutor.execute(R.xml.rooms, new LocalRoomsHandler());

            mLocalExecutor.execute(R.xml.tracks, new LocalTracksHandler());
            mLocalExecutor.execute(R.xml.search_suggest, new LocalSearchSuggestHandler());
            mLocalExecutor.execute(R.xml.sessions, new LocalSessionsHandler());

            // Parse values from local cache first, since spreadsheet copy
            // or network might be down.
            mLocalExecutor.execute(context, Setup.EVENT_PREFIX + "cache-sessions.xml",
                    new RemoteSessionsHandler());
            mLocalExecutor.execute(context, Setup.EVENT_PREFIX + "cache-speakers.xml",
                    new RemoteSpeakersHandler());

            if (Setup.FEATURE_VENDORS_ON) {
                mLocalExecutor.execute(context, Setup.EVENT_PREFIX + "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(WORKSHEETS_URL, new RemoteWorksheetsHandler(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.vk.sdk.payments.VKPaymentsServerSender.java

private int restoreAnswer(Context ctx) {
    synchronized (VKPaymentsServerSender.class) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx.getApplicationContext());
        return prefs.getInt(KEY_ANSWER, CHECK_USER_INSTALL_ANSWER_UNKNOWN);
    }/*from   w  w w .  j  a v a 2  s . c o m*/
}