List of usage examples for android.text.format Time setToNow
public void setToNow()
From source file:me.futuretechnology.blops.ui.HomeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // startService(new Intent(getApplication(), CleanupService.class)); // if (sharedPrefs.getBoolean(Keys.FIRST_RUN, true)) // {//w w w. j ava 2 s . c om // Editor editor = sharedPrefs.edit(); // editor.putBoolean(Keys.FIRST_RUN, false); // editor.apply(); // schedule cleanup service // FIXME temp fix Time time = new Time(); time.setToNow(); // time.hour = 3; // time.minute = 0; // time.second = 0; // ++time.monthDay; // time.normalize(true); Intent intent = new Intent(getApplication(), OnAlarmReceiver.class); intent.setAction(OnAlarmReceiver.ACTION_CLEANUP); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, time.toMillis(true), PendingIntent.getBroadcast(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); // } EventBus.getDefault().register(this); }
From source file:org.zapto.samhippiemiddlepoolchecker.Values.java
public void save() { //stores everything as sharedpreferences so the they will be shown when the app is opened SharedPreferences.Editor editor = settings.edit(); editor.putFloat("accepted", accepted); editor.putFloat("rejected", rejected); editor.putFloat("immature", immature); editor.putFloat("unexchanged", unexchanged); editor.putFloat("balance", balance); editor.putFloat("paid", paid); //have to make sure that the user's time and date preferences are respected Date date = new Date(); java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context); Time time = new Time(); time.setToNow(); String formattedTime;/*w ww . j ava 2s .co m*/ if (DateFormat.is24HourFormat(context)) { formattedTime = time.format("%k:%M"); } else { formattedTime = time.format("%l:%M %p"); } editor.putString("lastUpdatedTime", dateFormat.format(date) + " " + formattedTime); editor.commit(); //update widget here MainActivity.updateWidget(context); }
From source file:be.ac.ucl.lfsab1509.llncampus.services.AlarmService.java
/** * Send an alert to the user for the event e. * /* w ww .ja va 2 s . c o m*/ * @param e * Event to notify to the user. */ private void sendAlert(Event e) { final NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Time currentTime = new Time(); currentTime.setToNow(); long nbMin = e.getBeginTime().toMillis(false) / 60L / 1000L - currentTime.toMillis(false) / 60L / 1000L; final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(android.R.drawable.ic_dialog_alert) .setContentTitle(e.getDetail(Event.COURSE) + " " + getString(R.string.begins_in) + " " + nbMin + " " + getString(R.string.minutes)) .setContentText(e.getDetail(Event.ROOM) + " - " + e.getDetail(Event.TITLE)).setAutoCancel(true); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String ringtone = preferences.getString(SettingsActivity.NOTIFY_RINGTONE, null); if (ringtone == null) { notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } else { notificationBuilder.setSound(Uri.parse(ringtone)); } notificationManager.notify(1, notificationBuilder.build()); }
From source file:org.mozilla.gecko.FilePickerResultHandler.java
public String generateImageName() { Time now = new Time(); now.setToNow(); mImageName = now.format("%Y-%m-%d %H.%M.%S") + ".jpg"; return mImageName; }
From source file:pro.jariz.reisplanner.fragments.PlannerFragment.java
@Override public void Invoke(Object Result, Integer TaskType) { if (Result == null) { //Result has returned null, which means somethings wrong. //Show feedback to user in form of a Crouton, using NSTask.LastExceptionMessage Crouton.showText(this.getActivity(), "Unable to update station list: " + NSTask.LastExceptionMessage, CroutonStyles.errorStyle); return;//from w w w.j a va2s . c om } Object[] stationso = (Object[]) Result; NSStation[] stations = Arrays.copyOf(stationso, stationso.length, NSStation[].class); if (TaskType == NSTask.TYPE_STATIONS) { //update cache time & clear & insert into db Time now = new Time(); now.setToNow(); DB.setLastCacheTime("stations", new BigDecimal(now.toMillis(true)).intValue()); DB.clearStations(); DB.insertStations(stations); Crouton.showText(this.getActivity(), getResources().getString(R.string.updating_station_list_done), CroutonStyles.successStyle); } Render(stations, thisView, this.getActivity()); }
From source file:net.networksaremadeofstring.rhybudd.ZenossAPI.java
public static void updateLastChecked(Context mContext) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(mContext).edit(); Time now = new Time(); now.setToNow(); Log.e("toMillis", Long.toString(now.toMillis(true))); editor.putLong("lastCheck", now.toMillis(true)); editor.commit();/*from ww w.j av a2 s . c o m*/ }
From source file:uk.co.alt236.floatinginfo.provider.generalinfo.GeneralInfoProvider.java
@Override public void onLogShare() { final StringBuilder sb = new StringBuilder(); sb.append(mUiManager.getSharePayload()); final Time now = new Time(); now.setToNow(); final String ts = now.format3339(false); final Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, sb.toString()); shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_subject) + " " + ts); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(shareIntent);/*w ww . j a va2 s. c om*/ }
From source file:net.networksaremadeofstring.rhybudd.ZenossAPI.java
public static boolean shouldRefresh(Context mContext) { Time now = new Time(); now.setToNow(); if ((now.toMillis(true) - PreferenceManager.getDefaultSharedPreferences(mContext).getLong("lastCheck", now.toMillis(true))) > 900000) { return true; } else {/*w w w . ja va2s. c o m*/ return false; } }
From source file:be.ac.ucl.lfsab1509.llncampus.services.AlarmService.java
/** * Check if an event will occur and send a alert if needed. *//*from w ww. ja v a 2 s. c o m*/ private void checkAlarm() { SharedPreferences preferences = new SecurePreferences(this); if (!preferences.getBoolean(SettingsActivity.COURSES_NOTIFY, false)) { Log.d("AlarmService", "Course notifications are disabled."); return; } if (Course.getList().size() != 0 && nextEvent == null) { loadNextEvent(); } if (nextEvent != null) // If there is a next event, check if an alert should be sent. { int nbMin = LLNCampus.getIntPreference(SettingsActivity.NOTIFY_MINUTE, DEFAULT_NOTIFY_MINUTE, this); // Added computations if notifications depend on the position of the user. if (preferences.getBoolean(SettingsActivity.NOTIFY_WITH_GPS, false)) { Coordinates eventCoord = nextEvent.getCoordinates(); if (eventCoord != null) { Coordinates currentCoord = LLNCampus.getGPS().getPosition(); if (currentCoord != null) { double dist = eventCoord.getDistance(currentCoord); if (dist > MIN_DISTANCE && dist < LLNCampus.getIntPreference(SettingsActivity.NOTIFY_MAX_DISTANCE, DEFAULT_MAX_DISTANCE, this)) { int speedInKmPerHour = LLNCampus.getIntPreference(SettingsActivity.NOTIFY_SPEED_MOVE, DEFAULT_NOTIFY_SPEED, this); int speedMetersPerMinute = speedInKmPerHour * 1000 / 60; nbMin = (int) (dist / speedMetersPerMinute) + LLNCampus .getIntPreference(SettingsActivity.NOTIFY_MORE_TIME, DEFAULT_MORE_TIME, this); } } } } Time currentTime = new Time(); currentTime.setToNow(); // Check if a notification should be sent. if (Course.getList().size() != 0 && nextEvent.getBeginTime().toMillis(false) - nbMin * 60L * 1000L - currentTime.toMillis(false) < 0L) { sendAlert(nextEvent); loadNextEvent(); } } }
From source file:org.tomdroid.Note.java
public void setLastChangeDate() { Time now = new Time(); now.setToNow(); String time = now.format3339(false); setLastChangeDate(time);//from ww w .java 2 s .co m }