Implement real QS user switcher
Replaces the stop-gap user switcher with the real deal.
Dimensions may need some further adjustments.
Bug: 15545213
Change-Id: I4399635c03553dac935049d5b8297fe5f5c1dc9a
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
index 5f09cbd..4901f40 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
@@ -108,6 +108,9 @@
mHost = host;
}
+ public QSTileHost getHost() {
+ return mHost;
+ }
public void updateResources() {
final Resources res = mContext.getResources();
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetail.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetail.java
deleted file mode 100644
index a9a2724..0000000
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetail.java
+++ /dev/null
@@ -1,78 +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.systemui.qs.tiles;
-
-import com.android.systemui.R;
-import com.android.systemui.qs.QSTile;
-
-import android.content.Context;
-import android.content.Intent;
-import android.util.AttributeSet;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.FrameLayout;
-
-/**
- * Quick settings detail view for user switching.
- */
-public class UserDetail extends FrameLayout {
-
- static final Intent USER_SETTINGS_INTENT = new Intent("android.settings.USER_SETTINGS");
-
- public UserDetail(Context context) {
- this(context, null);
- }
-
- public UserDetail(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public UserDetail(Context context, AttributeSet attrs, int defStyleAttr) {
- this(context, attrs, defStyleAttr, 0);
- }
-
- public UserDetail(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- }
-
- public static QSTile.DetailAdapter USER_DETAIL_ADAPTER = new QSTile.DetailAdapter() {
- @Override
- public int getTitle() {
- return R.string.quick_settings_user_title;
- }
-
- @Override
- public Boolean getToggleState() {
- return null;
- }
-
- @Override
- public View createDetailView(Context context, View convertView, ViewGroup parent) {
- return LayoutInflater.from(context).inflate(R.layout.qs_user_detail, parent, false);
- }
-
- @Override
- public Intent getSettingsIntent() {
- return USER_SETTINGS_INTENT;
- }
-
- @Override
- public void setToggleState(boolean state) {
- }
- };
-}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailItemView.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailItemView.java
new file mode 100644
index 0000000..d765aab
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailItemView.java
@@ -0,0 +1,82 @@
+/*
+ * 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.systemui.qs.tiles;
+
+import com.android.systemui.R;
+import com.android.systemui.statusbar.phone.UserAvatarView;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+/**
+ * Displays one user in the {@link UserDetailView} view.
+ */
+public class UserDetailItemView extends LinearLayout {
+
+ private UserAvatarView mAvatar;
+ private TextView mName;
+
+ public UserDetailItemView(Context context) {
+ this(context, null);
+ }
+
+ public UserDetailItemView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ public static UserDetailItemView convertOrInflate(Context context, View convertView,
+ ViewGroup root) {
+ if (!(convertView instanceof UserDetailItemView)) {
+ convertView = LayoutInflater.from(context).inflate(
+ R.layout.qs_user_detail_item, root, false);
+ }
+ return (UserDetailItemView) convertView;
+ }
+
+ public void bind(String name, Bitmap picture) {
+ mName.setText(name);
+ mAvatar.setBitmap(picture);
+ }
+
+ public void bind(String name, Drawable picture) {
+ mName.setText(name);
+ mAvatar.setDrawable(picture);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ mAvatar = (UserAvatarView) findViewById(R.id.user_picture);
+ mName = (TextView) findViewById(R.id.user_name);
+ }
+
+}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java
new file mode 100644
index 0000000..ec5f28c
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/UserDetailView.java
@@ -0,0 +1,101 @@
+/*
+ * 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.systemui.qs.tiles;
+
+import com.android.systemui.R;
+import com.android.systemui.statusbar.policy.UserSwitcherController;
+
+import android.content.Context;
+import android.content.Intent;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.GridView;
+
+/**
+ * Quick settings detail view for user switching.
+ */
+public class UserDetailView extends GridView {
+
+ public UserDetailView(Context context) {
+ this(context, null);
+ }
+
+ public UserDetailView(Context context, AttributeSet attrs) {
+ this(context, attrs, android.R.attr.gridViewStyle);
+ }
+
+ public UserDetailView(Context context, AttributeSet attrs, int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public UserDetailView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+
+ setOnItemClickListener(new OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ UserSwitcherController.UserRecord tag =
+ (UserSwitcherController.UserRecord) view.getTag();
+ ((Adapter)getAdapter()).switchTo(tag);
+ }
+ });
+ }
+
+ public static UserDetailView inflate(Context context, ViewGroup parent, boolean attach) {
+ return (UserDetailView) LayoutInflater.from(context).inflate(
+ R.layout.qs_user_detail, parent, attach);
+ }
+
+ public void createAndSetAdapter(UserSwitcherController controller) {
+ setAdapter(new Adapter(mContext, controller));
+ }
+
+ public static class Adapter extends UserSwitcherController.BaseUserAdapter {
+
+ private Context mContext;
+
+ public Adapter(Context context, UserSwitcherController controller) {
+ super(controller);
+ mContext = context;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ UserSwitcherController.UserRecord item = getItem(position);
+ UserDetailItemView v = UserDetailItemView.convertOrInflate(
+ mContext, convertView, parent);
+ String name;
+ if (item.isGuest) {
+ name = mContext.getString(
+ item.info == null ? R.string.guest_new_guest : R.string.guest_nickname);
+ } else {
+ name = item.info.name;
+ }
+ if (item.picture == null) {
+ v.bind(name, mContext.getDrawable(R.drawable.ic_account_circle));
+ } else {
+ v.bind(name, item.picture);
+ }
+ v.setActivated(item.isCurrent);
+ v.setTag(item);
+ return v;
+ }
+ }
+}