Download - Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Transcript
Page 1: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Optimizing Your Apps For Emerging Markets

#DroidconMtl

Page 2: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

+VinayGaba@vinaygaba

Page 3: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Emerging MarketsDrive Growth

Page 4: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Source: Mediacells via The Guardian

Page 5: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Source: Mediacells via The Guardian

Page 6: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

44

36

21

5137

11

80

109

25

66

9

Smartphone Feature phone Multimedia phone

Brazil Russia

India China

Page 7: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

1. Optimizing App Size

Page 8: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

The smaller, the better

Page 9: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Color Filters

Page 10: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Use Color Filter

• Faster way to experiment with color schemes.• Reduce the number of assets, which in turn reduces

the apk size.• Less memory used as the number of assets are

reduced.

Page 11: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Code

ImageView redCircle = (ImageView) findViewById(R.id.circle_red_imageview); ImageView greenCircle = (ImageView) findViewById(R.id.circle_green_imageview); ImageView blueCircle = (ImageView) findViewById(R.id.circle_blue_imageview); // we can create the color values in different ways: redCircle.getDrawable().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY ); greenCircle.getDrawable().setColorFilter(0xff00ff00, PorterDuff.Mode.MULTIPLY ); blueCircle.getDrawable().setColorFilter(getResources().getColor(R.color.blue),PorterDuff.Mode.MULTIPLY );

Page 12: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Image Optimizatio

nsColor Filters

Page 13: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

JPEG WEBP PNG GIF

Lossy

Lossless

Transparency

Animation

WebP

Page 14: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

No Noticeable Change

PNG24 kb

WebP10 kb

Page 15: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

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.

Page 16: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Other Libraries

• Use programs like OptiPNG, TruePNG and PNGCrushto 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.

Page 17: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Remove Unused Content

Image Optimizatio

nsColor Filters

Page 18: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Remove Unused Content

• Use Resource Shrinking.

Page 19: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Code

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

Page 20: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

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/

Page 21: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

2. Optimizing NetworkCalls

Page 22: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Expensive Data

Flaky Networks

Challenges

Page 23: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Build for Failure

Page 24: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Most efficient way to transfer is to not transfer

Page 25: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Image Scaling

Page 26: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Appropriate Image Size

• Store multiple image sizes on the server• Low-res devices might never need a full resolution

image• Most times the smallest image size is sufficient.

Page 27: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015
Page 28: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

ChecksumImage Scaling

Page 29: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Client A Client BServer

Checksum

ID

Send File ID

Transfer File

CS ID

Page 30: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Code

public static String getMD5EncryptedString(String encTarget){ MessageDigest mdEnc = null; mdEnc = MessageDigest.getInstance("MD5"); // 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; }

Page 31: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

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 existson the server. • The cost to upload the entire file again can be

avoided.

Page 32: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Image Scaling Checksum Transfer in

Blocks

Page 33: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Transfer in blocks

• Do data transfers in blocks.• Keep track of the blocks that have been transferred

and yet to be transferred.• The block size can vary based on the type of

connection.

Page 34: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Testing for different networks is a pain

Page 35: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Testing for different networks

• Facebook recently open-sourced Augmented Traffic 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 countries.

http://facebook.github.io/augmented-traffic-control/

Page 36: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

3. Optimizing for DifferentPhones

Page 37: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Small Screens

Slow Processing

Challenges

Page 38: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Developing for flagshipdevices is easy

Page 39: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Year Class

Page 40: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015
Page 41: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Code

int year = YearClass.get(getApplicationContext()); 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

Page 42: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

RedesignYear Class

Page 43: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

Redesign

• Remove features from low-end devices if they won’thave the best user experience.• This could be animations, videos or even

functionalities.• No feature >>> Bad feature

Page 44: Optimizing Your Apps For Emerging Markets - Droidcon Montreal 2015

@vinaygaba

Questions?