Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8447884 authored by Selim Cinek's avatar Selim Cinek Committed by android-build-merger
Browse files

Merge "Fixed the relative time spoken with accessibility" into nyc-dev am: 38b5946f

am: 0361d504

* commit '0361d504':
  Fixed the relative time spoken with accessibility

Change-Id: I52740a97b660f996f0212e4be7c363180cefb242
parents 5295bc4e 0361d504
Loading
Loading
Loading
Loading
+58 −1
Original line number Diff line number Diff line
@@ -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<DateTimeView> mAttachedViews = new ArrayList<DateTimeView>();
        private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+48 −0
Original line number Diff line number Diff line
@@ -2474,6 +2474,54 @@
        <item quantity="other">in <xliff:g example="2" id="count">%d</xliff:g>y</item>
    </plurals>

    <!-- Phrase describing a relative time using minutes in the past that is not shown on the screen but used for accessibility. [CHAR LIMIT=NONE] -->
    <plurals name="duration_minutes_relative">
        <item quantity="one"><xliff:g example="1" id="count">%d</xliff:g> minute ago</item>
        <item quantity="other"><xliff:g example="2" id="count">%d</xliff:g> minutes ago</item>
    </plurals>

    <!-- Phrase describing a relative time using hours in the past that is not shown on the screen but used for accessibility. [CHAR LIMIT=NONE] -->
    <plurals name="duration_hours_relative">
        <item quantity="one"><xliff:g example="1" id="count">%d</xliff:g> hour ago</item>
        <item quantity="other"><xliff:g example="2" id="count">%d</xliff:g> hours ago</item>
    </plurals>

    <!-- Phrase describing a relative time using days in the past that is not shown on the screen but used for accessibility. [CHAR LIMIT=NONE] -->
    <plurals name="duration_days_relative">
        <item quantity="one"><xliff:g example="1" id="count">%d</xliff:g> day ago</item>
        <item quantity="other"><xliff:g example="2" id="count">%d</xliff:g> days ago</item>
    </plurals>

    <!-- Phrase describing a relative time using years in the past that is not shown on the screen but used for accessibility. [CHAR LIMIT=NONE] -->
    <plurals name="duration_years_relative">
        <item quantity="one"><xliff:g example="1" id="count">%d</xliff:g> year ago</item>
        <item quantity="other"><xliff:g example="2" id="count">%d</xliff:g> years ago</item>
    </plurals>

    <!-- Phrase describing a relative time using minutes that is not shown on the screen but used for accessibility. This version should be a future point in time. [CHAR LIMIT=NONE] -->
    <plurals name="duration_minutes_relative_future">
        <item quantity="one">in <xliff:g example="1" id="count">%d</xliff:g> minute</item>
        <item quantity="other">in <xliff:g example="2" id="count">%d</xliff:g> minutes</item>
    </plurals>

    <!-- Phrase describing a relative time using hours that is not shown on the screen but used for accessibility. This version should be a future point in time. [CHAR LIMIT=NONE] -->
    <plurals name="duration_hours_relative_future">
        <item quantity="one">in <xliff:g example="1" id="count">%d</xliff:g> hour</item>
        <item quantity="other">in <xliff:g example="2" id="count">%d</xliff:g> hours</item>
    </plurals>

    <!-- Phrase describing a relative time using days that is not shown on the screen but used for accessibility. This version should be a future point in time. [CHAR LIMIT=NONE] -->
    <plurals name="duration_days_relative_future">
        <item quantity="one">in <xliff:g example="1" id="count">%d</xliff:g> day</item>
        <item quantity="other">in <xliff:g example="2" id="count">%d</xliff:g> days</item>
    </plurals>

    <!-- Phrase describing a relative time using years that is not shown on the screen but used for accessibility. This version should be a future point in time. [CHAR LIMIT=NONE] -->
    <plurals name="duration_years_relative_future">
        <item quantity="one">in <xliff:g example="1" id="count">%d</xliff:g> year</item>
        <item quantity="other">in <xliff:g example="2" id="count">%d</xliff:g> years</item>
    </plurals>

    <!-- Title for error alert when a video cannot be played.  it can be used by any app. -->
    <string name="VideoView_error_title">Video problem</string>
    <!-- Text for error alert when a video container is not valid for progressive download/playback. -->
+9 −0
Original line number Diff line number Diff line
@@ -2522,6 +2522,15 @@
  <java-symbol type="plurals" name="duration_days_shortest_future" />
  <java-symbol type="plurals" name="duration_years_shortest_future" />

  <java-symbol type="plurals" name="duration_minutes_relative" />
  <java-symbol type="plurals" name="duration_hours_relative" />
  <java-symbol type="plurals" name="duration_days_relative" />
  <java-symbol type="plurals" name="duration_years_relative" />
  <java-symbol type="plurals" name="duration_minutes_relative_future" />
  <java-symbol type="plurals" name="duration_hours_relative_future" />
  <java-symbol type="plurals" name="duration_days_relative_future" />
  <java-symbol type="plurals" name="duration_years_relative_future" />

  <java-symbol type="string" name="now_string_shortest" />

  <!-- Encryption notification while accounts are locked by credential encryption -->