31 |
31 |
32 /** |
32 /** |
33 * Shown when connecting to the server, and the server requests a password. |
33 * Shown when connecting to the server, and the server requests a password. |
34 */ |
34 */ |
35 public class PasswordDialog extends ConnectionDependendDialogFragment { |
35 public class PasswordDialog extends ConnectionDependendDialogFragment { |
36 String username; |
36 String username; |
37 |
37 |
38 public PasswordDialog() { |
38 public PasswordDialog() { |
39 } |
39 } |
40 |
40 |
41 public PasswordDialog(String username) { |
41 public PasswordDialog(String username) { |
42 this.username = username; |
42 this.username = username; |
43 } |
43 } |
44 |
44 |
45 @Override |
45 @Override |
46 public void onSaveInstanceState(Bundle icicle) { |
46 public void onSaveInstanceState(Bundle icicle) { |
47 super.onSaveInstanceState(icicle); |
47 super.onSaveInstanceState(icicle); |
48 icicle.putString("username", username); |
48 icicle.putString("username", username); |
49 } |
49 } |
50 |
50 |
51 @Override |
51 @Override |
52 public Dialog onCreateDialog(Bundle savedInstanceState) { |
52 public Dialog onCreateDialog(Bundle savedInstanceState) { |
53 if(savedInstanceState != null) { |
53 if(savedInstanceState != null) { |
54 username = savedInstanceState.getString("username"); |
54 username = savedInstanceState.getString("username"); |
55 } |
55 } |
56 final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); |
56 final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); |
57 final EditText editText = new EditText(getActivity()); |
57 final EditText editText = new EditText(getActivity()); |
58 final Netplay netplay = Netplay.getAppInstance(getActivity().getApplicationContext()); |
58 final Netplay netplay = Netplay.getAppInstance(getActivity().getApplicationContext()); |
59 |
59 |
60 editText.setHint(R.string.dialog_password_hint); |
60 editText.setHint(R.string.dialog_password_hint); |
61 editText.setId(android.R.id.text1); |
61 editText.setId(android.R.id.text1); |
62 editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); |
62 editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); |
63 editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); |
63 editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); |
64 builder.setView(editText); |
64 builder.setView(editText); |
65 builder.setTitle(R.string.dialog_password_title); |
65 builder.setTitle(R.string.dialog_password_title); |
66 builder.setMessage(getString(R.string.dialog_password_message, username)); |
66 builder.setMessage(getString(R.string.dialog_password_message, username)); |
67 builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
67 builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
68 public void onClick(DialogInterface dialog, int which) { |
68 public void onClick(DialogInterface dialog, int which) { |
69 String password = editText.getText().toString(); |
69 String password = editText.getText().toString(); |
70 editText.setText(""); |
70 editText.setText(""); |
71 netplay.sendPassword(password); |
71 netplay.sendPassword(password); |
72 } |
72 } |
73 }); |
73 }); |
74 return builder.create(); |
74 return builder.create(); |
75 } |
75 } |
76 |
76 |
77 @Override |
77 @Override |
78 public void onCancel(DialogInterface dialog) { |
78 public void onCancel(DialogInterface dialog) { |
79 super.onCancel(dialog); |
79 super.onCancel(dialog); |
80 Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect(); |
80 Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect(); |
81 } |
81 } |
82 } |
82 } |