From: Robert Snoeberger Date: Tue, 5 Feb 2019 16:09:48 +0000 (-0500) Subject: Fixes for typographic clock string. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=326d0c13b2f51a08ddd678bdd259e0be10837d99;p=android-x86%2Fframeworks-base.git Fixes for typographic clock string. Need plural forms for some languages based on the number of hours. Need template where "hours" and "minute" is filled into the sentence. This enables a conjunction to be added between "hours" and "minutes". And enables, for languages like Basque, the verb "It's" to moved from the beginning. "It's" can be moved either between "hours" and "minutes" or after "minutes". Bug: 123638383 Bug: 123638464 Bug: 123643485 Test: mp sysuig and manually tested Change-Id: I69865d004ed346a21a13e86d96a4bdad379f08df --- diff --git a/packages/SystemUI/res-keyguard/layout/type_clock.xml b/packages/SystemUI/res-keyguard/layout/type_clock.xml index 21c64e9c7dbe..f4a73765acc1 100644 --- a/packages/SystemUI/res-keyguard/layout/type_clock.xml +++ b/packages/SystemUI/res-keyguard/layout/type_clock.xml @@ -24,32 +24,8 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" - > - - - - + android:paddingLeft="50dp" + style="@style/widget_big" + android:textSize="40dp" + /> diff --git a/packages/SystemUI/res-keyguard/values/strings.xml b/packages/SystemUI/res-keyguard/values/strings.xml index 1f333073d8e0..94481e7fe456 100644 --- a/packages/SystemUI/res-keyguard/values/strings.xml +++ b/packages/SystemUI/res-keyguard/values/strings.xml @@ -402,8 +402,25 @@ number">%d remaining attempt before SIM becomes permanently unusable. number">%d remaining attempts before SIM becomes permanently unusable. Contact carrier for details. - - It\u2019s + + + It\u2019s\n^1\n^2 + It\u2019s\n^1\n^2 + It\u2019s\n^1\n^2 + diff --git a/packages/SystemUI/src/com/android/keyguard/clock/TypographicClock.java b/packages/SystemUI/src/com/android/keyguard/clock/TypographicClock.java index 5f9da3ee33bb..8feae53159ac 100644 --- a/packages/SystemUI/src/com/android/keyguard/clock/TypographicClock.java +++ b/packages/SystemUI/src/com/android/keyguard/clock/TypographicClock.java @@ -17,9 +17,14 @@ package com.android.keyguard.clock; import android.content.Context; import android.content.res.Resources; +import android.text.Annotation; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.SpannedString; +import android.text.TextUtils; import android.text.format.DateFormat; +import android.text.style.ForegroundColorSpan; import android.util.AttributeSet; -import android.widget.LinearLayout; import android.widget.TextView; import com.android.keyguard.R; @@ -31,13 +36,14 @@ import java.util.TimeZone; /** * Clock that presents the time in words. */ -public class TypographicClock extends LinearLayout { +public class TypographicClock extends TextView { + private static final String ANNOTATION_COLOR = "color"; + + private final Resources mResources; private final String[] mHours; private final String[] mMinutes; - private TextView mHeaderText; - private TextView mHourText; - private TextView mMinuteText; + private final int mAccentColor; private Calendar mTime; private String mDescFormat; private TimeZone mTimeZone; @@ -54,9 +60,10 @@ public class TypographicClock extends LinearLayout { super(context, attrs, defStyleAttr); mTime = Calendar.getInstance(); mDescFormat = ((SimpleDateFormat) DateFormat.getTimeFormat(context)).toLocalizedPattern(); - Resources res = context.getResources(); - mHours = res.getStringArray(R.array.type_clock_hours); - mMinutes = res.getStringArray(R.array.type_clock_minutes); + mResources = context.getResources(); + mHours = mResources.getStringArray(R.array.type_clock_hours); + mMinutes = mResources.getStringArray(R.array.type_clock_minutes); + mAccentColor = mResources.getColor(R.color.typeClockAccentColor, null); } /** @@ -65,11 +72,28 @@ public class TypographicClock extends LinearLayout { public void onTimeChanged() { mTime.setTimeInMillis(System.currentTimeMillis()); setContentDescription(DateFormat.format(mDescFormat, mTime)); - final int hour = mTime.get(Calendar.HOUR); - mHourText.setText(mHours[hour % 12]); - final int minute = mTime.get(Calendar.MINUTE); - mMinuteText.setText(mMinutes[minute % 60]); - invalidate(); + final int hour = mTime.get(Calendar.HOUR) % 12; + final int minute = mTime.get(Calendar.MINUTE) % 60; + + // Get the quantity based on the hour for languages like Portuguese and Czech. + SpannedString typeTemplate = (SpannedString) mResources.getQuantityText( + R.plurals.type_clock_header, hour); + + // Find the "color" annotation and set the foreground color to the accent color. + Annotation[] annotations = typeTemplate.getSpans(0, typeTemplate.length(), + Annotation.class); + SpannableString spanType = new SpannableString(typeTemplate); + for (int i = 0; i < annotations.length; i++) { + Annotation annotation = annotations[i]; + String key = annotation.getValue(); + if (ANNOTATION_COLOR.equals(key)) { + spanType.setSpan(new ForegroundColorSpan(mAccentColor), + spanType.getSpanStart(annotation), spanType.getSpanEnd(annotation), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } + } + + setText(TextUtils.expandTemplate(spanType, mHours[hour], mMinutes[minute])); } /** @@ -82,25 +106,6 @@ public class TypographicClock extends LinearLayout { mTime.setTimeZone(timeZone); } - /** - * Set the color of the text used to display the time. - * - * This is necessary when the wallpaper shown behind the clock on the - * lock screen changes. - */ - public void setTextColor(int color) { - mHourText.setTextColor(color); - mMinuteText.setTextColor(color); - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - mHeaderText = findViewById(R.id.header); - mHourText = findViewById(R.id.hour); - mMinuteText = findViewById(R.id.minute); - } - @Override protected void onAttachedToWindow() { super.onAttachedToWindow();