1 /*
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 
17 package com.android.car.settings.accounts;
18 
19 import android.accounts.Account;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.os.UserHandle;
23 
24 import androidx.annotation.XmlRes;
25 
26 import com.android.car.settings.R;
27 import com.android.car.settings.common.SettingsFragment;
28 
29 /**
30  * Shows details for syncing an account.
31  */
32 public class AccountSyncDetailsFragment extends SettingsFragment {
33     private static final String EXTRA_ACCOUNT = "extra_account";
34     private static final String EXTRA_USER_HANDLE = "extra_user_handle";
35 
36     /**
37      * Creates a new AccountSyncDetailsFragment.
38      *
39      * <p>Passes the provided account and user handle to the fragment via fragment arguments.
40      */
newInstance(Account account, UserHandle userHandle)41     public static AccountSyncDetailsFragment newInstance(Account account, UserHandle userHandle) {
42         AccountSyncDetailsFragment accountSyncDetailsFragment = new AccountSyncDetailsFragment();
43         Bundle bundle = new Bundle();
44         bundle.putParcelable(EXTRA_ACCOUNT, account);
45         bundle.putParcelable(EXTRA_USER_HANDLE, userHandle);
46         accountSyncDetailsFragment.setArguments(bundle);
47         return accountSyncDetailsFragment;
48     }
49 
50     @Override
51     @XmlRes
getPreferenceScreenResId()52     protected int getPreferenceScreenResId() {
53         return R.xml.account_sync_details_fragment;
54     }
55 
56     @Override
onAttach(Context context)57     public void onAttach(Context context) {
58         super.onAttach(context);
59 
60         Account account = getArguments().getParcelable(EXTRA_ACCOUNT);
61         UserHandle userHandle = getArguments().getParcelable(EXTRA_USER_HANDLE);
62 
63         use(AccountDetailsWithSyncStatusPreferenceController.class,
64                 R.string.pk_account_details_with_sync)
65                 .setAccount(account);
66         use(AccountDetailsWithSyncStatusPreferenceController.class,
67                 R.string.pk_account_details_with_sync)
68                 .setUserHandle(userHandle);
69 
70         use(AccountSyncDetailsPreferenceController.class, R.string.pk_account_sync_details)
71                 .setAccount(account);
72         use(AccountSyncDetailsPreferenceController.class, R.string.pk_account_sync_details)
73                 .setUserHandle(userHandle);
74     }
75 }
76