diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-02 22:54:33 -0800 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-02 22:54:33 -0800 |
| commit | 3dec7d563a2f3e1eb967ce2054a00b6620e3558c (patch) | |
| tree | aa3b0365c47cb3c1607c0dc76c8d32b4046fc287 /core/java/android/text | |
| parent | 15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b (diff) | |
| download | frameworks_base-3dec7d563a2f3e1eb967ce2054a00b6620e3558c.zip frameworks_base-3dec7d563a2f3e1eb967ce2054a00b6620e3558c.tar.gz frameworks_base-3dec7d563a2f3e1eb967ce2054a00b6620e3558c.tar.bz2 | |
auto import from //depot/cupcake/@137055
Diffstat (limited to 'core/java/android/text')
| -rw-r--r-- | core/java/android/text/InputType.java | 5 | ||||
| -rw-r--r-- | core/java/android/text/Styled.java | 249 | ||||
| -rw-r--r-- | core/java/android/text/format/DateUtils.java | 216 | ||||
| -rw-r--r-- | core/java/android/text/method/NumberKeyListener.java | 5 |
4 files changed, 299 insertions, 176 deletions
diff --git a/core/java/android/text/InputType.java b/core/java/android/text/InputType.java index a073cf4..f643f92 100644 --- a/core/java/android/text/InputType.java +++ b/core/java/android/text/InputType.java @@ -128,11 +128,6 @@ public interface InputType { */ public static final int TYPE_TEXT_FLAG_IME_MULTI_LINE = 0x00040000; - /** - * Flag for {@link #TYPE_CLASS_TEXT}: flags any text being used as a search string - */ - public static final int TYPE_TEXT_FLAG_SEARCH = 0x00080000; - // ---------------------------------------------------------------------- /** diff --git a/core/java/android/text/Styled.java b/core/java/android/text/Styled.java index 05c27ea..0aa2004 100644 --- a/core/java/android/text/Styled.java +++ b/core/java/android/text/Styled.java @@ -16,25 +16,26 @@ package android.text; -import android.graphics.Paint; import android.graphics.Canvas; -import android.graphics.Path; -import android.graphics.RectF; -import android.graphics.Typeface; -import android.graphics.MaskFilter; -import android.graphics.Rasterizer; -import android.graphics.LayerRasterizer; -import android.text.style.*; - -/* package */ class Styled +import android.graphics.Paint; +import android.text.style.CharacterStyle; +import android.text.style.MetricAffectingSpan; +import android.text.style.ReplacementSpan; + +/** + * This class provides static methods for drawing and measuring styled texts, like + * {@link android.text.Spanned} object with {@link android.text.style.ReplacementSpan}. + * @hide + */ +public class Styled { private static float each(Canvas canvas, Spanned text, int start, int end, int dir, boolean reverse, float x, int top, int y, int bottom, - Paint.FontMetricsInt fm, - TextPaint realPaint, + Paint.FontMetricsInt fmi, TextPaint paint, + TextPaint workPaint, boolean needwid) { boolean havewid = false; @@ -43,9 +44,9 @@ import android.text.style.*; ReplacementSpan replacement = null; - realPaint.bgColor = 0; - realPaint.baselineShift = 0; - paint.set(realPaint); + paint.bgColor = 0; + paint.baselineShift = 0; + workPaint.set(paint); if (spans.length > 0) { for (int i = 0; i < spans.length; i++) { @@ -55,7 +56,7 @@ import android.text.style.*; replacement = (ReplacementSpan)span; } else { - span.updateDrawState(paint); + span.updateDrawState(workPaint); } } } @@ -74,66 +75,66 @@ import android.text.style.*; tmpend = end; } - if (fm != null) { - paint.getFontMetricsInt(fm); + if (fmi != null) { + workPaint.getFontMetricsInt(fmi); } if (canvas != null) { - if (paint.bgColor != 0) { - int c = paint.getColor(); - Paint.Style s = paint.getStyle(); - paint.setColor(paint.bgColor); - paint.setStyle(Paint.Style.FILL); + if (workPaint.bgColor != 0) { + int c = workPaint.getColor(); + Paint.Style s = workPaint.getStyle(); + workPaint.setColor(workPaint.bgColor); + workPaint.setStyle(Paint.Style.FILL); if (!havewid) { - ret = paint.measureText(tmp, tmpstart, tmpend); + ret = workPaint.measureText(tmp, tmpstart, tmpend); havewid = true; } if (dir == Layout.DIR_RIGHT_TO_LEFT) - canvas.drawRect(x - ret, top, x, bottom, paint); + canvas.drawRect(x - ret, top, x, bottom, workPaint); else - canvas.drawRect(x, top, x + ret, bottom, paint); + canvas.drawRect(x, top, x + ret, bottom, workPaint); - paint.setStyle(s); - paint.setColor(c); + workPaint.setStyle(s); + workPaint.setColor(c); } if (dir == Layout.DIR_RIGHT_TO_LEFT) { if (!havewid) { - ret = paint.measureText(tmp, tmpstart, tmpend); + ret = workPaint.measureText(tmp, tmpstart, tmpend); havewid = true; } canvas.drawText(tmp, tmpstart, tmpend, - x - ret, y + paint.baselineShift, paint); + x - ret, y + workPaint.baselineShift, workPaint); } else { if (needwid) { if (!havewid) { - ret = paint.measureText(tmp, tmpstart, tmpend); + ret = workPaint.measureText(tmp, tmpstart, tmpend); havewid = true; } } canvas.drawText(tmp, tmpstart, tmpend, - x, y + paint.baselineShift, paint); + x, y + workPaint.baselineShift, workPaint); } } else { if (needwid && !havewid) { - ret = paint.measureText(tmp, tmpstart, tmpend); + ret = workPaint.measureText(tmp, tmpstart, tmpend); havewid = true; } } } else { - ret = replacement.getSize(paint, text, start, end, fm); + ret = replacement.getSize(workPaint, text, start, end, fmi); if (canvas != null) { if (dir == Layout.DIR_RIGHT_TO_LEFT) replacement.draw(canvas, text, start, end, - x - ret, top, y, bottom, paint); + x - ret, top, y, bottom, workPaint); else replacement.draw(canvas, text, start, end, - x, top, y, bottom, paint); + x, top, y, bottom, workPaint); } } @@ -143,15 +144,29 @@ import android.text.style.*; return ret; } - public static int getTextWidths(TextPaint realPaint, - TextPaint paint, - Spanned text, int start, int end, - float[] widths, Paint.FontMetricsInt fm) { - + /** + * Return the advance widths for the characters in the string. + * See also {@link android.graphics.Paint#getTextWidths(CharSequence, int, int, float[])}. + * + * @param paint The main {@link TextPaint} object. + * @param workPaint The {@link TextPaint} object used for temporal workspace. + * @param text The text to measure + * @param start The index of the first char to to measure + * @param end The end of the text slice to measure + * @param widths Array to receive the advance widths of the characters. + * Must be at least a large as (end - start). + * @param fmi FontMetrics information. Can be null. + * @return The actual number of widths returned. + */ + public static int getTextWidths(TextPaint paint, + TextPaint workPaint, + Spanned text, int start, int end, + float[] widths, Paint.FontMetricsInt fmi) { + // Keep workPaint as is so that developers reuse the workspace. MetricAffectingSpan[] spans = text.getSpans(start, end, MetricAffectingSpan.class); ReplacementSpan replacement = null; - paint.set(realPaint); + workPaint.set(paint); for (int i = 0; i < spans.length; i++) { MetricAffectingSpan span = spans[i]; @@ -159,15 +174,15 @@ import android.text.style.*; replacement = (ReplacementSpan)span; } else { - span.updateMeasureState(paint); + span.updateMeasureState(workPaint); } } if (replacement == null) { - paint.getFontMetricsInt(fm); - paint.getTextWidths(text, start, end, widths); + workPaint.getFontMetricsInt(fmi); + workPaint.getTextWidths(text, start, end, widths); } else { - int wid = replacement.getSize(paint, text, start, end, fm); + int wid = replacement.getSize(workPaint, text, start, end, fmi); if (end > start) { widths[0] = wid; @@ -183,10 +198,10 @@ import android.text.style.*; CharSequence text, int start, int end, int dir, boolean reverse, float x, int top, int y, int bottom, - Paint.FontMetricsInt fm, + Paint.FontMetricsInt fmi, TextPaint paint, TextPaint workPaint, - boolean needwid) { + boolean needWidth) { if (! (text instanceof Spanned)) { float ret = 0; @@ -194,22 +209,22 @@ import android.text.style.*; CharSequence tmp = TextUtils.getReverse(text, start, end); int tmpend = end - start; - if (canvas != null || needwid) + if (canvas != null || needWidth) ret = paint.measureText(tmp, 0, tmpend); if (canvas != null) canvas.drawText(tmp, 0, tmpend, x - ret, y, paint); } else { - if (needwid) + if (needWidth) ret = paint.measureText(text, start, end); if (canvas != null) canvas.drawText(text, start, end, x, y, paint); } - if (fm != null) { - paint.getFontMetricsInt(fm); + if (fmi != null) { + paint.getFontMetricsInt(fmi); } return ret * dir; //Layout.DIR_RIGHT_TO_LEFT == -1 @@ -232,67 +247,129 @@ import android.text.style.*; next = sp.nextSpanTransition(i, end, division); x += each(canvas, sp, i, next, dir, reverse, - x, top, y, bottom, fm, paint, workPaint, - needwid || next != end); - - if (fm != null) { - if (fm.ascent < asc) - asc = fm.ascent; - if (fm.descent > desc) - desc = fm.descent; - - if (fm.top < ftop) - ftop = fm.top; - if (fm.bottom > fbot) - fbot = fm.bottom; + x, top, y, bottom, fmi, paint, workPaint, + needWidth || next != end); + + if (fmi != null) { + if (fmi.ascent < asc) + asc = fmi.ascent; + if (fmi.descent > desc) + desc = fmi.descent; + + if (fmi.top < ftop) + ftop = fmi.top; + if (fmi.bottom > fbot) + fbot = fmi.bottom; } } - if (fm != null) { + if (fmi != null) { if (start == end) { - paint.getFontMetricsInt(fm); + paint.getFontMetricsInt(fmi); } else { - fm.ascent = asc; - fm.descent = desc; - fm.top = ftop; - fm.bottom = fbot; + fmi.ascent = asc; + fmi.descent = desc; + fmi.top = ftop; + fmi.bottom = fbot; } } return x - ox; } - public static float drawText(Canvas canvas, - CharSequence text, int start, int end, - int dir, boolean reverse, - float x, int top, int y, int bottom, - TextPaint paint, - TextPaint workPaint, - boolean needwid) { - if ((dir == Layout.DIR_RIGHT_TO_LEFT && !reverse)||(reverse && dir == Layout.DIR_LEFT_TO_RIGHT)) { + + /* package */ static float drawText(Canvas canvas, + CharSequence text, int start, int end, + int direction, boolean reverse, + float x, int top, int y, int bottom, + TextPaint paint, + TextPaint workPaint, + boolean needWidth) { + if ((direction == Layout.DIR_RIGHT_TO_LEFT && !reverse) || + (reverse && direction == Layout.DIR_LEFT_TO_RIGHT)) { float ch = foreach(null, text, start, end, Layout.DIR_LEFT_TO_RIGHT, false, 0, 0, 0, 0, null, paint, workPaint, true); - ch *= dir; // DIR_RIGHT_TO_LEFT == -1 - foreach(canvas, text, start, end, -dir, + ch *= direction; // DIR_RIGHT_TO_LEFT == -1 + foreach(canvas, text, start, end, -direction, reverse, x + ch, top, y, bottom, null, paint, workPaint, true); return ch; } - return foreach(canvas, text, start, end, dir, reverse, + return foreach(canvas, text, start, end, direction, reverse, x, top, y, bottom, null, paint, workPaint, - needwid); + needWidth); } - + + /** + * Draw the specified range of text, specified by start/end, with its origin at (x,y), + * in the specified Paint. The origin is interpreted based on the Align setting in the + * Paint. + * + * This method considers style information in the text + * (e.g. Even when text is an instance of {@link android.text.Spanned}, this method + * correctly draws the text). + * See also + * {@link android.graphics.Canvas#drawText(CharSequence, int, int, float, float, Paint)} + * and + * {@link android.graphics.Canvas#drawRect(float, float, float, float, Paint)}. + * + * @param canvas The target canvas. + * @param text The text to be drawn + * @param start The index of the first character in text to draw + * @param end (end - 1) is the index of the last character in text to draw + * @param direction The direction of the text. This must be + * {@link android.text.Layout#DIR_LEFT_TO_RIGHT} or + * {@link android.text.Layout#DIR_RIGHT_TO_LEFT}. + * @param x The x-coordinate of origin for where to draw the text + * @param top The top side of the rectangle to be drawn + * @param y The y-coordinate of origin for where to draw the text + * @param bottom The bottom side of the rectangle to be drawn + * @param paint The main {@link TextPaint} object. + * @param workPaint The {@link TextPaint} object used for temporal workspace. + * @param needWidth If true, this method returns the width of drawn text. + * @return Width of the drawn text if needWidth is true. + */ + public static float drawText(Canvas canvas, + CharSequence text, int start, int end, + int direction, + float x, int top, int y, int bottom, + TextPaint paint, + TextPaint workPaint, + boolean needWidth) { + // For safety. + direction = direction >= 0 ? Layout.DIR_LEFT_TO_RIGHT : Layout.DIR_RIGHT_TO_LEFT; + /* + * Hided "reverse" parameter since it is meaningless for external developers. + * Kept workPaint as is so that developers reuse the workspace. + */ + return drawText(canvas, text, start, end, direction, false, + x, top, y, bottom, paint, workPaint, needWidth); + } + + /** + * Return the width of the text, considering style information in the text + * (e.g. Even when text is an instance of {@link android.text.Spanned}, this method + * correctly mesures the width of the text). + * + * @param paint The main {@link TextPaint} object. + * @param workPaint The {@link TextPaint} object used for temporal workspace. + * @param text The text to measure + * @param start The index of the first character to start measuring + * @param end 1 beyond the index of the last character to measure + * @param fmi FontMetrics information. Can be null + * @return The width of the text + */ public static float measureText(TextPaint paint, TextPaint workPaint, CharSequence text, int start, int end, - Paint.FontMetricsInt fm) { + Paint.FontMetricsInt fmi) { + // Keep workPaint as is so that developers reuse the workspace. return foreach(null, text, start, end, Layout.DIR_LEFT_TO_RIGHT, false, - 0, 0, 0, 0, fm, paint, workPaint, true); + 0, 0, 0, 0, fmi, paint, workPaint, true); } } diff --git a/core/java/android/text/format/DateUtils.java b/core/java/android/text/format/DateUtils.java index feae6cf..8a7cdd9 100644 --- a/core/java/android/text/format/DateUtils.java +++ b/core/java/android/text/format/DateUtils.java @@ -595,6 +595,17 @@ public class DateUtils * @param elapsedSeconds the elapsed time in seconds. */ public static String formatElapsedTime(long elapsedSeconds) { + return formatElapsedTime(null, elapsedSeconds); + } + + /** + * Formats an elapsed time in the form "MM:SS" or "H:MM:SS" + * for display on the call-in-progress screen. + * + * @param recycle {@link StringBuilder} to recycle, if possible + * @param elapsedSeconds the elapsed time in seconds. + */ + public static String formatElapsedTime(StringBuilder recycle, long elapsedSeconds) { initFormatStrings(); long hours = 0; @@ -613,18 +624,24 @@ public class DateUtils String result; if (hours > 0) { - return formatElapsedTime(sElapsedFormatHMMSS, hours, minutes, seconds); + return formatElapsedTime(recycle, sElapsedFormatHMMSS, hours, minutes, seconds); } else { - return formatElapsedTime(sElapsedFormatMMSS, minutes, seconds); + return formatElapsedTime(recycle, sElapsedFormatMMSS, minutes, seconds); } } /** * Fast formatting of h:mm:ss */ - private static String formatElapsedTime(String format, long hours, long minutes, long seconds) { + private static String formatElapsedTime(StringBuilder recycle, String format, long hours, + long minutes, long seconds) { if (FAST_FORMAT_HMMSS.equals(format)) { - StringBuffer sb = new StringBuffer(16); + StringBuilder sb = recycle; + if (sb == null) { + sb = new StringBuilder(8); + } else { + sb.setLength(0); + } sb.append(hours); sb.append(TIME_SEPARATOR); if (minutes < 10) { @@ -649,9 +666,15 @@ public class DateUtils /** * Fast formatting of m:ss */ - private static String formatElapsedTime(String format, long minutes, long seconds) { + private static String formatElapsedTime(StringBuilder recycle, String format, long minutes, + long seconds) { if (FAST_FORMAT_MMSS.equals(format)) { - StringBuffer sb = new StringBuffer(16); + StringBuilder sb = recycle; + if (sb == null) { + sb = new StringBuilder(8); + } else { + sb.setLength(0); + } if (minutes < 10) { sb.append(TIME_PADDING); } else { @@ -1028,8 +1051,9 @@ public class DateUtils * If FORMAT_NO_YEAR is set, then the year is not shown. * If neither FORMAT_SHOW_YEAR nor FORMAT_NO_YEAR are set, then the year * is shown only if it is different from the current year, or if the start - * and end dates fall on different years. - * + * and end dates fall on different years. If both are set, + * FORMAT_SHOW_YEAR takes precedence. + * * <p> * Normally the date is shown unless the start and end day are the same. * If FORMAT_SHOW_DATE is set, then the date is always shown, even for @@ -1120,24 +1144,28 @@ public class DateUtils boolean abbrevMonth = (flags & (FORMAT_ABBREV_MONTH | FORMAT_ABBREV_ALL)) != 0; boolean noMonthDay = (flags & FORMAT_NO_MONTH_DAY) != 0; boolean numericDate = (flags & FORMAT_NUMERIC_DATE) != 0; - - Time startDate; + + // If we're getting called with a single instant in time (from + // e.g. formatDateTime(), below), then we can skip a lot of + // computation below that'd otherwise be thrown out. + boolean isInstant = (startMillis == endMillis); + + Time startDate = useUTC ? new Time(Time.TIMEZONE_UTC) : new Time(); + startDate.set(startMillis); + Time endDate; - - if (useUTC) { - startDate = new Time(Time.TIMEZONE_UTC); - endDate = new Time(Time.TIMEZONE_UTC); + int dayDistance; + if (isInstant) { + endDate = startDate; + dayDistance = 0; } else { - startDate = new Time(); - endDate = new Time(); + endDate = useUTC ? new Time(Time.TIMEZONE_UTC) : new Time(); + endDate.set(endMillis); + int startJulianDay = Time.getJulianDay(startMillis, startDate.gmtoff); + int endJulianDay = Time.getJulianDay(endMillis, endDate.gmtoff); + dayDistance = endJulianDay - startJulianDay; } - - startDate.set(startMillis); - endDate.set(endMillis); - int startJulianDay = Time.getJulianDay(startMillis, startDate.gmtoff); - int endJulianDay = Time.getJulianDay(endMillis, endDate.gmtoff); - int dayDistance = endJulianDay - startJulianDay; - + // If the end date ends at 12am at the beginning of a day, // then modify it to make it look like it ends at midnight on // the previous day. This will allow us to display "8pm - midnight", @@ -1152,20 +1180,21 @@ public class DateUtils // and an end date of Nov 12 at 00:00. // If the start and end time are the same, then skip this and don't // adjust the date. - if ((endDate.hour | endDate.minute | endDate.second) == 0 - && (!showTime || dayDistance <= 1) && (startMillis != endMillis)) { + if (!isInstant + && (endDate.hour | endDate.minute | endDate.second) == 0 + && (!showTime || dayDistance <= 1)) { endDate.monthDay -= 1; endDate.normalize(true /* ignore isDst */); } - + int startDay = startDate.monthDay; int startMonthNum = startDate.month; int startYear = startDate.year; - + int endDay = endDate.monthDay; int endMonthNum = endDate.month; int endYear = endDate.year; - + String startWeekDayString = ""; String endWeekDayString = ""; if (showWeekDay) { @@ -1176,9 +1205,9 @@ public class DateUtils weekDayFormat = WEEKDAY_FORMAT; } startWeekDayString = startDate.format(weekDayFormat); - endWeekDayString = endDate.format(weekDayFormat); + endWeekDayString = isInstant ? startWeekDayString : endDate.format(weekDayFormat); } - + String startTimeString = ""; String endTimeString = ""; if (showTime) { @@ -1204,7 +1233,7 @@ public class DateUtils boolean capNoon = (flags & FORMAT_CAP_NOON) != 0; boolean noMidnight = (flags & FORMAT_NO_MIDNIGHT) != 0; boolean capMidnight = (flags & FORMAT_CAP_MIDNIGHT) != 0; - + boolean startOnTheHour = startDate.minute == 0 && startDate.second == 0; boolean endOnTheHour = endDate.minute == 0 && endDate.second == 0; if (abbrevTime && startOnTheHour) { @@ -1220,20 +1249,41 @@ public class DateUtils startTimeFormat = res.getString(com.android.internal.R.string.hour_minute_ampm); } } - if (abbrevTime && endOnTheHour) { - if (capAMPM) { - endTimeFormat = res.getString(com.android.internal.R.string.hour_cap_ampm); + + // Don't waste time on setting endTimeFormat when + // we're dealing with an instant, where we'll never + // need the end point. (It's the same as the start + // point) + if (!isInstant) { + if (abbrevTime && endOnTheHour) { + if (capAMPM) { + endTimeFormat = res.getString(com.android.internal.R.string.hour_cap_ampm); + } else { + endTimeFormat = res.getString(com.android.internal.R.string.hour_ampm); + } } else { - endTimeFormat = res.getString(com.android.internal.R.string.hour_ampm); + if (capAMPM) { + endTimeFormat = res.getString(com.android.internal.R.string.hour_minute_cap_ampm); + } else { + endTimeFormat = res.getString(com.android.internal.R.string.hour_minute_ampm); + } } - } else { - if (capAMPM) { - endTimeFormat = res.getString(com.android.internal.R.string.hour_minute_cap_ampm); - } else { - endTimeFormat = res.getString(com.android.internal.R.string.hour_minute_ampm); + + if (endDate.hour == 12 && endOnTheHour && !noNoon) { + if (capNoon) { + endTimeFormat = res.getString(com.android.internal.R.string.Noon); + } else { + endTimeFormat = res.getString(com.android.internal.R.string.noon); + } + } else if (endDate.hour == 0 && endOnTheHour && !noMidnight) { + if (capMidnight) { + endTimeFormat = res.getString(com.android.internal.R.string.Midnight); + } else { + endTimeFormat = res.getString(com.android.internal.R.string.midnight); + } } } - + if (startDate.hour == 12 && startOnTheHour && !noNoon) { if (capNoon) { startTimeFormat = res.getString(com.android.internal.R.string.Noon); @@ -1243,37 +1293,32 @@ public class DateUtils // Don't show the start time starting at midnight. Show // 12am instead. } - - if (endDate.hour == 12 && endOnTheHour && !noNoon) { - if (capNoon) { - endTimeFormat = res.getString(com.android.internal.R.string.Noon); - } else { - endTimeFormat = res.getString(com.android.internal.R.string.noon); - } - } else if (endDate.hour == 0 && endOnTheHour && !noMidnight) { - if (capMidnight) { - endTimeFormat = res.getString(com.android.internal.R.string.Midnight); - } else { - endTimeFormat = res.getString(com.android.internal.R.string.midnight); - } - } } + startTimeString = startDate.format(startTimeFormat); - endTimeString = endDate.format(endTimeFormat); + endTimeString = isInstant ? startTimeString : endDate.format(endTimeFormat); } - - // Get the current year - long millis = System.currentTimeMillis(); - Time time = new Time(); - time.set(millis); - int currentYear = time.year; - + // Show the year if the user specified FORMAT_SHOW_YEAR or if // the starting and end years are different from each other // or from the current year. But don't show the year if the - // user specified FORMAT_NO_YEAR; - showYear = showYear || (!noYear && (startYear != endYear || startYear != currentYear)); - + // user specified FORMAT_NO_YEAR. + if (showYear) { + // No code... just a comment for clarity. Keep showYear + // on, as they enabled it with FORMAT_SHOW_YEAR. This + // takes precedence over them setting FORMAT_NO_YEAR. + } else if (noYear) { + // They explicitly didn't want a year. + showYear = false; + } else if (startYear != endYear) { + showYear = true; + } else { + // Show the year if it's not equal to the current year. + Time currentTime = new Time(); + currentTime.setToNow(); + showYear = startYear != currentTime.year; + } + String defaultDateFormat, fullFormat, dateRange; if (numericDate) { defaultDateFormat = res.getString(com.android.internal.R.string.numeric_date); @@ -1306,7 +1351,7 @@ public class DateUtils } } } - + if (showWeekDay) { if (showTime) { fullFormat = res.getString(com.android.internal.R.string.wday1_date1_time1_wday2_date2_time2); @@ -1320,20 +1365,20 @@ public class DateUtils fullFormat = res.getString(com.android.internal.R.string.date1_date2); } } - + if (noMonthDay && startMonthNum == endMonthNum) { // Example: "January, 2008" String startDateString = startDate.format(defaultDateFormat); return startDateString; } - + if (startYear != endYear || noMonthDay) { // Different year or we are not showing the month day number. // Example: "December 31, 2007 - January 1, 2008" // Or: "January - February, 2008" String startDateString = startDate.format(defaultDateFormat); String endDateString = endDate.format(defaultDateFormat); - + // The values that are used in a fullFormat string are specified // by position. dateRange = String.format(fullFormat, @@ -1341,7 +1386,7 @@ public class DateUtils endWeekDayString, endDateString, endTimeString); return dateRange; } - + // Get the month, day, and year strings for the start and end dates String monthFormat; if (numericDate) { @@ -1354,16 +1399,17 @@ public class DateUtils String startMonthString = startDate.format(monthFormat); String startMonthDayString = startDate.format(MONTH_DAY_FORMAT); String startYearString = startDate.format(YEAR_FORMAT); - String endMonthString = endDate.format(monthFormat); - String endMonthDayString = endDate.format(MONTH_DAY_FORMAT); - String endYearString = endDate.format(YEAR_FORMAT); - + + String endMonthString = isInstant ? null : endDate.format(monthFormat); + String endMonthDayString = isInstant ? null : endDate.format(MONTH_DAY_FORMAT); + String endYearString = isInstant ? null : endDate.format(YEAR_FORMAT); + if (startMonthNum != endMonthNum) { // Same year, different month. // Example: "October 28 - November 3" // or: "Wed, Oct 31 - Sat, Nov 3, 2007" // or: "Oct 31, 8am - Sat, Nov 3, 2007, 5pm" - + int index = 0; if (showWeekDay) index = 1; if (showYear) index += 2; @@ -1371,7 +1417,7 @@ public class DateUtils if (numericDate) index += 8; int resId = sameYearTable[index]; fullFormat = res.getString(resId); - + // The values that are used in a fullFormat string are specified // by position. dateRange = String.format(fullFormat, @@ -1381,7 +1427,7 @@ public class DateUtils endYearString, endTimeString); return dateRange; } - + if (startDay != endDay) { // Same month, different day. int index = 0; @@ -1391,7 +1437,7 @@ public class DateUtils if (numericDate) index += 8; int resId = sameMonthTable[index]; fullFormat = res.getString(resId); - + // The values that are used in a fullFormat string are specified // by position. dateRange = String.format(fullFormat, @@ -1401,19 +1447,19 @@ public class DateUtils endYearString, endTimeString); return dateRange; } - + // Same start and end day boolean showDate = (flags & FORMAT_SHOW_DATE) != 0; - + // If nothing was specified, then show the date. if (!showTime && !showDate && !showWeekDay) showDate = true; - + // Compute the time string (example: "10:00 - 11:00 am") String timeString = ""; if (showTime) { // If the start and end time are the same, then just show the // start time. - if (startMillis == endMillis) { + if (isInstant) { // Same start and end time. // Example: "10:15 AM" timeString = startTimeString; @@ -1423,7 +1469,7 @@ public class DateUtils timeString = String.format(timeFormat, startTimeString, endTimeString); } } - + // Figure out which full format to use. fullFormat = ""; String dateString = ""; @@ -1457,7 +1503,7 @@ public class DateUtils } else if (showTime) { return timeString; } - + // The values that are used in a fullFormat string are specified // by position. dateRange = String.format(fullFormat, timeString, startWeekDayString, dateString); diff --git a/core/java/android/text/method/NumberKeyListener.java b/core/java/android/text/method/NumberKeyListener.java index e500fae..9270ca5 100644 --- a/core/java/android/text/method/NumberKeyListener.java +++ b/core/java/android/text/method/NumberKeyListener.java @@ -101,6 +101,11 @@ public abstract class NumberKeyListener extends BaseKeyListener selEnd = Math.max(a, b); } + if (selStart < 0 || selEnd < 0) { + selStart = selEnd = 0; + Selection.setSelection(content, 0); + } + int i = event != null ? lookup(event, content) : 0; int repeatCount = event != null ? event.getRepeatCount() : 0; if (repeatCount == 0) { |
