author | unc0rr |
Wed, 14 May 2014 21:41:42 +0400 | |
changeset 10243 | 9a3ba4e76e38 |
parent 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
1 |
/* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
2 |
* Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
3 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
4 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
6 |
* modify it under the terms of the GNU General Public License |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
7 |
* as published by the Free Software Foundation; either version 2 |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
8 |
* of the License, or (at your option) any later version. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
9 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
13 |
* GNU General Public License for more details. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
14 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
18 |
*/ |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
19 |
|
7444 | 20 |
package org.hedgewars.hedgeroid; |
21 |
||
22 |
import org.hedgewars.hedgeroid.netplay.Netplay; |
|
23 |
||
24 |
import android.app.AlertDialog; |
|
25 |
import android.app.Dialog; |
|
26 |
import android.content.DialogInterface; |
|
27 |
import android.os.Bundle; |
|
28 |
import android.text.InputType; |
|
29 |
import android.text.method.PasswordTransformationMethod; |
|
30 |
import android.widget.EditText; |
|
31 |
||
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
32 |
/** |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
33 |
* Shown when connecting to the server, and the server requests a password. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7444
diff
changeset
|
34 |
*/ |
7444 | 35 |
public class PasswordDialog extends ConnectionDependendDialogFragment { |
10017 | 36 |
String username; |
37 |
||
38 |
public PasswordDialog() { |
|
39 |
} |
|
40 |
||
41 |
public PasswordDialog(String username) { |
|
42 |
this.username = username; |
|
43 |
} |
|
44 |
||
45 |
@Override |
|
46 |
public void onSaveInstanceState(Bundle icicle) { |
|
47 |
super.onSaveInstanceState(icicle); |
|
48 |
icicle.putString("username", username); |
|
49 |
} |
|
50 |
||
51 |
@Override |
|
52 |
public Dialog onCreateDialog(Bundle savedInstanceState) { |
|
53 |
if(savedInstanceState != null) { |
|
54 |
username = savedInstanceState.getString("username"); |
|
55 |
} |
|
56 |
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); |
|
57 |
final EditText editText = new EditText(getActivity()); |
|
58 |
final Netplay netplay = Netplay.getAppInstance(getActivity().getApplicationContext()); |
|
59 |
||
60 |
editText.setHint(R.string.dialog_password_hint); |
|
61 |
editText.setId(android.R.id.text1); |
|
62 |
editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); |
|
63 |
editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); |
|
64 |
builder.setView(editText); |
|
65 |
builder.setTitle(R.string.dialog_password_title); |
|
66 |
builder.setMessage(getString(R.string.dialog_password_message, username)); |
|
67 |
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
|
68 |
public void onClick(DialogInterface dialog, int which) { |
|
69 |
String password = editText.getText().toString(); |
|
70 |
editText.setText(""); |
|
71 |
netplay.sendPassword(password); |
|
72 |
} |
|
73 |
}); |
|
74 |
return builder.create(); |
|
75 |
} |
|
76 |
||
77 |
@Override |
|
78 |
public void onCancel(DialogInterface dialog) { |
|
79 |
super.onCancel(dialog); |
|
80 |
Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect(); |
|
81 |
} |
|
7444 | 82 |
} |