Futureproof trusted credentials for multiple profiles

Made use of the shiny LayoutTransition.CHANGING animations. Now it's a
little more obvious where things are going when tapping a header.

Future work: maybe show the usernames / user icons in there too? This
could get complicated, and it'll need to be done everywhere at once.

Change-Id: Id7396235abe6218d591d16db91af0f56a83a7bcd
Fix: 28310002
This commit is contained in:
Robin Lee
2016-08-02 10:52:22 +01:00
parent b0d54ca660
commit 232f057df0
4 changed files with 49 additions and 82 deletions

View File

@@ -14,10 +14,9 @@
limitations under the License. limitations under the License.
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical">
android:visibility="gone">
<LinearLayout <LinearLayout
android:id="@+id/header_view" android:id="@+id/header_view"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@@ -54,4 +53,4 @@
android:id="@+id/cert_list" android:id="@+id/cert_list"
style="@style/TrustedCredentialsList"> style="@style/TrustedCredentialsList">
</ListView> </ListView>
</LinearLayout> </LinearLayout>

View File

@@ -54,20 +54,8 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:visibility="gone"> android:visibility="gone"
android:animateLayoutChanges="true">
<include
android:id="@+id/system_personal_container"
layout="@layout/trusted_credential_list_container"/>
<include
android:id="@+id/system_work_container"
layout="@layout/trusted_credential_list_container"/>
<ExpandableListView
android:id="@+id/system_expandable_list"
style="@style/TrustedCredentialsList"
android:visibility="gone">
</ExpandableListView>
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>
@@ -91,21 +79,8 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:visibility="gone"> android:visibility="gone"
android:animateLayoutChanges="true">
<include
android:id="@+id/user_personal_container"
layout="@layout/trusted_credential_list_container"/>
<include
android:id="@+id/user_work_container"
layout="@layout/trusted_credential_list_container"/>
<ExpandableListView
android:id="@+id/user_expandable_list"
style="@style/TrustedCredentialsList"
android:visibility="gone">
</ExpandableListView>
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>

View File

@@ -147,8 +147,8 @@
</style> </style>
<style name="TrustedCredentialsList"> <style name="TrustedCredentialsList">
<item name="android:layout_width">fill_parent</item> <item name="android:layout_width">match_parent</item>
<item name="android:layout_height">fill_parent</item> <item name="android:layout_height">match_parent</item>
<item name="android:scrollbarStyle">outsideOverlay</item> <item name="android:scrollbarStyle">outsideOverlay</item>
</style> </style>

View File

@@ -16,6 +16,10 @@
package com.android.settings; package com.android.settings;
import static android.widget.LinearLayout.LayoutParams.MATCH_PARENT;
import static android.widget.LinearLayout.LayoutParams.WRAP_CONTENT;
import android.animation.LayoutTransition;
import android.annotation.UiThread; import android.annotation.UiThread;
import android.app.Activity; import android.app.Activity;
import android.app.KeyguardManager; import android.app.KeyguardManager;
@@ -96,18 +100,12 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment
R.string.trusted_credentials_system_tab, R.string.trusted_credentials_system_tab,
R.id.system_tab, R.id.system_tab,
R.id.system_progress, R.id.system_progress,
R.id.system_personal_container,
R.id.system_work_container,
R.id.system_expandable_list,
R.id.system_content, R.id.system_content,
true), true),
USER("user", USER("user",
R.string.trusted_credentials_user_tab, R.string.trusted_credentials_user_tab,
R.id.user_tab, R.id.user_tab,
R.id.user_progress, R.id.user_progress,
R.id.user_personal_container,
R.id.user_work_container,
R.id.user_expandable_list,
R.id.user_content, R.id.user_content,
false); false);
@@ -115,21 +113,14 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment
private final int mLabel; private final int mLabel;
private final int mView; private final int mView;
private final int mProgress; private final int mProgress;
private final int mPersonalList;
private final int mWorkList;
private final int mExpandableList;
private final int mContentView; private final int mContentView;
private final boolean mSwitch; private final boolean mSwitch;
private Tab(String tag, int label, int view, int progress, int personalList, int workList, private Tab(String tag, int label, int view, int progress, int contentView, boolean withSwitch) {
int expandableList, int contentView, boolean withSwitch) {
mTag = tag; mTag = tag;
mLabel = label; mLabel = label;
mView = view; mView = view;
mProgress = progress; mProgress = progress;
mPersonalList = personalList;
mWorkList = workList;
mExpandableList = expandableList;
mContentView = contentView; mContentView = contentView;
mSwitch = withSwitch; mSwitch = withSwitch;
} }
@@ -279,31 +270,31 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment
.setContent(tab.mView); .setContent(tab.mView);
mTabHost.addTab(systemSpec); mTabHost.addTab(systemSpec);
final int profilesSize = mUserManager.getUserProfiles().size();
final GroupAdapter groupAdapter = new GroupAdapter(tab); final GroupAdapter groupAdapter = new GroupAdapter(tab);
mGroupAdapters.add(groupAdapter); mGroupAdapters.add(groupAdapter);
final int profilesSize = groupAdapter.getGroupCount();
if (profilesSize == 1) { // Add a transition for non-visibility events like resizing the pane.
final ChildAdapter adapter = groupAdapter.getChildAdapter(0); final ViewGroup contentView = (ViewGroup) mTabHost.findViewById(tab.mContentView);
adapter.setContainerViewId(tab.mPersonalList); contentView.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
adapter.prepare();
} else if (profilesSize == 2) {
final int workIndex = groupAdapter.getUserInfoByGroup(1).isManagedProfile() ? 1 : 0;
final int personalIndex = workIndex == 1 ? 0 : 1;
final ChildAdapter personalAdapter = groupAdapter.getChildAdapter(personalIndex); final LayoutInflater inflater = LayoutInflater.from(getActivity());
personalAdapter.setContainerViewId(tab.mPersonalList); for (int i = 0; i < groupAdapter.getGroupCount(); i++) {
personalAdapter.showHeader(true); final boolean isWork = groupAdapter.getUserInfoByGroup(i).isManagedProfile();
personalAdapter.prepare(); final ChildAdapter adapter = groupAdapter.getChildAdapter(i);
final ChildAdapter workAdapter = groupAdapter.getChildAdapter(workIndex); final LinearLayout containerView = (LinearLayout) inflater
workAdapter.setContainerViewId(tab.mWorkList); .inflate(R.layout.trusted_credential_list_container, contentView, false);
workAdapter.showHeader(true); adapter.setContainerView(containerView);
workAdapter.showDivider(true);
workAdapter.prepare(); adapter.showHeader(profilesSize > 1);
} else if (profilesSize >= 3) { adapter.showDivider(isWork);
groupAdapter.setExpandableListView( adapter.setExpandIfAvailable(profilesSize <= 2 ? true : !isWork);
(ExpandableListView) mTabHost.findViewById(tab.mExpandableList)); if (isWork) {
contentView.addView(containerView);
} else {
contentView.addView(containerView, 0);
}
} }
} }
@@ -504,10 +495,12 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment
AdapterView.OnItemClickListener { AdapterView.OnItemClickListener {
private final int[] GROUP_EXPANDED_STATE_SET = {com.android.internal.R.attr.state_expanded}; private final int[] GROUP_EXPANDED_STATE_SET = {com.android.internal.R.attr.state_expanded};
private final int[] EMPTY_STATE_SET = {}; private final int[] EMPTY_STATE_SET = {};
private final LinearLayout.LayoutParams HIDE_LAYOUT_PARAMS = new LinearLayout.LayoutParams( private final LinearLayout.LayoutParams HIDE_CONTAINER_LAYOUT_PARAMS =
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT, 0f);
private final LinearLayout.LayoutParams HIDE_LIST_LAYOUT_PARAMS =
new LinearLayout.LayoutParams(MATCH_PARENT, 0);
private final LinearLayout.LayoutParams SHOW_LAYOUT_PARAMS = new LinearLayout.LayoutParams( private final LinearLayout.LayoutParams SHOW_LAYOUT_PARAMS = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1f); LinearLayout.LayoutParams.MATCH_PARENT, MATCH_PARENT, 1f);
private final GroupAdapter mParent; private final GroupAdapter mParent;
private final int mGroupPosition; private final int mGroupPosition;
/* /*
@@ -577,9 +570,8 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment
showCertDialog(getItem(pos)); showCertDialog(getItem(pos));
} }
public void setContainerViewId(int viewId) { public void setContainerView(LinearLayout containerView) {
mContainerView = (LinearLayout) mTabHost.findViewById(viewId); mContainerView = containerView;
mContainerView.setVisibility(View.VISIBLE);
mListView = (ListView) mContainerView.findViewById(R.id.cert_list); mListView = (ListView) mContainerView.findViewById(R.id.cert_list);
mListView.setAdapter(this); mListView.setAdapter(this);
@@ -607,9 +599,9 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment
dividerView.setVisibility(showDivider ? View.VISIBLE : View.GONE ); dividerView.setVisibility(showDivider ? View.VISIBLE : View.GONE );
} }
public void prepare() { public void setExpandIfAvailable(boolean expanded) {
mIsListExpanded = mParent.checkGroupExpandableAndStartWarningActivity(mGroupPosition, mIsListExpanded = expanded && mParent.checkGroupExpandableAndStartWarningActivity(
false /* startActivity */); mGroupPosition, false /* startActivity */);
refreshViews(); refreshViews();
} }
@@ -620,9 +612,10 @@ public class TrustedCredentialsSettings extends OptionsMenuFragment
private void refreshViews() { private void refreshViews() {
mIndicatorView.setImageState(mIsListExpanded ? GROUP_EXPANDED_STATE_SET mIndicatorView.setImageState(mIsListExpanded ? GROUP_EXPANDED_STATE_SET
: EMPTY_STATE_SET, false); : EMPTY_STATE_SET, false);
mListView.setVisibility(mIsListExpanded ? View.VISIBLE : View.GONE); mListView.setLayoutParams(mIsListExpanded ? SHOW_LAYOUT_PARAMS
: HIDE_LIST_LAYOUT_PARAMS);
mContainerView.setLayoutParams(mIsListExpanded ? SHOW_LAYOUT_PARAMS mContainerView.setLayoutParams(mIsListExpanded ? SHOW_LAYOUT_PARAMS
: HIDE_LAYOUT_PARAMS); : HIDE_CONTAINER_LAYOUT_PARAMS);
} }
// Get group indicator from styles of ExpandableListView // Get group indicator from styles of ExpandableListView