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

Commit 3a2ef6db authored by Wu Ahan's avatar Wu Ahan Committed by Android (Google) Code Review
Browse files

Merge "Use GlifLayout#setDescriptionText in SetupChooseLockGenericFragment" into tm-qpr-dev

parents 1d68fbf0 ae84ac35
Loading
Loading
Loading
Loading
+0 −26
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2016 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.
-->

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/SudDescription.Glif"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:paddingTop="@dimen/sud_description_glif_margin_top"
    android:paddingBottom="@dimen/sud_description_glif_margin_bottom_lists"
    android:text="@string/lock_settings_picker_biometrics_added_security_message" />
+0 −26
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2016 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.
-->

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/SudDescription.Glif"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:paddingTop="@dimen/sud_description_glif_margin_top"
    android:paddingBottom="@dimen/sud_description_glif_margin_bottom_lists"
    android:text="@string/setup_lock_settings_picker_message" />
+10 −5
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
            super.onViewCreated(view, savedInstanceState);

            GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
            layout.setDescriptionText(loadDescriptionText());
            layout.setDividerItemDecoration(new SettingsDividerItemDecoration(getContext()));
            layout.setDividerInset(getContext().getResources().getDimensionPixelSize(
                    R.dimen.sud_items_glif_text_divider_inset));
@@ -129,11 +130,9 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {

        @Override
        protected void addHeaderView() {
            if (isForBiometric()) {
                setHeaderView(R.layout.setup_choose_lock_generic_biometrics_header);
            } else {
                setHeaderView(R.layout.setup_choose_lock_generic_header);
            }
            // The original logic has been moved to onViewCreated and
            // uses GlifLayout#setDescriptionText instead,
            // keep empty body here since we won't call super method.
        }

        @Override
@@ -239,6 +238,12 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
        private boolean isForBiometric() {
            return mForFingerprint || mForFace || mForBiometrics;
        }

        String loadDescriptionText() {
            return getString(isForBiometric()
                    ? R.string.lock_settings_picker_biometrics_added_security_message
                    : R.string.setup_lock_settings_picker_message);
        }
    }

    public static class InternalActivity extends ChooseLockGeneric.InternalActivity {
+48 −2
Original line number Diff line number Diff line
@@ -23,15 +23,20 @@ import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_R

import static com.google.common.truth.Truth.assertThat;

import static org.robolectric.Shadows.shadowOf;

import android.content.Intent;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.android.settings.password.SetupChooseLockGeneric.SetupChooseLockGenericFragment;
import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
import com.android.settings.testutils.shadow.ShadowPasswordUtils;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.testutils.shadow.ShadowUtils;

import com.google.android.setupdesign.GlifPreferenceLayout;

import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,6 +46,8 @@ import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;

import java.util.List;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
        ShadowUserManager.class,
@@ -78,4 +85,43 @@ public class SetupChooseLockGenericTest {
        ShadowActivity shadowActivity = Shadows.shadowOf(activity);
        assertThat(shadowActivity.isFinishing()).isFalse();
    }

    @Test
    public void setupChooseLockGenericUsingDescriptionTextOfGlifLayout() {
        SetupChooseLockGenericFragment fragment = getFragmentOfSetupChooseLockGeneric(false);
        GlifPreferenceLayout view = getViewOfSetupChooseLockGenericFragment(fragment);
        assertThat(TextUtils.isEmpty(view.getDescriptionText())).isFalse();
        assertThat(view.getDescriptionText().toString()).isEqualTo(fragment.loadDescriptionText());
    }

    @Test
    public void setupChooseLockGenericUsingDescriptionTextOfGlifLayoutForBiometric() {
        SetupChooseLockGenericFragment fragment = getFragmentOfSetupChooseLockGeneric(true);
        GlifPreferenceLayout view = getViewOfSetupChooseLockGenericFragment(fragment);
        assertThat(TextUtils.isEmpty(view.getDescriptionText())).isFalse();
        assertThat(view.getDescriptionText().toString()).isEqualTo(fragment.loadDescriptionText());
    }

    private SetupChooseLockGenericFragment getFragmentOfSetupChooseLockGeneric(boolean biometric) {
        ShadowPasswordUtils.addGrantedPermission(REQUEST_PASSWORD_COMPLEXITY);
        Intent intent = new Intent("com.android.settings.SETUP_LOCK_SCREEN");
        intent.putExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, PASSWORD_COMPLEXITY_HIGH);
        intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, biometric);
        SetupChooseLockGeneric activity =
                Robolectric.buildActivity(SetupChooseLockGeneric.class, intent).setup().get();

        List<Fragment> fragments = activity.getSupportFragmentManager().getFragments();
        assertThat(fragments).isNotNull();
        assertThat(fragments.size()).isEqualTo(1);
        assertThat(fragments.get(0)).isInstanceOf(SetupChooseLockGenericFragment.class);

        return (SetupChooseLockGenericFragment) fragments.get(0);
    }
    private GlifPreferenceLayout getViewOfSetupChooseLockGenericFragment(
            @NonNull SetupChooseLockGenericFragment fragment) {
        assertThat(fragment.getView()).isNotNull();
        assertThat(fragment.getView()).isInstanceOf(GlifPreferenceLayout.class);

        return (GlifPreferenceLayout) fragment.getView();
    }
}