Search in sources :

Example 86 with Time

use of org.bouncycastle.asn1.x509.Time in project Etar-Calendar by Etar-Group.

the class RecurrencePickerDialog method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRecurrence.wkst = EventRecurrence.timeDay2Day(Utils.getFirstDayOfWeek(getActivity()));
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    boolean endCountHasFocus = false;
    if (savedInstanceState != null) {
        RecurrenceModel m = (RecurrenceModel) savedInstanceState.get(BUNDLE_MODEL);
        if (m != null) {
            mModel = m;
        }
        endCountHasFocus = savedInstanceState.getBoolean(BUNDLE_END_COUNT_HAS_FOCUS);
    } else {
        Bundle b = getArguments();
        if (b != null) {
            mTime.set(b.getLong(BUNDLE_START_TIME_MILLIS));
            String tz = b.getString(BUNDLE_TIME_ZONE);
            if (!TextUtils.isEmpty(tz)) {
                mTime.setTimezone(tz);
            }
            mTime.normalize();
            // Time days of week: Sun=0, Mon=1, etc
            mModel.weeklyByDayOfWeek[mTime.getWeekDay()] = true;
            String rrule = b.getString(BUNDLE_RRULE);
            if (!TextUtils.isEmpty(rrule)) {
                mModel.recurrenceState = RecurrenceModel.STATE_RECURRENCE;
                mRecurrence.parse(rrule);
                copyEventRecurrenceToModel(mRecurrence, mModel);
                // Leave today's day of week as checked by default in weekly view.
                if (mRecurrence.bydayCount == 0) {
                    mModel.weeklyByDayOfWeek[mTime.getWeekDay()] = true;
                }
            }
        } else {
            mTime.set(System.currentTimeMillis());
        }
    }
    mResources = getResources();
    mView = inflater.inflate(R.layout.recurrencepicker, container, true);
    final Activity activity = getActivity();
    final Configuration config = activity.getResources().getConfiguration();
    mRepeatSwitch = mView.findViewById(R.id.repeat_switch);
    mRepeatSwitch.setChecked(mModel.recurrenceState == RecurrenceModel.STATE_RECURRENCE);
    mRepeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mModel.recurrenceState = isChecked ? RecurrenceModel.STATE_RECURRENCE : RecurrenceModel.STATE_NO_RECURRENCE;
            togglePickerOptions();
        }
    });
    mFreqSpinner = (Spinner) mView.findViewById(R.id.freqSpinner);
    mFreqSpinner.setOnItemSelectedListener(this);
    ArrayAdapter<CharSequence> freqAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.recurrence_freq, R.layout.recurrencepicker_freq_item);
    freqAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mFreqSpinner.setAdapter(freqAdapter);
    mInterval = (EditText) mView.findViewById(R.id.interval);
    mInterval.addTextChangedListener(new minMaxTextWatcher(1, INTERVAL_DEFAULT, INTERVAL_MAX) {

        @Override
        void onChange(int v) {
            if (mIntervalResId != -1 && mInterval.getText().toString().length() > 0) {
                mModel.interval = v;
                updateIntervalText();
                mInterval.requestLayout();
            }
        }
    });
    mIntervalPreText = (TextView) mView.findViewById(R.id.intervalPreText);
    mIntervalPostText = (TextView) mView.findViewById(R.id.intervalPostText);
    mEndNeverStr = mResources.getString(R.string.recurrence_end_continously);
    mEndDateLabel = mResources.getString(R.string.recurrence_end_date_label);
    mEndCountLabel = mResources.getString(R.string.recurrence_end_count_label);
    mEndSpinnerArray.add(mEndNeverStr);
    mEndSpinnerArray.add(mEndDateLabel);
    mEndSpinnerArray.add(mEndCountLabel);
    mEndSpinner = (Spinner) mView.findViewById(R.id.endSpinner);
    mEndSpinner.setOnItemSelectedListener(this);
    mEndSpinnerAdapter = new EndSpinnerAdapter(getActivity(), mEndSpinnerArray, R.layout.recurrencepicker_freq_item, R.layout.recurrencepicker_end_text);
    mEndSpinnerAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mEndSpinner.setAdapter(mEndSpinnerAdapter);
    mEndCount = (EditText) mView.findViewById(R.id.endCount);
    mEndCount.addTextChangedListener(new minMaxTextWatcher(1, COUNT_DEFAULT, COUNT_MAX) {

        @Override
        void onChange(int v) {
            if (mModel.endCount != v) {
                mModel.endCount = v;
                updateEndCountText();
                mEndCount.requestLayout();
            }
        }
    });
    mPostEndCount = (TextView) mView.findViewById(R.id.postEndCount);
    mEndDateTextView = (TextView) mView.findViewById(R.id.endDate);
    mEndDateTextView.setOnClickListener(this);
    if (mModel.endDate == null) {
        mModel.endDate = new Time();
        mModel.endDate.set(mTime);
        switch(mModel.freq) {
            case RecurrenceModel.FREQ_DAILY:
            case RecurrenceModel.FREQ_WEEKLY:
                mModel.endDate.setMonth(mModel.endDate.getMonth() + 1);
                break;
            case RecurrenceModel.FREQ_MONTHLY:
                mModel.endDate.setMonth(mModel.endDate.getMonth() + 3);
                break;
            case RecurrenceModel.FREQ_YEARLY:
                mModel.endDate.setYear(mModel.endDate.getYear() + 3);
                break;
        }
        mModel.endDate.normalize();
    }
    mWeekGroup = (LinearLayout) mView.findViewById(R.id.weekGroup);
    mWeekGroup2 = (LinearLayout) mView.findViewById(R.id.weekGroup2);
    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    String[] dayOfWeekString = new DateFormatSymbols().getWeekdays();
    mMonthRepeatByDayOfWeekStrs = new String[7][];
    // from Time.SUNDAY as 0 through Time.SATURDAY as 6
    mMonthRepeatByDayOfWeekStrs[0] = mResources.getStringArray(R.array.repeat_by_nth_sun);
    mMonthRepeatByDayOfWeekStrs[1] = mResources.getStringArray(R.array.repeat_by_nth_mon);
    mMonthRepeatByDayOfWeekStrs[2] = mResources.getStringArray(R.array.repeat_by_nth_tues);
    mMonthRepeatByDayOfWeekStrs[3] = mResources.getStringArray(R.array.repeat_by_nth_wed);
    mMonthRepeatByDayOfWeekStrs[4] = mResources.getStringArray(R.array.repeat_by_nth_thurs);
    mMonthRepeatByDayOfWeekStrs[5] = mResources.getStringArray(R.array.repeat_by_nth_fri);
    mMonthRepeatByDayOfWeekStrs[6] = mResources.getStringArray(R.array.repeat_by_nth_sat);
    // In Time.java day of week order e.g. Sun = 0
    int idx = Utils.getFirstDayOfWeek(getActivity());
    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    dayOfWeekString = new DateFormatSymbols().getShortWeekdays();
    int numOfButtonsInRow1;
    int numOfButtonsInRow2;
    if (mResources.getConfiguration().screenWidthDp > MIN_SCREEN_WIDTH_FOR_SINGLE_ROW_WEEK) {
        numOfButtonsInRow1 = 7;
        numOfButtonsInRow2 = 0;
        mWeekGroup2.setVisibility(View.GONE);
        mWeekGroup2.getChildAt(3).setVisibility(View.GONE);
    } else {
        numOfButtonsInRow1 = 4;
        numOfButtonsInRow2 = 3;
        mWeekGroup2.setVisibility(View.VISIBLE);
        // Set rightmost button on the second row invisible so it takes up
        // space and everything centers properly
        mWeekGroup2.getChildAt(3).setVisibility(View.INVISIBLE);
    }
    /* First row */
    for (int i = 0; i < 7; i++) {
        if (i >= numOfButtonsInRow1) {
            mWeekGroup.getChildAt(i).setVisibility(View.GONE);
            continue;
        }
        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);
        if (++idx >= 7) {
            idx = 0;
        }
    }
    /* 2nd Row */
    for (int i = 0; i < 3; i++) {
        if (i >= numOfButtonsInRow2) {
            mWeekGroup2.getChildAt(i).setVisibility(View.GONE);
            continue;
        }
        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup2.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);
        if (++idx >= 7) {
            idx = 0;
        }
    }
    mMonthGroup = (LinearLayout) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup = (RadioGroup) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup.setOnCheckedChangeListener(this);
    mRepeatMonthlyByNthDayOfWeek = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfTheWeek);
    mRepeatMonthlyByNthDayOfMonth = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfMonth);
    mDone = (Button) mView.findViewById(R.id.done);
    mDone.setOnClickListener(this);
    togglePickerOptions();
    updateDialog();
    if (endCountHasFocus) {
        mEndCount.requestFocus();
    }
    return mView;
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Configuration(android.content.res.Configuration) Bundle(android.os.Bundle) Activity(android.app.Activity) Time(com.android.calendarcommon2.Time) DateFormatSymbols(java.text.DateFormatSymbols) CompoundButton(android.widget.CompoundButton)

Example 87 with Time

use of org.bouncycastle.asn1.x509.Time in project Etar-Calendar by Etar-Group.

the class CalendarAppWidgetModel method buildFromCursor.

public void buildFromCursor(Cursor cursor, String timeZone) {
    final Time recycle = new Time(timeZone);
    final ArrayList<LinkedList<RowInfo>> mBuckets = new ArrayList<LinkedList<RowInfo>>(CalendarAppWidgetService.MAX_DAYS);
    for (int i = 0; i < CalendarAppWidgetService.MAX_DAYS; i++) {
        mBuckets.add(new LinkedList<RowInfo>());
    }
    recycle.set(System.currentTimeMillis());
    mShowTZ = !TextUtils.equals(timeZone, Utils.getCurrentTimezone());
    if (mShowTZ) {
        mHomeTZName = TimeZone.getTimeZone(timeZone).getDisplayName(false, TimeZone.SHORT);
    }
    cursor.moveToPosition(-1);
    String tz = Utils.getTimeZone(mContext, null);
    while (cursor.moveToNext()) {
        final int rowId = cursor.getPosition();
        final long eventId = cursor.getLong(CalendarAppWidgetService.INDEX_EVENT_ID);
        final boolean allDay = cursor.getInt(CalendarAppWidgetService.INDEX_ALL_DAY) != 0;
        long start = cursor.getLong(CalendarAppWidgetService.INDEX_BEGIN);
        long end = cursor.getLong(CalendarAppWidgetService.INDEX_END);
        final String title = cursor.getString(CalendarAppWidgetService.INDEX_TITLE);
        final String location = cursor.getString(CalendarAppWidgetService.INDEX_EVENT_LOCATION);
        // we don't compute these ourselves because it seems to produce the
        // wrong endDay for all day events
        final int startDay = cursor.getInt(CalendarAppWidgetService.INDEX_START_DAY);
        final int endDay = cursor.getInt(CalendarAppWidgetService.INDEX_END_DAY);
        final int color = cursor.getInt(CalendarAppWidgetService.INDEX_COLOR);
        final int selfStatus = cursor.getInt(CalendarAppWidgetService.INDEX_SELF_ATTENDEE_STATUS);
        // Adjust all-day times into local timezone
        if (allDay) {
            start = Utils.convertAlldayUtcToLocal(recycle, start, tz);
            end = Utils.convertAlldayUtcToLocal(recycle, end, tz);
        }
        if (LOGD) {
            Log.d(TAG, "Row #" + rowId + " allDay:" + allDay + " start:" + start + " end:" + end + " eventId:" + eventId);
        }
        // deal with all-day events
        if (end < mNow) {
            continue;
        }
        int i = mEventInfos.size();
        mEventInfos.add(populateEventInfo(eventId, allDay, start, end, startDay, endDay, title, location, color, selfStatus));
        // populate the day buckets that this event falls into
        int from = Math.max(startDay, mTodayJulianDay);
        int to = Math.min(endDay, mMaxJulianDay);
        for (int day = from; day <= to; day++) {
            LinkedList<RowInfo> bucket = mBuckets.get(day - mTodayJulianDay);
            RowInfo rowInfo = new RowInfo(RowInfo.TYPE_MEETING, i);
            if (allDay) {
                bucket.addFirst(rowInfo);
            } else {
                bucket.add(rowInfo);
            }
        }
    }
    int day = mTodayJulianDay;
    int count = 0;
    for (LinkedList<RowInfo> bucket : mBuckets) {
        if (!bucket.isEmpty()) {
            // We don't show day header in today
            if (day != mTodayJulianDay) {
                final DayInfo dayInfo = populateDayInfo(day, recycle);
                // Add the day header
                final int dayIndex = mDayInfos.size();
                mDayInfos.add(dayInfo);
                mRowInfos.add(new RowInfo(RowInfo.TYPE_DAY, dayIndex));
            }
            // Add the event row infos
            mRowInfos.addAll(bucket);
            count += bucket.size();
        }
        day++;
        if (count >= CalendarAppWidgetService.EVENT_MIN_COUNT) {
            break;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Time(com.android.calendarcommon2.Time) LinkedList(java.util.LinkedList)

Example 88 with Time

use of org.bouncycastle.asn1.x509.Time in project Etar-Calendar by Etar-Group.

the class UtilsTests method createTimeInMillis.

private static long createTimeInMillis(int second, int minute, int hour, int monthDay, int month, int year, String timezone) {
    Time t = new Time(timezone);
    t.set(second, minute, hour, monthDay, month, year);
    t.normalize();
    return t.toMillis();
}
Also used : Time(com.android.calendarcommon2.Time)

Example 89 with Time

use of org.bouncycastle.asn1.x509.Time in project Etar-Calendar by Etar-Group.

the class CalendarAppWidgetServiceTest method setUp.

// TODO Disabled test since this CalendarAppWidgetModel is not used for the no event case
// 
// @SmallTest
// public void testGetAppWidgetModel_noEvents() throws Exception {
// // Input
// MatrixCursor cursor = new MatrixCursor(CalendarAppWidgetService.EVENT_PROJECTION, 0);
// 
// // Expected Output
// CalendarAppWidgetModel expected = new CalendarAppWidgetModel();
// expected.visibNoEvents = View.VISIBLE;
// 
// // Test
// long now = 1270000000000L;
// MarkedEvents events = CalendarAppWidgetService.buildMarkedEvents(cursor, null, now);
// CalendarAppWidgetModel actual = CalendarAppWidgetService.getAppWidgetModel(
// getTestContext(), cursor, events, now);
// 
// assertEquals(expected.toString(), actual.toString());
// }
@Override
protected void setUp() throws Exception {
    super.setUp();
    // we want to run these tests in a predictable timezone
    TimeZone.setDefault(TimeZone.getTimeZone(DEFAULT_TIMEZONE));
    // Set the "current time" to 2am tomorrow.
    Time time = new Time();
    time.set(System.currentTimeMillis());
    time.setDay(time.getDay() + 1);
    time.setHour(2);
    time.setMinute(0);
    time.setSecond(0);
    now = time.normalize();
}
Also used : Time(com.android.calendarcommon2.Time)

Example 90 with Time

use of org.bouncycastle.asn1.x509.Time in project pdfbox by apache.

the class TestCreateSignature method testAddValidationInformation.

/**
 * Test adding LTV information. This tests the status quo. If we use a new file (or if the file
 * gets updated) then the test may have to be adjusted. The test is not really perfect, but it
 * tries to check a minimum of things that should match. If the test fails and you didn't change
 * anything in signing, then find out whether some external servers involved are unresponsive.
 * At the time of writing this, the OCSP server http://ocsp.quovadisglobal.com responds with 502
 * "UNAUTHORIZED". That is not a problem as long as the CRL URL works.
 *
 * @throws java.io.IOException
 * @throws java.security.GeneralSecurityException
 * @throws org.bouncycastle.cert.ocsp.OCSPException
 * @throws org.bouncycastle.operator.OperatorCreationException
 * @throws org.bouncycastle.cms.CMSException
 */
@Test
void testAddValidationInformation() throws IOException, GeneralSecurityException, OCSPException, OperatorCreationException, CMSException {
    File inFile = new File("target/pdfs", "notCertified_368835_Sig_en_201026090509.pdf");
    String name = inFile.getName();
    String substring = name.substring(0, name.lastIndexOf('.'));
    File outFile = new File(OUT_DIR, substring + "_LTV.pdf");
    AddValidationInformation addValidationInformation = new AddValidationInformation();
    addValidationInformation.validateSignature(inFile, outFile);
    checkLTV(outFile);
}
Also used : AddValidationInformation(org.apache.pdfbox.examples.signature.validation.AddValidationInformation) BEROctetString(org.bouncycastle.asn1.BEROctetString) File(java.io.File) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

Time (com.android.calendarcommon2.Time)178 IOException (java.io.IOException)50 Date (java.util.Date)43 X509Certificate (java.security.cert.X509Certificate)37 BigInteger (java.math.BigInteger)32 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)32 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)32 X500Name (org.bouncycastle.asn1.x500.X500Name)28 DEROctetString (org.bouncycastle.asn1.DEROctetString)27 X509CertificateHolder (org.bouncycastle.cert.X509CertificateHolder)26 ArrayList (java.util.ArrayList)25 Paint (android.graphics.Paint)20 DERSequence (org.bouncycastle.asn1.DERSequence)17 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15 CertificateException (java.security.cert.CertificateException)15 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)15 Time (org.bouncycastle.asn1.x509.Time)15 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 SecureRandom (java.security.SecureRandom)14