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

@@ -819,14 +819,21 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
View title = null; View title = null;
if (detail.detailLabels != null) { if (detail.detailLabels != null) {
for (CharSequence label : detail.detailLabels) { final int n = detail.detailLabels.length;
for (int i = 0; i < n; ++i) {
CharSequence label = detail.detailLabels[i];
CharSequence contentDescription = detail.detailContentDescriptions[i];
title = inflater.inflate(R.layout.data_usage_app_title, mAppTitles, false); title = inflater.inflate(R.layout.data_usage_app_title, mAppTitles, false);
((TextView) title.findViewById(R.id.app_title)).setText(label); TextView appTitle = (TextView) title.findViewById(R.id.app_title);
appTitle.setText(label);
appTitle.setContentDescription(contentDescription);
mAppTitles.addView(title); mAppTitles.addView(title);
} }
} else { } else {
title = inflater.inflate(R.layout.data_usage_app_title, mAppTitles, false); title = inflater.inflate(R.layout.data_usage_app_title, mAppTitles, false);
((TextView) title.findViewById(R.id.app_title)).setText(detail.label); TextView appTitle = (TextView) title.findViewById(R.id.app_title);
appTitle.setText(detail.label);
appTitle.setContentDescription(detail.contentDescription);
mAppTitles.addView(title); mAppTitles.addView(title);
} }
@@ -2222,6 +2229,7 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
if (detail != null) { if (detail != null) {
icon.setImageDrawable(detail.icon); icon.setImageDrawable(detail.icon);
title.setText(detail.label); title.setText(detail.label);
title.setContentDescription(detail.contentDescription);
} else { } else {
icon.setImageDrawable(null); icon.setImageDrawable(null);
title.setText(null); title.setText(null);

View File

@@ -34,12 +34,15 @@ public class PowerGaugePreference extends Preference {
private BatteryEntry mInfo; private BatteryEntry mInfo;
private int mProgress; private int mProgress;
private CharSequence mProgressText; 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); super(context);
setLayoutResource(R.layout.preference_app_percentage); setLayoutResource(R.layout.preference_app_percentage);
setIcon(icon != null ? icon : new ColorDrawable(0)); setIcon(icon != null ? icon : new ColorDrawable(0));
mInfo = info; mInfo = info;
mContentDescription = contentDescription;
} }
public void setPercent(double percentOfMax, double percentOfTotal) { 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); final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
text1.setText(mProgressText); 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.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.os.BatteryStats; import android.os.BatteryStats;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@@ -294,8 +295,14 @@ public class PowerUsageSummary extends PreferenceFragment {
} }
final UserHandle userHandle = new UserHandle(UserHandle.getUserId(sipper.getUid())); final UserHandle userHandle = new UserHandle(UserHandle.getUserId(sipper.getUid()));
final BatteryEntry entry = new BatteryEntry(getActivity(), mHandler, mUm, sipper); 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(), final PowerGaugePreference pref = new PowerGaugePreference(getActivity(),
mUm.getBadgedDrawableForUser(entry.getIcon(), userHandle), entry); badgedIcon, contentDescription, entry);
final double percentOfMax = (sipper.value * 100) / mStatsHelper.getMaxPower(); final double percentOfMax = (sipper.value * 100) / mStatsHelper.getMaxPower();
sipper.percent = percentOfTotal; sipper.percent = percentOfTotal;

View File

@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.IPackageManager; import android.content.pm.IPackageManager;
import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Process; import android.os.Process;
@@ -30,6 +31,8 @@ import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.preference.Preference; import android.preference.Preference;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
@@ -74,12 +77,35 @@ public class RecentLocationApps {
} }
} }
private Preference createRecentLocationEntry( /**
* Subclass of {@link Preference} to intercept views and allow content description to be set on
* them for accessibility purposes.
*/
private static class AccessiblePreference extends Preference {
public String mContentDescription;
public AccessiblePreference(Context context, String contentDescription) {
super(context);
mContentDescription = contentDescription;
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
if (mContentDescription != null) {
final TextView titleView = (TextView) view.findViewById(android.R.id.title);
titleView.setContentDescription(mContentDescription);
}
}
}
private AccessiblePreference createRecentLocationEntry(
Drawable icon, Drawable icon,
CharSequence label, CharSequence label,
boolean isHighBattery, boolean isHighBattery,
String contentDescription,
Preference.OnPreferenceClickListener listener) { Preference.OnPreferenceClickListener listener) {
Preference pref = new Preference(mActivity); AccessiblePreference pref = new AccessiblePreference(mActivity, contentDescription);
pref.setIcon(icon); pref.setIcon(icon);
pref.setTitle(label); pref.setTitle(label);
if (isHighBattery) { if (isHighBattery) {
@@ -172,16 +198,20 @@ public class RecentLocationApps {
int uid = ops.getUid(); int uid = ops.getUid();
int userId = UserHandle.getUserId(uid); int userId = UserHandle.getUserId(uid);
Preference preference = null; AccessiblePreference preference = null;
try { try {
IPackageManager ipm = AppGlobals.getPackageManager(); IPackageManager ipm = AppGlobals.getPackageManager();
ApplicationInfo appInfo = ApplicationInfo appInfo =
ipm.getApplicationInfo(packageName, PackageManager.GET_META_DATA, userId); ipm.getApplicationInfo(packageName, PackageManager.GET_META_DATA, userId);
Resources res = mActivity.getResources();
Drawable icon = um.getBadgedDrawableForUser( final UserHandle userHandle = new UserHandle(userId);
mPackageManager.getApplicationIcon(appInfo), new UserHandle(userId)); Drawable appIcon = mPackageManager.getApplicationIcon(appInfo);
Drawable icon = um.getBadgedDrawableForUser(appIcon, userHandle);
CharSequence appLabel = mPackageManager.getApplicationLabel(appInfo);
String badgedAppLabel = um.getBadgedLabelForUser(appLabel.toString(), userHandle);
preference = createRecentLocationEntry(icon, preference = createRecentLocationEntry(icon,
mPackageManager.getApplicationLabel(appInfo), highBattery, appLabel, highBattery, badgedAppLabel,
new PackageEntryClickedListener(packageName)); new PackageEntryClickedListener(packageName));
} catch (RemoteException e) { } catch (RemoteException e) {
Log.w(TAG, "Error while retrieving application info", e); Log.w(TAG, "Error while retrieving application info", e);

View File

@@ -20,6 +20,8 @@ import android.graphics.drawable.Drawable;
public class UidDetail { public class UidDetail {
public CharSequence label; public CharSequence label;
public CharSequence contentDescription;
public CharSequence[] detailLabels; public CharSequence[] detailLabels;
public CharSequence[] detailContentDescriptions;
public Drawable icon; public Drawable icon;
} }

View File

@@ -148,27 +148,30 @@ public class UidDetailProvider {
final String[] packageNames = pm.getPackagesForUid(uid); final String[] packageNames = pm.getPackagesForUid(uid);
final int length = packageNames != null ? packageNames.length : 0; final int length = packageNames != null ? packageNames.length : 0;
try { try {
final UserHandle userHandle = new UserHandle(UserHandle.getUserId(uid));
if (length == 1) { if (length == 1) {
final ApplicationInfo info = pm.getApplicationInfo(packageNames[0], 0); final ApplicationInfo info = pm.getApplicationInfo(packageNames[0], 0);
detail.label = info.loadLabel(pm).toString(); detail.label = info.loadLabel(pm).toString();
detail.icon = um.getBadgedDrawableForUser(info.loadIcon(pm), detail.icon = um.getBadgedDrawableForUser(info.loadIcon(pm), userHandle);
new UserHandle(UserHandle.getUserId(uid)));
} else if (length > 1) { } else if (length > 1) {
detail.detailLabels = new CharSequence[length]; detail.detailLabels = new CharSequence[length];
detail.detailContentDescriptions = new CharSequence[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
final String packageName = packageNames[i]; final String packageName = packageNames[i];
final PackageInfo packageInfo = pm.getPackageInfo(packageName, 0); final PackageInfo packageInfo = pm.getPackageInfo(packageName, 0);
final ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0); final ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0);
detail.detailLabels[i] = appInfo.loadLabel(pm).toString(); detail.detailLabels[i] = appInfo.loadLabel(pm).toString();
detail.detailContentDescriptions[i] = um.getBadgedLabelForUser(
detail.detailLabels[i], userHandle);
if (packageInfo.sharedUserLabel != 0) { if (packageInfo.sharedUserLabel != 0) {
detail.label = pm.getText(packageName, packageInfo.sharedUserLabel, detail.label = pm.getText(packageName, packageInfo.sharedUserLabel,
packageInfo.applicationInfo).toString(); packageInfo.applicationInfo).toString();
detail.icon = um.getBadgedDrawableForUser(appInfo.loadIcon(pm), detail.icon = um.getBadgedDrawableForUser(appInfo.loadIcon(pm), userHandle);
new UserHandle(UserHandle.getUserId(uid)));
} }
} }
} }
detail.contentDescription = um.getBadgedLabelForUser(detail.label, userHandle);
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
} }