Example usage for android.text.format Time set

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

Introduction

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

Prototype

public void set(Time that) 

Source Link

Document

Copy the value of that to this Time object.

Usage

From source file:com.android.mms.ui.MessageUtils.java

public static String formatTimeStampStringExtend(Context context, long when) {
    Time then = new Time();
    then.set(when);
    Time now = new Time();
    now.setToNow();//  www  . ja va 2 s .c  o m

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

    // 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.
        if ((now.yearDay - then.yearDay) == 1) {
            return context.getString(R.string.str_ipmsg_yesterday);
        } else {
            format_flags |= DateUtils.FORMAT_SHOW_DATE;
        }
    } else if ((now.toMillis(false) - then.toMillis(false)) < 60000) {
        return context.getString(R.string.time_now);
    } else {
        // Otherwise, if the message is from today, show the time.
        format_flags |= DateUtils.FORMAT_SHOW_TIME;
    }
    sOpMessageUtilsExt.formatTimeStampStringExtend(context, when, format_flags);
    return DateUtils.formatDateTime(context, when, format_flags);
}

From source file:com.android.mms.ui.MessageUtils.java

public static String formatTimeStampString(Context context, long when, boolean fullFormat) {
    Time then = new Time();
    then.set(when);
    Time now = new Time();
    now.setToNow();//from   w  w w  . j a  v a2 s.  c  o m

    // Basic settings for formatDateTime() we want for all cases.
    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT |
    /// M: Fix ALPS00419488 to show 12:00, so mark DateUtils.FORMAT_ABBREV_ALL
    //DateUtils.FORMAT_ABBREV_ALL |
            DateUtils.FORMAT_CAP_AMPM;

    // 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);
    }

    String dateTime = sOpMessageUtilsExt.formatTimeStampString(context, when, format_flags);
    if (dateTime != null) {
        return dateTime;
    }
    return DateUtils.formatDateTime(context, when, format_flags);
}

From source file:com.android.calendar.EventInfoFragment.java

private void updateEvent(View view) {
    if (mEventCursor == null || view == null) {
        return;// w w  w  .  j a va 2 s  .c  o  m
    }

    Context context = view.getContext();
    if (context == null) {
        return;
    }

    String eventName = mEventCursor.getString(EVENT_INDEX_TITLE);
    if (eventName == null || eventName.length() == 0) {
        eventName = getActivity().getString(R.string.no_title_label);
    }

    // 3rd parties might not have specified the start/end time when firing the
    // Events.CONTENT_URI intent.  Update these with values read from the db.
    if (mStartMillis == 0 && mEndMillis == 0) {
        mStartMillis = mEventCursor.getLong(EVENT_INDEX_DTSTART);
        mEndMillis = mEventCursor.getLong(EVENT_INDEX_DTEND);
        if (mEndMillis == 0) {
            String duration = mEventCursor.getString(EVENT_INDEX_DURATION);
            if (!TextUtils.isEmpty(duration)) {
                try {
                    Duration d = new Duration();
                    d.parse(duration);
                    long endMillis = mStartMillis + d.getMillis();
                    if (endMillis >= mStartMillis) {
                        mEndMillis = endMillis;
                    } else {
                        Log.d(TAG, "Invalid duration string: " + duration);
                    }
                } catch (DateException e) {
                    Log.d(TAG, "Error parsing duration string " + duration, e);
                }
            }
            if (mEndMillis == 0) {
                mEndMillis = mStartMillis;
            }
        }
    }

    mAllDay = mEventCursor.getInt(EVENT_INDEX_ALL_DAY) != 0;
    String location = mEventCursor.getString(EVENT_INDEX_EVENT_LOCATION);
    String description = mEventCursor.getString(EVENT_INDEX_DESCRIPTION);
    String rRule = mEventCursor.getString(EVENT_INDEX_RRULE);
    String eventTimezone = mEventCursor.getString(EVENT_INDEX_EVENT_TIMEZONE);

    mHeadlines.setBackgroundColor(mCurrentColor);

    // What
    if (eventName != null) {
        setTextCommon(view, R.id.title, eventName);
    }

    // When
    // Set the date and repeats (if any)
    String localTimezone = Utils.getTimeZone(mActivity, mTZUpdater);

    Resources resources = context.getResources();
    String displayedDatetime = Utils.getDisplayedDatetime(mStartMillis, mEndMillis, System.currentTimeMillis(),
            localTimezone, mAllDay, context);

    String displayedTimezone = null;
    if (!mAllDay) {
        displayedTimezone = Utils.getDisplayedTimezone(mStartMillis, localTimezone, eventTimezone);
    }
    // Display the datetime.  Make the timezone (if any) transparent.
    if (displayedTimezone == null) {
        setTextCommon(view, R.id.when_datetime, displayedDatetime);
    } else {
        int timezoneIndex = displayedDatetime.length();
        displayedDatetime += "  " + displayedTimezone;
        SpannableStringBuilder sb = new SpannableStringBuilder(displayedDatetime);
        ForegroundColorSpan transparentColorSpan = new ForegroundColorSpan(
                resources.getColor(R.color.event_info_headline_transparent_color));
        sb.setSpan(transparentColorSpan, timezoneIndex, displayedDatetime.length(),
                Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        setTextCommon(view, R.id.when_datetime, sb);
    }

    // Display the repeat string (if any)
    String repeatString = null;
    if (!TextUtils.isEmpty(rRule)) {
        EventRecurrence eventRecurrence = new EventRecurrence();
        eventRecurrence.parse(rRule);
        Time date = new Time(localTimezone);
        date.set(mStartMillis);
        if (mAllDay) {
            date.timezone = Time.TIMEZONE_UTC;
        }
        eventRecurrence.setStartDate(date);
        repeatString = EventRecurrenceFormatter.getRepeatString(mContext, resources, eventRecurrence, true);
    }
    if (repeatString == null) {
        view.findViewById(R.id.when_repeat).setVisibility(View.GONE);
    } else {
        setTextCommon(view, R.id.when_repeat, repeatString);
    }

    // Organizer view is setup in the updateCalendar method

    // Where
    if (location == null || location.trim().length() == 0) {
        setVisibilityCommon(view, R.id.where, View.GONE);
    } else {
        final TextView textView = mWhere;
        if (textView != null) {
            textView.setAutoLinkMask(0);
            textView.setText(location.trim());
            try {
                textView.setText(Utils.extendedLinkify(textView.getText().toString(), true));

                // Linkify.addLinks() sets the TextView movement method if it finds any links.
                // We must do the same here, in case linkify by itself did not find any.
                // (This is cloned from Linkify.addLinkMovementMethod().)
                MovementMethod mm = textView.getMovementMethod();
                if ((mm == null) || !(mm instanceof LinkMovementMethod)) {
                    if (textView.getLinksClickable()) {
                        textView.setMovementMethod(LinkMovementMethod.getInstance());
                    }
                }
            } catch (Exception ex) {
                // unexpected
                Log.e(TAG, "Linkification failed", ex);
            }

            textView.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    try {
                        return v.onTouchEvent(event);
                    } catch (ActivityNotFoundException e) {
                        // ignore
                        return true;
                    }
                }
            });
        }
    }

    // Description
    if (description != null && description.length() != 0) {
        mDesc.setText(description);
    }

    // Launch Custom App
    if (Utils.isJellybeanOrLater()) {
        updateCustomAppButton();
    }
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private boolean initNextView(int deltaX) {
    // Change the view to the previous day or week
    DayView view = (DayView) mViewSwitcher.getNextView();
    Time date = view.mBaseDate;
    date.set(mBaseDate);
    boolean switchForward;
    if (deltaX > 0) {
        date.monthDay -= mNumDays;/* ww  w.  j av  a  2  s.c  o  m*/
        view.setSelectedDay(mSelectionDay - mNumDays);
        switchForward = false;
    } else {
        date.monthDay += mNumDays;
        view.setSelectedDay(mSelectionDay + mNumDays);
        switchForward = true;
    }
    date.normalize(true /* ignore isDst */);
    initView(view);
    view.layout(getLeft(), getTop(), getRight(), getBottom());
    view.reloadEvents();
    return switchForward;
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private View switchViews(boolean forward, float xOffSet, float width, float velocity) {
    mAnimationDistance = width - xOffSet;

    float progress = Math.abs(xOffSet) / width;
    if (progress > 1.0f) {
        progress = 1.0f;//  w w  w  .jav  a 2  s  . co m
    }

    float inFromXValue, inToXValue;
    float outFromXValue, outToXValue;
    if (forward) {
        inFromXValue = 1.0f - progress;
        inToXValue = 0.0f;
        outFromXValue = -progress;
        outToXValue = -1.0f;
    } else {
        inFromXValue = progress - 1.0f;
        inToXValue = 0.0f;
        outFromXValue = progress;
        outToXValue = 1.0f;
    }

    final Time start = new Time(mBaseDate.timezone);
    start.set(mController.getTime());
    if (forward) {
        start.monthDay += mNumDays;
    } else {
        start.monthDay -= mNumDays;
    }
    mController.setTime(start.normalize(true));

    Time newSelected = start;

    if (mNumDays == 7) {
        newSelected = new Time(start);
        adjustToBeginningOfWeek(start);
    }

    final Time end = new Time(start);
    end.monthDay += mNumDays - 1;

    // We have to allocate these animation objects each time we switch views
    // because that is the only way to set the animation parameters.
    TranslateAnimation inAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, inFromXValue,
            Animation.RELATIVE_TO_SELF, inToXValue, Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f);

    TranslateAnimation outAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, outFromXValue,
            Animation.RELATIVE_TO_SELF, outToXValue, Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f);

    long duration = calculateDuration(width - Math.abs(xOffSet), width, velocity);
    inAnimation.setDuration(duration);
    inAnimation.setInterpolator(mHScrollInterpolator);
    outAnimation.setInterpolator(mHScrollInterpolator);
    outAnimation.setDuration(duration);
    outAnimation.setAnimationListener(new GotoBroadcaster(start, end));

    mViewSwitcher.setInAnimation(inAnimation);
    mViewSwitcher.setOutAnimation(outAnimation);

    DayView view = (DayView) mViewSwitcher.getCurrentView();
    view.cleanup();
    mViewSwitcher.showNext();
    view = (DayView) mViewSwitcher.getCurrentView();
    view.setSelected(newSelected, true, false);
    view.requestFocus();
    view.reloadEvents();
    view.updateTitle();
    view.restartCurrentTimeUpdates();

    return view;
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

public void reloadEvents() {
    // Protect against this being called before this view has been
    // initialized.
    if (mContext == null) {
        return;//ww  w  .  j av  a 2 s.  c  om
    }

    // Make sure our time zones are up to date
    mTZUpdater.run();

    setSelectedEvent(null);
    mSelectedEvents.clear();

    // The start date is the beginning of the week at 12am
    Time weekStart = new Time(DayUtils.getTimeZone(mContext, mTZUpdater));
    weekStart.set(mBaseDate);
    weekStart.hour = 0;
    weekStart.minute = 0;
    weekStart.second = 0;
    long millis = weekStart.normalize(true /* ignore isDst */);

    // Avoid reloading events unnecessarily.
    if (millis == mLastReloadMillis) {
        return;
    }
    mLastReloadMillis = millis;

    // load events in the background
    final ArrayList<Event> events = new ArrayList<Event>();
    mEventLoader.loadEventsInBackground(mNumDays, events, mFirstJulianDay, new Runnable() {

        public void run() {
            boolean fadeinEvents = mFirstJulianDay != mLoadedFirstJulianDay;
            mEvents = events;
            mLoadedFirstJulianDay = mFirstJulianDay;

            // New events, new layouts
            if (mLayouts == null || mLayouts.length < events.size()) {
                mLayouts = new StaticLayout[events.size()];
            } else {
                Arrays.fill(mLayouts, null);
            }

            computeEventRelations();

            mRemeasure = true;
            mComputeSelectedEvents = true;
            recalc();

            // Start animation to cross fade the events
            if (fadeinEvents) {
                if (mEventsCrossFadeAnimation == null) {
                    mEventsCrossFadeAnimation = ObjectAnimator.ofInt(DayView.this, "EventsAlpha", 0, 255);
                    mEventsCrossFadeAnimation.setDuration(EVENTS_CROSS_FADE_DURATION);
                }
                mEventsCrossFadeAnimation.start();
            } else {
                invalidate();
            }
        }
    }, mCancelCallback);
}

From source file:de.vanita5.twittnuker.util.Utils.java

@SuppressWarnings("deprecation")
public static String formatToLongTimeString(final Context context, final long timestamp) {
    if (context == null)
        return null;
    final Time then = new Time();
    then.set(timestamp);
    final Time now = new Time();
    now.setToNow();/*w  w w  .ja v a  2s. com*/

    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    format_flags |= DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME;

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

From source file:de.vanita5.twittnuker.util.Utils.java

@SuppressWarnings("deprecation")
public static String formatTimeStampString(final Context context, final long timestamp) {
    if (context == null)
        return null;
    final Time then = new Time();
    then.set(timestamp);
    final Time now = new Time();
    now.setToNow();/*from w w w  . j a v a 2  s  .co m*/

    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    if (then.year != now.year) {
        format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        format_flags |= DateUtils.FORMAT_SHOW_DATE;
    } else {
        format_flags |= DateUtils.FORMAT_SHOW_TIME;
    }

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