Skip to content

Instantly share code, notes, and snippets.

@edwardinubuntu
Created March 28, 2015 03:05
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 edwardinubuntu/fa7e2e2ffa0e12d6c5bf to your computer and use it in GitHub Desktop.
Save edwardinubuntu/fa7e2e2ffa0e12d6c5bf to your computer and use it in GitHub Desktop.
User Login
final TextView userErrorTextView = (TextView)rootView.findViewById(R.id.user_login_exception_text_view);
rootView.findViewById(R.id.user_login_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (userIdLoginEditText.getText() != null
&& userIdLoginEditText.getText().length() > 0
&& userPasswordLoginEditText.getText() != null
&& userPasswordLoginEditText.getText().length() > 0) {
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(userPasswordLoginEditText.getWindowToken(), 0);
userErrorTextView.setText(null);
updateRefreshItem(true);
ParseUser.logInInBackground(userIdLoginEditText.getText().toString(),
userPasswordLoginEditText.getText().toString(), new LogInCallback() {
@Override
public void done(ParseUser parseUser, ParseException e) {
updateRefreshItem(false);
if (parseUser != null) {
// Hooray! The user logged in.
Toast.makeText(getActivity(), getResources().getText(R.string.action_username_login_success), Toast.LENGTH_SHORT).show();
putNeedUpdate();
getActivity().setResult(Activity.RESULT_OK);
getActivity().finish();
} else {
// Sign up failed.
userErrorTextView.setText(e.getLocalizedMessage());
}
}
});
} else {
Toast.makeText(getActivity(), getResources().getText(R.string.action_login_form_validate_failure), Toast.LENGTH_SHORT).show();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment