Search in sources :

Example 21 with Time

use of android.text.format.Time in project qksms by moezbhatti.

the class NetworkPolicyManager method computeNextCycleBoundary.

/**
     * {@hide}
     */
public static long computeNextCycleBoundary(long currentTime, NetworkPolicy policy) {
    if (policy.cycleDay == CYCLE_NONE) {
        throw new IllegalArgumentException("Unable to compute boundary without cycleDay");
    }
    final Time now = new Time(policy.cycleTimezone);
    now.set(currentTime);
    // first, find cycle boundary for current month
    final Time cycle = new Time(now);
    cycle.hour = cycle.minute = cycle.second = 0;
    snapToCycleDay(cycle, policy.cycleDay);
    if (Time.compare(cycle, now) <= 0) {
        // cycle boundary is before now, use next cycle boundary; start by
        // pushing ourselves squarely into next month.
        final Time nextMonth = new Time(now);
        nextMonth.hour = nextMonth.minute = nextMonth.second = 0;
        nextMonth.monthDay = 1;
        nextMonth.month += 1;
        nextMonth.normalize(true);
        cycle.set(nextMonth);
        snapToCycleDay(cycle, policy.cycleDay);
    }
    return cycle.toMillis(true);
}
Also used : Time(android.text.format.Time)

Example 22 with Time

use of android.text.format.Time in project chromeview by pwnall.

the class InputDialogContainer method normalizeTime.

private Time normalizeTime(int year, int month, int monthDay, int hour, int minute, int second) {
    Time result = new Time();
    if (year == 0 && month == 0 && monthDay == 0 && hour == 0 && minute == 0 && second == 0) {
        Calendar cal = Calendar.getInstance();
        result.set(cal.get(Calendar.SECOND), cal.get(Calendar.MINUTE), cal.get(Calendar.HOUR), cal.get(Calendar.DATE), cal.get(Calendar.MONTH), cal.get(Calendar.YEAR));
    } else {
        result.set(second, minute, hour, monthDay, month, year);
    }
    return result;
}
Also used : Calendar(java.util.Calendar) Time(android.text.format.Time)

Example 23 with Time

use of android.text.format.Time in project chromeview by pwnall.

the class InputDialogContainer method showDialog.

void showDialog(final int dialogType, int year, int month, int monthDay, int hour, int minute, int second) {
    if (isDialogShowing())
        mDialog.dismiss();
    Time time = normalizeTime(year, month, monthDay, hour, minute, second);
    if (dialogType == sTextInputTypeDate) {
        mDialog = new DatePickerDialog(mContext, new DateListener(dialogType), time.year, time.month, time.monthDay);
        mDialog.setTitle(mContext.getText(R.string.date_picker_dialog_title));
    } else if (dialogType == sTextInputTypeTime) {
        mDialog = new TimePickerDialog(mContext, new TimeListener(dialogType), time.hour, time.minute, DateFormat.is24HourFormat(mContext));
    } else if (dialogType == sTextInputTypeDateTime || dialogType == sTextInputTypeDateTimeLocal) {
        mDialog = new DateTimePickerDialog(mContext, new DateTimeListener(dialogType), time.year, time.month, time.monthDay, time.hour, time.minute, DateFormat.is24HourFormat(mContext));
    } else if (dialogType == sTextInputTypeMonth) {
        mDialog = new MonthPickerDialog(mContext, new MonthListener(dialogType), time.year, time.month);
    }
    mDialog.setButton(DialogInterface.BUTTON_POSITIVE, mContext.getText(R.string.date_picker_dialog_set), (DialogInterface.OnClickListener) mDialog);
    mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, mContext.getText(android.R.string.cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            mDialogAlreadyDismissed = true;
            mInputActionDelegate.cancelDateTimeDialog();
        }
    });
    mDialog.setButton(DialogInterface.BUTTON_NEUTRAL, mContext.getText(R.string.date_picker_dialog_clear), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            mDialogAlreadyDismissed = true;
            mInputActionDelegate.replaceDateTime(dialogType, 0, 0, 0, 0, 0, 0);
        }
    });
    mDialogAlreadyDismissed = false;
    mDialog.show();
}
Also used : DatePickerDialog(android.app.DatePickerDialog) DialogInterface(android.content.DialogInterface) Time(android.text.format.Time) TimePickerDialog(android.app.TimePickerDialog)

Example 24 with Time

use of android.text.format.Time in project robolectric by robolectric.

the class ShadowTimeTest method shouldParseRfc3339_withQuestionableFormat.

@Test
@Config(maxSdk = KITKAT)
public // this fails on LOLLIPOP+; is the shadow impl of parse3339 correct for pre-LOLLIPOP?
void shouldParseRfc3339_withQuestionableFormat() {
    for (String tz : Arrays.asList("Europe/Berlin", "America/Los Angeles", "Australia/Adelaide")) {
        String desc = "Eval when local timezone is " + tz;
        TimeZone.setDefault(TimeZone.getTimeZone(tz));
        Time t = new Time("Europe/Berlin");
        assertTrue(desc, t.parse3339("2008-10-13T16:30:50.999-03"));
        assertEquals(desc, 2008, t.year);
        assertEquals(desc, 9, t.month);
        assertEquals(desc, 13, t.monthDay);
        assertEquals(desc, 19, t.hour);
        assertEquals(desc, 30, t.minute);
        assertEquals(desc, 50, t.second);
        assertEquals(desc, "UTC", t.timezone);
        assertFalse(desc, t.allDay);
    }
}
Also used : Time(android.text.format.Time) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 25 with Time

use of android.text.format.Time in project robolectric by robolectric.

the class ShadowTimeTest method shouldFormat.

@Test
public void shouldFormat() throws Exception {
    Time t = new Time(Time.TIMEZONE_UTC);
    t.set(3600000L);
    assertEquals("Hello epoch 01 1970 01", t.format("Hello epoch %d %Y %d"));
    assertEquals("Hello epoch  1:00 AM", t.format("Hello epoch %l:%M %p"));
}
Also used : Time(android.text.format.Time) Test(org.junit.Test)

Aggregations

Time (android.text.format.Time)394 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