Skip to content

Instantly share code, notes, and snippets.

@BindingAdapter({"bind:imageUrl", "bind:error"})
public static void loadImage(ImageView view, String url, Drawable error) {
Picasso.with(view.getContext()).load(url).error(error).into(view);
}
private class Todo {
public final ObservableField<String> image = new ObservableField<>();
public final ObservableField<String> date = new ObservableField<>();
public final ObservableInt priority = new ObservableInt();
}
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="todo"
type="com.b00sti.models.Todo" />
</data>
public static Observable<User> getFromApi(String username) {
Retrofit retrofit = new Retrofit.Builder()
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(ENDPOINT)
.build();
UserService apiService = retrofit.create(UserService.class);
return apiService.getUser(username);
}
UserService apiService = retrofit.create(UserService.class);
String username = "b00sti";
Call<User> call = apiService.getUser(username);
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
int statusCode = response.code();
User user = response.body();
public static final String ENDPOINT = "http://api.b00sti.com/";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ENDPOINT)
.addConverterFactory(GsonConverterFactory.create())
.build();
public interface UserService {
@GET("users/{username}")
Call<User> getUser(@Path("username") String username);
@GET("group/{id}/users")
Call<List<User>> groupList(@Path("id") int groupId, @Query("sort") String sort);
@POST("users/new")
Call<User> createUser(@Body User user);
@EActivity(R.layout.translate) // Sets content view to R.layout.translate
public class TranslateActivity extends Activity {
@ViewById // Injects R.id.textInput
EditText textInput;
@ViewById(R.id.myTextView) // Injects R.id.myTextView
TextView result;
@AnimationRes // Injects android.R.anim.fade_in
<resources>
<color name="red_50">#FFEBEE</color>
<color name="red_100">#FFCDD2</color>
<color name="red_200">#EF9A9A</color>
<color name="red_300">#E57373</color>
<color name="red_400">#EF5350</color>
<color name="red_500">#F44336</color>
<color name="red_600">#E53935</color>
<color name="red_700">#D32F2F</color>
public class NonNullExapmle {
private String placeName;
public NonNullExapmle(Place place) {
if (place != null) {
throw new NullPointerException("place");
}
this.placeName = place.getName();
}
}
public class NonNullExapmle {
private String placeName;
public NonNullExapmle(@NonNull Place place) {
this.placeName = place.getName();
}
}