Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab1277f6 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix the display abnormal of Tap & pay screen in landscape mode"

parents c3038940 3526f666
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2019 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.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_gravity="center"
              android:gravity="center"
              android:orientation="horizontal">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|right"
        android:src="@drawable/tapandpay_emptystate"/>
    <TextView
        android:layout_width="264dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingStart="36dp"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="?android:attr/textColorSecondary"
        android:text="@string/nfc_payment_no_apps"/>
</LinearLayout>
+20 −4
Original line number Diff line number Diff line
@@ -30,6 +30,10 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -70,11 +74,12 @@ public class PaymentSettings extends DashboardFragment {
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        if (isShowEmptyImage(getPreferenceScreen())) {
            View emptyView = getActivity().getLayoutInflater().inflate(
                    R.layout.nfc_payment_empty, null, false);
            ((ViewGroup) view.findViewById(android.R.id.list_container)).addView(emptyView);
        }
    }

    @Override
    public void onResume() {
@@ -97,6 +102,17 @@ public class PaymentSettings extends DashboardFragment {
        menuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    @VisibleForTesting
    boolean isShowEmptyImage(PreferenceScreen screen) {
        for (int i = 0; i < screen.getPreferenceCount(); i++) {
            final Preference preference = screen.getPreference(i);
            if(preference.isVisible()) {
                return false;
            }
        }
        return true;
    }

    public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider(R.xml.nfc_payment_settings) {

+32 −0
Original line number Diff line number Diff line
@@ -29,6 +29,10 @@ import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;

import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -113,6 +117,34 @@ public class PaymentSettingsTest {
        assertThat(niks).containsAllOf(FOREGROUND_KEY, PAYMENT_KEY, PAYMENT_SCREEN_KEY);
    }

    @Test
    public void isShowEmptyImage_hasVisiblePreference_returnFalse() {
        final PaymentSettings paymentSettings = new PaymentSettings();
        final PreferenceManager preferenceManager = new PreferenceManager(mContext);
        final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
        final Preference preference1 = new Preference(mContext);
        screen.addPreference(preference1);
        final Preference preference2 = new Preference(mContext);
        screen.addPreference(preference2);

        assertThat(paymentSettings.isShowEmptyImage(screen)).isFalse();
    }

    @Test
    public void isShowEmptyImage_hasNoVisiblePreference_returnTrue() {
        final PaymentSettings paymentSettings = new PaymentSettings();
        final PreferenceManager preferenceManager = new PreferenceManager(mContext);
        final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
        final Preference preference1 = new Preference(mContext);
        preference1.setVisible(false);
        screen.addPreference(preference1);
        final Preference preference2 = new Preference(mContext);
        screen.addPreference(preference2);
        preference2.setVisible(false);

        assertThat(paymentSettings.isShowEmptyImage(screen)).isTrue();
    }

    @Implements(PaymentBackend.class)
    public static class ShadowPaymentBackend {
        private ArrayList<PaymentBackend.PaymentAppInfo> mAppInfos;