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.view.Menu; 28 import android.view.MenuInflater; 29 import android.view.MenuItem; 30 import android.view.View; 31 import android.view.ViewGroup; 32 33 import androidx.annotation.VisibleForTesting; 34 import androidx.preference.Preference; 35 import androidx.preference.PreferenceScreen; 36 37 import com.android.settings.R; 38 import com.android.settings.dashboard.DashboardFragment; 39 import com.android.settings.search.BaseSearchIndexProvider; 40 import com.android.settingslib.search.SearchIndexable; 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 if (isShowEmptyImage(getPreferenceScreen())) { 78 View emptyView = getActivity().getLayoutInflater().inflate( 79 R.layout.nfc_payment_empty, null, false); 80 ((ViewGroup) view.findViewById(android.R.id.list_container)).addView(emptyView); 81 } 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 @VisibleForTesting isShowEmptyImage(PreferenceScreen screen)106 boolean isShowEmptyImage(PreferenceScreen screen) { 107 for (int i = 0; i < screen.getPreferenceCount(); i++) { 108 final Preference preference = screen.getPreference(i); 109 if(preference.isVisible()) { 110 return false; 111 } 112 } 113 return true; 114 } 115 116 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 117 new BaseSearchIndexProvider(R.xml.nfc_payment_settings) { 118 119 @Override 120 protected boolean isPageSearchEnabled(Context context) { 121 final UserManager userManager = context.getSystemService(UserManager.class); 122 final UserInfo myUserInfo = userManager.getUserInfo(UserHandle.myUserId()); 123 if (myUserInfo.isGuest()) { 124 return false; 125 } 126 final PackageManager pm = context.getPackageManager(); 127 return pm.hasSystemFeature(PackageManager.FEATURE_NFC); 128 } 129 }; 130 }