This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState) { | |
super.onCreateDialog(savedInstanceState); | |
Log.i(TAG, "onCreateDialog"); | |
LayoutInflater lf = LayoutInflater.from(getActivity()); | |
/** | |
* Inflate our custom view for this dialog, it contains | |
* two TextViews and two EditTexts, one set for the username | |
* and a second set for the password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
password.setOnEditorActionListener(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" > | |
<TextView | |
android:id="@+id/login_username_label" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Interface for Activities to implement to receive the result (the | |
* username and password in this case) | |
* | |
*/ | |
public interface LoginDialogListener { | |
void onFinishLoginDialog(String username, String password); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LoginDialogFragment extends DialogFragment implements | |
OnEditorActionListener, TextWatcher, OnShowListener { | |
private TextView password; | |
private TextView username; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<EditText | |
android:id="@+id/login_password" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:imeOptions="actionDone" | |
android:inputType="textPassword" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* These TextWatchers are used to clear the error icons | |
* automatically once the user has remedied an error | |
*/ | |
username.addTextChangedListener(this); | |
password.addTextChangedListener(this); |