Example usage for android.text.format Time normalize

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

Introduction

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

Prototype

public long normalize(boolean ignoreDst) 

Source Link

Document

Ensures the values in each field are in range.

Usage

From source file:com.dgsd.android.ShiftTracker.Fragment.EditShiftFragment.java

private void prepopulate() {
    if (mInitialShift != null) {
        mName.setText(mInitialShift.name);
        mNotes.setText(mInitialShift.note);
        mSaveAsTemplate.setChecked(mInitialShift.isTemplate);
        if (mInitialShift.julianDay >= 0)
            onDateSelected(TYPE_CODE_START, mInitialShift.julianDay);

        if (mInitialShift.endJulianDay >= 0)
            onDateSelected(TYPE_CODE_END, mInitialShift.endJulianDay);

        if (mInitialShift.getStartTime() != -1)
            setStartTime(mInitialShift.getStartTime());

        if (mInitialShift.getEndTime() != -1)
            setEndTime(mInitialShift.getEndTime());

        if (mInitialShift.breakDuration >= 0)
            mUnpaidBreak.setText(String.valueOf(mInitialShift.breakDuration));

        if (mInitialShift.payRate >= 0)
            mPayRate.setText(String.valueOf(mInitialShift.payRate));

        for (int i = 0, len = mRemindersValues.length; i < len; i++) {
            if (String.valueOf(mInitialShift.reminder).equals(mRemindersValues[i])) {
                setSelection(mReminders, i);
                break;
            }/*from  www  .ja  va2s .  c om*/
        }

        getSherlockActivity().invalidateOptionsMenu();
    } else {
        //No initial shift, just set up our date/time values
        final int jd = mInitialJulianDay < 0 ? TimeUtils.getCurrentJulianDay() : mInitialJulianDay;
        onDateSelected(TYPE_CODE_START, jd);
        onDateSelected(TYPE_CODE_END, jd);

        //Default 9 - 5 shift
        Time t = new Time();
        t.setToNow();
        t.hour = 9;
        t.minute = 0;
        t.second = 0;
        t.normalize(true);

        final Prefs p = Prefs.getInstance(getActivity());
        setStartTime(p.get(getString(R.string.settings_key_default_start_time), t.toMillis(true)));

        t.hour = 17;
        t.normalize(true);

        setEndTime(p.get(getString(R.string.settings_key_default_end_time), t.toMillis(true)));

        mUnpaidBreak.setText(p.get(getString(R.string.settings_key_default_break_duration), null));
        mPayRate.setText(p.get(getString(R.string.settings_key_default_pay_rate), null));

        String remindersVal = p.get(getString(R.string.settings_key_default_reminder), "None");
        int index = 0;
        for (int i = 0, len = mRemindersLabels.length; i < len; i++) {
            if (TextUtils.equals(remindersVal, mRemindersLabels[i])) {
                index = i;
                break;
            }
        }

        setSelection(mReminders, index);
    }
}

From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java

private void resolveDelayAction(Intent intent) {
    if (!(intent.hasExtra(EXTRA_TASK_DUE) && intent.hasExtra(EXTRA_TIMEZONE))) {
        return;/*  w  ww. j  av  a 2 s .  c om*/
    }
    final String action = intent.getAction();
    final Uri taskUri = intent.getData();
    long due = intent.getLongExtra(EXTRA_TASK_DUE, -1);
    String tz = intent.getStringExtra(EXTRA_TIMEZONE);
    boolean allDay = intent.getBooleanExtra(EXTRA_ALLDAY, false);

    int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.cancel(notificationId);

    if (ACTION_DELAY_1H.equals(action)) {
        Time time = new Time(tz);
        time.set(due);
        time.allDay = false;
        time.hour++;
        time.normalize(true);
        delayTask(taskUri, time);
    } else if (ACTION_DELAY_1D.equals(action)) {
        if (tz == null) {
            tz = "UTC";
        }
        Time time = new Time(tz);
        time.set(due);
        time.allDay = allDay;
        time.monthDay++;
        time.normalize(true);
        delayTask(taskUri, time);
    }

}

From source file:com.a.mirko.android.datetimepicker.time.RadialPickerLayout.java

/**
 * Announce the currently-selected time when launched.
 *///from  www  .  j a  v a2 s.  co m
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current time will be spoken.
        event.getText().clear();
        Time time = new Time();
        time.hour = getHours();
        time.minute = getMinutes();
        long millis = time.normalize(true);
        int flags = DateUtils.FORMAT_SHOW_TIME;
        if (mIs24HourMode) {
            flags |= DateUtils.FORMAT_24HOUR;
        }
        String timeString = DateUtils.formatDateTime(getContext(), millis, flags);
        event.getText().add(timeString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}

From source file:com.redinput.datetimepickercompat.time.RadialPickerLayout.java

private void installAccessibilityDelegate() {
    // The accessibility delegate enables customizing accessibility behavior
    // via composition as opposed as inheritance. The main benefit is that
    // one can write a backwards compatible application by setting the delegate
    // only if the API level is high enough i.e. the delegate is part of the APIs.
    // The easiest way to achieve that is by using the support library which
    // takes the burden of checking API version and knowing which API version
    // introduced the delegate off the developer.
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {

        @Override/* w ww  .j  a  v a 2 s. c o m*/
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            // Note that View.onInitializeAccessibilityNodeInfo was introduced in
            // ICS and we would like to tweak a bit the text that is reported to
            // accessibility services via the AccessibilityNodeInfo.
            info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
            info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);
        }

        @Override
        public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
            if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
                // Clear the event's current text so that only the current time will be spoken.
                event.getText().clear();
                Time time = new Time();
                time.hour = getHours();
                time.minute = getMinutes();
                long millis = time.normalize(true);
                int flags = DateUtils.FORMAT_SHOW_TIME;
                if (mIs24HourMode) {
                    flags |= DateUtils.FORMAT_24HOUR;
                }
                String timeString = DateUtils.formatDateTime(getContext(), millis, flags);
                event.getText().add(timeString);
                return true;
            }

            return super.dispatchPopulateAccessibilityEvent(host, event);
        }

        @Override
        public boolean performAccessibilityAction(View host, int action, Bundle args) {
            if (super.performAccessibilityAction(host, action, args)) {
                return true;
            }

            int changeMultiplier = 0;
            if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) {
                changeMultiplier = 1;
            } else if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) {
                changeMultiplier = -1;
            }
            if (changeMultiplier != 0) {
                int value = getCurrentlyShowingValue();
                int stepSize = 0;
                int currentItemShowing = getCurrentItemShowing();
                if (currentItemShowing == HOUR_INDEX) {
                    stepSize = HOUR_VALUE_TO_DEGREES_STEP_SIZE;
                    value %= 12;
                } else if (currentItemShowing == MINUTE_INDEX) {
                    stepSize = MINUTE_VALUE_TO_DEGREES_STEP_SIZE;
                }

                int degrees = value * stepSize;
                degrees = snapOnly30s(degrees, changeMultiplier);
                value = degrees / stepSize;
                int maxValue = 0;
                int minValue = 0;
                if (currentItemShowing == HOUR_INDEX) {
                    if (mIs24HourMode) {
                        maxValue = 23;
                    } else {
                        maxValue = 12;
                        minValue = 1;
                    }
                } else {
                    maxValue = 55;
                }
                if (value > maxValue) {
                    // If we scrolled forward past the highest number, wrap around to the
                    // lowest.
                    value = minValue;
                } else if (value < minValue) {
                    // If we scrolled backward past the lowest number, wrap around to the
                    // highest.
                    value = maxValue;
                }
                setItem(currentItemShowing, value);
                mListener.onValueSelected(currentItemShowing, value, false);
                return true;
            }

            return false;
        }
    });
}

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

@Override
protected void onNewIntent(Intent intent) {
    String action = intent.getAction();
    if (DEBUG)/*from w w w .  j av a 2s. c  o m*/
        Log.d(TAG, "New intent received " + intent.toString());
    // Don't change the date if we're just returning to the app's home
    if (Intent.ACTION_VIEW.equals(action) && !intent.getBooleanExtra(Utils.INTENT_KEY_HOME, false)) {
        long millis = parseViewAction(intent);
        if (millis == -1) {
            millis = Utils.timeFromIntentInMillis(intent);
        }
        if (millis != -1 && mViewEventId == -1 && mController != null) {
            Time time = new Time(mTimeZone);
            time.set(millis);
            time.normalize(true);
            mController.sendEvent(this, EventType.GO_TO, time, time, -1, ViewType.CURRENT);
        }
    }
}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java

@Override
public void onRecurrenceSet(String s) {

    EventRecurrence event = new EventRecurrence();

    LocalDate now = LocalDate.now();
    Time startDate = new Time(Time.getCurrentTimezone());
    startDate.set(now.getDayOfMonth(), now.getMonthOfYear(), now.getYear());
    startDate.normalize(true);
    event.parse(s);/*from w  ww .  ja  v  a 2s  .com*/
    event.setStartDate(startDate);

    Log.d(TAG, "OnRecurrenceSet: " + event.startDate);

    schedule.setRepetition(new RepetitionRule("RRULE:" + s));
    setScheduleStart(schedule.start());
    LocalDate end = schedule.end();
    Log.d(TAG, "ICAL: " + schedule.rule().toIcal());
    setScheduleEnd(end);
    Log.d(TAG, "ICAL: " + schedule.rule().toIcal());
    ruleText.setText(getCurrentSchedule());
}

From source file:org.level28.android.moca.json.ScheduleDeserializer.java

/**
 * Pure Java reimplementation of {@link Time#parse3339(String)}.
 * <p>/*ww  w  .j a  v  a2 s  .  co  m*/
 * Due to <a
 * href="http://code.google.com/p/android/issues/detail?id=16002">Issue
 * 16002</a>, {@code Time.parse3339()} leaks memory on short input. However,
 * the same leak happens <em>also</em> if the function is fed a formally
 * invalid RFC3339 timestamp.
 * <p>
 * The safest option is a full rewrite in pure Java, since JNI on Android is
 * a mess (we'd have to ship the same library for three different
 * architectures &mdash; not pretty...).
 * 
 * @param timeString
 *            a date/time specification formatted as an RFC3339 string
 * @return the same date/time specification in milliseconds since the Epoch
 * @throws ParseException
 *             if the string is formally invalid per RFC3339
 * @throws NullPointerException
 *             if the string is {@code null}
 * @throws IllegalArgumentException
 *             if the string is less than 10 characters long
 */
private static long parseTime(String timeString) throws ParseException {
    checkNotNull(timeString, "Time input should not be null");
    final int len = timeString.length();
    checkArgument(len >= 10, "Time input is too short; must be at least 10 characters");
    final char[] s = timeString.toCharArray();

    final Time t = new Time();
    int n;
    boolean inUtc = false;

    // Year
    n = getChar(s, 0, 1000);
    n += getChar(s, 1, 100);
    n += getChar(s, 2, 10);
    n += getChar(s, 3, 1);
    t.year = n;

    // '-'
    checkChar(s, 4, '-');

    // Month
    n = getChar(s, 5, 10);
    n += getChar(s, 6, 1);
    --n;
    t.month = n;

    // '-'
    checkChar(s, 7, '-');

    // Day
    n = getChar(s, 8, 10);
    n += getChar(s, 9, 1);
    t.monthDay = n;

    // Check if we have a time as well
    if (len >= 19) {
        // 'T'
        checkChar(s, 10, 'T');
        t.allDay = false;

        // Hour
        n = getChar(s, 11, 10);
        n += getChar(s, 12, 1);
        int hour = n;

        // ':'
        checkChar(s, 13, ':');

        // Minute
        n = getChar(s, 14, 10);
        n += getChar(s, 15, 1);
        int minute = n;

        // ':'
        checkChar(s, 16, ':');

        // Second
        n = getChar(s, 17, 10);
        n += getChar(s, 18, 1);
        t.second = n;

        // Skip subsecond component (if any)
        int tz_index = 19;
        if (tz_index < len && s[tz_index] == '.') {
            do {
                tz_index++;
            } while (tz_index < len && s[tz_index] >= '0' && s[tz_index] <= '9');
        }

        int offset = 0;
        if (len > tz_index) {
            final char c = s[tz_index];

            switch (c) {
            case 'Z':
                // UTC
                offset = 0;
                break;
            case '-':
                offset = 1;
                break;
            case '+':
                offset = -1;
                break;
            default:
                throw new ParseException("Unexpected character", tz_index);
            }
            inUtc = true;

            if (offset != 0) {
                // Hour
                n = getChar(s, tz_index + 1, 10);
                n += getChar(s, tz_index + 2, 1);
                n *= offset;
                hour += n;

                // ':'
                checkChar(s, tz_index + 3, ':');

                // Minute
                n = getChar(s, tz_index + 4, 10);
                n += getChar(s, tz_index + 5, 1);
                n *= offset;
                minute += n;
            }
        }
        t.hour = hour;
        t.minute = minute;

        if (offset != 0) {
            t.normalize(false);
        }
    } else {
        // We don't
        t.allDay = true;
        t.hour = 0;
        t.minute = 0;
        t.second = 0;
    }

    t.weekDay = 0;
    t.yearDay = 0;
    t.isDst = -1;
    t.gmtoff = 0;

    if (inUtc) {
        t.timezone = Time.TIMEZONE_UTC;
    }

    return t.toMillis(false);
}

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

public void updateTitle() {
    Time start = new Time(mBaseDate);
    start.normalize(true);
    Time end = new Time(start);
    end.monthDay += mNumDays - 1;/*www .j  av a2s.c om*/
    // 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:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private void doSingleTapUp(MotionEvent ev) {
    if (!mHandleActionUp || mScrolling) {
        return;/*from  w w  w  .ja  v  a  2  s .com*/
    }

    int x = (int) ev.getX();
    int y = (int) ev.getY();

    boolean validPosition = setSelectionFromPosition(x, y, false);
    if (!validPosition) {
        if (y < DAY_HEADER_HEIGHT) {
            Time selectedTime = new Time(mBaseDate);
            selectedTime.setJulianDay(mSelectionDay);
            selectedTime.hour = mSelectionHour;
            selectedTime.normalize(true /* ignore isDst */);
        }
        return;
    }

    if (mSelectedEvent != null) {
        long clearDelay = (CLICK_DISPLAY_DURATION + mOnDownDelay)
                - (System.currentTimeMillis() - mDownTouchTime);
        if (clearDelay > 0) {
            this.postDelayed(mClearClick, clearDelay);
        } else {
            this.post(mClearClick);
        }

    }
    invalidate();
}

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

private void adjustToBeginningOfWeek(Time time) {
    int dayOfWeek = time.weekDay;
    int diff = dayOfWeek - mFirstDayOfWeek;
    if (diff != 0) {
        if (diff < 0) {
            diff += 7;// w  ww  .  ja  v  a 2s  .  c  o m
        }
        time.monthDay -= diff;
        time.normalize(true /* ignore isDst */);
    }
}