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

Advanced Android Development Tools

Jaydeep
November 16, 2014

Advanced Android Development Tools

This slide deck focuses on productivity of Android developer. It also helps understand some concepts in Android Studio, comparison between Android Studio and Eclipse, Android Studio plugins, Gradle, some useful tips and tools

Jaydeep

November 16, 2014
Tweet

Other Decks in Programming

Transcript

  1. Lets Get Productive At... • IDE • Build System •

    Emulators • Libraries • Tools
  2. Android Studio • Goodness of IntelliJ • Template based wizards

    • IDE Enhancements • Graphical Layout Preview with device art • Built-in VCS and it works!! • IDE themes (Dracula. Awesomeness)
  3. IDE features • String previews • Icons and color previews

    in gutter • Easy strings externalization to strings.xml • @Nullable and @NonNull annotations for easy Null check. • Keymaps and key bindings • Different Project Structures • Design time layout attributes • Record video • High resolution screenshots • Memory monitor
  4. Shortcuts Nirvana • Rename refactor = Shift + F6 •

    Block conditionals = Ctrl + Shift + Enter • Extract to a method = Ctrl + Alt + M • Search a file = Ctrl + Shift + N • Search a class = Ctrl + N • Recently changed files = Ctrl + Shift + E • Goto a symbol = Ctrl + Alt + Shift + N • Group rename = Ctrl + Alt + mouse selection
  5. Layout Editor • Smart suggestions • Keeps code and graphical

    preview in sync • Preview on different screens • Preview with different locales
  6. Eclipse ~ Android Studio • Run configuration ~ Edit configuration

    • Project properties ~ Module settings • Manual file system refresh ~ Auto file system refresh • Java project structure ~ Android project structure • project.properties ~ settings.gradle
  7. Dependency Management dependencies { compile fileTree(dir: ‘libs’, include: [‘*.jar’]) compile

    ‘com.android.support:appcompat-v7:21.0.0’ compile ‘com.squareup.retrofit:retrofit:1.7.0’ }
  8. Build Types buildTypes { release { // your release configuration

    runProgaurd true } debug { // your debug configuration runProgaurd false } }
  9. AAR Format The 'aar' bundle is the binary distribution of

    an Android Library Project ▪ /AndroidManifest.xml (mandatory) ▪ /classes.jar (mandatory) ▪ /res/ (mandatory) ▪ /R.txt (mandatory) ▪ /assets/ (optional) ▪ /libs/*.jar (optional) ▪ /jni/<abi>/*.so (optional) ▪ /proguard.txt (optional) ▪ /lint.jar (optional)
  10. applicationId != package applicationId = Unique identifier for the app

    on device and Google Play package = Place where R class resides
  11. Gradle Summary • Simple Android project • Automate app signing

    • Build variants • Manage dependencies • Automate publishing to Google Play Store
  12. Emulators • High speed (faster than QEMU supported by SDK

    emulator) • Easy to get started with • Based on AndroVM Open Source project • Integrates with Eclipse/Android Studio via plugins • Amazing hardware feature access • Multi-platform
  13. Hardware Features • Camera • GPS • Battery • Speaker

    • Microphone • Rotation • Physical Keyboard • Customizable resolutions
  14. Software Features • API level 20 ready! • OpenGL •

    Virtual Keys • Full Screen(F11) • CLI support • Emulates most widely used devices
  15. Flexibility • Monkey • Robotium • UI Automator • Jenkins

    Can I test apps using these on Genymotion? YES
  16. Retrofit Type safe networking library for Android and Java •

    Exposes REST API as a Java interface • URL parameter replacement and query parameter support • Automatic object conversion to request body(JSON default) • Multi-part requests and file uploads
  17. Url Manipulation @GET("/group/{id}/users") List<User> groupList(@Path("id") long groupId); // request group

    members List<User> list = client.groupList(98748177231); // resultant url // https://api.github.com/group/98748177231/users
  18. Query Parameter @GET("/group/{id}/users") List<User> groupList(@Path("id") int groupId, @Query("sort") String sortValue);

    // request group members List<User> list = client.groupList(98748177231, “lastName”); // resultant url // https://api.github.com/group/98748177231/users?sort=lastName
  19. Multiple Query Parameters // request group members with filters HashMap<String,

    String> params = new HashMap(); params.add(“sort”, “lastName”); params.add(“scope”, “myCompany”); params.add(“bio”, “allowed”); List<User> list = client.groupList(98748177231, params); // resultant url // https://api.github.com/group/98748177231/users? sort=lastName&scope=myCompany&bio=allowed
  20. Synchronous vs Asynchronous Calls // A method with a return

    type will be executed synchronously @GET("/user/{id}/photo") Photo getUserPhoto(@Path("id") int id); // Asynchronous execution requires last parameter to be Callback object @GET("/user/{id}/photo") void getUserPhoto(@Path("id") int id, Callback<Photo> cb);
  21. Raw HTTP Response // For accessing raw HTTP response, specify

    Response class @GET("/users/list") Response userList(); @GET("/users/list") void userList(Callback<Response> cb); @GET("/users/list") Observable<Response> userList();
  22. More Features • Header manipulation • Custom response data converters

    • Custom error handling • Useful logging levels • Both Maven and Gradle dependencies available
  23. Picasso A powerful image loading and caching library for Android

    • Simple API • Handles ImageView recycling and request cancellation in an Adapter • Complex image transformations with minimal memory use • Automatic memory and disc caching
  24. Adapter Downloads @Override public void getView(int position, View convertView, ViewGroup

    parent) { SquaredImageView view = (SquaredImageView) convertView; if (view == null) { view = new SquaredImageView(context); } String url = getItem(position); Picasso.with(context).load(url).into(view); }
  25. Summary • Simple API • Not very customizable • No

    API to enable default configuration • Lower memory footprint • Smaller in size (just around 85KB) • All requests are asynchronous • Allows image transformations
  26. Universal Image Loader A powerful image loading and caching library

    for Android • Customizable API • Provides both sync and async image loading • Provides greater control over loading and caching • Great documentation
  27. Using Callback / / Load image, decode it to Bitmap

    and return Bitmap to callback imageLoader.loadImage(imageUri, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { // Do whatever you want with Bitmap } });
  28. Summary • Highly customizable • Provides API to enable default

    configuration • Moderate memory footprint • Comparatively bulky in size (about 150KB) • Doesn’t allows image transformations
  29. Android Annotations Advanced dependency injection • Inject views • Improves

    code readability • Enhance Activities • Enhance Fragments • Lot more
  30. Sample Usage public class BookmarksToClipboardActivity extends Activity { EditText searchBox;

    Button search; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN); setContentView(R.layout.bookmarks); searchBox = (EditText) findViewById(R.id.search_box); search = (Button) findViewById(R.id.search_btn); search.setOnClickListener(new View.OnClickListener( public void onClick(View view) { // start searching... } )); }
  31. Annotations Awesomeness @NoTitle @Fullscreen @EActivity(R.layout.bookmarks) public class BookmarksToClipboardActivity extends Activity

    { @ViewById(R.id.search_box) EditText searchBox; @ViewById(R.id.search_btn) Button search; @onClick(R.id.search_btn) void onSearchClick() { // start searching... } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } }
  32. Exoplayer Open source library to play audio/video on Android by

    Google • Provides features not currently provided by MediaPlayer class • Supports Dynamic Adapter Streaming over HTTP (DASH) • Smooth streaming • Persistent caching • DRM protected playback(API 18+)
  33. Useful Tools • AndroidArsenal.com • AndroidCustomViews.com • AndroidPttrns.com • Clean

    status bar • App rater • DPI calculator • Postman REST API client
  34. App Rater public class HomeActivity extends Activity { @Override protected

    void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AppRater.app_launched(this); } } • Simple initialization • Enable/disable on version update using setVersionCodeCheckEnabled() • Provides Market interface to implement your own app market url.
  35. Protips public class MembersAdapter extends ArrayAdapter<Member> { ArrayList<Member> mMembers; public

    LogsAdapter(Context context, int textViewResourceId, ArrayList<Member> members) { super(context, textViewResourceId, members); mMembers = members; } public View getView(int position, View convertView, ViewGroup parent) { Member member = mMembers.get(position); // incorrect way Member member = getItem(position); // correct way } }
  36. Protips LayoutInflater mLayoutInflater; @Override public View getView(int position, View convertView,

    ViewGroup parent) { Object object = getItem(position); if (convertView == null) { // incorrect way convertView = mLayoutInflator .inflate(R.layout.title_strip, parent, false); // correct way convertView = LayoutInflater.from(getContext()) .inflate(R.layout.title_strip, parent, false); } }