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(Time other) 

Source Link

Document

A copy constructor.

Usage

From source file:com.xandy.calendar.AllInOneActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Time t = null;// ww w .j  a v a2 s. co m
    int viewType = ViewType.CURRENT;
    long extras = CalendarController.EXTRA_GOTO_TIME;
    final int itemId = item.getItemId();
    if (itemId == R.id.action_refresh) {
        mController.refreshCalendars();
        return true;
    } else if (itemId == R.id.action_today) {
        viewType = ViewType.CURRENT;
        t = new Time(mTimeZone);
        t.setToNow();
        extras |= CalendarController.EXTRA_GOTO_TODAY;
    } else if (itemId == R.id.action_create_event) {
        t = new Time();
        t.set(mController.getTime());
        if (t.minute > 30) {
            t.hour++;
            t.minute = 0;
        } else if (t.minute > 0 && t.minute < 30) {
            t.minute = 30;
        }
        mController.sendEventRelatedEvent(this, EventType.CREATE_EVENT, -1, t.toMillis(true), 0, 0, 0, -1);
        return true;
    } else if (itemId == R.id.action_select_visible_calendars) {
        mController.sendEvent(this, EventType.LAUNCH_SELECT_VISIBLE_CALENDARS, null, null, 0, 0);
        return true;
    } else if (itemId == R.id.action_settings) {
        mController.sendEvent(this, EventType.LAUNCH_SETTINGS, null, null, 0, 0);
        return true;
    } else if (itemId == R.id.action_hide_controls) {
        mHideControls = !mHideControls;
        Utils.setSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, !mHideControls);
        item.setTitle(mHideControls ? mShowString : mHideString);
        if (!mHideControls) {
            mMiniMonth.setVisibility(View.VISIBLE);
            mCalendarsList.setVisibility(View.VISIBLE);
            mMiniMonthContainer.setVisibility(View.VISIBLE);
        }
        final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
                mHideControls ? 0 : mControlsAnimateWidth, mHideControls ? mControlsAnimateWidth : 0);
        slideAnimation.setDuration(mCalendarControlsAnimationTime);
        ObjectAnimator.setFrameDelay(0);
        slideAnimation.start();
        return true;
    } else if (itemId == R.id.action_search) {
        return false;
    } else {
        return mExtensions.handleItemSelected(item, this);
    }
    mController.sendEvent(this, EventType.GO_TO, t, null, t, -1, viewType, extras, null, null);
    return true;
}

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

public Time getSelectedDay() {
    Time time = new Time(mBaseDate);
    time.setJulianDay(mSelectionDay);//  w w w  .  j  a va  2 s .com
    time.hour = mSelectionHour;

    // We ignore the "isDst" field because we want normalize() to figure
    // out the correct DST value and not adjust the selected time based
    // on the current setting of DST.
    time.normalize(true /* ignore isDst */);
    return time;
}

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

public void updateTitle() {
    Time start = new Time(mBaseDate);
    start.normalize(true);//from w  ww  .  jav  a 2s. co  m
    Time end = new Time(start);
    end.monthDay += mNumDays - 1;
    // Move it forward one minute so the formatter doesn't lose a day
    end.minute += 1;
    end.normalize(true);

    long formatFlags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
    if (mNumDays != 1) {
        // Don't show day of the month if for multi-day view
        formatFlags |= DateUtils.FORMAT_NO_MONTH_DAY;

        // Abbreviate the month if showing multiple months
        if (start.month != end.month) {
            formatFlags |= DateUtils.FORMAT_ABBREV_MONTH;
        }
    }

    mController.sendEvent(this, EventType.UPDATE_TITLE, start, end, null, -1, ViewType.CURRENT, formatFlags,
            null, null);
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Time t = null;//from  w  w  w . java 2 s . c  o m
    int viewType = ViewType.CURRENT;
    long extras = CalendarController.EXTRA_GOTO_TIME;
    final int itemId = item.getItemId();
    if (itemId == R.id.action_refresh) {
        mController.refreshCalendars();
        return true;
    } else if (itemId == R.id.action_today) {
        viewType = ViewType.CURRENT;
        t = new Time(mTimeZone);
        t.setToNow();
        extras |= CalendarController.EXTRA_GOTO_TODAY;
    } else if (itemId == R.id.action_goto) {
        Time todayTime;
        t = new Time(mTimeZone);
        t.set(mController.getTime());
        todayTime = new Time(mTimeZone);
        todayTime.setToNow();
        if (todayTime.month == t.month) {
            t = todayTime;
        }

        DatePickerDialog datePickerDialog = DatePickerDialog
                .newInstance(new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) {
                        Time selectedTime = new Time(mTimeZone);
                        selectedTime.year = year;
                        selectedTime.month = monthOfYear;
                        selectedTime.monthDay = dayOfMonth;
                        long extras = CalendarController.EXTRA_GOTO_TIME | CalendarController.EXTRA_GOTO_DATE;
                        mController.sendEvent(this, EventType.GO_TO, selectedTime, null, selectedTime, -1,
                                ViewType.CURRENT, extras, null, null);
                    }
                }, t.year, t.month, t.monthDay);
        datePickerDialog.show(getFragmentManager(), "datePickerDialog");

    } else if (itemId == R.id.action_hide_controls) {
        mHideControls = !mHideControls;
        Utils.setSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, !mHideControls);
        item.setTitle(mHideControls ? mShowString : mHideString);
        if (!mHideControls) {
            mMiniMonth.setVisibility(View.VISIBLE);
            mCalendarsList.setVisibility(View.VISIBLE);
            mMiniMonthContainer.setVisibility(View.VISIBLE);
        }
        final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
                mHideControls ? 0 : mControlsAnimateWidth, mHideControls ? mControlsAnimateWidth : 0);
        slideAnimation.setDuration(mCalendarControlsAnimationTime);
        ObjectAnimator.setFrameDelay(0);
        slideAnimation.start();
        return true;
    } else if (itemId == R.id.action_search) {
        return false;
    } else if (itemId == R.id.action_import) {
        ImportActivity.pickImportFile(this);
    } else {
        return mExtensions.handleItemSelected(item, this);
    }
    mController.sendEvent(this, EventType.GO_TO, t, null, t, -1, viewType, extras, null, null);
    return true;
}

From source file:com.appeaser.sublimepickerlibrary.recurrencepicker.RecurrenceOptionCreator.java

public void initializeData(long currentlyChosenTime, String timeZone, String recurrenceRule,
        @NonNull OnRecurrenceSetListener callback) {
    mRecurrence.wkst = EventRecurrence.timeDay2Day(RecurrenceUtils.getFirstDayOfWeek());
    mRecurrenceSetListener = callback;//from  ww w.j  a v a  2s.  com

    mTime.set(currentlyChosenTime);

    if (!TextUtils.isEmpty(timeZone)) {
        mTime.timezone = timeZone;
    }
    mTime.normalize(false);

    // Time days of week: Sun=0, Mon=1, etc
    mModel.weeklyByDayOfWeek[mTime.weekDay] = true;

    if (!TextUtils.isEmpty(recurrenceRule)) {
        mModel.recurrenceState = RecurrenceModel.STATE_RECURRENCE;
        mRecurrence.parse(recurrenceRule);
        copyEventRecurrenceToModel(mRecurrence, mModel);
        // Leave today's day of week as checked by default in weekly view.
        if (mRecurrence.bydayCount == 0) {
            mModel.weeklyByDayOfWeek[mTime.weekDay] = true;
        }
    } else {
        // Default
        mModel.recurrenceState = RecurrenceModel.STATE_RECURRENCE;
    }

    if (mModel.endDate == null) {
        mModel.endDate = new Time(mTime);
        switch (mModel.freq) {
        case RecurrenceModel.FREQ_DAILY:
        case RecurrenceModel.FREQ_WEEKLY:
            mModel.endDate.month += 1;
            break;
        case RecurrenceModel.FREQ_MONTHLY:
            mModel.endDate.month += 3;
            break;
        case RecurrenceModel.FREQ_YEARLY:
            mModel.endDate.year += 3;
            break;
        }
        mModel.endDate.normalize(false);
    }

    togglePickerOptions();
    updateDialog();
    showRecurrencePicker();
}

From source file:com.android.calendar.event.EditEventView.java

public EditEventView(FragmentActivity activity, View view, EditDoneRunnable done,
        boolean timeSelectedWasStartTime, boolean dateSelectedWasStartDate) {

    mActivity = activity;/*from   www.  j a v a  2 s .  c o m*/
    mView = view;
    mDone = done;

    // cache top level view elements
    mLoadingMessage = (TextView) view.findViewById(R.id.loading_message);
    mScrollView = (ScrollView) view.findViewById(R.id.scroll_view);

    // cache all the widgets
    mCalendarsSpinner = (Spinner) view.findViewById(R.id.calendars_spinner);
    mTitleTextView = (TextView) view.findViewById(R.id.title);
    mLocationTextView = (AutoCompleteTextView) view.findViewById(R.id.location);
    mDescriptionTextView = (TextView) view.findViewById(R.id.description);
    mTimezoneLabel = (TextView) view.findViewById(R.id.timezone_label);
    mStartDateButton = (Button) view.findViewById(R.id.start_date);
    mEndDateButton = (Button) view.findViewById(R.id.end_date);
    mWhenView = (TextView) mView.findViewById(R.id.when);
    mTimezoneTextView = (TextView) mView.findViewById(R.id.timezone_textView);
    mStartTimeButton = (Button) view.findViewById(R.id.start_time);
    mEndTimeButton = (Button) view.findViewById(R.id.end_time);
    mTimezoneButton = (Button) view.findViewById(R.id.timezone_button);
    mTimezoneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showTimezoneDialog();
        }
    });
    mTimezoneRow = view.findViewById(R.id.timezone_button_row);
    mStartTimeHome = (TextView) view.findViewById(R.id.start_time_home_tz);
    mStartDateHome = (TextView) view.findViewById(R.id.start_date_home_tz);
    mEndTimeHome = (TextView) view.findViewById(R.id.end_time_home_tz);
    mEndDateHome = (TextView) view.findViewById(R.id.end_date_home_tz);
    mAllDayCheckBox = (CheckBox) view.findViewById(R.id.is_all_day);
    mRruleButton = (Button) view.findViewById(R.id.rrule);
    mAvailabilitySpinner = (Spinner) view.findViewById(R.id.availability);
    mAccessLevelSpinner = (Spinner) view.findViewById(R.id.visibility);
    mCalendarSelectorGroup = view.findViewById(R.id.calendar_selector_group);
    mCalendarSelectorWrapper = view.findViewById(R.id.calendar_selector_wrapper);
    mCalendarStaticGroup = view.findViewById(R.id.calendar_group);
    mRemindersGroup = view.findViewById(R.id.reminders_row);
    mResponseGroup = view.findViewById(R.id.response_row);
    mOrganizerGroup = view.findViewById(R.id.organizer_row);
    mAttendeesGroup = view.findViewById(R.id.add_attendees_row);
    mLocationGroup = view.findViewById(R.id.where_row);
    mDescriptionGroup = view.findViewById(R.id.description_row);
    mStartHomeGroup = view.findViewById(R.id.from_row_home_tz);
    mEndHomeGroup = view.findViewById(R.id.to_row_home_tz);
    mAttendeesList = (MultiAutoCompleteTextView) view.findViewById(R.id.attendees);

    mColorPickerNewEvent = view.findViewById(R.id.change_color_new_event);
    mColorPickerExistingEvent = view.findViewById(R.id.change_color_existing_event);

    mTitleTextView.setTag(mTitleTextView.getBackground());
    mLocationTextView.setTag(mLocationTextView.getBackground());
    mLocationAdapter = new EventLocationAdapter(activity);
    mLocationTextView.setAdapter(mLocationAdapter);
    mLocationTextView.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                // Dismiss the suggestions dropdown. Return false so the
                // other
                // side effects still occur (soft keyboard going away,
                // etc.).
                mLocationTextView.dismissDropDown();
            }
            return false;
        }
    });

    mAvailabilityExplicitlySet = false;
    mAllDayChangingAvailability = false;
    mAvailabilityCurrentlySelected = -1;
    mAvailabilitySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // The spinner's onItemSelected gets called while it is being
            // initialized to the first item, and when we explicitly set it
            // in the allDay checkbox toggling, so we need these checks to
            // find out when the spinner is actually being clicked.

            // Set the initial selection.
            if (mAvailabilityCurrentlySelected == -1) {
                mAvailabilityCurrentlySelected = position;
            }

            if (mAvailabilityCurrentlySelected != position && !mAllDayChangingAvailability) {
                mAvailabilityExplicitlySet = true;
            } else {
                mAvailabilityCurrentlySelected = position;
                mAllDayChangingAvailability = false;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    mDescriptionTextView.setTag(mDescriptionTextView.getBackground());
    mAttendeesList.setTag(mAttendeesList.getBackground());
    mOriginalPadding[0] = mLocationTextView.getPaddingLeft();
    mOriginalPadding[1] = mLocationTextView.getPaddingTop();
    mOriginalPadding[2] = mLocationTextView.getPaddingRight();
    mOriginalPadding[3] = mLocationTextView.getPaddingBottom();
    mEditViewList.add(mTitleTextView);
    mEditViewList.add(mLocationTextView);
    mEditViewList.add(mDescriptionTextView);
    mEditViewList.add(mAttendeesList);

    mViewOnlyList.add(view.findViewById(R.id.when_row));
    mViewOnlyList.add(view.findViewById(R.id.timezone_textview_row));

    mEditOnlyList.add(view.findViewById(R.id.all_day_row));
    mEditOnlyList.add(view.findViewById(R.id.availability_row));
    mEditOnlyList.add(view.findViewById(R.id.visibility_row));
    mEditOnlyList.add(view.findViewById(R.id.from_row));
    mEditOnlyList.add(view.findViewById(R.id.to_row));
    mEditOnlyList.add(mTimezoneRow);
    mEditOnlyList.add(mStartHomeGroup);
    mEditOnlyList.add(mEndHomeGroup);

    mResponseRadioGroup = (RadioGroup) view.findViewById(R.id.response_value);
    mRemindersContainer = (LinearLayout) view.findViewById(R.id.reminder_items_container);

    mTimezone = Utils.getTimeZone(activity, null);
    mIsMultipane = activity.getResources().getBoolean(R.bool.tablet_config);
    mStartTime = new Time(mTimezone);
    mEndTime = new Time(mTimezone);
    mEmailValidator = new Rfc822Validator(null);
    initMultiAutoCompleteTextView((RecipientEditTextView) mAttendeesList);

    // Display loading screen
    setModel(null);

    FragmentManager fm = activity.getSupportFragmentManager();
    RecurrencePickerDialog rpd = (RecurrencePickerDialog) fm.findFragmentByTag(FRAG_TAG_RECUR_PICKER);
    if (rpd != null) {
        rpd.setOnRecurrenceSetListener(this);
    }
    TimeZonePickerDialog tzpd = (TimeZonePickerDialog) fm.findFragmentByTag(FRAG_TAG_TIME_ZONE_PICKER);
    if (tzpd != null) {
        tzpd.setOnTimeZoneSetListener(this);
    }
    TimePickerDialog tpd = (TimePickerDialog) fm.findFragmentByTag(FRAG_TAG_TIME_PICKER);
    if (tpd != null) {
        View v;
        mTimeSelectedWasStartTime = timeSelectedWasStartTime;
        if (timeSelectedWasStartTime) {
            v = mStartTimeButton;
        } else {
            v = mEndTimeButton;
        }
        tpd.setOnTimeSetListener(new TimeListener(v));
    }
    mDatePickerDialog = (DatePickerDialog) fm.findFragmentByTag(FRAG_TAG_DATE_PICKER);
    if (mDatePickerDialog != null) {
        View v;
        mDateSelectedWasStartDate = dateSelectedWasStartDate;
        if (dateSelectedWasStartDate) {
            v = mStartDateButton;
        } else {
            v = mEndDateButton;
        }
        mDatePickerDialog.setOnDateSetListener(new DateListener(v));
    }
}

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;//from  w  w  w.  j  av  a 2 s.c o 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:be.billington.calendar.recurrencepicker.RecurrencePickerDialog.java

@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
    if (mModel.endDate == null) {
        mModel.endDate = new Time(mTime.timezone);
        mModel.endDate.hour = mModel.endDate.minute = mModel.endDate.second = 0;
    }//from  w ww .j ava2  s. c o  m
    mModel.endDate.year = year;
    mModel.endDate.month = monthOfYear;
    mModel.endDate.monthDay = dayOfMonth;
    mModel.endDate.normalize(false);
    updateDialog();
}

From source file:com.codetroopers.betterpickers.recurrencepicker.RecurrencePickerDialog.java

@Override
public void onDateSet(CalendarDatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
    if (mModel.endDate == null) {
        mModel.endDate = new Time(mTime.timezone);
        mModel.endDate.hour = mModel.endDate.minute = mModel.endDate.second = 0;
    }//from   w w w. j  ava2s . com
    mModel.endDate.year = year;
    mModel.endDate.month = monthOfYear;
    mModel.endDate.monthDay = dayOfMonth;
    mModel.endDate.normalize(false);
    updateDialog();
}

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;//from  w  w w  .  java  2 s  .c o m
    }

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