Merge "[Physical Keybaord] Add keyboard touchpad/Mouse page - part1" into main

This commit is contained in:
Shaowei Shen
2024-11-25 09:31:58 +00:00
committed by Android (Google) Code Review
15 changed files with 575 additions and 14 deletions

View File

@@ -136,7 +136,7 @@ import com.android.settings.inputmethod.ModifierKeysSettings;
import com.android.settings.inputmethod.NewKeyboardLayoutEnabledLocalesFragment;
import com.android.settings.inputmethod.PhysicalKeyboardFragment;
import com.android.settings.inputmethod.SpellCheckersSettings;
import com.android.settings.inputmethod.TrackpadSettings;
import com.android.settings.inputmethod.TouchpadAndMouseSettings;
import com.android.settings.inputmethod.UserDictionaryList;
import com.android.settings.inputmethod.UserDictionarySettings;
import com.android.settings.language.LanguageSettings;
@@ -237,7 +237,7 @@ public class SettingsGateway {
KeyboardSettings.class.getName(),
ModifierKeysSettings.class.getName(),
NewKeyboardLayoutEnabledLocalesFragment.class.getName(),
TrackpadSettings.class.getName(),
TouchpadAndMouseSettings.class.getName(),
SpellCheckersSettings.class.getName(),
UserDictionaryList.class.getName(),
UserDictionarySettings.class.getName(),

View File

@@ -0,0 +1,83 @@
/*
* 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.InputManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
public abstract class InputDeviceSettingsController extends BasePreferenceController
implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop,
InputManager.InputDeviceListener {
private final InputManager mIm;
@Nullable
private Preference mPreference;
public InputDeviceSettingsController(@NonNull Context context, @NonNull String key) {
super(context, key);
mIm = context.getSystemService(InputManager.class);
}
@Override
public void onInputDeviceAdded(int deviceId) {
updateEntry();
}
@Override
public void onInputDeviceRemoved(int deviceId) {
updateEntry();
}
@Override
public void onInputDeviceChanged(int deviceId) {
updateEntry();
}
@Override
public void onStart() {
mIm.registerInputDeviceListener(this, null);
}
@Override
public void onStop() {
mIm.unregisterInputDeviceListener(this);
}
@Override
public void updateState(Preference preference) {
mPreference = preference;
updateEntry();
}
private void updateEntry() {
if (mPreference == null) {
return;
}
mPreference.setVisible(isAvailable());
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.app.settings.SettingsEnums;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.keyboard.Flags;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
@SearchIndexable
public class MouseSettingFragment extends DashboardFragment {
private static final String TAG = MouseSettingFragment.class.getSimpleName();
@Override
protected int getPreferenceScreenResId() {
return R.xml.mouse_settings;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public int getMetricsCategory() {
return SettingsEnums.SETTINGS_KEYBOARD_MOUSE;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.mouse_settings) {
@Override
protected boolean isPageSearchEnabled(Context context) {
return Flags.keyboardAndTouchpadA11yNewPageEnabled()
&& InputPeripheralsSettingsUtils.isMouse();
}
};
}

View File

@@ -0,0 +1,40 @@
/*
* 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 androidx.annotation.NonNull;
import com.android.settings.keyboard.Flags;
public class MouseSettingsController extends InputDeviceSettingsController {
public MouseSettingsController(@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
boolean isFeatureOn = Flags.keyboardAndTouchpadA11yNewPageEnabled();
boolean isPointerCustomizationEnabled =
android.view.flags.Flags.enableVectorCursorA11ySettings();
boolean isMouse = InputPeripheralsSettingsUtils.isMouse();
return (isFeatureOn && isPointerCustomizationEnabled && isMouse) ? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
}
}

View File

@@ -29,9 +29,9 @@ import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
@SearchIndexable
public class TrackpadSettings extends DashboardFragment {
public class TouchpadAndMouseSettings extends DashboardFragment {
private static final String TAG = "TrackpadSettings";
private static final String TAG = TouchpadAndMouseSettings.class.getSimpleName();
@Override
public void onAttach(@NonNull Context context) {
@@ -58,11 +58,11 @@ public class TrackpadSettings extends DashboardFragment {
@Override
protected int getPreferenceScreenResId() {
return R.xml.trackpad_settings;
return R.xml.touchpad_and_mouse_settings;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.trackpad_settings) {
new BaseSearchIndexProvider(R.xml.touchpad_and_mouse_settings) {
@Override
protected boolean isPageSearchEnabled(Context context) {
return FeatureFlagUtils

View File

@@ -20,6 +20,8 @@ import android.content.Context;
import android.hardware.input.InputManager;
import android.util.FeatureFlagUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import com.android.settings.core.BasePreferenceController;
@@ -28,15 +30,16 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
public class TrackpadSettingsController extends BasePreferenceController
public class TouchpadAndMouseSettingsController extends BasePreferenceController
implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop,
InputManager.InputDeviceListener {
private final InputManager mIm;
@Nullable
private Preference mPreference;
public TrackpadSettingsController(Context context, String key) {
public TouchpadAndMouseSettingsController(@NonNull Context context, @NonNull String key) {
super(context, key);
mIm = context.getSystemService(InputManager.class);
}

View File

@@ -0,0 +1,55 @@
/*
* 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.app.settings.SettingsEnums;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.keyboard.Flags;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
@SearchIndexable
public class TouchpadSettingFragment extends DashboardFragment {
private static final String TAG = TouchpadSettingFragment.class.getSimpleName();
@Override
protected int getPreferenceScreenResId() {
return R.xml.touchpad_settings;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public int getMetricsCategory() {
return SettingsEnums.SETTINGS_KEYBOARDS_TOUCHPAD;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.touchpad_settings) {
@Override
protected boolean isPageSearchEnabled(Context context) {
return Flags.keyboardAndTouchpadA11yNewPageEnabled()
&& InputPeripheralsSettingsUtils.isTouchpad();
}
};
}

View File

@@ -0,0 +1,37 @@
/*
* 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 androidx.annotation.NonNull;
import com.android.settings.keyboard.Flags;
public class TouchpadSettingsController extends InputDeviceSettingsController {
public TouchpadSettingsController(@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
boolean isFeatureOn = Flags.keyboardAndTouchpadA11yNewPageEnabled();
boolean isTouchpad = InputPeripheralsSettingsUtils.isTouchpad();
return (isFeatureOn && isTouchpad) ? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
}
}