Files
app_Settings/src/com/android/settings/inputmethod/KeyboardAccessibilityMouseKeysController.java
shaoweishen 0393a8165b [Physical Keybard] add Mouse key main page
Add page for Mouse key, which contain a main switch toggle and list of
explain images.
demo video: b/346949547#comment38
images:
https://screenshot.googleplex.com/3mc6KnyMdvfAia9.png
https://screenshot.googleplex.com/489mTfSYg9KMUpW.png

Bug: 346949547
Test: atest SettingsRoboTests
Flag: com.android.settings.keyboard.keyboard_and_touchpad_a11y_new_page_enabled
Change-Id: Ia40d5f071cc674ce0118d7ec8a4f0d5e914ce8b9
2024-10-23 07:24:12 +00:00

93 lines
3.2 KiB
Java

/*
* Copyright 2024 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.inputmethod;
import android.content.Context;
import android.hardware.input.InputSettings;
import android.net.Uri;
import android.provider.Settings;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LifecycleObserver;
import androidx.preference.PreferenceScreen;
import com.android.settingslib.PrimarySwitchPreference;
import com.android.settingslib.widget.MainSwitchPreference;
public class KeyboardAccessibilityMouseKeysController extends
InputSettingPreferenceController implements
LifecycleObserver {
private static final String KEY_MOUSE_KEY = "accessibility_mouse_keys";
private static final String KEY_MOUSE_KEY_MAIN_PAGE = "mouse_keys_main_switch";
@Nullable
private PrimarySwitchPreference mPrimaryPreference;
@Nullable
private MainSwitchPreference mMainSwitchPreference;
public KeyboardAccessibilityMouseKeysController(@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
if (KEY_MOUSE_KEY.equals(getPreferenceKey())) {
mPrimaryPreference = screen.findPreference(getPreferenceKey());
} else if (KEY_MOUSE_KEY_MAIN_PAGE.equals(getPreferenceKey())) {
mMainSwitchPreference = screen.findPreference(getPreferenceKey());
}
}
@Override
public boolean isChecked() {
return InputSettings.isAccessibilityMouseKeysEnabled(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
InputSettings.setAccessibilityMouseKeysEnabled(mContext,
isChecked);
return true;
}
@Override
public int getAvailabilityStatus() {
return (super.getAvailabilityStatus() == AVAILABLE)
&& InputSettings.isAccessibilityMouseKeysFeatureFlagEnabled() ? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
@Override
protected void onInputSettingUpdated() {
if (mPrimaryPreference != null) {
mPrimaryPreference.setChecked(
InputSettings.isAccessibilityMouseKeysEnabled(mContext));
} else if (mMainSwitchPreference != null) {
mMainSwitchPreference.setChecked(
InputSettings.isAccessibilityMouseKeysEnabled(mContext));
}
}
@Override
protected Uri getSettingUri() {
return Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_MOUSE_KEYS_ENABLED);
}
}