Multiuser settings revamp - followup to address comments
Bug: 15761405
Change-Id: I9c03432a2f2651a931486ce65fb3b5af37608be0
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 2887b1a..692d8f3 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -18,12 +18,14 @@
import android.app.ActivityManager;
import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.Fragment;
import android.app.IActivityManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -61,6 +63,7 @@
import android.widget.ListView;
import android.widget.TabWidget;
+import com.android.settings.R.string;
import com.android.settings.dashboard.DashboardCategory;
import com.android.settings.dashboard.DashboardTile;
@@ -636,4 +639,35 @@
// Default to current profile
return new UserHandle(currentUser);
}
+
+ /**
+ * Creates a dialog to confirm with the user if it's ok to remove the user
+ * and delete all the data.
+ *
+ * @param context a Context object
+ * @param removingUserId The userId of the user to remove
+ * @param onConfirmListener Callback object for positive action
+ * @return the created Dialog
+ */
+ public static Dialog createRemoveConfirmationDialog(Context context, int removingUserId,
+ DialogInterface.OnClickListener onConfirmListener) {
+ UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ UserInfo userInfo = um.getUserInfo(removingUserId);
+ Dialog dlg = new AlertDialog.Builder(context)
+ .setTitle(UserHandle.myUserId() == removingUserId
+ ? R.string.user_confirm_remove_self_title
+ : (userInfo.isRestricted()
+ ? R.string.user_profile_confirm_remove_title
+ : R.string.user_confirm_remove_title))
+ .setMessage(UserHandle.myUserId() == removingUserId
+ ? R.string.user_confirm_remove_self_message
+ : (userInfo.isRestricted()
+ ? R.string.user_profile_confirm_remove_message
+ : R.string.user_confirm_remove_message))
+ .setPositiveButton(R.string.user_delete_button,
+ onConfirmListener)
+ .setNegativeButton(android.R.string.cancel, null)
+ .create();
+ return dlg;
+ }
}
diff --git a/src/com/android/settings/users/RemoveUserUtil.java b/src/com/android/settings/users/RemoveUserUtil.java
deleted file mode 100644
index ac74bfa..0000000
--- a/src/com/android/settings/users/RemoveUserUtil.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.users;
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.pm.UserInfo;
-import android.os.UserHandle;
-import android.os.UserManager;
-
-import com.android.settings.R;
-
-public class RemoveUserUtil {
-
- static Dialog createConfirmationDialog(Context context, int removingUserId,
- DialogInterface.OnClickListener onConfirmListener) {
- final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
- final UserInfo userInfo = um.getUserInfo(removingUserId);
- Dialog dlg = new AlertDialog.Builder(context)
- .setTitle(UserHandle.myUserId() == removingUserId
- ? R.string.user_confirm_remove_self_title
- : (userInfo.isRestricted()
- ? R.string.user_profile_confirm_remove_title
- : R.string.user_confirm_remove_title))
- .setMessage(UserHandle.myUserId() == removingUserId
- ? R.string.user_confirm_remove_self_message
- : (userInfo.isRestricted()
- ? R.string.user_profile_confirm_remove_message
- : R.string.user_confirm_remove_message))
- .setPositiveButton(R.string.user_delete_button,
- onConfirmListener)
- .setNegativeButton(android.R.string.cancel, null)
- .create();
- return dlg;
- }
-}
diff --git a/src/com/android/settings/users/RestrictedProfileSettings.java b/src/com/android/settings/users/RestrictedProfileSettings.java
index 41acda4..535e196 100644
--- a/src/com/android/settings/users/RestrictedProfileSettings.java
+++ b/src/com/android/settings/users/RestrictedProfileSettings.java
@@ -101,7 +101,7 @@
mHeaderView.setOnClickListener(this);
mUserIconView = (ImageView) mHeaderView.findViewById(android.R.id.icon);
mUserNameView = (TextView) mHeaderView.findViewById(android.R.id.title);
- //getListView().setFastScrollEnabled(true);
+ getListView().setFastScrollEnabled(true);
}
// This is going to bind the preferences.
super.onActivityCreated(savedInstanceState);
diff --git a/src/com/android/settings/users/UserDetailsSettings.java b/src/com/android/settings/users/UserDetailsSettings.java
index 56b4598..d342fad 100644
--- a/src/com/android/settings/users/UserDetailsSettings.java
+++ b/src/com/android/settings/users/UserDetailsSettings.java
@@ -34,6 +34,7 @@
* Settings screen for configuring a specific user. It can contain user restrictions
* and deletion controls. It is shown when you tap on the settings icon in the
* user management (UserSettings) screen.
+ *
* Arguments to this fragment must include the userId of the user (in EXTRA_USER_ID) for whom
* to display controls, or should contain the EXTRA_USER_GUEST = true.
*/
@@ -130,7 +131,7 @@
if (context == null) return null;
switch (dialogId) {
case DIALOG_CONFIRM_REMOVE: {
- Dialog dlg = RemoveUserUtil.createConfirmationDialog(getActivity(), mUserInfo.id,
+ Dialog dlg = Utils.createRemoveConfirmationDialog(getActivity(), mUserInfo.id,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
removeUser();
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 42e1a5b..2d58327 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -211,10 +211,8 @@
mAddUser.setOnPreferenceClickListener(this);
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
Context.DEVICE_POLICY_SERVICE);
- // No restricted profiles for tablets with a device owner, or
- // phones.
- if (dpm.getDeviceOwner() != null
- || Utils.isVoiceCapable(context)) {
+ // No restricted profiles for tablets with a device owner, or phones.
+ if (dpm.getDeviceOwner() != null || Utils.isVoiceCapable(context)) {
mCanAddRestrictedProfile = false;
mAddUser.setTitle(R.string.user_add_user_menu);
}
@@ -431,7 +429,11 @@
extras.putInt(UserDetailsSettings.EXTRA_USER_ID, userId);
((SettingsActivity) getActivity()).startPreferencePanel(
UserDetailsSettings.class.getName(),
- extras, -1, info.name, null, 0);
+ extras,
+ -1, /* No title res id */
+ info.name, /* title */
+ null, /* resultTo */
+ 0 /* resultRequestCode */);
}
}
@@ -458,7 +460,7 @@
switch (dialogId) {
case DIALOG_CONFIRM_REMOVE: {
Dialog dlg =
- RemoveUserUtil.createConfirmationDialog(getActivity(), mRemovingUserId,
+ Utils.createRemoveConfirmationDialog(getActivity(), mRemovingUserId,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
removeUserNow();
@@ -665,8 +667,6 @@
pref = new UserPreference(context, null, user.id,
showSettings ? this : null,
showDelete ? this : null);
- //mIsOwner && user.isRestricted() ? this : null,
- //mIsOwner ? this : null);
pref.setOnPreferenceClickListener(this);
pref.setKey("id=" + user.id);
mUserListCategory.addPreference(pref);