Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Enable isInvertColorsEnabled property to AccessibilityInfo component #31070

Closed
wants to merge 1 commit into from

Conversation

MSzalowski
Copy link

Summary

This PR enables isInvertColorsEnabled() of AccessibilityInfo for Android.

That setting is queried using the Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED property.
https://developer.android.com/reference/android/provider/Settings.Secure#ACCESSIBILITY_DISPLAY_INVERSION_ENABLED

Changelog

[Android] [Added] - isInvertColorsEnabled() of AccessibilityInfo

Test Plan

Enable and disable color inversion setting in device/emulator accessibility settings and check if property getter updates with a new value.

@facebook-github-bot
Copy link
Contributor

Hi @MSzalowski!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code analysis results:

@@ -11,6 +11,7 @@
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.provider.Settings.Secure;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-java-format suggested changes:

@@ -14 +13,0 @@
-import android.provider.Settings.Secure;

@@ -95,6 +99,14 @@ private boolean getIsReduceMotionEnabledValue() {
return value != null && value.equals("0.0");
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-java-format suggested changes:

@@ -105 +104,2 @@
-      Settings.Secure.getString(mContentResolver, Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
+        Settings.Secure.getString(
+            mContentResolver, Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);

boolean isInvertColorsEnabled = this.getIsInvertColorsEnabled();

if (mInvertColorsEnabled != isInvertColorsEnabled) {
mInvertColorsEnabled = isInvertColorsEnabled;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-java-format suggested changes:

@@ -162,2 +162,2 @@
-          .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
-          .emit(INVERT_COLORS_EVENT_NAME, mInvertColorsEnabled);
+            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
+            .emit(INVERT_COLORS_EVENT_NAME, mInvertColorsEnabled);

ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
if (reactApplicationContext != null) {
reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-java-format suggested changes:

@@ -167 +166,0 @@
-

@analysis-bot
Copy link

analysis-bot commented Feb 28, 2021

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 866bf5f

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 28, 2021
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@analysis-bot
Copy link

analysis-bot commented Feb 28, 2021

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,903,532 -370,759
android hermes armeabi-v7a 8,395,536 -395,369
android hermes x86 9,392,110 -343,373
android hermes x86_64 9,334,535 -367,154
android jsc arm64-v8a 10,354,247 -527,640
android jsc armeabi-v7a 9,829,344 -562,183
android jsc x86 10,404,324 -505,478
android jsc x86_64 10,987,010 -530,904

Base commit: 118489f

Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code analysis results:

@@ -95,6 +98,14 @@ private boolean getIsReduceMotionEnabledValue() {
return value != null && value.equals("0.0");
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-java-format suggested changes:

@@ -103,2 +103,3 @@
-    String value = Settings.Secure.getString(
-      mContentResolver, Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
+    String value =
+        Settings.Secure.getString(
+            mContentResolver, Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);


if (mInvertColorsEnabled != isInvertColorsEnabled) {
mInvertColorsEnabled = isInvertColorsEnabled;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-java-format suggested changes:

@@ -161,2 +162,2 @@
-          .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
-          .emit(INVERT_COLORS_EVENT_NAME, mInvertColorsEnabled);
+            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
+            .emit(INVERT_COLORS_EVENT_NAME, mInvertColorsEnabled);

@kacieb
Copy link
Contributor

kacieb commented Mar 16, 2021

Hey! Thanks so much for working on this, this is great! I'm going to tag in @blavalla to check the Android code.

Please also fix the lint related changes when you can, since we'll need those fixed to merge!

@kacieb kacieb requested a review from blavalla March 16, 2021 20:04
Copy link
Contributor

@blavalla blavalla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Android code looks good to me. Just be sure to follow the spacing that the bot suggested to keep things consistent.

Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code analysis results:

@@ -95,6 +98,15 @@ private boolean getIsReduceMotionEnabledValue() {
return value != null && value.equals("0.0");
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-java-format suggested changes:

@@ -103 +103 @@
-    String value = 
+    String value =

@facebook-github-bot
Copy link
Contributor

@kacieb has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@blavalla blavalla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay here, I didn't realize there was a gap here at first!

Let me know if you have any questions for how to implement this. The approach taken by reduce motion should be exactly what you need to follow here.

@MSzalowski
Copy link
Author

Sorry, for the really late update. I don't want to make excuses, but I've had a really busy last few months and haven't had a moment to look here.

@blavalla
I have made the suggested changes. Could you take a look to see if it is ok now?

@@ -58,6 +58,7 @@ public void onChange(boolean selfChange) {
public void onChange(boolean selfChange, Uri uri) {
if (getReactApplicationContext().hasActiveCatalystInstance()) {
AccessibilityInfoModule.this.updateAndSendReduceMotionChangeEvent();
AccessibilityInfoModule.this.updateAndSendInvertColorsChangeEvent();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't going to work as part of the same observer.

The way these observers work is that the URI passed into them is a reference to the specific setting changed, and this one is being trigged on Settings.Global.getUriFor(Settings.Global.TRANSITION_ANIMATION_SCALE); (line 175 of this file), which is the URI for the animation_scale setting, not the display inversion setting.

You'll instead either need to make a second ContentObserver, or use the same observer as you have done, but add a check for the URI in the onChange method and only fire the update method associated with the URI that has triggered it. Whichever approach you opt for you'll also still need to call registerContentObserver with your new URI on line 176 like this:

mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED), false, YOUR_CONTENT_RESOLVER_HERE);

Let me know if any of this needs any clarification!

@blavalla
Copy link
Contributor

Sorry, for the really late update. I don't want to make excuses, but I've had a really busy last few months and haven't had a moment to look here.

@blavalla
I have made the suggested changes. Could you take a look to see if it is ok now?

No problem on the timing, whenever you have time to work on this, it's appreciated!

I've commented with one change above. Let me know if anything needs any clarification!

@MSzalowski
Copy link
Author

Everything is clear. Thank you for the detailed information. I'll work on this today

Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code analysis results:

}
}
}

@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void onHostResume() {
mAccessibilityManager.addTouchExplorationStateChangeListener(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-java-format suggested changes:

@@ -191 +191,2 @@
-    Uri invertColorsUri = Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
+    Uri invertColorsUri =
+        Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);

}
}
}

@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void onHostResume() {
mAccessibilityManager.addTouchExplorationStateChangeListener(
mTouchExplorationStateChangeListener);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-java-format suggested changes:

@@ -193 +194,2 @@
-    mContentResolver.registerContentObserver(invertColorsUri, false, accessibilityDisplayInversionObserver);
+    mContentResolver.registerContentObserver(
+        invertColorsUri, false, accessibilityDisplayInversionObserver);

Copy link
Contributor

@blavalla blavalla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes, this looks great!

@facebook-github-bot
Copy link
Contributor

@kacieb has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot react-native-bot added Platform: Android Android applications. Type: Enhancement A new feature or enhancement of an existing feature. labels Oct 1, 2021
@XantreDev
Copy link
Contributor

What about this PR. It's seems to be approved but for some reason not merged
@kacieb Can it be approved?
Or there should be some fixes? If so I can help with it)

@MSzalowski
Copy link
Author

After years - I've run google java format on requested files 😅

@github-actions
Copy link

Fails
🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L13 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 13 – Use relative paths when importing within 'react-native' (lint/no-react-native-imports)

🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L49 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 49 – Insert · (prettier/prettier)

🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L56 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 56 – Insert · (prettier/prettier)

🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L60 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 60 – Insert · (prettier/prettier)

🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L70 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 70 – Insert · (prettier/prettier)

🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L83 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 83 – Insert · (prettier/prettier)

🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L87 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 87 – Insert · (prettier/prettier)

🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L110 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 110 – Insert · (prettier/prettier)

🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L144 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 144 – Insert · (prettier/prettier)

🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L163 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 163 – Insert · (prettier/prettier)

🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L170 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 170 – Insert · (prettier/prettier)

🚫

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L183 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 183 – Insert · (prettier/prettier)

Warnings
⚠️

Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js#L11 - Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js line 11 – Requires should be sorted alphabetically (lint/sort-imports)

⚠️

Libraries/Components/AccessibilityInfo/NativeAccessibilityInfo.js#L11 - Libraries/Components/AccessibilityInfo/NativeAccessibilityInfo.js line 11 – Requires should be sorted alphabetically (lint/sort-imports)

Generated by 🚫 dangerJS against 3d0342f

@pull-bot
Copy link

Fails
🚫

❗ Base Branch - The base branch for this PR is something other than master. Are you sure you want to target something other than the master branch?

Generated by 🚫 dangerJS against 3d0342f

@MSzalowski MSzalowski closed this Dec 28, 2022
@MSzalowski MSzalowski deleted the master branch December 28, 2022 07:47
@MSzalowski
Copy link
Author

Due to the conflicts and number of version that were released since I've sent my pr for the first time - I've closed the pr and I'll submit a new one from more recent main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accessibility CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Platform: Android Android applications. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android: Color inversion
9 participants