Slide 1

Slide 1 text

@NYTDevs | developers.nytimes.com

Slide 2

Slide 2 text

@NYTDevs | developers.nytimes.com How can we reduce Bitmap footprints? ● Bitmap.Config ● ARGB_8888 - 4 bytes total per pixel ● RGB_565 - 2 bytes total per pixel

Slide 3

Slide 3 text

@NYTDevs | developers.nytimes.com Let’s do the Math For a 1080 width by 720 height image: ● ARGB_8888 = 1080 * 720 * 32 / 8 = ~3.1MB ● RGB_565 = 1080 * 720 * 16 / 8 = ~1.5Mb

Slide 4

Slide 4 text

@NYTDevs | developers.nytimes.com Requirements ● Images need to be scaled to width of device ● Can’t be stretched or cropped ● Picasso Transformation method (no preprocessing or image service)

Slide 5

Slide 5 text

@NYTDevs | developers.nytimes.com Picasso Transformation Picasso interface for declaring custom image transformations. @Override public Bitmap transform(Bitmap Source) @Override public String key()

Slide 6

Slide 6 text

@NYTDevs | developers.nytimes.com Picasso Configuration Picasso.with(context) .load(urlString) .config(Bitmap.Config.RGB_565) ….. Fingers crossed……...

Slide 7

Slide 7 text

@NYTDevs | developers.nytimes.com No dice! Let’s dig ● github.com/square/picasso/issues/390 ● “In most cases, inPreferredConfig is ignored and ARGB_8888 is used.”

Slide 8

Slide 8 text

@NYTDevs | developers.nytimes.com Now What…….. In our transform class: Bitmap result = Bitmap.createScaledBitmap (source, targetWidth, targetHeight, false);

Slide 9

Slide 9 text

@NYTDevs | developers.nytimes.com Bitmap.createScaledBitmap() looks at the provided source bitmap to determine the bitmap configuration. ● createScaledBitmap() → creates matrix and scale value ● createBitmap() → sanity check, boilerplate dimension calculations, and config resolution.

Slide 10

Slide 10 text

@NYTDevs | developers.nytimes.com Nothing Crazy...Let’s rip it out! public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter, Bitmap.Config newConfig) public static Bitmap createBitmap(Bitmap source, int x_coordinate, int y_coordinate, int width, int height, Matrix matrix, boolean filter, Bitmap. Config newConfig)

Slide 11

Slide 11 text

@NYTDevs | developers.nytimes.com

Slide 12

Slide 12 text

@NYTDevs | developers.nytimes.com Problems with Blue

Slide 13

Slide 13 text

@NYTDevs | developers.nytimes.com Conclusion ● Use it where it makes sense ● Small thumbnails or places where quality can be sacrificed github.com/brianPlummer/Rgb565Example bit.ly/1K7VV3j

Slide 14

Slide 14 text

@NYTDevs | developers.nytimes.com Dumpsys gfxinfo ● Correct way to get rendering information ● Great data but not formatted for consumption. It needs massaging. ● Who’s got time for that?

Slide 15

Slide 15 text

@NYTDevs | developers.nytimes.com Cookie-Butter

Slide 16

Slide 16 text

@NYTDevs | developers.nytimes.com Where and how? ● github.com/Turnsole/cookie-butter bit. ly/1MaXIYB python generate_frametime_graphs.py [-h] package [seconds] [title] [device] python generate_frametime_graphs.py com.nytimes.android.debug 20 20_sec_af_04 HT4CJJT01102

Slide 17

Slide 17 text

@NYTDevs | developers.nytimes.com Percent Support Library ● There is currently no good way to specify view sizes as percentages of viewport. ● Layout weights are clumsy and are only available in FrameLayout and LinearLayout

Slide 18

Slide 18 text

@NYTDevs | developers.nytimes.com compile 'com.android.support:percent:22.2.0' ● Android SDK v22 ● Android Build Tools v22.0.1 ● Android Percent Support Repository v22.2.0 ● Android Support v4 Repository v22.2.0 Requirements

Slide 19

Slide 19 text

@NYTDevs | developers.nytimes.com What do you get? Percent implementations of RelativeLayout, FrameLayout, and LinearLayout heightPercent, widthPercent, marginBottomPercent, marginEndPercent, marginLeftPercent, marginPercent, marginRightPercent, marginStartPercent, marginTopPercent

Slide 20

Slide 20 text

@NYTDevs | developers.nytimes.com

Slide 21

Slide 21 text

@NYTDevs | developers.nytimes.com

Slide 22

Slide 22 text

@NYTDevs | developers.nytimes.com Where to get it? ● github.com/JulienGenoud/android-percent- support-lib-sample (bit.ly/1HvoQx9) ● juliengenoud.github.io/android-percent- support-lib-sample/ (bit.ly/1M6lST5)

Slide 23

Slide 23 text

We’re hiring nytimes.com/careers @NYTDevs | developers.nytimes.com