package com.safemobile.activities; import android.app.TabActivity; import android.content.BroadcastReceiver; 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 java.util.ArrayList; import java.util.Hashtable; @SuppressWarnings("deprecation") public abstract class AbstractSDParentActivity extends TabActivity { /** Misc */ private static final boolean SHOULD_DISPLAY_LOGCAT = true; // show logCat messages when TCP send was successful private String imei; private String mess; public int demoPosition = 0; private ArrayList allVehicle = new ArrayList<>(); private Hashtable superVehHash = new Hashtable<>(); private Hashtable vehHashByScId = new Hashtable<>(); /** 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) 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#" + userID + "#"); if (res && SHOULD_DISPLAY_LOGCAT) 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 && SHOULD_DISPLAY_LOGCAT) 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 && SHOULD_DISPLAY_LOGCAT) 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 && SHOULD_DISPLAY_LOGCAT) 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 && SHOULD_DISPLAY_LOGCAT) 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 && SHOULD_DISPLAY_LOGCAT) 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 sendAlarmAcknowledge(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 [sendAlarmAcknowledge] sent to app server alarm_id:" + alarm_id + " type:" + type); else SM.Debug("Could not send message [sendAlarmAcknowledge]!!"); 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 + "#"); 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 String getImei() { return imei; } public void setImei(String imei) { this.imei = imei; } public String getMess() { return mess; } public void setMess(String mess) { this.mess = mess; } /** Lists */ public ArrayList getAllVehicle() { return allVehicle; } public void setAllVehicle(ArrayList allVehicle) { this.allVehicle = allVehicle; } public Hashtable getSuperVehHash() { return superVehHash; } public void setSuperVehHash(Hashtable superVehHash) { this.superVehHash = superVehHash; } public Hashtable getVehHashByScId() { return vehHashByScId; } public void setVehHashByScId(Hashtable vehHashByScId) { this.vehHashByScId = vehHashByScId; } }