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:
@@ -819,14 +819,21 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
|
||||
|
||||
View title = 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);
|
||||
((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);
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -2222,6 +2229,7 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
|
||||
if (detail != null) {
|
||||
icon.setImageDrawable(detail.icon);
|
||||
title.setText(detail.label);
|
||||
title.setContentDescription(detail.contentDescription);
|
||||
} else {
|
||||
icon.setImageDrawable(null);
|
||||
title.setText(null);
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -22,6 +22,7 @@ import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
@@ -30,6 +31,8 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.preference.Preference;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
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,
|
||||
CharSequence label,
|
||||
boolean isHighBattery,
|
||||
String contentDescription,
|
||||
Preference.OnPreferenceClickListener listener) {
|
||||
Preference pref = new Preference(mActivity);
|
||||
AccessiblePreference pref = new AccessiblePreference(mActivity, contentDescription);
|
||||
pref.setIcon(icon);
|
||||
pref.setTitle(label);
|
||||
if (isHighBattery) {
|
||||
@@ -172,16 +198,20 @@ public class RecentLocationApps {
|
||||
int uid = ops.getUid();
|
||||
int userId = UserHandle.getUserId(uid);
|
||||
|
||||
Preference preference = null;
|
||||
AccessiblePreference preference = null;
|
||||
try {
|
||||
IPackageManager ipm = AppGlobals.getPackageManager();
|
||||
ApplicationInfo appInfo =
|
||||
ipm.getApplicationInfo(packageName, PackageManager.GET_META_DATA, userId);
|
||||
Resources res = mActivity.getResources();
|
||||
|
||||
Drawable icon = um.getBadgedDrawableForUser(
|
||||
mPackageManager.getApplicationIcon(appInfo), new UserHandle(userId));
|
||||
final UserHandle userHandle = 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,
|
||||
mPackageManager.getApplicationLabel(appInfo), highBattery,
|
||||
appLabel, highBattery, badgedAppLabel,
|
||||
new PackageEntryClickedListener(packageName));
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, "Error while retrieving application info", e);
|
||||
|
@@ -20,6 +20,8 @@ import android.graphics.drawable.Drawable;
|
||||
|
||||
public class UidDetail {
|
||||
public CharSequence label;
|
||||
public CharSequence contentDescription;
|
||||
public CharSequence[] detailLabels;
|
||||
public CharSequence[] detailContentDescriptions;
|
||||
public Drawable icon;
|
||||
}
|
||||
|
@@ -148,27 +148,30 @@ public class UidDetailProvider {
|
||||
final String[] packageNames = pm.getPackagesForUid(uid);
|
||||
final int length = packageNames != null ? packageNames.length : 0;
|
||||
try {
|
||||
final UserHandle userHandle = new UserHandle(UserHandle.getUserId(uid));
|
||||
if (length == 1) {
|
||||
final ApplicationInfo info = pm.getApplicationInfo(packageNames[0], 0);
|
||||
detail.label = info.loadLabel(pm).toString();
|
||||
detail.icon = um.getBadgedDrawableForUser(info.loadIcon(pm),
|
||||
new UserHandle(UserHandle.getUserId(uid)));
|
||||
detail.icon = um.getBadgedDrawableForUser(info.loadIcon(pm), userHandle);
|
||||
} else if (length > 1) {
|
||||
detail.detailLabels = new CharSequence[length];
|
||||
detail.detailContentDescriptions = new CharSequence[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
final String packageName = packageNames[i];
|
||||
final PackageInfo packageInfo = pm.getPackageInfo(packageName, 0);
|
||||
final ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0);
|
||||
|
||||
detail.detailLabels[i] = appInfo.loadLabel(pm).toString();
|
||||
detail.detailContentDescriptions[i] = um.getBadgedLabelForUser(
|
||||
detail.detailLabels[i], userHandle);
|
||||
if (packageInfo.sharedUserLabel != 0) {
|
||||
detail.label = pm.getText(packageName, packageInfo.sharedUserLabel,
|
||||
packageInfo.applicationInfo).toString();
|
||||
detail.icon = um.getBadgedDrawableForUser(appInfo.loadIcon(pm),
|
||||
new UserHandle(UserHandle.getUserId(uid)));
|
||||
detail.icon = um.getBadgedDrawableForUser(appInfo.loadIcon(pm), userHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
detail.contentDescription = um.getBadgedLabelForUser(detail.label, userHandle);
|
||||
} catch (NameNotFoundException e) {
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user