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:com.android.calendar.agenda.AgendaFragment.java

public AgendaFragment(long timeMillis, boolean usedForSearch, boolean inShareMode) {
    mInitialTimeMillis = timeMillis;//from ww  w .java 2s .  c  om
    mTime = new Time();
    mLastHandledEventTime = new Time();

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

From source file:org.mozilla.gecko.FilePickerResultHandler.java

public String generateImageName() {
    Time now = new Time();
    now.setToNow();//from  w w  w . ja  va2s .c  o m
    mImageName = now.format("%Y-%m-%d %H.%M.%S") + ".jpg";
    return mImageName;
}

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();/*from  w  w w  . j  ava 2 s  .  c  o  m*/
    Log.e("toMillis", Long.toString(now.toMillis(true)));
    editor.putLong("lastCheck", now.toMillis(true));
    editor.commit();
}

From source file:com.demo.digit_dayview.EventResourceFromJson.java

@Override
public List<Event> get(int startJulianDay, int numDays, Predicate continueLoading) {

    // Get the data from our separate thread
    try {/*from w w w .  jav a  2 s  .com*/
        new RetrieveFromJSON().execute().get();
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ExecutionException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // Debug statements
    /*
    Log.d("event array", event_name_list.toString());
    Log.d("start times", start_time_list.toString());
    Log.d("end times", end_time_list.toString());
            
    Log.d("test", event_name_list.get(0));
    Log.d("test2", start_time_list.get(2));
            
    Log.d("sizeof array", "size: " + event_name_list.size());
    */

    List<Event> events = Lists.newArrayList();

    int startHours, endHours, startMinutes, endMinutes;

    for (int i = 0; i < numDays; i++) {

        // Make new time for the day
        Time scratch = new Time();
        Event e;

        // Start adding the list of events from JSON
        for (int j = 0; j < event_name_list.size(); j++) {

            // Create the event
            e = new Event();

            e.setAllDay(false);
            e.setEndDay(startJulianDay + i);
            e.setId(j + 1L);

            // Calculating the height of event by time
            Double endTime = Double.parseDouble(end_time_list.get(j));
            Double startTime = Double.parseDouble(start_time_list.get(j));

            // Check whether or not there is a dot character
            // first for end time, then for start time
            if (end_time_list.get(j).contains(".")) {
                String[] time = end_time_list.get(j).split("\\.");

                // Make into hours and minutes from the time array
                endHours = Integer.parseInt(time[0]);
                endMinutes = Integer.parseInt(time[1]);

                // Append . in minutes
                String myMinute = "." + endMinutes;

                // Parse the minute string
                Double calculatedMinute = Double.parseDouble(myMinute) * 60;
                //Log.d("the end time", "j:" + j + " " + (int) (endHours * 60 + calculatedMinute));

                // Set the end time from the minutes and hours
                e.setEndTime((int) (endHours * 60 + calculatedMinute));
            } else {
                endHours = Integer.parseInt(end_time_list.get(j));
                e.setEndTime(endHours * 60 - 1);
                //Log.d("the end time without min", "j:" + j + " " + (endHours * 60));
            }

            e.setStartDay(startJulianDay + i);

            if (start_time_list.get(j).contains(".")) {
                // Same idea as above in check list
                String[] time = start_time_list.get(j).split("\\.");

                startHours = Integer.parseInt(time[0]);
                startMinutes = Integer.parseInt(time[1]);

                String myMinute = "." + startMinutes;

                Double calculatedMinute = Double.parseDouble(myMinute) * 60;

                e.setStartTime((int) (startHours * 60 + calculatedMinute));
                //Log.d("the start time (Y-coord)", "j:" + j + " " + (int) (startHours * 60 + calculatedMinute));
            } else {
                startHours = Integer.parseInt(start_time_list.get(j));
                e.setStartTime(startHours * 60);
                //Log.d("the start time without min (Y-coord)", "j:" + j + " " + (startHours * 60));
            }

            Log.d("Y coordinate in time", start_time_list.get(j));

            e.setColor(randomColour());

            // At the first event of the day, start the day
            if (j == 0)
                scratch.setJulianDay(startJulianDay + i);

            // Allocate the times
            scratch.hour = startHours;
            scratch.minute = e.getStartTime() % 60;
            e.setStartMillis(scratch.toMillis(false));
            scratch.hour = endHours;
            scratch.minute = e.getEndTime() % 60;
            e.setEndMillis(scratch.toMillis(false));

            Log.d("height in time", ("" + (endTime - startTime)));

            e.setTitle(event_name_list.get(j));
            //Log.d("event name", event_name_list.get(j));
            events.add(e);

        }
    }

    Collections.sort(events, new Comparator<Event>() {

        @Override
        public int compare(Event lhs, Event rhs) {
            long l = lhs.getStartMillis() - rhs.getStartMillis();
            if (l < 0) {
                return -1;
            } else if (l > 0) {
                return 1;
            } else
                return 0;
        }
    });

    return events;

}

From source file:com.catchnotes.api.CatchNotesXmlParser.java

public CatchNotesXmlParser() {
    try {/*from w ww  .j av a  2 s  . com*/
        if (Integer.parseInt(Build.VERSION.SDK) >= Build.VERSION_CODES.ECLAIR_0_1) {
            // We can use Time & TimeFormatException on Android 2.0.1
            // (API level 6) or greater. It crashes the VM otherwise.
            timestamper = new Time();
        }
    } catch (Exception e) {
    }
}

From source file:net.networksaremadeofstring.rhybudd.ZenossAPI.java

public static boolean shouldRefresh(Context mContext) {
    Time now = new Time();
    now.setToNow();//  w ww  .  j  a v a2 s  .  c  om

    if ((now.toMillis(true) - PreferenceManager.getDefaultSharedPreferences(mContext).getLong("lastCheck",
            now.toMillis(true))) > 900000) {
        return true;
    } else {
        return false;
    }
}

From source file:com.socialdisasters.other.MessageAdapter.java

public static String formatTimeStampString(Context context, long when, boolean fullFormat) {
    Time then = new Time();
    then.set(when);//from  w  w w  . ja va  2  s  . com
    Time now = new Time();
    now.setToNow();

    // Basic settings for formatDateTime() we want for all cases.
    int format_flags = DateUtils.FORMAT_ABBREV_ALL;

    // If the message is from a different year, show the date and year.
    if (then.year != now.year) {
        format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        // If it is from a different day than today, show only the date.
        format_flags |= DateUtils.FORMAT_SHOW_DATE;
    } else {
        // Otherwise, if the message is from today, show the time.
        format_flags |= DateUtils.FORMAT_SHOW_TIME;
    }

    // If the caller has asked for full details, make sure to show the date
    // and time no matter what we've determined above (but still make showing
    // the year only happen if it is a different year from today).
    if (fullFormat) {
        format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
    }

    return DateUtils.formatDateTime(context, when, format_flags);
}

From source file:com.tdispatch.passenger.model.BookingData.java

public BookingData setPickupDate(String stamp) {
    // date is RFC 3339
    Time time = new Time();
    time.parse3339(stamp);//from   w  w  w . j  a v a  2 s  .c  o  m

    mPickupDateString = stamp;
    mPickupDate = new Date(time.toMillis(false));

    return this;
}

From source file:com.wso2.mobile.mdm.services.Operation.java

public Operation(Context context, int mode, Intent intent) {
    this.context = context;
    this.intent = intent;
    this.mode = mode;

    logger = new LoggerCustom(context);
    Time now = new Time();
    now.setToNow();/*from  www. j  av  a 2  s  .  c o m*/
    String log_in = logger.readFileAsString("wso2log.txt");
    String to_write = "";
    if (CommonUtilities.DEBUG_MODE_ENABLED) {
        if (log_in != null && !log_in.equals("") && !log_in.equals("null")) {
            to_write = "<br> SERVER TO AGENT AT " + now.hour + ":" + now.minute + " : <br> CODE : "
                    + intent.getStringExtra("message").trim() + "<br> MSG ID : "
                    + intent.getStringExtra("token").trim() + "<br> DATA : " + intent.getStringExtra("data")
                    + "<br>==========================================================<br>" + log_in;
        } else {
            to_write = "<br> SERVER TO AGENT AT " + now.hour + ":" + now.minute + ": <br> CODE : "
                    + intent.getStringExtra("message").trim() + "<br> MSG ID : "
                    + intent.getStringExtra("token").trim() + "<br> DATA : " + intent.getStringExtra("data")
                    + "<br>==========================================================<br>";
        }

        logger.writeStringAsFile(to_write, "wso2log.txt");
    }

    if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_MONITOR)) {
        policy_token = intent.getStringExtra("token").trim();
        policy_code = intent.getStringExtra("message").trim();
        Log.v("Token", policy_token);
    } else {
        token = intent.getStringExtra("token").trim();
        code = intent.getStringExtra("message").trim();
        Log.v("Code", code);
        Log.v("Token", token);
    }

    if (intent.getStringExtra("data") != null) {
        data = intent.getStringExtra("data");
        Log.v("Data", data);
    }

    if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_BUNDLE)) {
        try {
            SharedPreferences mainPrefp = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
            Editor editorp = mainPrefp.edit();
            editorp.putString("policy", "");
            editorp.commit();

            SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
            Editor editor = mainPref.edit();
            editor.putString("policy", data);
            editor.commit();

            /*if (mainPref.getString("policy_applied", "") == null
                  || mainPref.getString("policy_applied", "").trim()
                .equals("0")
                  || mainPref.getString("policy_applied", "").trim()
                .equals("")) {*/
            executePolicy();
            //}
            /*
             * JSONArray jArray = new JSONArray(data); for(int i = 0;
             * i<jArray.length(); i++){ JSONObject policyObj =
             * (JSONObject)jArray.getJSONObject(i);
             * if(policyObj.getString("data")!=null &&
             * policyObj.getString("data")!=""){
             * doTask(policyObj.getString("code"),
             * policyObj.getString("data"), REQUEST_MODE_BUNDLE); } }
             * doTask(code, "", REQUEST_MODE_NORMAL);
             */
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_MONITOR)) {
        doTask(policy_code, data, REQUEST_MODE_NORMAL);
    } else {
        doTask(code, data, REQUEST_MODE_NORMAL);
    }

}

From source file:org.wso2.cdm.agent.services.Operation.java

public Operation(Context context, int mode, Intent intent) {
    this.context = context;
    this.intent = intent;
    this.mode = mode;

    if (CommonUtilities.DEBUG_MODE_ENABLED) {
        logger = new LoggerCustom(context);
        Time now = new Time();
        now.setToNow();/*  w ww  . j  a v a 2s.  c o  m*/
        String log_in = logger.readFileAsString("wso2log.txt");
        String to_write = "";

        if (log_in != null && !log_in.equals("") && !log_in.equals("null")) {
            to_write = "<br> SERVER TO AGENT AT " + now.hour + ":" + now.minute + " : <br> CODE : "
                    + intent.getStringExtra("message").trim() + "<br> MSG ID : "
                    + intent.getStringExtra("token").trim() + "<br> DATA : " + intent.getStringExtra("data")
                    + "<br>==========================================================<br>" + log_in;
        } else {
            to_write = "<br> SERVER TO AGENT AT " + now.hour + ":" + now.minute + ": <br> CODE : "
                    + intent.getStringExtra("message").trim() + "<br> MSG ID : "
                    + intent.getStringExtra("token").trim() + "<br> DATA : " + intent.getStringExtra("data")
                    + "<br>==========================================================<br>";
        }
        logger.writeStringAsFile(to_write, "wso2log.txt");
    }

    if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_MONITOR)) {
        policy_token = intent.getStringExtra("token").trim();
        policy_code = intent.getStringExtra("message").trim();
        Log.v("Token", policy_token);
    } else {
        token = intent.getStringExtra("token").trim();
        code = intent.getStringExtra("message").trim();
        Log.v("Code", code);
        Log.v("Token", token);
    }

    if (intent.getStringExtra("data") != null) {
        data = intent.getStringExtra("data");
        Log.v("Data", data);
    }

    if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_BUNDLE)) {
        try {
            SharedPreferences mainPrefp = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
            Editor editorp = mainPrefp.edit();
            editorp.putString("policy", "");
            editorp.commit();

            SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
            Editor editor = mainPref.edit();
            editor.putString("policy", data);
            editor.commit();

            /*if (mainPref.getString("policy_applied", "") == null
                  || mainPref.getString("policy_applied", "").trim()
                .equals("0")
                  || mainPref.getString("policy_applied", "").trim()
                .equals("")) {*/
            //executePolicy();
            //}
            /*
             * JSONArray jArray = new JSONArray(data); for(int i = 0;
             * i<jArray.length(); i++){ JSONObject policyObj =
             * (JSONObject)jArray.getJSONObject(i);
             * if(policyObj.getString("data")!=null &&
             * policyObj.getString("data")!=""){
             * doTask(policyObj.getString("code"),
             * policyObj.getString("data"), REQUEST_MODE_BUNDLE); } }
             * doTask(code, "", REQUEST_MODE_NORMAL);
             */
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else if (intent.getStringExtra("message").trim().equals(CommonUtilities.OPERATION_POLICY_MONITOR)) {
        doTask(policy_code, data, REQUEST_MODE_NORMAL);
    } else {
        doTask(code, data, REQUEST_MODE_NORMAL);
    }

}