Skip to content

Instantly share code, notes, and snippets.

View v3n3's full-sized avatar

Julien Veneziano v3n3

View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="presenter"
type="com.example.MyPresenter"/>
<variable
@v3n3
v3n3 / ProgressColorBinding.java
Last active October 11, 2018 00:09
Using BindingAdapter to change ProgressBar color for pre-lollipop
@BindingAdapter("progressColor")
public static void setProgressBarColor(ProgressBar loader, int color) {
if (loader != null) {
loader.getIndeterminateDrawable()
.setColorFilter(color, android.graphics.PorterDuff.Mode.SRC_IN);
}
}
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
bind:progressColor="@{@android:color/holo_green_dark}"
/>
/**
* Bind Glide with an ImageView.
*
* @param view the ImageView to bind to Glide.
* @param src The URL of the image to load.
* @param placeholder The placeholder icon.
* @param error The error icon.
* @param blurValue The blur radius value between 1 and 25.
* @param cropCircle Crop the image in a circle of not.
*/
<ImageView
android:layout_width="@dimen/logo_size"
android:layout_height="@dimen/logo_size"
android:contentDescription="@null"
bind:src="@{logoURL}"
bind:blur="@{20}"
bind:cropCircle="@{true}"
bind:error="@{@drawable/ic_error_black_24dp}"
bind:placeholder="@{@drawable/ic_rowing_black_24dp}"
/>
@BindingAdapter("onKeyDone")
public static void onKeyDone(EditText editText, final OnKeyPressedListener action) {
if (editText != null) {
editText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
boolean handled = false;
if (keyCode == KeyEvent.KEYCODE_ENTER
&& event.getAction() == KeyEvent.ACTION_DOWN) {
action.onKeyPressed();
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionSend"
app:onKeyDone="@{()-> model.doLogin()}"
/>
/**
* Enable a TextView to handle HTML links.
* @param view The TextView where the link will be located.
* @param linkRes The resource id that contains the HTML link.
*/
@SuppressWarnings("deprecation")
@android.databinding.BindingAdapter("link")
public static void addLinkToTextView(TextView view, @StringRes int linkRes) {
if (view != null) {
Resources resources = view.getContext().getResources();
/**
* Underline a portion of the text.
*
* @param view The TextView containing the text to underline.
* @param spanSize an array that contain the start index and the end index.
*/
@android.databinding.BindingAdapter("underline")
public static void underlineText(TextView view, @NonNull int[] spanSize) {
if (view != null && spanSize.length == 2) {
SpannableString content = new SpannableString(view.getText());
@android.databinding.BindingAdapter("showKeyboard")
public static void showKeyBoard(final EditText editText, final boolean showFlag) {
editText.post(new Runnable() {
@Override
public void run() {
if (showFlag) {
KeyboardUtils.showKeyboard(editText);
} else {
editText.clearFocus();
+ KeyboardUtils.hideKeyboard(editText.getContext(), editText);