1 /* 2 * Copyright (C) 2013 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.nfc; 18 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.preference.PreferenceManager; 22 import android.preference.PreferenceScreen; 23 import android.view.Menu; 24 import android.view.MenuInflater; 25 import android.view.MenuItem; 26 import android.view.View; 27 import android.view.ViewGroup; 28 import com.android.internal.logging.MetricsLogger; 29 import com.android.settings.R; 30 import com.android.settings.SettingsPreferenceFragment; 31 import com.android.settings.nfc.PaymentBackend.PaymentAppInfo; 32 33 import java.util.List; 34 35 public class PaymentSettings extends SettingsPreferenceFragment { 36 public static final String TAG = "PaymentSettings"; 37 private PaymentBackend mPaymentBackend; 38 39 @Override getMetricsCategory()40 protected int getMetricsCategory() { 41 return MetricsLogger.NFC_PAYMENT; 42 } 43 44 @Override onCreate(Bundle icicle)45 public void onCreate(Bundle icicle) { 46 super.onCreate(icicle); 47 48 mPaymentBackend = new PaymentBackend(getActivity()); 49 setHasOptionsMenu(true); 50 } 51 52 @Override onViewCreated(View view, Bundle savedInstanceState)53 public void onViewCreated(View view, Bundle savedInstanceState) { 54 super.onViewCreated(view, savedInstanceState); 55 ViewGroup contentRoot = (ViewGroup) getListView().getParent(); 56 View emptyView = getActivity().getLayoutInflater().inflate( 57 R.layout.nfc_payment_empty, contentRoot, false); 58 contentRoot.addView(emptyView); 59 getListView().setEmptyView(emptyView); 60 61 PreferenceManager manager = getPreferenceManager(); 62 PreferenceScreen screen = manager.createPreferenceScreen(getActivity()); 63 64 List<PaymentAppInfo> appInfos = mPaymentBackend.getPaymentAppInfos(); 65 if (appInfos != null && appInfos.size() > 0) { 66 NfcPaymentPreference preference = 67 new NfcPaymentPreference(getActivity(), mPaymentBackend); 68 screen.addPreference(preference); 69 NfcForegroundPreference foreground = new NfcForegroundPreference(getActivity(), 70 mPaymentBackend); 71 screen.addPreference(foreground); 72 } 73 setPreferenceScreen(screen); 74 } 75 76 @Override onResume()77 public void onResume() { 78 super.onResume(); 79 mPaymentBackend.onResume(); 80 } 81 82 @Override onPause()83 public void onPause() { 84 super.onPause(); 85 mPaymentBackend.onPause(); 86 } 87 88 @Override onCreateOptionsMenu(Menu menu, MenuInflater inflater)89 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 90 super.onCreateOptionsMenu(menu, inflater); 91 MenuItem menuItem = menu.add(R.string.nfc_payment_how_it_works); 92 Intent howItWorksIntent = new Intent(getActivity(), HowItWorks.class); 93 menuItem.setIntent(howItWorksIntent); 94 menuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_NEVER); 95 } 96 } 97