Fix onboarding background - Canvas: trying to draw too large bitmap #4888
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.
Task/Issue URL: #3914
Description
We were calling
View#setBackground
which is incorrect and inefficient because:android:scaleType="centerCrop"
applies tosrc
of theImageView
, not the background of aView
, which is set inWelcomePage
I could've changed this to
setImageResource
, but we can just setsrc
in xml, and add xml resources forlight
andnight
This should fix the OOM, because setting the background probably set an upscaled version of this bitmap, so even though the large version of the bitmap is about 10MB, this device perhaps thinks it is an
xxhdpi
device and does anx3
making this large bitmap require 100MB. That's probably what we see in the logs anyway. This PR will hopefully scale the bitmap properly so Canvas is not overwhelmed.I've simplified the bitmap resolution by using the resource folders for each bitmap for each combination of
light | dark & < 600dp | > 600dp
. I just deleted the holder drawable files, because the only interesting thing they did was setclampMode
, but that wasn't (intentionally) being used anyway, because the bitmap was usual too big, and if it was going to be used it probably wouldn't look very good depending on which edge is clamped. And there was ascaleMode
set on theImageView
which was unused because nosrc
was applied.I also changed
sceneBg
toImageView
in one override to match the other xml file, so that the binding will not be "downcast" to aView
, but will be accessible asImageView
, which should help devs find theImageView
methods they need, and remove any desire for casting.If anyone doesn't know,
<ImageView>
will be inflated asAppCompatImageView
if inflated in anAppCompatActivity
.Steps to test this PR
Open the app in a low spec tablet.
Observe app does not crash.
UI changes
...and the proper center-cropping kinda looks better too 🎉