Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions app/src/main/java/com/android/calendar/DayView.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Formatter;
import java.util.Locale;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -3133,6 +3134,12 @@ private void drawEvents(int date, int dayIndex, int top, Canvas canvas, Paint p)
selectionArea.right = selectionArea.left + cellWidth;

final ArrayList<Event> events = mEvents;

// Sort events by column, so they are drawn in order of column. This
// leads to events with the higher column number being drawn last, which
// ensures proper z-sorting when multiple events overlap.
events.sort(Comparator.comparingInt(Event::getColumn));

int numEvents = events.size();
EventGeometry geometry = mEventGeometry;

Expand Down Expand Up @@ -3163,6 +3170,7 @@ private void drawEvents(int date, int dayIndex, int top, Canvas canvas, Paint p)
if (r.top > viewEndY || r.bottom < mViewStartY) {
continue;
}

StaticLayout layout = getEventLayout(mLayouts, i, event, eventTextPaint, r);
// TODO: not sure why we are 4 pixels off
drawEventText(layout, r, canvas, mViewStartY + 4, mViewStartY + mViewHeight
Expand Down Expand Up @@ -4762,16 +4770,24 @@ private void findSelectedEvent(int x, int y) {

// If there are any events in the selected region, then assign the
// closest one to mSelectedEvent.
if (mSelectedEvents.size() > 0) {
if (!mSelectedEvents.isEmpty()) {
int len = mSelectedEvents.size();
Event closestEvent = null;
float minDist = mViewWidth + mViewHeight; // some large distance
float maxCol = -99999;
for (int index = 0; index < len; index++) {
Event ev = mSelectedEvents.get(index);

// dist will yield 0.0 for all events overlapping each other.
// In order to select the correct one we use the topmost event (i.e. the one with
// the highest col value!

float dist = geometry.pointToEvent(x, y, ev);
if (dist < minDist) {
float col = ev.getColumn();
if (dist <= minDist && col > maxCol) {
minDist = dist;
closestEvent = ev;
maxCol = col;
}
}
setSelectedEvent(closestEvent);
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/android/calendar/EventGeometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class EventGeometry {

private float mMinuteHeight;

// How many pixels is each column set off from the
// very left of column 0?
// This is used to enable stacked parallel events.
private static final float mPerColMargin = 32;

private float mHourGap;
private float mMinEventHeight;

Expand Down Expand Up @@ -97,8 +102,9 @@ public boolean computeEventRect(int date, int left, int top, int cellWidth, Even
event.bottom = event.top + mMinEventHeight;
}

float colWidth = (float) (cellWidth - (maxCols + 1) * mCellMargin) / (float) maxCols;
event.left = left + col * (colWidth + mCellMargin);

float colWidth = (float) (cellWidth - (maxCols) * mCellMargin) - (float) (col * mPerColMargin);
event.left = left + (col) * mPerColMargin;
event.right = event.left + colWidth;
return true;
}
Expand Down