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 */ 16 17 package com.android.settings.accounts; 18 19 import static android.content.Intent.EXTRA_USER; 20 21 import android.accounts.Account; 22 import android.content.Context; 23 import android.os.Bundle; 24 import android.os.UserHandle; 25 import android.support.v7.preference.Preference; 26 27 import com.android.internal.logging.nano.MetricsProto; 28 import com.android.settings.R; 29 import com.android.settings.Utils; 30 import com.android.settings.core.PreferenceController; 31 32 public class AccountSyncPreferenceController extends PreferenceController { 33 34 private static final String TAG = "AccountSyncController"; 35 private static final String KEY_ACCOUNT_SYNC = "account_sync"; 36 37 private Account mAccount; 38 private UserHandle mUserHandle; 39 40 public AccountSyncPreferenceController(Context context) { 41 super(context); 42 } 43 44 @Override 45 public boolean isAvailable() { 46 return true; 47 } 48 49 @Override 50 public boolean handlePreferenceTreeClick(Preference preference) { 51 if (!KEY_ACCOUNT_SYNC.equals(preference.getKey())) { 52 return false; 53 } 54 final Bundle args = new Bundle(); 55 args.putParcelable(AccountSyncSettings.ACCOUNT_KEY, mAccount); 56 args.putParcelable(EXTRA_USER, mUserHandle); 57 Utils.startWithFragment(mContext, AccountSyncSettings.class.getName(), args, null, 0, 58 R.string.account_sync_title, null, MetricsProto.MetricsEvent.ACCOUNT); 59 60 return true; 61 } 62 63 @Override 64 public String getPreferenceKey() { 65 return KEY_ACCOUNT_SYNC; 66 } 67 68 public void init(Account account, UserHandle userHandle) { 69 mAccount = account; 70 mUserHandle = userHandle; 71 } 72 } 73