Search in sources :

Example 21 with Time

use of dev.hawala.xns.level4.common.Time2.Time in project android_packages_apps_Etar by LineageOS.

the class SimpleWeekView method getDayFromLocation.

/**
 * Calculates the day that the given x position is in, accounting for week
 * number. Returns a Time referencing that day or null if
 *
 * @param x The x position of the touch event
 * @return A time object for the tapped day or null if the position wasn't
 *         in a day
 */
public Time getDayFromLocation(float x) {
    int dayStart = mPadding;
    if (x < dayStart || x > mWidth - mPadding) {
        return null;
    }
    // Selection is (x - start) / (pixels/day) == (x -s) * day / pixels
    int dayPosition = (int) ((x - dayStart) * mNumDays / (mWidth - dayStart - mPadding));
    int day = mFirstJulianDay + dayPosition;
    Time time = new Time(mTimeZone);
    if (mWeek == 0) {
        // This week is weird...
        if (day < Utils.EPOCH_JULIAN_DAY) {
            day++;
        } else if (day == Utils.EPOCH_JULIAN_DAY) {
            time.set(1, 0, 1970);
            time.normalize();
            return time;
        }
    }
    time.setJulianDay(day);
    return time;
}
Also used : Time(com.android.calendarcommon2.Time) Paint(android.graphics.Paint)

Example 22 with Time

use of dev.hawala.xns.level4.common.Time2.Time in project android_packages_apps_Etar by LineageOS.

the class MonthByWeekAdapter method setDayParameters.

private void setDayParameters(Time day) {
    day.setTimezone(mHomeTimeZone);
    Time currTime = new Time(mHomeTimeZone);
    currTime.set(mController.getTime());
    day.setHour(currTime.getHour());
    day.setMinute(currTime.getMinute());
    day.setAllDay(false);
    day.normalize();
}
Also used : Time(com.android.calendarcommon2.Time)

Example 23 with Time

use of dev.hawala.xns.level4.common.Time2.Time in project android_packages_apps_Etar by LineageOS.

the class RecurrencePickerDialog method onDateSet.

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    if (mModel.endDate == null) {
        mModel.endDate = new Time(mTime.getTimezone());
        mModel.endDate.setHour(0);
        mModel.endDate.setMinute(0);
        mModel.endDate.setSecond(0);
    }
    mModel.endDate.setYear(year);
    mModel.endDate.setMonth(monthOfYear);
    mModel.endDate.setDay(dayOfMonth);
    mModel.endDate.normalize();
    updateDialog();
}
Also used : Time(com.android.calendarcommon2.Time)

Example 24 with Time

use of dev.hawala.xns.level4.common.Time2.Time in project android_packages_apps_Etar by LineageOS.

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 25 with Time

use of dev.hawala.xns.level4.common.Time2.Time in project android_packages_apps_Etar by LineageOS.

the class CalendarAppWidgetProvider method performUpdate.

/**
 * Process and push out an update for the given appWidgetIds. This call
 * actually fires an intent to start {@link CalendarAppWidgetService} as a
 * background service which handles the actual update, to prevent ANR'ing
 * during database queries.
 *
 * @param context Context to use when starting {@link CalendarAppWidgetService}.
 * @param appWidgetIds List of specific appWidgetIds to update, or null for
 *            all.
 * @param changedEventIds Specific events known to be changed. If present,
 *            we use it to decide if an update is necessary.
 */
private void performUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, long[] changedEventIds) {
    if (!isWidgetSupported(context)) {
        return;
    }
    // Launch over to service so it can perform update
    for (int appWidgetId : appWidgetIds) {
        if (LOGD)
            Log.d(TAG, "Building widget update...");
        Intent updateIntent = new Intent(context, CalendarAppWidgetService.class);
        updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        if (changedEventIds != null) {
            updateIntent.putExtra(EXTRA_EVENT_IDS, changedEventIds);
        }
        updateIntent.setData(Uri.parse(updateIntent.toUri(Intent.URI_INTENT_SCHEME)));
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget);
        // Calendar header
        Time time = new Time(Utils.getTimeZone(context, null));
        time.set(System.currentTimeMillis());
        long millis = time.toMillis();
        final String dayOfWeek = DateUtils.getDayOfWeekString(time.getWeekDay() + 1, DateUtils.LENGTH_MEDIUM);
        final String date = Utils.formatDateRange(context, millis, millis, DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR);
        views.setTextViewText(R.id.day_of_week, dayOfWeek);
        views.setTextViewText(R.id.date, date);
        // Set widget header background based on chosen primary app color
        int headerColor = DynamicTheme.getColorId(DynamicTheme.getPrimaryColor(context));
        views.setInt(R.id.header, "setBackgroundResource", headerColor);
        // Set widget background color based on chosen app theme
        int backgroundColor = DynamicTheme.getWidgetBackgroundStyle(context);
        views.setInt(R.id.widget_background, "setBackgroundResource", backgroundColor);
        // Attach to list of events
        views.setRemoteAdapter(R.id.events_list, updateIntent);
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.events_list);
        // Launch calendar app when the user taps on the header
        final Intent launchCalendarIntent = new Intent(Intent.ACTION_VIEW);
        launchCalendarIntent.setClass(context, AllInOneActivity.class);
        launchCalendarIntent.setData(Uri.parse("content://com.android.calendar/time/" + millis));
        final PendingIntent launchCalendarPendingIntent = PendingIntent.getActivity(context, 0, /* no requestCode */
        launchCalendarIntent, Utils.PI_FLAG_IMMUTABLE);
        views.setOnClickPendingIntent(R.id.header, launchCalendarPendingIntent);
        // Open Add event option when user clicks on the add button on widget
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setClass(context, EditEventActivity.class);
        intent.putExtra(EXTRA_EVENT_ALL_DAY, false);
        intent.putExtra(CalendarContract.Events.CALENDAR_ID, -1);
        final PendingIntent addEventPendingIntent = PendingIntent.getActivity(context, 0, /* no requestCode */
        intent, PI_FLAG_IMMUTABLE);
        views.setOnClickPendingIntent(R.id.iv_add, addEventPendingIntent);
        // Each list item will call setOnClickExtra() to let the list know
        // which item
        // is selected by a user.
        final PendingIntent updateEventIntent = getLaunchPendingIntentTemplate(context);
        views.setPendingIntentTemplate(R.id.events_list, updateEventIntent);
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
Also used : RemoteViews(android.widget.RemoteViews) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Time(com.android.calendarcommon2.Time) PendingIntent(android.app.PendingIntent)

Aggregations

Time (com.android.calendarcommon2.Time)178 Paint (android.graphics.Paint)20 ArrayList (java.util.ArrayList)16 Time (org.bouncycastle.asn1.x509.Time)15 Intent (android.content.Intent)12 Uri (android.net.Uri)12 TextPaint (android.text.TextPaint)12 TextView (android.widget.TextView)12 Resources (android.content.res.Resources)10 ContentValues (android.content.ContentValues)8 Context (android.content.Context)8 Cursor (android.database.Cursor)8 View (android.view.View)8 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)8 EventRecurrence (com.android.calendarcommon2.EventRecurrence)8 DERSequence (org.bouncycastle.asn1.DERSequence)8 Date (java.util.Date)7 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)7 MotionEvent (android.view.MotionEvent)6 IOException (java.io.IOException)6