1 /*
2  * Copyright (C) 2014 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.tv.settings.accounts;
18 
19 import android.accounts.Account;
20 import android.accounts.AccountManager;
21 import android.app.Fragment;
22 import android.os.Bundle;
23 import android.text.TextUtils;
24 
25 import com.android.tv.settings.TvSettingsActivity;
26 import com.android.tv.settings.overlay.FeatureFactory;
27 
28 /**
29  * Displays the sync settings for a given account.
30  */
31 public class AccountSyncActivity extends TvSettingsActivity {
32 
33     private static final String ARG_ACCOUNT = "account";
34     public static final String EXTRA_ACCOUNT = "account_name";
35 
36     @Override
createSettingsFragment()37     protected Fragment createSettingsFragment() {
38         String accountName = getIntent().getStringExtra(EXTRA_ACCOUNT);
39         Account account = null;
40         if (!TextUtils.isEmpty(accountName)) {
41             // Search for the account.
42             for (Account candidateAccount : AccountManager.get(this).getAccounts()) {
43                 if (candidateAccount.name.equals(accountName)) {
44                     account = candidateAccount;
45                     break;
46                 }
47             }
48         }
49         return FeatureFactory.getFactory(this).getSettingsFragmentProvider()
50             .newSettingsFragment(AccountSyncFragment.class.getName(), getArguments(account));
51     }
52 
getArguments(Account account)53     private Bundle getArguments(Account account) {
54         final Bundle b = new Bundle(1);
55         b.putParcelable(ARG_ACCOUNT, account);
56         return b;
57     }
58 }
59