Merge changes I502e52f6,Iabf58566,Ida773967,Ic6c48861,If9e5cc6e, ...

* changes:
  New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (15/n).
  New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (14/n).
  New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (13/n).
  New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (12/n).
  New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (11/n).
  New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (10/n).
This commit is contained in:
PETER LIANG
2022-02-11 13:42:55 +00:00
committed by Android (Google) Code Review
23 changed files with 1262 additions and 14 deletions

View File

@@ -0,0 +1,54 @@
/*
* 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 androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
/**
* Tests for {@link DisplaySizeData}.
*/
@RunWith(RobolectricTestRunner.class)
public class DisplaySizeDataTest {
private final Context mContext = ApplicationProvider.getApplicationContext();
private DisplaySizeData mDisplaySizeData;
@Before
public void setUp() {
mDisplaySizeData = new DisplaySizeData(mContext);
}
@Ignore("Ignore it since a NPE is happened in ShadowWindowManagerGlobal. (Ref. b/214161063)")
@Test
public void commit_success() {
final int progress = 4;
mDisplaySizeData.commit(progress);
final float density = mContext.getResources().getDisplayMetrics().density;
assertThat(density).isEqualTo(mDisplaySizeData.getValues().get(progress));
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
/**
* Tests for {@link FontSizeData}.
*/
@RunWith(RobolectricTestRunner.class)
public class FontSizeDataTest {
private final Context mContext = ApplicationProvider.getApplicationContext();
private FontSizeData mFontSizeData;
@Before
public void setUp() {
mFontSizeData = new FontSizeData(mContext);
}
@Test
public void commit_success() {
final int progress = 3;
mFontSizeData.commit(progress);
final float currentScale =
Settings.System.getFloat(mContext.getContentResolver(), Settings.System.FONT_SCALE,
/* def= */ 1.0f);
assertThat(currentScale).isEqualTo(mFontSizeData.getValues().get(progress));
}
}

View File

@@ -0,0 +1,98 @@
/*
* 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 static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.widget.LabeledSeekBarPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
/**
* Tests for {@link PreviewSizeSeekBarController}.
*/
@RunWith(RobolectricTestRunner.class)
public class PreviewSizeSeekBarControllerTest {
private static final String FONT_SIZE_KEY = "font_size";
private final Context mContext = ApplicationProvider.getApplicationContext();
private PreviewSizeSeekBarController mSeekBarController;
private FontSizeData mFontSizeData;
private LabeledSeekBarPreference mSeekBarPreference;
@Mock
private PreferenceScreen mPreferenceScreen;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFontSizeData = new FontSizeData(mContext);
mSeekBarController =
new PreviewSizeSeekBarController(mContext, FONT_SIZE_KEY, mFontSizeData);
mSeekBarPreference = spy(new LabeledSeekBarPreference(mContext, /* attrs= */ null));
when(mPreferenceScreen.findPreference(anyString())).thenReturn(mSeekBarPreference);
}
@Test
public void initMax_matchResult() {
when(mPreferenceScreen.findPreference(anyString())).thenReturn(mSeekBarPreference);
mSeekBarController.displayPreference(mPreferenceScreen);
assertThat(mSeekBarPreference.getMax()).isEqualTo(
mFontSizeData.getValues().size() - 1);
}
@Test
public void initProgress_matchResult() {
when(mPreferenceScreen.findPreference(anyString())).thenReturn(mSeekBarPreference);
mSeekBarController.displayPreference(mPreferenceScreen);
verify(mSeekBarPreference).setProgress(mFontSizeData.getInitialIndex());
}
@Test
public void resetToDefaultState_matchResult() {
final int defaultProgress =
mFontSizeData.getValues().indexOf(mFontSizeData.getDefaultValue());
when(mPreferenceScreen.findPreference(anyString())).thenReturn(mSeekBarPreference);
mSeekBarController.displayPreference(mPreferenceScreen);
mSeekBarPreference.setProgress(defaultProgress + 1);
mSeekBarController.resetState();
assertThat(mSeekBarPreference.getProgress()).isEqualTo(defaultProgress);
}
}

View File

@@ -0,0 +1,119 @@
/*
* 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 org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.display.PreviewPagerAdapter;
import com.android.settings.widget.LabeledSeekBarPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowChoreographer;
import java.util.ArrayList;
import java.util.List;
/**
* Tests for {@link TextReadingPreviewController}.
*/
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowChoreographer.class)
public class TextReadingPreviewControllerTest {
private static final String PREVIEW_KEY = "preview";
private static final String FONT_SIZE_KEY = "font_size";
private static final String DISPLAY_SIZE_KEY = "display_size";
private final Context mContext = ApplicationProvider.getApplicationContext();
private TextReadingPreviewController mPreviewController;
private TextReadingPreviewPreference mPreviewPreference;
private LabeledSeekBarPreference mFontSizePreference;
private LabeledSeekBarPreference mDisplaySizePreference;
@Mock
private DisplaySizeData mDisplaySizeData;
@Mock
private PreferenceScreen mPreferenceScreen;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final FontSizeData fontSizeData = new FontSizeData(mContext);
final List<Integer> displayData = createFakeDisplayData();
when(mDisplaySizeData.getValues()).thenReturn(displayData);
mPreviewPreference = spy(new TextReadingPreviewPreference(mContext, /* attr= */ null));
mPreviewController = new TextReadingPreviewController(mContext, PREVIEW_KEY, fontSizeData,
mDisplaySizeData);
mFontSizePreference = new LabeledSeekBarPreference(mContext, /* attr= */ null);
mDisplaySizePreference = new LabeledSeekBarPreference(mContext, /* attr= */ null);
}
@Test
public void initPreviewerAdapter_verifyAction() {
when(mPreferenceScreen.findPreference(PREVIEW_KEY)).thenReturn(mPreviewPreference);
when(mPreferenceScreen.findPreference(FONT_SIZE_KEY)).thenReturn(mFontSizePreference);
when(mPreferenceScreen.findPreference(DISPLAY_SIZE_KEY)).thenReturn(mDisplaySizePreference);
mPreviewController.displayPreference(mPreferenceScreen);
verify(mPreviewPreference).setPreviewAdapter(any(PreviewPagerAdapter.class));
}
@Test(expected = NullPointerException.class)
public void initPreviewerAdapterWithoutDisplaySizePreference_throwNPE() {
when(mPreferenceScreen.findPreference(PREVIEW_KEY)).thenReturn(mPreviewPreference);
when(mPreferenceScreen.findPreference(DISPLAY_SIZE_KEY)).thenReturn(mDisplaySizePreference);
mPreviewController.displayPreference(mPreferenceScreen);
verify(mPreviewPreference).setPreviewAdapter(any(PreviewPagerAdapter.class));
}
@Test(expected = NullPointerException.class)
public void initPreviewerAdapterWithoutFontSizePreference_throwNPE() {
when(mPreferenceScreen.findPreference(PREVIEW_KEY)).thenReturn(mPreviewPreference);
when(mPreferenceScreen.findPreference(FONT_SIZE_KEY)).thenReturn(mFontSizePreference);
mPreviewController.displayPreference(mPreferenceScreen);
verify(mPreviewPreference).setPreviewAdapter(any(PreviewPagerAdapter.class));
}
private List<Integer> createFakeDisplayData() {
final List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
return list;
}
}

View File

@@ -16,8 +16,16 @@
package com.android.settings.accessibility;
import static com.android.settings.accessibility.TextReadingPreviewController.PREVIEW_SAMPLE_RES_IDS;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.res.Configuration;
import android.view.LayoutInflater;
@@ -50,12 +58,11 @@ public class TextReadingPreviewPreferenceTest {
@Before
public void setUp() {
final Context context = ApplicationProvider.getApplicationContext();
final int[] sampleResIds = new int[]{1, 2, 3, 4, 5, 6};
final Configuration[] configurations = createConfigurations(6);
final Configuration[] configurations = createConfigurations(PREVIEW_SAMPLE_RES_IDS.length);
mTextReadingPreviewPreference = new TextReadingPreviewPreference(context);
mPreviewPagerAdapter =
new PreviewPagerAdapter(context, /* isLayoutRtl= */ false, sampleResIds,
configurations);
spy(new PreviewPagerAdapter(context, /* isLayoutRtl= */ false,
PREVIEW_SAMPLE_RES_IDS, configurations));
final LayoutInflater inflater = LayoutInflater.from(context);
final View view =
inflater.inflate(mTextReadingPreviewPreference.getLayoutResource(),
@@ -87,7 +94,7 @@ public class TextReadingPreviewPreferenceTest {
@Test
public void setCurrentItem_success() {
final int currentItem = 3;
final int currentItem = 1;
mTextReadingPreviewPreference.setPreviewAdapter(mPreviewPagerAdapter);
mTextReadingPreviewPreference.onBindViewHolder(mHolder);
@@ -104,6 +111,24 @@ public class TextReadingPreviewPreferenceTest {
mTextReadingPreviewPreference.setCurrentItem(currentItem);
}
@Test(expected = NullPointerException.class)
public void updatePagerWithoutPreviewAdapter_throwNPE() {
final int index = 1;
mTextReadingPreviewPreference.notifyPreviewPagerChanged(index);
}
@Test
public void notifyPreviewPager_setPreviewLayer() {
final int index = 2;
mTextReadingPreviewPreference.setPreviewAdapter(mPreviewPagerAdapter);
mTextReadingPreviewPreference.onBindViewHolder(mHolder);
mTextReadingPreviewPreference.notifyPreviewPagerChanged(index);
verify(mPreviewPagerAdapter).setPreviewLayer(eq(index), anyInt(), anyInt(), anyBoolean());
}
private static Configuration[] createConfigurations(int count) {
final Configuration[] configurations = new Configuration[count];
for (int i = 0; i < count; i++) {

View File

@@ -0,0 +1,119 @@
/*
* 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.android.settings.accessibility.TextReadingResetController.ResetStateListener;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.view.View;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import java.util.ArrayList;
import java.util.List;
/**
* Tests for {@link TextReadingResetController}.
*/
@RunWith(RobolectricTestRunner.class)
public class TextReadingResetControllerTest {
private static final String TEST_KEY = "test";
private static final String RESET_KEY = "reset";
private final Context mContext = ApplicationProvider.getApplicationContext();
private final View mResetView = new View(mContext);
private final List<ResetStateListener> mListeners = new ArrayList<>();
private TextReadingResetController mResetController;
private TestPreferenceController mPreferenceController;
@Mock
private PreferenceScreen mPreferenceScreen;
@Mock
private LayoutPreference mLayoutPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mPreferenceController = new TestPreferenceController(mContext, TEST_KEY);
mListeners.add(mPreferenceController);
mResetController = new TextReadingResetController(mContext, RESET_KEY, mListeners);
}
@Test
public void setClickListener_success() {
setupResetButton();
mResetController.displayPreference(mPreferenceScreen);
assertThat(mResetView.hasOnClickListeners()).isTrue();
}
@Test
public void triggerResetState_success() {
setupResetButton();
mResetController.displayPreference(mPreferenceScreen);
mResetView.callOnClick();
assertThat(mPreferenceController.isReset()).isTrue();
}
private void setupResetButton() {
when(mPreferenceScreen.findPreference(RESET_KEY)).thenReturn(mLayoutPreference);
when(mLayoutPreference.findViewById(R.id.reset_button)).thenReturn(mResetView);
}
private static class TestPreferenceController extends BasePreferenceController implements
ResetStateListener {
private boolean mIsReset = false;
TestPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public void resetState() {
mIsReset = true;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
boolean isReset() {
return mIsReset;
}
}
}