2 * Copyright (C) 2016 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.android.settings.accounts;
18 import static android.provider.Settings.EXTRA_AUTHORITIES;
20 import android.app.Activity;
21 import android.content.Context;
22 import android.os.UserHandle;
23 import android.provider.SearchIndexableResource;
24 import android.text.BidiFormatter;
26 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
27 import com.android.settings.R;
28 import com.android.settings.dashboard.DashboardFragment;
29 import com.android.settings.dashboard.SummaryLoader;
30 import com.android.settings.search.BaseSearchIndexProvider;
31 import com.android.settingslib.accounts.AuthenticatorHelper;
32 import com.android.settingslib.core.AbstractPreferenceController;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
38 public class AccountDashboardFragment extends DashboardFragment {
40 private static final String TAG = "AccountDashboardFrag";
44 public int getMetricsCategory() {
45 return MetricsEvent.ACCOUNT;
49 protected String getLogTag() {
54 protected int getPreferenceScreenResId() {
55 return R.xml.accounts_dashboard_settings;
59 public int getHelpResource() {
60 return R.string.help_url_user_and_account_dashboard;
64 protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
65 final List<AbstractPreferenceController> controllers = new ArrayList<>();
66 final String[] authorities = getIntent().getStringArrayExtra(EXTRA_AUTHORITIES);
67 final AccountPreferenceController accountPrefController =
68 new AccountPreferenceController(context, this, authorities);
69 getLifecycle().addObserver(accountPrefController);
70 controllers.add(accountPrefController);
74 private static class SummaryProvider implements SummaryLoader.SummaryProvider {
76 private final Context mContext;
77 private final SummaryLoader mSummaryLoader;
79 public SummaryProvider(Context context, SummaryLoader summaryLoader) {
81 mSummaryLoader = summaryLoader;
85 public void setListening(boolean listening) {
87 final AuthenticatorHelper authHelper = new AuthenticatorHelper(mContext,
88 UserHandle.of(UserHandle.myUserId()), null /* OnAccountsUpdateListener */);
89 final String[] types = authHelper.getEnabledAccountTypes();
91 final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
93 CharSequence summary = null;
95 // Show up to 3 account types
96 final int size = Math.min(3, types.length);
98 for (int i = 0; i < size; i++) {
99 final CharSequence label = authHelper.getLabelForType(mContext, types[i]);
100 if (summary == null) {
101 summary = bidiFormatter.unicodeWrap(label);
103 summary = mContext.getString(R.string.join_many_items_middle, summary,
104 bidiFormatter.unicodeWrap(label));
107 mSummaryLoader.setSummary(this, summary);
112 public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
113 = new SummaryLoader.SummaryProviderFactory() {
115 public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
116 SummaryLoader summaryLoader) {
117 return new SummaryProvider(activity, summaryLoader);
121 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
122 new BaseSearchIndexProvider() {
124 public List<SearchIndexableResource> getXmlResourcesToIndex(
125 Context context, boolean enabled) {
126 final SearchIndexableResource sir = new SearchIndexableResource(context);
127 sir.xmlResId = R.xml.accounts_dashboard_settings;
128 return Arrays.asList(sir);