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

Commit b7dd3964 authored by Andrew Lee's avatar Andrew Lee
Browse files

Fix call duration talkback verbalization.

+ Uncomment code which generates content description.
+ Pass in local context, rather than System context, for getting
the plurals resource strings. This fixes a crash happening in
languages even if correctly translations existed.
+ Catch Resource.NotFoundExceptions in the utility which generates
this human-readable string so that for locales missing the
translation we don't crash the whole Dialer.

Bug: 20813003
Change-Id: I861078a116d2d31f3ac361757a14581726a78f1c
parent 9b8d23fb
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -708,11 +708,11 @@ public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPr
            }
            String callTimeElapsed = DateUtils.formatElapsedTime(duration / 1000);
            mElapsedTime.setText(callTimeElapsed);
            /*
             * TODO: Temporarily disabled (b/20427882)
            String durationDescription = InCallDateUtils.formatDetailedDuration(duration);
            mElapsedTime.setContentDescription(durationDescription);
            */

            String durationDescription =
                    InCallDateUtils.formatDuration(getView().getContext(), duration);
            mElapsedTime.setContentDescription(
                    !TextUtils.isEmpty(durationDescription) ? durationDescription : null);
        } else {
            // hide() animation has no effect if it is already hidden.
            AnimUtils.fadeOut(mElapsedTime, AnimUtils.DEFAULT_DURATION);
+21 −20
Original line number Diff line number Diff line
package com.android.incallui;

import android.content.Context;
import android.content.res.Resources;

/**
 * Methods to parse time and date information in the InCallUi
 */
public class InCallDateUtils {
    public InCallDateUtils() {

    }

    /**
     * Return given duration in a human-friendly format. For example, "4
     * minutes 3 seconds" or "3 hours 1 second". Returns the hours, minutes and seconds in that
     * order if they exist.
     * Return given duration in a human-friendly format. For example, "4 minutes 3 seconds" or
     * "3 hours 1 second". Returns the hours, minutes and seconds in that order if they exist.
     */
    public static String formatDetailedDuration(long millis) {
    public static String formatDuration(Context context, long millis) {
        int hours = 0;
        int minutes = 0;
        int seconds = 0;
@@ -30,8 +27,9 @@ public class InCallDateUtils {
        }
        seconds = elapsedSeconds;

        final Resources res = Resources.getSystem();
        final Resources res = context.getResources();
        StringBuilder duration = new StringBuilder();
        try {
            if (hours > 0) {
                duration.append(res.getQuantityString(R.plurals.duration_hours, hours, hours));
            }
@@ -47,7 +45,10 @@ public class InCallDateUtils {
                }
                duration.append(res.getQuantityString(R.plurals.duration_seconds, seconds, seconds));
            }
        } catch (Resources.NotFoundException e) {
            // Ignore; plurals throws an exception for an untranslated quantity for a given locale.
            return null;
        }
        return duration.toString();
    }

}