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

Commit b5cd2179 authored by Amanda Lin Dietz's avatar Amanda Lin Dietz
Browse files

[Blinking Text Cursor Setting] Add developer setting under Display

* Add a custom TextCursorBlinkRateSliderPreference.
* Add TextCursorBlinkRatePreferenceController to development settings.
* Add strings for preference.
* Add tests for controller and preference.
* Add settings/accessibility OWNERS to
  TextCursorBlinkRatePreferenceController file.

Bug: 402134144
Bug: 385781377
Bug: 416557613
Flag: android.view.accessibility.text_cursor_blink_interval
Test: Manual local testing, TextCursorBlinkRatePreferenceControllerTest,
TextCursorBlinkRateSliderPreferenceTest

Change-Id: I603ad764c173cdf82e6295a83912a75e636f89ef
parent e5277afa
Loading
Loading
Loading
Loading
+109 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 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.
  -->

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:orientation="horizontal"
    android:background="?android:attr/selectableItemBackground"
    android:clipToPadding="false"
    android:baselineAligned="false">

    <include layout="@layout/settingslib_icon_frame"/>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingVertical="@dimen/settingslib_expressive_space_small1">

        <TextView
            android:id="@android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:textAlignment="viewStart"
            android:textAppearance="?android:attr/textAppearanceListItem"
            android:maxLines="2"
            android:ellipsize="marquee"/>

        <TextView
            android:id="@android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@android:id/title"
            android:layout_alignLeft="@android:id/title"
            android:layout_alignStart="@android:id/title"
            android:layout_gravity="start"
            android:textAlignment="viewStart"
            android:textAppearance="?android:attr/textAppearanceListItemSecondary"
            android:textColor="?android:attr/textColorSecondary"
            android:maxLines="10"/>

        <include
            layout="@layout/settingslib_expressive_layout_slider"
            android:id="@+id/slider_frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignStart="@android:id/summary"
            android:layout_below="@android:id/summary" />

        <LinearLayout
            android:id="@+id/label_frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/slider_frame"
            android:orientation="horizontal"
            android:visibility="gone">

            <TextView
                android:id="@android:id/text1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="start|top"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="?android:attr/textColorSecondary"
                android:gravity="start"
                android:layout_weight="1"/>

            <TextView
                android:id="@android:id/text2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="end|top"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="?android:attr/textColorSecondary"
                android:gravity="end"
                android:layout_weight="1"/>
        </LinearLayout>

        <Button
            android:id="@+id/reset_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/slider_frame"
            android:paddingVertical="14dp"
            android:text="@string/accessibility_text_cursor_blink_rate_reset_button_label"
            style="@style/ActionPrimaryButton"/>

    </RelativeLayout>
</LinearLayout>
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
@@ -5843,6 +5843,16 @@
    <string name="accessibility_disable_animations">Remove animations</string>
    <!-- Summary for the accessibility preference for disabling animations. [CHAR LIMIT=60] -->
    <string name="accessibility_disable_animations_summary">Reduce movement on the screen</string>
    <!-- Title for the accessibility preference for the text cursor blink rate. [CHAR LIMIT=35] -->
    <string name="accessibility_text_cursor_blink_rate_title">Text cursor blinking</string>
    <!-- Summary for the accessibility preference for the text cursor blink rate. [CHAR LIMIT=60] -->
    <string name="accessibility_text_cursor_blink_rate_summary">Adjust the text cursor\'s blinking speed or turn off blinking. May not be supported on all apps or websites.</string>
    <!-- Description for the button that decreases the text cursor blink rate. [CHAR_LIMIT=NONE] -->
    <string name="accessibility_text_cursor_blink_rate_slower_desc">Decrease blink speed</string>
    <!-- Description for the button that increases the text cursor blink rate. [CHAR_LIMIT=NONE] -->
    <string name="accessibility_text_cursor_blink_rate_faster_desc">Increase blink speed</string>
    <!-- Label for the button that resets the text cursor blink rate. [CHAR_LIMIT=20] -->
    <string name="accessibility_text_cursor_blink_rate_reset_button_label">Reset</string>
    <!-- Title for the accessibility preference for primary mono. [CHAR LIMIT=35] -->
    <string name="accessibility_toggle_primary_mono_title">Mono audio</string>
    <!-- Summary for the accessibility preference for primary mono. [CHAR LIMIT=60] -->
+5 −0
Original line number Diff line number Diff line
@@ -589,6 +589,11 @@
            android:title="@string/transparent_navigation_bar"
            android:summary="@string/transparent_navigation_bar_summary" />

        <com.android.settings.accessibility.TextCursorBlinkRateSliderPreference
            android:key="accessibility_text_cursor_blink_interval_ms"
            android:title="@string/accessibility_text_cursor_blink_rate_title"
            android:summary="@string/accessibility_text_cursor_blink_rate_summary" />

    </PreferenceCategory>

    <PreferenceCategory
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.accessibility;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceViewHolder;

import com.android.settings.R;
import com.android.settingslib.widget.SliderPreference;

public class TextCursorBlinkRateSliderPreference extends SliderPreference {
    private @Nullable Button mResetButton;
    private @Nullable View.OnClickListener mClickListener;

    public TextCursorBlinkRateSliderPreference(@NonNull Context context,
            @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setTickVisible(true);
        setSliderIncrement(1);
        setIconStart(R.drawable.ic_remove_24dp);
        setIconStartContentDescription(R.string.accessibility_text_cursor_blink_rate_slower_desc);
        setIconEnd(R.drawable.ic_add_24dp);
        setIconEndContentDescription(R.string.accessibility_text_cursor_blink_rate_faster_desc);
        setLayoutResource(R.layout.text_cursor_blink_rate_slider_preference);
    }

    public TextCursorBlinkRateSliderPreference(@NonNull Context context,
            @Nullable AttributeSet attrs) {
        this(context, attrs, 0 /* defStyleAttr */);
    }

    public TextCursorBlinkRateSliderPreference(@NonNull Context context) {
        this(context, null);
    }

    /**
     * Return Button
     */
    public @Nullable Button getButton() {
        return mResetButton;
    }

    /**
     * Set the click listener for the reset button.
     */
    public void setResetClickListener(@NonNull View.OnClickListener clickListener) {
        mClickListener = clickListener;
        if (mResetButton != null) {
            mResetButton.setOnClickListener(clickListener);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);
        mResetButton = (Button) holder.findViewById(R.id.reset_button);
        if (mClickListener != null) {
            setResetClickListener(mClickListener);
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -859,6 +859,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new GrammaticalGenderPreferenceController(context));
        controllers.add(new SensitiveContentProtectionPreferenceController(context));
        controllers.add(new ShadeDisplayAwarenessPreferenceController(context));
        controllers.add(new TextCursorBlinkRatePreferenceController(context));

        return controllers;
    }
Loading