Jake Wharton Jake has been developing for














































gdg10.pptx
- Размер: 2.7 Мб
- Автор:
- Количество слайдов: 45
Описание презентации Jake Wharton Jake has been developing for по слайдам
Jake Wharton • Jake has been developing for Android since the first public M 3 SDK preview. He focuses on writing small, modular, well-tested libraries and tools to solve some of the ubiquitous problems which developers face. • He enjoys learning tools and libraries from other, emerging languages and applying their knowledge and techniques to advance Android and Java development and tooling. http: //jakewharton. com /
Jesse Wilson • Jesse Wilson develops apps and open source at Square. He’s worked on Android, Gson, Guice, Guava, and Shush. https: //publicobject. com/ https: //github. com/swankjesse
Action. Bar. Sherlock • Action. Bar. Sherlock is an standalone library designed to facilitate the use of the action bar design pattern across all versions of Android through a single API. https: //github. com/Jake. Wharton/Action. Bar. Sherlock
Nine. Old. Androids • Android library for using the Honeycomb (Android 3. 0) animation API on all versions of the platform back to 1. 0! https: //github. com/Jake. Wharton/Nine. Old. Androids
Disk. Lru. Cache • LRU — least recently used • A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key and a fixed number of values. Each key must match the regex [a-z 0 -9_-]{1, 120}. Values are byte sequences, accessible as streams or files. Each value must be between 0 and Integer. MAX_VALUE bytes in length. • The cache stores its data in a directory on the filesystem. This directory must be exclusive to the cache; the cache may delete or overwrite files from its directory. It is an error for multiple processes to use the same cache directory at the same time. https: //github. com/Jake. Wharton/Disk. Lru. Cache
Square projects
Picasso A powerful image downloading and caching library for Android https: //github. com/square/picasso
Flow • Navigate between UI states. Support the back button easily without confusing your users with surprising results. • Remember the UI state, and its history, as you navigate and across configuration changes and process death. • Manage resources with set-up/tear-down hooks invoked for each UI states can easily share resources, and they’ll be disposed when no longer needed. • Manage all types of UIs— complex master-detail views, multiple layers, and window-based dialogs are all simple to manage. https: //habrahabr. ru/post/277289 /https: //github. com/square/flow
Okio • Okio is a new library that complements java. io and java. nio to make it much easier to access, store, and process your data. https: //github. com/square/okio
Moshi • Moshi is a modern JSON library for Android and Java. It makes it easy to parse JSON into Java objects https: //github. com/square/moshi https: //habrahabr. ru/company/luxoft/blog/280782/
Leak. Canary • A memory leak detection library for Android and Java. • “ A small leak will sink a great ship. ” — Benjamin Franklin https: //habrahabr. ru/post/257633/https: //github. com/square/leakcanary
Ok. Http • An HTTP & HTTP/2 client for Android and Java applications. https: //github. com/square/okhttps: //habrahabr. ru/post/281965/
Retrofit • Type-safe HTTP client for Android and Java by Square, Inc. https: //habrahabr. ru/post/314028/https: //github. com/square/retrofit
Jake Wharton’s Projects
Butterknife • Bind Android views and callbacks to fields and methods. https: //github. com/Jake. Wharton/butterknife
Hugo • Annotation-triggered method call logging for your debug builds. • As a programmer, you often add log statements to print method calls, their arguments, their return values, and the time it took to execute. This is not a question. Every one of you does this. Shouldn’t it be easier? • Simply add @Debug. Log to your methods and you will automatically get all of the things listed above logged for free. https: //github. com/Jake. Wharton/hugo
Timber • This is a logger with a small, extensible API which provides utility on top of Android’s normal Log class. • I copy this class into all the little apps I make. I’m tired of doing it. Now it’s a library. There are no Tree implementations installed by default because every time you log in production, a puppy dies. https: //github. com/Jake. Wharton/timber
Rx. Binding • Rx. Java binding APIs for Android UI widgets from the platform and support libraries. https: //github. com/Jake. Wharton/Rx. Binding https: //habrahabr. ru/company/piter/blog/
Ссылки на статьи из хабра
Butterknife vs. Data. Binding public class User { private final String first. Name; private final String last. Name; public User(String first. Name, String last. Name) { this. first. Name = first. Name; this. last. Name = last. Name; } public String get. First. Name() { return this. first. Name; } public String get. Last. Name() { return this. last. Name; } }
Butterknife class Example. Activity extends Activity { @Bind. View(R. id. title) Text. View name; @Bind. View(R. id. subtitle) Text. View lastname; @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. simple_activity); Butter. Knife. bind(this); User user = new user(“Jake”, “Wharton”); name. set. Text(user. get. First. Name()); lastname. set. Text(user. get. Last. Name()); } }
Data. Binding •
Data. Binding class Example. Activity extends Activity { @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); set. Content. View(R. layout. simple_activity); Main. Activity. Binding binding = Data. Binding. Util. set. Content. View(this, R. layout. simple_activity); User user = new User( «Sergey», “Brin»); binding. set. User(user); } }
Butter. Knife @Bind. Views({ R. id. first_name, R. id. middle_name, R. id. last_name }) List name. Views; @On. Click({ R. id. door 1, R. id. door 2, R. id. door 3 }) public void pick. Door(Door. View door) { if (door. has. Prize. Behind()) { Toast. make. Text(this, «You win!», LENGTH_SHORT). show(); } else { Toast. make. Text(this, «Try again», LENGTH_SHORT). show(); } }
Data. Binding • android: on. Click=»@{(door. View) -> pick. Door(door. View))}»
Picasso vs. Glide R. drawable. image либо URL на изображение
Picasso. with (context). load (R. drawable. image). placeholder(R. drawable. placeholder). error(R. drawable. error). fit(). into(image. View, call. Back); Callback call. Back = new Callback () { @Override public void on. Success () { Toast. make. Text(context, «Картинка загрузилась», Toast. LENGTH_LONG). show (); } @Override public void on. Error () { Toast. make. Text(context, «Картинка o загрузилась», Toast. LENGTH_LONG). show (); } };
Glide. with(context). load(R. drawable. image). placeholder(R. drawable. placeholder). error(R. drawable. error). fit. Center(). listener(listener) . into(image. Frame) ; Request. Listener listener = new Request. Listener() { @Override public boolean on. Exception(Exception e, String model, Target target, boolean is. First. Resource) { Toast. make. Text(context, «Картинка не загрузилась», Toast. LENGTH_LONG). show (); } @Override public boolean on. Resource. Ready(Glide. Drawable resource, String model, Target target, boolean is. From. Memory. Cache, boolean is. First. Resource) { Toast. make. Text(context, «Картинка загрузилась», Toast. LENGTH_LONG). show (); } }
Ok. Http vs. Retrofit vs. Volley • GET запрос https: //randomsite. com/helloworld/ • POST запрос https: //randomsite. com/iwanttohidemyparams/ Параметры запроса “ first. Param” = “Russia” “ second. Param” = “Matryoshka”
Ok. Http (GET) Request request = new Request. Builder() . url(«http: //publicobject. com/helloworld»). build(); Response response = client. new. Call(request). execute(); if (!response. is. Successful()) { throw new IOException(«Unexpected code » + response); } else { //some tasks }
Retrofit (GET) public interface Random. Site. Service { @GET(“/helloworld») Call helloworld(); @POST(“/iwanttohidemyparams”) Call iwanttohidemyparams(@Field String first. Param, @Field String second. Param); } Retrofit retrofit = new Retrofit. Builder(). base. Url(«https: //randomsite. com/») . build(); Random. Site. Service service = retrofit. create(Random. Site. Service. class); Call request = service. helloworld(); String response = request. execute();
Volley (GET) Request. Queue queue = Volley. new. Request. Queue(context); String url =»http: //publicobject. com/helloworld»; String. Request string. Request = new String. Request(Request. Method. GET, url, new Response. Listener() { @Override public void on. Response(String response) { //some tasks } }, new Response. Error. Listener() { @Override public void on. Error. Response(Volley. Error error) { //some error tasks } }); queue. add(string. Request);
Ok. Http (POST) Ok. Http. Client client = new Ok. Http. Client(); Request. Body form. Body = new Form. Body. Builder(). add(“first. Param», “Russia»). add(“second. Param», “Matryoshka»). build(); Request request = new Request. Builder() . url(» https: //randomsite. com/iwanttohidemyparams/ «) . post(form. Body). build(); Response response = client. new. Call(request). execute(); if (!response. is. Successful()) { throw new IOException(«Unexpected code » + response); } else { //some tasks }
Retrofit (POST) Retrofit retrofit = new Retrofit. Builder() . base. Url(«https: //randomsite. com/») . build(); Random. Site. Service service = retrofit. create(Random. Site. Service. class); Call request = service. iwanttohidemyparams(“Russia”, “Matryoshka”); String response = request. execute();
Volley (POST) Request. Queue queue = Volley. new. Request. Queue(context); String url =»http: //publicobject. com/iwanttohidemyparams»; Request post. Request = new Request(Request. Method. POST, url, new Response. Listener() { @Override public void on. Response(Response response) { //some tasks } }, new Response. Error. Listener() { @Override public void on. Error. Response(Volley. Error error) { //some tasks } } ) { @Override protected Map get. Params() { Map params = new Hash. Map(); params. put(“first. Param», “Russia»); params. put(“second. Param», “Matryoushka»); return params; } }; queue. add(post. Request);
Ok. Http (Async) client. new. Call(request). enqueue(new Callback() { @Override public void on. Failure(Call call, IOException e) { //some error tasks } @Override public void on. Response(Call call, Response response) throws IOException { if (!response. is. Successful()) { throw new IOException(«Unexpected code » + response); } else { //some tasks } } });
Retrofit (Async) Call call = task. Service. get. Tasks(); call. enqueue(new Callback() { @Override public void on. Response(Call call, Response response) { if (response. is. Successful()) { //some tasks } else { //some error tasks } } @Override public void on. Failure(Call<List> call, Throwable t) { //some error tasks } }
Leak. Canary In your Application class: public class Example. Application extends Application { @Override public void on. Create() { super. on. Create(); if (Leak. Canary. is. In. Analyzer. Process(this)) { // This process is dedicated to Leak. Canary for heap analysis. // You should not init your app in this process. return; } Leak. Canary. install(this); // Normal app init code. . . } }
Android Monitor