Use DimmableIconPreference for Add user action
Moved DimmableIconPreference from location to the root package since it is now used in several places. Add user action now uses DimmableIconPreference. Added a new summary string, which is displayed when no more users can be added. Bug: 20892920 Change-Id: I00b00f80ba8933a00a2de85777b9f7e55d03c31b
This commit is contained in:
@@ -5425,6 +5425,8 @@
|
||||
<string name="user_nickname">Nickname</string>
|
||||
<!-- Title for add user type dialog [CHAR LIMIT=45] -->
|
||||
<string name="user_add_user_type_title">Add</string>
|
||||
<!-- Summary for add user action, when it's disabled [CHAR LIMIT=100] -->
|
||||
<string name="user_add_max_count">You can add up to <xliff:g id="user_count">%1$d</xliff:g> users</string>
|
||||
<!-- Summary for add user entry in the choice dialog [CHAR LIMIT=none] -->
|
||||
<string name="user_add_user_item_summary">Users have their own apps and content</string>
|
||||
<!-- Summary for add restricted profile entry in the choice dialog [CHAR LIMIT=none] -->
|
||||
|
@@ -23,7 +23,7 @@
|
||||
android:title="@string/user_list_title">
|
||||
</PreferenceCategory>
|
||||
|
||||
<Preference
|
||||
<com.android.settings.DimmableIconPreference
|
||||
android:key="user_add"
|
||||
android:title="@string/user_add_user_or_profile_menu"
|
||||
android:icon="@drawable/ic_menu_add_dark" />
|
||||
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.location;
|
||||
package com.android.settings;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
@@ -35,16 +35,9 @@ public class DimmableIconPreference extends Preference {
|
||||
|
||||
private final CharSequence mContentDescription;
|
||||
|
||||
public DimmableIconPreference(Context context, AttributeSet attrs, int defStyle,
|
||||
@Nullable CharSequence contentDescription) {
|
||||
super(context, attrs, defStyle);
|
||||
mContentDescription = contentDescription;
|
||||
}
|
||||
|
||||
public DimmableIconPreference(Context context, AttributeSet attrs,
|
||||
@Nullable CharSequence contentDescription) {
|
||||
public DimmableIconPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mContentDescription = contentDescription;
|
||||
mContentDescription = null;
|
||||
}
|
||||
|
||||
public DimmableIconPreference(Context context, @Nullable CharSequence contentDescription) {
|
@@ -31,6 +31,8 @@ import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.preference.Preference;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.DimmableIconPreference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.applications.InstalledAppDetails;
|
||||
|
@@ -39,6 +39,8 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.android.settings.DimmableIconPreference;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@@ -818,12 +818,31 @@ public class UserSettings extends SettingsPreferenceFragment
|
||||
// Append Add user to the end of the list
|
||||
if (mUserCaps.mCanAddUser) {
|
||||
boolean moreUsers = mUserManager.canAddMoreUsers();
|
||||
mAddUser.setEnabled(moreUsers);
|
||||
mAddUser.setOrder(Preference.DEFAULT_ORDER);
|
||||
preferenceScreen.addPreference(mAddUser);
|
||||
mAddUser.setEnabled(moreUsers);
|
||||
if (!moreUsers) {
|
||||
mAddUser.setSummary(getString(R.string.user_add_max_count, getMaxRealUsers()));
|
||||
} else {
|
||||
mAddUser.setSummary(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getMaxRealUsers() {
|
||||
// guest is not counted against getMaxSupportedUsers() number
|
||||
final int maxUsersAndGuest = UserManager.getMaxSupportedUsers() + 1;
|
||||
final List<UserInfo> users = mUserManager.getUsers();
|
||||
// managed profiles are counted against getMaxSupportedUsers()
|
||||
int managedProfiles = 0;
|
||||
for (UserInfo user : users) {
|
||||
if (user.isManagedProfile()) {
|
||||
managedProfiles++;
|
||||
}
|
||||
}
|
||||
return maxUsersAndGuest - managedProfiles;
|
||||
}
|
||||
|
||||
private boolean shouldShowGuestUserPreference(List<UserInfo> users) {
|
||||
boolean showGuestPreference = !mUserCaps.mIsGuest;
|
||||
// If user has DISALLOW_ADD_USER don't allow creating a guest either.
|
||||
|
Reference in New Issue
Block a user