Skip to content

Instantly share code, notes, and snippets.

@PuercoPop
Created April 16, 2014 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PuercoPop/10849607 to your computer and use it in GitHub Desktop.
Save PuercoPop/10849607 to your computer and use it in GitHub Desktop.
loginButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// First check if email or password are empty, if any of those
// is empty, focus them. Else try to authenticate on the
// endpoint.
final EditText email = (EditText) rootView.findViewById(R.id.login_email);
final EditText password = (EditText) rootView.findViewById(R.id.login_password);
AuthenticatorMock authenticator = new AuthenticatorMock();
try {
final User user = authenticator.login(email.getText().toString(),
password.getText().toString());
} catch (InvalidCredentialsException e) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.credential_failure_title)
.setMessage(R.string.crentials_failure_message);
AlertDialog dialog = builder.create();
}
}
});
/// =====
public class AuthenticatorMock implements AuthenticatorInterface {
public User login(String username, String password) throws InvalidCredentialsException {
if (username.equals("Carmen") && password.equals("Sawada")) {
return new User("chiina@gmail.com");
} else {
// TODO: User values/strings.xml
throw new InvalidCredentialsException("Credenciales Equivocados");
}
}
}
@PuercoPop
Copy link
Author

Execution failed for task ':app:compileDebugJava'.

Compilation failed; see the compiler error output for details.
/home/puercopop/Projects/NoQ/app/src/main/java/com/puercopop/noq/LoginActivity.java
Error(87, 25) error: exception InvalidCredentialsException is never thrown in body of corresponding try statement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment