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

Andorid Bootcamp

Ye Lin Aung
September 28, 2014

Andorid Bootcamp

Slides from Andorid Bootcamp

Ye Lin Aung

September 28, 2014
Tweet

More Decks by Ye Lin Aung

Other Decks in Programming

Transcript

  1. About us Ye Lin Aung - Programmer, Zwenexsys Ye Mon

    Kyaw - Software Engineer, Myanmar Plus Swan Htet Aung - Software Engineer, Nex Labs Poe Poe Myint Swe - Software Engineer, Zwenexsys Thiha Aye Kyaw - Startup Coach, ideabox (made Frozen Keyboard) Zaw Myo Htet - Software Engineer, Frontiir Thura Hlaing - Google Country Consultant for Myanmar Nyan Lynn Htut, Software Engineer, Myanmar Links
  2. - Not to teach to write a specific app -

    Not to teach about all the Android APIs - To teach you to think like a mobile developer - To give the idea of building a basic mobile app Goals
  3. Create new project Android Project Build Resources Manifest Byte code

    Sign Install on Device Gradle Gradle Jar Signer ADB
  4. Frame Layout • Simple Layout • Single View or Stack

    of Views • Views are overlapped • Most recently added child on top
  5. Create ListView • Modify fragment_my.xml • Set ListView with id

    “@+id/listview_forecast” • Change Relative Layout to Frame Layout
  6. Create Fake data • Create ArrayList of Strings for each

    forecast entry String[] forecastArray = { "Today - Sunny - 88/60", "Tomorrow - Foggy - 70/40", "Friday - Cloudy - 72/63", "Saturday - Heavy Rain - 65/56" }; ! List<String> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray));
  7. Initialize Adapter • Create a ArrayAdapter<String> in Placeholder Fragment.java onCreateView(

    ) • Parameters • Context • ID of list item layout • ID of text view • List of data
  8. Context ? • Context has the global information about the

    app environment. • Allows us to access to System services and resources, application service resources as we define.
  9. Promo • Bindez (http://bindez.com) is hiring Android developers! • First

    Myanmar Search Engine. • Drop a mail to [email protected] if you’re interested.
  10. Promo • Frontiir (http://www.frontiir.com) is hiring developers! • To provide

    affordable digital access and useful information services to people and help bridge the global digital divide. • Drop a mail to [email protected] if you’re interested.
  11. • JSON Format • 1 Week of Data • Postal

    code / City Name / Lat, Lng • Metric ( ℃ / ℉ ) OpenWeatherMap.org
  12. Http Request For Weather • Make Http Request • Read

    response from input stream • Clean up and log any errors
  13. Http Request For Weather • Please see the gist at

    http://goo.gl/m5avQj • HttpUrlConnection OR Apache’s HTTP client • Recommends HttpUrlConnection
  14. Logging • Error • Warnings • Info • Debug •

    Verbose Log.e(String tag, String msg) Log.w(String tag, String msg) Log.i(String tag, String msg) Log.d(String tag, String msg) Log.v(String tag, String msg) Tips! Don’t print out everything to log and remember to disable again.
  15. Threads • Android runs on Main Thread (aka UI Thread)

    • Handles all user input and output • Avoid long operations • Background Threads for long running Thread
  16. Create a menu • Create new menu layout forecast_fragment_menu.xml with

    menu item that has ID action_refresh with label Refresh. • Execute AsyncTask on Refresh action.
  17. Permission • Each app is a sandbox • App “A”

    data is inaccessible to app “B” • Each app has to declare the permission required rather than asking user each time.
  18. Permission • Add <uses-permission android:name="android.permission.INTERNET" /> to AndroidManifest.xml • Learn

    more about permission at http://developer.android.com/ reference/android/Manifest.permission.html
  19. Questions & Recap • Making HTTP Request • AsyncTask •

    Menu • Permissions • JSON Parsing • Updating UI
  20. Promo • NexLabs (http://nexlabs.co) is hiring Android developers! • Arguably

    hottest startup in town. • Drop a mail to [email protected] or speak with @swanhtet1992
  21. Promo • Myanmar+ (http://myanmarplus.net) is hiring Android developers! • Design

    focus, fast growing digital agency • Drop a mail to [email protected] if you’re interested.
  22. Let’s save the location • Set a default location with

    • Open a menu • A pop-up dialog with an EditText will be showed. • Change the location and save again by using SharedPreferences
  23. SharedPreferences • Key - value Store • You can save

    any primitive data: • booleans, • floats, • ints, • longs, and • strings.
  24. Create a menu • Create a menu with name id

    action_change_location • Create a string “Change location” and set title for the menu.
  25. Create a dialog with EditText • Copy the gist from

    http://goo.gl/mA6Lo5 • weather_change.xml http://goo.gl/XjIJCd • Set it at the menu item click • Set setPositiveButton and setNegativeButton
  26. Create a SharedPreference • Create a SharedPreference. • Create a

    singleton to get an instance. • Gist is at http://goo.gl/EQic1B
  27. Get/Set data from/to SharedPreferences • Load default value from SharedPreferences

    to EditText • Save the default value to SharedPreferences. • Tips! How do we check if someone entered empty ?
  28. Let’s modify AsyncTask a little bit • Accept location as

    an argument • Two ways to accept • as a constructor parameter • as AsyncTask param • Use UriBuilder to construct the URL • Get the argument, launch the rocket !
  29. Uri Builder • Copy the gist from http://goo.gl/HFimMY • Get

    the location from params[0] • Pass the saved value from SharedPreference when executing the AsyncTask. !
  30. Let’s update the data when app starts • Execute the

    AsyncTask on onStart() • Abstract the common Async operation into a method. • Put the method in onStart() • Remove the dummy data
  31. Share the data • Share Intent • Add a string

    • Create a new menu and use this gist http://goo.gl/ WFQln9 • Add the menu into Detail Fragment
  32. Share the data • Create a ShareIntent. Use this gist.

    http://goo.gl/M9g3TR • You should see a menu on Detail screen.
  33. Customizing the List Row • Split the ArrayAdapter into a

    separate class • Create an object Item with the following attributes. • String text • String image • The gist is at http://goo.gl/bxhV4g
  34. Using External Library with Gradle • Open app/build.gradle • Search

    dependencies or find the link via GitHub • We use two library • Picasso ( http://square.github.io/picasso ) • ButterKnife ( http://jakewharton.github.io/butterknife )
  35. Custom ArrayAdapter • Custom ArrayAdapter with Item type. • Inflate

    own view in getView • The code is at http://goo.gl/UH5LT5
  36. Load images with Picasso • Picasso loads images from a

    given url into a given ImageView Picasso.with(context).load("http://i.imgur.com/ DvpvklR.png").into(imageView);
  37. Using ViewHolder pattern • ListView is tricky • The more

    items you have, the slower your ListView will be • Use AsyncTask • Use ViewHolder pattern • http://developer.android.com/training/improving-layouts/ smooth-scrolling.html
  38. Signing the apk • You need to sign your app

    before upload to Play Store
  39. Signing the apk • Build • Generate signed apk •

    Create key store • Create key store password • Choose a flavor • Tada! ! !
  40. Questions & Recap • Customizing ListView • Using external library

    • Customizing ArrayAdapter • Using ViewHolder pattern • Signing APK