OSDN Git Service

Zen Condition text and primary click changes
[android-x86/packages-apps-Settings.git] / src / com / android / settings / accounts / AccountDashboardFragment.java
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.android.settings.accounts;
17
18 import static android.provider.Settings.EXTRA_AUTHORITIES;
19
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;
25
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;
33
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
37
38 public class AccountDashboardFragment extends DashboardFragment {
39
40     private static final String TAG = "AccountDashboardFrag";
41
42
43     @Override
44     public int getMetricsCategory() {
45         return MetricsEvent.ACCOUNT;
46     }
47
48     @Override
49     protected String getLogTag() {
50         return TAG;
51     }
52
53     @Override
54     protected int getPreferenceScreenResId() {
55         return R.xml.accounts_dashboard_settings;
56     }
57
58     @Override
59     public int getHelpResource() {
60         return R.string.help_url_user_and_account_dashboard;
61     }
62
63     @Override
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);
71         return controllers;
72     }
73
74     private static class SummaryProvider implements SummaryLoader.SummaryProvider {
75
76         private final Context mContext;
77         private final SummaryLoader mSummaryLoader;
78
79         public SummaryProvider(Context context, SummaryLoader summaryLoader) {
80             mContext = context;
81             mSummaryLoader = summaryLoader;
82         }
83
84         @Override
85         public void setListening(boolean listening) {
86             if (listening) {
87                 final AuthenticatorHelper authHelper = new AuthenticatorHelper(mContext,
88                         UserHandle.of(UserHandle.myUserId()), null /* OnAccountsUpdateListener */);
89                 final String[] types = authHelper.getEnabledAccountTypes();
90
91                 final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
92
93                 CharSequence summary = null;
94
95                 // Show up to 3 account types
96                 final int size = Math.min(3, types.length);
97
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);
102                     } else {
103                         summary = mContext.getString(R.string.join_many_items_middle, summary,
104                                 bidiFormatter.unicodeWrap(label));
105                     }
106                 }
107                 mSummaryLoader.setSummary(this, summary);
108             }
109         }
110     }
111
112     public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
113             = new SummaryLoader.SummaryProviderFactory() {
114         @Override
115         public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
116                 SummaryLoader summaryLoader) {
117             return new SummaryProvider(activity, summaryLoader);
118         }
119     };
120
121     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
122             new BaseSearchIndexProvider() {
123                 @Override
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);
129                 }
130             };
131 }