// 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;
				GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].cursor.node.pushProperty(\"TW\",\""+coords+"\")");
			}

			GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].refresh()");
		} catch (JSONException e) {
			e.printStackTrace();
			showMessage("warning: error counting");
		}
		return sc;
	}

	/**
	 * we remove all territories and X in the goban but not in the sgf,
	 * because we'll need them to compute the "toggled dead stones" to estimate the score
	 * we then add back the X from the server onto the goban, so that the user knows which stones were
	 * marked dead and he can modify them. It should also make the toggle computing easier
	 */
	void cleanTerritory() {
		GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].detsoncleanT()");
		Game g = Game.gameShown;
		String serverMarkedStones = g.deadstInSgf;
		System.out.println("clean territory: serverMarkedStones: "+serverMarkedStones);
		for (int i=0;i<serverMarkedStones.length();i+=2) {
			String coord = serverMarkedStones.substring(i,i+2);
			GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].cursor.node.pushProperty(\"MA\", \""+coord+"\")");
		}
		GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].refresh()");
	}

	void copyEidogo(final String edir, final File odir) {
// 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;

				GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].cursor.node.pushProperty(\"TW\",\""+coords+"\")");
			}

			GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].refresh()");
		} catch (JSONException e) {
			e.printStackTrace();
			showMessage("warning: error counting");
		}
		return sc;
	}

	/**
	 * we remove all territories and X in the goban but not in the sgf,
	 * because we'll need them to compute the "toggled dead stones" to estimate the score
	 * we then add back the X from the server onto the goban, so that the user knows which stones were
	 * marked dead and he can modify them. It should also make the toggle computing easier
	 */
	void cleanTerritory() {
		GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].detsoncleanT()");
		Game g = Game.gameShown;
		String serverMarkedStones = g.deadstInSgf;
		System.out.println("clean territory: serverMarkedStones: "+serverMarkedStones);
		for (int i=0;i<serverMarkedStones.length();i+=2) {
			String coord = serverMarkedStones.substring(i,i+2);
			GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].cursor.node.pushProperty(\"MA\", \""+coord+"\")");
		}
		GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].refresh()");
	}

	void copyEidogo(final String edir, final File odir) {
		EventManager.getEventManager().sendEvent(eventType.copyEidogoStart);