Use entity header on AccountDetailDashboardFragment

Bug: 37669238
Test: make RunSettingsRoboTests
Change-Id: Iaf92730e8c6b5c44cb8eca4525fc931487ce9630
This commit is contained in:
Fan Zhang
2017-05-18 15:11:01 -07:00
parent d7414259d0
commit 98289a887b
8 changed files with 216 additions and 96 deletions

View File

@@ -22,9 +22,8 @@ import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.Utils;
@@ -45,7 +44,6 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
public static final String KEY_ACCOUNT_TYPE = "account_type";
public static final String KEY_ACCOUNT_LABEL = "account_label";
public static final String KEY_ACCOUNT_TITLE_RES = "account_title_res";
public static final String KEY_ACCOUNT_HEADER = "account_header";
public static final String KEY_USER_HANDLE = "user_handle";
@VisibleForTesting
@@ -110,6 +108,8 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
controllers.add(mAccountSynController);
mRemoveAccountController = new RemoveAccountPreferenceController(context, this);
controllers.add(mRemoveAccountController);
controllers.add(new AccountHeaderPreferenceController(
context, getActivity(), this, getArguments()));
return controllers;
}
@@ -127,8 +127,6 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
@VisibleForTesting
void updateUi() {
final Preference headerPreference = findPreference(KEY_ACCOUNT_HEADER);
headerPreference.setTitle(mAccount.name);
final Context context = getContext();
UserHandle userHandle = null;
Bundle args = getArguments();
@@ -136,14 +134,12 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
userHandle = args.getParcelable(KEY_USER_HANDLE);
}
final AuthenticatorHelper helper = new AuthenticatorHelper(context, userHandle, null);
headerPreference.setIcon(helper.getDrawableForType(context, mAccountType));
final AccountTypePreferenceLoader accountTypePreferenceLoader =
new AccountTypePreferenceLoader(this, helper, userHandle);
PreferenceScreen prefs =
accountTypePreferenceLoader.addPreferencesForType(mAccountType, getPreferenceScreen());
new AccountTypePreferenceLoader(this, helper, userHandle);
PreferenceScreen prefs = accountTypePreferenceLoader.addPreferencesForType(
mAccountType, getPreferenceScreen());
if (prefs != null) {
accountTypePreferenceLoader.updatePreferenceIntents(prefs, mAccountType, mAccount);
}
}
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright (C) 2017 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.settings.accounts;
import android.accounts.Account;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.os.UserHandle;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.PreferenceController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.accounts.AuthenticatorHelper;
import static com.android.settings.accounts.AccountDetailDashboardFragment.KEY_ACCOUNT;
import static com.android.settings.accounts.AccountDetailDashboardFragment.KEY_USER_HANDLE;
public class AccountHeaderPreferenceController extends PreferenceController {
private static final String KEY_ACCOUNT_HEADER = "account_header";
private final Activity mActivity;
private final Fragment mHost;
private final Account mAccount;
private final UserHandle mUserHandle;
public AccountHeaderPreferenceController(Context context, Activity activity, Fragment host,
Bundle args) {
super(context);
mActivity = activity;
mHost = host;
if (args != null && args.containsKey(KEY_ACCOUNT)) {
mAccount = args.getParcelable(KEY_ACCOUNT);
} else {
mAccount = null;
}
if (args != null && args.containsKey(KEY_USER_HANDLE)) {
mUserHandle = args.getParcelable(KEY_USER_HANDLE);
} else {
mUserHandle = null;
}
}
@Override
public boolean isAvailable() {
return mAccount != null && mUserHandle != null;
}
@Override
public String getPreferenceKey() {
return KEY_ACCOUNT_HEADER;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
final LayoutPreference headerPreference =
(LayoutPreference) screen.findPreference(KEY_ACCOUNT_HEADER);
final AuthenticatorHelper helper = new AuthenticatorHelper(mContext, mUserHandle, null);
EntityHeaderController
.newInstance(mActivity, mHost, headerPreference.findViewById(R.id.entity_header))
.setLabel(mAccount.name)
.setIcon(helper.getDrawableForType(mContext, mAccount.type))
.done(mActivity, true /* rebindButtons */);
}
}