Merge "Avoid the reset item having inconsistent alignment with the others under SuW."
This commit is contained in:
@@ -57,9 +57,8 @@
|
||||
android:summary="@string/accessibility_toggle_high_text_contrast_preference_summary"
|
||||
android:title="@string/accessibility_toggle_high_text_contrast_preference_title" />
|
||||
|
||||
<com.android.settingslib.widget.LayoutPreference
|
||||
<com.android.settings.accessibility.TextReadingResetPreference
|
||||
android:key="reset"
|
||||
android:layout="@layout/accessibility_text_reading_reset_button"
|
||||
android:persistent="false"
|
||||
android:selectable="false" />
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -27,10 +27,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import com.google.android.setupdesign.GlifPreferenceLayout;
|
||||
import com.google.android.setupdesign.util.LayoutStyler;
|
||||
|
||||
|
||||
/**
|
||||
@@ -50,8 +48,6 @@ public class TextReadingPreferenceFragmentForSetupWizard extends TextReadingPref
|
||||
icon.setTintList(Utils.getColorAttr(getContext(), android.R.attr.colorPrimary));
|
||||
AccessibilitySetupWizardUtils.updateGlifPreferenceLayout(getContext(), layout, title,
|
||||
/* description= */ null, icon);
|
||||
|
||||
updateResetButtonPadding();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,14 +67,4 @@ public class TextReadingPreferenceFragmentForSetupWizard extends TextReadingPref
|
||||
// Hides help center in action bar and footer bar in SuW
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the padding of the reset button to meet for SetupWizard style.
|
||||
*/
|
||||
private void updateResetButtonPadding() {
|
||||
final LayoutPreference resetPreference = (LayoutPreference) findPreference(RESET_KEY);
|
||||
final ViewGroup parentView =
|
||||
(ViewGroup) resetPreference.findViewById(R.id.reset_button).getParent();
|
||||
LayoutStyler.applyPartnerCustomizationLayoutPaddingStyle(parentView);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,9 @@ import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.instrumentation.SettingsStatsLog;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
/**
|
||||
* The controller of the reset button in the text and reading options page.
|
||||
@@ -52,9 +50,9 @@ class TextReadingResetController extends BasePreferenceController {
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
final LayoutPreference layoutPreference = screen.findPreference(getPreferenceKey());
|
||||
final View view = layoutPreference.findViewById(R.id.reset_button);
|
||||
view.setOnClickListener(v -> {
|
||||
final TextReadingResetPreference resetPreference =
|
||||
(TextReadingResetPreference) screen.findPreference(getPreferenceKey());
|
||||
resetPreference.setOnResetClickListener(v -> {
|
||||
if (mOnResetClickListener != null) {
|
||||
mOnResetClickListener.onClick(v);
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* The preference which is used for resetting the status of all preferences in the display size
|
||||
* and text page.
|
||||
*/
|
||||
public class TextReadingResetPreference extends Preference {
|
||||
private View.OnClickListener mOnResetClickListener;
|
||||
|
||||
public TextReadingResetPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
setLayoutResource(R.layout.accessibility_text_reading_reset_button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
final View view = holder.findViewById(R.id.reset_button);
|
||||
view.setOnClickListener(mOnResetClickListener);
|
||||
}
|
||||
|
||||
void setOnResetClickListener(View.OnClickListener resetClickListener) {
|
||||
mOnResetClickListener = resetClickListener;
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -28,14 +27,13 @@ import android.view.View;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/**
|
||||
@@ -45,8 +43,11 @@ import org.robolectric.RobolectricTestRunner;
|
||||
public class TextReadingResetControllerTest {
|
||||
private static final String RESET_KEY = "reset";
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
private final View mResetView = new View(mContext);
|
||||
private TextReadingResetController mResetController;
|
||||
private TextReadingResetPreference mResetPreference;
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
@Mock
|
||||
private View.OnClickListener mOnResetButtonClickListener;
|
||||
@@ -54,37 +55,19 @@ public class TextReadingResetControllerTest {
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
|
||||
@Mock
|
||||
private LayoutPreference mLayoutPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mResetController = new TextReadingResetController(mContext, RESET_KEY,
|
||||
mOnResetButtonClickListener);
|
||||
mResetPreference = spy(new TextReadingResetPreference(mContext, /* attrs= */ null));
|
||||
|
||||
when(mPreferenceScreen.findPreference(RESET_KEY)).thenReturn(mResetPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setClickListener_success() {
|
||||
setupResetButton();
|
||||
|
||||
public void displayResetPreference_verifyResetClickListener() {
|
||||
mResetController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mResetView.hasOnClickListeners()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickResetButtonAfterDisplayPreference_verifyClickListener() {
|
||||
setupResetButton();
|
||||
|
||||
mResetController.displayPreference(mPreferenceScreen);
|
||||
mResetView.callOnClick();
|
||||
|
||||
verify(mOnResetButtonClickListener).onClick(any(View.class));
|
||||
}
|
||||
|
||||
private void setupResetButton() {
|
||||
when(mPreferenceScreen.findPreference(RESET_KEY)).thenReturn(mLayoutPreference);
|
||||
when(mLayoutPreference.findViewById(R.id.reset_button)).thenReturn(mResetView);
|
||||
verify(mResetPreference).setOnResetClickListener(any(View.OnClickListener.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/**
|
||||
* Tests for {@link TextReadingResetPreference}.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class TextReadingResetPreferenceTest {
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
private TextReadingResetPreference mResetPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
private View mButtonView;
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
@Mock
|
||||
private View.OnClickListener mOnResetClickListener;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mResetPreference = new TextReadingResetPreference(mContext, /* attrs= */ null);
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final View view = inflater.inflate(mResetPreference.getLayoutResource(),
|
||||
new FrameLayout(mContext), false);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
mButtonView = view.findViewById(R.id.reset_button);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setResetListener_success() {
|
||||
mResetPreference.setOnResetClickListener(mOnResetClickListener);
|
||||
mResetPreference.onBindViewHolder(mHolder);
|
||||
|
||||
assertThat(mButtonView.hasOnClickListeners()).isTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user