Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Droidcon Montreal 2015: Optimizing Your Apps For Emerging Markets

Droidcon Montreal 2015: Optimizing Your Apps For Emerging Markets

Talk that I gave at Droidcon Montreal 2015 about ways in which you can optimize your apps for markets which are driving the growth of smartphones.

vinaygaba

May 15, 2015
Tweet

More Decks by vinaygaba

Other Decks in Technology

Transcript

  1. Optimizing Your Apps
    For Emerging Markets
    #DroidconMtl

    View Slide

  2. View Slide

  3. Emerging Markets
    Drive Growth

    View Slide

  4. Source: Mediacells via The Guardian

    View Slide

  5. Source: Mediacells via The Guardian

    View Slide

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

    View Slide

  7. 1. Optimizing App Size

    View Slide

  8. The smaller, the better

    View Slide

  9. Color Filters

    View Slide

  10. 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.

    View Slide

  11. 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 );

    View Slide

  12. Image
    Optimizations
    Color Filters

    View Slide

  13. JPEG WEBP PNG GIF
    Lossy
    Lossless
    Transparenc
    y
    Animation
    WebP

    View Slide

  14. No Noticeable Change
    PNG
    24 kb
    WebP
    10 kb

    View Slide

  15. 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.

    View Slide

  16. 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.

    View Slide

  17. Remove
    Unused
    Content
    Image
    Optimizations
    Color Filters

    View Slide

  18. Remove Unused Content
    • Use Resource Shrinking.

    View Slide

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

    View Slide

  20. 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/

    View Slide

  21. 2. Optimizing Network
    Calls

    View Slide

  22. Expensive
    Data
    Flaky
    Networks
    Challenges

    View Slide

  23. Build for Failure

    View Slide

  24. Most efficient way to
    transfer is to not transfer

    View Slide

  25. Image Scaling

    View Slide

  26. 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.

    View Slide

  27. View Slide

  28. Checksum
    Image Scaling

    View Slide

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

    View Slide

  30. 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;
    }

    View Slide

  31. 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.

    View Slide

  32. Image Scaling Checksum
    Transfer in
    Blocks

    View Slide

  33. 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.

    View Slide

  34. Testing for different
    networks is a pain

    View Slide

  35. 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/

    View Slide

  36. 3. Optimizing for Differen
    Phones

    View Slide

  37. Small Screens
    Slow
    Processing
    Challenges

    View Slide

  38. Developing for flagship
    devices is easy

    View Slide

  39. Year Class

    View Slide

  40. View Slide

  41. 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

    View Slide

  42. Redesign
    Year Class

    View Slide

  43. 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

    View Slide

  44. @vinaygaba
    Questions?

    View Slide