background preloader


Introduction Retrofit turns your REST API into a Java interface. public interface GitHubService { @GET("/users/{user}/repos") List<Repo> listRepos(@Path("user") String user);} The RestAdapter class generates an implementation of the GitHubService interface. RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(" .build(); GitHubService service = restAdapter.create(GitHubService.class); Each call on the generated GitHubService makes an HTTP request to the remote webserver. List<Repo> repos = service.listRepos("octocat"); Use annotations to describe the HTTP request: URL parameter replacement and query parameter support Object conversion to request body (e.g., JSON, protocol buffers) Multipart request body and file upload API Declaration Annotations on the interface methods and its parameters indicate how a request will be handled. Request Method Every method must have an HTTP annotation that provides the request method and relative URL. @GET("/users/list") Download Related:  Java LibrariesLibrarieslw

ArcBees/Jukito Butter Knife Introduction Annotate fields with @Bind and a view ID for Butter Knife to find and automatically cast the corresponding view in your layout. class ExampleActivity extends Activity { @Bind( TextView title; @Bind( TextView subtitle; @Bind( TextView footer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_activity); ButterKnife.bind(this); // TODO Use fields... }} Instead of slow reflection, code is generated to perform the view look-ups. Calling bind delegates to this generated code that you can see and debug. The generated code for the above example is roughly equivalent to the following: public void bind(ExampleActivity activity) { activity.subtitle = (android.widget.TextView) activity.findViewById(2130968578); activity.footer = (android.widget.TextView) activity.findViewById(2130968579); activity.title = (android.widget.TextView) activity.findViewById(2130968577);} View Lists

OkHttp Overview HTTP is the way modern applications network. It’s how we exchange data & media. OkHttp is an HTTP client that’s efficient by default: HTTP/2 support allows all requests to the same host to share a socket. OkHttp perseveres when the network is troublesome: it will silently recover from common connection problems. Using OkHttp is easy. OkHttp supports Android 2.3 and above. Examples Get a URL This program downloads a URL and print its contents as a string. OkHttpClient client = new OkHttpClient(); String run(String url) throws IOException { Request request = new Request.Builder() .url(url) .build(); Response response = client.newCall(request).execute(); return response.body().string();} Post to a Server This program posts data to a service. Download ↓ v3.4.1 JAR You'll also need Okio, which OkHttp uses for fast I/O and resizable buffers. The source code to OkHttp, its samples, and this website is available on GitHub. Maven Gradle compile 'com.squareup.okhttp3:okhttp:3.4.1' Contributing

Android Bootstrap Android : Volley and Gson tutorial Android Volley is the new way to make network requests. It has a lot of advantages : configurable thread pool, request priority, caching, request cancel. AsyncTask is no more needed and this is a good new as AsyncTask is known for its memory leak issues. In this quick step tutorial, i show the piece of source code to make it work with google gson library. Test before If you wish to test before, you can install the application with the following link. Your app ideaMichenuxFree Prerequisite At this time, there is no release of volley library so you have to download the source code and copy it inside your project. git clone In the activity Declare a new attribute of type RequestQueue : private RequestQueue requestQueue; In the onCreate method, initialize the RequestCode and let’s call our startRequest method : this.requestQueue = Volley.newRequestQueue(this.getActivity()); startRequest() This is my startRequest method.

fernandezpablo85/scribe-java square/tape Picasso Introduction Images add much-needed context and visual flair to Android applications. Picasso allows for hassle-free image loading in your application—often in one line of code! Picasso.with(context).load(" Many common pitfalls of image loading on Android are handled automatically by Picasso: Handling ImageView recycling and download cancelation in an adapter. Features Adapter Downloads Adapter re-use is automatically detected and the previous download canceled. @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);} Image Transformations Transform images to better fit into layouts and to reduce memory size. Picasso.with(context) .load(url) .resize(50, 50) .centerCrop() .into(imageView) Place Holders Resource Loading Debug Indicators

Gson User Guide - gson Serializing and Deserializing Collection with Objects of Arbitrary Types Sometimes you are dealing with JSON array that contains mixed types. For example: The equivalent Collection containing this is: Collection collection = new ArrayList(); collection.add("hello"); collection.add(5); collection.add(new Event("GREETINGS", "guest")); Where the Event class is defined as: class Event { private String name; private String source; private Event(String name, String source) { = name; this.source = source; You can serialize the collection with Gson without doing anything specific: toJson(collection) would write out the desired output. However, deserialization with fromJson(json, Collection.class) will not work since Gson has no way of knowing how to map the input to the types. Option 1: Use Gson's parser API (low-level streaming parser or the DOM parser JsonParser) to parse the array elements and then use Gson.fromJson() on each of the array elements.This is the preferred approach. Compact Vs.

AndroidBootstrap/android-bootstrap Java 8 Resources | lambdas | method references | defender methods | streams square/otto