blob: a8d93d589d8754fabb9cf109995b668411cbfe26 [file] [log] [blame]
Fan Zhangf6747a22018-08-09 09:51:35 -07001/*
2 * Copyright (C) 2018 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
17package com.android.settings.accounts;
18
19import android.content.Context;
20import android.icu.text.ListFormatter;
21import android.os.UserHandle;
22import android.text.BidiFormatter;
23import android.text.TextUtils;
24
25import com.android.settings.R;
26import com.android.settings.core.BasePreferenceController;
27import com.android.settingslib.accounts.AuthenticatorHelper;
28
29import java.util.ArrayList;
30import java.util.List;
31
32public class TopLevelAccountEntryPreferenceController extends BasePreferenceController {
33 public TopLevelAccountEntryPreferenceController(Context context, String preferenceKey) {
34 super(context, preferenceKey);
35 }
36
37 @Override
38 public int getAvailabilityStatus() {
39 return AVAILABLE_UNSEARCHABLE;
40 }
41
42 @Override
43 public CharSequence getSummary() {
44 final AuthenticatorHelper authHelper = new AuthenticatorHelper(mContext,
45 UserHandle.of(UserHandle.myUserId()), null /* OnAccountsUpdateListener */);
46 final String[] types = authHelper.getEnabledAccountTypes();
47 final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
48 final List<CharSequence> summaries = new ArrayList<>();
49
50 if (types == null || types.length == 0) {
51 summaries.add(mContext.getString(R.string.account_dashboard_default_summary));
52 } else {
53 // Show up to 3 account types, ignore any null value
54 int accountToAdd = Math.min(3, types.length);
55
56 for (int i = 0; i < types.length && accountToAdd > 0; i++) {
57 final CharSequence label = authHelper.getLabelForType(mContext, types[i]);
58 if (TextUtils.isEmpty(label)) {
59 continue;
60 }
61
62 summaries.add(bidiFormatter.unicodeWrap(label));
63 accountToAdd--;
64 }
65 }
66 return ListFormatter.getInstance().format(summaries);
67 }
68}