diff options
author | Amith Yamasani <yamasani@google.com> | 2014-06-11 17:25:51 -0700 |
---|---|---|
committer | Amith Yamasani <yamasani@google.com> | 2014-06-12 12:59:47 -0700 |
commit | 1e9c21871e81642669079cd290ef47818a3165bd (patch) | |
tree | b8f951004c8a017f1a9b92290ab1308bc6e89ee5 /packages/SystemUI/src/com/android/systemui/settings | |
parent | 02a9c359a1a6e1175cdd2d560f97be9cdb816a0e (diff) | |
download | frameworks_base-1e9c21871e81642669079cd290ef47818a3165bd.zip frameworks_base-1e9c21871e81642669079cd290ef47818a3165bd.tar.gz frameworks_base-1e9c21871e81642669079cd290ef47818a3165bd.tar.bz2 |
Guest user first iteration
Setting for controlling if guest is enabled on the device.
Setting to hint to apps that they should skip showing first use clings.
User switcher handles creation and deletion of the guest user.
Some tweaks to the user switcher to show some feedback and make the icons
circular.
Change-Id: I187dc381d2ee7c372ec6d35e14aa9ea4dfbe5936
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/settings')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/settings/UserSwitcherHostView.java | 110 |
1 files changed, 102 insertions, 8 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/settings/UserSwitcherHostView.java b/packages/SystemUI/src/com/android/systemui/settings/UserSwitcherHostView.java index d67e7cb..a3b10f2 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/UserSwitcherHostView.java +++ b/packages/SystemUI/src/com/android/systemui/settings/UserSwitcherHostView.java @@ -21,8 +21,16 @@ import com.android.systemui.R; import android.app.ActivityManagerNative; import android.content.Context; import android.content.pm.UserInfo; +import android.graphics.Bitmap; +import android.graphics.BitmapShader; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Shader; +import android.os.Handler; import android.os.RemoteException; import android.os.UserManager; +import android.provider.Settings; +import android.provider.Settings.SettingNotFoundException; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; @@ -43,15 +51,18 @@ import java.util.List; /** * A quick and dirty view to show a user switcher. */ -public class UserSwitcherHostView extends FrameLayout implements ListView.OnItemClickListener { +public class UserSwitcherHostView extends FrameLayout + implements ListView.OnItemClickListener, View.OnClickListener { private static final String TAG = "UserSwitcherDialog"; private ArrayList<UserInfo> mUserInfo = new ArrayList<UserInfo>(); + private UserInfo mGuestUser; private Adapter mAdapter = new Adapter(); private UserManager mUserManager; private Runnable mFinishRunnable; private ListView mListView; + private boolean mGuestUserEnabled; public UserSwitcherHostView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); @@ -60,6 +71,9 @@ public class UserSwitcherHostView extends FrameLayout implements ListView.OnItem return; } mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); + + mGuestUserEnabled = Settings.Global.getInt(context.getContentResolver(), + Settings.Global.GUEST_USER_ENABLED, 0) == 1; } public UserSwitcherHostView(Context context, AttributeSet attrs) { @@ -80,7 +94,39 @@ public class UserSwitcherHostView extends FrameLayout implements ListView.OnItem @Override public void onItemClick(AdapterView<?> l, View v, int position, long id) { - int userId = mAdapter.getItem(position).id; + // Last item is the guest + if (position == mUserInfo.size()) { + postDelayed(new Runnable() { + public void run() { + switchToGuestUser(); + } + }, 100); + } else { + final int userId = mAdapter.getItem(position).id; + postDelayed(new Runnable() { + public void run() { + switchUser(userId); + } + }, 100); + } + } + + @Override + public void onClick(View v) { + // Delete was clicked + postDelayed(new Runnable() { + public void run() { + if (mGuestUser != null) { + switchUser(0); + mUserManager.removeUser(mGuestUser.id); + mGuestUser = null; + refreshUsers(); + } + } + }, 100); + } + + private void switchUser(int userId) { try { WindowManagerGlobal.getWindowManagerService().lockNow(null); ActivityManagerNative.getDefault().switchUser(userId); @@ -90,6 +136,15 @@ public class UserSwitcherHostView extends FrameLayout implements ListView.OnItem } } + private void switchToGuestUser() { + if (mGuestUser == null) { + // No guest user. Create one. + mGuestUser = mUserManager.createGuest(mContext, + mContext.getResources().getString(R.string.guest_nickname)); + } + switchUser(mGuestUser.id); + } + private void finish() { if (mFinishRunnable != null) { mFinishRunnable.run(); @@ -119,9 +174,12 @@ public class UserSwitcherHostView extends FrameLayout implements ListView.OnItem public void refreshUsers() { mUserInfo.clear(); + mGuestUser = null; List<UserInfo> users = mUserManager.getUsers(true); for (UserInfo user : users) { - if (!user.isManagedProfile()) { + if (user.isGuest()) { + mGuestUser = user; + } else if (!user.isManagedProfile()) { mUserInfo.add(user); } } @@ -132,17 +190,25 @@ public class UserSwitcherHostView extends FrameLayout implements ListView.OnItem @Override public int getCount() { - return mUserInfo.size(); + return mUserInfo.size() + (mGuestUserEnabled ? 1 : 0); } @Override public UserInfo getItem(int position) { - return mUserInfo.get(position); + if (position < mUserInfo.size()) { + return mUserInfo.get(position); + } else { + return mGuestUser; + } } @Override public long getItemId(int position) { - return getItem(position).serialNumber; + if (position < mUserInfo.size()) { + return getItem(position).serialNumber; + } else { + return mGuestUser != null ? mGuestUser.serialNumber : -1; + } } @Override @@ -161,18 +227,46 @@ public class UserSwitcherHostView extends FrameLayout implements ListView.OnItem ViewHolder h = new ViewHolder(); h.name = (TextView) v.findViewById(R.id.user_name); h.picture = (ImageView) v.findViewById(R.id.user_picture); + h.delete = (ImageView) v.findViewById(R.id.user_delete); v.setTag(h); return v; } private void bindView(ViewHolder h, UserInfo item) { - h.name.setText(item.name); - h.picture.setImageBitmap(mUserManager.getUserIcon(item.id)); + if (item != null) { + h.name.setText(item.name); + h.picture.setImageBitmap(circularClip(mUserManager.getUserIcon(item.id))); + h.delete.setVisibility(item.isGuest() ? View.VISIBLE : View.GONE); + h.delete.setOnClickListener(UserSwitcherHostView.this); + if (item.isGuest()) { + h.picture.setImageResource(R.drawable.ic_account_circle); + } + } else { + h.name.setText(R.string.guest_new_guest); + h.picture.setImageResource(R.drawable.ic_account_circle); + h.delete.setVisibility(View.GONE); + } + } + + private Bitmap circularClip(Bitmap input) { + if (input == null) { + return null; + } + Bitmap output = Bitmap.createBitmap(input.getWidth(), + input.getHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(output); + final Paint paint = new Paint(); + paint.setShader(new BitmapShader(input, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); + paint.setAntiAlias(true); + canvas.drawCircle(input.getWidth() / 2, input.getHeight() / 2, input.getWidth() / 2, + paint); + return output; } class ViewHolder { TextView name; ImageView picture; + ImageView delete; } } } |