1 /* 2 * Copyright (C) 2015 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 package com.android.settings.nfc; 17 18 import android.content.Context; 19 import android.support.v7.preference.DropDownPreference; 20 21 import com.android.settings.R; 22 23 public class NfcForegroundPreference extends DropDownPreference implements 24 PaymentBackend.Callback { 25 26 private final PaymentBackend mPaymentBackend; 27 public NfcForegroundPreference(Context context, PaymentBackend backend) { 28 super(context); 29 mPaymentBackend = backend; 30 mPaymentBackend.registerCallback(this); 31 refresh(); 32 } 33 34 @Override 35 public void onPaymentAppsChanged() { 36 refresh(); 37 } 38 39 void refresh() { 40 PaymentBackend.PaymentAppInfo defaultApp = mPaymentBackend.getDefaultApp(); 41 boolean foregroundMode = mPaymentBackend.isForegroundMode(); 42 setPersistent(false); 43 setTitle(getContext().getString(R.string.nfc_payment_use_default)); 44 CharSequence favorOpen; 45 CharSequence favorDefault; 46 setEntries(new CharSequence[] { 47 getContext().getString(R.string.nfc_payment_favor_open), 48 getContext().getString(R.string.nfc_payment_favor_default) 49 }); 50 setEntryValues(new CharSequence[] { "1", "0" }); 51 if (foregroundMode) { 52 setValue("1"); 53 } else { 54 setValue("0"); 55 } 56 } 57 58 @Override 59 protected boolean persistString(String value) { 60 mPaymentBackend.setForegroundMode(Integer.parseInt(value) != 0); 61 return true; 62 } 63 } 64