Transcript

ANDROID DEVELOPER

TOOLBOX

Shem Magnezi@shemag8 • shem8.github.com

New Developers

Libraries

Resources

Tools

Libraries

Why?

Outsource your problems

Help the community

Why not?

Legal issues

Old / Buggy code

App size

Don’t outsource your

core logic

Basics

Support LibraryProvide 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/support-library

Google Play Servicestake 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/support-library

Network

MoshiA modern JSON library for Android and Java.

MyObj item = new MyObj(...);

Moshi moshi =

new Moshi.Builder().build();

JsonAdapter<MyObj> adapter =

moshi.adapter(MyObj.class);

adapter.toJson(item);

adapter.fromJson(jsonStr);

github.com/square/moshi

OkHttp3An 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

RetrofitA type-safe HTTP client for Android and Java

public interface GitHub {

@GET("users/{user}/repos")

Call<List<Repo>> repos(

@Path("user") String user);

}

Retrofit retrofit =

new Retrofit.Builder()

.baseUrl("https://api.github.com")

.build();

GitHub service =

retrofit.create(GitHub.class);

Call<List<Repo>> repos =

service.repos("octocat");

square.github.io/retrofit

Persistency

RoomAbstraction 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<User> loadAllByIds(

int[] userIds);

}developer.android.com/training/data-storage/room/index.html

ObjectBoxThe easy object-oriented database for small devices

BoxStore boxStore =

MyObjectBox.builder()

.androidContext(...)

.build();

Box<Person> 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

Room ObjectBox

Support Speed

RealmA 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();

Images

GlideAn 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);

PicassoA 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);

Glide Picasso

More features Small

UI

Material IntroA simple material design app intro with cool animations and a fluent API.

github.com/heinrichreimer/material-intro

ToastyThe usual Toast, but with steroids.

github.com/GrenderG/Toasty

CoordinatorTab LayoutCustom composite control that quickly implements the combination of TabLayout and CoordinatorLayout.

github.com/hugeterry/CoordinatorTabLayout

ShimmerRecyclerViewA custom recycler view with shimmer views to indicate that views are loading.

github.com/sharish/ShimmerRecyclerView

Ultimate RecyclerViewA RecyclerView with refreshing,loading more,animation and many other features.

github.com/cymcsg/UltimateRecyclerView

Photo ViewImplementation of ImageView for Android that supports zooming, by various touch gestures.

github.com/chrisbanes/PhotoView

DialogPlusAdvanced dialog solution for android

github.com/orhanobut/dialogplus

WilliamChartAndroid library to create charts.

github.com/diogobernardino/WilliamChart

Utils

ParcelerAndroid 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

IcepickAndroid 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

TimberA 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");

Joda timeJoda-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

ThreeTenABPAn 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/ThreeTenABP

Joda Time ThreeTenABP

More options Size

Event BusEvent 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(...));

TextView view = (TextView) findViewById(R.id.view);

Butter KnifeField 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);

}

AndroidAnnotationsFast 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(...) { ... }

}

Firebase JobDispatcherA 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);

Dagger2A 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());

RxJava & RxAndroidA library for composing asynchronous and event-based programs using observable sequences

github.com/ReactiveX/RxJavagithub.com/ReactiveX/RxAndroid

Observable.just(items)

.subscribeOn(

Schedulers.newThread())

.observeOn(

AndroidSchedulers

.mainThread())

.subscribe(/* an Observer */);

WAKE UP

Tools

Layout InspectorInspect your app's view hierarchy at runtime from within the Android Studio IDE.

developer.android.com/studio/debug/layout-inspector.html

Memory ProfilerHelps you identify memory leaks and memory churn that can lead to stutter, freezes, and even app crashes.

https://developer.android.com/studio/profile/memory-profiler.html

CPU ProfilerInspect your app’s CPU usage and thread activity in real-time, and record method traces.

developer.android.com/studio/profile/cpu-profiler.html

Network Profilerdisplays real time network activity on a timeline, showing data sent and received, as well as the current number of connections.

developer.android.com/studio/profile/network-profiler.html

The MonkeyGenerates pseudo-random streams of user events

https://developer.android.com/studio/test/monkey.html

adb shell monkey

-p your.package.name

-v 500

Developer optionsRealtime on device debugging.

https://developer.android.com/studio/debug/dev-options.html

StethoA debug bridge for Android applications

http://facebook.github.io/stetho/

Shape ShifterWeb-app that simplifies the creation of icon animations for Android, iOS, and the web.

shapeshifter.design/

LottieParses Adobe After Effects animations exported as json with Bodymovin and renders them natively on mobile.

airbnb.io/lottie

ALMOST THERE

Resources

Android ArsenalA categorized directory of libraries and tools for Android

android-arsenal.com

Android library statisticsInsights on what Ad Networks, Social SDKs and developer tools are present in Android apps and what their market shares are.

www.appbrain.com/stats/librarie

Android Developers BlogThe latest Android and Google Play news for app and game developers.

android-developers.blogspot.co.il

Android Developers BackstageA podcast by and for Android developers, Hosted by developers from the Android engineering team.

androidbackstage.blogspot.co.il

Android WeeklyA free newsletter that helps you to stay cutting-edge with your Android Development.

androidweekly.net

QUESTIONS?@shemag8 • shem8.github.com