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

Commit cc9641fa authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "feat(high contrast text): make high contrast text API public" into main

parents b75d879f ef60a7c0
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -54956,6 +54956,7 @@ package android.view.accessibility {
    method public boolean addAccessibilityStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener);
    method public void addAccessibilityStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener, @Nullable android.os.Handler);
    method public void addAudioDescriptionRequestedChangeListener(@NonNull java.util.concurrent.Executor, @NonNull android.view.accessibility.AccessibilityManager.AudioDescriptionRequestedChangeListener);
    method @FlaggedApi("com.android.graphics.hwui.flags.high_contrast_text_small_text_rect") public void addHighContrastTextStateChangeListener(@NonNull java.util.concurrent.Executor, @NonNull android.view.accessibility.AccessibilityManager.HighContrastTextStateChangeListener);
    method public boolean addTouchExplorationStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener);
    method public void addTouchExplorationStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener, @Nullable android.os.Handler);
    method @ColorInt public int getAccessibilityFocusColor();
@@ -54968,12 +54969,14 @@ package android.view.accessibility {
    method public static boolean isAccessibilityButtonSupported();
    method public boolean isAudioDescriptionRequested();
    method public boolean isEnabled();
    method @FlaggedApi("com.android.graphics.hwui.flags.high_contrast_text_small_text_rect") public boolean isHighContrastTextEnabled();
    method public boolean isRequestFromAccessibilityTool();
    method public boolean isTouchExplorationEnabled();
    method public void removeAccessibilityRequestPreparer(android.view.accessibility.AccessibilityRequestPreparer);
    method public boolean removeAccessibilityServicesStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener);
    method public boolean removeAccessibilityStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener);
    method public boolean removeAudioDescriptionRequestedChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AudioDescriptionRequestedChangeListener);
    method @FlaggedApi("com.android.graphics.hwui.flags.high_contrast_text_small_text_rect") public void removeHighContrastTextStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.HighContrastTextStateChangeListener);
    method public boolean removeTouchExplorationStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener);
    method public void sendAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
    field public static final int FLAG_CONTENT_CONTROLS = 4; // 0x4
@@ -54993,6 +54996,10 @@ package android.view.accessibility {
    method public void onAudioDescriptionRequestedChanged(boolean);
  }
  @FlaggedApi("com.android.graphics.hwui.flags.high_contrast_text_small_text_rect") public static interface AccessibilityManager.HighContrastTextStateChangeListener {
    method public void onHighContrastTextStateChanged(boolean);
  }
  public static interface AccessibilityManager.TouchExplorationStateChangeListener {
    method public void onTouchExplorationStateChanged(boolean);
  }
+7 −7
Original line number Diff line number Diff line
@@ -238,7 +238,7 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityInteractionClient;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener;
import android.view.accessibility.AccessibilityManager.HighTextContrastChangeListener;
import android.view.accessibility.AccessibilityManager.HighContrastTextStateChangeListener;
import android.view.accessibility.AccessibilityNodeIdManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
@@ -1800,8 +1800,8 @@ public final class ViewRootImpl implements ViewParent,
        }
        mAccessibilityManager.addAccessibilityStateChangeListener(
                mAccessibilityInteractionConnectionManager, mHandler);
        mAccessibilityManager.addHighTextContrastStateChangeListener(
                mHighContrastTextManager, mHandler);
        mAccessibilityManager.addHighContrastTextStateChangeListener(
                mExecutor, mHighContrastTextManager);
        DisplayManagerGlobal
                .getInstance()
                .registerDisplayListener(
@@ -1838,7 +1838,7 @@ public final class ViewRootImpl implements ViewParent,
    private void unregisterListeners() {
        mAccessibilityManager.removeAccessibilityStateChangeListener(
                mAccessibilityInteractionConnectionManager);
        mAccessibilityManager.removeHighTextContrastStateChangeListener(
        mAccessibilityManager.removeHighContrastTextStateChangeListener(
                mHighContrastTextManager);
        DisplayManagerGlobal
                .getInstance()
@@ -11907,12 +11907,12 @@ public final class ViewRootImpl implements ViewParent,
        }
    }
    final class HighContrastTextManager implements HighTextContrastChangeListener {
    final class HighContrastTextManager implements HighContrastTextStateChangeListener {
        HighContrastTextManager() {
            ThreadedRenderer.setHighContrastText(mAccessibilityManager.isHighTextContrastEnabled());
            ThreadedRenderer.setHighContrastText(mAccessibilityManager.isHighContrastTextEnabled());
        }
        @Override
        public void onHighTextContrastStateChanged(boolean enabled) {
        public void onHighContrastTextStateChanged(boolean enabled) {
            ThreadedRenderer.setHighContrastText(enabled);
            destroyAndInvalidate();
+43 −45
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ public final class AccessibilityManager {
    boolean mIsTouchExplorationEnabled;

    @UnsupportedAppUsage(trackingBug = 123768939L)
    boolean mIsHighTextContrastEnabled;
    boolean mIsHighContrastTextEnabled;

    boolean mIsAudioDescriptionByDefaultRequested;

@@ -276,8 +276,8 @@ public final class AccessibilityManager {
    private final ArrayMap<TouchExplorationStateChangeListener, Handler>
            mTouchExplorationStateChangeListeners = new ArrayMap<>();

    private final ArrayMap<HighTextContrastChangeListener, Handler>
            mHighTextContrastStateChangeListeners = new ArrayMap<>();
    private final ArrayMap<HighContrastTextStateChangeListener, Executor>
            mHighContrastTextStateChangeListeners = new ArrayMap<>();

    private final ArrayMap<AccessibilityServicesStateChangeListener, Executor>
            mServicesStateChangeListeners = new ArrayMap<>();
@@ -356,21 +356,20 @@ public final class AccessibilityManager {
    }

    /**
     * Listener for the system high text contrast state. To listen for changes to
     * the high text contrast state on the device, implement this interface and
     * Listener for the system high contrast text state. To listen for changes to
     * the high contrast text state on the device, implement this interface and
     * register it with the system by calling
     * {@link #addHighTextContrastStateChangeListener}.
     *
     * @hide
     * {@link #addHighContrastTextStateChangeListener}.
     */
    public interface HighTextContrastChangeListener {
    @FlaggedApi(com.android.graphics.hwui.flags.Flags.FLAG_HIGH_CONTRAST_TEXT_SMALL_TEXT_RECT)
    public interface HighContrastTextStateChangeListener {

        /**
         * Called when the high text contrast enabled state changes.
         * Called when the high contrast text enabled state changes.
         *
         * @param enabled Whether high text contrast is enabled.
         * @param enabled Whether high contrast text is enabled.
         */
        void onHighTextContrastStateChanged(boolean enabled);
        void onHighContrastTextStateChanged(boolean enabled);
    }

    /**
@@ -655,24 +654,23 @@ public final class AccessibilityManager {
    }

    /**
     * Returns if the high text contrast in the system is enabled.
     * Returns if high contrast text in the system is enabled.
     * <p>
     * <strong>Note:</strong> You need to query this only if you application is
     * doing its own rendering and does not rely on the platform rendering pipeline.
     * </p>
     *
     * @return True if high text contrast is enabled, false otherwise.
     * @return True if high contrast text is enabled, false otherwise.
     *
     * @hide
     */
    @UnsupportedAppUsage
    public boolean isHighTextContrastEnabled() {
    @FlaggedApi(com.android.graphics.hwui.flags.Flags.FLAG_HIGH_CONTRAST_TEXT_SMALL_TEXT_RECT)
    public boolean isHighContrastTextEnabled() {
        synchronized (mLock) {
            IAccessibilityManager service = getServiceLocked();
            if (service == null) {
                return false;
            }
            return mIsHighTextContrastEnabled;
            return mIsHighContrastTextEnabled;
        }
    }

@@ -1303,32 +1301,32 @@ public final class AccessibilityManager {
    }

    /**
     * Registers a {@link HighTextContrastChangeListener} for changes in
     * the global high text contrast state of the system.
     * Registers a {@link HighContrastTextStateChangeListener} for changes in
     * the global high contrast text state of the system.
     *
     * @param listener The listener.
     *
     * @hide
     * @param executor a executor to call the listener from
     * @param listener The listener to be called
     */
    public void addHighTextContrastStateChangeListener(
            @NonNull HighTextContrastChangeListener listener, @Nullable Handler handler) {
    @FlaggedApi(com.android.graphics.hwui.flags.Flags.FLAG_HIGH_CONTRAST_TEXT_SMALL_TEXT_RECT)
    public void addHighContrastTextStateChangeListener(
            @NonNull @CallbackExecutor Executor executor,
            @NonNull HighContrastTextStateChangeListener listener
    ) {
        synchronized (mLock) {
            mHighTextContrastStateChangeListeners
                    .put(listener, (handler == null) ? mHandler : handler);
            mHighContrastTextStateChangeListeners.put(listener, executor);
        }
    }

    /**
     * Unregisters a {@link HighTextContrastChangeListener}.
     * Unregisters a {@link HighContrastTextStateChangeListener}.
     *
     * @param listener The listener.
     *
     * @hide
     */
    public void removeHighTextContrastStateChangeListener(
            @NonNull HighTextContrastChangeListener listener) {
    @FlaggedApi(com.android.graphics.hwui.flags.Flags.FLAG_HIGH_CONTRAST_TEXT_SMALL_TEXT_RECT)
    public void removeHighContrastTextStateChangeListener(
            @NonNull HighContrastTextStateChangeListener listener) {
        synchronized (mLock) {
            mHighTextContrastStateChangeListeners.remove(listener);
            mHighContrastTextStateChangeListeners.remove(listener);
        }
    }

@@ -1505,13 +1503,13 @@ public final class AccessibilityManager {

        final boolean wasEnabled = isEnabled();
        final boolean wasTouchExplorationEnabled = mIsTouchExplorationEnabled;
        final boolean wasHighTextContrastEnabled = mIsHighTextContrastEnabled;
        final boolean wasHighTextContrastEnabled = mIsHighContrastTextEnabled;
        final boolean wasAudioDescriptionByDefaultRequested = mIsAudioDescriptionByDefaultRequested;

        // Ensure listeners get current state from isZzzEnabled() calls.
        mIsEnabled = enabled;
        mIsTouchExplorationEnabled = touchExplorationEnabled;
        mIsHighTextContrastEnabled = highTextContrastEnabled;
        mIsHighContrastTextEnabled = highTextContrastEnabled;
        mIsAudioDescriptionByDefaultRequested = audioDescriptionEnabled;

        if (wasEnabled != isEnabled()) {
@@ -1523,7 +1521,7 @@ public final class AccessibilityManager {
        }

        if (wasHighTextContrastEnabled != highTextContrastEnabled) {
            notifyHighTextContrastStateChanged();
            notifyHighContrastTextStateChanged();
        }

        if (wasAudioDescriptionByDefaultRequested
@@ -2397,24 +2395,24 @@ public final class AccessibilityManager {
    }

    /**
     * Notifies the registered {@link HighTextContrastChangeListener}s.
     * Notifies the registered {@link HighContrastTextStateChangeListener}s.
     */
    private void notifyHighTextContrastStateChanged() {
    private void notifyHighContrastTextStateChanged() {
        final boolean isHighTextContrastEnabled;
        final ArrayMap<HighTextContrastChangeListener, Handler> listeners;
        final ArrayMap<HighContrastTextStateChangeListener, Executor> listeners;
        synchronized (mLock) {
            if (mHighTextContrastStateChangeListeners.isEmpty()) {
            if (mHighContrastTextStateChangeListeners.isEmpty()) {
                return;
            }
            isHighTextContrastEnabled = mIsHighTextContrastEnabled;
            listeners = new ArrayMap<>(mHighTextContrastStateChangeListeners);
            isHighTextContrastEnabled = mIsHighContrastTextEnabled;
            listeners = new ArrayMap<>(mHighContrastTextStateChangeListeners);
        }

        final int numListeners = listeners.size();
        for (int i = 0; i < numListeners; i++) {
            final HighTextContrastChangeListener listener = listeners.keyAt(i);
            listeners.valueAt(i).post(() ->
                    listener.onHighTextContrastStateChanged(isHighTextContrastEnabled));
            final HighContrastTextStateChangeListener listener = listeners.keyAt(i);
            listeners.valueAt(i).execute(() ->
                    listener.onHighContrastTextStateChanged(isHighTextContrastEnabled));
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ public class Canvas extends BaseCanvas {
    /**
     * Indicates whether this Canvas is drawing high contrast text.
     *
     * @see android.view.accessibility.AccessibilityManager#isHighTextContrastEnabled()
     * @see android.view.accessibility.AccessibilityManager#isHighContrastTextEnabled()
     * @return True if high contrast text is enabled, false otherwise.
     *
     * @hide