am 66b9fb16: Iintial stab at multi-user switcher on Keyguard
* commit '66b9fb1662b304d24984af1ac4cc02f2ae8f4cc3': Iintial stab at multi-user switcher on Keyguard
This commit is contained in:
40
core/res/res/layout/keyguard_multi_user_avatar.xml
Normal file
40
core/res/res/layout/keyguard_multi_user_avatar.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
**
|
||||
** Copyright 2009, 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<!-- This is a view that shows general status information in Keyguard. -->
|
||||
<com.android.internal.policy.impl.keyguard.KeyguardMultiUserAvatar
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="125dp"
|
||||
android:layout_height="125dp"
|
||||
android:background="#550000ff"
|
||||
android:gravity="center_horizontal">
|
||||
<ImageView
|
||||
android:id="@+id/keyguard_user_avatar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"/>
|
||||
<TextView
|
||||
android:id="@+id/keyguard_user_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|right"
|
||||
android:textSize="12sp"
|
||||
android:background="#99FFFFFF"
|
||||
android:textColor="#ff000000"/>
|
||||
</com.android.internal.policy.impl.keyguard.KeyguardMultiUserAvatar>
|
||||
41
core/res/res/layout/keyguard_multi_user_selector.xml
Normal file
41
core/res/res/layout/keyguard_multi_user_selector.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
**
|
||||
** Copyright 2009, 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.
|
||||
*/
|
||||
-->
|
||||
<com.android.internal.policy.impl.keyguard.KeyguardMultiUserSelectorView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="375dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<include
|
||||
android:id="@+id/keyguard_active_user"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="250dp"
|
||||
layout="@layout/keyguard_multi_user_avatar"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="125dp"
|
||||
android:layout_height="250dp">
|
||||
<LinearLayout
|
||||
android:id="@+id/keyguard_inactive_users"
|
||||
android:orientation="vertical"
|
||||
layout_width="match_parent"
|
||||
layout_height="wrap_content"/>
|
||||
</ScrollView>
|
||||
</com.android.internal.policy.impl.keyguard.KeyguardMultiUserSelectorView>
|
||||
28
core/res/res/layout/keyguard_multi_user_selector_widget.xml
Normal file
28
core/res/res/layout/keyguard_multi_user_selector_widget.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
**
|
||||
** Copyright 2009, 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<!-- This is a view that shows general status information in Keyguard. -->
|
||||
<com.android.internal.policy.impl.keyguard.KeyguardWidgetFrame
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<include layout="@layout/keyguard_multi_user_selector"/>
|
||||
|
||||
</com.android.internal.policy.impl.keyguard.KeyguardWidgetFrame>
|
||||
@@ -32,7 +32,7 @@
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1"
|
||||
android:visibility="gone">
|
||||
<!-- TODO: Remove this once supported as a widget -->
|
||||
<!-- TODO: Remove this when supported as a widget -->
|
||||
<include layout="@layout/keyguard_status_view"/>
|
||||
</com.android.internal.policy.impl.keyguard.KeyguardWidgetPager>
|
||||
|
||||
|
||||
@@ -1139,6 +1139,8 @@
|
||||
<java-symbol type="layout" name="notification_template_part_time" />
|
||||
<java-symbol type="layout" name="notification_template_part_chronometer" />
|
||||
<java-symbol type="layout" name="notification_template_inbox" />
|
||||
<java-symbol type="layout" name="keyguard_multi_user_avatar" />
|
||||
<java-symbol type="layout" name="keyguard_multi_user_selector_widget" />
|
||||
|
||||
<java-symbol type="anim" name="slide_in_child_bottom" />
|
||||
<java-symbol type="anim" name="slide_in_right" />
|
||||
@@ -1338,6 +1340,10 @@
|
||||
<java-symbol type="id" name="sim_pin_entry" />
|
||||
<java-symbol type="id" name="puk_delete_button" />
|
||||
<java-symbol type="id" name="pin_delete_button" />
|
||||
<java-symbol type="id" name="keyguard_user_avatar" />
|
||||
<java-symbol type="id" name="keyguard_user_name" />
|
||||
<java-symbol type="id" name="keyguard_active_user" />
|
||||
<java-symbol type="id" name="keyguard_inactive_users" />
|
||||
<java-symbol type="integer" name="config_carDockRotation" />
|
||||
<java-symbol type="integer" name="config_defaultUiModeType" />
|
||||
<java-symbol type="integer" name="config_deskDockRotation" />
|
||||
|
||||
@@ -29,26 +29,30 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentSender;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.os.UserManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.Button;
|
||||
import android.widget.ViewFlipper;
|
||||
import android.widget.RemoteViews.OnClickHandler;
|
||||
import android.widget.ViewFlipper;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.policy.impl.keyguard.KeyguardSecurityModel.SecurityMode;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.internal.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class KeyguardHostView extends KeyguardViewBase {
|
||||
// Use this to debug all of keyguard
|
||||
@@ -614,6 +618,7 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
Log.v(TAG, "Keyguard widgets disabled because of device policy admin");
|
||||
return;
|
||||
}
|
||||
inflateAndAddUserSelectorWidgetIfNecessary();
|
||||
SharedPreferences prefs = mContext.getSharedPreferences(
|
||||
KEYGUARD_WIDGET_PREFS, Context.MODE_PRIVATE);
|
||||
for (String key : prefs.getAll().keySet()) {
|
||||
@@ -627,6 +632,21 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
}
|
||||
}
|
||||
|
||||
private void inflateAndAddUserSelectorWidgetIfNecessary() {
|
||||
// if there are multiple users, we need to add the multi-user switcher widget to the
|
||||
// keyguard.
|
||||
UserManager mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
List<UserInfo> users = mUm.getUsers();
|
||||
|
||||
if (users.size() > 1) {
|
||||
KeyguardWidgetFrame userswitcher = (KeyguardWidgetFrame)
|
||||
LayoutInflater.from(mContext).inflate(R.layout.keyguard_multi_user_selector_widget,
|
||||
mAppWidgetContainer, false);
|
||||
// add the switcher in the first position
|
||||
mAppWidgetContainer.addView(userswitcher, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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.internal.policy.impl.keyguard;
|
||||
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.content.Context;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.RemoteException;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManagerGlobal;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.R;
|
||||
|
||||
class KeyguardMultiUserAvatar extends FrameLayout {
|
||||
private static final String TAG = "KeyguardViewHost";
|
||||
|
||||
private ImageView mUserImage;
|
||||
private TextView mUserName;
|
||||
private UserInfo mUserInfo;
|
||||
private KeyguardMultiUserSelectorView mUserSelector;
|
||||
|
||||
public static KeyguardMultiUserAvatar fromXml(int resId, Context context,
|
||||
KeyguardMultiUserSelectorView userSelector, UserInfo info) {
|
||||
KeyguardMultiUserAvatar icon = (KeyguardMultiUserAvatar)
|
||||
LayoutInflater.from(context).inflate(resId, userSelector, false);
|
||||
|
||||
icon.setup(info, userSelector);
|
||||
return icon;
|
||||
}
|
||||
|
||||
public KeyguardMultiUserAvatar(Context context) {
|
||||
super(context, null, 0);
|
||||
}
|
||||
|
||||
public KeyguardMultiUserAvatar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs, 0);
|
||||
}
|
||||
|
||||
public KeyguardMultiUserAvatar(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public void setup(UserInfo user, KeyguardMultiUserSelectorView userSelector) {
|
||||
mUserInfo = user;
|
||||
mUserSelector = userSelector;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mUserImage = (ImageView) findViewById(R.id.keyguard_user_avatar);
|
||||
mUserName = (TextView) findViewById(R.id.keyguard_user_name);
|
||||
|
||||
mUserImage.setImageDrawable(Drawable.createFromPath(mUserInfo.iconPath));
|
||||
mUserName.setText(mUserInfo.name);
|
||||
setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
ActivityManagerNative.getDefault().switchUser(mUserInfo.id);
|
||||
WindowManagerGlobal.getWindowManagerService().lockNow();
|
||||
mUserSelector.init();
|
||||
} catch (RemoteException re) {
|
||||
Log.e(TAG, "Couldn't switch user " + re);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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.internal.policy.impl.keyguard;
|
||||
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.content.Context;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.internal.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class KeyguardMultiUserSelectorView extends LinearLayout{
|
||||
private KeyguardMultiUserAvatar mActiveUser;
|
||||
private LinearLayout mInactiveUsers;
|
||||
|
||||
public KeyguardMultiUserSelectorView(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public KeyguardMultiUserSelectorView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public KeyguardMultiUserSelectorView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
protected void onFinishInflate () {
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
mActiveUser = (KeyguardMultiUserAvatar) findViewById(R.id.keyguard_active_user);
|
||||
mInactiveUsers = (LinearLayout) findViewById(R.id.keyguard_inactive_users);
|
||||
|
||||
mInactiveUsers.removeAllViews();
|
||||
|
||||
UserInfo currentUser;
|
||||
try {
|
||||
currentUser = ActivityManagerNative.getDefault().getCurrentUser();
|
||||
} catch (RemoteException re) {
|
||||
currentUser = null;
|
||||
}
|
||||
|
||||
UserManager mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUm.getUsers());
|
||||
for (UserInfo user: users) {
|
||||
if (user.id == currentUser.id) {
|
||||
setActiveUser(user);
|
||||
} else {
|
||||
createAndAddInactiveUser(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setActiveUser(UserInfo user) {
|
||||
mActiveUser.setup(user, this);
|
||||
}
|
||||
|
||||
private void createAndAddInactiveUser(UserInfo user) {
|
||||
KeyguardMultiUserAvatar uv = KeyguardMultiUserAvatar.fromXml(
|
||||
R.layout.keyguard_multi_user_avatar, mContext, this, user);
|
||||
mInactiveUsers.addView(uv);
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ public class KeyguardWidgetFrame extends FrameLayout {
|
||||
private static Drawable sRightOverscrollDrawable;
|
||||
|
||||
private Drawable mForegroundDrawable;
|
||||
private float mOverScrollAmount = 0f;
|
||||
private final Rect mForegroundRect = new Rect();
|
||||
private int mForegroundAlpha = 0;
|
||||
|
||||
@@ -80,14 +81,17 @@ public class KeyguardWidgetFrame extends FrameLayout {
|
||||
}
|
||||
|
||||
void setOverScrollAmount(float r, boolean left) {
|
||||
if (left && mForegroundDrawable != sLeftOverscrollDrawable) {
|
||||
mForegroundDrawable = sLeftOverscrollDrawable;
|
||||
} else if (!left && mForegroundDrawable != sRightOverscrollDrawable) {
|
||||
mForegroundDrawable = sRightOverscrollDrawable;
|
||||
}
|
||||
if (Float.compare(mOverScrollAmount, r) != 0) {
|
||||
mOverScrollAmount = r;
|
||||
if (left && mForegroundDrawable != sLeftOverscrollDrawable) {
|
||||
mForegroundDrawable = sLeftOverscrollDrawable;
|
||||
} else if (!left && mForegroundDrawable != sRightOverscrollDrawable) {
|
||||
mForegroundDrawable = sRightOverscrollDrawable;
|
||||
}
|
||||
|
||||
mForegroundAlpha = (int) Math.round((r * 255));
|
||||
mForegroundDrawable.setAlpha(mForegroundAlpha);
|
||||
invalidate();
|
||||
mForegroundAlpha = (int) Math.round((r * 255));
|
||||
mForegroundDrawable.setAlpha(mForegroundAlpha);
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,9 @@ public class KeyguardWidgetPager extends PagedView {
|
||||
v.setPivotY(pageHeight / 2.0f);
|
||||
v.setPivotX(pageWidth / 2.0f);
|
||||
v.setRotationY(0f);
|
||||
if (v instanceof KeyguardWidgetFrame) {
|
||||
((KeyguardWidgetFrame) v).setOverScrollAmount(0, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user