Merge "Pull weekday names directly from ICU" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a3a3f35e8d
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package android.widget;
|
package android.widget;
|
||||||
|
|
||||||
|
import com.android.internal.R;
|
||||||
|
import com.android.internal.widget.ExploreByTouchHelper;
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
@@ -44,14 +47,13 @@ import android.view.accessibility.AccessibilityEvent;
|
|||||||
import android.view.accessibility.AccessibilityNodeInfo;
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
|
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
|
||||||
|
|
||||||
import com.android.internal.R;
|
|
||||||
import com.android.internal.widget.ExploreByTouchHelper;
|
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import libcore.icu.LocaleData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A calendar-like view displaying a specified month and the appropriate selectable day numbers
|
* A calendar-like view displaying a specified month and the appropriate selectable day numbers
|
||||||
* within the specified month.
|
* within the specified month.
|
||||||
@@ -66,7 +68,6 @@ class SimpleMonthView extends View {
|
|||||||
private static final int DEFAULT_WEEK_START = Calendar.SUNDAY;
|
private static final int DEFAULT_WEEK_START = Calendar.SUNDAY;
|
||||||
|
|
||||||
private static final String MONTH_YEAR_FORMAT = "MMMMy";
|
private static final String MONTH_YEAR_FORMAT = "MMMMy";
|
||||||
private static final String DAY_OF_WEEK_FORMAT = "EEEEE";
|
|
||||||
|
|
||||||
private static final int SELECTED_HIGHLIGHT_ALPHA = 0xB0;
|
private static final int SELECTED_HIGHLIGHT_ALPHA = 0xB0;
|
||||||
|
|
||||||
@@ -80,6 +81,7 @@ class SimpleMonthView extends View {
|
|||||||
private final Paint mDayHighlightPaint = new Paint();
|
private final Paint mDayHighlightPaint = new Paint();
|
||||||
private final Paint mDayHighlightSelectorPaint = new Paint();
|
private final Paint mDayHighlightSelectorPaint = new Paint();
|
||||||
|
|
||||||
|
/** Array of single-character weekday labels ordered by column index. */
|
||||||
private final String[] mDayOfWeekLabels = new String[7];
|
private final String[] mDayOfWeekLabels = new String[7];
|
||||||
|
|
||||||
private final Calendar mCalendar;
|
private final Calendar mCalendar;
|
||||||
@@ -120,7 +122,7 @@ class SimpleMonthView extends View {
|
|||||||
*/
|
*/
|
||||||
private int mToday = DEFAULT_SELECTED_DAY;
|
private int mToday = DEFAULT_SELECTED_DAY;
|
||||||
|
|
||||||
/** The first day of the week (ex. Calendar.SUNDAY). */
|
/** The first day of the week (ex. Calendar.SUNDAY) indexed from one. */
|
||||||
private int mWeekStart = DEFAULT_WEEK_START;
|
private int mWeekStart = DEFAULT_WEEK_START;
|
||||||
|
|
||||||
/** The number of days (ex. 28) in the current month. */
|
/** The number of days (ex. 28) in the current month. */
|
||||||
@@ -199,13 +201,11 @@ class SimpleMonthView extends View {
|
|||||||
Log.d(LOG_TAG, "mWeekStart => " + mWeekStart);
|
Log.d(LOG_TAG, "mWeekStart => " + mWeekStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Calendar calendar = Calendar.getInstance(mLocale);
|
// Use tiny (e.g. single-character) weekday names from ICU. The indices
|
||||||
calendar.setFirstDayOfWeek(mWeekStart);
|
// for this list correspond to Calendar days, e.g. SUNDAY is index 1.
|
||||||
|
final String[] tinyWeekdayNames = LocaleData.get(mLocale).tinyWeekdayNames;
|
||||||
final SimpleDateFormat formatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, mLocale);
|
for (int i = 0; i < DAYS_IN_WEEK; i++) {
|
||||||
for (int i = 0; i < 7; i++) {
|
mDayOfWeekLabels[i] = tinyWeekdayNames[(mWeekStart + i - 1) % DAYS_IN_WEEK + 1];
|
||||||
calendar.set(Calendar.DAY_OF_WEEK, i);
|
|
||||||
mDayOfWeekLabels[i] = formatter.format(calendar.getTime());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DEBUG_WRONG_DATE) {
|
if (DEBUG_WRONG_DATE) {
|
||||||
@@ -662,8 +662,7 @@ class SimpleMonthView extends View {
|
|||||||
colCenterRtl = colCenter;
|
colCenterRtl = colCenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int dayOfWeek = (col + mWeekStart) % DAYS_IN_WEEK;
|
final String label = mDayOfWeekLabels[col];
|
||||||
final String label = mDayOfWeekLabels[dayOfWeek];
|
|
||||||
canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p);
|
canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -813,6 +812,11 @@ class SimpleMonthView extends View {
|
|||||||
*/
|
*/
|
||||||
void setMonthParams(int selectedDay, int month, int year, int weekStart, int enabledDayStart,
|
void setMonthParams(int selectedDay, int month, int year, int weekStart, int enabledDayStart,
|
||||||
int enabledDayEnd) {
|
int enabledDayEnd) {
|
||||||
|
if (DEBUG_WRONG_DATE) {
|
||||||
|
Log.d(LOG_TAG, "setMonthParams(" + selectedDay + ", " + month + ", " + year + ", "
|
||||||
|
+ weekStart + ", " + enabledDayStart + ", " + enabledDayEnd + ")");
|
||||||
|
}
|
||||||
|
|
||||||
mActivatedDay = selectedDay;
|
mActivatedDay = selectedDay;
|
||||||
|
|
||||||
if (isValidMonth(month)) {
|
if (isValidMonth(month)) {
|
||||||
@@ -849,6 +853,14 @@ class SimpleMonthView extends View {
|
|||||||
mTouchHelper.invalidateRoot();
|
mTouchHelper.invalidateRoot();
|
||||||
|
|
||||||
updateMonthYearLabel();
|
updateMonthYearLabel();
|
||||||
|
|
||||||
|
if (DEBUG_WRONG_DATE) {
|
||||||
|
Log.d(LOG_TAG, "mMonth = " + mMonth);
|
||||||
|
Log.d(LOG_TAG, "mDayOfWeekStart = " + mDayOfWeekStart);
|
||||||
|
Log.d(LOG_TAG, "mWeekStart = " + mWeekStart);
|
||||||
|
Log.d(LOG_TAG, "mDaysInMonth = " + mDaysInMonth);
|
||||||
|
Log.d(LOG_TAG, "mToday = " + mToday);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getDaysInMonth(int month, int year) {
|
private static int getDaysInMonth(int month, int year) {
|
||||||
|
|||||||
Reference in New Issue
Block a user