OSDN Git Service

Fixed the problem where newline characters appear as squares in calendar
authorMichael Chan <mchan@android.com>
Tue, 14 Jul 2009 23:04:32 +0000 (16:04 -0700)
committerMichael Chan <mchan@android.com>
Tue, 14 Jul 2009 23:16:52 +0000 (16:16 -0700)
src/com/android/calendar/CalendarView.java

index a608386..8db673b 100644 (file)
@@ -64,6 +64,8 @@ import android.widget.TextView;
 
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * This is the base class for a set of classes that implement views (day view
@@ -305,7 +307,7 @@ public class CalendarView extends View
 
     private String mDateRange;
     private TextView mTitleTextView;
-
+    
     public CalendarView(CalendarActivity activity) {
         super(activity);
         mResources = activity.getResources();
@@ -2147,6 +2149,17 @@ public class CalendarView extends View
         return rf;
     }
 
+    private Pattern drawTextSanitizerFilter = Pattern.compile("[\t\n],");
+
+    // Sanitize a string before passing it to drawText or else we get little
+    // squares. For newlines and tabs before a comma, delete the character.
+    // Otherwise, just replace them with a space.
+    private String drawTextSanitizer(String string) {
+        Matcher m = drawTextSanitizerFilter.matcher(string);
+        string = m.replaceAll(",").replace('\n', ' ').replace('\n', ' ');
+        return string;
+    }
+
     private void drawEventText(Event event, RectF rf, Canvas canvas, Paint p, int topMargin) {
         if (!mDrawTextInEventRect) {
             return;
@@ -2165,6 +2178,9 @@ public class CalendarView extends View
 
         // Truncate the event title to a known (large enough) limit
         String text = event.getTitleAndLocation();
+
+        text = drawTextSanitizer(text);
+
         int len = text.length();
         if (len > MAX_EVENT_TEXT_LEN) {
             text = text.substring(0, MAX_EVENT_TEXT_LEN);