Skip to content

Instantly share code, notes, and snippets.

benchmark_1 | Cloning into './test'...
benchmark_1 | Branch getting-running set up to track remote branch getting-running from origin.
benchmark_1 | Switched to a new branch 'getting-running'
benchmark_1 | Starting run for repo: https://github.com/joefiorini/flittal.git
benchmark_1 | Original elm-make
benchmark_1 | Success! Compiled 91 modules.
benchmark_1 | Successfully generated index.html
benchmark_1 | 104,028,098,272 bytes allocated in the heap
benchmark_1 | 3,109,829,544 bytes copied during GC
benchmark_1 | 45,512,368 bytes maximum residency (259 sample(s))
@antew
antew / LoginDialogFragment.java
Created February 17, 2013 20:36
getErrorDrawable
/**
* Returns an error icon for use with
* {@link EditText#setError(CharSequence)}
*
* @return A {@link Drawable} of the error icon
*/
public Drawable getErrorDrawable() {
Resources r = getActivity().getResources();
Drawable drawable
= r.getDrawable(R.drawable.custom_indicator_input_error);
/**
* Returns true if the username and password pass validation.
*
* @return False if the username or password is blank
*/
private boolean hasErrors() {
boolean hasErrors = false;
Drawable errorIcon = getErrorDrawable();
String errorText = null;
if (username.getText().length() == 0) {
/**
* Perform the login, provided {@link #hasErrors()} returns false
*/
private void doLogin() {
if (!hasErrors()) {
listener.onFinishLoginDialog(username.getText().toString(),
password.getText().toString());
this.dismiss();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {}
/**
* If the user receives an error message due to a blank field, this
/**
* These TextWatchers are used to clear the error icons
* automatically once the user has remedied an error
*/
username.addTextChangedListener(this);
password.addTextChangedListener(this);
/**
* We have to override setOnShowListener here (min API level 8) in
* order to validate the inputs before closing the dialog. Just
* overriding setPositiveButton closes the automatically when the
* button is pressed
*
* @return The onShowListener for the AlertDialog
*/
@Override
public void onShow(DialogInterface dialog) {
public class LoginDialogFragment extends DialogFragment implements
OnEditorActionListener, TextWatcher, OnShowListener {
/**
* Perform the login if the user presses the Done key from the
* password field
*/
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
doLogin();
return true;
password.setOnEditorActionListener(this);