获取 enable/disable 状态和可访问性颜色反转模式

Get enable/disable status and of accessibility Colour inversion mode

在我的应用程序中,当用户启用辅助颜色反转模式时,我需要进行一些 UI 更改。

我们有任何 api 来检查 android 颜色反转模式的 enable/disable 状态吗?

颜色反转不会改变颜色之间的对比度,所以如果你从灰色背景上的白色文本开始,并且你声称深灰色上的反转黑色很难看到,那么它也很难供部分用户查看原文。

也许原文颜色应该是黑色?最终,根据 WCAG criterion 1.4.3 on Contrast, you should have a minimum ratio of 4.5:1. See this post on the UX Stack Exchange for how to compute using black vs. white text.

下面是检查enable/disable可访问性反转模式状态的代码。在某些 phone 中,反转模式将可用为 "Negative colour"。

public boolean isInversionModeEnabled() {
    boolean isInversionEnabled =  false;
    int accessibilityEnabled = 0;
    try {
        accessibilityEnabled = Settings.Secure.getInt(this.getContentResolver(),
                android.provider.Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
    } catch (SettingNotFoundException e) {
        Log.d(TAG, "Error finding setting ACCESSIBILITY_DISPLAY_INVERSION_ENABLED: " + e.getMessage());
        Log.d(TAG, "Checking negative color enabled status");
        final String SEM_HIGH_CONTRAST = "high_contrast";
        accessibilityEnabled = Settings.System.getInt(getContentResolver(), SEM_HIGH_CONTRAST, 0);
    }
    if (accessibilityEnabled == 1) {
        Log.d(TAG, "inversion  or negative colour is enabled");
        isInversionEnabled = true;
    } else {
        Log.d(TAG, "inversion  or negative colour is disabled");
    }
    return isInversionEnabled;

}