Skip to content
This repository was archived by the owner on Nov 14, 2018. It is now read-only.

fix issue #500 View.toBitmap should take scroll state into consideration#504

Merged
romainguy merged 5 commits intoandroid:masterfrom
LanderlYoung:master
Apr 22, 2018
Merged

fix issue #500 View.toBitmap should take scroll state into consideration#504
romainguy merged 5 commits intoandroid:masterfrom
LanderlYoung:master

Conversation

@LanderlYoung
Copy link
Copy Markdown
Contributor

related issue #500

@LanderlYoung
Copy link
Copy Markdown
Contributor Author

GCLOUD_SERVICE_KEY is not set, can't run unit test. Maybe someone could fix that.

#!/bin/bash -eo pipefail
ftl-tests/setup.sh
GCLOUD_SERVICE_KEY env variable is empty. Exiting.
Exited with code 1

In my local environment (Android Studio 3.2 Preview + Emulator), testes passed.

textView.textSize = 10f
textView.setTextColor(Color.BLACK)
textView.text = (0..10).joinToString("\n") {
UUID.randomUUID().toString()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you use something that isn't random? Maybe just it.toString().repeat(20).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, that's ok

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could also speed up the test by just drawing colored rectangles and just doing a couple of getPixel checks. That's all you need to test scrolling.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TextView drawText is reasonably fast. I don't think there is any need to do some optimization.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't care about drawText(), it's the comparison of all the pixel using getPixel(), one by one, that bothers me. Please just make a simpler test and check only a couple of pixels. It's enough.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

already fixed

}
return Bitmap.createBitmap(width, height, config).applyCanvas(::draw)
return Bitmap.createBitmap(width, height, config).applyCanvas {
withSave {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since the canvas isn't re-used we don't need to bother with save/restoring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's true. But with save/restore, we can keep code consistent with normal view draws. ^_^

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That consistency provides no value. You're doing work for no gain. Please remove.

textView.textSize = 10f
textView.setTextColor(Color.BLACK)
textView.text = (0..10).joinToString("\n") {
UUID.randomUUID().toString()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could also speed up the test by just drawing colored rectangles and just doing a couple of getPixel checks. That's all you need to test scrolling.

val height = lhs.height
for (x in 0 until width) {
for (y in 0 until height) {
if (lhs.getPixel(x, y) != rhs.getPixel(x + offX, y + offY)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will be very slow

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, sort of, about 100ms to run toBitmapScrolls test.

BTW, just ask, since this is test code, does it really matters?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes it does. There are many tests to run and if each one takes several 100s of ms, it adds up :) There's absolutely no benefit in checking all the pixels here.

@romainguy romainguy merged commit 3253c2e into android:master Apr 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants