Skip to content

Instantly share code, notes, and snippets.

@MrOnyszko
Created December 28, 2016 12:08
Show Gist options
  • Save MrOnyszko/3ef00465fd8a423f0d3ac551ce64707c to your computer and use it in GitHub Desktop.
Save MrOnyszko/3ef00465fd8a423f0d3ac551ce64707c to your computer and use it in GitHub Desktop.
Signature pad android databinding adapter: https://github.com/gcacace/android-signaturepad
import android.databinding.BindingAdapter;
import com.github.gcacace.signaturepad.views.SignaturePad;
/**
* Example:
*
* <pre>
* {@code
* <com.github.gcacace.signaturepad.views.SignaturePad xmlns:bind="http://schemas.android.com/apk/res-auto"
* android:id="@+id/signature_pad"
* android:layout_width="match_parent"
* android:layout_height="match_parent"
* bind:onStartSigning="@{activity.onStartSigning}"
* bind:onClear="@{activity.onClear}"
* bind:onSigned="@{activity.onSigned}" />
* }
* </pre>
*
* @author Sławomir Onyszko
*/
public final class SignaturePadBindingAdapter {
@BindingAdapter("bind:onStartSigning")
public static void setOnSignedListener(SignaturePad view, final OnStartSigningListener onStartSigningListener) {
setOnSignedListener(view, onStartSigningListener, null, null);
}
@BindingAdapter("bind:onSigned")
public static void setOnSignedListener(SignaturePad view, final OnSignedListener onSignedListener) {
setOnSignedListener(view, null, onSignedListener, null);
}
@BindingAdapter("bind:onClear")
public static void setOnSignedListener(SignaturePad view, final OnClearListener onClearListener) {
setOnSignedListener(view, null, null, onClearListener);
}
@BindingAdapter(value = {"bind:onStartSigning", "bind:onSigned", "bind:onClear"}, requireAll = false)
public static void setOnSignedListener(SignaturePad view, final OnStartSigningListener onStartSigningListener, final OnSignedListener onSignedListener, final OnClearListener onClearListener) {
view.setOnSignedListener(new SignaturePad.OnSignedListener() {
@Override
public void onStartSigning() {
if (onStartSigningListener != null) {
onStartSigningListener.onStartSigning();
}
}
@Override
public void onSigned() {
if (onSignedListener != null) {
onSignedListener.onSigned();
}
}
@Override
public void onClear() {
if (onClearListener != null) {
onClearListener.onClear();
}
}
});
}
public interface OnStartSigningListener {
void onStartSigning();
}
public interface OnSignedListener {
void onSigned();
}
public interface OnClearListener {
void onClear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment