Slide 1

Slide 1 text

OSSの動向を捉えた実装方針 wasabeef DroidKaigi 2016

Slide 2

Slide 2 text

About me Daichi Furiya wasabeef @wasabeef_jp CyberAgent, Inc.

Slide 3

Slide 3 text

OSSの動向を捉えた実装方針?

Slide 4

Slide 4 text

Research

Slide 5

Slide 5 text

GitHub/trending Android Weekly Android Arsenal Twitter Research

Slide 6

Slide 6 text

Introduction

Slide 7

Slide 7 text

Languages

Slide 8

Slide 8 text

Kotlin Java • RetroLambda • Lightweight-Stream-API • ThreeTen Android Languages

Slide 9

Slide 9 text

Kotlin by JetBrains

Slide 10

Slide 10 text

Kotlin 1.0 Java連携 …more Kotlin

Slide 11

Slide 11 text

RetroLambda by Esko Luontola

Slide 12

Slide 12 text

Lambda Method Reference RetroLambda view.setOnClickListener(v -> { finish(); }); view.setOnClickListener(this::something);

Slide 13

Slide 13 text

Lightweight-Stream-API by Victor Melnik

Slide 14

Slide 14 text

Stream API Lightweight-Stream-API Stream.of(lines) .map(str -> str.split(t)) .filter(arr -> arr.length == 2) .map(arr -> new Word(arr[0], arr[1])) .collect(Collectors.toList());

Slide 15

Slide 15 text

Optional Lightweight-Stream-API Optional.ofNullable(getSupportActionBar()) .ifPresent(ab -> { ab.setDisplayHomeAsUpEnabled(true); ab.setHomeButtonEnabled(true); }); Optional.ofNullable(i.getStringExtra(EXTRA_URI)) .map(Uri::parse) .orElse(null);

Slide 16

Slide 16 text

ThreeTen Android by Jake Wharton

Slide 17

Slide 17 text

JSR-310 ThreeTen Android // Now LocalDateTime.now(); // 2016.2.18 10:30:40 LocalDateTime.of(2016, 2, 18, 10, 30, 40); // +1 truncated second LocalDateTime.now() .plusHours(1).truncatedTo(ChronoUnit.HOURS); // Epoch LocalDateTime.now() .toInstant(ZoneOffset.UTC).toEpochMilli();

Slide 18

Slide 18 text

Views

Slide 19

Slide 19 text

Support Library Android-ObservableScrollView Calligraphy florent37/ViewAnimator View

Slide 20

Slide 20 text

Support Library by Google

Slide 21

Slide 21 text

View (RecyclerView...etc ) RenderScript MultiDex Annotations Support Library

Slide 22

Slide 22 text

Sample... Support Library compile 'com.android.support:support-v4:+' compile 'com.android.support:appcompat-v7:+' compile 'com.android.support:design:+' compile 'com.android.support:recyclerview-v7:+' compile 'com.android.support:cardview-v7:+' compile 'com.android.support:support-annotations:+' compile ‘com.android.support:percent:+'

Slide 23

Slide 23 text

Android ObservableScrollView by ksoichiro

Slide 24

Slide 24 text

ScrollView , ListView, RecyclerViewなどのスクロー ル制御を監視 Android-ObservableScrollView https://github.com/ksoichiro/Android-ObservableScrollView

Slide 25

Slide 25 text

Calligraphy by Christopher Jenkins

Slide 26

Slide 26 text

Calligraphy アプリ全体にFont適用 xmlでもjavaでも可 簡単 https://github.com/chrisjenx/Calligraphy

Slide 27

Slide 27 text

CalligraphyConfig Calligraphy CalligraphyConfig.initDefault(new CalligraphyConfig.Builder() .setDefaultFontPath("fonts/mplus-2p-regular.ttf") .setFontAttrId(R.attr.fontPath) .build();

Slide 28

Slide 28 text

ViewAnimator by Florent CHAMPIGNY

Slide 29

Slide 29 text

ViewAnimator AnimatorSet animSet = new AnimatorSet(); animSet.playTogether( ObjectAnimator.ofFloat(image, View.TRANSLATION_Y, -1000,0), ObjectAnimator.ofFloat(image, View.ALPHA, 0,1), ObjectAnimator.ofFloat(text, View.TRANSLATION_X, -200,0) ); animSet.setInterpolator(new DescelerateInterpolator()); animSet.setDuration(2000); animSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { AnimatorSet anim = new AnimatorSet(); anim.playTogether( ObjectAnimator.ofFloat(image, View.SCALE_X, 1f, 0.5f, 1f), ObjectAnimator.ofFloat(image, View.SCALE_Y, 1f, 0.5f, 1f) ); anim.setInterpolator(new AccelerateInterpolator()); anim.setDuration(1000); anim.start(); } }); animSet.start();

Slide 30

Slide 30 text

ViewAnimator ViewAnimator .animate(image) .translationY(-1000, 0) .alpha(0, 1) .andAnimate(text) .dp().translationX(-200, 0) .descelerate() .duration(2000) .thenAnimate(image) .scale(1f, 0.5f, 1f) .accelerate() .duration(1000) .start();

Slide 31

Slide 31 text

DataBinding

Slide 32

Slide 32 text

Android Data Binding by Google

Slide 33

Slide 33 text

xmlとjavaのBinding Annotation Processing たまにビルドエラーが出る.. Android Data Binding

Slide 34

Slide 34 text

Android Data Binding

Slide 35

Slide 35 text

Android Data Binding

Slide 36

Slide 36 text

Android Data Binding

Slide 37

Slide 37 text

Custom Setters Android Data Binding public final class ImageBindingAdapters { @BindingAdapter({ "bind:image" }) public static void loadImage(ImageView view, String url) { Glide.with(view.getContext().getApplicationContext()) .load(url) .into(view); } }

Slide 38

Slide 38 text

DataBindingUtil Android Data Binding @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); binding.userName.setOnClickListener(v -> ...); }

Slide 39

Slide 39 text

Networking

Slide 40

Slide 40 text

(Volley) Retrofit + OkHttp Networking

Slide 41

Slide 41 text

Retrofit+OkHttp by Square

Slide 42

Slide 42 text

REST RxJava support Pluggable client Converters(Gson, Wire...) Retrofit+OkHttp

Slide 43

Slide 43 text

Retrofit Retrofit retrofit = new Retrofit.Builder() .client(okHttpClient) .baseUrl("https://api.github.com") .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build(); GitHubService service = retrofit.create(GitHubService.class); service.repos("wasabeef") .subscribe(repo -> { // ... }, e -> { Timber.w(e); }); public interface GitHubService { @GET(/users/{user}/repos) Observable> repos(@Path(user) String user); }

Slide 44

Slide 44 text

JSON & ProtoBuf

Slide 45

Slide 45 text

(Gson) (Jackson) (Moshi) Wire Serialisations

Slide 46

Slide 46 text

Wire by Square

Slide 47

Slide 47 text

Protocol Buffers okioを利用 Server/Clientで定義を共通化 Webからは扱いづらい Wire

Slide 48

Slide 48 text

Wire syntax = "proto3"; package helloworld; message HelloRequest { string name = 1; } message HelloReply { string message = 1; } hello.proto

Slide 49

Slide 49 text

Wire Build # java -jar wire-compiler-2.0.1-jar-with-dependencies.jar \ —proto_path=. \ —java_out=. hello.proto Writing helloworld.HelloRequest to . Writing helloworld.HelloReply to .

Slide 50

Slide 50 text

Parcelables

Slide 51

Slide 51 text

(android-parcelable-intellij-plugin) Parceler (Auto-Value-Parcel) Icepick Parcelables

Slide 52

Slide 52 text

Parceler by John Ericksen

Slide 53

Slide 53 text

Annotation Processing AutoValue Parceler

Slide 54

Slide 54 text

Parceler @Parcel public class User { public String name; public String thumbnail; User() { } } // Wrap Bundle bundle = new Bundle(); bundle.putParcelable("user", Parcels.wrap(user)); // Unwrap User user = Parcels.unwrap(getIntent().getParcelableExtra("user"));

Slide 55

Slide 55 text

Icepick by Frankie Sardo

Slide 56

Slide 56 text

Simple Icepick public class MainActivity extends Activity { @State String name; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Icepick.restoreInstanceState(this, savedInstanceState); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Icepick.saveInstanceState(this, outState); } }

Slide 57

Slide 57 text

Image Loaders

Slide 58

Slide 58 text

(Universal Image Loader) Picasso Glide Fresco Image Loaders

Slide 59

Slide 59 text

Picasso by Square

Slide 60

Slide 60 text

Simple Cache Transformations Debug Picasso

Slide 61

Slide 61 text

Simple Picasso Picasso.with(context) .load(“http://i.imgur.com/DvpvklR.png”) .setIndicatorsEnabled(true) .into(imageView);

Slide 62

Slide 62 text

Glide by Google (unofficial)

Slide 63

Slide 63 text

Glide Bitmap Pool Gif support Thumbnail Animation support Transformations

Slide 64

Slide 64 text

Simple Glide Glide.with(context) .load(“http://i.imgur.com/DvpvklR.png”) .crossFade() .thumbnail(.1f) .into(imageView);

Slide 65

Slide 65 text

Picasso? Glide?

Slide 66

Slide 66 text

Picasso? Glide? http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en

Slide 67

Slide 67 text

Picasso? Glide? http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en

Slide 68

Slide 68 text

Picasso? Glide? http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en Library's size

Slide 69

Slide 69 text

Picasso? Glide? http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en Method Count

Slide 70

Slide 70 text

Fresco by Facebook

Slide 71

Slide 71 text

Fresco Ashmem heap View Gif support Animation

Slide 72

Slide 72 text

Fresco

Slide 73

Slide 73 text

Fresco

Slide 74

Slide 74 text

Effects

Slide 75

Slide 75 text

Blurry Android StackBlur GPUImage for Android Picasso/Glide Transformations Effects

Slide 76

Slide 76 text

Blurry by Wasabeef

Slide 77

Slide 77 text

Blurry Blur RenderScript DownSampling

Slide 78

Slide 78 text

Android StackBlur by Enrique López Mañas

Slide 79

Slide 79 text

Blur RenderScript NDK Android StackBlur

Slide 80

Slide 80 text

Android StackBlur https://github.com/kikoso/android-stackblur

Slide 81

Slide 81 text

Android StackBlur https://github.com/kikoso/android-stackblur

Slide 82

Slide 82 text

GPUImage for Android by CyberAgent

Slide 83

Slide 83 text

GPUImage OpenGL ES 70 Filters Tone Curve

Slide 84

Slide 84 text

Picasso/Glide Transformations by Wasabeef

Slide 85

Slide 85 text

Transformations Picasso, Glide, Fresco Crop Blur Color Filter GPU Filter

Slide 86

Slide 86 text

DI

Slide 87

Slide 87 text

(AndroidAnnotations) (Square/Dagger) Google/Dagger Butter Knife DI

Slide 88

Slide 88 text

Dagger2 by Google

Slide 89

Slide 89 text

Annotation Processing テスト・メンテナンス Dagger2

Slide 90

Slide 90 text

Butter Knife by Jake Wharton

Slide 91

Slide 91 text

View Injection Butter Knife public class MainActivity extends Activity { @Bind(R.id.user_name) TextView userName; @Bind(R.id.user_thumbnail) ImageView thumbnail; @BindString(R.string.title) String title; @BindDrawable(R.drawable.graphic) Drawable graphic; @BindColor(R.color.red) int red; @BindDimen(R.dimen.spacer) float spacer; }

Slide 92

Slide 92 text

OnClick, OnTextChange, OnFocusChange...etc Butter Knife @OnClick(R.id.user_name) public void click(View view) { // ... } @OnClick({ R.id.user_name, R.id.user_thumbnail }) public void click(View door) { // ... }

Slide 93

Slide 93 text

FRP

Slide 94

Slide 94 text

RxJava RxAndroid (RxBinding) (RxLifecycle) FRP

Slide 95

Slide 95 text

RxJava by Netflix

Slide 96

Slide 96 text

非同期、リスト操作が簡単 Retrolambdaがあると良い  Leakが怖い Retrofitと併用 RxJava

Slide 97

Slide 97 text

Sample RxJava Observable.just("Google", "Apple", "MicroSoft") .map(String::toUpperCase) .subscribe(name -> { Timber.d("OnNext " + name); }, throwable -> { Timber.d("OnError"); });

Slide 98

Slide 98 text

Sample RxJava Observable.just("Google", "Apple", "MicroSoft") .map(String::toUpperCase) .subscribe(name -> { Timber.d("OnNext " + name); }, throwable -> { Timber.d("OnError"); });

Slide 99

Slide 99 text

lift compose rxjava-extras (by Dave Moten) RxJava

Slide 100

Slide 100 text

RxAndroid by RxAndroid authors

Slide 101

Slide 101 text

Scheduler RxAndroid

Slide 102

Slide 102 text

Main Thread RxAndroid Observable.just("one", "two", "three", "four", "five") .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(/* an Observer */); final Handler handler = new Handler(); Observable.just("one", "two", "three", "four", "five") .subscribeOn(Schedulers.newThread()) .observeOn(HandlerScheduler.from(handler)) .subscribe(/* an Observer */) Arbitrary Thread

Slide 103

Slide 103 text

DB/ORM

Slide 104

Slide 104 text

(ActiveAndroid) Realm (SQLBrite) Android Orma DB/ORM

Slide 105

Slide 105 text

Realm by Realm

Slide 106

Slide 106 text

Not SQLite RxJava? Thread間の制約 Realm

Slide 107

Slide 107 text

Android Orma by gfx

Slide 108

Slide 108 text

SQLite Annotation Processing RxJava Semi-automatic migration Android Orma

Slide 109

Slide 109 text

Event Buses

Slide 110

Slide 110 text

Otto EventBus (RxJava) Event Buses

Slide 111

Slide 111 text

Otto by Square

Slide 112

Slide 112 text

Deprecated! Square @Produceが少し便利 Otto

Slide 113

Slide 113 text

EventBus by greenrobot

Slide 114

Slide 114 text

EventBus EventBus3 Threading Support Annotation Processing

Slide 115

Slide 115 text

Debugging

Slide 116

Slide 116 text

Timber Hugo Debugging Stetho Leak Canary Takt Crashlytics

Slide 117

Slide 117 text

Timber by Jake Wharton

Slide 118

Slide 118 text

Logger Timber.Treeを継承して追加する ことで、出力先を自由に変えれる Timber if (BuildConfig.DEBUG) { Timber.plant(new Timber.DebugTree()); } else { Timber.plant(new CrashReportingTree()); }

Slide 119

Slide 119 text

Hugo by Jake Wharton

Slide 120

Slide 120 text

AnnotationでMethod Callsを Loggingできる Hugo @DebugLog public String getName(String first, String last) { return first + " " + last; } V/Example: ⇢ getName(first="Daichi", last="Furiya") V/Example: ⇠ getName [0ms] = “Daichi Furiya"

Slide 121

Slide 121 text

Stetho by Facebook

Slide 122

Slide 122 text

Chrome Developer Toolsを利 用して、Network、Dataの状 況の把握 Stetho-Realm (by uPhyca) Stetho

Slide 123

Slide 123 text

Stetho

Slide 124

Slide 124 text

Stetho

Slide 125

Slide 125 text

Stetho

Slide 126

Slide 126 text

Leak Canary by Square

Slide 127

Slide 127 text

メモリリークを検出 Leak Canary

Slide 128

Slide 128 text

Takt by Wasabeef

Slide 129

Slide 129 text

FPSを表示 Takt

Slide 130

Slide 130 text

Crashlytics by Twitter

Slide 131

Slide 131 text

クラッシュの検出 リアルタイム分析 NDKサポート Crashlytics

Slide 132

Slide 132 text

Crashlytics

Slide 133

Slide 133 text

Others

Slide 134

Slide 134 text

Multi-Dex ProGuard Others

Slide 135

Slide 135 text

MultiDex by Google

Slide 136

Slide 136 text

メソッド数の65k制限 最近は安定してきた MultiDex

Slide 137

Slide 137 text

Android Methods Count MultiDex https://plugins.jetbrains.com/plugin/8076

Slide 138

Slide 138 text

ProGuard by GuardSquare

Slide 139

Slide 139 text

ソースコードの難読化 未使用なリソースの削除 難しい ProGuard

Slide 140

Slide 140 text

ProGuard 15M sample-production.apk Total methods count: 99,280 (multidex enabled) 13M sample-production-proguard.apk Total methods count: 54,977 Proguard あり Proguard なし

Slide 141

Slide 141 text

Conclusion

Slide 142

Slide 142 text

Thank you. twitter.com/wasabeef_jp wasabeef.jp github.com/wasabeef