Merge "[Material Next] Update accessibility tool footer style" into sc-dev

This commit is contained in:
Menghan Li
2021-05-03 11:13:28 +00:00
committed by Android (Google) Code Review
24 changed files with 804 additions and 74 deletions

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2021 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.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link AccessibilityButtonFooterPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class AccessibilityButtonFooterPreferenceControllerTest {
private static final String TEST_KEY = "test_key";
private final Context mContext = ApplicationProvider.getApplicationContext();
private PreferenceScreen mScreen;
private AccessibilityButtonFooterPreferenceController mController;
@Before
public void setUp() {
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
mScreen = preferenceManager.createPreferenceScreen(mContext);
final AccessibilityFooterPreference footerPreference =
new AccessibilityFooterPreference(mContext);
footerPreference.setKey(TEST_KEY);
mScreen.addPreference(footerPreference);
mController = new AccessibilityButtonFooterPreferenceController(mContext, TEST_KEY);
}
@Test
public void onPreferenceChange_shouldSetCorrectIconContentDescription() {
mController.displayPreference(mScreen);
final AccessibilityFooterPreference footerPreference = mScreen.findPreference(TEST_KEY);
final String packageName = mContext.getString(R.string.accessibility_button_title);
final String iconContentDescription = mContext.getString(
R.string.accessibility_introduction_title,
packageName);
assertThat(footerPreference.getIconContentDescription()).isEqualTo(iconContentDescription);
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2021 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.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link AccessibilityControlTimeoutFooterPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class AccessibilityControlTimeoutFooterPreferenceControllerTest {
private static final String TEST_KEY = "test_key";
private final Context mContext = ApplicationProvider.getApplicationContext();
private PreferenceScreen mScreen;
private AccessibilityControlTimeoutFooterPreferenceController mController;
@Before
public void setUp() {
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
mScreen = preferenceManager.createPreferenceScreen(mContext);
final AccessibilityFooterPreference footerPreference =
new AccessibilityFooterPreference(mContext);
footerPreference.setKey(TEST_KEY);
mScreen.addPreference(footerPreference);
mController = new AccessibilityControlTimeoutFooterPreferenceController(mContext, TEST_KEY);
}
@Test
public void onPreferenceChange_shouldSetCorrectIconContentDescription() {
mController.displayPreference(mScreen);
final AccessibilityFooterPreference footerPreference =
mScreen.findPreference(TEST_KEY);
final String packageName =
mContext.getString(R.string.accessibility_setting_item_control_timeout_title);
final String iconContentDescription = mContext.getString(
R.string.accessibility_introduction_title,
packageName);
assertThat(footerPreference.getIconContentDescription()).isEqualTo(iconContentDescription);
}
}

View File

@@ -0,0 +1,86 @@
/*
* 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.
*/
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.LinearLayout;
import android.widget.TextView;
import androidx.preference.PreferenceViewHolder;
import com.android.settingslib.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
/** Tests for {@link AccessibilityFooterPreference} */
@RunWith(RobolectricTestRunner.class)
public final class AccessibilityFooterPreferenceTest {
private static final String DEFAULT_SUMMARY = "default summary";
private static final String DEFAULT_DESCRIPTION = "default description";
private AccessibilityFooterPreference mAccessibilityFooterPreference;
private PreferenceViewHolder mPreferenceViewHolder;
@Before
public void setUp() {
final Context context = RuntimeEnvironment.application;
mAccessibilityFooterPreference = new AccessibilityFooterPreference(context);
final LayoutInflater inflater = LayoutInflater.from(context);
final View view =
inflater.inflate(R.layout.preference_footer, null);
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(view);
}
@Test
public void onBindViewHolder_initTextConfig_parseTextAndFocusable() {
mAccessibilityFooterPreference.setSummary(DEFAULT_SUMMARY);
mAccessibilityFooterPreference.onBindViewHolder(mPreferenceViewHolder);
final TextView summaryView = (TextView) mPreferenceViewHolder.findViewById(
android.R.id.title);
assertThat(summaryView.getText().toString()).isEqualTo(DEFAULT_SUMMARY);
assertThat(summaryView.isFocusable()).isEqualTo(true);
}
@Test
public void onBindViewHolder_initTextConfigAndAccessibleIcon_groupContentForAccessible() {
mAccessibilityFooterPreference.setSummary(DEFAULT_SUMMARY);
mAccessibilityFooterPreference.setIconContentDescription(DEFAULT_DESCRIPTION);
mAccessibilityFooterPreference.onBindViewHolder(mPreferenceViewHolder);
final TextView summaryView = (TextView) mPreferenceViewHolder.findViewById(
android.R.id.title);
assertThat(summaryView.getText().toString()).isEqualTo(DEFAULT_SUMMARY);
assertThat(summaryView.isFocusable()).isEqualTo(false);
final LinearLayout infoFrame = (LinearLayout) mPreferenceViewHolder.findViewById(
R.id.icon_frame);
assertThat(infoFrame.getContentDescription()).isEqualTo(DEFAULT_DESCRIPTION);
assertThat(infoFrame.isFocusable()).isEqualTo(false);
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2021 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.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link CaptionFooterPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class CaptionFooterPreferenceControllerTest {
private static final String TEST_KEY = "test_key";
private final Context mContext = ApplicationProvider.getApplicationContext();
private PreferenceScreen mScreen;
private CaptionFooterPreferenceController mController;
@Before
public void setUp() {
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
mScreen = preferenceManager.createPreferenceScreen(mContext);
final AccessibilityFooterPreference footerPreference =
new AccessibilityFooterPreference(mContext);
footerPreference.setKey(TEST_KEY);
mScreen.addPreference(footerPreference);
mController = new CaptionFooterPreferenceController(mContext, TEST_KEY);
}
@Test
public void onPreferenceChange_shouldSetCorrectIconContentDescription() {
mController.displayPreference(mScreen);
final AccessibilityFooterPreference footerPreference = mScreen.findPreference(TEST_KEY);
final String packageName = mContext.getString(R.string.accessibility_captioning_title);
final String iconContentDescription = mContext.getString(
R.string.accessibility_introduction_title,
packageName);
assertThat(footerPreference.getIconContentDescription()).isEqualTo(iconContentDescription);
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (C) 2021 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.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link ToggleAutoclickFooterPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class ToggleAutoclickFooterPreferenceControllerTest {
private static final String TEST_KEY = "test_key";
private final Context mContext = ApplicationProvider.getApplicationContext();
private PreferenceScreen mScreen;
private ToggleAutoclickFooterPreferenceController mController;
@Before
public void setUp() {
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
mScreen = preferenceManager.createPreferenceScreen(mContext);
final AccessibilityFooterPreference footerPreference =
new AccessibilityFooterPreference(mContext);
footerPreference.setKey(TEST_KEY);
mScreen.addPreference(footerPreference);
mController = new ToggleAutoclickFooterPreferenceController(mContext, TEST_KEY);
}
@Test
public void onPreferenceChange_shouldSetCorrectIconContentDescription() {
mController.displayPreference(mScreen);
final AccessibilityFooterPreference footerPreference = mScreen.findPreference(TEST_KEY);
final String packageName = mContext.getString(
R.string.accessibility_autoclick_preference_title);
final String iconContentDescription = mContext.getString(
R.string.accessibility_introduction_title,
packageName);
assertThat(footerPreference.getIconContentDescription()).isEqualTo(iconContentDescription);
}
}

View File

@@ -39,6 +39,7 @@ import androidx.annotation.XmlRes;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
@@ -48,6 +49,7 @@ import com.android.settings.testutils.shadow.ShadowFragment;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@@ -63,6 +65,8 @@ public class ToggleFeaturePreferenceFragmentTest {
private static final ComponentName PLACEHOLDER_COMPONENT_NAME = new ComponentName(
PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_CLASS_NAME);
private static final String PLACEHOLDER_DIALOG_TITLE = "title";
private static final String DEFAULT_SUMMARY = "default summary";
private static final String DEFAULT_DESCRIPTION = "default description";
private static final String SOFTWARE_SHORTCUT_KEY =
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
@@ -70,9 +74,10 @@ public class ToggleFeaturePreferenceFragmentTest {
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
private TestToggleFeaturePreferenceFragment mFragment;
private PreferenceScreen mScreen;
private Context mContext = ApplicationProvider.getApplicationContext();
@Mock
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceManager mPreferenceManager;
@Before
@@ -83,7 +88,9 @@ public class ToggleFeaturePreferenceFragmentTest {
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
when(mFragment.getContext()).thenReturn(mContext);
doReturn(null).when(mFragment).getPreferenceScreen();
mScreen = spy(new PreferenceScreen(mContext, null));
when(mScreen.getPreferenceManager()).thenReturn(mPreferenceManager);
doReturn(mScreen).when(mFragment).getPreferenceScreen();
}
@Test
@@ -195,6 +202,21 @@ public class ToggleFeaturePreferenceFragmentTest {
assertThat(expectedType).isEqualTo(UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE);
}
@Test
public void createFooterPreference_shouldSetAsExpectedValue() {
mFragment.createFooterPreference(mFragment.getPreferenceScreen(),
DEFAULT_SUMMARY, DEFAULT_DESCRIPTION);
AccessibilityFooterPreference accessibilityFooterPreference =
(AccessibilityFooterPreference) mFragment.getPreferenceScreen().getPreference(
mFragment.getPreferenceScreen().getPreferenceCount() - 1);
assertThat(accessibilityFooterPreference.getSummary()).isEqualTo(DEFAULT_SUMMARY);
assertThat(accessibilityFooterPreference.getIconContentDescription()).isEqualTo(
DEFAULT_DESCRIPTION);
assertThat(accessibilityFooterPreference.isSelectable()).isEqualTo(true);
assertThat(accessibilityFooterPreference.getOrder()).isEqualTo(Integer.MAX_VALUE - 1);
}
private void putStringIntoSettings(String key, String componentName) {
Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
}