Android Developer Toolbox 2017

  • View
    218

  • Download
    0

Embed Size (px)

Text of Android Developer Toolbox 2017

  1. 1. ANDROID DEVELOPER TOOLBOX
  2. 2. Shem Magnezi @shemag8 shem8.github.com
  3. 3. New Developers
  4. 4. Libraries Resources Tools
  5. 5. Libraries
  6. 6. Why?
  7. 7. Outsource your problems
  8. 8. Help the community
  9. 9. Why not?
  10. 10. Legal issues
  11. 11. Old / Buggy code
  12. 12. App size
  13. 13. Dont outsource your core logic
  14. 14. Basics
  15. 15. Support Library Provide backward compatible versions of Android framework APIs - ActivityCompat - FragmentActivity - ContextCompat - IntentCompat - Loader - RecyclerView - ViewPager - GridLayout - PercentFrameLayout - DrawerLayout - SwipeRefreshLayout - CardView - AppCompatDialogFragment - CoordinatorLayout - AppBarLayout - FloatingActionButton - TabLayout - Snackbar - VectorDrawableCompat ...developer.android.com/topic/libraries/s upport-library
  16. 16. Google Play Services take advantage of the latest, Google- powered features with automatic platform updates distributed as an APK through the Google Play store. - Google+ - Google Account - Google Action - Google Sign - Google Analytics - Google Awareness - Google Cast - Google Cloud - Google Drive - Google Fit - Google Location - Google Maps - Google Places - Mobile Vision - Google Nearby - Google Panorama - Google Play - Android Pay - Android Wear ...developer.android.com/topic/libraries/s upport-library
  17. 17. Network
  18. 18. Moshi A modern JSON library for Android and Java. MyObj item = new MyObj(...); Moshi moshi = new Moshi.Builder().build(); JsonAdapter adapter = moshi.adapter(MyObj.class); adapter.toJson(item); adapter.fromJson(jsonStr); github.com/square/moshi
  19. 19. OkHttp3 An HTTP & SPDY client for Android and Java applications OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(url) .build(); Response response = client.newCall(request) .execute(); return response.body().string(); square.github.io/okhttp
  20. 20. Retrofit A type-safe HTTP client for Android and Java public interface GitHub { @GET("users/{user}/repos") Call repos( @Path("user") String user); } Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.github.com") .build(); GitHub service = retrofit.create(GitHub.class); Call repos = service.repos("octocat"); square.github.io/retrofit
  21. 21. Persistency
  22. 22. Room Abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite. @Entity public class User { @PrimaryKey private int uid; @ColumnInfo(name = "first_name") private String firstName; } @Dao public interface UserDao { @Insert Void insertAll(User users); @Query("SELECT * FROM user WHERE uid IN (:userIds)") List loadAllByIds( int[] userIds); } developer.android.com/training/data- storage/room/index.html
  23. 23. Object Box The easy object- oriented database for small devices BoxStore boxStore = MyObjectBox.builder() .androidContext(...) .build(); Box box = boxStore.boxFor(Person.class); Person person = new Person("Joe", "Green"); // Create long id = box.put(person); // Read Person person = box.get(id); // Update person.setLastName("Black"); box.put(person); // Delete box.remove(person); github.com/objectbox/objectbox-java
  24. 24. Room Object Box Support Speed
  25. 25. Realm A mobile database that runs directly inside phones, tablets or wearables github.com/realm/realm-java class Dog extends RealmObject { private String name; } Realm realm = Realm.getDefaultInstance(); Dog dog = new Dog(); dog.setName("Rex"); realm.beginTransaction(); realm.copyToRealm(dog); realm.commitTransaction(); Dog dog = realm.where(Dog.class) .equalTo("name", "Rex") .findFirst();
  26. 26. Images
  27. 27. Glide An image loading and caching library for Android focused on smooth scrolling github.com/bumptech/glide GlideApp.with(cx) .load(url) .into(imageView); GlideApp.with(cx) .load(url) .centerCrop() .placeholder(R.drawable.ph) .into(imageView);
  28. 28. Picasso A powerful image downloading and caching library for Android square.github.io/picasso Picasso.with(context) .load(url) .resize(50, 50) .centerCrop() .into(imageView); Picasso.with(context) .load(url) .placeholder(R.drawable.ph) .error(R.drawable.error) .into(imageView);
  29. 29. Glide Picasso More features Small
  30. 30. UI
  31. 31. Material Intro A simple material design app intro with cool animations and a fluent API. github.com/heinrichreimer/material- intro
  32. 32. Toasty The usual Toast, but with steroids. github.com/GrenderG/Toasty
  33. 33. Coordinator Tab Layout Custom composite control that quickly implements the combination of TabLayout and CoordinatorLayout. github.com/hugeterry/CoordinatorTabL ayout
  34. 34. Shimmer Recycler View A custom recycler view with shimmer views to indicate that views are loading. github.com/sharish/ShimmerRecyclerVi ew
  35. 35. Ultimate Recycler View A RecyclerView with refreshing,loading more,animation and many other features. github.com/cymcsg/UltimateRecyclerVi ew
  36. 36. Photo View Implementation of ImageView for Android that supports zooming, by various touch gestures. github.com/chrisbanes/PhotoView
  37. 37. Dialog Plus Advanced dialog solution for android github.com/orhanobut/dialogplus
  38. 38. William Chart Android library to create charts. github.com/diogobernardino/WilliamC hart
  39. 39. Utils
  40. 40. Parceler Android Parcelables made easy through code generation. @Parcel public class Example { String name; int age; /* Constructors, getters, etc. */ } Bundle bundle = new Bundle(); bundle.putParcelable( "key", Parcels.wrap(example)); Example example = Parcels.unwrap( this.getIntent() .getParcelableExtra("key")); github.com/johncarl81/parceler
  41. 41. Icepick Android library that eliminates the boilerplate of saving and restoring instance state. // This will be automatically saved and restored @State String username; @Override public void onCreate(Bundle state) { ... Icepick.restoreInstanceState(this, state); } @Override public void onSaveInstanceState(Bundle outState) { ... Icepick.saveInstanceState(this, outState); } github.com/frankiesardo/icepick
  42. 42. Timber A logger with a small, extensible API which provides utility on top of Android's normal Log class. github.com/JakeWharton/timber @Override public void onCreate() { super.onCreate(); if (BuildConfig.DEBUG) Timber.plant( new DebugTree()); else Timber.plant( new NotLoggingTree()); } Timber.v("some verbose logs here");
  43. 43. Joda time Joda-Time is the widely used replacement for the Java date and time classes. DateTime datetime = ... ; datetime.getMonthOfYear(); datetime.getDayOfMonth(); LocalDate fromDate = ... ; LocalDate newYear = fromDate.plusYears(1) .withDayOfYear(1); Days.daysBetween(fromDate, newYear); dateOfBirth.monthOfYear() .getAsText(Locale.ENGLISH); github.com/JodaOrg/joda-time
  44. 44. ThreeTen ABP An adaptation of the JSR-310 backport for Android. LocalDateTime ldt = LocalDateTime.now(); int ld = ldt.getDayOfMonth(); int lm = ldt.getMonthValue(); int ly = ldt.getYear(); ldt.withYear(2000); ldt.plusHours(2); ldt = LocalDateTime .of(2005, 3, 26, 12, 0, 0, 0); ldt.plusDays(1); ldt.plus(24,ChronoUnit.HOURS); github.com/JakeWharton/ThreeTenAB P
  45. 45. Joda Time ThreeTen ABP More options Size
  46. 46. Event Bus Event bus for Android that simplifies communication between Activities, Fragments, Threads, etc. greenrobot.org/eventbus/ public class Event { public final String message; ... } EventBus.getDefault() .register(this); @Subscribe public void onEvent(Event event) { // Handle event } EventBus.getDefault() .post(new Event(...));
  47. 47. TextView view = (TextView) findViewById(R.id.view);
  48. 48. Butter Knife Field and method binding for Android views jakewharton.github.io/butterknife/ @BindView(R.id.view) TextView view; @BindString(R.string.title) String title; @OnClick(R.id.submit) public void submit() { // Handle click } @Override public void onCreate(...) { ... ButterKnife.bind(this); }
  49. 49. Android Annotations Fast Android Development. Easy maintenance. github.com/excilys/androidannotations @EActivity(R.layout.activty) public class MyActivity extends Activity { @ViewById EditText textInput; @AnimationRes Animation fadeIn; @Click void doTranslate(...) { ... } @Background void runOnBackground(...) { ... } @UiThread void runOnUI(...) { ... } }
  50. 50. Firebase Job Dispatcher A library for scheduling background jobs in your Android app. It provides a JobScheduler- compatible API. github.com/firebase/firebase- jobdispatcher-android Job myJob = dispatcher.newJobBuilder() .setService(MyJobService.class) .setTag("my-unique-tag") .setRecurring(false) .setLifetime(UNTIL_NEXT_BOOT) .setReplaceCurrent(false) .setConstraints( ON_UNMETERED_NETWORK, DEVICE_CHARGING ) .setExtras(extrasBundle) .build(); dispatcher.mustSchedule(myJob);
  51. 51. Dagger2 A fast dependency injector for Android and Java github.com/google/dagger/ class CoffeeMaker { @Inject Heater heater; } @Module class DripCoffeeModule { @Provides Heater provideHeater() { return new ElectricHeater(); } } ObjectGraph.create( new DripCoffeeModule());
  52. 52. RxJava & RxAndroid A library for composing asynchronous and event-based programs using observable sequences github.com/ReactiveX/RxJava github.com/ReactiveX/RxAndroid Observable.just(items) .subscribeOn( Schedulers.newThread()) .observeOn( AndroidSchedulers .mainThread()) .subscribe(/* an Observer */);
  53. 53. WAKE UP
  54. 54. Tools
  55. 55. Layout Inspector Inspect your app's view hierarchy at runtime from within the Android Studio IDE. developer.android.com/studio/debug/la yout-inspector.html
  56. 56. Memo