7444
|
1 |
package org.hedgewars.hedgeroid;
|
|
2 |
|
|
3 |
import org.hedgewars.hedgeroid.netplay.Netplay;
|
|
4 |
|
|
5 |
import android.app.AlertDialog;
|
|
6 |
import android.app.Dialog;
|
|
7 |
import android.content.DialogInterface;
|
|
8 |
import android.os.Bundle;
|
|
9 |
import android.text.InputType;
|
|
10 |
import android.text.method.PasswordTransformationMethod;
|
|
11 |
import android.widget.EditText;
|
|
12 |
|
|
13 |
public class PasswordDialog extends ConnectionDependendDialogFragment {
|
|
14 |
String username;
|
|
15 |
|
|
16 |
public PasswordDialog() {
|
|
17 |
}
|
|
18 |
|
|
19 |
public PasswordDialog(String username) {
|
|
20 |
this.username = username;
|
|
21 |
}
|
|
22 |
|
|
23 |
@Override
|
|
24 |
public void onSaveInstanceState(Bundle icicle) {
|
|
25 |
super.onSaveInstanceState(icicle);
|
|
26 |
icicle.putString("username", username);
|
|
27 |
}
|
|
28 |
|
|
29 |
@Override
|
|
30 |
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
31 |
if(savedInstanceState != null) {
|
|
32 |
username = savedInstanceState.getString("username");
|
|
33 |
}
|
|
34 |
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
35 |
final EditText editText = new EditText(getActivity());
|
|
36 |
final Netplay netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
|
|
37 |
|
|
38 |
editText.setHint(R.string.dialog_password_hint);
|
|
39 |
editText.setId(android.R.id.text1);
|
|
40 |
editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
|
41 |
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
|
42 |
builder.setView(editText);
|
|
43 |
builder.setTitle(R.string.dialog_password_title);
|
|
44 |
builder.setMessage(getString(R.string.dialog_password_message, username));
|
|
45 |
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
46 |
public void onClick(DialogInterface dialog, int which) {
|
|
47 |
String password = editText.getText().toString();
|
|
48 |
editText.setText("");
|
|
49 |
netplay.sendPassword(password);
|
|
50 |
}
|
|
51 |
});
|
|
52 |
return builder.create();
|
|
53 |
}
|
|
54 |
|
|
55 |
@Override
|
|
56 |
public void onCancel(DialogInterface dialog) {
|
|
57 |
super.onCancel(dialog);
|
|
58 |
Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect();
|
|
59 |
}
|
|
60 |
}
|