Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87e6c01a authored by Yuhan Yang's avatar Yuhan Yang Committed by Android (Google) Code Review
Browse files

Merge "Add primary key switch preference in mousekeys page" into main

parents 335e546c def9851b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4898,6 +4898,8 @@
    <string name="mouse_keys_seek_bar_increase_button_description">Increase</string>
    <!-- Title for the 'Mouse reverse scrolling' preference switch, which reverses the direction of mouse scroll wheels so that moving the wheel up scrolls the content down. [CHAR LIMIT=60] -->
    <string name="mouse_reverse_vertical_scrolling">Reverse scrolling</string>
    <!-- Title for a toggle switch for 'Use primary keys' under mouse key main page, an accessibility setting that allows the user to use primary keyboard keys to control the cursor instead of using numpad keys. [CHAR LIMIT=35] -->
    <string name="mouse_keys_use_primary_keys_title">Use primary keys</string>
    <!-- Summary text for the 'Mouse reverse scrolling' preference switch indicating to users that when the setting is enabled that scrolling up with their mouse wheel will move the page content down. [CHAR LIMIT=NONE] -->
    <string name="mouse_reverse_vertical_scrolling_summary">Scroll up to move the page down</string>
    <!-- Title for the scrolling section of the mouse settings page. [CHAR LIMIT=60] -->
+6 −0
Original line number Diff line number Diff line
@@ -43,6 +43,12 @@
        android:selectable="false"
        settings:controller="com.android.settings.inputmethod.MouseKeysMaxSpeedController"/>

    <SwitchPreferenceCompat
        android:key="mouse_key_use_primary_key_preference"
        android:title="@string/mouse_keys_use_primary_keys_title"
        android:defaultValue="true"
        settings:controller="com.android.settings.inputmethod.MouseKeysPrimaryKeysController"/>

    <com.android.settingslib.widget.LayoutPreference
        android:key="mouse_keys_list"
        android:layout="@layout/mouse_keys_image_list"/>
+86 −0
Original line number Diff line number Diff line
/*
 * Copyright 2025 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.annotation.Nullable;
import android.content.Context;
import android.net.Uri;
import android.provider.Settings;

import androidx.annotation.NonNull;
import androidx.preference.PreferenceScreen;
import androidx.preference.TwoStatePreference;

/**
 * Controller class that controls primary keys settings for Mouse Keys.
 *
 * When primary key setting is on, the user can use primary keyboard keys instead of numpad keys
 * to control the mouse key.
 */
public class MouseKeysPrimaryKeysController extends
        InputSettingPreferenceController {

    @Nullable
    @SuppressWarnings("unused")
    private TwoStatePreference mTwoStatePreference;

    public MouseKeysPrimaryKeysController(@NonNull Context context,
            @NonNull String key) {
        super(context, key);
    }

    @Override
    public void displayPreference(@NonNull PreferenceScreen screen) {
        super.displayPreference(screen);
        mTwoStatePreference = screen.findPreference(getPreferenceKey());
    }

    @Override
    public boolean isChecked() {
        // TODO(b/393569995): Read primary keys from settings once it's added into
        // Settings.Secure.
        return true;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        // TODO(b/393569995): Update primary keys settings value once it's added into
        // Settings.Secure.
        return true;
    }

    @Override
    protected void onInputSettingUpdated() {
        // TODO(b/393569995): Update preference status based on primary keys settings value
        // once it's added into Settings.Secure.
    }

    @Override
    protected Uri getSettingUri() {
        // TODO(b/393569995): InputSettingPreferenceController requires getSettingUri()
        // implementation so using ACCESSIBILITY_MOUSE_KEYS_ENABLED as a placeholder.
        // Update the uri once primary keys settings are landed.
        return Settings.Secure.getUriFor(
                Settings.Secure.ACCESSIBILITY_MOUSE_KEYS_ENABLED);
    }

    @Override
    public int getAvailabilityStatus() {
        return com.android.server.accessibility.Flags.enableMouseKeyEnhancement()
                ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
    }
}
+67 −0
Original line number Diff line number Diff line
/*
 * Copyright 2025 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 static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;

import androidx.test.core.app.ApplicationProvider;

import com.android.settings.core.BasePreferenceController;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

/** Tests for {@link MouseKeysPrimaryKeysController} */
@RunWith(RobolectricTestRunner.class)
public class MouseKeysPrimaryKeysControllerTest {
    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    private static final String PREFERENCE_KEY = "mouse_key_use_primary_key_preference";

    private Context mContext;
    private MouseKeysPrimaryKeysController mController;

    @Before
    public void setUp() {
        mContext = ApplicationProvider.getApplicationContext();
        mController = new MouseKeysPrimaryKeysController(
                mContext, PREFERENCE_KEY);
    }

    @Test
    @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_MOUSE_KEY_ENHANCEMENT)
    public void getAvailabilityStatus_expected() {
        assertThat(mController.getAvailabilityStatus())
                .isEqualTo(BasePreferenceController.AVAILABLE);
    }

    @Test
    @DisableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_MOUSE_KEY_ENHANCEMENT)
    public void getAvailabilityStatus_flagIsDisabled_notSupport() {
        assertThat(mController.getAvailabilityStatus())
                .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
    }
}