Search in sources :

Example 1 with Event

use of com.android.calendar.Event in project Etar-Calendar by Etar-Group.

the class MonthWeekEventsView method onHoverEvent.

@Override
public boolean onHoverEvent(MotionEvent event) {
    Context context = getContext();
    // only send accessibility events if accessibility and exploration are
    // on.
    AccessibilityManager am = (AccessibilityManager) context.getSystemService(Service.ACCESSIBILITY_SERVICE);
    if (!am.isEnabled() || !am.isTouchExplorationEnabled()) {
        return super.onHoverEvent(event);
    }
    if (event.getAction() != MotionEvent.ACTION_HOVER_EXIT) {
        Time hover = getDayFromLocation(event.getX());
        if (hover != null && (mLastHoverTime == null || Time.compare(hover, mLastHoverTime) != 0)) {
            Long millis = hover.toMillis(true);
            String date = Utils.formatDateRange(context, millis, millis, DateUtils.FORMAT_SHOW_DATE);
            AccessibilityEvent accessEvent = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
            accessEvent.getText().add(date);
            if (mShowDetailsInMonth && mEvents != null) {
                int dayStart = SPACING_WEEK_NUMBER + mPadding;
                int dayPosition = (int) ((event.getX() - dayStart) * mNumDays / (mWidth - dayStart - mPadding));
                ArrayList<Event> events = mEvents.get(dayPosition);
                List<CharSequence> text = accessEvent.getText();
                for (Event e : events) {
                    text.add(e.getTitleAndLocation() + ". ");
                    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
                    if (!e.allDay) {
                        flags |= DateUtils.FORMAT_SHOW_TIME;
                        if (DateFormat.is24HourFormat(context)) {
                            flags |= DateUtils.FORMAT_24HOUR;
                        }
                    } else {
                        flags |= DateUtils.FORMAT_UTC;
                    }
                    text.add(Utils.formatDateRange(context, e.startMillis, e.endMillis, flags) + ". ");
                }
            }
            sendAccessibilityEventUnchecked(accessEvent);
            mLastHoverTime = hover;
        }
    }
    return true;
}
Also used : Context(android.content.Context) AccessibilityManager(android.view.accessibility.AccessibilityManager) MotionEvent(android.view.MotionEvent) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) Event(com.android.calendar.Event) Time(android.text.format.Time) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 2 with Event

use of com.android.calendar.Event in project Etar-Calendar by Etar-Group.

the class MonthByWeekAdapter method setEvents.

public void setEvents(int firstJulianDay, int numDays, ArrayList<Event> events) {
    if (mIsMiniMonth) {
        if (Log.isLoggable(TAG, Log.ERROR)) {
            Log.e(TAG, "Attempted to set events for mini view. Events only supported in full" + " view.");
        }
        return;
    }
    mEvents = events;
    mFirstJulianDay = firstJulianDay;
    mQueryDays = numDays;
    // Create a new list, this is necessary since the weeks are referencing
    // pieces of the old list
    ArrayList<ArrayList<Event>> eventDayList = new ArrayList<ArrayList<Event>>();
    for (int i = 0; i < numDays; i++) {
        eventDayList.add(new ArrayList<Event>());
    }
    if (events == null || events.size() == 0) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "No events. Returning early--go schedule something fun.");
        }
        mEventDayList = eventDayList;
        refresh();
        return;
    }
    // Compute the new set of days with events
    for (Event event : events) {
        int startDay = event.startDay - mFirstJulianDay;
        int endDay = event.endDay - mFirstJulianDay + 1;
        if (startDay < numDays || endDay >= 0) {
            if (startDay < 0) {
                startDay = 0;
            }
            if (startDay > numDays) {
                continue;
            }
            if (endDay < 0) {
                continue;
            }
            if (endDay > numDays) {
                endDay = numDays;
            }
            for (int j = startDay; j < endDay; j++) {
                eventDayList.get(j).add(event);
            }
        }
    }
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Processed " + events.size() + " events.");
    }
    mEventDayList = eventDayList;
    refresh();
}
Also used : ArrayList(java.util.ArrayList) Event(com.android.calendar.Event) MotionEvent(android.view.MotionEvent)

Example 3 with Event

use of com.android.calendar.Event in project Etar-Calendar by Etar-Group.

the class MonthByWeekFragment method onLoadFinished.

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    synchronized (mUpdateLoader) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Found " + data.getCount() + " cursor entries for uri " + mEventUri);
        }
        CursorLoader cLoader = (CursorLoader) loader;
        if (mEventUri == null) {
            mEventUri = cLoader.getUri();
            updateLoadedDays();
        }
        if (cLoader.getUri().compareTo(mEventUri) != 0) {
            // result
            return;
        }
        ArrayList<Event> events = new ArrayList<Event>();
        Event.buildEventsFromCursor(events, data, mContext, mFirstLoadedJulianDay, mLastLoadedJulianDay);
        ((MonthByWeekAdapter) mAdapter).setEvents(mFirstLoadedJulianDay, mLastLoadedJulianDay - mFirstLoadedJulianDay + 1, events);
    }
}
Also used : CursorLoader(android.content.CursorLoader) ArrayList(java.util.ArrayList) MotionEvent(android.view.MotionEvent) Event(com.android.calendar.Event)

Example 4 with Event

use of com.android.calendar.Event in project Etar-Calendar by Etar-Group.

the class MonthWeekEventsView method drawEvents.

protected void drawEvents(Canvas canvas) {
    if (mEvents == null) {
        return;
    }
    int day = -1;
    for (ArrayList<Event> eventDay : mEvents) {
        day++;
        if (eventDay == null || eventDay.size() == 0) {
            continue;
        }
        int ySquare;
        int xSquare = computeDayLeftPosition(day) + 1;
        int rightEdge = computeDayLeftPosition(day + 1);
        ySquare = EVENT_Y_OFFSET_PORTRAIT + mMonthNumHeight + TOP_PADDING_MONTH_NUMBER;
        rightEdge -= 1;
        // Determine if everything will fit when time ranges are shown.
        boolean showTimes = mShowTimeInMonth;
        Iterator<Event> iter = eventDay.iterator();
        int yTest = ySquare;
        while (iter.hasNext()) {
            Event event = iter.next();
            int newY = drawEvent(canvas, event, xSquare, yTest, rightEdge, iter.hasNext(), showTimes, /*doDraw*/
            false);
            if (newY == yTest) {
                showTimes = false;
                break;
            }
            yTest = newY;
        }
        int eventCount = 0;
        iter = eventDay.iterator();
        while (iter.hasNext()) {
            Event event = iter.next();
            int newY = drawEvent(canvas, event, xSquare, ySquare, rightEdge, iter.hasNext(), showTimes, /*doDraw*/
            true);
            if (newY == ySquare) {
                break;
            }
            eventCount++;
            ySquare = newY;
        }
        int remaining = eventDay.size() - eventCount;
        if (remaining > 0) {
            drawMoreEvents(canvas, remaining, xSquare);
        }
    }
}
Also used : MotionEvent(android.view.MotionEvent) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) Event(com.android.calendar.Event) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Aggregations

MotionEvent (android.view.MotionEvent)4 Event (com.android.calendar.Event)4 Paint (android.graphics.Paint)2 TextPaint (android.text.TextPaint)2 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)2 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 CursorLoader (android.content.CursorLoader)1 Time (android.text.format.Time)1 AccessibilityManager (android.view.accessibility.AccessibilityManager)1