Search in sources :

Example 66 with Time

use of android.text.format.Time in project Etar-Calendar by Etar-Group.

the class AgendaListView method updatePastEvents.

// Go over all visible views and checks if all past events are grayed out.
// Returns true is there is at least one event that ended and it is not
// grayed out.
private boolean updatePastEvents() {
    int childCount = getChildCount();
    boolean needUpdate = false;
    long now = System.currentTimeMillis();
    Time time = new Time(mTimeZone);
    time.set(now);
    int todayJulianDay = Time.getJulianDay(now, time.gmtoff);
    // Go over views in list
    for (int i = 0; i < childCount; ++i) {
        View listItem = getChildAt(i);
        Object o = listItem.getTag();
        if (o instanceof AgendaByDayAdapter.ViewHolder) {
            // day view - check if day in the past and not grayed yet
            AgendaByDayAdapter.ViewHolder holder = (AgendaByDayAdapter.ViewHolder) o;
            if (holder.julianDay <= todayJulianDay && !holder.grayed) {
                needUpdate = true;
                break;
            }
        } else if (o instanceof AgendaAdapter.ViewHolder) {
            // meeting view - check if event in the past or started already and not grayed yet
            // All day meetings for a day are grayed out
            AgendaAdapter.ViewHolder holder = (AgendaAdapter.ViewHolder) o;
            if (!holder.grayed && ((!holder.allDay && holder.startTimeMilli <= now) || (holder.allDay && holder.julianDay <= todayJulianDay))) {
                needUpdate = true;
                break;
            }
        }
    }
    return needUpdate;
}
Also used : ViewHolder(com.android.calendar.agenda.AgendaAdapter.ViewHolder) ViewHolder(com.android.calendar.agenda.AgendaAdapter.ViewHolder) Time(android.text.format.Time) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 67 with Time

use of android.text.format.Time in project Etar-Calendar by Etar-Group.

the class AlertAdapter method updateView.

public static void updateView(Context context, View view, String eventName, String location, long startMillis, long endMillis, boolean allDay) {
    Resources res = context.getResources();
    TextView titleView = (TextView) view.findViewById(R.id.event_title);
    TextView whenView = (TextView) view.findViewById(R.id.when);
    TextView whereView = (TextView) view.findViewById(R.id.where);
    if (mFirstTime) {
        mPastEventColor = res.getColor(R.color.alert_past_event);
        mTitleColor = res.getColor(R.color.alert_event_title);
        mOtherColor = res.getColor(R.color.alert_event_other);
        mFirstTime = false;
    }
    if (endMillis < System.currentTimeMillis()) {
        titleView.setTextColor(mPastEventColor);
        whenView.setTextColor(mPastEventColor);
        whereView.setTextColor(mPastEventColor);
    } else {
        titleView.setTextColor(mTitleColor);
        whenView.setTextColor(mOtherColor);
        whereView.setTextColor(mOtherColor);
    }
    // What
    if (eventName == null || eventName.length() == 0) {
        eventName = res.getString(R.string.no_title_label);
    }
    titleView.setText(eventName);
    // When
    String when;
    int flags;
    String tz = Utils.getTimeZone(context, null);
    if (allDay) {
        flags = DateUtils.FORMAT_UTC | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_DATE;
        tz = Time.TIMEZONE_UTC;
    } else {
        flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE;
    }
    if (DateFormat.is24HourFormat(context)) {
        flags |= DateUtils.FORMAT_24HOUR;
    }
    Time time = new Time(tz);
    time.set(startMillis);
    boolean isDST = time.isDst != 0;
    StringBuilder sb = new StringBuilder(Utils.formatDateRange(context, startMillis, endMillis, flags));
    if (!allDay && tz != Time.getCurrentTimezone()) {
        sb.append(" ").append(TimeZone.getTimeZone(tz).getDisplayName(isDST, TimeZone.SHORT, Locale.getDefault()));
    }
    when = sb.toString();
    whenView.setText(when);
    // Where
    if (location == null || location.length() == 0) {
        whereView.setVisibility(View.GONE);
    } else {
        whereView.setText(location);
        whereView.setVisibility(View.VISIBLE);
    }
}
Also used : TextView(android.widget.TextView) Time(android.text.format.Time) Resources(android.content.res.Resources)

Example 68 with Time

use of android.text.format.Time in project Etar-Calendar by Etar-Group.

the class CalendarToolbarHandler method buildDayOfWeek.

// Builds a string with the day of the week and the word yesterday/today/tomorrow
// before it if applicable.
private String buildDayOfWeek() {
    Time t = new Time(mTimeZone);
    t.set(mMilliTime);
    long julianDay = Time.getJulianDay(mMilliTime, t.gmtoff);
    String dayOfWeek;
    mStringBuilder.setLength(0);
    if (julianDay == mTodayJulianDay) {
        dayOfWeek = mContext.getString(R.string.agenda_today, DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime, DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString());
    } else if (julianDay == mTodayJulianDay - 1) {
        dayOfWeek = mContext.getString(R.string.agenda_yesterday, DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime, DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString());
    } else if (julianDay == mTodayJulianDay + 1) {
        dayOfWeek = mContext.getString(R.string.agenda_tomorrow, DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime, DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString());
    } else {
        dayOfWeek = DateUtils.formatDateRange(mContext, mFormatter, mMilliTime, mMilliTime, DateUtils.FORMAT_SHOW_WEEKDAY, mTimeZone).toString();
    }
    return dayOfWeek;
}
Also used : Time(android.text.format.Time)

Example 69 with Time

use of android.text.format.Time in project Etar-Calendar by Etar-Group.

the class CalendarViewAdapter method setMidnightHandler.

// Sets a thread to run 1 second after midnight and update the current date
// This is used to display correctly the date of yesterday/today/tomorrow
private void setMidnightHandler() {
    mMidnightHandler.removeCallbacks(mTimeUpdater);
    // Set the time updater to run at 1 second after midnight
    long now = System.currentTimeMillis();
    Time time = new Time(mTimeZone);
    time.set(now);
    long runInMillis = (24 * 3600 - time.hour * 3600 - time.minute * 60 - time.second + 1) * 1000;
    mMidnightHandler.postDelayed(mTimeUpdater, runInMillis);
}
Also used : Time(android.text.format.Time)

Example 70 with Time

use of android.text.format.Time in project Etar-Calendar by Etar-Group.

the class CalendarViewAdapter method buildWeekDate.

private String buildWeekDate() {
    // Calculate the start of the week, taking into account the "first day of the week"
    // setting.
    Time t = new Time(mTimeZone);
    t.set(mMilliTime);
    int firstDayOfWeek = Utils.getFirstDayOfWeek(mContext);
    int dayOfWeek = t.weekDay;
    int diff = dayOfWeek - firstDayOfWeek;
    if (diff != 0) {
        if (diff < 0) {
            diff += 7;
        }
        t.monthDay -= diff;
        t.normalize(true);
    }
    long weekStartTime = t.toMillis(true);
    // The end of the week is 6 days after the start of the week
    long weekEndTime = weekStartTime + DateUtils.WEEK_IN_MILLIS - DateUtils.DAY_IN_MILLIS;
    // If week start and end is in 2 different months, use short months names
    Time t1 = new Time(mTimeZone);
    t1.set(weekEndTime);
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR;
    if (t.month != t1.month) {
        flags |= DateUtils.FORMAT_ABBREV_MONTH;
    }
    mStringBuilder.setLength(0);
    String date = DateUtils.formatDateRange(mContext, mFormatter, weekStartTime, weekEndTime, flags, mTimeZone).toString();
    return date;
}
Also used : Time(android.text.format.Time)

Aggregations

Time (android.text.format.Time)395 SmallTest (android.test.suitebuilder.annotation.SmallTest)97 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)23 Date (java.util.Date)21 NetworkPolicy (android.net.NetworkPolicy)16 TrustedTime (android.util.TrustedTime)16 TextView (android.widget.TextView)15 Bundle (android.os.Bundle)13 TimeFormatException (android.util.TimeFormatException)13 Suppress (android.test.suitebuilder.annotation.Suppress)12 View (android.view.View)12 Paint (android.graphics.Paint)11 IOException (java.io.IOException)11 Matcher (java.util.regex.Matcher)9 IntentFilter (android.content.IntentFilter)7 File (java.io.File)7 DateFormat (java.text.DateFormat)7 SimpleDateFormat (java.text.SimpleDateFormat)7 ContentValues (android.content.ContentValues)6