summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget/SimpleMonthView.java
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2015-04-22 13:43:31 -0700
committerAlan Viverette <alanv@google.com>2015-04-22 13:43:31 -0700
commitddf655c49f4173aa55c9ba1a2622cf75cf5bc2f2 (patch)
tree77b25d08489acc03d26cfa0abb073dce4123c25e /core/java/android/widget/SimpleMonthView.java
parentb5665c99105170998f0069b2a53d50587074f437 (diff)
downloadframeworks_base-ddf655c49f4173aa55c9ba1a2622cf75cf5bc2f2.zip
frameworks_base-ddf655c49f4173aa55c9ba1a2622cf75cf5bc2f2.tar.gz
frameworks_base-ddf655c49f4173aa55c9ba1a2622cf75cf5bc2f2.tar.bz2
Implement RTL support in framework ViewPager, DatePicker
Lays out ViewPager in the opposite direction when in RTL mode, e.g. the first item's starting edge is laid out at the largest possible scrolling distance. This preserves both the meaning of positive scrollX values and the meaning of positive adapter positions. Also removes clickable attribute from DayPickerView since it has a virtual view hierarchy. Bug: 19408740 Bug: 20134073 Change-Id: Ib6f945335bd88da59c8c593c7c270e290e15d0a5
Diffstat (limited to 'core/java/android/widget/SimpleMonthView.java')
-rw-r--r--core/java/android/widget/SimpleMonthView.java56
1 files changed, 47 insertions, 9 deletions
diff --git a/core/java/android/widget/SimpleMonthView.java b/core/java/android/widget/SimpleMonthView.java
index 0249c22..2778f0f 100644
--- a/core/java/android/widget/SimpleMonthView.java
+++ b/core/java/android/widget/SimpleMonthView.java
@@ -162,7 +162,6 @@ class SimpleMonthView extends View {
mTitleFormatter = new SimpleDateFormat(titleFormat, locale);
mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale);
- setClickable(true);
initPaints(res);
}
@@ -318,7 +317,8 @@ class SimpleMonthView extends View {
final int x = (int) (event.getX() + 0.5f);
final int y = (int) (event.getY() + 0.5f);
- switch (event.getAction()) {
+ final int action = event.getAction();
+ switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
final int touchedItem = getDayAtLocation(x, y);
@@ -326,6 +326,10 @@ class SimpleMonthView extends View {
mTouchedItem = touchedItem;
invalidate();
}
+ if (action == MotionEvent.ACTION_DOWN && touchedItem < 0) {
+ // Touch something that's not an item, reject event.
+ return false;
+ }
break;
case MotionEvent.ACTION_UP:
@@ -376,9 +380,16 @@ class SimpleMonthView extends View {
for (int col = 0; col < DAYS_IN_WEEK; col++) {
final int colCenter = colWidth * col + colWidth / 2;
+ final int colCenterRtl;
+ if (isLayoutRtl()) {
+ colCenterRtl = mPaddedWidth - colCenter;
+ } else {
+ colCenterRtl = colCenter;
+ }
+
final int dayOfWeek = (col + mWeekStart) % DAYS_IN_WEEK;
final String label = getDayOfWeekLabel(dayOfWeek);
- canvas.drawText(label, colCenter, rowCenter - halfLineHeight, p);
+ canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p);
}
}
@@ -402,6 +413,13 @@ class SimpleMonthView extends View {
for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
final int colCenter = colWidth * col + colWidth / 2;
+ final int colCenterRtl;
+ if (isLayoutRtl()) {
+ colCenterRtl = mPaddedWidth - colCenter;
+ } else {
+ colCenterRtl = colCenter;
+ }
+
int stateMask = 0;
if (day >= mEnabledDayStart && day <= mEnabledDayEnd) {
@@ -413,12 +431,12 @@ class SimpleMonthView extends View {
stateMask |= StateSet.VIEW_STATE_ACTIVATED;
// Adjust the circle to be centered on the row.
- canvas.drawCircle(colCenter, rowCenter, mDaySelectorRadius, mDaySelectorPaint);
+ canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint);
} else if (mTouchedItem == day) {
stateMask |= StateSet.VIEW_STATE_PRESSED;
// Adjust the circle to be centered on the row.
- canvas.drawCircle(colCenter, rowCenter, mDaySelectorRadius, mDayHighlightPaint);
+ canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDayHighlightPaint);
}
final boolean isDayToday = mToday == day;
@@ -431,7 +449,7 @@ class SimpleMonthView extends View {
}
p.setColor(dayTextColor);
- canvas.drawText(Integer.toString(day), colCenter, rowCenter - halfLineHeight, p);
+ canvas.drawText(Integer.toString(day), colCenterRtl, rowCenter - halfLineHeight, p);
col++;
@@ -583,6 +601,13 @@ class SimpleMonthView extends View {
}
@Override
+ public void onRtlPropertiesChanged(@ResolvedLayoutDir int layoutDirection) {
+ super.onRtlPropertiesChanged(layoutDirection);
+
+ requestLayout();
+ }
+
+ @Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
if (!changed) {
return;
@@ -657,8 +682,16 @@ class SimpleMonthView extends View {
return -1;
}
+ // Adjust for RTL after applying padding.
+ final int paddedXRtl;
+ if (isLayoutRtl()) {
+ paddedXRtl = mPaddedWidth - paddedX;
+ } else {
+ paddedXRtl = paddedX;
+ }
+
final int row = (paddedY - headerHeight) / mDayHeight;
- final int col = (paddedX * DAYS_IN_WEEK) / mPaddedWidth;
+ final int col = (paddedXRtl * DAYS_IN_WEEK) / mPaddedWidth;
final int index = col + row * DAYS_IN_WEEK;
final int day = index + 1 - findDayOffset();
if (day < 1 || day > mDaysInMonth) {
@@ -681,10 +714,15 @@ class SimpleMonthView extends View {
final int index = id - 1 + findDayOffset();
- // Compute left edge.
+ // Compute left edge, taking into account RTL.
final int col = index % DAYS_IN_WEEK;
final int colWidth = mCellWidth;
- final int left = getPaddingLeft() + col * colWidth;
+ final int left;
+ if (isLayoutRtl()) {
+ left = getWidth() - getPaddingRight() - (col + 1) * colWidth;
+ } else {
+ left = getPaddingLeft() + col * colWidth;
+ }
// Compute top edge.
final int row = index / DAYS_IN_WEEK;