Use our themes to fix the default tintMode to SRC_IN. #2902
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
As of https://github.com/opendatakit/collect/tree/db01cdcf, all disabled image buttons appear the same as enabled image buttons.
This appearance change occurred when
colors.xml
was edited in b41b817#diff-1f517f1a91abad16231a83752cef21a4 to change the icon colors for disabled buttons (lightIconColorDisabled
anddarkIconColorDisabled
) from solid grey#aaaaaa
to partial-opacity-black#61000000
or partial-opacity-white#61ffffff
.The actual cause is that Android uses an incorrect default blending mode for image colour tints.
The blending mode should be
SRC_IN
, which is the default blending mode everywhere else in Android. However,ImageView
uses the default modeSRC_ATOP
, which ignores the alpha channel when drawing the icon image.To fix this problem across our entire app, this PR sets the
android:tintMode
attribute tosrc_in
in our two themes, light and dark.What has been done to verify that this works as intended?
I built the app at
db01cdcf
and ran it in an emulator running Android 6.0, and confirmed that the problem existed (disabled buttons appear black in GeoTrace and GeoShape).I then built the app with this change and ran it in an emulator running Android 6.0, and confirmed that disabled buttons now appear grey, and they change between grey and black as they should when enabled and disabled. I also tested the dark theme, and the buttons were grey when disabled and white when enabled, as expected.
The tint mode functionality was introduced in Android 5.0, so I also tested the app both with and without this change in an emulator running Android 4.1.1 (API 16, the lowest level we support). Instead of turning grey, the disabled buttons become semitransparent when disabled, and that remains the case both with and without this change. Only the square background of the button becomes semitransparent; the icon remains solid black or solid white. This was also the case in version 1.19.0, before any alpha values were specified in
colors.xml
.Why is this the best possible solution? Were any other approaches considered?
I considered the following possible alternative approaches:
android:tintMode="src_in"
attributes to all<AppCompatButton>
tags in our layout XML files. There are 24 occurrences across 5 files.AppCompatButton
with a subclass that callssetImageTintMode(SRC_IN)
upon initialization, and use the subclass everywhere instead ofAppCompatButton
.AppCompatButton
with a subclass that overridessetEnabled
to callsetImageAlpha
with a hardcoded alpha value, and use the subclass everywhere instead ofAppCompatButton
.All three of these options involve touching every XML file that uses an image button, and wouldn't solve the problem for future image buttons (though, for Options 2 and 3, we could establish a convention that we always use our subclass instead of AppCompatButton, and even enforce that convention with a lint check).
Options 1 and 2 would have the same visible effect as this PR: buttons turn grey in Android 5.0 and higher, buttons turn semitransparent in Android 4.x.
Option 3 is the only solution I can think of that would actually turn the icon itself grey in all versions of Android. However, it is also by far the most expensive change, and we've lived with semitransparent non-grey buttons in Android 4.x so far, so it doesn't seem worth it.
Editing the theme, as this PR does, is the cheapest option that gets us back to the button appearance that we had in v1.19.0.
How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
This is a bug fix. Users shouldn't notice any changes.
Do we need any specific form for testing your changes? If so, please attach one.
You can use the Geo map widgets in the "All Widgets" form to see some enabled and disabled image buttons.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
No.
Before submitting this PR, please make sure you have:
./gradlew checkAll
and confirmed all checks still pass OR confirm CircleCI build passes and run./gradlew connectedDebugAndroidTest
locally.