// Path: java/anyremote/client/android/util/Address.java
// public class Address {
// 	public String name;
// 	public String URL;
// 	public String pass;	
// 	public boolean autoconnect;	
// }
// 
// Path: java/anyremote/client/android/util/InfoMessage.java
// public class InfoMessage {
// 	public int id;
// 	public int stage;
// }
// 
// Path: java/anyremote/client/android/util/ListItem.java
// public class ListItem {
// 	public String text;
//     public String icon;
// }
// 
// Path: java/anyremote/client/android/util/ProtocolMessage.java
// public class ProtocolMessage {
// 	public static final int FULL     = 0;
// 	public static final int FIRST    = 1;
// 	public static final int INTERMED = 2;
// 	public static final int LAST     = 3;
// 	
// 	public int id;
// 	public int stage;
// 	public Vector tokens;
// }


import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.TimerTask;
import java.util.Vector;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;
import anyremote.client.android.util.Address;
import anyremote.client.android.util.InfoMessage;
import anyremote.client.android.util.ListItem;
import anyremote.client.android.util.ProtocolMessage;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
	        case CMD_GETPING:    return "Get(ping)";
	        case CMD_GETICSIZE:  return "Get(icon_size)";
	        case CMD_GETPADDING: return "Get(icon_padding)";
	        case CMD_CLOSECONN:  return "CMD_CLOSECONN";
		    //case CMD_EXIT:     return "CMD_EXIT";
	        case CMD_EDIT_FORM_IP:   return "CMD_EDIT_FORM_IP";  // used for logging only ?
	        case CMD_EDIT_FORM_BT:   return "CMD_EDIT_FORM_BT";
	        case CMD_LIST_UPDATE:    return "CMD_LIST_UPDATE";
	        case CMD_SEARCH_DIALOG:  return "CMD_SEARCH_DIALOG";
            case CMD_SENSOR_DIALOG:  return "CMD_SENSOR_DIALOG";
	        case CMD_CLOSE:          return "CMD_CLOSE";
		}
		return "UNKNOWN";
	}
	
    private void handleGetCoverSizeCmd() {
	    Display d = context.getWindowManager().getDefaultDisplay(); 
        queueCommand("CoverSize("+(d.getWidth()*2)/3+",)");
    }

    private void handleGetScreeenSizeCmd() {
        Display display = context.getWindowManager().getDefaultDisplay(); 
        boolean rotated = (display.getOrientation() == Surface.ROTATION_90 ||
                           display.getOrientation() == Surface.ROTATION_270);
        String ori = (rotated ? "R" : "");
        
        queueCommand("SizeX("+display.getWidth() +","+ori+")");
        queueCommand("SizeY("+display.getHeight()+","+ori+")");
    }

// Path: java/anyremote/client/android/util/Address.java
// public class Address {
// 	public String name;
// 	public String URL;
// 	public String pass;	
// 	public boolean autoconnect;	
// }
// 
// Path: java/anyremote/client/android/util/InfoMessage.java
// public class InfoMessage {
// 	public int id;
// 	public int stage;
// }
// 
// Path: java/anyremote/client/android/util/ListItem.java
// public class ListItem {
// 	public String text;
//     public String icon;
// }
// 
// Path: java/anyremote/client/android/util/ProtocolMessage.java
// public class ProtocolMessage {
// 	public static final int FULL     = 0;
// 	public static final int FIRST    = 1;
// 	public static final int INTERMED = 2;
// 	public static final int LAST     = 3;
// 	
// 	public int id;
// 	public int stage;
// 	public Vector tokens;
// }


// Path: java/anyremote/client/android/Dispatcher.java
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.TimerTask;
import java.util.Vector;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;
import anyremote.client.android.util.Address;
import anyremote.client.android.util.InfoMessage;
import anyremote.client.android.util.ListItem;
import anyremote.client.android.util.ProtocolMessage;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

	        case CMD_GETPING:    return "Get(ping)";
	        case CMD_GETICSIZE:  return "Get(icon_size)";
	        case CMD_GETPADDING: return "Get(icon_padding)";
	        case CMD_CLOSECONN:  return "CMD_CLOSECONN";
		    //case CMD_EXIT:     return "CMD_EXIT";
	        case CMD_EDIT_FORM_IP:   return "CMD_EDIT_FORM_IP";  // used for logging only ?
	        case CMD_EDIT_FORM_BT:   return "CMD_EDIT_FORM_BT";
	        case CMD_LIST_UPDATE:    return "CMD_LIST_UPDATE";
	        case CMD_SEARCH_DIALOG:  return "CMD_SEARCH_DIALOG";
            case CMD_SENSOR_DIALOG:  return "CMD_SENSOR_DIALOG";
	        case CMD_CLOSE:          return "CMD_CLOSE";
		}
		return "UNKNOWN";
	}
	
    private void handleGetCoverSizeCmd() {
	    Display d = context.getWindowManager().getDefaultDisplay(); 
        queueCommand("CoverSize("+(d.getWidth()*2)/3+",)");
    }

    private void handleGetScreeenSizeCmd() {
        Display display = context.getWindowManager().getDefaultDisplay(); 
        boolean rotated = (display.getOrientation() == Surface.ROTATION_90 ||
                           display.getOrientation() == Surface.ROTATION_270);
        String ori = (rotated ? "R" : "");
        
        queueCommand("SizeX("+display.getWidth() +","+ori+")");
        queueCommand("SizeY("+display.getHeight()+","+ori+")");
    }

    public void handleCommand(ProtocolMessage msg) {