Example usage for android.text.format Time Time

List of usage examples for android.text.format Time Time

Introduction

In this page you can find the example usage for android.text.format Time Time.

Prototype

public Time() 

Source Link

Document

Construct a Time object in the default timezone.

Usage

From source file:net.yoik.cordova.plugins.ibeacon.YoikIBeacon.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    final Activity activity = cordova.getActivity();
    final YoikIBeacon that = this;

    this.lastNigh = new Time();
    this.lastNigh.setToNow();

    this.lastFar = new Time();
    this.lastFar.setToNow();
    this.firstNearFar = true;

    cordova.getThreadPool().execute(new Runnable() {
        @Override// w  w w .j av a2s  .c o m
        public void run() {

            iBeaconManager = IBeaconManager.getInstanceForApplication(activity);
            iBeaconManager.bind(that);
        }
    });
}

From source file:com.xandy.calendar.agenda.AgendaFragment.java

public AgendaFragment(long timeMillis, boolean usedForSearch) {
    mInitialTimeMillis = timeMillis;/*from w w  w  . ja v a  2 s  .c  om*/
    mTime = new Time();
    mLastHandledEventTime = new Time();

    if (mInitialTimeMillis == 0) {
        mTime.setToNow();
    } else {
        mTime.set(mInitialTimeMillis);
    }
    mLastHandledEventTime.set(mTime);
    mUsedForSearch = usedForSearch;
}

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.  j a  v a 2  s.co 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:org.cinedroid.tasks.impl.RetrievePerformancesTask.java

/**
 * Removes any times which have passed from the list
 * /*w  w w . j  av  a  2  s . c om*/
 * @param results
 */
private void filterPastDates(final FilmDate filmDate) {
    Time currentTime = new Time();
    currentTime.setToNow();

    Time performanceDate = new Time();
    String date = filmDate.getDate();
    performanceDate.parse(date);

    // Check if the performance date is before the current time. This will only be true in the situation that the filmDate represents
    // the current day, as the cineworld api does not return dates which have passed. If the object is the current date, the film
    // performances need filtering.
    if (currentTime.after(performanceDate)) {
        for (Iterator<FilmPerformance> i = filmDate.getPerformances().iterator(); i.hasNext();) {
            String time = i.next().getTime().replace(":", ""); // Get the time with the : removed.
            performanceDate.parse(String.format("%sT%s00", date, time));
            Log.d(TAG, String.format("Checking %s", performanceDate.format("%d %b %H:%M")));
            if (currentTime.after(performanceDate)) {
                Log.d(TAG, String.format("Removed %s", performanceDate.format("%d %b %H:%M")));
                i.remove();
            }
        }
    }
    Log.d(TAG, String.format("Current Time %s", currentTime.toString()));
}

From source file:com.ingeneo.cordova.plugins.ibeacon.GPIBeacon.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    activity = cordova.getActivity();//www.  j  a  va 2 s  .c  o  m
    final GPIBeacon that = this;

    this.gForeground = true;

    this.lastNigh = new Time();
    this.lastNigh.setToNow();

    this.lastFar = new Time();
    this.lastFar.setToNow();
    this.firstNearFar = true;
    beaconsData = new HashMap<String, JSONObject>();

    cordova.getThreadPool().execute(new Runnable() {
        @Override
        public void run() {

            iBeaconManager = IBeaconManager.getInstanceForApplication(activity);
            iBeaconManager.bind(that);
        }
    });
}

From source file:me.gpelaez.cordova.plugins.ibeacon.GPIBeacon.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    activity = cordova.getActivity();/*from   w w w .ja v  a  2s  . c om*/
    final GPIBeacon that = this;

    this.gForeground = true;

    this.lastNigh = new Time();
    this.lastNigh.setToNow();

    this.lastFar = new Time();
    this.lastFar.setToNow();
    this.firstNearFar = true;
    beaconsData = new Hashtable<String, JSONObject>();

    cordova.getThreadPool().execute(new Runnable() {
        @Override
        public void run() {

            iBeaconManager = IBeaconManager.getInstanceForApplication(activity);
            iBeaconManager.bind(that);
        }
    });
}

From source file:com.samsung.msf.youtubeplayer.client.util.FeedParser.java

public List<Entry> readJson(InputStream stream) {
    List<Entry> entries = new ArrayList<Entry>();

    // NEW Youtube API V3.0
    try {//from   w  w  w. ja  v a 2 s . co m
        // Convert this response into a readable string
        String jsonString = convertToString(stream);

        JSONObject json = new JSONObject(jsonString);

        JSONArray jsonArray = json.getJSONArray("items");
        Log.d(TAG, "readJson jsonArray item count  = " + jsonArray.length());

        // Loop round our JSON list of videos creating Video objects to use within our app
        for (int i = 0; i < jsonArray.length(); i++) {
            long publishedOn = 0;
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            // The title of the video

            String id;
            try {
                id = jsonObject.getJSONObject("id").getString("videoId");
            } catch (JSONException e) {
                continue;
            }

            JSONObject snippet = jsonObject.getJSONObject("snippet");

            String title = snippet.getString("title");
            String uploaded = snippet.getString("publishedAt");
            Log.d(TAG, "id = " + id + ", title = " + title + "uploaded = " + uploaded);
            Time t = new Time();
            t.parse3339(uploaded);
            publishedOn = t.toMillis(false);
            // The url link back to YouTube, this checks if it has a mobile url
            // if it doesnt it gets the standard url
            String url = "";

            JSONObject thumnail = snippet.getJSONObject("thumbnails");
            JSONObject defaultThumnail = thumnail.getJSONObject("default");
            JSONObject highThumnail = thumnail.getJSONObject("high");

            String thumbUrl;
            try {
                thumbUrl = highThumnail.getString("url");
            } catch (JSONException ignore) {
                thumbUrl = defaultThumnail.getString("url");
            }
            Log.d(TAG, "thumbUrl = " + thumbUrl);

            entries.add(new Entry(id, title, url, publishedOn, thumbUrl, 0)); // installed as default false;
        }
    } catch (IOException e) {
        Log.e(TAG, "Feck", e);
    } catch (JSONException e) {
        Log.e(TAG, "Feck", e);
    }
    return entries;
}

From source file:com.dgsd.android.ShiftTracker.Fragment.HoursAndIncomeSummaryFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
    Time time = new Time();
    time.setJulianDay(mJulianDay);//  www.j  ava  2s . c o  m

    switch (id) {
    case LOADER_ID_MONTH: {
        time.month--;
        break;
    }
    case LOADER_ID_3_MONTH: {
        time.month -= 3;
        break;
    }
    case LOADER_ID_6_MONTH: {
        time.month -= 6;
        break;
    }
    case LOADER_ID_9_MONTH: {
        time.month -= 9;
        break;
    }
    case LOADER_ID_YEAR:
        time.year--;
        break;
    }

    time.normalize(true);
    return getLoaderBetween(TimeUtils.getJulianDay(time), mJulianDay);
}

From source file:br.edu.ufcg.supervisor.SupervisorInterface.java

private void saveLogTraining(String content) {
    logString.replaceAll("<br>", "");
    try {//w  ww  .  ja  va  2 s  .co m
        Time time = new Time();
        //String fileName = "supervisorM-"+time.year+time.month+time.weekDay+time.hour+time.minute+time.second+".log";
        @SuppressWarnings("static-access")
        String fileName = "supervisorM-" + time.YEAR + time.MONTH + time.HOUR + time.MINUTE + time.SECOND
                + ".log";
        String folder = Environment.getExternalStorageDirectory().toString() + "/Download/";
        BufferedWriter writer = new BufferedWriter(new FileWriter(folder + fileName));
        writer.write(content);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:net.xisberto.work_schedule.alarm.CountdownService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        if (ACTION_START.equals(intent.getAction())) {
            if (intent.hasExtra(AlarmMessageActivity.EXTRA_PERIOD_ID)) {
                int period_id = intent.getIntExtra(AlarmMessageActivity.EXTRA_PERIOD_ID,
                        R.string.fstp_entrance);
                period = Period.getPeriod(this, period_id);
            } else {
                stopSelf();//  w w w .j  a  v a  2s  .co  m
                return super.onStartCommand(intent, flags, startId);
            }

            long millisInFuture = period.time.getTimeInMillis() - System.currentTimeMillis();
            if (millisInFuture > 0) {

                Intent mainIntent = new Intent(this, MainActivity.class);
                mainIntent.setAction(MainActivity.ACTION_SET_PERIOD);
                mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                Intent deleteIntent = new Intent(this, CountdownService.class);
                deleteIntent.setAction(ACTION_STOP);

                builder = new Builder(this).setSmallIcon(R.drawable.ic_stat_notification)
                        .setContentTitle(getString(period.getLabelId()))
                        .setTicker(getString(period.getLabelId())).setOnlyAlertOnce(true)
                        .setPriority(NotificationCompat.PRIORITY_LOW).setAutoCancel(false)
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setContentIntent(PendingIntent.getActivity(this, period.getId(), mainIntent,
                                PendingIntent.FLAG_CANCEL_CURRENT))
                        .setDeleteIntent(PendingIntent.getService(this, period.getId(), deleteIntent,
                                PendingIntent.FLAG_CANCEL_CURRENT));
                manager = ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE));
                manager.notify(0, builder.build());

                timer = new CountDownTimer(millisInFuture, 1000) {

                    @Override
                    public void onTick(long millisUntilFinished) {
                        Time t = new Time();
                        t.set(millisUntilFinished);
                        builder.setContentText(getString(R.string.time_until_alarm, t.format("%M:%S")));
                        manager.notify(0, builder.build());
                    }

                    @Override
                    public void onFinish() {
                        manager.cancel(0);
                        stopSelf();
                    }
                };

                timer.start();
            }
        } else if (ACTION_STOP_SPECIFIC.equals(intent.getAction())) {
            if (intent.hasExtra(AlarmMessageActivity.EXTRA_PERIOD_ID)) {
                int period_id = intent.getIntExtra(AlarmMessageActivity.EXTRA_PERIOD_ID,
                        R.string.fstp_entrance);
                if (period != null && period.getId() == period_id) {
                    stopAndCancel();
                }
            } else {
                stopSelf();
                return super.onStartCommand(intent, flags, startId);
            }
        } else if (ACTION_STOP.equals(intent.getAction())) {
            stopAndCancel();
        }

    }
    return super.onStartCommand(intent, flags, startId);
}