List of usage examples for android.text.format Time toMillis
public long toMillis(boolean ignoreDst)
From source file:Main.java
/** * transform a Time object into an equivalent Calendar (used in display events) * @param time/*from w w w .j a v a 2 s. co m*/ * @return */ public static Calendar timeToCalendar(Time time) { long millis = time.toMillis(false); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(millis); return cal; }
From source file:Main.java
static long getTimestamp() { Time time = new Time(); time.setToNow(); return time.toMillis(false); }
From source file:Main.java
/********** Time **********/ public static long currentTimeInMillis() { Time time = new Time(); time.setToNow();/*from w ww . j av a 2 s . c o m*/ return time.toMillis(false); }
From source file:Main.java
public static String GetCurrentFormatTime(String format) { Time time = new Time(); time.setToNow();/*from w ww. j a v a 2 s . co m*/ return GetCurrentFormatTime(time.toMillis(false), format); }
From source file:Main.java
/** * Parse the given string as a RFC 3339 timestamp, returning the value as * milliseconds since the epoch.//from w w w .j a v a 2s .com */ public static long parseTime(String timestamp) { final Time time = new Time(); time.parse3339(timestamp); return time.toMillis(false); }
From source file:Main.java
private static void getFormatTime(Context context, Time time, int i, boolean flag, CharBuffer charbuffer) { long l = time.toMillis(true); boolean flag1; if ((i & 1) != 0) flag1 = true;/*from ww w .j a v a 2s. c om*/ else flag1 = false; if (flag) charbuffer.append(DateUtils.formatDateRange(context, l, l, i)); else if (flag1) { if ((i ^ 1) != 0) { charbuffer.append(DateUtils.formatDateRange(context, l, l, i ^ 1)); charbuffer.append(" "); } String s = getDetailedAmPm(time.hour); if (time.hour > 12) time.hour = -12 + time.hour; long l1 = time.toMillis(true); String s1 = DateUtils.formatDateRange(context, l1, l1, 129); Resources resources = Resources.getSystem(); Object aobj[] = new Object[2]; aobj[0] = s1; aobj[1] = s; charbuffer.append(resources.getString(0x60c01f7, aobj)); } else { charbuffer.append(DateUtils.formatDateRange(context, l, l, i)); } }
From source file:be.ac.ucl.lfsab1509.llncampus.services.AlarmService.java
/** * Load the next event in the nextEvent variable. *///w w w .j av a2 s .c om private static void loadNextEvent() { Log.d("AlarmService", "nextEvent update"); long precTime; if (nextEvent == null) { Time currentDate = new Time(); currentDate.setToNow(); Log.d("AlarmService", "currentDate.toMilis= " + currentDate.toMillis(false)); precTime = currentDate.toMillis(false); } else { precTime = nextEvent.getBeginTime().toMillis(false); } Cursor c = LLNCampus.getDatabase() .sqlRawQuery("SELECT h.TIME_BEGIN, h.TIME_END, h.COURSE, h.ROOM, c.NAME " + "FROM Horaire as h, Courses as c " + "WHERE h.COURSE = c.CODE AND TIME_BEGIN > " + precTime + " " + "ORDER BY TIME_BEGIN ASC LIMIT 1"); c.moveToFirst(); try { nextEvent = new Event(c.getLong(0), c.getLong(1)); nextEvent.addDetail(Event.COURSE, c.getString(2)); nextEvent.addDetail(Event.ROOM, c.getString(3)); nextEvent.addDetail(Event.TITLE, c.getString(4)); c.close(); } catch (CursorIndexOutOfBoundsException e) // No event yet. { resetNextEvent(); } }
From source file:nz.ac.otago.psyanlab.common.util.FileUtils.java
/** * Generates a relatively unique path to use as a temporary directory. * //from w ww . j a v a2 s. co m * @return */ public static String generateTempPath() { Time now = new Time(); now.setToNow(); return "tmp-" + now.toMillis(false) + "/"; }
From source file:net.networksaremadeofstring.rhybudd.Notifications.java
public static void SendGCMNotification(ZenossEvent Event, Context context) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); Time now = new Time(); now.setToNow();//from w w w. ja v a 2 s . c o m //We don't need to overwhelm the user with their notification sound / vibrator if ((now.toMillis(true) - PreferenceManager.getDefaultSharedPreferences(context).getLong("lastCheck", now.toMillis(true))) < 3000) { //Log.e("SendGCMNotification", "Not publishing a notification due to stampede control"); return; } Intent notificationIntent = new Intent(context, ViewZenossEventsListActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("forceRefresh", true); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Uri soundURI = null; try { if (settings.getBoolean("notificationSound", true)) { if (settings.getString("notificationSoundChoice", "").equals("")) { soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } else { try { soundURI = Uri.parse(settings.getString("notificationSoundChoice", "")); } catch (Exception e) { soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } } } else { soundURI = null; } } catch (Exception e) { } String notifTitle = "New Events Received"; int notifPriority = Notification.PRIORITY_DEFAULT; //int AlertType = NOTIFICATION_GCM_GENERIC; try { if (Event.getSeverity().equals("5")) { notifTitle = context.getString(R.string.CriticalNotificationTitle); notifPriority = Notification.PRIORITY_MAX; //AlertType = NOTIFICATION_GCM_CRITICAL; } else if (Event.getSeverity().equals("4")) { notifTitle = context.getString(R.string.ErrorNotificationTitle); notifPriority = Notification.PRIORITY_HIGH; //AlertType = NOTIFICATION_GCM_ERROR; } else if (Event.getSeverity().equals("3")) { notifTitle = context.getString(R.string.WarnNotificationTitle); notifPriority = Notification.PRIORITY_DEFAULT; //AlertType = NOTIFICATION_GCM_WARNING; } else if (Event.getSeverity().equals("2")) { notifTitle = context.getString(R.string.InfoNotificationTitle); notifPriority = Notification.PRIORITY_LOW; //AlertType = NOTIFICATION_GCM_INFO; } else if (Event.getSeverity().equals("1")) { notifTitle = context.getString(R.string.DebugNotificationTitle); notifPriority = Notification.PRIORITY_MIN; //AlertType = NOTIFICATION_GCM_DEBUG; } } catch (Exception e) { } long[] vibrate = { 0, 100, 200, 300 }; try { AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); //Log.e("audio.getRingerMode()",Integer.toString(audio.getRingerMode())); switch (audio.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: //Do nothing to fix GitHub issue #13 //Log.e("AudioManager","Doing nothing because we are silent"); vibrate = new long[] { 0, 0 }; break; } } catch (Exception e) { e.printStackTrace(); } Intent broadcastMassAck = new Intent(); broadcastMassAck.setAction(MassAcknowledgeReceiver.BROADCAST_ACTION); PendingIntent pBroadcastMassAck = PendingIntent.getBroadcast(context, 0, broadcastMassAck, 0); if (Build.VERSION.SDK_INT >= 16) { Notification noti = new Notification.BigTextStyle(new Notification.Builder(context) .setContentTitle(notifTitle).setPriority(notifPriority).setAutoCancel(true).setSound(soundURI) .setVibrate(vibrate).setContentText(Event.getDevice()).setContentIntent(contentIntent) .addAction(R.drawable.ic_action_resolve_all, "Acknowledge all Events", pBroadcastMassAck) .setSmallIcon(R.drawable.ic_stat_alert)).bigText( Event.getSummary() + "\r\n" + Event.getComponentText() + "\r\n" + Event.geteventClass()) .build(); if (settings.getBoolean("notificationSoundInsistent", false)) noti.flags |= Notification.FLAG_INSISTENT; noti.tickerText = notifTitle; NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_GCM_GENERIC, noti); } else { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_alert).setContentTitle(notifTitle) .setContentText(Event.getDevice() + ": " + Event.getSummary()).setContentIntent(contentIntent) .setSound(soundURI).setVibrate(vibrate) .addAction(R.drawable.ic_action_resolve_all, "Acknowledge all Events", pBroadcastMassAck) .setAutoCancel(true).setPriority(notifPriority); NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_GCM_GENERIC, mBuilder.build()); } }
From source file:com.granita.tasks.notification.NotificationActionUtils.java
public static void sendStartNotification(Context context, String title, Uri taskUri, int notificationId, long startDate, boolean startAllDay, boolean silent) { String startString = ""; if (startAllDay) { startString = context.getString(R.string.notification_task_start_today); } else {//from w ww . j a v a2 s.c om startString = context.getString(R.string.notification_task_start_date, new DateFormatter(context) .format(makeTime(startDate, startAllDay), DateFormatContext.NOTIFICATION_VIEW)); } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // build notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notification) .setContentTitle(context.getString(R.string.notification_task_start_title, title)) .setContentText(startString); // dismisses the notification on click mBuilder.setAutoCancel(true); // set status bar test mBuilder.setTicker(title); // enable light, sound and vibration if (silent) { mBuilder.setDefaults(0); } else { mBuilder.setDefaults(Notification.DEFAULT_ALL); } // set notification time // set displayed time if (startAllDay) { Time now = new Time(); now.setToNow(); now.set(0, 0, 0, now.monthDay, now.month, now.year); mBuilder.setWhen(now.toMillis(true)); } else { mBuilder.setWhen(startDate); } // add actions if (android.os.Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) { NotificationAction completeAction = new NotificationAction( NotificationActionIntentService.ACTION_COMPLETE, R.string.notification_action_completed, notificationId, taskUri, startDate); mBuilder.addAction(NotificationActionIntentService.getCompleteAction(context, NotificationActionUtils.getNotificationActionPendingIntent(context, completeAction))); } // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(Intent.ACTION_VIEW); resultIntent.setData(taskUri); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); notificationManager.notify(notificationId, mBuilder.build()); }