Slide 1

Slide 1 text

Optimizing Your Apps For Emerging Markets #DroidconMtl

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Emerging Markets Drive Growth

Slide 4

Slide 4 text

Source: Mediacells via The Guardian

Slide 5

Slide 5 text

Source: Mediacells via The Guardian

Slide 6

Slide 6 text

44 36 21 51 37 11 80 10 9 25 66 9 Smartphone Feature phone Multimedia phone Brazil Russia India China

Slide 7

Slide 7 text

1. Optimizing App Size

Slide 8

Slide 8 text

The smaller, the better

Slide 9

Slide 9 text

Color Filters

Slide 10

Slide 10 text

Use Color Filter • Faster way to experiment with color schemes. • Reduce the number of assets, which in turn reduc the apk size. • Less memory used as the number of assets are reduced.

Slide 11

Slide 11 text

Code ImageView redCircle = (ImageView) findV iewById(R.id.circle_red_imageview); ImageView greenCircle = (ImageView) findV iewById(R.id.circle_green_imageview); ImageView blueCircle = (ImageView) findV iewById(R.id.circle_blue_imageview); // we can create the color values in different ways: redCircle.getDrawable().setColorFilter(C olor.RED, PorterDuff.M ode.M U LTIPLY ); greenCircle.getDrawable().setColorFilter(0xff00ff00, PorterDuff.M ode.M U LTIPLY ); blueCircle.getDrawable().setColorFilter(getResources().getColor(R.color.blue),PorterDuff.M ode. M U LTIPLY );

Slide 12

Slide 12 text

Image Optimizations Color Filters

Slide 13

Slide 13 text

JPEG WEBP PNG GIF Lossy Lossless Transparenc y Animation WebP

Slide 14

Slide 14 text

No Noticeable Change PNG 24 kb WebP 10 kb

Slide 15

Slide 15 text

Compatibility • You can use the native WebP decoder on 4.2 and later. • For lower versions, use libpng to convert to PNG format and then use it in the app.

Slide 16

Slide 16 text

Other Libraries • Use programs like OptiPNG, TruePNG and PNGC to significantly reduce the size of PNG images. • Use mozjpeg for jpeg images. • 5-10% size reduction • Won’t cause any visible changes to the images.

Slide 17

Slide 17 text

Remove Unused Content Image Optimizations Color Filters

Slide 18

Slide 18 text

Remove Unused Content • Use Resource Shrinking.

Slide 19

Slide 19 text

Code android { ... buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }

Slide 20

Slide 20 text

Remove Unused Content • Use Resource Shrinking. • Use tools like Lint and ProGuard. • Use Android-Unused-Resources jar file if you are still using Eclipse. https://code.google.com/p/android-unused-resources/

Slide 21

Slide 21 text

2. Optimizing Network Calls

Slide 22

Slide 22 text

Expensive Data Flaky Networks Challenges

Slide 23

Slide 23 text

Build for Failure

Slide 24

Slide 24 text

Most efficient way to transfer is to not transfer

Slide 25

Slide 25 text

Image Scaling

Slide 26

Slide 26 text

Appropriate Image Size • Store multiple image sizes on the server • Low-res devices might never need a full resolutio image • Most times the smallest image size is sufficient.

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Checksum Image Scaling

Slide 29

Slide 29 text

Client A Client B Server Checksum ID Send File ID Transfer File CS ID

Slide 30

Slide 30 text

Code public static String getM D5EncryptedString(String encTarget){ M essageDigest mdEnc = null; mdEnc = M essageDigest.getInstance("M D5"); // Encryption algorithm mdEnc.update(encTarget.getBytes(), 0, encTarget.length()); String md5 = new BigInteger(1, mdEnc.digest()).toString(16); while ( md5.length() < 32 ) { md5 = "0"+md5; } return md5; }

Slide 31

Slide 31 text

Checksum • Avoid transfers as much as possible. • For file transfers, first compute the md5 checksum and send it to the server to check if it already exis on the server. • The cost to upload the entire file again can be avoided.

Slide 32

Slide 32 text

Image Scaling Checksum Transfer in Blocks

Slide 33

Slide 33 text

Transfer in blocks • Do data transfers in blocks. • Keep track of the blocks that have been transferre and yet to be transferred. • The block size can vary based on the type of connection.

Slide 34

Slide 34 text

Testing for different networks is a pain

Slide 35

Slide 35 text

Testing for different networks • Facebook recently open-sourced Augmented Traf Control (ATC). • It is a tool to simulate network conditions. • It can simulate 2G, Edge, 3G, and LTE networks. • Has multiple profiles for a lot of different countri http://facebook.github.io/augmented-traffic-control/

Slide 36

Slide 36 text

3. Optimizing for Differen Phones

Slide 37

Slide 37 text

Small Screens Slow Processing Challenges

Slide 38

Slide 38 text

Developing for flagship devices is easy

Slide 39

Slide 39 text

Year Class

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Code int year = Y earC lass.get(getA pplicationContext()); if (year >= 2013) { // Do advanced animation } else if (year > 2010) { // Do simple animation } else { // Phone too slow, don't do any animations } https://github.com/facebook/device-year-class

Slide 42

Slide 42 text

Redesign Year Class

Slide 43

Slide 43 text

Redesign • Remove features from low-end devices if they wo have the best user experience. • This could be animations, videos or even functionalities. • No feature >>> Bad feature

Slide 44

Slide 44 text

@vinaygaba Questions?