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:gr.scify.newsum.ui.ViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    // Init custom category
    sCustomCategory = NewSumUiActivity.getAppContext(this).getResources().getString(R.string.custom_category);
    // Always select landscape orientation for big screens (?)
    if ((getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_NORMAL
            & (getResources().getConfiguration().screenLayout
                    & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_SMALL) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    }//from  w ww  .  j  a  v  a  2s .c om
    SharedPreferences usertheme = getSharedPreferences("theme", 0);
    int newTheme = usertheme.getInt("theme", 2);
    Utils.onActivityCreateSetTheme(this, newTheme);

}

From source file:com.justone.android.main.MainActivity.java

public void userFirstTips() {
    @SuppressWarnings("deprecation")
    SharedPreferences preferences = getSharedPreferences("count", MODE_WORLD_READABLE);
    int count = preferences.getInt("count", 0);

    // /*w  ww .  j  ava 2  s. c o m*/
    if (count == 0) {

        LayoutInflater inflater = getLayoutInflater();

        View layout = inflater.inflate(R.layout.first_tips, (ViewGroup) findViewById(R.id.first_tips));

        final AlertDialog dialog = new AlertDialog.Builder(this).setView(layout).show();

        layout.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                dialog.dismiss();
                return true;
            }
        });
        dialog.getWindow().setLayout(650, 650);
    }
    Editor editor = preferences.edit();
    // 
    editor.putInt("count", ++count);
    // 
    editor.commit();

}

From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);

    // Get user preferences
    final SharedPreferences sharedPrefs = context.getSharedPreferences(Const.APP_PREFS_NAME,
            Context.MODE_PRIVATE);
    final SharedPreferences.Editor sharedPrefsEditor = sharedPrefs.edit();
    final boolean hasNotifications = sharedPrefs.getBoolean(Const.PrefsNames.HAS_NOTIFICATIONS, false);
    final boolean hasVibration = (sharedPrefs.getBoolean(Const.PrefsNames.HAS_VIBRATION, false)
            && vibrator.hasVibrator());
    final boolean hasSound = sharedPrefs.getBoolean(Const.PrefsNames.HAS_SOUND, false);
    final boolean onScreenLock = sharedPrefs.getBoolean(Const.PrefsNames.ON_SCREEN_LOCK, true);
    final boolean onPowerLoss = sharedPrefs.getBoolean(Const.PrefsNames.ON_POWER_LOSS, false);
    final int delayToLock = Integer.parseInt(
            sharedPrefs.getString(Const.PrefsNames.DELAY_TO_LOCK, Const.PrefsValues.DELAY_FAST)) * 1000;
    final int notifyCount = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_COUNT, 1);
    final int notifyGroup = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_GROUP, 1);

    final String action = intent.getAction();
    if (action == null)
        return;/*from   w  w w  .j a v  a 2  s .  c  o  m*/

    if (action.equals(Const.IntentActions.NOTIFY_DELETE)) {
        if (hasNotifications) {
            // Reset the notification counter (and group) on NOTIFY_DELETE
            sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, 1);
            sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_GROUP, notifyGroup + 1);
            sharedPrefsEditor.apply();
        }
    } else if (action.equals(Intent.ACTION_POWER_CONNECTED)
            || action.equals(Intent.ACTION_POWER_DISCONNECTED)) {
        final boolean isConnectedPower = action.equals(Intent.ACTION_POWER_CONNECTED);

        // Lock the screen, following the user preferences
        if (delayToLock == 0) {
            LockScreenHelper.lockScreen(context, onScreenLock, onPowerLoss, isConnectedPower);
        } else {
            Intent intentService = new Intent(Intent.ACTION_SYNC, null, context, DelayedLockService.class);
            Bundle extras = new Bundle();
            extras.putBoolean(Const.IntentExtras.ON_SCREEN_LOCK, onScreenLock);
            extras.putBoolean(Const.IntentExtras.ON_POWER_LOSS, onPowerLoss);
            extras.putBoolean(Const.IntentExtras.IS_CONNECTED, isConnectedPower);
            extras.putInt(Const.IntentExtras.DELAY_TO_LOCK, delayToLock);
            intentService.putExtras(extras);
            context.startService(intentService);
        }

        // Save in database
        saveHistoryItem(context.getApplicationContext(), isConnectedPower, notifyGroup);

        if (hasNotifications) {
            // Send notification, with sound and vibration
            notify(context, isConnectedPower, hasVibration, hasSound, notifyCount);

            // Increment the notification counter
            sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, notifyCount + 1);
            sharedPrefsEditor.apply();
        } else {
            // Native Vibration or Sound, without Notifications
            nativeVibrate(context, hasVibration);

            nativeRingtone(context, hasSound);
        }
    }
}

From source file:com.seal.ui.components.CustomWebView.java

@SuppressLint("SetJavaScriptEnabled")
public void loadSettings() {
    WebSettings settings = getSettings();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());

    settings.setJavaScriptEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_JAVASCRIPT, true));
    settings.setLoadsImagesAutomatically(prefs.getBoolean(Constants.PREFERENCE_ENABLE_IMAGES, true));
    settings.setUseWideViewPort(prefs.getBoolean(Constants.PREFERENCE_USE_WIDE_VIEWPORT, true));
    settings.setLoadWithOverviewMode(prefs.getBoolean(Constants.PREFERENCE_LOAD_WITH_OVERVIEW, false));

    settings.setGeolocationEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_GEOLOCATION, true));
    settings.setSaveFormData(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_FORM_DATA, true));
    settings.setSavePassword(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_PASSWORDS, true));

    settings.setTextZoom(prefs.getInt(Constants.PREFERENCE_TEXT_SCALING, 100));

    int minimumFontSize = prefs.getInt(Constants.PREFERENCE_MINIMUM_FONT_SIZE, 1);
    settings.setMinimumFontSize(minimumFontSize);
    settings.setMinimumLogicalFontSize(minimumFontSize);

    settings.setUserAgentString(prefs.getString(Constants.PREFERENCE_USER_AGENT, Constants.USER_AGENT_ANDROID));
    // settings.setPluginState(PluginState.valueOf(prefs.getString(Constants.PREFERENCE_PLUGINS, PluginState.ON_DEMAND.toString())));

    CookieManager.getInstance().setAcceptCookie(prefs.getBoolean(Constants.PREFERENCE_ACCEPT_COOKIES, true));

    settings.setSupportZoom(true);/*from   ww w .j av  a  2 s.c om*/
    settings.setDisplayZoomControls(false);
    settings.setBuiltInZoomControls(true);
    settings.setSupportMultipleWindows(true);
    settings.setEnableSmoothTransition(true);

    if (mPrivateBrowsing) {
        settings.setGeolocationEnabled(false);
        settings.setSaveFormData(false);
        settings.setSavePassword(false);

        settings.setAppCacheEnabled(false);
        settings.setDatabaseEnabled(false);
        settings.setDomStorageEnabled(false);
    } else {
        // HTML5 API flags
        settings.setAppCacheEnabled(true);
        settings.setDatabaseEnabled(true);
        settings.setDomStorageEnabled(true);

        // HTML5 configuration settings.
        settings.setAppCacheMaxSize(3 * 1024 * 1024);
        settings.setAppCachePath(mContext.getDir("appcache", 0).getPath());
        settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
        settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
    }

    setLongClickable(true);
    setDownloadListener(this);
}

From source file:com.magnet.mmx.client.MMXClient.java

/**
 * Retrieves an instance of MMXClient that has been previously configured with a MMXClientConfig.
 * Will return null if it hasn't been configured.
 *
 * @param context The context to use for this instance
 * @param name The name of this instance
 * @return The MMXClient instance/*from   w  w  w .  ja  v a 2  s.  c  o  m*/
 */
public static MMXClient getExistingInstance(Context context, String name) {
    if (name == null) {
        return null;
    }
    MMXClient instance = null;
    synchronized (sInstanceMap) {
        instance = sInstanceMap.get(name);
        if (instance != null) {
            return instance;
        } else {
            //is there a prefs for this name?
            SharedPreferences prefs = getSharedPrefs(context, name);
            final String appId = prefs.getString(SHARED_PREF_KEY_CONFIG_APP_ID, null);
            if (appId != null) {
                final String host = prefs.getString(SHARED_PREF_KEY_CONFIG_HOST, null);
                final int port = prefs.getInt(SHARED_PREF_KEY_CONFIG_PORT, -1);
                final String securityLevel = prefs.getString(SHARED_PREF_KEY_SECURITY_LEVEL, null);
                final String apiKey = prefs.getString(SHARED_PREF_KEY_CONFIG_API_KEY, null);
                final String gcmSenderId = prefs.getString(SHARED_PREF_KEY_CONFIG_GCM_PROJECTID, null);
                final String serverUser = prefs.getString(SHARED_PREF_KEY_CONFIG_SERVER_USER, null);
                final String guestPassword = prefs.getString(SHARED_PREF_KEY_CONFIG_ANONYMOUS_SECRET, null);
                final String domainName = prefs.getString(SHARED_PREF_KEY_CONFIG_DOMAIN_NAME, null);
                instance = new MMXClient(name, context, new MMXClientConfig() {
                    public String getAppId() {
                        return appId;
                    }

                    public String getApiKey() {
                        return apiKey;
                    }

                    public String getGcmSenderId() {
                        return gcmSenderId;
                    }

                    public String getServerUser() {
                        return serverUser;
                    }

                    public String getAnonymousSecret() {
                        return guestPassword;
                    }

                    public String getHost() {
                        return host;
                    }

                    public int getPort() {
                        return port;
                    }

                    public SecurityLevel getSecurityLevel() {
                        return securityLevel == null ? SecurityLevel.STRICT
                                : SecurityLevel.valueOf(securityLevel);
                    }

                    public String getDomainName() {
                        return domainName;
                    }
                });
                instance.initClient();
                sInstanceMap.put(name, instance);
            }
            return instance;
        }
    }
}

From source file:com.groundupworks.wings.facebook.FacebookEndpoint.java

/**
 * Fetches the link settings from persisted storage.
 *
 * @return the {@link com.groundupworks.wings.facebook.FacebookSettings}; or null if unlinked.
 *//*w  ww .  j  a  v  a  2 s  .  c  o m*/
private FacebookSettings fetchSettings() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    if (!preferences.getBoolean(mContext.getString(R.string.wings_facebook__link_key), false)) {
        return null;
    }

    int destinationId = preferences.getInt(mContext.getString(R.string.wings_facebook__destination_id_key),
            DestinationId.UNLINKED);
    String accountName = preferences.getString(mContext.getString(R.string.wings_facebook__account_name_key),
            null);
    String albumName = preferences.getString(mContext.getString(R.string.wings_facebook__album_name_key), null);
    String albumGraphPath = preferences
            .getString(mContext.getString(R.string.wings_facebook__album_graph_path_key), null);
    String pageAccessToken = preferences
            .getString(mContext.getString(R.string.wings_facebook__page_access_token_key), null);
    String photoPrivacy = preferences.getString(mContext.getString(R.string.wings_facebook__photo_privacy_key),
            null);

    return FacebookSettings.newInstance(destinationId, accountName, albumName, albumGraphPath, pageAccessToken,
            photoPrivacy);
}

From source file:com.mogoweb.ui.components.CustomWebView.java

@SuppressLint("SetJavaScriptEnabled")
public void loadSettings() {
    WebSettings settings = getSettings();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());

    settings.setJavaScriptEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_JAVASCRIPT, true));
    settings.setLoadsImagesAutomatically(prefs.getBoolean(Constants.PREFERENCE_ENABLE_IMAGES, true));
    settings.setUseWideViewPort(prefs.getBoolean(Constants.PREFERENCE_USE_WIDE_VIEWPORT, true));
    settings.setLoadWithOverviewMode(prefs.getBoolean(Constants.PREFERENCE_LOAD_WITH_OVERVIEW, false));

    settings.setGeolocationEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_GEOLOCATION, true));
    settings.setSaveFormData(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_FORM_DATA, true));
    settings.setSavePassword(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_PASSWORDS, true));

    settings.setTextZoom(prefs.getInt(Constants.PREFERENCE_TEXT_SCALING, 100));

    int minimumFontSize = prefs.getInt(Constants.PREFERENCE_MINIMUM_FONT_SIZE, 1);
    settings.setMinimumFontSize(minimumFontSize);
    settings.setMinimumLogicalFontSize(minimumFontSize);

    settings.setUserAgentString(prefs.getString(Constants.PREFERENCE_USER_AGENT, Constants.USER_AGENT_ANDROID));
    //      settings.setPluginState(PluginState.valueOf(prefs.getString(Constants.PREFERENCE_PLUGINS, PluginState.ON_DEMAND.toString())));

    CookieManager.getInstance().setAcceptCookie(prefs.getBoolean(Constants.PREFERENCE_ACCEPT_COOKIES, true));

    settings.setSupportZoom(true);/*from   www  .  ja va  2s. co m*/
    settings.setDisplayZoomControls(false);
    settings.setBuiltInZoomControls(true);
    settings.setSupportMultipleWindows(true);
    settings.setEnableSmoothTransition(true);

    if (mPrivateBrowsing) {
        settings.setGeolocationEnabled(false);
        settings.setSaveFormData(false);
        settings.setSavePassword(false);

        settings.setAppCacheEnabled(false);
        settings.setDatabaseEnabled(false);
        settings.setDomStorageEnabled(false);
    } else {
        // HTML5 API flags
        settings.setAppCacheEnabled(true);
        settings.setDatabaseEnabled(true);
        settings.setDomStorageEnabled(true);

        // HTML5 configuration settings.
        settings.setAppCacheMaxSize(3 * 1024 * 1024);
        settings.setAppCachePath(mContext.getDir("appcache", 0).getPath());
        settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
        settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
    }

    setLongClickable(true);
    setDownloadListener(this);
}

From source file:com.nextgis.firereporter.GetFiresService.java

protected void GetNasaData(boolean bShowProgress) {
    Location currentLocation = null;
    String sLat = null, sLon = null;

    if (mLocManager != null) {
        currentLocation = mLocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (currentLocation == null) {
            currentLocation = mLocManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }/*  w w w. j av a2 s . c o  m*/

        if (currentLocation == null) {
            SendError(getString(R.string.noLocation));
            return;
        } else {
            sLat = Double.toString(currentLocation.getLatitude());
            sLon = Double.toString(currentLocation.getLongitude());
        }
    }

    SharedPreferences prefs = getSharedPreferences(MainActivity.PREFERENCES, MODE_PRIVATE | MODE_MULTI_PROCESS);
    String sURL = prefs.getString(SettingsActivity.KEY_PREF_SRV_NASA,
            getResources().getString(R.string.stDefaultServer));
    String sLogin = prefs.getString(SettingsActivity.KEY_PREF_SRV_NASA_USER, "fire_usr");
    String sPass = prefs.getString(SettingsActivity.KEY_PREF_SRV_NASA_PASS, "J59DY");
    int nDayInterval = prefs.getInt(SettingsActivity.KEY_PREF_SEARCH_DAY_INTERVAL + "_int", 5);
    int fetchRows = prefs.getInt(SettingsActivity.KEY_PREF_ROW_COUNT + "_int", 15);
    int searchRadius = prefs.getInt(SettingsActivity.KEY_PREF_FIRE_SEARCH_RADIUS + "_int", 5) * 1000;//meters
    boolean searchByDate = prefs.getBoolean(SettingsActivity.KEY_PREF_SEARCH_CURR_DAY, false);

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date();
    long diff = 86400000L * nDayInterval;//1000 * 60 * 60 * 24 * 5;// 5 days  
    date.setTime(date.getTime() - diff);
    String dt = dateFormat.format(date);

    String sFullURL = sURL + "?function=get_rows_nasa&user=" + sLogin + "&pass=" + sPass + "&limit=" + fetchRows
            + "&radius=" + searchRadius;//
    if (searchByDate) {
        sFullURL += "&date=" + dt;
    }
    if (sLat.length() > 0 && sLon.length() > 0) {
        sFullURL += "&lat=" + sLat + "&lon=" + sLon;
    }

    //String sRemoteData = "http://gis-lab.info/data/zp-gis/soft/fires.php?function=get_rows_nasa&user=fire_usr&pass=J59DY&limit=5";
    //if(!oNasa.getStatus().equals(AsyncTask.Status.RUNNING) && !oNasa.getStatus().equals(AsyncTask.Status.PENDING))
    new HttpGetter(this, 2, getResources().getString(R.string.stDownLoading), mFillDataHandler, bShowProgress)
            .execute(sFullURL);
}

From source file:com.mainpanel.LifeApp_Map.java

public void showrestaurant(View view) throws IOException {
    spinner.setVisibility(View.VISIBLE);
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    food_type = sharedPrefs.getString("food_type", "restaurant");
    notification_status = sharedPrefs.getBoolean("prefnotification", true);
    food_radius = sharedPrefs.getInt("food_radius", 500);

    String msg = "Searching " + food_type + " within " + food_radius + " radius.";
    Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();

    double mLatitude = mLocationClient.getLastLocation().getLatitude();
    double mLongitude = mLocationClient.getLastLocation().getLongitude();

    //        mLatitude = 40.6944;
    //        mLongitude = -73.9865;

    CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(mLatitude, mLongitude))
            .zoom(15).build();//from w w w. j a  v  a 2s.  c o m

    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
    sb.append("location=" + mLatitude + "," + mLongitude);
    sb.append("&radius=" + food_radius);
    sb.append("&types=" + food_type.toLowerCase());
    sb.append("&sensor=true");
    sb.append("&key=AIzaSyAFAFiOe4YPhXPuD9Vdq9Q29m5Iel_imJE");

    // Creating a new non-ui thread task to download Google place json data
    PlacesTask placesTask = new PlacesTask(food_type.toLowerCase());

    // Invokes the "doInBackground()" method of the class PlaceTask
    placesTask.execute(sb.toString());
    spinner.setVisibility(View.GONE);
}

From source file:com.mainpanel.LifeApp_Map.java

public void showtourismplaces(View view) throws IOException {
    spinner.setVisibility(View.VISIBLE);
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    food_type = sharedPrefs.getString("food_type", "restaurant");
    notification_status = sharedPrefs.getBoolean("prefnotification", true);
    food_radius = sharedPrefs.getInt("food_radius", 500);

    String msg = "Searching " + food_type + " within " + food_radius + " radius.";
    Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();

    double mLatitude = mLocationClient.getLastLocation().getLatitude();
    double mLongitude = mLocationClient.getLastLocation().getLongitude();

    //        mLatitude = 40.6944;
    //        mLongitude = -73.9865;
    food_radius = 2000;//from  w w  w.ja v  a 2 s  .  co m

    CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(mLatitude, mLongitude))
            .zoom(15).build();

    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
    sb.append("location=" + mLatitude + "," + mLongitude);
    sb.append("&radius=" + food_radius);
    sb.append("&types=museum|zoo|stadium|shopping_mall|amusement_park");
    sb.append("&sensor=true");
    sb.append("&key=AIzaSyAFAFiOe4YPhXPuD9Vdq9Q29m5Iel_imJE");

    // Creating a new non-ui thread task to download Google place json data
    PlacesTask placesTask = new PlacesTask("tourism");

    // Invokes the "doInBackground()" method of the class PlaceTask
    placesTask.execute(sb.toString());
    spinner.setVisibility(View.GONE);
}