Apply predefined icon and label to managed profiles

Bug: 18132630
Change-Id: Ie6cfee420847d6992accb0bc0ca3f5535260bc55
This commit is contained in:
Alexandra Gherghina
2014-10-30 11:56:18 +00:00
parent 6f5b23f3fc
commit 0f5440f6e2
5 changed files with 34 additions and 35 deletions

View File

@@ -5177,8 +5177,6 @@
<string name="user_add_user_menu">Add user</string> <string name="user_add_user_menu">Add user</string>
<!-- User settings summary for a restricted profile [CHAR LIMIT=50] --> <!-- User settings summary for a restricted profile [CHAR LIMIT=50] -->
<string name="user_summary_restricted_profile">Restricted profile</string> <string name="user_summary_restricted_profile">Restricted profile</string>
<!-- User settings summary for a work profile [CHAR LIMIT=50] -->
<string name="user_summary_managed_profile">Work profile</string>
<!-- User settings warning that restricted profile needs a screen lock [CHAR LIMIT=NONE] --> <!-- User settings warning that restricted profile needs a screen lock [CHAR LIMIT=NONE] -->
<string name="user_need_lock_message">Before you can create a restricted profile, you\'ll need to set up a screen lock to protect your apps and personal data.</string> <string name="user_need_lock_message">Before you can create a restricted profile, you\'ll need to set up a screen lock to protect your apps and personal data.</string>
<!-- User settings dialog button to set screen lock [CHAR LIMIT=25] --> <!-- User settings dialog button to set screen lock [CHAR LIMIT=25] -->

View File

@@ -61,8 +61,6 @@ import android.provider.ContactsContract.Profile;
import android.provider.ContactsContract.RawContacts; import android.provider.ContactsContract.RawContacts;
import android.service.persistentdata.PersistentDataBlockManager; import android.service.persistentdata.PersistentDataBlockManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@@ -70,10 +68,8 @@ import android.view.ViewGroup;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TabWidget; import android.widget.TabWidget;
import com.android.internal.util.ImageUtils;
import com.android.internal.util.UserIcons; import com.android.internal.util.UserIcons;
import com.android.settings.UserSpinnerAdapter.UserDetails; import com.android.settings.UserSpinnerAdapter.UserDetails;
import com.android.settings.dashboard.DashboardCategory;
import com.android.settings.dashboard.DashboardTile; import com.android.settings.dashboard.DashboardTile;
import com.android.settings.drawable.CircleFramedDrawable; import com.android.settings.drawable.CircleFramedDrawable;
@@ -858,6 +854,12 @@ public final class Utils {
* Returns a circular icon for a user. * Returns a circular icon for a user.
*/ */
public static Drawable getUserIcon(Context context, UserManager um, UserInfo user) { public static Drawable getUserIcon(Context context, UserManager um, UserInfo user) {
if (user.isManagedProfile()) {
// We use predefined values for managed profiles
Bitmap b = BitmapFactory.decodeResource(context.getResources(),
com.android.internal.R.drawable.ic_corp_icon);
return CircleFramedDrawable.getInstance(context, b);
}
if (user.iconPath != null) { if (user.iconPath != null) {
Bitmap icon = um.getUserIcon(user.id); Bitmap icon = um.getUserIcon(user.id);
if (icon != null) { if (icon != null) {
@@ -867,6 +869,23 @@ public final class Utils {
return UserIcons.getDefaultUserIcon(user.id, /* light= */ false); return UserIcons.getDefaultUserIcon(user.id, /* light= */ false);
} }
/**
* Returns a label for the user, in the form of "User: user name" or "Work profile".
*/
public static String getUserLabel(Context context, UserInfo info) {
if (info.isManagedProfile()) {
// We use predefined values for managed profiles
return context.getString(R.string.managed_user_title);
}
String name = info != null ? info.name : null;
if (name == null && info != null) {
name = Integer.toString(info.id);
} else if (info == null) {
name = context.getString(R.string.unknown);
}
return context.getResources().getString(R.string.running_process_item_user_label, name);
}
/** /**
* Return whether or not the user should have a SIM Cards option in Settings. * Return whether or not the user should have a SIM Cards option in Settings.
* TODO: Change back to returning true if count is greater than one after testing. * TODO: Change back to returning true if count is greater than one after testing.

View File

@@ -16,9 +16,6 @@
package com.android.settings.applications; package com.android.settings.applications;
import com.android.settings.R;
import com.android.settings.Utils;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.ActivityManagerNative; import android.app.ActivityManagerNative;
import android.app.ActivityThread; import android.app.ActivityThread;
@@ -31,6 +28,8 @@ import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo; import android.content.pm.ServiceInfo;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable.ConstantState; import android.graphics.drawable.Drawable.ConstantState;
import android.os.Handler; import android.os.Handler;
@@ -44,6 +43,10 @@ import android.text.format.Formatter;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.drawable.CircleFramedDrawable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@@ -836,17 +839,8 @@ public class RunningState {
userItem.mUser = new UserState(); userItem.mUser = new UserState();
UserInfo info = mUm.getUserInfo(newItem.mUserId); UserInfo info = mUm.getUserInfo(newItem.mUserId);
userItem.mUser.mInfo = info; userItem.mUser.mInfo = info;
if (info != null) {
userItem.mUser.mIcon = Utils.getUserIcon(context, mUm, info); userItem.mUser.mIcon = Utils.getUserIcon(context, mUm, info);
} userItem.mUser.mLabel = Utils.getUserLabel(context, info);
String name = info != null ? info.name : null;
if (name == null && info != null) {
name = Integer.toString(info.id);
} else if (info == null) {
name = context.getString(R.string.unknown);
}
userItem.mUser.mLabel = context.getResources().getString(
R.string.running_process_item_user_label, name);
} }
newMergedItems.add(userItem); newMergedItems.add(userItem);
} }

View File

@@ -167,12 +167,7 @@ public class BatteryEntry {
UserInfo info = um.getUserInfo(sipper.userId); UserInfo info = um.getUserInfo(sipper.userId);
if (info != null) { if (info != null) {
icon = Utils.getUserIcon(context, um, info); icon = Utils.getUserIcon(context, um, info);
name = info != null ? info.name : null; name = Utils.getUserLabel(context, info);
if (name == null) {
name = Integer.toString(info.id);
}
name = context.getResources().getString(
R.string.running_process_item_user_label, name);
} else { } else {
icon = null; icon = null;
name = context.getResources().getString( name = context.getResources().getString(

View File

@@ -136,15 +136,8 @@ public class UidDetailProvider {
final int userHandle = getUserIdForKey(uid); final int userHandle = getUserIdForKey(uid);
final UserInfo info = um.getUserInfo(userHandle); final UserInfo info = um.getUserInfo(userHandle);
if (info != null) { if (info != null) {
if (info.isManagedProfile()) { detail.label = Utils.getUserLabel(mContext, info);
detail.label = res.getString(R.string.managed_user_title);
detail.icon = mContext.getDrawable(
com.android.internal.R.drawable.ic_corp_icon);
} else {
detail.label = res.getString(R.string.running_process_item_user_label,
info.name);
detail.icon = Utils.getUserIcon(mContext, um, info); detail.icon = Utils.getUserIcon(mContext, um, info);
}
return detail; return detail;
} }
} }