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:net.majorkernelpanic.spydroid.SpydroidActivity.java

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (key.equals("video_resX")) {
        Session.defaultVideoQuality.resX = sharedPreferences.getInt("video_resX", 0);
    } else if (key.equals("video_resY")) {
        Session.defaultVideoQuality.resY = sharedPreferences.getInt("video_resY", 0);
    } else if (key.equals("video_framerate")) {
        Session.defaultVideoQuality.frameRate = Integer
                .parseInt(sharedPreferences.getString("video_framerate", "0"));
    } else if (key.equals("video_bitrate")) {
        Session.defaultVideoQuality.bitRate = Integer
                .parseInt(sharedPreferences.getString("video_bitrate", "0")) * 1000;
    } else if (key.equals("stream_audio") || key.equals("audio_encoder")) {
        Session.setDefaultAudioEncoder(sharedPreferences.getBoolean("stream_audio", true)
                ? Integer.parseInt(sharedPreferences.getString("audio_encoder", "3"))
                : 0);/* ww  w . j  av a 2s .  co  m*/
    } else if (key.equals("stream_video") || key.equals("video_encoder")) {
        Session.setDefaultVideoEncoder(sharedPreferences.getBoolean("stream_video", true)
                ? Integer.parseInt(sharedPreferences.getString("video_encoder", "2"))
                : 0);
    } else if (key.equals("enable_http")) {
        if (sharedPreferences.getBoolean("enable_http", true)) {
            if (httpServer == null)
                httpServer = new CustomHttpServer(8080, this.getApplicationContext(), handler);
        } else {
            if (httpServer != null)
                httpServer = null;
        }
    } else if (key.equals("enable_rtsp")) {
        if (sharedPreferences.getBoolean("enable_rtsp", true)) {
            if (rtspServer == null)
                rtspServer = new RtspServer(8086, handler);
        } else {
            if (rtspServer != null)
                rtspServer = null;
        }
    }
}

From source file:com.application.utils.ApplicationLoader.java

private String getRegistrationId() {
    final SharedPreferences prefs = getGCMPreferences(applicationContext);
    String registrationId = prefs.getString(PROPERTY_REG_ID, "");
    if (registrationId.length() == 0) {
        Log.i(TAG, "Registration not found.");
        return "";
    }/*from www .  ja  v  a 2  s  . c  om*/
    int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
    int currentVersion = getAppVersion();
    if (registeredVersion != currentVersion) {
        Log.i(TAG, "App version changed.");
        return "";
    }
    return registrationId;
}

From source file:com.ultramegatech.ey.UpdateService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (!HttpHelper.isConnected(this)) {
        return;//w  w  w . jav  a 2 s  .  co  m
    }

    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    final long lastCheck = preferences.getLong(KEY_LAST_CHECK, 0);
    final long now = System.currentTimeMillis();
    if (now - lastCheck < CHECK_INTERVAL) {
        return;
    }

    Log.v(TAG, "Checking for updates");

    final int version = preferences.getInt(KEY_VERSION, 0);
    final int newVersion = HttpHelper.getVersion();
    if (newVersion > version) {
        Log.v(TAG, "Downloading updates...");

        final ContentValues[] valuesArray = fetchElementData(newVersion);
        if (valuesArray == null) {
            return;
        }

        final ContentResolver cr = getContentResolver();
        Uri uri;
        int changed;
        for (int i = 0; i < valuesArray.length; i++) {
            uri = ContentUris.withAppendedId(Elements.CONTENT_URI_NUMBER,
                    valuesArray[i].getAsLong(Elements.NUMBER));
            changed = cr.update(uri, valuesArray[i], null, null);

            if (changed == 0) {
                cr.insert(Elements.CONTENT_URI, valuesArray[i]);
            }
        }

        preferences.edit().putInt(KEY_VERSION, newVersion).commit();

        Log.v(TAG, "Update completed successfully");
    }

    preferences.edit().putLong(KEY_LAST_CHECK, System.currentTimeMillis()).commit();
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

public static int[] getUnreads(Context context) {
    SharedPreferences sharedPrefs = context.getSharedPreferences(
            "com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    int currentAccount = sharedPrefs.getInt("current_account", 1);

    HomeDataSource data = HomeDataSource.getInstance(context);
    int homeTweets = data.getUnreadCount(currentAccount);

    MentionsDataSource mentions = MentionsDataSource.getInstance(context);
    int mentionsTweets = mentions.getUnreadCount(currentAccount);

    int dmTweets = sharedPrefs.getInt("dm_unread_" + currentAccount, 0);

    return new int[] { homeTweets, mentionsTweets, dmTweets };
}

From source file:am.hour.beebird.Activity.MainActivity.java

public void selectItem(int position, int info) {
    // update the main content by replacing fragments
    //??????//w  w  w  . j ava 2s.co  m
    if (position == recent_fragment_number) {
        mDrawerLayout.closeDrawer(mDrawerLeftLayout);
        return;
    }
    if (position == 0) {
        setTitle(R.string.list_left_zero);
        if (fragments.get(position) == null) {
            SharedPreferences sharedpreference = getSharedPreferences("unknown", MODE_PRIVATE);
            int loginornot = sharedpreference.getInt("LOGINORNOT", 0);
            if (loginornot == 0)
                fragment = new LoginFragment();
            else if (loginornot == 1)
                fragment = new PersonalFragment();
        } else {

            fragment = fragments.get(position);
        }
        recent_fragment_number = 0;
    }
    if (position == 1) {

        ll_random.setBackgroundResource(R.color.ll_leftdrawer_checked);
        ll_liked.setBackgroundResource(R.color.ll_leftdrawer_nonchecked);
        ll_setting.setBackgroundResource(R.color.ll_leftdrawer_nonchecked);
        setTitle(R.string.list_left_one);
        if (fragments.get(position) == null) {

            fragment = new JobFragment();
        } else {

            fragment = fragments.get(position);

        }
        recent_fragment_number = 1;
    }
    if (position == 2) {
        ll_random.setBackgroundResource(R.color.ll_leftdrawer_nonchecked);
        ll_liked.setBackgroundResource(R.color.ll_leftdrawer_checked);
        ll_setting.setBackgroundResource(R.color.ll_leftdrawer_nonchecked);
        setTitle(R.string.list_left_two);
        if (fragments.get(position) == null) {

            fragment = new LikedFragment();
        } else {

            fragment = fragments.get(position);
        }
        recent_fragment_number = 2;
    }
    if (position == 3) {
        ll_random.setBackgroundResource(R.color.ll_leftdrawer_nonchecked);
        ll_liked.setBackgroundResource(R.color.ll_leftdrawer_nonchecked);
        ll_setting.setBackgroundResource(R.color.ll_leftdrawer_checked);
        setTitle(R.string.list_left_three);
        if (fragments.get(position) == null) {

            fragment = new SettingFragment();
        } else {

            fragment = fragments.get(position);
        }
        recent_fragment_number = 3;
    }

    Bundle args = new Bundle();
    args.putInt(Constant.ARG_FRAGMENT_INFO, info);
    fragment.setArguments(args);

    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

    mDrawerLayout.closeDrawer(mDrawerLeftLayout);
}

From source file:com.facebook.android.friendsmash.FriendSmashApplication.java

public void loadInventory() {
    if (ParseUser.getCurrentUser() != null) {
        setBombs(ParseUser.getCurrentUser().getInt("bombs"));
        setCoins(ParseUser.getCurrentUser().getInt("coins"));
    } else {//from   w w  w  .  j  ava 2  s  .c  om
        SharedPreferences prefs = getApplicationContext().getSharedPreferences("Inventory", MODE_PRIVATE);
        long lastSavedTime = prefs.getLong("lastSavedTime", 0);

        if (lastSavedTime == 0) {
            setBombs(NEW_USER_BOMBS);
            setCoins(NEW_USER_COINS);
        } else {
            setBombs(prefs.getInt("bombs", 0));
            setCoins(prefs.getInt("coins", 0));
        }
    }
}

From source file:com.facebook.internal.LikeActionController.java

private synchronized static void performFirstInitialize() {
    if (isInitialized) {
        return;//  www.  j  a  v a 2  s.  c  o  m
    }

    handler = new Handler(Looper.getMainLooper());

    SharedPreferences sharedPreferences = applicationContext.getSharedPreferences(LIKE_ACTION_CONTROLLER_STORE,
            Context.MODE_PRIVATE);

    objectSuffix = sharedPreferences.getInt(LIKE_ACTION_CONTROLLER_STORE_OBJECT_SUFFIX_KEY, 1);
    controllerDiskCache = new FileLruCache(applicationContext, TAG, new FileLruCache.Limits());

    registerSessionBroadcastReceivers();

    isInitialized = true;
}

From source file:ru.gkpromtech.exhibition.db.DbHelper.java

public void applyUpdates(SQLiteDatabase db, JsonNode updates, boolean isStatic) throws Exception {

    JsonNode nodeRev = updates.get("revision");
    if (nodeRev == null)
        return;/*w  w  w  .  ja v a 2s  . c o m*/

    final String synchronous = getPragma(db, "synchronous");
    final String journalMode = getPragma(db, "journal_mode");

    db.rawQuery("PRAGMA synchronous = OFF", null);
    db.rawQuery("PRAGMA journal_mode = MEMORY", null);
    //  FK,  ?   ???    add-update
    db.execSQL("PRAGMA foreign_keys = OFF");

    SharedPreferences prefs = getPrefs();

    int langId = Profile.getInstance(mContext).getLangId();
    int currentRevision = prefs.getInt("revision", 0);
    ObjectMapper mapper = new ObjectMapper();
    int revision = nodeRev.asInt();
    ArrayNode nodeChanges = (ArrayNode) updates.get("changes");

    TypeReference<List<Change>> typeRef = new TypeReference<List<Change>>() {
    };
    List<Change> changes = mapper.readValue(nodeChanges.traverse(), typeRef);

    Map<Table, List<Integer>> deletedTableRowIds = new HashMap<>();

    try {
        db.beginTransaction();

        for (Change change : changes) {
            if (currentRevision > change.id) {
                Log.w("PPDB", "Skipping old change #" + change.id);
                continue;
            }

            boolean tr = change.entity.endsWith("_tr");
            String entityName = !tr ? change.entity : change.entity.substring(0, change.entity.length() - 3);

            Class<? extends Entity> entity = getEntityForTableName(entityName);
            if (entity == null) {
                Log.e("PPDB", "Cannot find entity for " + entityName);
                continue;
            }

            Table<? extends Entity> table = getTableFor(entity);
            if (table == null) {
                Log.e("PPDB", "Cannot find table for entity " + entityName);
                continue;
            }

            if (!tr) {
                if (change.data != null) {
                    switch (change.changetype) {
                    case Change.ADDED:
                        table.insert(db, change.data, SQLiteDatabase.CONFLICT_FAIL);
                        break;
                    case Change.UPDATED:
                        change.data.remove("id");
                        table.partialUpdate(db, change.rowid, change.data, SQLiteDatabase.CONFLICT_FAIL);
                        break;
                    }
                } else {
                    if (change.changetype == Change.DELETED) {
                        List<Integer> ids = deletedTableRowIds.get(table);
                        if (ids == null) {
                            ids = new ArrayList<>();
                            deletedTableRowIds.put(table, ids);
                        }
                        ids.add(change.rowid);
                    }
                }
            } else if (change.data != null) {
                int changeLangId = change.data.get("languageid").asInt();
                if (changeLangId != langId)
                    continue;
                change.data.remove("languageid");
                switch (change.changetype) {
                case Change.ADDED:
                case Change.UPDATED:
                    TableRef annotation = entity.getAnnotation(TableRef.class);
                    if (annotation == null) {
                        Log.e("PPDB", "Cannot get trid field for entity " + entityName);
                        continue;
                    }
                    String trIdName = annotation.trid();
                    JsonNode nodeTrId = change.data.get(trIdName);
                    if (nodeTrId == null) {
                        Log.e("PPDB", "Change data don't have a field [" + trIdName + "]: " + entityName);
                        continue;
                    }
                    int id = nodeTrId.asInt();
                    change.data.remove("id");
                    change.data.remove(trIdName);
                    table.partialUpdate(db, id, change.data, SQLiteDatabase.CONFLICT_FAIL);
                    break;
                }
            }
        }

        db.setTransactionSuccessful();

    } finally {
        db.endTransaction();
    }

    //   ??? ?, ? FK
    db.execSQL("PRAGMA foreign_keys = ON");

    try {
        db.beginTransaction();

        for (Map.Entry<Table, List<Integer>> entry : deletedTableRowIds.entrySet()) {
            Table table = entry.getKey();
            List<Integer> ids = entry.getValue();
            for (Integer id : ids)
                table.delete(db, id);
        }

        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }

    if (synchronous != null)
        db.rawQuery("PRAGMA synchronous = " + synchronous, null);
    if (journalMode != null)
        db.rawQuery("PRAGMA journal_mode = " + journalMode, null);

    if (revision > currentRevision)
        prefs.edit().putInt("revision", revision).apply();

    if (isStatic)
        prefs.edit().putInt("jsonRevision", revision).apply();
}

From source file:com.amaze.filemanager.adapters.TabSpinnerAdapter.java

@Override
public View getDropDownView(final int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View row = inflater.inflate(R.layout.spinner_dropdown_layout, parent, false);

    ma = ((Main) fragmentTransaction.findFragmentById(R.id.content_frame));
    final TextView textView = (TextView) row.findViewById(R.id.spinnerText);
    LinearLayout linearLayout = (LinearLayout) row.findViewById(R.id.textParent);
    final SharedPreferences sharedPreferences1 = PreferenceManager.getDefaultSharedPreferences(context);
    String skin = sharedPreferences1.getString("skin_color", "#5677fc");
    final int spinner_current = sharedPreferences1.getInt("spinner_selected", 0);
    ImageButton imageButton = (ImageButton) row.findViewById(R.id.spinnerButton);
    if (items.get(position).equals("/"))
        textView.setText(R.string.rootdirectory);
    else//from   w  w  w  .  j a  v  a2s .  c  o  m
        textView.setText(new File(items.get(position)).getName());
    imageButton.setBackgroundColor(Color.parseColor(skin));

    if (position == spinner_current) {

        textView.setTextColor(Color.parseColor(skin));
        textView.setTypeface(null, Typeface.BOLD);

    }

    linearLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            hideSpinnerDropDown(spinner);

            if (position == spinner_current) {
            } else {

                TabHandler tabHandler1 = new TabHandler(context, null, null, 1);
                Tab tab = tabHandler1.findTab(position);
                String name = tab.getPath();
                //Toast.makeText(getActivity(), name, Toast.LENGTH_SHORT).show();
                sharedPreferences1.edit().putString("current", name).apply();
                sharedPreferences1.edit().putInt("spinner_selected", position).apply();

                Main ma = ((Main) fragmentTransaction.findFragmentById(R.id.content_frame));
                ma.loadlist(new File(tab.getPath()), false);

                Animation animationLeft = AnimationUtils.loadAnimation(getContext(), R.anim.tab_selection_left);
                Animation animationRight = AnimationUtils.loadAnimation(getContext(),
                        R.anim.tab_selection_right);

                if (position < spinner_current) {
                    ma.listView.setAnimation(animationLeft);
                    ma.gridView.setAnimation(animationLeft);
                } else {
                    ma.listView.setAnimation(animationRight);
                    ma.gridView.setAnimation(animationRight);
                }

            }
        }
    });

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            TabHandler tabHandler = new TabHandler(context, null, null, 1);
            Tab tab = tabHandler.findTab(position);
            if (position > spinner_current) {

                //Toast.makeText(getContext(), "Closed", Toast.LENGTH_SHORT).show();
                items.remove(position);

                int old_tab = tab.getTab();
                int a;
                for (a = old_tab; a < tabHandler.getTabsCount() - 1; a++) {

                    int new_tab = a + 1;
                    Tab tab1 = tabHandler.findTab(new_tab);
                    String next_label = tab1.getLabel();
                    String next_path = tab1.getPath();
                    tabHandler.updateTab(new Tab(a, next_label, next_path));
                }
                tabHandler.deleteTab(tabHandler.getTabsCount() - 1);
                hideSpinnerDropDown(spinner);

            } else if (position < spinner_current) {

                // Toast.makeText(getContext(), "Closed", Toast.LENGTH_SHORT).show();
                items.remove(position);
                int old_tab = tab.getTab();
                int a;
                for (a = old_tab; a < tabHandler.getTabsCount() - 1; a++) {

                    int new_tab = a + 1;
                    Tab tab1 = tabHandler.findTab(new_tab);
                    String next_label = tab1.getLabel();
                    String next_path = tab1.getPath();
                    tabHandler.updateTab(new Tab(a, next_label, next_path));
                }
                tabHandler.deleteTab(tabHandler.getTabsCount() - 1);
                int older_spinner_selected = sharedPreferences1.getInt("spinner_selected", 0);
                older_spinner_selected--;
                sharedPreferences1.edit().putInt("spinner_selected", older_spinner_selected).apply();
                hideSpinnerDropDown(spinner);

            } else if (position == spinner_current) {

                if (tabHandler.getTabsCount() == 1) {
                    // Toast.makeText(getContext(), "exits the app", Toast.LENGTH_SHORT).show();
                    ma.home();

                } else if (tabHandler.getTabsCount() - 1 > position) {
                    items.remove(position);
                    int old_tab = tab.getTab();
                    int a;
                    for (a = old_tab; a < tabHandler.getTabsCount() - 1; a++) {

                        int new_tab = a + 1;
                        Tab tab1 = tabHandler.findTab(new_tab);
                        String next_label = tab1.getLabel();
                        String next_path = tab1.getPath();
                        tabHandler.updateTab(new Tab(a, next_label, next_path));
                    }
                    tabHandler.deleteTab(tabHandler.getTabsCount() - 1);
                    Tab tab1 = tabHandler.findTab(spinner_current);
                    ma.loadlist(new File(tab1.getPath()), false);

                } else if (tabHandler.getTabsCount() - 1 == position) {
                    items.remove(position);
                    tabHandler.deleteTab(tabHandler.getTabsCount() - 1);

                    int older_spinner_selected = sharedPreferences1.getInt("spinner_selected", 0);
                    older_spinner_selected--;
                    sharedPreferences1.edit().putInt("spinner_selected", older_spinner_selected).apply();
                    Tab tab1 = tabHandler.findTab(older_spinner_selected);
                    Main ma = ((Main) fragmentTransaction.findFragmentById(R.id.content_frame));
                    ma.loadlist(new File(tab1.getPath()), false);
                }
            }
        }
    });
    return row;
}

From source file:ac.robinson.mediaphone.activity.TemplateBrowserActivity.java

@Override
protected void onResume() {
    super.onResume();
    // reload previous scroll position
    SharedPreferences rotationSettings = getSharedPreferences(MediaPhone.APPLICATION_NAME,
            Context.MODE_PRIVATE);
    mTemplates.setSelectionFromTop(rotationSettings.getInt(getString(R.string.key_template_list_top), 0),
            rotationSettings.getInt(getString(R.string.key_template_list_position), 0));
}