Merge "Add a cursor preference to Accessibility Settings"
This commit is contained in:
committed by
Android (Google) Code Review
commit
89be5b0d46
@@ -2861,6 +2861,22 @@
|
|||||||
column="13"/>
|
column="13"/>
|
||||||
</issue>
|
</issue>
|
||||||
|
|
||||||
|
<issue
|
||||||
|
id="HardCodedColor"
|
||||||
|
severity="Error"
|
||||||
|
message="Avoid using hardcoded color"
|
||||||
|
category="Correctness"
|
||||||
|
priority="4"
|
||||||
|
summary="Using hardcoded color"
|
||||||
|
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||||
|
errorLine1=" android:color="@color/accessibility_feature_background"/>"
|
||||||
|
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||||
|
<location
|
||||||
|
file="res/drawable/ic_accessibility_software_cursor.xml"
|
||||||
|
line="22"
|
||||||
|
column="13"/>
|
||||||
|
</issue>
|
||||||
|
|
||||||
<issue
|
<issue
|
||||||
id="HardCodedColor"
|
id="HardCodedColor"
|
||||||
severity="Error"
|
severity="Error"
|
||||||
|
35
res/drawable/ic_accessibility_software_cursor.xml
Normal file
35
res/drawable/ic_accessibility_software_cursor.xml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<!--
|
||||||
|
Copyright 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item>
|
||||||
|
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||||
|
android:width="@dimen/accessibility_icon_size"
|
||||||
|
android:height="@dimen/accessibility_icon_size"
|
||||||
|
android:color="@color/accessibility_feature_background"/>
|
||||||
|
</item>
|
||||||
|
<item android:gravity="center">
|
||||||
|
<vector
|
||||||
|
android:height="@dimen/accessibility_icon_foreground_size" android:viewportHeight="400"
|
||||||
|
android:viewportWidth="400" android:width="@dimen/accessibility_icon_foreground_size">
|
||||||
|
<path android:fillColor="#ffffff" android:pathData="M258.35,149.56l10.36,5.13l-7.6,15.35l-10.36,-5.13L258.35,149.56zM194.11,175.1l5.07,-10.24l15.54,7.69l-5.07,10.24L194.11,175.1z"/>
|
||||||
|
<path android:fillColor="#ffffff" android:pathData="M210.38,195.9l3.73,10.83l-16.35,5.41l-3.73,-10.83L210.38,195.9zM219.98,148.91l10.88,-3.6l5.61,16.29l-10.88,3.6L219.98,148.91zM288.78,173.93l3.73,10.83c-8.2,2.76 -8.43,2.83 -16.38,5.46l-3.73,-10.83C280.3,176.74 280.84,176.56 288.78,173.93z"/>
|
||||||
|
<path android:fillColor="#ffffff" android:fillType="evenOdd" android:pathData="M301.3,245.59l-26.75,-14.14c-3.93,-2.07 -7.27,-3.42 -7.27,-7.08c0,-26.44 4.38,-52.43 -20.64,-52.43c-26.2,2.55 -20.64,28.7 -20.64,55.14c0,18.58 0,1.63 0,9.34v28.44l-15.19,-3.4l-0.83,-0.17c-0.83,-0.17 -1.65,-0.26 -2.64,-0.26c-4.38,0 -8.5,1.83 -11.64,5.15l0,0c-6.5,6.96 -6.46,17.78 0.09,24.7l30.38,32.1c3.55,3.84 8.5,6.02 13.62,6.02h52.01c8.09,0 14.94,-6.11 16.26,-14.57l6.6,-41.1C316.49,261.99 311.12,250.82 301.3,245.59zM296.38,271l-6.16,36.42c-0.25,1.49 -1.54,2.58 -3.06,2.58h-49.36c-1.98,0 -3.32,-1.74 -3.9,-2.26l-24.53,-24.49c-1.18,-1.25 -0.03,-3.27 1.64,-2.9l18.91,4.19c5.44,1.2 10.6,-2.94 10.07,-8.52v-82.17c0,-3.43 2.84,-6.82 6.71,-6.82c4.54,0 7.29,2.74 7.29,7.19v34.99c-0.21,8.12 2.87,13.62 9.3,17.45l0,0l28.54,15.09C295.15,263.49 296.96,267.24 296.38,271z"/>
|
||||||
|
<path android:fillColor="#ffffff" android:pathData="M223,117h-33.23C186.6,95.08 169.55,77.83 148,74.84V42h-14v33.82c-21.66,3.2 -38.72,19.95 -41.92,41.18H59v14h33.88c2.98,21.88 19.77,39.18 41.12,42.47V206h14v-33.3c22.14,-2.95 39.64,-20.04 42.71,-41.7H223V117zM141.99,163h-2.08c-20.39,-0.54 -36.84,-16.67 -37.91,-36.92v-4.16c1.07,-20.25 17.52,-36.38 37.91,-36.92h2.08c21.08,0.56 38.01,17.78 38.01,39C180,145.22 163.07,162.44 141.99,163z"/>
|
||||||
|
<path android:fillColor="#ffffff" android:pathData="M141,124m-18,0a18,18 0,1 1,36 0a18,18 0,1 1,-36 0"/>
|
||||||
|
</vector>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
@@ -5137,6 +5137,12 @@
|
|||||||
<string name="accessibility_turn_screen_darker_title">Turn screen darker</string>
|
<string name="accessibility_turn_screen_darker_title">Turn screen darker</string>
|
||||||
<!-- Title for the accessibility preference category of interaction control services and settings. [CHAR LIMIT=50] -->
|
<!-- Title for the accessibility preference category of interaction control services and settings. [CHAR LIMIT=50] -->
|
||||||
<string name="interaction_control_category_title">Interaction controls</string>
|
<string name="interaction_control_category_title">Interaction controls</string>
|
||||||
|
<!-- Title for the accessibility Software Cursor settings . [CHAR LIMIT=50] -->
|
||||||
|
<string name="accessibility_software_cursor_title" translatable="false">Software Cursor</string>
|
||||||
|
<!-- Summary for the accessibility Software Cursor settings . [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="accessibility_software_cursor_summary" translatable="false">Control your Android device using an on screen cursor</string>
|
||||||
|
<!-- Title for the accessibility Software Cursor settings screen. -->
|
||||||
|
<string name="accessibility_screen_software_cursor_title" translatable="false">Software Cursor</string>
|
||||||
<!-- Title for the accessibility tap assistance page. [CHAR LIMIT=50] -->
|
<!-- Title for the accessibility tap assistance page. [CHAR LIMIT=50] -->
|
||||||
<string name="accessibility_tap_assistance_title">Timing controls</string>
|
<string name="accessibility_tap_assistance_title">Timing controls</string>
|
||||||
<!-- Title for the accessibility system controls page. [CHAR LIMIT=50] -->
|
<!-- Title for the accessibility system controls page. [CHAR LIMIT=50] -->
|
||||||
@@ -5874,6 +5880,8 @@
|
|||||||
<string name="keywords_accessibility">Ease of use, ease of access, assistance, assistive</string>
|
<string name="keywords_accessibility">Ease of use, ease of access, assistance, assistive</string>
|
||||||
<!-- List of synonyms used in the settings search bar to find the “Magnification”. [CHAR LIMIT=NONE] -->
|
<!-- List of synonyms used in the settings search bar to find the “Magnification”. [CHAR LIMIT=NONE] -->
|
||||||
<string name="keywords_magnification">Window Magnifier, Zoom, Magnification, Low vision, Enlarge, make bigger</string>
|
<string name="keywords_magnification">Window Magnifier, Zoom, Magnification, Low vision, Enlarge, make bigger</string>
|
||||||
|
<!-- List of synonyms used in the settings search bar to find “Software Cursor". [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="keywords_software_cursor" translatable="false">Cursor, Trackpad, Software Cursor, Mouse</string>
|
||||||
<!-- List of synonyms used in the settings search bar to find the “TalkBack”. [CHAR LIMIT=NONE] -->
|
<!-- List of synonyms used in the settings search bar to find the “TalkBack”. [CHAR LIMIT=NONE] -->
|
||||||
<string name="keywords_talkback"></string>
|
<string name="keywords_talkback"></string>
|
||||||
<!-- List of synonyms used in the settings search bar to find the “Live Caption”. [CHAR LIMIT=NONE] -->
|
<!-- List of synonyms used in the settings search bar to find the “Live Caption”. [CHAR LIMIT=NONE] -->
|
||||||
|
25
res/xml/accessibility_cursor_settings.xml
Normal file
25
res/xml/accessibility_cursor_settings.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 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.
|
||||||
|
-->
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:title="@string/accessibility_screen_software_cursor_title"
|
||||||
|
settings:searchable="false">
|
||||||
|
<com.android.settings.widget.SettingsMainSwitchPreference
|
||||||
|
android:key="screen_software_cursor_preference_switch"
|
||||||
|
android:title="@string/accessibility_screen_software_cursor_title"
|
||||||
|
settings:controller="com.android.settings.accessibility.SoftwareCursorTogglePreferenceController"/>
|
||||||
|
</PreferenceScreen>
|
@@ -102,6 +102,17 @@
|
|||||||
settings:keywords="@string/keywords_vibration"
|
settings:keywords="@string/keywords_vibration"
|
||||||
android:summary="@string/accessibility_vibration_settings_summary"/>
|
android:summary="@string/accessibility_vibration_settings_summary"/>
|
||||||
|
|
||||||
|
<!-- TODO(b/241023294): UX review of where Software Cursor feature should be positioned. -->
|
||||||
|
<Preference
|
||||||
|
android:key="software_cursor_preference_screen"
|
||||||
|
android:icon="@drawable/ic_accessibility_software_cursor"
|
||||||
|
android:fragment="com.android.settings.accessibility.CursorPreferenceFragment"
|
||||||
|
android:title="@string/accessibility_software_cursor_title"
|
||||||
|
settings:searchable="true"
|
||||||
|
settings:keywords="@string/keywords_software_cursor"
|
||||||
|
android:summary="@string/accessibility_software_cursor_summary"
|
||||||
|
settings:controller="com.android.settings.accessibility.SoftwareCursorPreferenceController"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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.app.settings.SettingsEnums;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
|
/** Settings fragment containing software cursor preferences. */
|
||||||
|
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||||
|
public final class CursorPreferenceFragment extends DashboardFragment {
|
||||||
|
|
||||||
|
private static final String TAG = "CursorPreferenceFragment";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.accessibility_cursor_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.ACCESSIBILITY_TOGGLE_SOFTWARE_CURSOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
new BaseSearchIndexProvider(R.xml.accessibility_cursor_settings);
|
||||||
|
}
|
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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.FeatureFlagUtils;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preference controller for the software cursor feature.
|
||||||
|
*/
|
||||||
|
public class SoftwareCursorPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
public SoftwareCursorPreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
// Hide the Software Cursor preference if the feature flag is not enabled.
|
||||||
|
return FeatureFlagUtils.isEnabled(mContext,
|
||||||
|
FeatureFlagUtils.SETTINGS_ACCESSIBILITY_SIMPLE_CURSOR) ? AVAILABLE
|
||||||
|
: CONDITIONALLY_UNAVAILABLE;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* 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.AccessibilityUtil.State.OFF;
|
||||||
|
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.widget.Switch;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
import com.android.settings.widget.SettingsMainSwitchPreference;
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
|
/** Preference controller for toggling software cursor. */
|
||||||
|
public class SoftwareCursorTogglePreferenceController extends TogglePreferenceController
|
||||||
|
implements OnMainSwitchChangeListener {
|
||||||
|
|
||||||
|
private final ContentResolver mContentResolver;
|
||||||
|
|
||||||
|
public SoftwareCursorTogglePreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
mContentResolver = context.getContentResolver();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isChecked() {
|
||||||
|
return Settings.Secure.getInt(mContentResolver,
|
||||||
|
Settings.Secure.ACCESSIBILITY_SOFTWARE_CURSOR_ENABLED, OFF) == ON;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setChecked(boolean isChecked) {
|
||||||
|
Settings.Secure.putInt(mContentResolver,
|
||||||
|
Settings.Secure.ACCESSIBILITY_SOFTWARE_CURSOR_ENABLED, isChecked ? ON : OFF);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
|
||||||
|
SettingsMainSwitchPreference preference = screen.findPreference(getPreferenceKey());
|
||||||
|
preference.addOnSwitchChangeListener(this);
|
||||||
|
preference.setChecked(isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSliceHighlightMenuRes() {
|
||||||
|
return R.string.menu_key_accessibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
|
if (isChecked != isChecked()) {
|
||||||
|
setChecked(isChecked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.BasePreferenceController.AVAILABLE;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class SoftwareCursorPreferenceControllerTest {
|
||||||
|
|
||||||
|
private SoftwareCursorPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mController = new SoftwareCursorPreferenceController(
|
||||||
|
ApplicationProvider.getApplicationContext(), "test_key");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_featureFlagEnabled_shouldReturnAvailable() {
|
||||||
|
FeatureFlagUtils.setEnabled(ApplicationProvider.getApplicationContext(),
|
||||||
|
FeatureFlagUtils.SETTINGS_ACCESSIBILITY_SIMPLE_CURSOR, /* enabled= */ true);
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_featureFlagDisabled_shouldReturnUnavailable() {
|
||||||
|
FeatureFlagUtils.setEnabled(ApplicationProvider.getApplicationContext(),
|
||||||
|
FeatureFlagUtils.SETTINGS_ACCESSIBILITY_SIMPLE_CURSOR, /* enabled= */ false);
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* 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.AccessibilityUtil.State.OFF;
|
||||||
|
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.widget.SettingsMainSwitchPreference;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
/** Tests for {@link SoftwareCursorTogglePreferenceController}. */
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class SoftwareCursorTogglePreferenceControllerTest {
|
||||||
|
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
private SoftwareCursorTogglePreferenceController mController;
|
||||||
|
private SettingsMainSwitchPreference mSwitchPreference;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
if (Looper.myLooper() == null) {
|
||||||
|
Looper.prepare();
|
||||||
|
}
|
||||||
|
mController = new SoftwareCursorTogglePreferenceController(mContext,
|
||||||
|
"screen_software_cursor_preference_switch");
|
||||||
|
mSwitchPreference = new SettingsMainSwitchPreference(mContext);
|
||||||
|
mSwitchPreference.setKey(mController.getPreferenceKey());
|
||||||
|
PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||||
|
mScreen = preferenceManager.createPreferenceScreen(mContext);
|
||||||
|
mScreen.addPreference(mSwitchPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_SOFTWARE_CURSOR_ENABLED, OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_shouldReturnAvailable() {
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void performClick_cursorEnabled_shouldSetCursorDisabled() {
|
||||||
|
mController.setChecked(true);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
mSwitchPreference.performClick();
|
||||||
|
|
||||||
|
assertThat(mSwitchPreference.isChecked()).isFalse();
|
||||||
|
assertThat(isSoftwareCursorEnabled()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void performClick_cursorDisabled_shouldSetCursorEnabled() {
|
||||||
|
mController.setChecked(false);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
mSwitchPreference.performClick();
|
||||||
|
|
||||||
|
assertThat(mSwitchPreference.isChecked()).isTrue();
|
||||||
|
assertThat(isSoftwareCursorEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setChecked_switchChecked_shouldSetCursorEnabled() {
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
mController.setChecked(/* isChecked= */ true);
|
||||||
|
|
||||||
|
assertThat(isSoftwareCursorEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setChecked_switchUnchecked_shouldSetCursorDisabled() {
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
mController.setChecked(/* isChecked= */ false);
|
||||||
|
|
||||||
|
assertThat(isSoftwareCursorEnabled()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSwitchChanged_switchChecked_shouldSetCursorEnabled() {
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
mController.onSwitchChanged(/* switchView= */ null, /* isChecked= */ true);
|
||||||
|
|
||||||
|
assertThat(isSoftwareCursorEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSwitchChanged_switchUnchecked_shouldSetCursorDisabled() {
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
mController.onSwitchChanged(/* switchView= */ null, /* isChecked= */ false);
|
||||||
|
|
||||||
|
|
||||||
|
assertThat(isSoftwareCursorEnabled()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSoftwareCursorEnabled() {
|
||||||
|
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_SOFTWARE_CURSOR_ENABLED, OFF) == ON;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user