Add a cursor preference to Accessibility Settings

Bug: 240194047

Test: atest SoftwareCursorPreferencesControllerTest and
SoftwareCursorTogglerPreferenceControllerTest

Change-Id: I97e226d8d8c0bcdfd0e2612e86b81987480063d1
This commit is contained in:
Lauren Winston
2022-07-25 22:58:56 +00:00
parent e530a17247
commit 205018a854
10 changed files with 463 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}