AccountDashboardFragment.java revision 1d583e125faf3ae4c9cd82636d8f3ecf1cdec3aa
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 */ 16package com.android.settings.accounts; 17 18import static android.provider.Settings.EXTRA_AUTHORITIES; 19 20import android.app.Activity; 21import android.content.Context; 22import android.content.pm.UserInfo; 23import android.os.Bundle; 24import android.os.UserHandle; 25import android.os.UserManager; 26import android.provider.SearchIndexableResource; 27 28import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 29import com.android.settings.R; 30import com.android.settings.dashboard.DashboardFragment; 31import com.android.settings.dashboard.SummaryLoader; 32import com.android.settings.search.BaseSearchIndexProvider; 33import com.android.settingslib.core.AbstractPreferenceController; 34import com.android.settingslib.drawer.Tile; 35 36import java.util.ArrayList; 37import java.util.Arrays; 38import java.util.List; 39 40public class UserAndAccountDashboardFragment extends DashboardFragment { 41 42 private static final String TAG = "UserAndAccountDashboard"; 43 private static final String METADATA_IA_ACCOUNT = "com.android.settings.ia.account"; 44 45 @Override 46 public int getMetricsCategory() { 47 return MetricsEvent.ACCOUNT; 48 } 49 50 @Override 51 protected String getLogTag() { 52 return TAG; 53 } 54 55 @Override 56 protected int getPreferenceScreenResId() { 57 return R.xml.user_and_accounts_settings; 58 } 59 60 @Override 61 protected int getHelpResource() { 62 return R.string.help_url_user_and_account_dashboard; 63 } 64 65 @Override 66 protected List<AbstractPreferenceController> getPreferenceControllers(Context context) { 67 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 68 controllers.add(new EmergencyInfoPreferenceController(context)); 69 AddUserWhenLockedPreferenceController addUserWhenLockedPrefController = 70 new AddUserWhenLockedPreferenceController(context); 71 controllers.add(addUserWhenLockedPrefController); 72 getLifecycle().addObserver(addUserWhenLockedPrefController); 73 controllers.add(new AutoSyncDataPreferenceController(context, this)); 74 controllers.add(new AutoSyncPersonalDataPreferenceController(context, this)); 75 controllers.add(new AutoSyncWorkDataPreferenceController(context, this)); 76 String[] authorities = getIntent().getStringArrayExtra(EXTRA_AUTHORITIES); 77 final AccountPreferenceController accountPrefController = 78 new AccountPreferenceController(context, this, authorities); 79 getLifecycle().addObserver(accountPrefController); 80 controllers.add(accountPrefController); 81 return controllers; 82 } 83 84 private static class SummaryProvider implements SummaryLoader.SummaryProvider { 85 86 private final Context mContext; 87 private final SummaryLoader mSummaryLoader; 88 89 public SummaryProvider(Context context, SummaryLoader summaryLoader) { 90 mContext = context; 91 mSummaryLoader = summaryLoader; 92 } 93 94 @Override 95 public void setListening(boolean listening) { 96 if (listening) { 97 UserInfo info = mContext.getSystemService(UserManager.class).getUserInfo( 98 UserHandle.myUserId()); 99 mSummaryLoader.setSummary(this, 100 mContext.getString(R.string.users_and_accounts_summary, info.name)); 101 } 102 } 103 } 104 105 public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY 106 = new SummaryLoader.SummaryProviderFactory() { 107 @Override 108 public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity, 109 SummaryLoader summaryLoader) { 110 return new SummaryProvider(activity, summaryLoader); 111 } 112 }; 113 114 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 115 new BaseSearchIndexProvider() { 116 @Override 117 public List<SearchIndexableResource> getXmlResourcesToIndex( 118 Context context, boolean enabled) { 119 final SearchIndexableResource sir = new SearchIndexableResource(context); 120 sir.xmlResId = R.xml.user_and_accounts_settings; 121 return Arrays.asList(sir); 122 } 123 }; 124}