package com.safemobile.activities; import java.util.ArrayList; import java.util.Hashtable; import com.safemobile.bluetooth.BluetoothTether; import com.safemobile.lib.AppParams; import com.safemobile.lib.SM; import com.safemobile.lib.SuperVehicle; import com.safemobile.lib.Vehicle; import com.safemobile.services.TCPhandler; import com.safemobile.services.TCPmsgParser; import android.app.Activity; import android.app.NotificationManager; import android.app.TabActivity; import android.content.BroadcastReceiver; import android.content.Context; import android.os.Handler; import android.widget.ImageView; import android.widget.RelativeLayout; @SuppressWarnings("deprecation") public abstract class AbstractSDParentActivity extends TabActivity { /** UI Elements */ public RelativeLayout layoutLoading; public ImageView imageViewLoading; /** Misc */ public Activity activity; public Context context; public NotificationManager mNotificationManager; public boolean displayLogCat = true; // show logCat messages when TCP send was successful public String imei, mess; public int demoPosition = 0; /** Lists */ public ArrayList allVehicle = new ArrayList(); public Hashtable SuperVehHash = new Hashtable(); public Hashtable VehHashbySc_id = new Hashtable(); /** Handler */ public Handler myHandler = new Handler(); /** BlueTooth Tether */ public BluetoothTether bluetoothTether = null; /** Broadcast Receiver */ public BroadcastReceiver mReceiver = null; /** TCP */ protected TCPhandler tcp = null; protected TCPmsgParser tcpParser = null; /** Methods */ public abstract void displayToast(final String msg); public abstract void whenBackPressed(AppParams.ActivityResult result); public abstract void changeLanguage(); public abstract void enableMenuButtons(boolean enable); public abstract void setRadioActivity(AbstractRadioActivity radioActivity); public abstract void setLiveActivity(AbstractLiveActivity liveActivity); public abstract void setMessagesActivity(AbstractMessagesActivity messageActivity); /** get if TCP is connected or disconnected or null */ public Object getTCPState() { // return true if tcp connection is on, false if not connected and null if(tcp!=null && tcp.isConnectionUP) return "true"; else if(tcp!=null && !tcp.isConnectionUP) return "false"; return null; } public abstract void unregisterReceivers(BroadcastReceiver receiver); public abstract void cancelNotification(int drawable); public abstract void stopTCP(); public abstract void stopTCPParser(); public abstract void executeNetworkStuff(String[] params); public abstract void recreateTCPConnection(); public abstract void removeITCPListener(); public abstract void updateDemoPosition(); public abstract void updateResultsPollInUi(String type); public abstract double best_zoom(double LATMAX,double LATmin,double LNGMAX,double LNGmin); /* SafeDispatch Mobile functions */ /** get Vehicles for an user id */ public boolean getVehicles(int userID) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#21#" + AppParams.USERID + "#"); if(res && displayLogCat) SM.Debug("Message (getVehs) sent to app server"); else SM.Debug("Could not send message(getVehs)!!"); return res; } /** get vehicles Last Positions for an user id */ public boolean getLastPositions(int userID) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#25#" + userID + "#"); if(res && displayLogCat) SM.Debug("Message (getLastPOS) sent to app server"); else SM.Debug("Could not send message(getLastSMS)!!"); return res; } /** set Enable/Disable a vehicle */ public boolean setVehicleStatus(int radioCode, int opCode, int sc_id, int enable) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#"+radioCode+"#"+opCode+"#" + sc_id+"#" + enable + "#"); if(res && displayLogCat) SM.Debug("Message (Option4Unit) sent to app server radioCode:"+radioCode+ " opCode:"+opCode+ " sc_id:"+sc_id+ " value:" + enable); else SM.Debug("Could not send message(Option4Unit)!!"); return res; } /** get Last SMSs for an user */ public boolean getLastSMSs(int userID) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#23#" + userID + "#"); if(res && displayLogCat) SM.Debug("#Send Request#", "Message [getLastSMSs] sent to app server"); else SM.Debug("#Send Request#", "Could not send message [getLastSMSs]!!"); return res; } /** get SMSs for an user that are recent than timeGMT * @param sc_id the vehicle imei for which we want the SMSs * @param timeGMT the unix time for the last message in the grid or messages that are newer than this time */ public boolean getRecentSMSs(int sc_id, long timeGMT) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#22#"+sc_id+"#" +timeGMT+"#"); if(res && displayLogCat) SM.Debug("#Send Request#", "Message [getRecentSMSs] sent to app server"); else SM.Debug("#Send Request#", "Could not send message [getRecentSMSs]!!"); return res; } /** send a SMS to a vehicle * @param seqID is a unique identifier for the SMS * @param sc_id vehicle imei to which you want to send the SMS * @param txt the message to be send */ public boolean sendSMS(String seqID, int sc_id, String txt) { if(tcp == null) return false; boolean res = tcp.Write(seqID, "#24#" + AppParams.USERID + "#" + sc_id + "#" + txt + "#"); if(res && displayLogCat) SM.Debug("Message [sendSMS] sent to app server sc_id:"+sc_id+ " txt:"+txt); else SM.Debug("Could not send message [sendSMS]!!"); return res; } public boolean sendAlarmAcknoledge(int alarm_id, int type) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#28#" + alarm_id + "#" + type + "#"); if(res) SM.Debug("Message [sendAlarmAcknoledge] sent to app server alarm_id:" + alarm_id + " type:" + type); else SM.Debug("Could not send message [sendAlarmAcknoledge]!!"); return res; } public boolean sendPlayRecordingRequest(long record_id) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#18#" + record_id + "#"); if(res) SM.Debug("Message [sendPlayRecordingRequest] sent to app server record_id:"+record_id); else SM.Debug("Could not send message [sendPlayRecordingRequest]!!"); return res; } public boolean sendDekey(int gwID, int radioID) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#30#160#" + gwID + "." + radioID + "#"); if(res) SM.Debug("Message [sendDekey] sent to app server record_id"); else SM.Debug("Could not send message [sendDeKey]!!"); return res; } public boolean getHistoryPositions(int sc_id, long timeGMTStart, long timeGMTStop) { if(tcp == null) return false; String histSeqID = "1."+Integer.toString((int) (System.currentTimeMillis() / 1000L)); boolean res = tcp.Write(histSeqID,"#26#"+sc_id+"#"+timeGMTStart+"#"+timeGMTStop+"#"); if(res) SM.Debug("Message [getHistoryPositions] sent to app server"); else SM.Debug("Could not send message [getHistoryPositions]!!"); return res; } public boolean getRadiosList() { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#30#100#"); if(res) SM.Debug("Message [getRadiosList] sent to app server"); else SM.Debug("Could not send message [getRadiosList]!!"); return res; } // if zoneNr=0 and channelNR =0 then function acts as GET public boolean getSetZoneAndChannel(int gwID, int rgwID, int zoneNR, int channelNR) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#30#104#" + gwID + "#" + rgwID + "#" + zoneNR + "#" +channelNR +"#"); if(res) SM.Debug("Message [GetSetZoneAndChannel] sent to app server zoneNR:"+zoneNR+ " channelNR:"+channelNR); else SM.Debug("Could not send message [GetSetZoneAndChannel]!!"); return res; } public boolean getRadioStatus(int gwID, int rgwID) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#30#99#" + gwID + "#" + rgwID + "#"); if(res) SM.Debug("Message [RadioGetRadioList] sent to app server || gwID: " + gwID + " | rgwID: " + rgwID); else SM.Debug("Could not send message [getLastSMS]!!"); return res; } public boolean getAlarms(long userID) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#27#" + userID + "#"); // = tcp.Write("0.0", "#30#99#" + gwID + "#" + rgwID + "#"); if(res) SM.Debug("Message [GetAlarms] sent to app server"); else SM.Debug("Could not send message [GetAlarms]!!"); return res; } public boolean getRecordings(int gwID, int radioID) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#29#"+AppParams.USERID+"#"+ gwID +"#"+ radioID +"#"); if(res) SM.Debug("Message [GetRecordings] sent to app server"); else SM.Debug("Could not send message [GetRecordings]!!"); return res; } //public abstract void getVehiclePosition(long imei); /* public abstract void onResume(); public abstract void onStart(); public abstract void onPause(); */ }