UI to add a photo to a user's profile.
Photo will be shown in user management screen and switcher. Change-Id: Icc0a39487daae13530fc1741780fb42fee0dada4
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<original-package android:name="com.android.settings" />
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.DEVICE_POWER" />
|
||||
|
@@ -4065,4 +4065,9 @@
|
||||
<string name="help_url_backup_reset" translatable="false"></string>
|
||||
<!-- Help URL, Tethering [DO NOT TRANSLATE] -->
|
||||
<string name="help_url_tether" translatable="false"></string>
|
||||
|
||||
<!-- User account title [CHAR LIMIT=30] -->
|
||||
<string name="user_account_title">Account for content</string>
|
||||
<!-- User picture title [CHAR LIMIT=30] -->
|
||||
<string name="user_picture_title">Photo ID</string>
|
||||
</resources>
|
||||
|
@@ -106,13 +106,6 @@
|
||||
<!-- PERSONAL -->
|
||||
<header android:title="@string/header_category_personal" />
|
||||
|
||||
<!-- Manage users -->
|
||||
<header
|
||||
android:fragment="com.android.settings.users.UserSettings"
|
||||
android:icon="@drawable/ic_settings_sync"
|
||||
android:title="@string/user_settings_title"
|
||||
android:id="@+id/user_settings" />
|
||||
|
||||
<!-- Location -->
|
||||
<header
|
||||
android:fragment="com.android.settings.LocationSettings"
|
||||
@@ -146,6 +139,13 @@
|
||||
android:id="@+id/account_settings"
|
||||
android:title="@string/account_settings" />
|
||||
|
||||
<!-- Manage users -->
|
||||
<header
|
||||
android:fragment="com.android.settings.users.UserSettings"
|
||||
android:icon="@drawable/ic_settings_sync"
|
||||
android:title="@string/user_settings_title"
|
||||
android:id="@+id/user_settings" />
|
||||
|
||||
<header
|
||||
android:id="@+id/account_add"
|
||||
android:title="@string/add_account_label"
|
||||
|
@@ -26,11 +26,22 @@
|
||||
android:title="@string/user_name_title"
|
||||
android:persistent="false"
|
||||
/>
|
||||
<Preference
|
||||
android:key="user_picture"
|
||||
android:title="@string/user_picture_title"
|
||||
android:persistent="false"
|
||||
/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="restrictions_category"
|
||||
android:title="@string/user_restrictions_heading">
|
||||
<Preference
|
||||
android:key="associated_account"
|
||||
android:title="@string/user_account_title"
|
||||
android:enabled="false"
|
||||
android:persistent="false"
|
||||
/>
|
||||
<CheckBoxPreference
|
||||
android:key="market_requires_pin"
|
||||
android:title="@string/user_market_requires_pin"
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.users;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
@@ -26,12 +27,14 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.CompressFormat;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemProperties;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.Preference;
|
||||
@@ -50,7 +53,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener, DialogCreatable {
|
||||
implements Preference.OnPreferenceChangeListener, DialogCreatable,
|
||||
Preference.OnPreferenceClickListener {
|
||||
|
||||
private static final String TAG = "UserDetailsSettings";
|
||||
|
||||
@@ -58,15 +62,16 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
private static final int DIALOG_CONFIRM_REMOVE = 1;
|
||||
|
||||
private static final String KEY_USER_NAME = "user_name";
|
||||
private static final String KEY_USER_PICTURE = "user_picture";
|
||||
private static final String KEY_INSTALLED_APPS = "market_apps_category";
|
||||
private static final String KEY_SYSTEM_APPS = "system_apps_category";
|
||||
private static final String KEY_ACCOUNT = "associated_account";
|
||||
private static final String KEY_RESTRICTIONS = "restrictions_category";
|
||||
|
||||
public static final String EXTRA_USER_ID = "user_id";
|
||||
|
||||
private static final String[] SYSTEM_APPS = {
|
||||
"com.google.android.browser",
|
||||
"com.google.android.gm",
|
||||
"com.google.android.youtube"
|
||||
};
|
||||
private static final int RESULT_PICK_IMAGE = 1;
|
||||
private static final int RESULT_CROP_IMAGE = 2;
|
||||
|
||||
static class AppState {
|
||||
boolean dirty;
|
||||
@@ -81,6 +86,8 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
private PreferenceGroup mSystemAppGroup;
|
||||
private PreferenceGroup mInstalledAppGroup;
|
||||
private EditTextPreference mNamePref;
|
||||
private Preference mPicturePref;
|
||||
private Preference mAccountPref;
|
||||
|
||||
private IPackageManager mIPm;
|
||||
private PackageManager mPm;
|
||||
@@ -106,7 +113,16 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
mInstalledAppGroup = (PreferenceGroup) findPreference(KEY_INSTALLED_APPS);
|
||||
mNamePref = (EditTextPreference) findPreference(KEY_USER_NAME);
|
||||
mNamePref.setOnPreferenceChangeListener(this);
|
||||
mPicturePref = findPreference(KEY_USER_PICTURE);
|
||||
mPicturePref.setOnPreferenceClickListener(this);
|
||||
mAccountPref = findPreference(KEY_ACCOUNT);
|
||||
mAccountPref.setOnPreferenceClickListener(this);
|
||||
|
||||
if (mUserId == 0) {
|
||||
getPreferenceScreen().removePreference(mSystemAppGroup);
|
||||
getPreferenceScreen().removePreference(mInstalledAppGroup);
|
||||
getPreferenceScreen().removePreference(findPreference(KEY_RESTRICTIONS));
|
||||
}
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@@ -114,7 +130,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mPm = getActivity().getPackageManager();
|
||||
if (mUserId > 0) {
|
||||
if (mUserId >= 0) {
|
||||
initExistingUser();
|
||||
} else {
|
||||
initNewUser();
|
||||
@@ -124,6 +140,9 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (mUserId == 0) {
|
||||
return;
|
||||
}
|
||||
MenuItem addAccountItem = menu.add(0, MENU_REMOVE_USER, 0,
|
||||
mNewUser ? R.string.user_discard_user_menu : R.string.user_remove_user_menu);
|
||||
addAccountItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
|
||||
@@ -153,6 +172,9 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
if (foundUser != null) {
|
||||
mNamePref.setSummary(foundUser.name);
|
||||
mNamePref.setText(foundUser.name);
|
||||
if (foundUser.iconPath != null) {
|
||||
setPhotoId(foundUser.iconPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,6 +222,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
private void refreshApps() {
|
||||
if (mUserId == 0) return;
|
||||
mSystemAppGroup.removeAll();
|
||||
mInstalledAppGroup.removeAll();
|
||||
|
||||
@@ -254,7 +277,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
mIPm.updateUserName(mUserId, (String) newValue);
|
||||
mIPm.setUserName(mUserId, (String) newValue);
|
||||
mNamePref.setSummary((String) newValue);
|
||||
} catch (RemoteException re) {
|
||||
return false;
|
||||
@@ -282,4 +305,72 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (preference == mAccountPref) {
|
||||
// Intent launch = AccountManager.newChooseAccountsIntent(null, null, new String[]{"com.google"}, false, null,
|
||||
// null, null, null);
|
||||
} else if (preference == mPicturePref) {
|
||||
Intent intent = new Intent();
|
||||
intent.setType("image/*");
|
||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
|
||||
startActivityForResult(intent, RESULT_PICK_IMAGE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode != Activity.RESULT_OK) {
|
||||
return;
|
||||
}
|
||||
switch (requestCode) {
|
||||
case RESULT_PICK_IMAGE:
|
||||
if (data.getData() != null) {
|
||||
Uri imageUri = data.getData();
|
||||
System.err.println("imageUri = " + imageUri);
|
||||
cropImage(imageUri);
|
||||
}
|
||||
break;
|
||||
case RESULT_CROP_IMAGE:
|
||||
saveCroppedImage(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void cropImage(Uri imageUri) {
|
||||
final Uri inputPhotoUri = imageUri;
|
||||
Intent intent = new Intent("com.android.camera.action.CROP");
|
||||
intent.setDataAndType(inputPhotoUri, "image/*");
|
||||
intent.putExtra("crop", "true");
|
||||
intent.putExtra("aspectX", 1);
|
||||
intent.putExtra("aspectY", 1);
|
||||
intent.putExtra("outputX", 96);
|
||||
intent.putExtra("outputY", 96);
|
||||
intent.putExtra("return-data", true);
|
||||
startActivityForResult(intent, RESULT_CROP_IMAGE);
|
||||
}
|
||||
|
||||
private void saveCroppedImage(Intent data) {
|
||||
try {
|
||||
if (data.hasExtra("data")) {
|
||||
Bitmap bitmap = (Bitmap) data.getParcelableExtra("data");
|
||||
ParcelFileDescriptor fd = mIPm.setUserIcon(mUserId);
|
||||
if (fd != null) {
|
||||
bitmap.compress(CompressFormat.PNG, 100,
|
||||
new ParcelFileDescriptor.AutoCloseOutputStream(fd));
|
||||
setPhotoId(mPm.getUser(mUserId).iconPath);
|
||||
}
|
||||
}
|
||||
} catch (RemoteException re) {
|
||||
}
|
||||
}
|
||||
|
||||
private void setPhotoId(String realPath) {
|
||||
Drawable d = Drawable.createFromPath(realPath);
|
||||
if (d == null) return;
|
||||
mPicturePref.setIcon(d);
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.users;
|
||||
|
||||
import android.content.pm.UserInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
@@ -83,15 +84,23 @@ public class UserSettings extends SettingsPreferenceFragment
|
||||
|
||||
mUserListCategory.removeAll();
|
||||
for (UserInfo user : users) {
|
||||
if (user.id == 0) continue;
|
||||
Preference pref = new Preference(getActivity());
|
||||
pref.setTitle(user.name);
|
||||
pref.setOnPreferenceClickListener(this);
|
||||
pref.setKey("id=" + user.id);
|
||||
if (user.iconPath != null) {
|
||||
setPhotoId(pref, user.iconPath);
|
||||
}
|
||||
mUserListCategory.addPreference(pref);
|
||||
}
|
||||
}
|
||||
|
||||
private void setPhotoId(Preference pref, String realPath) {
|
||||
Drawable d = Drawable.createFromPath(realPath);
|
||||
if (d == null) return;
|
||||
pref.setIcon(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference pref) {
|
||||
String sid = pref.getKey();
|
||||
|
Reference in New Issue
Block a user