diff --git a/core/java/android/widget/DateTimeView.java b/core/java/android/widget/DateTimeView.java index d2ee86622e082..e172044a87d6c 100644 --- a/core/java/android/widget/DateTimeView.java +++ b/core/java/android/widget/DateTimeView.java @@ -34,6 +34,7 @@ import android.icu.util.Calendar; import android.os.Handler; import android.text.format.Time; import android.util.AttributeSet; +import android.view.accessibility.AccessibilityNodeInfo; import android.widget.RemoteViews.RemoteView; import com.android.internal.R; @@ -118,7 +119,6 @@ public class DateTimeView extends TextView { public void setTime(long time) { Time t = new Time(); t.set(time); - t.second = 0; mTimeMillis = t.toMillis(false); mTime = new Date(t.year-1900, t.month, t.monthDay, t.hour, t.minute, 0); update(); @@ -333,6 +333,63 @@ public class DateTimeView extends TextView { update(); } + @Override + public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfoInternal(info); + if (mShowRelativeTime) { + // The short version of the time might not be completely understandable and for + // accessibility we rather have a longer version. + long now = System.currentTimeMillis(); + long duration = Math.abs(now - mTimeMillis); + int count; + boolean past = (now >= mTimeMillis); + String result; + if (duration < MINUTE_IN_MILLIS) { + result = mNowText; + } else if (duration < HOUR_IN_MILLIS) { + count = (int)(duration / MINUTE_IN_MILLIS); + result = String.format(getContext().getResources().getQuantityString(past + ? com.android.internal. + R.plurals.duration_minutes_relative + : com.android.internal. + R.plurals.duration_minutes_relative_future, + count), + count); + } else if (duration < DAY_IN_MILLIS) { + count = (int)(duration / HOUR_IN_MILLIS); + result = String.format(getContext().getResources().getQuantityString(past + ? com.android.internal. + R.plurals.duration_hours_relative + : com.android.internal. + R.plurals.duration_hours_relative_future, + count), + count); + } else if (duration < YEAR_IN_MILLIS) { + // In weird cases it can become 0 because of daylight savings + TimeZone timeZone = TimeZone.getDefault(); + count = Math.max(Math.abs(dayDistance(timeZone, mTimeMillis, now)), 1); + result = String.format(getContext().getResources().getQuantityString(past + ? com.android.internal. + R.plurals.duration_days_relative + : com.android.internal. + R.plurals.duration_days_relative_future, + count), + count); + + } else { + count = (int)(duration / YEAR_IN_MILLIS); + result = String.format(getContext().getResources().getQuantityString(past + ? com.android.internal. + R.plurals.duration_years_relative + : com.android.internal. + R.plurals.duration_years_relative_future, + count), + count); + } + info.setText(result); + } + } + private static class ReceiverInfo { private final ArrayList mAttachedViews = new ArrayList(); private final BroadcastReceiver mReceiver = new BroadcastReceiver() { diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 9d714758f3aef..e30fd1a868225 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -2474,6 +2474,54 @@ in %dy + + + %d minute ago + %d minutes ago + + + + + %d hour ago + %d hours ago + + + + + %d day ago + %d days ago + + + + + %d year ago + %d years ago + + + + + in %d minute + in %d minutes + + + + + in %d hour + in %d hours + + + + + in %d day + in %d days + + + + + in %d year + in %d years + + Video problem diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 4925e52db6dc0..115c49fb50a92 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2522,6 +2522,15 @@ + + + + + + + + +