project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/PasswordDialog.java
author unc0rr
Sun, 10 Feb 2013 01:27:32 +0400
changeset 8484 99c14f14f788
parent 7584 7831c84cc644
child 10017 de822cd3df3a
permissions -rw-r--r--
New checker of engine messages which is aware of glued together messages
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
package org.hedgewars.hedgeroid;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
import org.hedgewars.hedgeroid.netplay.Netplay;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
import android.app.AlertDialog;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
import android.app.Dialog;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
import android.content.DialogInterface;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
import android.os.Bundle;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
import android.text.InputType;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
import android.text.method.PasswordTransformationMethod;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
import android.widget.EditText;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    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
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
public class PasswordDialog extends ConnectionDependendDialogFragment {
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
	String username;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
	
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
	public PasswordDialog() {
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
	}
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
	
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
	public PasswordDialog(String username) {
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
		this.username = username;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
	}
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
	
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
	@Override
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
	public void onSaveInstanceState(Bundle icicle) {
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
		super.onSaveInstanceState(icicle);
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
		icicle.putString("username", username);
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
	}
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
	
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
	@Override
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
	public Dialog onCreateDialog(Bundle savedInstanceState) {
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
		if(savedInstanceState != null) {
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
			username = savedInstanceState.getString("username");
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
		}
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
		final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
		final EditText editText = new EditText(getActivity());
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
		final Netplay netplay = Netplay.getAppInstance(getActivity().getApplicationContext());
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
		
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
		editText.setHint(R.string.dialog_password_hint);
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
		editText.setId(android.R.id.text1);
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
		editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    63
		editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    64
		builder.setView(editText);
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    65
		builder.setTitle(R.string.dialog_password_title);
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
		builder.setMessage(getString(R.string.dialog_password_message, username));
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
		builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
			public void onClick(DialogInterface dialog, int which) {
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    69
				String password = editText.getText().toString();
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    70
				editText.setText("");
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    71
				netplay.sendPassword(password);
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    72
			}
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    73
		});
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    74
		return builder.create();
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    75
	}
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    76
	
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    77
	@Override
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    78
	public void onCancel(DialogInterface dialog) {
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    79
		super.onCancel(dialog);
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    80
		Netplay.getAppInstance(getActivity().getApplicationContext()).disconnect();
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    81
	}
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    82
}