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.example.cal.mysunshine.Utility.java

/**
 * Helper method to convert the database representation of the date into something to display
 * to users.  As classy and polished a user experience as "20140102" is, we can do better.
 *
 * @param context Context to use for resource localization
 * @param dateInMillis The date in milliseconds
 * @return a user-friendly representation of the date.
 *//*from w  ww .j av a2s.c  om*/
public static String getFriendlyDayString(Context context, long dateInMillis) {
    // The day string for forecast uses the following logic:
    // For today: "Today, June 8"
    // For tomorrow:  "Tomorrow"
    // For the next 5 days: "Wednesday" (just the day name)
    // For all days after that: "Mon Jun 8"

    Time time = new Time();
    time.setToNow();
    long currentTime = System.currentTimeMillis();
    int julianDay = Time.getJulianDay(dateInMillis, time.gmtoff);
    int currentJulianDay = Time.getJulianDay(currentTime, time.gmtoff);

    // If the date we're building the String for is today's date, the format
    // is "Today, June 24"
    if (julianDay == currentJulianDay) {
        String today = context.getString(R.string.today);
        int formatId = R.string.format_full_friendly_date;
        return String.format(context.getString(formatId), today, getFormattedMonthDay(context, dateInMillis));
    } else if (julianDay < currentJulianDay + 7) {
        // If the input date is less than a week in the future, just return the day name.
        return getDayName(context, dateInMillis);
    } else {
        // Otherwise, use the form "Mon Jun 3"
        SimpleDateFormat shortenedDateFormat = new SimpleDateFormat("EEE MMM dd");
        return shortenedDateFormat.format(dateInMillis);
    }
}

From source file:Main.java

/***
 * Fetch the raw estimated time enroute given the input parameters
 * @param distance - how far to the target
 * @param speed - how fast we are moving
 * @param calculated - already calculated value
 * @param calc - or should I calculate?//from  w  ww  .  j  av a  2s .  c  o  m
 * @return int value of HR * 100 + MIN for the ete, -1 if not applicable
 */
private static Time fetchRawEte(double distance, double speed, long calculated, boolean calc) {

    double eteTotal = calculated;
    if (calc) {
        // Calculate the travel time in seconds
        eteTotal = (distance / speed) * 3600;
    }

    // Allocate an empty time object
    Time ete = new Time();

    // Extract the hours
    ete.hour = (int) (eteTotal / 3600); // take whole int value as the hours
    eteTotal -= (ete.hour * 3600); // Remove the hours that we extracted

    // Convert what's left to fractional minutes
    ete.minute = (int) (eteTotal / 60); // Get the int value as the minutes now
    eteTotal -= (ete.minute * 60); // remove the minutes we just extracted

    // What's left is the remaining seconds 
    ete.second = Math.round((int) eteTotal); // round as appropriate

    // Account for the seconds being 60
    if (ete.second >= 60) {
        ete.minute++;
        ete.second -= 60;
    }

    // account for the minutes being 60
    if (ete.minute >= 60) {
        ete.hour++;
        ete.minute -= 60;
    }

    // Time object is good to go now
    return ete;
}

From source file:org.gnucash.android.ui.util.RecurrenceViewClickListener.java

@Override
public void onClick(View v) {
    FragmentManager fm = mActivity.getSupportFragmentManager();
    Bundle b = new Bundle();
    Time t = new Time();
    t.setToNow();/*from   w w w.  jav  a 2 s  . co  m*/
    b.putLong(RecurrencePickerDialogFragment.BUNDLE_START_TIME_MILLIS, t.toMillis(false));
    b.putString(RecurrencePickerDialogFragment.BUNDLE_TIME_ZONE, t.timezone);

    // may be more efficient to serialize and pass in EventRecurrence
    b.putString(RecurrencePickerDialogFragment.BUNDLE_RRULE, mRecurrenceRule);

    RecurrencePickerDialogFragment rpd = (RecurrencePickerDialogFragment) fm
            .findFragmentByTag(FRAGMENT_TAG_RECURRENCE_PICKER);
    if (rpd != null) {
        rpd.dismiss();
    }
    rpd = new RecurrencePickerDialogFragment();
    rpd.setArguments(b);
    rpd.setOnRecurrenceSetListener(mRecurrenceSetListener);
    rpd.show(fm, FRAGMENT_TAG_RECURRENCE_PICKER);
}

From source file:com.joeyturczak.jtscanner.utils.Utility.java

public static long normalizeDate(long startDate) {
    // normalize the start date to the beginning of the (UTC) day
    Time time = new Time();
    time.set(startDate);/*www  . ja  va  2 s  . c  o m*/
    int julianDay = Time.getJulianDay(startDate, time.gmtoff);
    return time.setJulianDay(julianDay);
}

From source file:com.granita.tasks.groupings.BaseTaskViewDescriptor.java

protected void setDueDate(TextView view, ImageView dueIcon, Time dueDate, boolean isClosed) {
    if (view != null && dueDate != null) {
        Time now = mNow;//www . j  a  v a2s .co  m
        if (now == null) {
            now = mNow = new Time();
        }
        if (!now.timezone.equals(TimeZone.getDefault().getID())) {
            now.clear(TimeZone.getDefault().getID());
        }

        if (Math.abs(now.toMillis(false) - System.currentTimeMillis()) > 5000) {
            now.setToNow();
            now.normalize(true);
        }

        dueDate.normalize(true);

        view.setText(new DateFormatter(view.getContext()).format(dueDate, now, DateFormatContext.LIST_VIEW));
        if (dueIcon != null) {
            dueIcon.setVisibility(View.VISIBLE);
        }

        // highlight overdue dates & times, handle allDay tasks separately
        if ((!dueDate.allDay && dueDate.before(now) || dueDate.allDay
                && (dueDate.year < now.year || dueDate.yearDay <= now.yearDay && dueDate.year == now.year))
                && !isClosed) {
            view.setTextAppearance(view.getContext(), R.style.task_list_overdue_text);
        } else {
            view.setTextAppearance(view.getContext(), R.style.task_list_due_text);
        }
    } else if (view != null) {
        view.setText("");
        if (dueIcon != null) {
            dueIcon.setVisibility(View.GONE);
        }
    }
}

From source file:com.dgsd.android.ShiftTracker.Adapter.WeekPagerAdapter.java

public WeekPagerAdapter(Context context, FragmentManager fm, int weekContainingJulianDay) {
    super(fm);/*from   w ww .  j av a 2  s  .com*/
    mContext = context;
    mTime = new Time();
    mStringBuilder = new StringBuilder();
    mFormatter = new Formatter(mStringBuilder);

    SharedPreferences p = context.getSharedPreferences(Const.SHARED_PREFS_NAME, Context.MODE_PRIVATE);
    String startDayAsStr = p.getString(context.getString(R.string.settings_key_start_day), "1");
    mWeekStartDay = Integer.valueOf(startDayAsStr);

    mCenterJulianDay = adjustJulianDay(mWeekStartDay, weekContainingJulianDay);
}

From source file:com.markupartist.sthlmtraveling.provider.planner.JourneyQuery.java

public JourneyQuery(Parcel parcel) {
    origin = parcel.readParcelable(Location.class.getClassLoader());
    destination = parcel.readParcelable(Location.class.getClassLoader());
    via = parcel.readParcelable(Location.class.getClassLoader());
    time = new Time();
    time.parse(parcel.readString());// w w w .j  a va2s . com
    isTimeDeparture = (parcel.readInt() == 1) ? true : false;
    alternativeStops = (parcel.readInt() == 1) ? true : false;
    transportModes = new ArrayList<String>();
    parcel.readStringList(transportModes);
    ident = parcel.readString();
    seqnr = parcel.readString();
}

From source file:com.cloudkick.monitoring.CheckState.java

public CheckState(JSONObject state) throws JSONException {
    // Grab the "whence" if available
    if (state.has("whence")) {
        whenceWireFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        whenceWireFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
        String whenceString = state.getString("whence");
        try {/*from  w  ww. ja  v  a2s.  c  om*/
            long whenceMillis = whenceWireFormat.parse(whenceString).getTime();
            Time now = new Time();
            now.setToNow();
            long diffMillis = ((now.toMillis(true)) - whenceMillis);
            if (whenceMillis == 0) {
                whence = "never";
            } else if (diffMillis < 3600 * 1000) {
                whence = String.format("%d m", diffMillis / (1000 * 60));
            } else if (diffMillis < (24 * 3600 * 1000)) {
                long mins = (diffMillis / (1000 * 60)) % 60;
                long hours = (diffMillis / (1000 * 3600));
                whence = String.format("%d h, %d m", hours, mins);
            } else if (diffMillis < (7 * 24 * 3600 * 1000)) {
                long hours = (diffMillis / (1000 * 60 * 60)) % 24;
                long days = (diffMillis / (1000 * 60 * 60 * 24));
                whence = String.format("%d d, %d h", days, hours);
            } else {
                long days = (diffMillis / (1000 * 60 * 60 * 24)) % 7;
                long weeks = (diffMillis / (1000 * 60 * 60 * 24 * 7));
                whence = String.format("%d w, %d d", weeks, days);
            }
        } catch (ParseException e) {
            whence = null;
        }
    } else {
        whence = null;
    }

    // Grab the "service_state" if available
    if (state.has("service_state")) {
        serviceState = state.getString("service_state");
    } else {
        serviceState = "UNKNOWN";
    }

    // Depending on the serviceState set the status and color
    if (serviceState.equals("OK")) {
        status = state.getString("status");
        stateColor = 0xFF088A08;
        stateSymbol = "\u2714";
        priority = 4;
    } else if (serviceState.equals("ERROR")) {
        status = state.getString("status");
        stateColor = 0xFFE34648;
        stateSymbol = "\u2718";
        priority = 0;
    } else if (serviceState.equals("WARNING")) {
        status = state.getString("status");
        stateColor = 0xFFDF7401;
        stateSymbol = "!";
        priority = 1;
    } else if (serviceState.equals("NO-AGENT")) {
        status = "Agent Not Connected";
        stateColor = 0xFF6E6E6E;
        stateSymbol = "?";
        priority = 2;
    } else if (serviceState.equals("UNKNOWN")) {
        status = "No Data Available";
        stateColor = 0xFF6E6E6E;
        stateSymbol = "?";
        priority = 3;
    } else {
        Log.e("Check", "Unknown Service State: " + serviceState);
        status = state.getString("status");
        stateColor = 0xFF6E6E6E;
        stateSymbol = "?";
        priority = 3;
    }
}

From source file:com.dgsd.android.ShiftTracker.Adapter.MonthPagerAdapter.java

public MonthPagerAdapter(Context context, FragmentManager fm, int monthContainingJulianDay) {
    super(fm);//from w w  w . ja  v a 2 s . c om
    mContext = context;
    mTime = new Time();
    mCenterJulianDay = monthContainingJulianDay;
}

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))
    // {/*from  w  w  w.j a  v a  2 s. co  m*/
    // 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);
}