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 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
<?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
Button logout = (Button) findViewById(R.id.logout); | |
logout.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
LogoutDialogFragment logoutFragment = LogoutDialogFragment | |
.newInstance(); | |
logoutFragment.show(getSupportFragmentManager(), "logout"); | |
} |
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 performLogout() { | |
Toast.makeText(this, | |
"Received log out request!", | |
Toast.LENGTH_SHORT | |
).show(); | |
} | |
@Override |
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 onClick(DialogInterface dialog, int which) { | |
switch (which) { | |
case DialogInterface.BUTTON_POSITIVE: | |
listener.performLogout(); | |
break; | |
case DialogInterface.BUTTON_NEGATIVE: | |
listener.cancelLogout(); | |
break; |
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) { | |
// Get the username from the arguments, if one isn't passed | |
// we use a blank string so it still looks OK | |
String username = ""; | |
if (getArguments().containsKey(USERNAME)) | |
username = ", " + getArguments().getString(USERNAME); | |
// "Are you sure you want to log out, <username>?" | |
String message |
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
private static final String USERNAME = "Username"; | |
... | |
public static LogoutDialogFragment newInstance(String username) { | |
LogoutDialogFragment fragment = new LogoutDialogFragment(); | |
// Add the username to the bundle of arguments for the fragment | |
Bundle args = new Bundle(); | |
args.putString(USERNAME, username); | |
fragment.setArguments(args); |