Status Update
Comments
ra...@google.com <ra...@google.com>
ra...@google.com <ra...@google.com>
ad...@google.com <ad...@google.com> #2
When you call navController.setGraph(R.navigation.navigation_graph), it stores that ID and will restore that ID automatically.
If you were to instead use:
NavInflater navInflater = new NavInflater(this, navController.getNavigatorProvider());
navController.setGraph(navInflater.inflate(R.navigation.navigation_graph));
Then NavController would not restore the graph itself and the call to restoreState() you point out would only restore the back stack state, etc. but would wait for you to call setGraph again.
You're right that the inconsistency between the two setGraph methods is concerning. We'll take a look.
ro...@google.com <ro...@google.com>
si...@google.com <si...@google.com> #3
za...@attractions.io <za...@attractions.io> #4
za...@attractions.io <za...@attractions.io> #5
Apologies it wasn't from the emulator, it was a Samsung S20 running Android 11.
si...@google.com <si...@google.com> #6
Let me separate a few concerns here:
-
Policy
- canvas.drawText is platform code, and starting from Android 12 should update to the new emoji automatically and if nothing in the string is changed (i.e. replacement spans for supporting custom emoji) it should work.
- The
mentions that "Apps running on Android 12 and above must comply with the latest Unicode version within 4 months of public availability.". Therefore it applies to Android 12 and above.policy - I suspect the drawText function you mentioned does not show new emoji on an older device.
-
Being able to render emoji using EmojiCompat on all android versions
- If the text you pass to drawText is a Spannable that is processed by EmojiCompat and the emoji spans are added, currently canvas.drawText will not be able to draw those since it discards the spans the last time I checked. It might be possible to draw render some spans but there is no support.
- On the current state, StaticLayout is the one that can draw the Span's. Is it (code wise, or performance wise) possible to use a StaticLayout instead of drawText in your use case?
As a side note: It might be possible to create a compat class/code that will draw at least the known some of the known spans (not the spans such as line height etc).
za...@attractions.io <za...@attractions.io> #7
Thank you. I can confirm that on a device running Android 12 the emojis show correctly using canvas.drawText()
. (see android_12_emoji.jpg)
I will look into the methods stated to support the emojis running on older devices.
ja...@gmail.com <ja...@gmail.com> #8
si...@google.com <si...@google.com>
se...@google.com <se...@google.com> #9
Can we add emojicompat support to Canvas.drawText()
.
Short answer: Not directly Longer answer: We would have to do this as a ktx library, which won't allow extensions on Canvas.
How can you draw emoji today on a Canvas
- EmojiCompat.process(str); add emoji spans
- Layout result of #1 using StaticLayout directly
StaticLayout.Builder - Use StaticLayout.draw(canvas)
Layout.draw
StaticLayout is required to draw spans correctly, and it looks like the existing drawText overloads don't use it
Can we add something to EmojiCompat to do the above?
Yes. What sort of API are you interested in?
Thanks,
Sean
za...@attractions.io <za...@attractions.io> #10
Hi Sean,
I have done some testing and the methodology you've described works well. There was an emojis that rendered incorrectly: 👠(screenshots attached of what it should look like) but otherwise it looked good.
I'll need to do some research into this EmojiCompat
library. I used: EmojiCompat.init(BundledEmojiCompatConfig(context))
so maybe this is why the emoji above didn't render properly. I also called val emojiProcessText = EmojiCompat.get().process(iconLabel)
straight after and it kept failing saying that EmojiCompat wasn't initialised so I had to put a Thread.sleep(1000)
in between for testing purposes.
I also note that in the documentation it says this BundledEmojiCompatConfig
is 10MB so will have to research into an alternative method.
I think for now this method would be fine for me, the current difficulty is around the initialisation and setup of EmojiCompat
, which is just spending more time looking at the documentation (time isn't on my side sorry), so an extension to EmojiCompat
wouldn't really help me much versus the method you've described.
Description
With the upcoming Emoji Policy compliance we've updated the version of the
AppCompat
library to support the latest emoji releases as per the documentation.Within a recycler view this upgrade displays ZWJ emojis correctly (see google_bug_1.jpeg). However, in our map view where we use
canvas.drawText()
the ZWJ emojis display as their individual components (see google_bug_2.jpeg).If I use a simple layout file with just a TextView and instead of using
canvas.drawText()
, I draw the layout file to the canvas then it works as expected with the ZWJ emojis (see google_bug_3.png).Can support for ZWJ emojis be added to the
canvas.drawText()
method?