List of usage examples for android.content SharedPreferences getLong
long getLong(String key, long defValue);
From source file:com.hplasplas.reminders.services.NotificationService.java
private long getPreviousNotifyInterval(SharedPreferences notificationPreferences, long currentNotifyInterval) { long previousNotifyInterval = notificationPreferences.getLong(PREVIOUS_ALARM_INTERVAL, 0); if (previousNotifyInterval == 0) { previousNotifyInterval = currentNotifyInterval; }// w w w .ja v a 2s .c o m return previousNotifyInterval; }
From source file:eu.chainfire.geolog.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override//w w w . jav a 2 s .c o m public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); invalidateOptionsMenu(); } }); mViewPager.setOffscreenPageLimit(3); for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { actionBar .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } int play = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (play == ConnectionResult.SUCCESS) { // Force database creation Database.Helper helper = Database.Helper.getInstance(this); helper.getReadableDatabase(); // Force Off profile as default SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); long id = prefs.getLong(SettingsFragment.PREF_CURRENT_PROFILE, 0); Database.Profile profile = Database.Profile.getById(helper, id, null); if (profile == null) id = 0; if (id == 0) { profile = Database.Profile.getOffProfile(helper); id = profile.getId(); prefs.edit().putLong(SettingsFragment.PREF_CURRENT_PROFILE, id).commit(); } // Start background service if (profile.getType() != Database.Profile.Type.OFF) BackgroundService.startService(this); } else { GooglePlayServicesUtil.getErrorDialog(play, this, 0).show(); finish(); } }
From source file:com.notepadlite.WelcomeFragment.java
@Override public void onStart() { super.onStart(); // Read preferences SharedPreferences prefMain = getActivity().getPreferences(Context.MODE_PRIVATE); // Before we do anything else, check for a saved draft; if one exists, load it if (prefMain.getLong("draft-name", 0) != 0) { Bundle bundle = new Bundle(); bundle.putString("filename", "draft"); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle);//from ww w .j av a2 s . c om // Add NoteEditFragment getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit(); } else { // Change window title String title = getResources().getString(R.string.app_name); getActivity().setTitle(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, null, getResources().getColor(R.color.primary)); getActivity().setTaskDescription(taskDescription); } // Don't show the Up button in the action bar, and disable the button ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false); ((AppCompatActivity) getActivity()).getSupportActionBar().setHomeButtonEnabled(false); // Floating action button FloatingActionButton floatingActionButton = (FloatingActionButton) getActivity() .findViewById(R.id.button_floating_action_welcome); floatingActionButton.setImageResource(R.drawable.ic_action_new); floatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle bundle = new Bundle(); bundle.putString("filename", "new"); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); // Add NoteEditFragment getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit(); } }); } }
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
public static int getRemainingTrialDays(Context context) { SharedPreferences prefs = getPreferences(context); long installTime = prefs.getLong(Constants.PREFERENCES_KEY_INSTALL_TIME, 0L); if (installTime == 0L) { installTime = System.currentTimeMillis(); SharedPreferences.Editor editor = prefs.edit(); editor.putLong(Constants.PREFERENCES_KEY_INSTALL_TIME, installTime); editor.commit();// w ww.j av a 2 s. c om } long now = System.currentTimeMillis(); long millisPerDay = 24L * 60L * 60L * 1000L; int daysSinceInstall = (int) ((now - installTime) / millisPerDay); return Math.max(0, Constants.FREE_TRIAL_DAYS - daysSinceInstall); }
From source file:com.anjalimacwan.fragment.WelcomeFragment.java
@Override public void onStart() { super.onStart(); // Read preferences SharedPreferences prefMain = getActivity().getPreferences(Context.MODE_PRIVATE); // Before we do anything else, check for a saved draft; if one exists, load it if (prefMain.getLong("draft-name", 0) != 0) { Bundle bundle = new Bundle(); bundle.putString("filename", "draft"); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle);//from w w w . j av a2s .c om // Add NoteEditFragment getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit(); } else { // Change window title String title = getResources().getString(R.string.app_name); getActivity().setTitle(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, null, ContextCompat.getColor(getActivity(), R.color.primary)); getActivity().setTaskDescription(taskDescription); } // Don't show the Up button in the action bar, and disable the button ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false); ((AppCompatActivity) getActivity()).getSupportActionBar().setHomeButtonEnabled(false); // Floating action button FloatingActionButton floatingActionButton = (FloatingActionButton) getActivity() .findViewById(R.id.button_floating_action_welcome); floatingActionButton.setImageResource(R.drawable.ic_action_new); floatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle bundle = new Bundle(); bundle.putString("filename", "new"); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); // Add NoteEditFragment getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit(); } }); } }
From source file:com.farmerbb.notepad.fragment.WelcomeFragment.java
@Override public void onStart() { super.onStart(); // Read preferences SharedPreferences prefMain = getActivity().getPreferences(Context.MODE_PRIVATE); // Before we do anything else, check for a saved draft; if one exists, load it if (prefMain.getLong("draft-name", 0) != 0) { Bundle bundle = new Bundle(); bundle.putString("filename", "draft"); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle);//from w ww .ja v a2 s .c om // Add NoteEditFragment getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit(); } else { // Change window title String title = getResources().getString(R.string.app_name); getActivity().setTitle(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.ic_recents_logo)).getBitmap(); ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, bitmap, ContextCompat.getColor(getActivity(), R.color.primary)); getActivity().setTaskDescription(taskDescription); } // Don't show the Up button in the action bar, and disable the button ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false); ((AppCompatActivity) getActivity()).getSupportActionBar().setHomeButtonEnabled(false); // Floating action button FloatingActionButton floatingActionButton = getActivity() .findViewById(R.id.button_floating_action_welcome); floatingActionButton.setImageResource(R.drawable.ic_action_new); floatingActionButton.setOnClickListener(v -> { Bundle bundle = new Bundle(); bundle.putString("filename", "new"); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); // Add NoteEditFragment getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit(); }); } }
From source file:org.teleportr.ConnectorService.java
public void cleanUp(SharedPreferences prefs) { long older_than = System.currentTimeMillis() - prefs.getLong(CLEANUP_INTERVAL, 21 * 24 * 3600000); // 3 weeks if (prefs.getLong(LAST_CLEANUP, 0) < older_than) { getContentResolver().delete(/* w w w .j av a 2s .co m*/ RidesProvider.getRidesUri(getContext()).buildUpon() .appendQueryParameter(RidesProvider.OLDER_THAN, String.valueOf(older_than)).build(), null, null); prefs.edit().putLong(LAST_CLEANUP, System.currentTimeMillis()).commit(); } }
From source file:withings.apiaccess.WithingsAPI.java
private WithingsAPI(Context context) { this.context = context; loadUser();/*from w ww . j a v a2s . c om*/ // Load the last update SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE); lastUpdate = preferences.getLong("lastUpdate", WeightValue.DATE_NOT_RECORDED); }
From source file:org.svij.taskwarriorapp.TasksActivity.java
@Override protected void onResume() { super.onResume(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); long date_long = prefs.getLong("notifications_alarm_time", System.currentTimeMillis()); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Intent i = new Intent(this, NotificationService.class); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date_long); if (!calendar.getTime().before(new Date())) { am.cancel(pi);/*from ww w.j a v a2s .com*/ am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), calendar.getTimeInMillis() + AlarmManager.INTERVAL_DAY, pi); } }