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.alucas.snorlax.app.home.HomeActivity.java

private void checkIfFirstTime() {
    final String version = "version";
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    if (preferences.getInt(version, -1) < BuildConfig.VERSION_CODE) {
        mDonationDialog = HomeDialog.showDonation(this);
        preferences.edit().putInt(version, BuildConfig.VERSION_CODE).apply();
    }/* www  .  j  a  v  a2 s. co m*/
}

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

public static String getServerName(Context context) {
    SharedPreferences prefs = getPreferences(context);
    int instance = prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
    return prefs.getString(Constants.PREFERENCES_KEY_SERVER_NAME + instance, null);
}

From source file:com.data.RetrieveDataTask.java

protected Boolean doInBackground(Object... params) {

    try {//w ww  . j  av  a  2s  .c  om
        Timber.d("check for updates...");
        DataProvider dataProvider = new DataProvider();
        boolean isAlreadyStored = false;
        isAlreadyStored = dataProvider.isDataStored((Activity) params[0]);

        if (!isAlreadyStored) {
            Timber.d("no data available, so retrieve data...");
            HttpResponse response = new DefaultHttpClient().execute(new HttpGet(Constants.NAME_ROOM_URL));
            BufferedInputStream in = new BufferedInputStream(response.getEntity().getContent());

            LinkedList<Byte> bytes = new LinkedList<>();
            int b;
            while ((b = in.read()) != -1) {
                bytes.add((byte) b);
            }

            byte[] decryptedData = DecryptionService.decryptData(bytes, (String) params[1]);
            String data = new String(decryptedData);
            for (String l : data.split("\n")) {
                dataProvider.addNewEntry(l, (Activity) params[0]);
            }
        }
        SharedPreferences spData = ((Activity) params[0]).getApplicationContext().getSharedPreferences("Data",
                0);
        int remoteVersion = spData.getInt("DataVersionRemote", 0);
        spData.edit().putInt("DataVersion", remoteVersion).apply();

        Timber.d("... update success");
        return true;
    } catch (Exception e) {
        Timber.e(e, "... update failure " + e.getMessage());
    }
    return false;

}

From source file:com.google.android.apps.chrometophone.C2DMReceiver.java

private void generateNotification(Context context, String msg, String title, Intent intent) {
    int icon = R.drawable.status_icon;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, title, when);
    notification.setLatestEventInfo(context, title, msg, PendingIntent.getActivity(context, 0, intent, 0));
    notification.defaults = Notification.DEFAULT_SOUND;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    SharedPreferences settings = Prefs.get(context);
    int notificatonID = settings.getInt("notificationID", 0); // allow multiple notifications

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(notificatonID, notification);

    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("notificationID", ++notificatonID % 32);
    editor.commit();/*from ww  w  .  ja va  2s  . co  m*/
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.service.CfpSyncService.java

@Override
protected void doSync(Intent intent) throws Exception {
    Log.d(TAG, "Start sync");

    final Context context = this;

    final SharedPreferences settings = Prefs.get(context);
    final int localVersion = settings.getInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_NONE);

    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
        mLocalExecutor.execute(R.xml.search_suggest, new SearchSuggestHandler());
        mLocalExecutor.execute(R.xml.rooms, new RoomsHandler());
        mLocalExecutor.execute(R.xml.tracks, new TracksHandler());
        mLocalExecutor.execute(R.xml.presentationtypes, new SessionTypesHandler());
        mLocalExecutor.execute(context, "cache-speakers.json", new SpeakersHandler());
        mLocalExecutor.execute(context, "cache-presentations.json", new SessionsHandler());
        mLocalExecutor.execute(context, "cache-schedule.json", new ScheduleHandler());

        // Save local parsed version
        settings.edit().putInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_CURRENT).commit();

        final ContentValues values = new ContentValues();
        values.put(Sessions.SESSION_NEW, 0);
        getContentResolver().update(Sessions.CONTENT_NEW_URI, values, null, null);
    }/*from w  ww. j  ava2s.  c  o  m*/
    Log.d(TAG, "Local sync took " + (System.currentTimeMillis() - startLocal) + "ms");

    final CfpSyncManager syncManager = new CfpSyncManager(context);
    if (syncManager.shouldPerformRemoteSync(Intent.ACTION_SYNC.equals(intent.getAction()))) {
        Log.d(TAG, "Should perform remote sync");
        final long startRemote = System.currentTimeMillis();
        Editor prefsEditor = syncManager.hasRemoteContentChanged(mHttpClient);
        if (prefsEditor != null) {
            Log.d(TAG, "Remote content was changed");
            mRemoteExecutor.executeGet(SPEAKERS_URL, new SpeakersHandler());
            mRemoteExecutor.executeGet(PRESENTATIONS_URL, new SessionsHandler());
            mRemoteExecutor.executeGet(SCHEDULE_URL, new ScheduleHandler());
            prefsEditor.commit();
        }
        Log.d(TAG, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms");
    } else {
        Log.d(TAG, "Should not perform remote sync");
    }

    final CfpDatabase database = new CfpDatabase(this);
    database.cleanupLinkTables();

    if (!localParse) {
        final NotifierManager notifierManager = new NotifierManager(this);
        notifierManager.notifyNewSessions();
    }

    Log.d(TAG, "Sync finished");
}

From source file:codes.simen.l50notifications.ReminderService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    final String action = intent.getAction();
    if (ACTION_REMIND.equals(action)) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        final int reminderDelay = preferences.getInt("reminder_delay", 5000);

        final Bundle extras = intent.getExtras();

        reminders.put(System.currentTimeMillis() + reminderDelay, extras);

        handler.postDelayed(displayReminder, reminderDelay);

        builder = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.drawable.ic_reminder)
                .setContentTitle(String.format("%d reminders", reminders.size()))
                .setContentText("Tap to cancel all reminders").setOngoing(true)
                .setPriority(NotificationCompat.PRIORITY_MIN)
                .setContentIntent(PendingIntent.getService(getApplicationContext(), 0,
                        new Intent(getApplicationContext(), ReminderService.class).setAction(ACTION_STOP),
                        PendingIntent.FLAG_UPDATE_CURRENT));

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(NOTIFICATION_ID, builder.build());

    } else if (ACTION_STOP.equals(action)) {
        stopSelf();//from w  ww.j  a va 2 s  .c  om
        Toast.makeText(getApplicationContext(), "All reminders cancelled", Toast.LENGTH_SHORT).show();
    }
    return START_NOT_STICKY;
}

From source file:net.peterkuterna.android.apps.devoxxsched.service.CfpSyncService.java

@Override
protected void doSync(Intent intent) throws Exception {
    Log.d(TAG, "Start sync");

    Thread.sleep(5000);/*from  www  .  j a v  a2s.  c  o m*/

    final Context context = this;

    final SharedPreferences settings = Prefs.get(context);
    final int localVersion = settings.getInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_NONE);

    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
        mLocalExecutor.execute(R.xml.search_suggest, new SearchSuggestHandler());
        mLocalExecutor.execute(R.xml.rooms, new RoomsHandler());
        mLocalExecutor.execute(R.xml.tracks, new TracksHandler());
        mLocalExecutor.execute(R.xml.presentationtypes, new SessionTypesHandler());
        mLocalExecutor.execute(context, "cache-speakers.json", new SpeakersHandler());
        mLocalExecutor.execute(context, "cache-presentations.json", new SessionsHandler());
        mLocalExecutor.execute(context, "cache-schedule.json", new ScheduleHandler());

        mLocalExecutor.execute(context, "cache-parleys-presentations.json", new ParleysPresentationsHandler());

        // Save local parsed version
        settings.edit().putInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_CURRENT).commit();

        final ContentValues values = new ContentValues();
        values.put(Sessions.SESSION_NEW, 0);
        getContentResolver().update(Sessions.CONTENT_NEW_URI, values, null, null);
    }
    Log.d(TAG, "Local sync took " + (System.currentTimeMillis() - startLocal) + "ms");

    final CfpSyncManager syncManager = new CfpSyncManager(context);
    if (syncManager.shouldPerformRemoteSync(Intent.ACTION_SYNC.equals(intent.getAction()))) {
        Log.d(TAG, "Should perform remote sync");
        final long startRemote = System.currentTimeMillis();

        Editor prefsEditor = syncManager.hasRemoteContentChanged(mHttpClient);
        if (prefsEditor != null) {
            Log.d(TAG, "Remote content was changed");
            mRemoteExecutor.executeGet(SPEAKERS_URL, new SpeakersHandler());
            mRemoteExecutor.executeGet(PRESENTATIONS_URL, new SessionsHandler());
            mRemoteExecutor.executeGet(SCHEDULE_URL, new ScheduleHandler());
            prefsEditor.commit();
        }
        Log.d(TAG, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms");
    } else {
        Log.d(TAG, "Should not perform remote sync");
    }

    final CfpDatabase database = new CfpDatabase(this);
    database.cleanupLinkTables();

    final NotifierManager notifierManager = new NotifierManager(this);
    notifierManager.notifyNewSessions();

    Log.d(TAG, "Sync finished");
}

From source file:com.budrotech.jukebox.service.RESTMusicService.java

public static HttpUrl.Builder getSubsonicUrl(Context context, String method) {
    SharedPreferences preferences = Util.getPreferences(context);

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

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

    HttpUrl.Builder builder = HttpUrl.parse(serverUrl).newBuilder();
    builder.addPathSegment("rest");
    builder.addPathSegment(method + ".view");
    builder.addQueryParameter("u", username);
    builder.addQueryParameter("p", password);
    builder.addQueryParameter("v", Constants.REST_PROTOCOL_VERSION);
    builder.addQueryParameter("c", Constants.REST_CLIENT_ID);

    return builder;
}

From source file:at.florian_lentsch.expirysync.NotifyChecker.java

/**
 * (non-Javadoc) The alarm has been triggered -> create a notification, if
 * there are any expired products (or any that will soon expire)
 *//*from w  ww  .  ja va 2 s . com*/
@Override
public void onReceive(Context context, Intent intent) {
    Context appContext = context.getApplicationContext();
    final SharedPreferences sharedPref = appContext.getSharedPreferences("main", Context.MODE_PRIVATE);

    int daysBeforeMedium = sharedPref.getInt(SettingsActivity.KEY_DAYS_BEFORE_MEDIUM, 0);

    DatabaseManager.init(appContext);
    List<ProductEntry> products = DatabaseManager.getInstance().getAllProductEntries();
    List<String> expiringProducts = new ArrayList<String>();
    for (ProductEntry productEntry : products) {
        if ((new DateTime(productEntry.expiration_date)).minusDays(daysBeforeMedium).isBeforeNow()) {
            expiringProducts.add(productEntry.amount + "x " + productEntry.article.name);
        }
    }

    if (expiringProducts.size() > 0) {
        this.createExpiryNotification(appContext, expiringProducts);
    }
}

From source file:com.android.mms.MmsConfig.java

public static int getSimCardInfo() {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MmsApp.getApplication());
    int siminfo = sp.getInt("CmccSimCardInfo", 0);
    return siminfo;
}