Badge texts correctly for accessibility in Settings

If an app is a managed profile's app then its label should read correctly by TalkBack.
Affected screens: Data Usage, Location, Battery.

Bug:16053981
Change-Id: I393c0ebf56917032d619b1e39b4bf141ee236981
This commit is contained in:
Zoltan Szatmary-Ban
2014-07-23 11:02:46 +01:00
parent f34c350194
commit ebb36ec920
6 changed files with 73 additions and 15 deletions

View File

@@ -34,12 +34,15 @@ public class PowerGaugePreference extends Preference {
private BatteryEntry mInfo;
private int mProgress;
private CharSequence mProgressText;
private final String mContentDescription;
public PowerGaugePreference(Context context, Drawable icon, BatteryEntry info) {
public PowerGaugePreference(Context context, Drawable icon, String contentDescription,
BatteryEntry info) {
super(context);
setLayoutResource(R.layout.preference_app_percentage);
setIcon(icon != null ? icon : new ColorDrawable(0));
mInfo = info;
mContentDescription = contentDescription;
}
public void setPercent(double percentOfMax, double percentOfTotal) {
@@ -62,5 +65,10 @@ public class PowerGaugePreference extends Preference {
final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
text1.setText(mProgressText);
if (mContentDescription != null) {
final TextView titleView = (TextView) view.findViewById(android.R.id.title);
titleView.setContentDescription(mContentDescription);
}
}
}

View File

@@ -21,6 +21,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.os.BatteryStats;
import android.os.Bundle;
import android.os.Handler;
@@ -294,8 +295,14 @@ public class PowerUsageSummary extends PreferenceFragment {
}
final UserHandle userHandle = new UserHandle(UserHandle.getUserId(sipper.getUid()));
final BatteryEntry entry = new BatteryEntry(getActivity(), mHandler, mUm, sipper);
final Drawable badgedIcon = mUm.getBadgedDrawableForUser(entry.getIcon(),
userHandle);
// TODO: type of this will be replaced by CharSequence (see
// https://b.corp.google.com/issue?id=16401636 )
final String contentDescription = mUm.getBadgedLabelForUser(entry.getLabel(),
userHandle);
final PowerGaugePreference pref = new PowerGaugePreference(getActivity(),
mUm.getBadgedDrawableForUser(entry.getIcon(), userHandle), entry);
badgedIcon, contentDescription, entry);
final double percentOfMax = (sipper.value * 100) / mStatsHelper.getMaxPower();
sipper.percent = percentOfTotal;