Refrain user-unfriendly overwrap. Do not merge

Bug: 3031917
Change-Id: I0b450806abd808c7b7c0293115c20e8c83a93d9c
diff --git a/src/com/android/calendar/CalendarView.java b/src/com/android/calendar/CalendarView.java
index e012d89..bf9ca21 100644
--- a/src/com/android/calendar/CalendarView.java
+++ b/src/com/android/calendar/CalendarView.java
@@ -260,6 +260,28 @@
     private static final int MAX_EVENT_TEXT_LEN = 500;
     private static float MIN_EVENT_HEIGHT = 15.0F;  // in pixels
 
+    // This value forces the position calculator to take care of the overwap which can't be
+    // detected from the view of event time but actually is detected when rendering them.
+    //
+    // Detail:
+    // Imagine there are two events: A (from 1:00pm to 1:01pm) and B (from 1:02pm to 2:00pm).
+    // The position calculator (Event#doComputePositions()), marks them as "not overwrapped"
+    // as A finishes before B's begin time, so those events are put on the same column
+    // (or, horizontal position).
+    // From the view of renderer, however, the actual rectangle for A is larger than "1 min."
+    // for accomodating at least 1 line of text in it.
+    // As a result, A's rectangle is overwrapped by B's, and A becomes hard to be touched
+    // without trackball or DPAD (as, it is beneath B from the user' view).
+    // This values forces the original calculator to take care of the actual overwrap detected in
+    // rendering time.
+    //
+    // Note:
+    // Theoretically we can calcurate an ideal value for this purpose by making the calculator
+    // understand the relation between each event and pixel-level height of actual rectangles,
+    // but we don't do so as currently the calculator doesn't have convenient way to obtain
+    // necessary values for the calculation.
+    /* package */ static int EVENT_OVERWRAP_MARGIN_TIME = MILLIS_PER_MINUTE * 15;
+
     private static int mSelectionColor;
     private static int mPressedColor;
     private static int mSelectedEventTextColor;
diff --git a/src/com/android/calendar/Event.java b/src/com/android/calendar/Event.java
index 32a6131..87cc705 100644
--- a/src/com/android/calendar/Event.java
+++ b/src/com/android/calendar/Event.java
@@ -402,7 +402,7 @@
      *
      * @param eventsList the list of events, sorted into increasing time order
      */
-    static void computePositions(ArrayList<Event> eventsList) {
+    private static void computePositions(ArrayList<Event> eventsList) {
         if (eventsList == null)
             return;
 
@@ -432,13 +432,16 @@
                         + " "  + e.title);
             }
 
-            // Remove the inactive events. An event on the active list
-            // becomes inactive when its end time is less than or equal to
-            // the current event's start time.
+            // Remove the inactive events.
+            // An event on the active list becomes inactive when its end time + margin time is less
+            // than or equal to the current event's start time. For more information about
+            // the margin time, see the comment in EVENT_OVERWRAP_MARGIN_TIME.
             Iterator<Event> iter = activeList.iterator();
             while (iter.hasNext()) {
                 Event active = iter.next();
-                if (active.getEndMillis() <= start) {
+                float duration = Math.max(active.getEndMillis() - active.getStartMillis(),
+                        CalendarView.EVENT_OVERWRAP_MARGIN_TIME);
+                if ((active.getStartMillis() + duration) <= start) {
                     if (false && event.allDay) {
                         Event e = active;
                         Log.i("Cal", "  removing: start,end day: " + e.startDay + "," + e.endDay