Solution for recurrence spinner issues

Bug: 8895602
Change-Id: I22b71def459fe8fc9ccf6b60144a5341d4db4655
diff --git a/res/layout/recurrencepicker.xml b/res/layout/recurrencepicker.xml
index cfe4b6a..9ad5a0d 100644
--- a/res/layout/recurrencepicker.xml
+++ b/res/layout/recurrencepicker.xml
@@ -223,6 +223,7 @@
                             android:layout_height="wrap_content"
                             android:layout_gravity="center_vertical"
                             android:gravity="bottom"
+                            android:singleLine="true"
                             android:layout_marginBottom="-3dp"
                             android:visibility="gone" />
 
@@ -234,6 +235,8 @@
                             android:layout_width="wrap_content"
                             android:layout_height="wrap_content"
                             android:layout_gravity="center"
+                            android:singleLine="true"
+                            android:minWidth="80dp"
                             android:contentDescription="@string/acessibility_recurrence_choose_end_date_description"
                             android:gravity="center_horizontal|bottom"
                             android:layout_marginTop="3dp"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5a71aae..49bcf87 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -718,16 +718,16 @@
     <!-- Repeat an monthly event on the same day of every month [CHAR LIMIT=20] -->
     <string name="recurrence_month_pattern_by_day">on the same day each month</string>
 
-    <!-- Specifies that a repeating event to repeat forever (based on the defined frequency) instead of ending at a future date[CHAR LIMIT=25] -->
+    <!-- Specifies that a repeating event to repeat forever (based on the defined frequency) instead of ending at a future date[CHAR LIMIT=20] -->
     <string name="recurrence_end_continously">Forever</string>
     <!-- Specifies that a repeating event to repeat until a certain date[CHAR LIMIT=25] -->
     <string name="recurrence_end_date_label">Until a date</string>
-    <!-- Specifies that a repeating event to repeat until a certain date[CHAR LIMIT=25] -->
+    <!-- Specifies that a repeating event to repeat until a certain date[CHAR LIMIT=20] -->
     <string name="recurrence_end_date">Until <xliff:g id="date">%s</xliff:g></string>
     <!-- Specifies that a repeating event to repeat for a number of times. A repeating event can repeat forever, repeat in a certain frequency until a certain date, or repeat for a number of times. e.g. repeat 10 times and stop. This string is for the last case [CHAR LIMIT=25] -->
     <string name="recurrence_end_count_label">For a number of events</string>
 
-    <!-- Specifies that a repeating event should repeat for a certain number of iterations. -->
+    <!-- Specifies that a repeating event should repeat for a certain number of iterations. [CHAR LIMIT=20]-->
     <plurals name="recurrence_end_count">
         <item quantity="one">For <xliff:g id="event_count">%d</xliff:g> event</item>
         <item quantity="other">For <xliff:g id="event_count">%d</xliff:g> events</item>
diff --git a/src/com/android/calendar/recurrencepicker/RecurrencePickerDialog.java b/src/com/android/calendar/recurrencepicker/RecurrencePickerDialog.java
index 580d211..a11591f 100644
--- a/src/com/android/calendar/recurrencepicker/RecurrencePickerDialog.java
+++ b/src/com/android/calendar/recurrencepicker/RecurrencePickerDialog.java
@@ -34,8 +34,8 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
-import android.view.ViewGroup.LayoutParams;
 import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
 import android.view.Window;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemSelectedListener;
@@ -56,7 +56,6 @@
 
 import com.android.calendar.R;
 import com.android.calendar.Utils;
-import com.android.calendar.CalendarController.ViewType;
 import com.android.calendarcommon2.EventRecurrence;
 import com.android.datetimepicker.date.DatePickerDialog;
 
@@ -1012,17 +1011,9 @@
                 mIntervalPreText.setText("");
             } else {
                 int postTextStart = markerStart + INTERVAL_COUNT_MARKER.length();
-                if (postTextStart < intervalString.length() &&
-                        intervalString.charAt(postTextStart) == ' ') {
-                    postTextStart++;
-                }
-                mIntervalPostText.setText(intervalString.subSequence(postTextStart,
-                        intervalString.length()));
-
-                if (intervalString.charAt(markerStart - 1) == ' ') {
-                    markerStart--;
-                }
-                mIntervalPreText.setText(intervalString.subSequence(0, markerStart));
+                mIntervalPostText.setText(intervalString.substring(postTextStart,
+                        intervalString.length()).trim());
+                mIntervalPreText.setText(intervalString.substring(0, markerStart).trim());
             }
         }
     }
@@ -1042,12 +1033,8 @@
                 Log.e(TAG, "No text to put in to recurrence's end spinner.");
             } else {
                 int postTextStart = markerStart + END_COUNT_MARKER.length();
-                if (postTextStart < endString.length() &&
-                        endString.charAt(postTextStart) == ' ') {
-                    postTextStart++;
-                }
-                mPostEndCount.setText(endString.subSequence(postTextStart,
-                        endString.length()));
+                mPostEndCount.setText(endString.substring(postTextStart,
+                        endString.length()).trim());
             }
         }
     }
@@ -1256,10 +1243,7 @@
                             // so we'll just set the whole "Until a date" string.
                             item.setText(mEndDateLabel);
                         } else {
-                            if (mEndDateString.charAt(markerStart - 1) == ' ') {
-                                markerStart--;
-                            }
-                            item.setText(mEndDateString.subSequence(0, markerStart));
+                            item.setText(mEndDateString.substring(0, markerStart).trim());
                         }
                     }
                     break;
@@ -1279,11 +1263,8 @@
                             mHidePostEndCount = true;
                         } else {
                             int postTextStart = markerStart + END_COUNT_MARKER.length();
-                            if (endString.charAt(postTextStart) == ' ') {
-                                postTextStart++;
-                            }
-                            mPostEndCount.setText(endString.subSequence(postTextStart,
-                                    endString.length()));
+                            mPostEndCount.setText(endString.substring(postTextStart,
+                                    endString.length()).trim());
                             // In case it's a recycled view that wasn't visible.
                             if (mModel.end == RecurrenceModel.END_BY_COUNT) {
                                 mPostEndCount.setVisibility(View.VISIBLE);
@@ -1291,7 +1272,7 @@
                             if (endString.charAt(markerStart - 1) == ' ') {
                                 markerStart--;
                             }
-                            item.setText(endString.subSequence(0, markerStart));
+                            item.setText(endString.substring(0, markerStart).trim());
                         }
                     }
                     break;