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.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.pm.PackageManager; 23 import android.content.pm.UserInfo; 24 import android.os.Bundle; 25 import android.os.UserHandle; 26 import android.os.UserManager; 27 import android.provider.SearchIndexableResource; 28 import android.view.Menu; 29 import android.view.MenuInflater; 30 import android.view.MenuItem; 31 import android.view.View; 32 import android.view.ViewGroup; 33 34 import com.android.settings.R; 35 import com.android.settings.dashboard.DashboardFragment; 36 import com.android.settings.search.BaseSearchIndexProvider; 37 import com.android.settingslib.search.SearchIndexable; 38 39 import java.util.Arrays; 40 import java.util.List; 41 42 43 @SearchIndexable 44 public class PaymentSettings extends DashboardFragment { 45 public static final String TAG = "PaymentSettings"; 46 47 private PaymentBackend mPaymentBackend; 48 49 @Override getLogTag()50 protected String getLogTag() { 51 return TAG; 52 } 53 54 @Override getMetricsCategory()55 public int getMetricsCategory() { 56 return SettingsEnums.NFC_PAYMENT; 57 } 58 59 @Override getPreferenceScreenResId()60 protected int getPreferenceScreenResId() { 61 return R.xml.nfc_payment_settings; 62 } 63 64 @Override onAttach(Context context)65 public void onAttach(Context context) { 66 super.onAttach(context); 67 mPaymentBackend = new PaymentBackend(getActivity()); 68 setHasOptionsMenu(true); 69 70 use(NfcPaymentPreferenceController.class).setPaymentBackend(mPaymentBackend); 71 use(NfcForegroundPreferenceController.class).setPaymentBackend(mPaymentBackend); 72 } 73 74 @Override onViewCreated(View view, Bundle savedInstanceState)75 public void onViewCreated(View view, Bundle savedInstanceState) { 76 super.onViewCreated(view, savedInstanceState); 77 ViewGroup contentRoot = (ViewGroup) getListView().getParent(); 78 View emptyView = getActivity().getLayoutInflater().inflate( 79 R.layout.nfc_payment_empty, contentRoot, false); 80 contentRoot.addView(emptyView); 81 setEmptyView(emptyView); 82 } 83 84 @Override onResume()85 public void onResume() { 86 super.onResume(); 87 mPaymentBackend.onResume(); 88 } 89 90 @Override onPause()91 public void onPause() { 92 super.onPause(); 93 mPaymentBackend.onPause(); 94 } 95 96 @Override onCreateOptionsMenu(Menu menu, MenuInflater inflater)97 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 98 super.onCreateOptionsMenu(menu, inflater); 99 MenuItem menuItem = menu.add(R.string.nfc_payment_how_it_works); 100 Intent howItWorksIntent = new Intent(getActivity(), HowItWorks.class); 101 menuItem.setIntent(howItWorksIntent); 102 menuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_NEVER); 103 } 104 105 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 106 new BaseSearchIndexProvider() { 107 @Override 108 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, 109 boolean enabled) { 110 final SearchIndexableResource sir = new SearchIndexableResource(context); 111 sir.xmlResId = R.xml.nfc_payment_settings; 112 return Arrays.asList(sir); 113 } 114 115 @Override 116 protected boolean isPageSearchEnabled(Context context) { 117 final UserManager userManager = context.getSystemService(UserManager.class); 118 final UserInfo myUserInfo = userManager.getUserInfo(UserHandle.myUserId()); 119 if (myUserInfo.isGuest()) { 120 return false; 121 } 122 final PackageManager pm = context.getPackageManager(); 123 return pm.hasSystemFeature(PackageManager.FEATURE_NFC); 124 } 125 }; 126 }