package org.SHS.Pult;

import android.os.Bundle;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.AlertDialog;
import android.app.Activity;
import android.view.View;
import android.view.LayoutInflater;
import android.view.WindowManager;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.EditText;
import org.SHS.Pult.Bridge;

public class AddressDialog extends AlertDialog {

	private Activity m_activity = null;
	private View m_view = null;

	public AddressDialog(Activity act, String addr) {
		super(act);
		m_activity = act;
		setTitle(m_activity.getString(R.string.title));
		setMessage(m_activity.getString(R.string.message));
		setButton(DialogInterface.BUTTON_POSITIVE, m_activity.getString(R.string.connect), new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					EditText addressEdit = (EditText)m_view.findViewById(R.id.address);
					Bridge.returnDialogResult(addressEdit.getText().toString());
				}
			});
		setButton(DialogInterface.BUTTON_NEGATIVE, m_activity.getString(R.string.cancel), new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					if (dialog != null) {
						 dialog.dismiss();
					}
				}
			});
		LayoutInflater inflater = m_activity.getLayoutInflater();
		m_view = inflater.inflate(R.layout.dialog_address, null);
		setView(m_view);
		EditText addressEdit = (EditText)m_view.findViewById(R.id.address);
		addressEdit.append(addr);
		addressEdit.selectAll();
	}

	public void show() {
		EditText addressEdit = (EditText)m_view.findViewById(R.id.address);
		addressEdit.requestFocus();
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
		super.show();
	}

}
