1 /* 2 * Copyright (C) 2017 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 17 package com.android.car.settings.accounts; 18 19 import android.os.Bundle; 20 import android.os.UserHandle; 21 22 import androidx.car.widget.ListItemProvider; 23 24 import com.android.car.settings.R; 25 import com.android.car.settings.common.ListItemSettingsFragment; 26 import com.android.car.settings.common.Logger; 27 import com.android.settingslib.accounts.AuthenticatorHelper; 28 29 /** 30 * Activity asking a user to select an account to be set up. 31 * 32 * <p>An extra {@link UserHandle} can be specified in the intent as {@link EXTRA_USER}, 33 * if the user for which the action needs to be performed is different to the one the 34 * Settings App will run in. 35 */ 36 public class ChooseAccountFragment extends ListItemSettingsFragment 37 implements AuthenticatorHelper.OnAccountsUpdateListener { 38 private static final Logger LOG = new Logger(ChooseAccountFragment.class); 39 40 private ChooseAccountItemProvider mItemProvider; 41 newInstance()42 public static ChooseAccountFragment newInstance() { 43 ChooseAccountFragment 44 chooseAccountFragment = new ChooseAccountFragment(); 45 Bundle bundle = ListItemSettingsFragment.getBundle(); 46 bundle.putInt(EXTRA_TITLE_ID, R.string.add_an_account); 47 bundle.putInt(EXTRA_ACTION_BAR_LAYOUT, R.layout.action_bar_with_button); 48 chooseAccountFragment.setArguments(bundle); 49 return chooseAccountFragment; 50 } 51 52 @Override onActivityCreated(Bundle savedInstanceState)53 public void onActivityCreated(Bundle savedInstanceState) { 54 mItemProvider = new ChooseAccountItemProvider(getContext(), this); 55 super.onActivityCreated(savedInstanceState); 56 } 57 58 @Override onAccountsUpdate(UserHandle userHandle)59 public void onAccountsUpdate(UserHandle userHandle) { 60 LOG.v("Accounts changed, refreshing the account list."); 61 mItemProvider.refreshItems(); 62 refreshList(); 63 } 64 65 @Override getItemProvider()66 public ListItemProvider getItemProvider() { 67 return mItemProvider; 68 } 69 } 70