From 204fa8a42048a7e760827e0d9920ba61d2fb488b Mon Sep 17 00:00:00 2001 From: Toby Chuang Date: Tue, 24 Mar 2020 16:07:13 +0800 Subject: [PATCH] [NFC] Add a picture under NFC settings to show NFC detection point. Each smartphone has a different NFC antenna detection point, users would confuse where the NFC antenna is and how to place the smartphone close to the card reader/equipment. Starting from Android R device, we move NFC antenna position from top area to middle center of the phone. From the OEMs perspective, they could implement their own picture to indicate the best NFC detection point.Hence, we propose to show NFC antenna position under NFC setting. Bug: 142230563 Test: build pass Change-Id: Ib3cd7fc3ea299be1667aba0aeebaa148fb49015f --- res/drawable-nodpi/nfc_detection_point.png | Bin 0 -> 95 bytes res/layout/nfc_detection_point.xml | 29 ++++++++++ res/values/config.xml | 3 ++ res/values/dimens.xml | 2 + res/xml/nfc_and_payment_settings.xml | 8 ++- .../nfc/NfcDetectionPointController.java | 48 +++++++++++++++++ .../nfc/NfcDetectionPointControllerTest.java | 50 ++++++++++++++++++ 7 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 res/drawable-nodpi/nfc_detection_point.png create mode 100644 res/layout/nfc_detection_point.xml create mode 100644 src/com/android/settings/nfc/NfcDetectionPointController.java create mode 100644 tests/robotests/src/com/android/settings/nfc/NfcDetectionPointControllerTest.java diff --git a/res/drawable-nodpi/nfc_detection_point.png b/res/drawable-nodpi/nfc_detection_point.png new file mode 100644 index 0000000000000000000000000000000000000000..1914264c08781d1f30ee0b8482bccf44586f2dc1 GIT binary patch literal 95 zcmeAS@N?(olHy`uVBq!ia0vp^j3CU&3?x-=hn)ga%mF?ju0VQumF+E%TuG2$FoVOh l8)-lem#2$k2*>s01R$Gz9%CSj!PC{xWt~$(697H@6ZHT9 literal 0 HcmV?d00001 diff --git a/res/layout/nfc_detection_point.xml b/res/layout/nfc_detection_point.xml new file mode 100644 index 00000000000..8f938d1926e --- /dev/null +++ b/res/layout/nfc_detection_point.xml @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/res/values/config.xml b/res/values/config.xml index 64d9ab7081f..5bddc5eb291 100755 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -442,4 +442,7 @@ + + + false diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 79071ed3a05..c4b80a07350 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -67,6 +67,8 @@ 6 + 300dp + 64dp 20dp 4dp diff --git a/res/xml/nfc_and_payment_settings.xml b/res/xml/nfc_and_payment_settings.xml index f240388279a..8ff4983579b 100644 --- a/res/xml/nfc_and_payment_settings.xml +++ b/res/xml/nfc_and_payment_settings.xml @@ -19,6 +19,12 @@ xmlns:settings="http://schemas.android.com/apk/res-auto" android:title="@string/nfc_quick_toggle_title"> + + - \ No newline at end of file + diff --git a/src/com/android/settings/nfc/NfcDetectionPointController.java b/src/com/android/settings/nfc/NfcDetectionPointController.java new file mode 100644 index 00000000000..b2e8f6abdea --- /dev/null +++ b/src/com/android/settings/nfc/NfcDetectionPointController.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.nfc; + +import android.content.Context; + +import androidx.annotation.VisibleForTesting; + +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; +/** + * Controller that used to show nfc detection point guidance + */ +public class NfcDetectionPointController extends BasePreferenceController { + private boolean mEnabled; + + public NfcDetectionPointController(Context context, String preferenceKey) { + super(context, preferenceKey); + mEnabled = mContext.getResources().getBoolean(R.bool.config_nfc_detection_point); + } + + @Override + public int getAvailabilityStatus() { + if (!mEnabled) { + return UNSUPPORTED_ON_DEVICE; + } + return AVAILABLE; + } + + @VisibleForTesting + public void setConfig(boolean value) { + mEnabled = value; + } +} diff --git a/tests/robotests/src/com/android/settings/nfc/NfcDetectionPointControllerTest.java b/tests/robotests/src/com/android/settings/nfc/NfcDetectionPointControllerTest.java new file mode 100644 index 00000000000..31ac7d67e02 --- /dev/null +++ b/tests/robotests/src/com/android/settings/nfc/NfcDetectionPointControllerTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.nfc; + +import static com.google.common.truth.Truth.assertThat; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; + +@RunWith(RobolectricTestRunner.class) +public class NfcDetectionPointControllerTest { + + private NfcDetectionPointController mController; + + @Before + public void setUp() { + mController = new NfcDetectionPointController(RuntimeEnvironment.application, "fakeKey"); + } + + @Test + public void getAvailabilityStatus_withConfigIsTrue_returnAvailable() { + mController.setConfig(true); + assertThat(mController.getAvailabilityStatus()) + .isEqualTo(NfcDetectionPointController.AVAILABLE); + } + + @Test + public void getAvailabilityStatus_withConfigIsFalse_returnUnavailable() { + mController.setConfig(false); + assertThat(mController.getAvailabilityStatus()) + .isNotEqualTo(NfcDetectionPointController.AVAILABLE); + } +}