// Path: src/fr/xtof54/jsgo/EventManager.java
// enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady,
// 	msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd};
// 
// Path: src/fr/xtof54/jsgo/ServerConnection.java
// public interface DetLogger {
//     public void showMsg(String s);
// }


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.concurrent.ArrayBlockingQueue;
import org.json.JSONException;
import org.json.JSONObject;
import fr.xtof54.jsgo.R;
import fr.xtof54.jsgo.EventManager.eventType;
import fr.xtof54.jsgo.ServerConnection.DetLogger;
import android.net.TrafficStats;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.os.Handler;
import android.os.Process;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.AssetManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
import android.webkit.ConsoleMessage;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.MotionEvent;
		}
		return u+" "+p;
	}
	boolean initServer() {
		System.out.println("call initserver "+server);
		if (server!=null) return true;
		String loginkey = PrefUtils.PREFS_LOGIN_USERNAME_KEY;
		String pwdkey = PrefUtils.PREFS_LOGIN_PASSWORD_KEY;
		if (chosenLogin==1) {
			loginkey = PrefUtils.PREFS_LOGIN_USERNAME2_KEY;
			pwdkey = PrefUtils.PREFS_LOGIN_PASSWORD2_KEY;
		}
		String u = PrefUtils.getFromPrefs(this, loginkey ,null);
		String p = PrefUtils.getFromPrefs(this, pwdkey ,null);
		System.out.println("credsdebug "+u+" "+p+" "+chosenLogin);
		if (u==null||p==null) {
			showMessage("Please enter your credentials first via menu Settings");
			return false;
		}
		{
			int i=PrefUtils.getFromPrefs(getApplicationContext(), PrefUtils.PREFS_BADNWIDTH_MODE, Game.ALWAYS_DOWNLOAD_SGF);
			Game.bandwidthMode=i;
			if (i==Game.PREFER_LOCAL_SGF)
				System.out.println("Set prefer local sgf from saved preferences");
		}

		final GoJsActivity m = this;
		System.out.println("credentials passed to server "+u+" "+p);
		if (server==null) {
			server = new ServerConnection(chosenServer, u, p);
// Path: src/fr/xtof54/jsgo/EventManager.java
// enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady,
// 	msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd};
// 
// Path: src/fr/xtof54/jsgo/ServerConnection.java
// public interface DetLogger {
//     public void showMsg(String s);
// }


// Path: src/fr/xtof54/jsgo/GoJsActivity.java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.concurrent.ArrayBlockingQueue;
import org.json.JSONException;
import org.json.JSONObject;
import fr.xtof54.jsgo.R;
import fr.xtof54.jsgo.EventManager.eventType;
import fr.xtof54.jsgo.ServerConnection.DetLogger;
import android.net.TrafficStats;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.os.Handler;
import android.os.Process;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.AssetManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
import android.webkit.ConsoleMessage;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.MotionEvent;

		}
		return u+" "+p;
	}
	boolean initServer() {
		System.out.println("call initserver "+server);
		if (server!=null) return true;
		String loginkey = PrefUtils.PREFS_LOGIN_USERNAME_KEY;
		String pwdkey = PrefUtils.PREFS_LOGIN_PASSWORD_KEY;
		if (chosenLogin==1) {
			loginkey = PrefUtils.PREFS_LOGIN_USERNAME2_KEY;
			pwdkey = PrefUtils.PREFS_LOGIN_PASSWORD2_KEY;
		}
		String u = PrefUtils.getFromPrefs(this, loginkey ,null);
		String p = PrefUtils.getFromPrefs(this, pwdkey ,null);
		System.out.println("credsdebug "+u+" "+p+" "+chosenLogin);
		if (u==null||p==null) {
			showMessage("Please enter your credentials first via menu Settings");
			return false;
		}
		{
			int i=PrefUtils.getFromPrefs(getApplicationContext(), PrefUtils.PREFS_BADNWIDTH_MODE, Game.ALWAYS_DOWNLOAD_SGF);
			Game.bandwidthMode=i;
			if (i==Game.PREFER_LOCAL_SGF)
				System.out.println("Set prefer local sgf from saved preferences");
		}

		final GoJsActivity m = this;
		System.out.println("credentials passed to server "+u+" "+p);
		if (server==null) {
			server = new ServerConnection(chosenServer, u, p);
			DetLogger l = new DetLogger() {