// Path: RetroShareAndroidIntegration/src/org/retroshare/android/RsCtrlService.java
// public enum ConnectionError
// {
// 	/**
// 	 * No error
// 	 */
// 	NONE,
// 
// 	/**
// 	 * The IP address of the host could not be determined.
// 	 */
// 	UnknownHostException,
// 
// 	/**
// 	 * Signals that an error occurred while attempting to onConnectButtonPressed a socket
// 	 * to a remote address and port. Typically, the remote host cannot be
// 	 * reached because of an intervening firewall, or if an intermediate
// 	 * router is down.
// 	 */
// 	NoRouteToHostException,
// 
// 	/**
// 	 * Signals that an error occurred while attempting to onConnectButtonPressed a socket
// 	 * to a remote address and port. Typically, the connection was refused
// 	 * remotely (e.g., no process is listening on the remote address/port).
// 	 */
// 	ConnectException,
// 
// 	/**
// 	 * Hostkey mismatch, hostkey changed since first connection this can mean that someone is trying to do a Man In The Middle attack
// 	 */
// 	BadSignatureException,
// 
// 	/**
// 	 * Wrong user name or password
// 	 */
// 	AuthenticationFailedException,
// 
// 	/**
// 	 * IO Level exception caught sending data
// 	 */
// 	SEND_ERROR,
// 
// 	/**
// 	 * IO Level exception caught receiving data
// 	 */
// 	RECEIVE_ERROR,
// 
// 	/**
// 	 * Something is not working but we don't know what/why
// 	 */
// 	UNKNOWN,
// }
// 
// Path: RetroShareAndroidIntegration/src/org/retroshare/android/RsCtrlService.java
// public class ConnectionEvent
// {
// 	public RsCtrlService trigger = RsCtrlService.this;
// 	public ConnectionEventKind kind;
// 
// 	ConnectionEvent(RsCtrlService trig, ConnectionEventKind k)
// 	{
// 		trigger = trig;
// 		kind = k;
// 	}
// 
// 	ConnectionEvent(ConnectionEventKind k) { kind = k; }
// }
// 
// Path: RetroShareAndroidIntegration/src/org/retroshare/android/RsCtrlService.java
// public interface RsCtrlServiceListener
// {
// 	/**
// 	 * Callback invoked on all registered listeners each time something happens
// 	 * @param ce a ConnectionEvent containing information about what happened
// 	 */
// 	public void onConnectionStateChanged(ConnectionEvent ce);
// }


import org.retroshare.android.RsCtrlService.ConnectionEvent;
import org.retroshare.android.RsCtrlService.RsCtrlServiceListener;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import org.retroshare.android.RsCtrlService.ConnectionError;
	
	// new new don't delete
	public static class HandlerThread extends Handler implements HandlerThreadInterface
	{
		@Override
		public void postToHandlerThread(Runnable r) { post(r); }
	}

	@Override
	public void onConnectionStateChanged(ConnectionEvent ce)
	{
		if( ce.kind == RsCtrlService.ConnectionEventKind.SERVER_DATA_CHANGED ) saveData();
		updateNotification();
	}
	
	private void updateNotification()
	{
		int icon;
		String tickerText;
		String contentTitle=(String) getResources().getText(R.string.app_name);
		String contentMessage;
		
		boolean isOnline = false, hasError = false;
		for( RsBund bund : serverBunds.values() )
		{
			if(bund.server.isOnline())
			{
				isOnline = true;
				break;
			}
// Path: RetroShareAndroidIntegration/src/org/retroshare/android/RsCtrlService.java
// public enum ConnectionError
// {
// 	/**
// 	 * No error
// 	 */
// 	NONE,
// 
// 	/**
// 	 * The IP address of the host could not be determined.
// 	 */
// 	UnknownHostException,
// 
// 	/**
// 	 * Signals that an error occurred while attempting to onConnectButtonPressed a socket
// 	 * to a remote address and port. Typically, the remote host cannot be
// 	 * reached because of an intervening firewall, or if an intermediate
// 	 * router is down.
// 	 */
// 	NoRouteToHostException,
// 
// 	/**
// 	 * Signals that an error occurred while attempting to onConnectButtonPressed a socket
// 	 * to a remote address and port. Typically, the connection was refused
// 	 * remotely (e.g., no process is listening on the remote address/port).
// 	 */
// 	ConnectException,
// 
// 	/**
// 	 * Hostkey mismatch, hostkey changed since first connection this can mean that someone is trying to do a Man In The Middle attack
// 	 */
// 	BadSignatureException,
// 
// 	/**
// 	 * Wrong user name or password
// 	 */
// 	AuthenticationFailedException,
// 
// 	/**
// 	 * IO Level exception caught sending data
// 	 */
// 	SEND_ERROR,
// 
// 	/**
// 	 * IO Level exception caught receiving data
// 	 */
// 	RECEIVE_ERROR,
// 
// 	/**
// 	 * Something is not working but we don't know what/why
// 	 */
// 	UNKNOWN,
// }
// 
// Path: RetroShareAndroidIntegration/src/org/retroshare/android/RsCtrlService.java
// public class ConnectionEvent
// {
// 	public RsCtrlService trigger = RsCtrlService.this;
// 	public ConnectionEventKind kind;
// 
// 	ConnectionEvent(RsCtrlService trig, ConnectionEventKind k)
// 	{
// 		trigger = trig;
// 		kind = k;
// 	}
// 
// 	ConnectionEvent(ConnectionEventKind k) { kind = k; }
// }
// 
// Path: RetroShareAndroidIntegration/src/org/retroshare/android/RsCtrlService.java
// public interface RsCtrlServiceListener
// {
// 	/**
// 	 * Callback invoked on all registered listeners each time something happens
// 	 * @param ce a ConnectionEvent containing information about what happened
// 	 */
// 	public void onConnectionStateChanged(ConnectionEvent ce);
// }


// Path: RetroShareAndroidIntegration/src/org/retroshare/android/RetroShareAndroidProxy.java
import org.retroshare.android.RsCtrlService.ConnectionEvent;
import org.retroshare.android.RsCtrlService.RsCtrlServiceListener;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import org.retroshare.android.RsCtrlService.ConnectionError;

	
	// new new don't delete
	public static class HandlerThread extends Handler implements HandlerThreadInterface
	{
		@Override
		public void postToHandlerThread(Runnable r) { post(r); }
	}

	@Override
	public void onConnectionStateChanged(ConnectionEvent ce)
	{
		if( ce.kind == RsCtrlService.ConnectionEventKind.SERVER_DATA_CHANGED ) saveData();
		updateNotification();
	}
	
	private void updateNotification()
	{
		int icon;
		String tickerText;
		String contentTitle=(String) getResources().getText(R.string.app_name);
		String contentMessage;
		
		boolean isOnline = false, hasError = false;
		for( RsBund bund : serverBunds.values() )
		{
			if(bund.server.isOnline())
			{
				isOnline = true;
				break;
			}
			else if(bund.server.getLastConnectionError() != ConnectionError.NONE) hasError = true;