From 34c578fdf500d34aa5bc1998d6d9d2d4a85f39bb Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 23 Mar 2022 13:07:40 +0200 Subject: [PATCH] SD-188 - cleaned up TabLayoutActivity of unused code - small refactor - null checks --- .../safemobile/interfaces/ITCPListener.java | 8 +- .../com/safemobile/services/TCPmsgParser.java | 3 +- .../safemobile/dispatch/AlarmActivity.java | 2 +- .../safemobile/dispatch/HistoryActivity.java | 4 +- .../com/safemobile/dispatch/LiveActivity.java | 2 +- .../safemobile/dispatch/MessagesActivity.java | 2 +- .../safemobile/dispatch/RadioActivity.java | 82 +- .../dispatch/RecordingsActivity.java | 18 +- .../safemobile/dispatch/SDMobileActivity.java | 6 +- .../dispatch/SDMobileActivity_beforeMod.java | 8 +- .../safemobile/dispatch/SetupActivity.java | 4 +- .../dispatch/TabLayoutActivity.java | 3645 +++++++---------- 12 files changed, 1642 insertions(+), 2142 deletions(-) diff --git a/libSafeMobile/src/main/java/com/safemobile/interfaces/ITCPListener.java b/libSafeMobile/src/main/java/com/safemobile/interfaces/ITCPListener.java index 4b38556..c88ab20 100644 --- a/libSafeMobile/src/main/java/com/safemobile/interfaces/ITCPListener.java +++ b/libSafeMobile/src/main/java/com/safemobile/interfaces/ITCPListener.java @@ -16,7 +16,7 @@ public interface ITCPListener { public void onHistoryPositionsCountReceived( TCPEvent event ); public void onAlarmsReceived( TCPEvent event ); public void onAlarmAckReceived(TCPEvent event); - public void alarmLiveRecv(TCPEvent event); + public void alarmLiveReceived(TCPEvent event); public void onRecordingPlayReceived(TCPEvent event); public void onPollReceived(TCPEvent event); @@ -27,7 +27,7 @@ public interface ITCPListener { public void onRecordingsListReceived(TCPEvent event); public void onPONGReceived(); - public void onTCPConnectionDown(boolean previuosWasConnectionUp); - public void onTCPConnectionUp(boolean previuosWasConnectionUp); - public void onTCPConnectionStatusReceived(boolean isConnectionUp, boolean previuosWasConnectionUp); + public void onTCPConnectionDown(boolean previousWasConnectionUp); + public void onTCPConnectionUp(boolean previousWasConnectionUp); + public void onTCPConnectionStatusReceived(boolean isConnectionUp, boolean previousWasConnectionUp); } diff --git a/libSafeMobile/src/main/java/com/safemobile/services/TCPmsgParser.java b/libSafeMobile/src/main/java/com/safemobile/services/TCPmsgParser.java index 51a579a..e528666 100644 --- a/libSafeMobile/src/main/java/com/safemobile/services/TCPmsgParser.java +++ b/libSafeMobile/src/main/java/com/safemobile/services/TCPmsgParser.java @@ -10,7 +10,6 @@ import com.safemobile.interfaces.TCPEvent; import com.safemobile.lib.OperationCodes; import com.safemobile.lib.SM; import com.safemobile.lib.TCPmsg; -import com.safemobile.services.TCPhandler; public class TCPmsgParser implements Runnable{ @@ -150,7 +149,7 @@ public class TCPmsgParser implements Runnable{ TCPEvent event = new TCPEvent( this, _msg ); Iterator listeners = _listeners.iterator(); while( listeners.hasNext() ) { - ( (ITCPListener) listeners.next() ).alarmLiveRecv(event); + ( (ITCPListener) listeners.next() ).alarmLiveReceived(event); } } diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/AlarmActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/AlarmActivity.java index 70631e5..38fa774 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/AlarmActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/AlarmActivity.java @@ -76,7 +76,7 @@ public class AlarmActivity extends Activity { textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf")); textView1.setTextSize(24); - getParentTab().alarmActivity = this; + getParentTab().setAlarmActivity(this); } @Override diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java index eaa171c..bff2914 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java @@ -42,12 +42,12 @@ public class HistoryActivity extends AppCompatActivity { setContentView(R.layout.tabhistory); parentTab = (TabLayoutActivity) getParent(); - parentTab.historyActivity = this; + parentTab.setHistoryActivity(this); Locale locale = new Locale(AppParams.LANGUAGETMP); Locale.setDefault(locale); - googleMap = parentTab.liveActivity.getMap(); + googleMap = parentTab.getLiveActivity().getMap(); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/LiveActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/LiveActivity.java index 34d0e31..6dfd492 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/LiveActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/LiveActivity.java @@ -112,7 +112,7 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall // get parentTab setParentTab((AbstractSDParentActivity) getParent()); try { - ((TabLayoutActivity) getParentTab()).liveActivity = this; + ((TabLayoutActivity) getParentTab()).setLiveActivity(this); } catch (Exception ignored) { // ignored } diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java index b40e85d..e6c048e 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java @@ -215,7 +215,7 @@ public class MessagesActivity extends Activity { gridView.setId(1); // id needed for IconContextMenu registerForContextMenu(gridView); - parentTab.messageActivity = this; + parentTab.setMessageActivity(this); } // Create runnable for posting diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/RadioActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/RadioActivity.java index 30f59e5..7ab7cf2 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/RadioActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/RadioActivity.java @@ -236,7 +236,7 @@ public class RadioActivity extends Activity { } // send current activity to parrent - parentTab.radioActivity = this; + parentTab.setRadioActivity(this); // register to be notified when an event is triggered registerBroadcastIntents(); @@ -315,10 +315,10 @@ public class RadioActivity extends Activity { if(!pttONoff) { String chanMsg = "", statMsg = ""; - if(parentTab.crtRadio!= null) - SendPTT(selectedCallType, selectedID,parentTab.crtRadio.GW_ID, parentTab.crtRadio.ID,AppParams.USERID); + if(parentTab.getCrtRadio() != null) + SendPTT(selectedCallType, selectedID, parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID,AppParams.USERID); // flag in Call - parentTab.inCall = true; + parentTab.setInCall(true); pttONoff= true; if(audioH!=null) audioH.soundNeeded = true; @@ -381,7 +381,7 @@ public class RadioActivity extends Activity { { String chanMsg = "", statMsg = ""; if(!AppParams.DEMO) - SendPTT(selectedCallType+10, 1,parentTab.crtRadio.GW_ID, parentTab.crtRadio.ID,AppParams.USERID); + SendPTT(selectedCallType+10, 1, parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID,AppParams.USERID); pttONoff= false; if(audioH!=null) audioH.soundNeeded = false; @@ -417,7 +417,7 @@ public class RadioActivity extends Activity { @Override public void onClick(View v) { - if(parentTab.crtRadio!=null) + if(parentTab.getCrtRadio() !=null) { // display dialog with adapter ArrayList tmp = new ArrayList(); @@ -438,7 +438,7 @@ public class RadioActivity extends Activity { //textViewChannel.setText(crtChannels.get(which).chName); // send change to App - onZoneCHChange(parentTab.crtRadio.ID, parentTab.crtRadio.GW_ID, getNR4Zone(textViewZone.getText().toString()), getNR4CH(crtChannels.get(which).chName)); + onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, getNR4Zone(textViewZone.getText().toString()), getNR4CH(crtChannels.get(which).chName)); } }); @@ -492,7 +492,7 @@ public class RadioActivity extends Activity { @Override public void onClick(View v) { - if(parentTab.crtRadio!=null) + if(parentTab.getCrtRadio() !=null) { // display dialog with adapter ArrayList tmp = new ArrayList(); @@ -511,7 +511,7 @@ public class RadioActivity extends Activity { // send change to App //onZoneCHChange(parentTab.crtRadio.ID, parentTab.crtRadio.GW_ID, getNR4Zone(crtZones.get(which).ZoneName), getNR4CH(textViewChannel.getText().toString())); - onZoneCHChange(parentTab.crtRadio.ID, parentTab.crtRadio.GW_ID, getNR4Zone(crtZones.get(which).ZoneName), 1); + onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, getNR4Zone(crtZones.get(which).ZoneName), 1); } }); @@ -560,7 +560,7 @@ public class RadioActivity extends Activity { @Override public void onClick(View v) { - if(parentTab.crtRadio!=null) + if(parentTab.getCrtRadio() !=null) { // create spinner selected AlertDialog.Builder builder = new AlertDialog.Builder(context); @@ -686,17 +686,17 @@ public class RadioActivity extends Activity { { // save radios AppParams.listRadios = radios; - if(parentTab.crtRadio == null) - parentTab.crtRadio = AppParams.listRadios.get(0); + if(parentTab.getCrtRadio() == null) + parentTab.setCrtRadio(AppParams.listRadios.get(0)); // if crtRadio not exists anymore - if(!AppParams.listRadios.contains(parentTab.crtRadio)) - parentTab.crtRadio = AppParams.listRadios.get(0); + if(!AppParams.listRadios.contains(parentTab.getCrtRadio())) + parentTab.setCrtRadio(AppParams.listRadios.get(0)); - SM.Debug(parentTab.crtRadio.toString()); + SM.Debug(parentTab.getCrtRadio().toString()); // get status for selected Radio - ReqRadioStatus(parentTab.crtRadio.ID, parentTab.crtRadio.GW_ID); + ReqRadioStatus(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID); // get selected Zone and CH - onZoneCHChange(parentTab.crtRadio.ID, parentTab.crtRadio.GW_ID, 0,0); + onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, 0,0); myHandler.post(updateGatewaysRUN); } @@ -716,7 +716,7 @@ public class RadioActivity extends Activity { allGWsIP.clear(); for(RadioGW radio: AppParams.listRadios) allGWsIP.add(radio.IP); - textViewGateway.setText(parentTab.crtRadio.IP); + textViewGateway.setText(parentTab.getCrtRadio().IP); } @@ -743,20 +743,20 @@ public class RadioActivity extends Activity { SM.Debug("am primit: " + _radioID + "," + _GWID + "," + _zoneNR + "," + _chNR); - if ((parentTab.crtRadio == null)||((parentTab.crtRadio.GW_ID == _GWID)&&(parentTab.crtRadio.ID == _radioID))) + if ((parentTab.getCrtRadio() == null)||((parentTab.getCrtRadio().GW_ID == _GWID)&&(parentTab.getCrtRadio().ID == _radioID))) { // update crtRadios, crtZones, and crtChannel for(RadioGW radio: AppParams.listRadios) if(radio.GW_ID == _GWID && radio.ID == _radioID) { - parentTab.crtRadio = radio; + parentTab.setCrtRadio(radio); crtZones = radio.zoneList; cmdForMe = true; } } if (cmdForMe) { - for(Zone zone: parentTab.crtRadio.zoneList) + for(Zone zone: parentTab.getCrtRadio().zoneList) if(zone.id == _zoneNR) crtChannels = zone.channelList; // update UI @@ -776,7 +776,7 @@ public class RadioActivity extends Activity { if(AppParams.listRadios.size()>0) { - textViewGateway.setText(parentTab.crtRadio.IP); + textViewGateway.setText(parentTab.getCrtRadio().IP); // get all radio IP allGWsIP.clear(); @@ -784,13 +784,13 @@ public class RadioActivity extends Activity { allGWsIP.add(radio.IP); // set spinners and text - if(parentTab.crtRadio == null) + if(parentTab.getCrtRadio() == null) { - parentTab.crtRadio = AppParams.listRadios.get(0); + parentTab.setCrtRadio(AppParams.listRadios.get(0)); textViewGateway.setText(allGWsIP.get(0)); // set zone ArrayList zones = new ArrayList(); - crtZones = parentTab.crtRadio.zoneList; + crtZones = parentTab.getCrtRadio().zoneList; for(Zone zone: crtZones) zones.add(zone.ZoneName); @@ -799,7 +799,7 @@ public class RadioActivity extends Activity { //spinnerZone.setSelection(0); // set channel ArrayList channel = new ArrayList(); - crtChannels = parentTab.crtRadio.zoneList.get(0).channelList; + crtChannels = parentTab.getCrtRadio().zoneList.get(0).channelList; for(Channel ch: crtChannels) channel.add(ch.chName); textViewChannel.setText(channel.get(0).toString()); @@ -811,10 +811,10 @@ public class RadioActivity extends Activity { { for(RadioGW radio: AppParams.listRadios) if(radio.ID == radioID && radio.GW_ID == GWID) - parentTab.crtRadio = radio; + parentTab.setCrtRadio(radio); // get zones for adapter ArrayList zones = new ArrayList(); - crtZones = parentTab.crtRadio.zoneList; + crtZones = parentTab.getCrtRadio().zoneList; int position = 0; // get selected Zone for(int i=0; i< crtZones.size(); i++) @@ -828,7 +828,7 @@ public class RadioActivity extends Activity { // set channel ArrayList channel = new ArrayList(); - crtChannels = parentTab.crtRadio.zoneList.get(position).channelList; + crtChannels = parentTab.getCrtRadio().zoneList.get(position).channelList; position = 0; // get current channel for(int i=0; i< crtChannels.size(); i++) @@ -856,7 +856,7 @@ public class RadioActivity extends Activity { { UpdateEnableDisableButtons("offline"); onZoneCHChange(radio.ID, radio.GW_ID,0,0); // get zone and channel for crt radio - parentTab.crtRadio = radio; + parentTab.setCrtRadio(radio); } textViewGateway.setText(newIP); @@ -957,10 +957,10 @@ public class RadioActivity extends Activity { buttonPTT.setEnabled(true); buttonDKey.setEnabled(false); } - if(parentTab.crtActivity == parentTab.RADIO && selectedCallType == calltype) + if(parentTab.getCrtActivity() == parentTab.RADIO_TAB_ID && selectedCallType == calltype) parentTab.enableMenuButtons(false); if(selectedCallType == calltype) - parentTab.inCall = true; + parentTab.setInCall(true); } else if (callstatus==3) @@ -986,7 +986,7 @@ public class RadioActivity extends Activity { } parentTab.enableMenuButtons(true); - parentTab.inCall = false; + parentTab.setInCall(false); } } } @@ -1182,8 +1182,8 @@ public class RadioActivity extends Activity { // send Dekey to AppServer private void SendDekey() { - if(parentTab.crtRadio != null) - parentTab.sendDekey(parentTab.crtRadio.GW_ID, parentTab.crtRadio.ID); + if(parentTab.getCrtRadio() != null) + parentTab.sendDekey(parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID); } // send change Channel and Zone message to AppServer @@ -1215,8 +1215,8 @@ public class RadioActivity extends Activity { //113 -grpcall stop public void SendPTT(int callType, int id,int gwid, int rgwid,long userID) { - SM.Debug("SendPTT callType:"+callType); - parentTab.SendPTT(callType, id,gwid,rgwid,userID); + SM.Debug("sendPTT callType:"+callType); + parentTab.sendPTT(callType, id,gwid,rgwid,userID); } @@ -1241,13 +1241,13 @@ public class RadioActivity extends Activity { UpdateZoneCH(zc.rgwID, zc.gwID, zc.zoneNr, zc.channelNr); } else if (action.equals(OperationCodes.RADIOID_CHANGED+"")) { - textViewGateway.setText(parentTab.crtRadio.IP); - textViewChannel.setText(parentTab.crtRadio.getChannelName()); - textViewZone.setText(parentTab.crtRadio.getZoneName()); + textViewGateway.setText(parentTab.getCrtRadio().IP); + textViewChannel.setText(parentTab.getCrtRadio().getChannelName()); + textViewZone.setText(parentTab.getCrtRadio().getZoneName()); // update UI myHandler.post(UpdateResultsZoneChannelRUN); - radioGWChanged(parentTab.crtRadio.IP); + radioGWChanged(parentTab.getCrtRadio().IP); } } }; diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/RecordingsActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/RecordingsActivity.java index c22f103..92d2431 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/RecordingsActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/RecordingsActivity.java @@ -127,7 +127,7 @@ public class RecordingsActivity extends Activity { // change gateway textViewGateway.setText(allGWsIP.get(which)); Toast.makeText(context, getString(R.string.loadingRecordings), Toast.LENGTH_SHORT).show(); - GetRecordings(parentTab.allRadios.get(which).GW_ID, parentTab.allRadios.get(which).ID); + GetRecordings(parentTab.getAllRadios().get(which).GW_ID, parentTab.getAllRadios().get(which).ID); } }); AlertDialog alert = builder.create(); @@ -137,7 +137,7 @@ public class RecordingsActivity extends Activity { textViewGateway.setVisibility(View.INVISIBLE); - parentTab.recordingsActivity = this; + parentTab.setRecordingsActivity(this); // register to receive broadcasts registerBroadcastIntents(); @@ -208,17 +208,17 @@ public class RecordingsActivity extends Activity { Toast.makeText(context, getString(R.string.moreRecordings), Toast.LENGTH_SHORT).show(); - if(parentTab.crtRadio != null) - textViewGateway.setText(parentTab.crtRadio.IP); + if(parentTab.getCrtRadio() != null) + textViewGateway.setText(parentTab.getCrtRadio().IP); /* if(parentTab.allRadios == null) GetGWRadios(); */ - if(playingPosition < 0 && parentTab.crtRadio != null) + if(playingPosition < 0 && parentTab.getCrtRadio() != null) { - SM.Debug("GetRecordings resume + crtRadio:"+parentTab.crtRadio.toString()); - GetRecordings(parentTab.crtRadio.GW_ID, parentTab.crtRadio.ID); + SM.Debug("GetRecordings resume + crtRadio:"+ parentTab.getCrtRadio().toString()); + GetRecordings(parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID); } } @@ -402,8 +402,8 @@ public class RecordingsActivity extends Activity { updateNumberOfRecordings(); } else if (action.equals(OperationCodes.RADIOID_CHANGED+"")) { - textViewGateway.setText(parentTab.crtRadio.IP); - GetRecordings(parentTab.crtRadio.GW_ID, parentTab.crtRadio.ID); + textViewGateway.setText(parentTab.getCrtRadio().IP); + GetRecordings(parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID); } } }; diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity.java index 20484f1..8e1943f 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity.java @@ -965,7 +965,7 @@ public class SDMobileActivity extends Activity { } @Override - public void alarmLiveRecv(TCPEvent event) { + public void alarmLiveReceived(TCPEvent event) { } @Override @@ -994,7 +994,7 @@ public class SDMobileActivity extends Activity { } @Override - public void onTCPConnectionDown(boolean previuosWasConnectionUp) { + public void onTCPConnectionDown(boolean previousWasConnectionUp) { SM.Debug("TCP connection with:" + (tcp != null ? tcp.serverHostname : AppParams.RADIOIP) + ":" + (tcp != null ? tcp.getPort() : 0) + " is DOWN!!!"); // update ui only when a change happens with tcp connection @@ -1034,7 +1034,7 @@ public class SDMobileActivity extends Activity { } @Override - public void onTCPConnectionStatusReceived(boolean isConnectionUp, boolean previuosWasConnectionUp) { + public void onTCPConnectionStatusReceived(boolean isConnectionUp, boolean previousWasConnectionUp) { } diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity_beforeMod.java b/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity_beforeMod.java index 630f4d9..ebb03b5 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity_beforeMod.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity_beforeMod.java @@ -1403,7 +1403,7 @@ public class SDMobileActivity_beforeMod extends Activity { public void onAlarmAckReceived(TCPEvent event) { } @Override - public void alarmLiveRecv(TCPEvent event) { } + public void alarmLiveReceived(TCPEvent event) { } @Override @@ -1425,7 +1425,7 @@ public class SDMobileActivity_beforeMod extends Activity { public void onRecordingsListReceived(TCPEvent event) { } @Override - public void onTCPConnectionDown(boolean previousConnectionWasUP) { + public void onTCPConnectionDown(boolean previousWasConnectionUp) { SM.Debug("TCP Connection Down"); // set connection is down @@ -1450,7 +1450,7 @@ public class SDMobileActivity_beforeMod extends Activity { } @Override - public void onTCPConnectionUp(boolean previousConnectionWasUP) { + public void onTCPConnectionUp(boolean previousWasConnectionUp) { SM.Debug("TCP Connection UP"); // set connection is up @@ -1505,7 +1505,7 @@ public class SDMobileActivity_beforeMod extends Activity { } @Override - public void onTCPConnectionStatusReceived(final boolean isConnectionUp, boolean previuosWasConnectionUp) { + public void onTCPConnectionStatusReceived(final boolean isConnectionUp, boolean previousWasConnectionUp) { //SM.Debug("TCP STATUS", "ConnectionUP: " + isConnectionUp + " | previous: " + previuosWasConnectionUp ); /* if(!lastTCPstatus && isConnectionUp) { diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/SetupActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/SetupActivity.java index 37a2450..a1b530f 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/SetupActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/SetupActivity.java @@ -199,7 +199,7 @@ public class SetupActivity extends Activity { // get default com port //COMPORT = prefs.getString("comport", "n/a"); // get Language - AppParams.LANGUAGE = AppParams.prefs.getString("language", parentTab.databaseLanguage); + AppParams.LANGUAGE = AppParams.prefs.getString("language", parentTab.DATABASE_LANGUAGE); } catch(Exception ex) { @@ -245,7 +245,7 @@ public class SetupActivity extends Activity { parentTab.stopTCPParser(); // recreate TCP with new settings parentTab.loadSettings(); - parentTab.TCPinit(); + parentTab.tcpInit(); */ // start thread to add listener /* diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java index 1c94bd5..78a2a57 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java @@ -9,6 +9,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Locale; +import java.util.Objects; import java.util.Timer; import java.util.TimerTask; @@ -45,6 +46,7 @@ import com.safemobile.services.TCPService; import com.safemobile.services.TCPhandler; import com.safemobile.services.TCPService.TCPBinder; +import android.annotation.SuppressLint; import android.app.Dialog; import android.app.Notification; import android.app.NotificationManager; @@ -63,11 +65,9 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; +import android.os.Looper; import android.util.Log; -import android.view.MotionEvent; import android.view.View; -import android.view.View.OnClickListener; -import android.view.View.OnTouchListener; import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.AnimationUtils; @@ -81,278 +81,407 @@ import android.widget.TextView; import android.widget.Toast; import android.widget.TabHost.TabSpec; -public class TabLayoutActivity extends AbstractSDParentActivity{ - +public class TabLayoutActivity extends AbstractSDParentActivity { + /* Misc */ private Resources res; private Context context; - - public RadioGW crtRadio = null; - public int crtActivity = 0, RADIO = 4; - private Boolean isMenuVisible = true, firstGetVehs = true, lastTCPstatus = false; - private Boolean NOSOUND = false; - public Boolean inCall = false; - - //public boolean DEMO; // value received through intent.getExtra() - - + + public static final int RADIO_TAB_ID = 4; + private static final String HASH_ERROR_MESSAGE = "Error load hash: "; + private static final boolean NO_SOUND = false; + private boolean isMenuVisible = true; + private boolean isFirstGetVehicles = true; + private boolean lastTcpStatus = false; + private boolean isInCall = false; + + private int crtActivity = 0; + private RadioGW crtRadio = null; + private MsgType activePopupType = MsgType.TCP; + /* Activities */ - public AbstractLiveActivity liveActivity = null; - public RadioActivity radioActivity = null; - public MessagesActivity messageActivity = null; - public HistoryActivity historyActivity = null; - public RecordingsActivity recordingsActivity = null; - public AlarmActivity alarmActivity = null; - + private AbstractLiveActivity liveActivity = null; + private RadioActivity radioActivity = null; + private MessagesActivity messageActivity = null; + private HistoryActivity historyActivity = null; + private RecordingsActivity recordingsActivity = null; + private AlarmActivity alarmActivity = null; + /* Handler for callbacks to the UI thread */ - public final Handler myHandler = new Handler(); + public final Handler myHandler = new Handler(Looper.getMainLooper()); /* Lists */ - public ArrayList allRadios; - public volatile ArrayList HistPosList = new ArrayList(); - public volatile Boolean firstHistData = false; - public volatile Boolean dropAllData = false; - public volatile ArrayList HistMsgList = new ArrayList(); - + private ArrayList allRadios; + private ArrayList historyPositionList = new ArrayList<>(); + private volatile Boolean firstHistoryData = false; + private volatile Boolean dropAllData = false; + private ArrayList historyMessageList = new ArrayList<>(); + /* DEMO lists */ - public ArrayList listSMS; - public ArrayList demoPositions = new ArrayList(); - + private ArrayList demoSmsList; + private ArrayList demoPositions = new ArrayList<>(); + /* Tab */ - private TabWidget tabWidget; - private TabSpec[] tabspecs; private TabHost tabHost; - private Intent[] intent; - + /* Visual Elements */ - private LinearLayout layoutMenu, layoutSlideMenu; private RelativeLayout layoutNewMessage; - private TextView textViewNMMessage, textViewNMFrom = null, slideTabsText; - private ImageView imageViewSlideMenu, imageViewPopUp, imageViewClose; - private ImageButton buttonLive, buttonHistory, buttonText, buttonRadio, buttonAlarms, buttonRecordings, buttonSetup, buttonLogo; - - - /* Notification */ - private Intent notificationIntent; - private final int NOTIFICATION_ACTIVITY_RESULT = 1; + private TextView textViewNMMessage; + private TextView textViewNMFrom = null; + private TextView slideTabsText; + private ImageView imageViewPopUp; + private ImageView imageViewClose; + private ImageButton buttonLive; + private ImageButton buttonHistory; + private ImageButton buttonText; + private ImageButton buttonRadio; + private ImageButton buttonAlarms; + private ImageButton buttonRecordings; + private ImageButton buttonSetup; + + /* NOTIFICATION */ + private static final int NOTIFICATION_ACTIVITY_RESULT = 1; private NotificationManager mNotificationManager; - + /* TCP */ protected Timer tcpTimer;//timer to check connection!!! - - /** TCP Service */ + + /* TCP Service */ private TCPService myService; private boolean isBound = false; - - /* User details */ - //protected int userID = 1;// ID of loged in userr - //public String userName; - - // default app language - public String databaseLanguage = "en"; // database language : en, de, tr, ro or empty - - - public enum MsgType { TCP,SMS,POLL,ALARM}; - - public MsgType activePopupType = MsgType.TCP; - - /** Called when the activity is first created. */ - public void onCreate(Bundle savedInstanceState) { - - if(AppParams.theme == AppParams.Theme.SAFENET) - this.setTheme(R.style.Theme_Safenet); - else if(AppParams.theme == AppParams.Theme.VISION) - this.setTheme(R.style.Theme_Vision); - else if(AppParams.theme == AppParams.Theme.HYTERA) - this.setTheme(R.style.Theme_Hytera); - else - this.setTheme(R.style.AppTheme); - super.onCreate(savedInstanceState); - SM.Debug("######### ON CREATE TAB"); - - // get settings - loadSettings(); - // save selected language (may differ from saved one) - if(AppParams.LANGUAGETMP==null) - AppParams.LANGUAGETMP = AppParams.LANGUAGE; - - - // change locale - Locale locale = new Locale(AppParams.LANGUAGETMP); - Locale.setDefault(locale); - Configuration config = new Configuration(); - config.locale = locale; - getBaseContext().getResources().updateConfiguration(config, - getBaseContext().getResources().getDisplayMetrics()); - - setContentView(R.layout.tabpanel); + + /* TABS */ + private static final String LIVE = "Live"; + private static final String HISTORY = "History"; + private static final String TEXT = "Text"; + private static final String RADIO = "Radio"; + private static final String RECORDINGS = "Recordings"; + private static final String ALARMS = "Alarms"; + private static final String SETTINGS = "Setup"; + private static final String ABOUT = "SafeMobile"; + + // default app language + public static final String DATABASE_LANGUAGE = "en"; // database language : en, de, tr, ro or empty + + public RadioGW getCrtRadio() { + return crtRadio; + } + + public void setCrtRadio(RadioGW crtRadio) { + this.crtRadio = crtRadio; + } + + public int getCrtActivity() { + return crtActivity; + } + + public void setCrtActivity(int crtActivity) { + this.crtActivity = crtActivity; + } + + public boolean isInCall() { + return isInCall; + } + + public void setInCall(boolean inCall) { + isInCall = inCall; + } + + public AbstractLiveActivity getLiveActivity() { + return liveActivity; + } + + public RadioActivity getRadioActivity() { + return radioActivity; + } + + public void setRadioActivity(RadioActivity radioActivity) { + this.radioActivity = radioActivity; + } + + public MessagesActivity getMessageActivity() { + return messageActivity; + } + + public void setMessageActivity(MessagesActivity messageActivity) { + this.messageActivity = messageActivity; + } + + public HistoryActivity getHistoryActivity() { + return historyActivity; + } + + public void setHistoryActivity(HistoryActivity historyActivity) { + this.historyActivity = historyActivity; + } + + public RecordingsActivity getRecordingsActivity() { + return recordingsActivity; + } + + public void setRecordingsActivity(RecordingsActivity recordingsActivity) { + this.recordingsActivity = recordingsActivity; + } + + public AlarmActivity getAlarmActivity() { + return alarmActivity; + } + + public void setAlarmActivity(AlarmActivity alarmActivity) { + this.alarmActivity = alarmActivity; + } + + public ArrayList getAllRadios() { + return allRadios; + } + + public void setAllRadios(ArrayList allRadios) { + this.allRadios = allRadios; + } + + public ArrayList getHistoryPositionList() { + return historyPositionList; + } + + public void setHistoryPositionList(ArrayList historyPositionList) { + this.historyPositionList = historyPositionList; + } + + public Boolean getFirstHistoryData() { + return firstHistoryData; + } + + public void setFirstHistoryData(Boolean firstHistoryData) { + this.firstHistoryData = firstHistoryData; + } + + public Boolean getDropAllData() { + return dropAllData; + } + + public void setDropAllData(Boolean dropAllData) { + this.dropAllData = dropAllData; + } + + public ArrayList getHistoryMessageList() { + return historyMessageList; + } + + public void setHistoryMessageList(ArrayList historyMessageList) { + this.historyMessageList = historyMessageList; + } + + public ArrayList getDemoSmsList() { + return demoSmsList; + } + + public void setDemoSmsList(ArrayList demoSmsList) { + this.demoSmsList = demoSmsList; + } + + public ArrayList getDemoPositions() { + return demoPositions; + } + + public void setDemoPositions(ArrayList demoPositions) { + this.demoPositions = demoPositions; + } + + public MsgType getActivePopupType() { + return activePopupType; + } + + public void setActivePopupType(MsgType activePopupType) { + this.activePopupType = activePopupType; + } + + public enum MsgType {TCP, SMS, POLL, ALARM} + + /** + * Called when the activity is first created. + */ + @SuppressLint("UseCompatLoadingForDrawables") + @SuppressWarnings("deprecation") + @Override + public void onCreate(Bundle savedInstanceState) { + + if (AppParams.theme == AppParams.Theme.SAFENET) + this.setTheme(R.style.Theme_Safenet); + else if (AppParams.theme == AppParams.Theme.VISION) + this.setTheme(R.style.Theme_Vision); + else if (AppParams.theme == AppParams.Theme.HYTERA) + this.setTheme(R.style.Theme_Hytera); + else + this.setTheme(R.style.AppTheme); + super.onCreate(savedInstanceState); + SM.Debug("######### ON CREATE TAB"); + + // get settings + loadSettings(); + // save selected language (may differ from saved one) + if (AppParams.LANGUAGETMP == null) + AppParams.LANGUAGETMP = AppParams.LANGUAGE; + + + // change locale + Locale locale = new Locale(AppParams.LANGUAGETMP); + Locale.setDefault(locale); + Configuration config = new Configuration(); + config.locale = locale; + getBaseContext().getResources().updateConfiguration(config, + getBaseContext().getResources().getDisplayMetrics()); + + setContentView(R.layout.tabpanel); context = this; res = getResources(); // Resource object to get Drawables - - - // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().detectNetwork().build(); - // StrictMode.setThreadPolicy(policy); - - //AppParams.USERID = getIntent().getExtras().getInt("userID"); - //AppParams.userName = getIntent().getExtras().getString("userName"); - //AppParams.DEMO = getIntent().getExtras().getBoolean("demo"); - - if(AppParams.DEMO) - { - getAllVehicle().add(new Vehicle(101, "101", 101, "101", 101, 101, 101, 0)); - getAllVehicle().add(new Vehicle(102, "102", 102, "102", 102, 102, 102, 0)); - getAllVehicle().add(new Vehicle(103, "103", 103, "Ambulance", 78, 103, 103, 0)); - getAllVehicle().add(new Vehicle(104, "104", 104, "104", 104, 104, 104, 0)); - getAllVehicle().add(new Vehicle(105, "105", 105, "Police", 105, 105, 105, 0)); - getAllVehicle().add(new Vehicle(106, "106", 106, "Mike", 106, 106, 106, 0)); - getAllVehicle().add(new Vehicle(107, "107", 107, "Rob", 107, 107, 107, 0)); - getAllVehicle().add(new Vehicle(108, "108", 108, "Ben", 108, 108, 108, 0)); - getAllVehicle().add(new Vehicle(109, "109", 109, "Taxi_3", 109, 109, 109, 0)); - getAllVehicle().add(new Vehicle(110, "110", 110, "Pam", 110, 110, 110, 0)); - - - listSMS = new ArrayList(); - - listSMS.add(new SMS(1, 1, 1324016412, "Only one left", 101, 0)); - listSMS.add(new SMS(2, 1, 1328061660, "Thanks", 0, 105)); - listSMS.add(new SMS(3, 1, 1328060100, "i'm at the train station", 0, 102)); - listSMS.add(new SMS(4, 1, 1121016818, "I'll be right there", 0, 103)); - - for(Vehicle veh: getAllVehicle()) - { - SuperVehicle tmpSuper = new SuperVehicle(veh.sc_id,veh.imei,veh.lp, veh.name, veh.driver_id, veh.time_route, veh.GPS_reporting_interval, veh.is_stolen); - if (veh.sc_id == 101) - tmpSuper.SetDataFromLastPos(30.1038811728358, -95.6229997426271, Calendar.getInstance().getTimeInMillis(), 47, "800-804 Sandy Ln, Tomball, TX 77375, USA", true); - else if (veh.sc_id == 102) - tmpSuper.SetDataFromLastPos(30.1035, -95.623, Calendar.getInstance().getTimeInMillis(), 33, "9th St", true); - else if (veh.sc_id == 103) - tmpSuper.SetDataFromLastPos(42.320986,-85.183182, Calendar.getInstance().getTimeInMillis(), 61, "Battle Creek, MI, USA", true); - else if (veh.sc_id == 104) - tmpSuper.SetDataFromLastPos(42.337166,-83.049345, Calendar.getInstance().getTimeInMillis(), 47, "Downtown Detroit, USA", true); - else if (veh.sc_id == 105) - tmpSuper.SetDataFromLastPos(42.382514,-83.373184, Calendar.getInstance().getTimeInMillis(), 47, "Livonia, MI, Detroit, USA", true); - else if (veh.sc_id == 106) - tmpSuper.SetDataFromLastPos(41.741667,-87.972336, Calendar.getInstance().getTimeInMillis(), 47, "Darien, IL , USA", true); - else if (veh.sc_id == 107) - tmpSuper.SetDataFromLastPos(41.739329,-87.97225, Calendar.getInstance().getTimeInMillis(), 47, "8205 S Cass Ave , USA", true); - else if (veh.sc_id == 108) - tmpSuper.SetDataFromLastPos(41.739105,-87.97298, Calendar.getInstance().getTimeInMillis(), 47, "8201-8205 S Cass Ave , USA", true); - else if (veh.sc_id == 109) - tmpSuper.SetDataFromLastPos(41.752521,-87.944655, Calendar.getInstance().getTimeInMillis(), 47, "Kingery Hwy, Willowbrook, IL 60527, USA", true); - else if (veh.sc_id == 110) - tmpSuper.SetDataFromLastPos(41.748391,-87.933497, Calendar.getInstance().getTimeInMillis(), 47, "Historic U.S. 66, Burr Ridge, IL 60527 , USA", true); - - getSuperVehHash().put(Long.valueOf(veh.imei), tmpSuper); - getVehHashByScId().put(veh.sc_id, veh); - } - - } - - - SM.Debug("Loged user:" + AppParams.USERNAME + " | ID: " + AppParams.USERID); - // do not dim the display - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - // get NewMessage Visual Element - layoutNewMessage = (RelativeLayout) findViewById(R.id.layoutNewMessage); - textViewNMMessage = (TextView) findViewById(R.id.textViewNMMessage); - textViewNMFrom = (TextView) findViewById(R.id.textViewNMFrom); - slideTabsText = (TextView) findViewById(R.id.slideTabsText); - imageViewPopUp = (ImageView) findViewById(R.id.imageViewPopUp); - imageViewClose = (ImageView) findViewById(R.id.imageViewClose); - if(AppParams.DEMO) + if (AppParams.DEMO) { + getAllVehicle().add(new Vehicle(101, "101", 101, "101", 101, 101, 101, 0)); + getAllVehicle().add(new Vehicle(102, "102", 102, "102", 102, 102, 102, 0)); + getAllVehicle().add(new Vehicle(103, "103", 103, "Ambulance", 78, 103, 103, 0)); + getAllVehicle().add(new Vehicle(104, "104", 104, "104", 104, 104, 104, 0)); + getAllVehicle().add(new Vehicle(105, "105", 105, "Police", 105, 105, 105, 0)); + getAllVehicle().add(new Vehicle(106, "106", 106, "Mike", 106, 106, 106, 0)); + getAllVehicle().add(new Vehicle(107, "107", 107, "Rob", 107, 107, 107, 0)); + getAllVehicle().add(new Vehicle(108, "108", 108, "Ben", 108, 108, 108, 0)); + getAllVehicle().add(new Vehicle(109, "109", 109, "Taxi_3", 109, 109, 109, 0)); + getAllVehicle().add(new Vehicle(110, "110", 110, "Pam", 110, 110, 110, 0)); + + setDemoSmsList(new ArrayList<>()); + + getDemoSmsList().add(new SMS(1, 1, 1324016412, "Only one left", 101, 0)); + getDemoSmsList().add(new SMS(2, 1, 1328061660, "Thanks", 0, 105)); + getDemoSmsList().add(new SMS(3, 1, 1328060100, "i'm at the train station", 0, 102)); + getDemoSmsList().add(new SMS(4, 1, 1121016818, "I'll be right there", 0, 103)); + + for (Vehicle veh : getAllVehicle()) { + SuperVehicle tmpSuper = new SuperVehicle(veh.sc_id, veh.imei, veh.lp, veh.name, veh.driver_id, veh.time_route, veh.GPS_reporting_interval, veh.is_stolen); + if (veh.sc_id == 101) + tmpSuper.SetDataFromLastPos(30.1038811728358, -95.6229997426271, Calendar.getInstance().getTimeInMillis(), 47, "800-804 Sandy Ln, Tomball, TX 77375, USA", true); + else if (veh.sc_id == 102) + tmpSuper.SetDataFromLastPos(30.1035, -95.623, Calendar.getInstance().getTimeInMillis(), 33, "9th St", true); + else if (veh.sc_id == 103) + tmpSuper.SetDataFromLastPos(42.320986, -85.183182, Calendar.getInstance().getTimeInMillis(), 61, "Battle Creek, MI, USA", true); + else if (veh.sc_id == 104) + tmpSuper.SetDataFromLastPos(42.337166, -83.049345, Calendar.getInstance().getTimeInMillis(), 47, "Downtown Detroit, USA", true); + else if (veh.sc_id == 105) + tmpSuper.SetDataFromLastPos(42.382514, -83.373184, Calendar.getInstance().getTimeInMillis(), 47, "Livonia, MI, Detroit, USA", true); + else if (veh.sc_id == 106) + tmpSuper.SetDataFromLastPos(41.741667, -87.972336, Calendar.getInstance().getTimeInMillis(), 47, "Darien, IL , USA", true); + else if (veh.sc_id == 107) + tmpSuper.SetDataFromLastPos(41.739329, -87.97225, Calendar.getInstance().getTimeInMillis(), 47, "8205 S Cass Ave , USA", true); + else if (veh.sc_id == 108) + tmpSuper.SetDataFromLastPos(41.739105, -87.97298, Calendar.getInstance().getTimeInMillis(), 47, "8201-8205 S Cass Ave , USA", true); + else if (veh.sc_id == 109) + tmpSuper.SetDataFromLastPos(41.752521, -87.944655, Calendar.getInstance().getTimeInMillis(), 47, "Kingery Hwy, Willowbrook, IL 60527, USA", true); + else if (veh.sc_id == 110) + tmpSuper.SetDataFromLastPos(41.748391, -87.933497, Calendar.getInstance().getTimeInMillis(), 47, "Historic U.S. 66, Burr Ridge, IL 60527 , USA", true); + + getSuperVehHash().put(Long.valueOf(veh.imei), tmpSuper); + getVehHashByScId().put(veh.sc_id, veh); + } + } + + SM.Debug("Logged user:" + AppParams.USERNAME + " | ID: " + AppParams.USERID); + // do not dim the display + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + + // get NewMessage Visual Element + layoutNewMessage = findViewById(R.id.layoutNewMessage); + textViewNMMessage = findViewById(R.id.textViewNMMessage); + textViewNMFrom = findViewById(R.id.textViewNMFrom); + slideTabsText = findViewById(R.id.slideTabsText); + imageViewPopUp = findViewById(R.id.imageViewPopUp); + imageViewClose = findViewById(R.id.imageViewClose); + if (AppParams.DEMO) imageViewClose.setVisibility(View.VISIBLE); - + tabHost = getTabHost(); // The activity TabHost tabHost.setTag("Tab Panel"); - tabWidget = findViewById(android.R.id.tabs); + /* Tab */ + TabWidget tabWidget = findViewById(android.R.id.tabs); tabWidget.setVisibility(View.GONE); - - intent = new Intent[8]; - tabspecs = new TabSpec[8]; - + + Intent[] intent = new Intent[8]; + TabSpec[] tabSpecs = new TabSpec[8]; + // add live tab - try - { + try { intent[0] = new Intent(context, LiveActivity.class); - tabspecs[0] = tabHost.newTabSpec("Live") - .setIndicator("Live", res.getDrawable(R.drawable.ic_tab_live_selected)) + tabSpecs[0] = tabHost.newTabSpec(LIVE) + .setIndicator(LIVE, res.getDrawable(R.drawable.ic_tab_live_selected)) .setContent(intent[0]); - } - catch(NoClassDefFoundError e) - { + } catch (NoClassDefFoundError e) { // exception when GoogleApi does not exist intent[0] = new Intent(context, AbstractEmptyActivity.class); - tabspecs[0] = tabHost.newTabSpec("Live") - .setIndicator("Live", res.getDrawable(R.drawable.ic_tab_live_selected)) + tabSpecs[0] = tabHost.newTabSpec(LIVE) + .setIndicator(LIVE, res.getDrawable(R.drawable.ic_tab_live_selected)) .setContent(intent[0]); } - + // add text tab intent[1] = new Intent(context, MessagesActivity.class); - tabspecs[1] = tabHost.newTabSpec("Text") - .setIndicator("Text", res.getDrawable(R.drawable.ic_tab_text_selected)) + tabSpecs[1] = tabHost.newTabSpec(TEXT) + .setIndicator(TEXT, res.getDrawable(R.drawable.ic_tab_text_selected)) .setContent(intent[1]); - + // add radio tab intent[2] = new Intent(context, RadioActivity.class); - tabspecs[2] = tabHost.newTabSpec("Radio") - .setIndicator("Radio", res.getDrawable(R.drawable.ic_tab_radio_selected)) + tabSpecs[2] = tabHost.newTabSpec(RADIO) + .setIndicator(RADIO, res.getDrawable(R.drawable.ic_tab_radio_selected)) .setContent(intent[2]); - + // add recordings tab intent[3] = new Intent(context, RecordingsActivity.class); - tabspecs[3] = tabHost.newTabSpec("Recordings") - .setIndicator("Recordings", res.getDrawable(R.drawable.ic_tab_recording_selected)) + tabSpecs[3] = tabHost.newTabSpec(RECORDINGS) + .setIndicator(RECORDINGS, res.getDrawable(R.drawable.ic_tab_recording_selected)) .setContent(intent[3]); - + // add alarms tab - intent[4] = new Intent(context, AlarmActivity.class); - tabspecs[4] = tabHost.newTabSpec("Alarms") - .setIndicator("Alarms", res.getDrawable(R.drawable.ic_tab_alarms_selected)) + intent[4] = new Intent(context, AlarmActivity.class); + tabSpecs[4] = tabHost.newTabSpec(ALARMS) + .setIndicator(ALARMS, res.getDrawable(R.drawable.ic_tab_alarms_selected)) .setContent(intent[4]); - + // add setup tab intent[5] = new Intent(context, SetupActivity.class); - tabspecs[5] = tabHost.newTabSpec("Setup") - .setIndicator("Setup", res.getDrawable(R.drawable.ic_tab_settings_selected)) + tabSpecs[5] = tabHost.newTabSpec(SETTINGS) + .setIndicator(SETTINGS, res.getDrawable(R.drawable.ic_tab_settings_selected)) .setContent(intent[5]); - + // add radio tab intent[6] = new Intent(context, AbstractEmptyActivity.class); - tabspecs[6] = tabHost.newTabSpec("SafeMobile") - .setIndicator("SafeMobile", res.getDrawable(AppParams.DEMO ? R.drawable.icon_demo : R.drawable.ic_launcher)) + tabSpecs[6] = tabHost.newTabSpec(ABOUT) + .setIndicator(ABOUT, res.getDrawable(AppParams.DEMO ? R.drawable.icon_demo : R.drawable.ic_launcher)) .setContent(intent[6]); // add history tab - try - { + try { intent[7] = new Intent(context, HistoryActivity.class); - tabspecs[7] = tabHost.newTabSpec("History") - .setIndicator("History", res.getDrawable(R.drawable.ic_tab_history_selected)) + tabSpecs[7] = tabHost.newTabSpec(HISTORY) + .setIndicator(HISTORY, res.getDrawable(R.drawable.ic_tab_history_selected)) .setContent(intent[7]); - } catch(NoClassDefFoundError e) { + } catch (NoClassDefFoundError e) { // exception when GoogleApi not exists intent[7] = new Intent(context, AbstractEmptyActivity.class); - tabspecs[7] = tabHost.newTabSpec("History") - .setIndicator("History", res.getDrawable(R.drawable.ic_tab_history_selected)) + tabSpecs[7] = tabHost.newTabSpec(HISTORY) + .setIndicator(HISTORY, res.getDrawable(R.drawable.ic_tab_history_selected)) .setContent(intent[1]); } - + // add tab in tabHost -// for(int i=0;i<7;i++ - for (TabSpec tab: tabspecs) { - if(tabHost != null) + for (TabSpec tab : tabSpecs) { + if (tabHost != null) tabHost.addTab(tab); } - layoutMenu = (LinearLayout) findViewById(R.id.layoutMenu); - + LinearLayout layoutMenu = findViewById(R.id.layoutMenu); + // get slide Menu layout image - imageViewSlideMenu = (ImageView) findViewById(R.id.imageViewSlideMenu); - + ImageView imageViewSlideMenu = findViewById(R.id.imageViewSlideMenu); + // get Live Button - buttonLive = findViewById(R.id.buttonLive); - buttonLive.setOnClickListener(v -> { + buttonLive = findViewById(R.id.buttonLive); + buttonLive.setOnClickListener(v -> { if (!buttonLive.isSelected()) { // select button buttonLive.setSelected(true); @@ -364,14 +493,14 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ buttonSetup.setSelected(false); buttonText.setSelected(false); // select tab - tabHost.setCurrentTabByTag("Live"); + tabHost.setCurrentTabByTag(LIVE); AppParams.crtTab = AppParams.Tabs.live; } }); - - // get History Button - buttonHistory = findViewById(R.id.buttonHistory); - buttonHistory.setOnClickListener(v -> { + + // get History Button + buttonHistory = findViewById(R.id.buttonHistory); + buttonHistory.setOnClickListener(v -> { if (!buttonHistory.isSelected()) { // select button buttonHistory.setSelected(true); @@ -383,14 +512,14 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ buttonSetup.setSelected(false); buttonText.setSelected(false); // select tab - tabHost.setCurrentTabByTag("History"); + tabHost.setCurrentTabByTag(HISTORY); AppParams.crtTab = AppParams.Tabs.history; } }); - - // get Text Button - buttonText= findViewById(R.id.buttonText); - buttonText.setOnClickListener(v -> { + + // get Text Button + buttonText = findViewById(R.id.buttonText); + buttonText.setOnClickListener(v -> { if (!buttonText.isSelected()) { // select button buttonText.setSelected(true); @@ -402,10 +531,10 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ buttonSetup.setSelected(false); buttonHistory.setSelected(false); // select tab - tabHost.setCurrentTabByTag("Text"); + tabHost.setCurrentTabByTag(TEXT); AppParams.crtTab = AppParams.Tabs.message; - if (AppParams.DEMO && messageActivity.getAllVehicle().size()== 0) { + if (AppParams.DEMO && getMessageActivity().getAllVehicle().isEmpty()) { // select button buttonText.setSelected(true); // deselect other buttons @@ -416,201 +545,178 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ buttonSetup.setSelected(false); buttonHistory.setSelected(false); // select tab - tabHost.setCurrentTabByTag("Text"); + tabHost.setCurrentTabByTag(TEXT); AppParams.crtTab = AppParams.Tabs.message; - - if (AppParams.DEMO && messageActivity.getAllVehicle().size()== 0) { - messageActivity.updateVehicles(getAllVehicle()); - messageActivity.updateSMS(listSMS); + + if (AppParams.DEMO && getMessageActivity().getAllVehicle().isEmpty()) { + getMessageActivity().updateVehicles(getAllVehicle()); + getMessageActivity().updateSMS(getDemoSmsList()); } } } }); - - // get Radio Button - buttonRadio = (ImageButton) findViewById(R.id.buttonRadio); - if(NOSOUND) - buttonRadio.setVisibility(View.GONE); - buttonRadio.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if(!buttonRadio.isSelected()) - { - // select button - buttonRadio.setSelected(true); - // deselect other buttons - buttonAlarms.setSelected(false); - buttonLive.setSelected(false); - buttonRecordings.setSelected(false); - buttonHistory.setSelected(false); - buttonSetup.setSelected(false); - buttonText.setSelected(false); - // select tab - tabHost.setCurrentTabByTag("Radio"); - AppParams.crtTab = AppParams.Tabs.radio; - - if(radioActivity!= null && radioActivity.allVehicle!= null && radioActivity.allVehicle.size()==0) - { - radioActivity.allVehicle = getAllVehicle(); - radioActivity.UpdateVehicle(); - } + + // get Radio Button + buttonRadio = findViewById(R.id.buttonRadio); + if (NO_SOUND) + buttonRadio.setVisibility(View.GONE); + buttonRadio.setOnClickListener(v -> { + if (!buttonRadio.isSelected()) { + // select button + buttonRadio.setSelected(true); + // deselect other buttons + buttonAlarms.setSelected(false); + buttonLive.setSelected(false); + buttonRecordings.setSelected(false); + buttonHistory.setSelected(false); + buttonSetup.setSelected(false); + buttonText.setSelected(false); + // select tab + tabHost.setCurrentTabByTag(RADIO); + AppParams.crtTab = AppParams.Tabs.radio; + + if (getRadioActivity() != null && getRadioActivity().allVehicle != null && getRadioActivity().allVehicle.isEmpty()) { + getRadioActivity().allVehicle = getAllVehicle(); + getRadioActivity().UpdateVehicle(); } } }); - - // get Recordings Button - buttonRecordings = (ImageButton) findViewById(R.id.buttonRecording); - if(NOSOUND) - buttonRecordings.setVisibility(View.GONE); - buttonRecordings.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if(!buttonRecordings.isSelected()) - { - // select button - buttonRecordings.setSelected(true); - // deselect other buttons - buttonRadio.setSelected(false); - buttonAlarms.setSelected(false); - buttonLive.setSelected(false); - buttonHistory.setSelected(false); - buttonSetup.setSelected(false); - buttonText.setSelected(false); - // select tab - tabHost.setCurrentTabByTag("Recordings"); - AppParams.crtTab = AppParams.Tabs.recordings; - - if(AppParams.DEMO && recordingsActivity!= null && recordingsActivity.allRecordings!= null && recordingsActivity.allRecordings.size() ==0 ) - { - ArrayList listRecordings = new ArrayList(); - Recording rec = new Recording(); - rec.NameForDisplay = "Rob"; - rec.subID = 101; - rec.endGMT = (int) Calendar.getInstance().getTime().getTime(); - rec.startGMT = rec.endGMT - 2; - rec.type = 102; - listRecordings.add(rec); - - rec = new Recording(); - rec.NameForDisplay = "Call1 [Rob]"; - rec.subID = 102; - rec.endGMT = (int) Calendar.getInstance().getTime().getTime(); - rec.startGMT = rec.endGMT - 2; - rec.type = 101; - listRecordings.add(rec); - - rec = new Recording(); - rec.NameForDisplay = "Call2 [Rob]"; - rec.subID = 101; - rec.endGMT = (int) Calendar.getInstance().getTime().getTime(); - rec.startGMT = rec.endGMT - 3; - listRecordings.add(rec); - rec.type = 103; - recordingsActivity.UpdateRecordings(listRecordings); - } - - } - - } - }); - - // get Alarm Button - buttonAlarms = (ImageButton) findViewById(R.id.buttonAlarms); - buttonAlarms.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if(!buttonAlarms.isSelected()) - { - // select button - buttonAlarms.setSelected(true); - // deselect other buttons - buttonHistory.setSelected(false); - buttonLive.setSelected(false); - buttonRadio.setSelected(false); - buttonRecordings.setSelected(false); - buttonSetup.setSelected(false); - buttonText.setSelected(false); - // select tab - tabHost.setCurrentTabByTag("Alarms"); - AppParams.crtTab = AppParams.Tabs.alarms; - - - if(AppParams.DEMO && alarmActivity!=null && alarmActivity.getAllAlarms() != null && alarmActivity.getAllAlarms().size() ==0 ) - { - ArrayList listAlarms = new ArrayList(); - Alarm alarm = new Alarm(); - alarm.ack = 0; - alarm.unitName = "Police"; - alarm.timeGMT = (int) Calendar.getInstance().getTime().getTime() - 5210; - alarm.sc_id = 105; - alarm.typestr = "Speeding"; - listAlarms.add(alarm); - - alarm = new Alarm(); - alarm.ack = 0; - alarm.unitName = "101"; - alarm.timeGMT = (int) Calendar.getInstance().getTime().getTime() - 3315; - alarm.sc_id = 101; - alarm.typestr = "Geofence"; - listAlarms.add(alarm); - - alarm = new Alarm(); - alarm.ack = 0; - alarm.unitName = "101"; - alarm.timeGMT = (int) Calendar.getInstance().getTime().getTime() - 1900; - alarm.sc_id = 101; - alarm.typestr = "Telemetry"; - listAlarms.add(alarm); - - alarm = new Alarm(); - alarm.ack = 0; - alarm.unitName = "Taxi_3"; - alarm.timeGMT = (int) Calendar.getInstance().getTime().getTime() - 1521; - alarm.sc_id = 109; - alarm.typestr = "Landmark"; - listAlarms.add(alarm); - - alarm = new Alarm(); - alarm.ack = 0; - alarm.unitName = "Ben"; - alarm.timeGMT = (int) Calendar.getInstance().getTime().getTime() - 521; - alarm.sc_id = 108; - alarm.typestr = "Emergency"; - listAlarms.add(alarm); - - alarmActivity.updateAlarms(listAlarms); - } - + + // get Recordings Button + buttonRecordings = findViewById(R.id.buttonRecording); + if (NO_SOUND) + buttonRecordings.setVisibility(View.GONE); + buttonRecordings.setOnClickListener(v -> { + if (!buttonRecordings.isSelected()) { + // select button + buttonRecordings.setSelected(true); + // deselect other buttons + buttonRadio.setSelected(false); + buttonAlarms.setSelected(false); + buttonLive.setSelected(false); + buttonHistory.setSelected(false); + buttonSetup.setSelected(false); + buttonText.setSelected(false); + // select tab + tabHost.setCurrentTabByTag(RECORDINGS); + AppParams.crtTab = AppParams.Tabs.recordings; + + if (AppParams.DEMO && getRecordingsActivity() != null && getRecordingsActivity().allRecordings != null && getRecordingsActivity().allRecordings.isEmpty()) { + ArrayList listRecordings = new ArrayList<>(); + Recording rec = new Recording(); + rec.NameForDisplay = "Rob"; + rec.subID = 101; + rec.endGMT = (int) Calendar.getInstance().getTime().getTime(); + rec.startGMT = rec.endGMT - 2; + rec.type = 102; + listRecordings.add(rec); + + rec = new Recording(); + rec.NameForDisplay = "Call1 [Rob]"; + rec.subID = 102; + rec.endGMT = (int) Calendar.getInstance().getTime().getTime(); + rec.startGMT = rec.endGMT - 2; + rec.type = 101; + listRecordings.add(rec); + + rec = new Recording(); + rec.NameForDisplay = "Call2 [Rob]"; + rec.subID = 101; + rec.endGMT = (int) Calendar.getInstance().getTime().getTime(); + rec.startGMT = rec.endGMT - 3; + listRecordings.add(rec); + rec.type = 103; + getRecordingsActivity().UpdateRecordings(listRecordings); } } }); - - //get Setup button - buttonSetup = (ImageButton) findViewById(R.id.buttonSetup); - buttonSetup.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if(!buttonSetup.isSelected()) - { - // select button - buttonSetup.setSelected(true); - // deselect other buttons - buttonAlarms.setSelected(false); - buttonLive.setSelected(false); - buttonRadio.setSelected(false); - buttonRecordings.setSelected(false); - buttonHistory.setSelected(false); - buttonText.setSelected(false); - // select tab - tabHost.setCurrentTabByTag("Setup"); - AppParams.crtTab = AppParams.Tabs.setup; + + // get Alarm Button + buttonAlarms = findViewById(R.id.buttonAlarms); + buttonAlarms.setOnClickListener(v -> { + if (!buttonAlarms.isSelected()) { + // select button + buttonAlarms.setSelected(true); + // deselect other buttons + buttonHistory.setSelected(false); + buttonLive.setSelected(false); + buttonRadio.setSelected(false); + buttonRecordings.setSelected(false); + buttonSetup.setSelected(false); + buttonText.setSelected(false); + // select tab + tabHost.setCurrentTabByTag(ALARMS); + AppParams.crtTab = AppParams.Tabs.alarms; + + if (AppParams.DEMO && getAlarmActivity() != null && getAlarmActivity().getAllAlarms() != null && getAlarmActivity().getAllAlarms().isEmpty()) { + ArrayList listAlarms = new ArrayList<>(); + Alarm alarm = new Alarm(); + alarm.ack = 0; + alarm.unitName = "Police"; + alarm.timeGMT = (int) Calendar.getInstance().getTime().getTime() - 5210L; + alarm.sc_id = 105; + alarm.typestr = "Speeding"; + listAlarms.add(alarm); + + alarm = new Alarm(); + alarm.ack = 0; + alarm.unitName = "101"; + alarm.timeGMT = (int) Calendar.getInstance().getTime().getTime() - 3315L; + alarm.sc_id = 101; + alarm.typestr = "Geofence"; + listAlarms.add(alarm); + + alarm = new Alarm(); + alarm.ack = 0; + alarm.unitName = "101"; + alarm.timeGMT = (int) Calendar.getInstance().getTime().getTime() - 1900L; + alarm.sc_id = 101; + alarm.typestr = "Telemetry"; + listAlarms.add(alarm); + + alarm = new Alarm(); + alarm.ack = 0; + alarm.unitName = "Taxi_3"; + alarm.timeGMT = (int) Calendar.getInstance().getTime().getTime() - 1521L; + alarm.sc_id = 109; + alarm.typestr = "Landmark"; + listAlarms.add(alarm); + + alarm = new Alarm(); + alarm.ack = 0; + alarm.unitName = "Ben"; + alarm.timeGMT = (int) Calendar.getInstance().getTime().getTime() - 521L; + alarm.sc_id = 108; + alarm.typestr = "Emergency"; + listAlarms.add(alarm); + + getAlarmActivity().updateAlarms(listAlarms); } } }); - - // get About Button - buttonLogo = findViewById(R.id.buttonLogo); - buttonLogo.setOnClickListener(v -> { + + //get Setup button + buttonSetup = findViewById(R.id.buttonSetup); + buttonSetup.setOnClickListener(v -> { + if (!buttonSetup.isSelected()) { + // select button + buttonSetup.setSelected(true); + // deselect other buttons + buttonAlarms.setSelected(false); + buttonLive.setSelected(false); + buttonRadio.setSelected(false); + buttonRecordings.setSelected(false); + buttonHistory.setSelected(false); + buttonText.setSelected(false); + // select tab + tabHost.setCurrentTabByTag(SETTINGS); + AppParams.crtTab = AppParams.Tabs.setup; + } + }); + + // get About Button + ImageButton buttonLogo = findViewById(R.id.buttonLogo); + buttonLogo.setOnClickListener(v -> { // create dialog final Dialog dialog = new Dialog(context); dialog.setTitle(AppParams.DEMO ? getString(R.string.app_name_demo) : getString(R.string.app_name)); @@ -619,363 +725,257 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ image.setImageResource(AppParams.DEMO ? R.drawable.icon_demo : R.drawable.ic_launcher); TextView text = dialog.findViewById(R.id.text); TextView text2 = dialog.findViewById(R.id.text2); - text.setText(getString(R.string.version) + "1.0.8"); - text2.setText(getString(R.string.email) + ": support@safemobile.com"); + text.setText(String.format("%s1.0.8", getString(R.string.version))); + text2.setText(String.format("%s: support@safemobile.com", getString(R.string.email))); dialog.setCancelable(true); dialog.setCanceledOnTouchOutside(true); dialog.show(); }); - - imageViewClose.setOnTouchListener(new OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - layoutNewMessage.setVisibility(View.GONE); - return false; + + imageViewClose.setOnTouchListener((v, event) -> { + layoutNewMessage.setVisibility(View.GONE); + return false; + }); + + // set Click event for NewMessageLayout + layoutNewMessage.setOnClickListener(v -> { + if (tcp != null && tcp.isConnectionUP && !isInCall()) { + if (slideTabsText.getText().toString().equals(getString(R.string.newMessage))) + viewReceived(AppParams.messageNotif); + else if (slideTabsText.getText().toString().equals(getString(R.string.newAlarm))) + viewReceived(AppParams.alertNotif); + else if (slideTabsText.getText().toString().equals(getString(R.string.newPoll))) + viewReceived(AppParams.pollNotif); + } else if (AppParams.DEMO) { + if (slideTabsText.getText().toString().equals(getString(R.string.newMessage))) + viewReceived(AppParams.messageNotif); + else if (slideTabsText.getText().toString().equals(getString(R.string.newPoll))) + viewReceived(AppParams.pollNotif); + } + layoutNewMessage.clearAnimation(); + layoutNewMessage.setVisibility(View.INVISIBLE); + }); + + LinearLayout layoutSlideMenu = findViewById(R.id.layoutSlideMenu); + layoutSlideMenu.setOnClickListener(v -> { + if (isMenuVisible) { + // hide Menu + layoutMenu.setVisibility(View.GONE); + // change image + imageViewSlideMenu.setImageResource(R.drawable.arrow_left); + // set visible false + isMenuVisible = false; + } else { + // hide Menu + layoutMenu.setVisibility(View.VISIBLE); + // change image + imageViewSlideMenu.setImageResource(R.drawable.arrow_right); + // set visible true + isMenuVisible = true; } }); - - // set Click event for NewMessageLayout - layoutNewMessage.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if(tcp!=null && tcp.isConnectionUP && inCall == false) - { - if(slideTabsText.getText().toString().equals(getString(R.string.newMessage))) - viewReceived(AppParams.messageNotif); - else if(slideTabsText.getText().toString().equals(getString(R.string.newAlarm))) - viewReceived(AppParams.alertNotif); - else if(slideTabsText.getText().toString().equals(getString(R.string.newPoll))) - viewReceived(AppParams.pollNotif); - } - else if (AppParams.DEMO) - { - if(slideTabsText.getText().toString().equals(getString(R.string.newMessage))) - viewReceived(AppParams.messageNotif); - else if(slideTabsText.getText().toString().equals(getString(R.string.newPoll))) - viewReceived(AppParams.pollNotif); - } - - layoutNewMessage.clearAnimation(); - layoutNewMessage.setVisibility(View.INVISIBLE); - /* - String currentActivityId = getLocalActivityManager().getCurrentId(); - SM.Debug(" curent activityID: " +currentActivityId); - while(currentActivityId == null) - { - try { - Thread.sleep(100); - currentActivityId = getLocalActivityManager().getCurrentId(); - SM.Debug(" curent activityID: " +currentActivityId); - } catch (InterruptedException e) { - SM.Debug(e.toString()); - } - } - Activity currentActivity = getLocalActivityManager().getActivity(currentActivityId); - //list for SMS - if(currentActivity instanceof MessagesActivity) - { - // run update showSMS4unit(int scId) form MessageActivity - ((MessagesActivity)currentActivity).showSMS4unit(getVehicle4Imei(imei).scId); - } - */ - } - }); - - - // if RADIOPAD hide buttons - - /* - // alarm animation - Animation a = AnimationUtils.loadAnimation(this, R.anim.alpha); - a.reset(); - textViewAlarm.clearAnimation(); - textViewAlarm.startAnimation(a); - imageViewAlarm.clearAnimation(); - imageViewAlarm.startAnimation(a); - */ - - layoutSlideMenu = (LinearLayout) findViewById(R.id.layoutSlideMenu); - layoutSlideMenu.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if(isMenuVisible) - { - // hide Menu - layoutMenu.setVisibility(View.GONE); - // change image - imageViewSlideMenu.setImageResource(R.drawable.arrow_left); - // set visibile false - isMenuVisible = false; - } - else - { - // hide Menu - layoutMenu.setVisibility(View.VISIBLE); - // change image - imageViewSlideMenu.setImageResource(R.drawable.arrow_right); - // set visibile true - isMenuVisible = true; - } - } - }); - // got to tab - tabHost.setCurrentTabByTag("Radio"); - tabHost.setCurrentTabByTag("Live"); + // got to tab + tabHost.setCurrentTabByTag(RADIO); + tabHost.setCurrentTabByTag(LIVE); buttonLive.setSelected(true); AppParams.crtTab = AppParams.Tabs.live; - + //start TCP timer tcpTimer = new Timer(); tcpTimer.scheduleAtFixedRate(new TimerTask() { - + @Override public void run() { - TimerMethod(); + timerMethod(); } }, AppParams.DEMO ? 3000 : 1000, 3000); - - - // hide buttons if safenet - if(AppParams.theme == AppParams.Theme.SAFENET) - { + + // hide buttons if SafeNet + if (AppParams.theme == AppParams.Theme.SAFENET) { buttonRadio.setVisibility(View.GONE); buttonRecordings.setVisibility(View.GONE); } - - - if(AppParams.DEMO && liveActivity != null) - { - liveActivity.vehiclesReceived(getAllVehicle()); - demoPositionsList(); - } - - if(!AppParams.DEMO) - { - //TCPinit(); - //* - Timer t = new Timer(); - t.schedule(new TimerTask() { - + + if (AppParams.DEMO && getLiveActivity() != null) { + getLiveActivity().vehiclesReceived(getAllVehicle()); + demoPositionsList(); + } + + if (!AppParams.DEMO) { + Timer t = new Timer(); + t.schedule(new TimerTask() { + @Override public void run() { - // init tcp - TCPinit(); + // init tcp + tcpInit(); } }, 100); - //*/ - } - - // Notification Click Filter - IntentFilter intentAlertFilter = new IntentFilter(NotificationActivity.NOTIFICATION_ALERT_INTENT); - IntentFilter intentMessageFilter = new IntentFilter(NotificationActivity.NOTIFICATION_MESSAGE_INTENT); - IntentFilter intentPollFilter = new IntentFilter(NotificationActivity.NOTIFICATION_POLL_INTENT); + } + + // Notification Click Filter + IntentFilter intentAlertFilter = new IntentFilter(NotificationActivity.NOTIFICATION_ALERT_INTENT); + IntentFilter intentMessageFilter = new IntentFilter(NotificationActivity.NOTIFICATION_MESSAGE_INTENT); + IntentFilter intentPollFilter = new IntentFilter(NotificationActivity.NOTIFICATION_POLL_INTENT); this.registerReceiver(mReceiver, intentAlertFilter); this.registerReceiver(mReceiver, intentMessageFilter); this.registerReceiver(mReceiver, intentPollFilter); - - /** Create Service and bind to it */ + + /* Create Service and bind to it */ getApplicationContext().bindService(new Intent(this, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE); - - - // set tab - /* - tabHost.setCurrentTabByTag("Alarms"); - AppParams.crtTab = AppParams.Tabs.setup; - //*/ } - - - /** Broadcast Received for notifications */ - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - // get notification click action - if (action.equals(NotificationActivity.NOTIFICATION_MESSAGE_INTENT) && tabHost.getCurrentTab() != 2) - viewReceived(AppParams.messageNotif); - else if (action.equals(NotificationActivity.NOTIFICATION_ALERT_INTENT) && tabHost.getCurrentTab() != 2) - viewReceived(AppParams.alertNotif); - else if (action.equals(NotificationActivity.NOTIFICATION_POLL_INTENT) && tabHost.getCurrentTab() != 2) - viewReceived(AppParams.pollNotif); - } - }; - - private void viewReceived(int icon) - { - switch(icon) - { - case AppParams.messageNotif : - // hide NewMessage Layout - layoutNewMessage.setVisibility(View.GONE); - // select button - buttonText.setSelected(true); - // deselect other buttons - buttonAlarms.setSelected(false); - buttonLive.setSelected(false); - buttonRadio.setSelected(false); - buttonRecordings.setSelected(false); - buttonSetup.setSelected(false); - buttonHistory.setSelected(false); - // select text tab - tabHost.setCurrentTabByTag("Text"); - AppParams.crtTab = AppParams.Tabs.message; - - messageActivity.setScId(getVehicle4Imei(getImei()).sc_id); - messageActivity.LASTMESSAGES = false; - messageActivity.getLastSMS(); - - // disable notification - if(mNotificationManager!=null) - mNotificationManager.cancel(R.drawable.message); - break; - case AppParams.alertNotif: - // hide NewMessage Layout - layoutNewMessage.setVisibility(View.GONE); - // select button - buttonAlarms.setSelected(true); - // deselect other buttons - buttonText.setSelected(false); - buttonLive.setSelected(false); - buttonRadio.setSelected(false); - buttonRecordings.setSelected(false); - buttonSetup.setSelected(false); - buttonHistory.setSelected(false); - // select tab - tabHost.setCurrentTabByTag("Alarms"); - AppParams.crtTab = AppParams.Tabs.alarms; - // disable notification - if(mNotificationManager!=null) - mNotificationManager.cancel(R.drawable.alert); - break; - case R.drawable.poll: - // hide NewMessage Layout - layoutNewMessage.setVisibility(View.GONE); - // select button - buttonLive.setSelected(true); - // deselect other buttons - buttonText.setSelected(false); - buttonAlarms.setSelected(false); - buttonRadio.setSelected(false); - buttonRecordings.setSelected(false); - buttonSetup.setSelected(false); - buttonHistory.setSelected(false); - // select tab - tabHost.setCurrentTabByTag("live"); - AppParams.crtTab = AppParams.Tabs.live; - // disable notification - if(mNotificationManager!=null) - mNotificationManager.cancel(R.drawable.poll); - break; - } - } - - - private void demoPositionsList() { - AssetManager assetManager = res.getAssets(); + + /** + * Broadcast Received for notifications + */ + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + // get notification click action + if (action.equals(NotificationActivity.NOTIFICATION_MESSAGE_INTENT) && tabHost.getCurrentTab() != 2) + viewReceived(AppParams.messageNotif); + else if (action.equals(NotificationActivity.NOTIFICATION_ALERT_INTENT) && tabHost.getCurrentTab() != 2) + viewReceived(AppParams.alertNotif); + else if (action.equals(NotificationActivity.NOTIFICATION_POLL_INTENT) && tabHost.getCurrentTab() != 2) + viewReceived(AppParams.pollNotif); + } + }; + + private void viewReceived(int icon) { + switch (icon) { + case AppParams.messageNotif: + // hide NewMessage Layout + layoutNewMessage.setVisibility(View.GONE); + // select button + buttonText.setSelected(true); + // deselect other buttons + buttonAlarms.setSelected(false); + buttonLive.setSelected(false); + buttonRadio.setSelected(false); + buttonRecordings.setSelected(false); + buttonSetup.setSelected(false); + buttonHistory.setSelected(false); + // select text tab + tabHost.setCurrentTabByTag(TEXT); + AppParams.crtTab = AppParams.Tabs.message; + Vehicle vehicle = getVehicle4Imei(getImei()); + if(vehicle != null) + getMessageActivity().setScId(vehicle.sc_id); + getMessageActivity().LASTMESSAGES = false; + getMessageActivity().getLastSMS(); + + // disable notification + if (mNotificationManager != null) + mNotificationManager.cancel(R.drawable.message); + break; + case AppParams.alertNotif: + // hide NewMessage Layout + layoutNewMessage.setVisibility(View.GONE); + // select button + buttonAlarms.setSelected(true); + // deselect other buttons + buttonText.setSelected(false); + buttonLive.setSelected(false); + buttonRadio.setSelected(false); + buttonRecordings.setSelected(false); + buttonSetup.setSelected(false); + buttonHistory.setSelected(false); + // select tab + tabHost.setCurrentTabByTag(ALARMS); + AppParams.crtTab = AppParams.Tabs.alarms; + // disable notification + if (mNotificationManager != null) + mNotificationManager.cancel(R.drawable.alert); + break; + case R.drawable.poll: + // hide NewMessage Layout + layoutNewMessage.setVisibility(View.GONE); + // select button + buttonLive.setSelected(true); + // deselect other buttons + buttonText.setSelected(false); + buttonAlarms.setSelected(false); + buttonRadio.setSelected(false); + buttonRecordings.setSelected(false); + buttonSetup.setSelected(false); + buttonHistory.setSelected(false); + // select tab + tabHost.setCurrentTabByTag(LIVE); + AppParams.crtTab = AppParams.Tabs.live; + // disable notification + if (mNotificationManager != null) + mNotificationManager.cancel(R.drawable.poll); + break; + default: + throw new IllegalStateException("Unexpected value: " + icon); + } + } + + private void demoPositionsList() { + AssetManager assetManager = res.getAssets(); SM.Debug("TRY 2 OPEN demo_positions.txt"); InputStream input = null; try { input = assetManager.open("demo_positions.txt"); - InputStreamReader inputreader = new InputStreamReader(input); - BufferedReader buffreader = new BufferedReader(inputreader); - String line = ""; - while ((line = buffreader.readLine()) != null) - { - String[] posi = line.split("#"); - HistPos gps = new HistPos(); - gps.lat = Double.parseDouble(posi[1]); - gps.lng = Double.parseDouble(posi[2]); - gps.speed = Integer.parseInt(posi[3]); - gps.Address = posi[4]; - demoPositions.add(gps); - } - HistPosmsg msg = new HistPosmsg(new TCPmsg(new char[]{})); - demoPositions = msg.CalcHeadingForArray(demoPositions); + InputStreamReader inputReader = new InputStreamReader(input); + try (BufferedReader bufferedReader = new BufferedReader(inputReader)) { + String line = ""; + while ((line = bufferedReader.readLine()) != null) { + String[] posi = line.split("#"); + HistPos gps = new HistPos(); + gps.lat = Double.parseDouble(posi[1]); + gps.lng = Double.parseDouble(posi[2]); + gps.speed = Integer.parseInt(posi[3]); + gps.Address = posi[4]; + getDemoPositions().add(gps); + } + } + HistPosmsg msg = new HistPosmsg(new TCPmsg(new char[]{})); + setDemoPositions(msg.CalcHeadingForArray(getDemoPositions())); } catch (IOException e1) { e1.printStackTrace(); } - } - @Override - public void onStart() - { - super.onStart(); - /* - SM.Debug("##### onSTART #####"); - if(FIRST) - { - // start thread to add listener - SM.Debug("##### START initTCPRUN"); - new Thread(new Runnable() { - public void run() { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - myHandler.post(initTCPRUN); - } - }).start(); - - FIRST = false; - } - */ - } - - ServiceConnection serviceConnection = new ServiceConnection() { - - @Override - public void onServiceDisconnected(ComponentName name) { - //Toast.makeText(context, "Fucking Service is disconnected", 1000).show(); - SM.Debug("Service is disconnected"); - isBound = false; - myService = null; - } - - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - //Toast.makeText(context, "Fucking Service is connected", 2000).show(); - SM.Debug("Service is connected"); - TCPBinder binder = (TCPBinder) service; - myService = binder.getService(); - isBound = true; - - tcpParser(); - } - }; - - - @Override - public void whenBackPressed(AppParams.ActivityResult result) - { - // close TCP - /* - if(tcp!= null) - { - tcp.Stop(); - tcpParser.Stop(); - }*/ + ServiceConnection serviceConnection = new ServiceConnection() { - if(tcpTimer!=null) - { + @Override + public void onServiceDisconnected(ComponentName name) { + SM.Debug("Service is disconnected"); + isBound = false; + myService = null; + } + + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + SM.Debug("Service is connected"); + TCPBinder binder = (TCPBinder) service; + myService = binder.getService(); + isBound = true; + + tcpParser(); + } + }; + + + @Override + public void whenBackPressed(AppParams.ActivityResult result) { + if (tcpTimer != null) { tcpTimer.cancel(); tcpTimer.purge(); tcpTimer = null; } - - if(radioActivity.audioThread != null) - { - Thread moribund = radioActivity.audioThread; - radioActivity.audioThread = null; + if (getRadioActivity().audioThread != null) { + Thread moribund = getRadioActivity().audioThread; + getRadioActivity().audioThread = null; moribund.interrupt(); } - - if(mReceiver!=null) - this.unregisterReceiver(mReceiver); + + this.unregisterReceiver(mReceiver); // unbound from tcp service if (isBound) { @@ -984,110 +984,84 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } // cancel new message notification if any - if(mNotificationManager!=null) { + if (mNotificationManager != null) { mNotificationManager.cancel(R.drawable.message); mNotificationManager.cancel(R.drawable.alert); mNotificationManager.cancel(R.drawable.poll); } - - + getIntent().putExtra("result", result); setResult(RESULT_OK, getIntent()); //-> used for exit finish(); - android.os.Process.killProcess(android.os.Process.myPid()); - System.exit(0); - } - - @Override - public void changeLanguage() - { - // recreate UI - Locale locale = new Locale(AppParams.LANGUAGETMP); - Locale.setDefault(locale); - android.content.res.Configuration configuration = new android.content.res.Configuration(); - configuration.locale = locale; - getBaseContext().getResources().updateConfiguration(configuration, - getBaseContext().getResources().getDisplayMetrics()); - - // change UI in Live Activity - // if(liveActivity != null) - //liveActivity.onCreate(liveActivity.savedInstanceState); - if(historyActivity!=null) - //historyActivity.onCreate(historyActivity.savedInstanceState); - // change UI for RadioActivity and MessageActivity - if(radioActivity!=null) - radioActivity.onCreate(radioActivity.savedInstanceState); - if(messageActivity!=null) - messageActivity.onCreate(messageActivity.getSavedInstanceState()); - if(recordingsActivity!=null) - recordingsActivity.onCreate(recordingsActivity.savedInstanceState); - if(alarmActivity!=null) - alarmActivity.onCreate(alarmActivity.getSavedInstanceState()); - } - - - // Create runnable for posting - public final Runnable initTCPRUN = new Runnable() { - public void run() { - //SM.Debug("##### GetVehicles()"); - // get all vehicles - //getVehs(); - } - }; - - //timer stuff - private void TimerMethod() - { - if(!AppParams.DEMO) - this.runOnUiThread(Timer_Tick); - else - // build TimerMethod for demo - this.runOnUiThread(Timer_TickDemo); + android.os.Process.killProcess(android.os.Process.myPid()); + System.exit(0); } - - private Runnable Timer_TickDemo = new Runnable() { - public void run() { - if(AppParams.crtTab == AppParams.Tabs.live) - { - if(getSuperVehHash().containsKey((long)101)) - { - - HistPos crtPos = demoPositions.get(demoPosition++ % demoPositions.size()); - - SM.Debug("########### UPDATE"); - int sc_id = demoPosition%3 == 0 ? 101:102; - ((SuperVehicle) getSuperVehHash().get((long)sc_id)).SetNewPosition(crtPos.lat, crtPos.lng, Calendar.getInstance().getTime().getTime(), crtPos.speed); - liveActivity.refreshMap(); - } - } - } - }; - - @Override - public void updateDemoPosition() - { - HistPos crtPos = demoPositions.get(demoPosition++ % demoPositions.size()); - + + @Override + public void changeLanguage() { + // recreate UI + Locale locale = new Locale(AppParams.LANGUAGETMP); + Locale.setDefault(locale); + android.content.res.Configuration configuration = new android.content.res.Configuration(); + configuration.locale = locale; + getBaseContext().getResources().updateConfiguration(configuration, + getBaseContext().getResources().getDisplayMetrics()); + + if (getHistoryActivity() != null) + getHistoryActivity().onCreate(getHistoryActivity().savedInstanceState); + // change UI for RadioActivity and MessageActivity + if (getRadioActivity() != null) + getRadioActivity().onCreate(getRadioActivity().savedInstanceState); + if (getMessageActivity() != null) + getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState()); + if (getRecordingsActivity() != null) + getRecordingsActivity().onCreate(getRecordingsActivity().savedInstanceState); + if (getAlarmActivity() != null) + getAlarmActivity().onCreate(getAlarmActivity().getSavedInstanceState()); + } + + //timer stuff + private void timerMethod() { + if (!AppParams.DEMO) + this.runOnUiThread(timerTick); + else + // build timerMethod for demo + this.runOnUiThread(timerTickDemo); + } + + private final Runnable timerTickDemo = () -> { + if (AppParams.crtTab == AppParams.Tabs.live && getSuperVehHash().containsKey((long) 101)) { + + HistPos crtPos = getDemoPositions().get(demoPosition++ % getDemoPositions().size()); + SM.Debug("########### UPDATE"); - int sc_id = Integer.parseInt(getImei()); - ((SuperVehicle) getSuperVehHash().get((long)sc_id)).SetNewPosition(crtPos.lat + 0.0002, crtPos.lng + 0.0002, Calendar.getInstance().getTime().getTime(), crtPos.speed+2); - setMess("Lat:" + String.format("%5f", crtPos.lat + 0.0002) + ", Lng:" + String.format("%5f", crtPos.lng + 0.0002)); - liveActivity.refreshMap(); - } - + int scId = demoPosition % 3 == 0 ? 101 : 102; + SuperVehicle superVehicle = (getSuperVehHash().get((long) scId)); + if(superVehicle != null) + superVehicle.SetNewPosition(crtPos.lat, crtPos.lng, Calendar.getInstance().getTime().getTime(), crtPos.speed); + getLiveActivity().refreshMap(); + } + }; - private Runnable Timer_Tick = new Runnable() { + @Override + public void updateDemoPosition() { + HistPos crtPos = getDemoPositions().get(demoPosition++ % getDemoPositions().size()); + + SM.Debug("########### UPDATE"); + int scId = Integer.parseInt(getImei()); + (Objects.requireNonNull(getSuperVehHash().get((long) scId))).SetNewPosition(crtPos.lat + 0.0002, crtPos.lng + 0.0002, Calendar.getInstance().getTime().getTime(), crtPos.speed + 2); + setMess("Lat:" + String.format("%5f", crtPos.lat + 0.0002) + ", Lng:" + String.format("%5f", crtPos.lng + 0.0002)); + getLiveActivity().refreshMap(); + } + + + private Runnable timerTick = new Runnable() { public void run() { - //This method runs in the same thread as the UI. - - //Do something to the UI thread here - if(tcp != null) - { - if(!tcp.isConnectionUP) - { - //SM.Debug("TCP connection with:"+tcp.serverHostname + " is DOWN!!!"); + //This method runs in the same thread as the UI. + if (tcp != null) { + if (Boolean.FALSE.equals(tcp.isConnectionUP)) { // set TextViews slideTabsText.setText(getString(R.string.connectionError)); textViewNMFrom.setText(getString(R.string.tcpConnection)); @@ -1097,353 +1071,234 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ layoutNewMessage.setVisibility(View.VISIBLE); // hide close button imageViewClose.setVisibility(View.INVISIBLE); - try - { - if(lastTCPstatus) - radioActivity.UpdateEnableDisableButtons("offline"); - } - catch(Exception ex) - { + try { + if (lastTcpStatus) + getRadioActivity().UpdateEnableDisableButtons("offline"); + } catch (Exception ex) { SM.Debug(ex.toString()); } - } - else - { - - //SM.Debug("TCP connection with:"+tcp.serverHostname + " is OKKKKK!!!"); - /* - if(layoutNewMessage.getVisibility() == View.VISIBLE) - { - switch (activePopupType) - { - case SMS: - imageViewPopUp.setImageResource(R.drawable.message); - break; - case ALARM: - imageViewPopUp.setImageResource(R.drawable.siren_on); - break; - case POLL: - imageViewPopUp.setImageResource(R.drawable.poll); - break; + } else { + if (getAllVehicle().isEmpty()) + new ConnectTask().execute(OperationCodes.GetVehicles + "", AppParams.USERID + ""); + if (getRadioActivity() != null && AppParams.listRadios.isEmpty()) + new ConnectTask().execute(OperationCodes.GetRadiosList + ""); - default: - imageViewPopUp.setImageResource(R.drawable.error); - break; - } - */ - // reset image to message - //imageViewPopUp.setImageResource(R.drawable.message); - // hide layout - //if(layoutNewMessage.getVisibility() == View.VISIBLE) - // when connection becomes true after it was false - - - if(getAllVehicle().size() == 0) - //connectTask.doIn(OperationCodes.GetVehicles, new Object[] {AppParams.USERID}); - new ConnectTask().execute(new String[] {OperationCodes.GetVehicles + "", AppParams.USERID + ""}); - //getVehicles(AppParams.USERID); - if(radioActivity != null && AppParams.listRadios.size() == 0) - new ConnectTask().execute(new String[] {OperationCodes.GetRadiosList + ""}); - //connectTask.execute("3#getRadiosList"); - - /* - new Thread(new Runnable() { - public void run() - { - try { - Thread.sleep(1500); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - //GetRadioStatus(crtRadio.GW_ID, crtRadio.ID); // get radio status - } - }).start(); - */ - layoutNewMessage.setVisibility(View.INVISIBLE); } // remember this tcp connection status - lastTCPstatus = tcp.isConnectionUP; + lastTcpStatus = tcp.isConnectionUP; } } }; - - - // hide tabs - public void hideTabs() - { - //tabWidget.setVisibility( View.GONE ); - layoutMenu.setVisibility(View.GONE); - } - // show tabs - public void showTabs() - { - //tabWidget.setVisibility( View.VISIBLE ); - layoutMenu.setVisibility(View.VISIBLE); - } - - // TCP part - public void TCPinit() - { + public void tcpInit() { SM.Debug("#### TCP INIT ####"); - - new ConnectTask().execute(new String[] {OperationCodes.TCP_CONNECTION_REQ + ""}); - //connectTask.execute(new Object[] {OperationCodes.GetTCPConnection}); + + new ConnectTask().execute(OperationCodes.TCP_CONNECTION_REQ + ""); } - - public void tcpParser() - { - SM.Debug("TCP PARSER ", "connectParserTask().execute && myService is : " + (myService == null ? " null " : " not null")); - - if(myService != null) { + + public void tcpParser() { + SM.Debug("TCP PARSER ", "ConnectParserTask().execute && myService is : " + (myService == null ? " null " : " not null")); + + if (myService != null) { tcpParser = myService.getTCPmsgParser(); tcp = myService.getTCPConnection(); } - - SM.Debug("connectParserTask","tcpParser is : " + (tcpParser == null ? "null" : "not null")); + + SM.Debug("ConnectParserTask", "tcpParser is : " + (tcpParser == null ? "null" : "not null")); // add TCPParserListener - if(tcpParser!=null) - { - SM.Debug("## tcpParser != null ", "#### call tcpParserListener(") ; + if (tcpParser != null) { + SM.Debug("## tcpParser != null ", "#### call tcpParserListener("); tcpParserListener(); } - - //new connectParserTask().execute(""); } - - public void tcpParserListener() - { - - SM.Debug("ADDING TCP Listener", "NEW TCP Listener"); - //manager.getActivity(id); - tcpParser.clearITCPListeners(); - tcpParser.addTCPListener(new ITCPListener() { - public void onLoginReceived(TCPEvent event) { } + public void tcpParserListener() { + + SM.Debug("ADDING TCP Listener", "NEW TCP Listener"); + tcpParser.clearITCPListeners(); + tcpParser.addTCPListener(new ITCPListener() { + + public void onLoginReceived(TCPEvent event) { + } public void onGPSReceived(TCPEvent event) { SM.Debug("Got GPS message"); - TCPmsg msg= event.msg(); - //SM.Debug("Got GPS message :" + msg.allData); - - GPSmsg GPSPos= new GPSmsg(msg); - //SM.Debug("Got new GPS pos data:" + GPSPos.data); + TCPmsg msg = event.msg(); - if (getSuperVehHash().get(GPSPos.gpsValue.imei) != null) { - getSuperVehHash().get(GPSPos.gpsValue.imei).SetNewPosition(GPSPos.gpsValue.lat, GPSPos.gpsValue.lng, GPSPos.gpsValue.timeGMT, GPSPos.gpsValue.speed); - - if (getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate) { + GPSmsg gpsPositionMessage = new GPSmsg(msg); + SuperVehicle superVehicle = getSuperVehHash().get(gpsPositionMessage.gpsValue.imei); + if (superVehicle != null) { + superVehicle.SetNewPosition(gpsPositionMessage.gpsValue.lat, gpsPositionMessage.gpsValue.lng, gpsPositionMessage.gpsValue.timeGMT, gpsPositionMessage.gpsValue.speed); + + if (superVehicle.needUpdate && AppParams.crtTab == AppParams.Tabs.live) { //list for live - if (AppParams.crtTab == AppParams.Tabs.live) { - //SM.Debug("+++++ duda +++++"); - SM.Debug("currentActivity instanceof LiveActivity"); - try { - if(liveActivity != null) - liveActivity.refreshMap(); - } catch (Exception ex) { - SM.Debug("Error load hash:"+ex.toString()); - } + SM.Debug("currentActivity instanceof LiveActivity"); + try { + if (getLiveActivity() != null) + getLiveActivity().refreshMap(); + } catch (Exception ex) { + SM.Debug(HASH_ERROR_MESSAGE + ex); } } } } - + @Override public void onPollReceived(TCPEvent event) { SM.Debug("Got POLL GPS message"); - TCPmsg msg= event.msg(); - GPSmsg GPSPos= new GPSmsg(msg); - setImei(Long.toString(GPSPos.gpsValue.imei)); - setMess("LAT:"+Double.toString(GPSPos.gpsValue.lat)+" LNG:"+Double.toString(GPSPos.gpsValue.lng)); - SM.Debug("Got new Poll pos data:" + GPSPos.data); - + TCPmsg msg = event.msg(); + GPSmsg gpsPositionMessage = new GPSmsg(msg); + setImei(Long.toString(gpsPositionMessage.gpsValue.imei)); + setMess("LAT:" + gpsPositionMessage.gpsValue.lat + " LNG:" + gpsPositionMessage.gpsValue.lng); + SM.Debug("Got new Poll pos data:" + gpsPositionMessage.data); - if(getSuperVehHash().get(GPSPos.gpsValue.imei) != null) { - ((SuperVehicle) getSuperVehHash().get(GPSPos.gpsValue.imei)).SetNewPosition(GPSPos.gpsValue.lat, GPSPos.gpsValue.lng, GPSPos.gpsValue.timeGMT, GPSPos.gpsValue.speed); + SuperVehicle superVehicle = getSuperVehHash().get(gpsPositionMessage.gpsValue.imei); + + if (superVehicle != null) { + superVehicle.SetNewPosition(gpsPositionMessage.gpsValue.lat, gpsPositionMessage.gpsValue.lng, gpsPositionMessage.gpsValue.timeGMT, gpsPositionMessage.gpsValue.speed); //if is not check i need to force check to put on the map - Boolean forceChecked =false; - if (!getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate) { - getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate =true; - forceChecked =true; + boolean forceChecked = false; + if (!superVehicle.needUpdate) { + superVehicle.needUpdate = true; + forceChecked = true; } - + //back to standard procedures to put on the map - if(getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate) - { - + if (AppParams.crtTab == AppParams.Tabs.live) { //list for live - if(AppParams.crtTab == AppParams.Tabs.live) - { - //SM.Debug("+++++ duda +++++"); - //SM.Debug("currentActivity instanceof LiveActivity"); - try - { - int x = 0; - if (forceChecked) - { - for (Vehicle veh : getAllVehicle()) - { - if (veh.imei.compareTo(Long.toString(GPSPos.gpsValue.imei))==0) break; - x++; - } + try { + int x = 0; + if (forceChecked) { + for (Vehicle veh : getAllVehicle()) { + if (veh.imei.compareTo(Long.toString(gpsPositionMessage.gpsValue.imei)) == 0) + break; + x++; } - else x = -1; - if(liveActivity!=null) - { - if (x!= getAllVehicle().size()) - liveActivity.pollReceived(x ,GPSPos.gpsValue.lat,GPSPos.gpsValue.lng); - else - liveActivity.pollReceived(-1 ,GPSPos.gpsValue.lat,GPSPos.gpsValue.lng); - } - } - catch (Exception ex) - { - SM.Debug("Error load hash:"+ex.toString()); - } - } + } else x = -1; + if (getLiveActivity() != null) { + if (x != getAllVehicle().size()) + getLiveActivity().pollReceived(x, gpsPositionMessage.gpsValue.lat, gpsPositionMessage.gpsValue.lng); + else + getLiveActivity().pollReceived(-1, gpsPositionMessage.gpsValue.lat, gpsPositionMessage.gpsValue.lng); + } + } catch (Exception ex) { + SM.Debug(HASH_ERROR_MESSAGE + ex); + } } } - myHandler.post(UpdateResultsPoll); + myHandler.post(updateResultsPoll); } - public void onSMSReceived(TCPEvent event) - { - try{ - TCPmsg msg= event.msg(); - SMSmsg sms= new SMSmsg(msg); + public void onSMSReceived(TCPEvent event) { + try { + TCPmsg msg = event.msg(); + SMSmsg sms = new SMSmsg(msg); SM.Debug("am primit lista cu primele SMSuri"); //list for SMS - if(AppParams.crtTab == AppParams.Tabs.message) - { - //SM.Debug("currentActivity instanceof MessagesActivity - newSMS"); - if(messageActivity != null) - messageActivity.updateSMS(sms.smsList); + if (AppParams.crtTab == AppParams.Tabs.message && getMessageActivity() != null) { + getMessageActivity().updateSMS(sms.smsList); } - } - catch(Exception ex) - { - SM.Debug("Error on smsRecived:"+ex.toString()); + } catch (Exception ex) { + SM.Debug("Error on smsReceived:" + ex.toString()); } } public void onVehiclesReceived(TCPEvent event) { - //SM.Debug("#########################","###########################"); - TCPmsg msg= event.msg(); + TCPmsg msg = event.msg(); VehMSG vMSG = new VehMSG(msg); - SM.Debug("### Vehicle Received ###","Received " + vMSG.vehList.size() + " vehicles"); - + SM.Debug("### Vehicle Received ###", "Received " + vMSG.vehList.size() + " vehicles"); + //list for live - if(AppParams.crtTab == AppParams.Tabs.live) - { - //SM.Debug("+++++ duda +++++"); + if (AppParams.crtTab == AppParams.Tabs.live) { SM.Debug("currentActivity instanceof LiveActivity"); - try - { - for(Vehicle veh:vMSG.vehList) - { - SuperVehicle tmpSuper = new SuperVehicle(veh.sc_id,veh.imei,veh.lp, veh.name, veh.driver_id, veh.time_route, veh.GPS_reporting_interval, veh.is_stolen); - getSuperVehHash().put(Long.valueOf(veh.imei), tmpSuper); - getVehHashByScId().put(veh.sc_id, veh); - } - SM.Debug(" #$############# " + getSuperVehHash().size() + " \nVEH " + vMSG.vehList.size()); - } - catch (Exception ex) - { - SM.Debug("Error load hash:"+ex.toString()); + try { + for (Vehicle veh : vMSG.vehList) { + SuperVehicle tmpSuper = new SuperVehicle(veh.sc_id, veh.imei, veh.lp, veh.name, veh.driver_id, veh.time_route, veh.GPS_reporting_interval, veh.is_stolen); + getSuperVehHash().put(Long.valueOf(veh.imei), tmpSuper); + getVehHashByScId().put(veh.sc_id, veh); + } + SM.Debug(" #$############# " + getSuperVehHash().size() + " \nVEH " + vMSG.vehList.size()); + } catch (Exception ex) { + SM.Debug(HASH_ERROR_MESSAGE + ex); } - if(liveActivity!=null) - liveActivity.vehiclesReceived(vMSG.vehList); - } - else if(firstGetVehs) - { + if (getLiveActivity() != null) + getLiveActivity().vehiclesReceived(vMSG.vehList); + } else if (isFirstGetVehicles) { // set vehicles to liveActivity - liveActivity.vehiclesReceived(vMSG.vehList); - firstGetVehs = false; + getLiveActivity().vehiclesReceived(vMSG.vehList); + isFirstGetVehicles = false; } - + //list for SMS - if(AppParams.crtTab == AppParams.Tabs.message) - { + if (AppParams.crtTab == AppParams.Tabs.message) { SM.Debug("currentActivity instanceof MessagesActivity"); - if(messageActivity != null) - messageActivity.updateVehicles(vMSG.vehList); - } + if (getMessageActivity() != null) + getMessageActivity().updateVehicles(vMSG.vehList); + } setAllVehicle(vMSG.vehList); } public void onLastSMSsReceived(TCPEvent event) { - try - { - TCPmsg msg= event.msg(); - SMSmsg sms= new SMSmsg(msg); + try { + TCPmsg msg = event.msg(); + SMSmsg sms = new SMSmsg(msg); SM.Debug("am primit lista cu primele SMSuri"); //list for SMS - if(AppParams.crtTab == AppParams.Tabs.message) - { - //SM.Debug("currentActivity instanceof MessagesActivity"); - if(messageActivity != null) - messageActivity.updateSMS(sms.smsList); + if (AppParams.crtTab == AppParams.Tabs.message && getMessageActivity() != null) { + getMessageActivity().updateSMS(sms.smsList); } - } - catch (Exception ex) - { - SM.Debug("Error on lastSMSRecived:"+ex.toString()); + } catch (Exception ex) { + SM.Debug("Error on lastSMSReceived:" + ex); } } - + @Override public void onAlarmsReceived(TCPEvent event) { - TCPmsg msg= event.msg(); - - AlarmMSG Alarms= new AlarmMSG(msg); + TCPmsg msg = event.msg(); + + AlarmMSG alarms = new AlarmMSG(msg); SM.Debug("am primit lista cu Alarme"); - + //list for SMS - if(AppParams.crtTab == AppParams.Tabs.alarms) - { + if (AppParams.crtTab == AppParams.Tabs.alarms && getAlarmActivity() != null) { SM.Debug("currentActivity instanceof AlarmActivity"); - if(alarmActivity != null) - alarmActivity.updateAlarms(Alarms.alarmList); + getAlarmActivity().updateAlarms(alarms.alarmList); } } - - + @Override public void onAlarmAckReceived(TCPEvent event) { - TCPmsg msg= event.msg(); - - SM.Debug("Got alarmACK :" + msg.allData); - String[] tempArr =msg.data.split("#"); - if (Integer.parseInt(tempArr[0])==1 && AppParams.crtTab == AppParams.Tabs.alarms) - { - if(alarmActivity != null) - alarmActivity.updateACK(); + TCPmsg msg = event.msg(); + + SM.Debug("Got alarmACK :" + msg.allData); + String[] tempArr = msg.data.split("#"); + if (Integer.parseInt(tempArr[0]) == 1 && AppParams.crtTab == AppParams.Tabs.alarms && getAlarmActivity() != null) { + getAlarmActivity().updateACK(); } } @Override public void onSMSAckReceived(TCPEvent event) { - TCPmsg msg= event.msg(); - SMSmsg sms= new SMSmsg(msg); + TCPmsg msg = event.msg(); + SMSmsg sms = new SMSmsg(msg); SM.Debug("Got smsComfirm msg.data:" + msg.data); - - if (messageActivity != null) - messageActivity.confirmSMS(sms.data, msg.seqID); + + if (getMessageActivity() != null) + getMessageActivity().confirmSMS(sms.data, msg.seqID); } @Override public void onNewSMSReceived(TCPEvent event) { - TCPmsg msg= event.msg(); + TCPmsg msg = event.msg(); SM.Debug("Got smsNew :" + msg.allData); - String[] tempArr =msg.data.split("#"); + String[] tempArr = msg.data.split("#"); SM.Debug("Unit imei:" + tempArr[0]); SM.Debug("Message:" + tempArr[1]); - + // change Visual Elements setImei(tempArr[0]); setMess(tempArr[1]); @@ -1451,473 +1306,375 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ try { // get time from the last received sms and divide it to 1000 to convert it to seconds time = Long.parseLong(msg.seqID.replace('.', '#').split("#")[1]) / 1000 - 100; + } catch (Exception ignored) { + //ignored } - catch(Exception ex) { - } - + // if tab is not TextTab - if(tabHost.getCurrentTab() != 2) { - myHandler.post(UpdateResults); - //mHandler.dispatchMessage(new Message()); + if (tabHost.getCurrentTab() != 2) { + myHandler.post(updateResults); } else - myHandler.post(() -> { - // create Notification - createNotification(AppParams.messageNotif); - }); + myHandler.post(() -> + createNotification(AppParams.messageNotif)); + //list for SMS - if(AppParams.crtTab == AppParams.Tabs.message && messageActivity!= null) { + if (AppParams.crtTab == AppParams.Tabs.message && getMessageActivity() != null) { SM.Debug("currentActivity instanceof MessagesActivity - newSMS | " + tempArr[0] + " | " + tempArr[1]); - messageActivity.newSMS(tempArr[0], tempArr[1], time); + getMessageActivity().newSMS(tempArr[0], tempArr[1], time); } } - + @Override public void onRecordingPlayReceived(TCPEvent event) { - TCPmsg msg= event.msg(); + TCPmsg msg = event.msg(); SM.Debug("Got PlayRec :" + msg.allData); - - if(NOSOUND) - { - //String[] tempArr =msg.data.split("#"); - //SM.Debug("Unit imei:" + tempArr[0]); + + if (NO_SOUND) { SM.Debug("Recording Play file ID:" + msg.data); - + //list for SMS - if(AppParams.crtTab == AppParams.Tabs.recordings) - { + if (AppParams.crtTab == AppParams.Tabs.recordings) { String tmp = msg.data.replace("#", ""); - + try { long id = Long.parseLong(tmp); - if(recordingsActivity != null) - recordingsActivity.PlayRecording(id); - } - catch(Exception ex) { + if (getRecordingsActivity() != null) + getRecordingsActivity().PlayRecording(id); + } catch (Exception ex) { SM.Exception(ex.toString()); } } - } + } } - + @Override public void onLastPositionsReceived(TCPEvent event) { - TCPmsg msg= event.msg(); + TCPmsg msg = event.msg(); SM.Debug("Got last pos"); - LastPosmsg lastPos= new LastPosmsg(msg); - //SM.Debug("Got LastPost msg.data:" + msg.data); - for(LastPos posMsg: lastPos.PosList) { - if(getSuperVehHash().get(posMsg.imei) != null) - getSuperVehHash().get(posMsg.imei).SetDataFromLastPos(posMsg.lat, posMsg.lng, posMsg.timeGMT, posMsg.speed, posMsg.Address, posMsg.isON); + LastPosmsg lastPos = new LastPosmsg(msg); + for (LastPos posMsg : lastPos.PosList) { + SuperVehicle superVehicle = getSuperVehHash().get(posMsg.imei); + if (superVehicle != null) + superVehicle.SetDataFromLastPos(posMsg.lat, posMsg.lng, posMsg.timeGMT, posMsg.speed, posMsg.Address, posMsg.isON); } } - + @Override public void onHistoryPositionsCountReceived(TCPEvent event) { - TCPmsg msg= event.msg(); + TCPmsg msg = event.msg(); SM.Debug("Got POS Count"); - //SM.Debug("Got lastpos :" + msg.allData); - - HistCountmsg histcount= new HistCountmsg(msg); - SM.Debug("Message Count:"+histcount.histcountValue.count); - //SM.Debug("Got LastPost msg.data:" + msg.data); - if (histcount.histcountValue.count>=2000) - { + + HistCountmsg histCountMsg = new HistCountmsg(msg); + SM.Debug("Message Count:" + histCountMsg.histcountValue.count); + if (histCountMsg.histcountValue.count >= 2000 && AppParams.crtTab == AppParams.Tabs.history) { //list for live - if(AppParams.crtTab == AppParams.Tabs.history) - { - //SM.Debug("+++++ duda +++++"); - SM.Debug("currentActivity instanceof HistoryActivity"); - try - { - if(historyActivity != null) - { - historyActivity.UpdateCancel(); - historyActivity.UpdateUnableDisp(); - } - //dialogLoading.cancel(); - } - catch (Exception ex) - { - SM.Debug("Error load hash:"+ex.toString()); - } - } - } - } - - @Override - public void onHistoryPositionsReceived(TCPEvent event) { - TCPmsg msg= event.msg(); - SM.Debug("Got HistoryPos :" + msg.allData); - if (!dropAllData){ - HistPosmsg tmpHist= new HistPosmsg(msg); - Boolean SendDataToMap =true; - try{ - - for (HistPos obj : tmpHist.PosList) - HistPosList.add(obj); - - SM.Debug("tmpHist seqID:"+tmpHist.seqID); - // - int pos = Integer.parseInt(tmpHist.seqID.substring(0,tmpHist.seqID.indexOf('.'))); - int all = Integer.parseInt(tmpHist.seqID.substring(tmpHist.seqID.indexOf('.')+1,tmpHist.seqID.length())); - if (all!=0) - { - if (firstHistData) - { - try - { - for(int i=0;i() - { - public int compare(Object o1, Object o2) { - HistPos p1 = (HistPos) o1; - HistPos p2 = (HistPos) o2; - if (p1.timeGMT) (o1, o2) -> { + HistPos p1 = (HistPos) o1; + HistPos p2 = (HistPos) o2; + return Long.compare(p1.timeGMT, p2.timeGMT); + }); + + //list for live + if (AppParams.crtTab == AppParams.Tabs.history) { + try { + if (getHistoryActivity() != null) { + // cancel last update + getHistoryActivity().UpdateCancel(); + + Thread.sleep(101); + if (getHistoryPositionList().size() < 2000) { + if ((getHistoryPositionList().size() != 1) || (getHistoryPositionList().get(0).timeGMT != 0)) { + getHistoryActivity().UpdateNrPos(getHistoryPositionList().size()); + } + + Thread.sleep(100); + + getHistoryActivity().UpdateMap(); + } else + getHistoryActivity().UpdateUnableDisp(); // update with more than 200 points + } + } catch (Exception ex) { + SM.Debug(HASH_ERROR_MESSAGE + ex); + Thread.currentThread().interrupt(); + } + } + SM.Debug("Got HistPost msg.data:" + msg.data); + } + } else SM.Debug("Drop history data"); } @Override public void onRadioMsgReceived(TCPEvent event) { SM.Debug("#### RadioMsgRecv"); - TCPmsg msg= event.msg(); - RadioMSG rmsg = new RadioMSG(msg); - - if(!NOSOUND) - { - - // update Zone and Channel - if(radioActivity != null && rmsg.zac !=null) - { - // update Zone and Channel in the allRadio List - for(RadioGW radio: allRadios) { - if(radio.GW_ID == rmsg.zac.gwID && radio.ID == rmsg.zac.rgwID) { - radio.lastZoneNr = rmsg.zac.zoneNr; - radio.lastChannelNr = rmsg.zac.channelNr; + TCPmsg msg = event.msg(); + RadioMSG radioMSG = new RadioMSG(msg); + + if (!NO_SOUND) { + // update Zone and Channel + if (getRadioActivity() != null && radioMSG.zac != null) { + // update Zone and Channel in the allRadio List + for (RadioGW radio : getAllRadios()) { + if (radio.GW_ID == radioMSG.zac.gwID && radio.ID == radioMSG.zac.rgwID) { + radio.lastZoneNr = radioMSG.zac.zoneNr; + radio.lastChannelNr = radioMSG.zac.channelNr; + } } + + AppParams.crtZoneAndChannel = radioMSG.zac; + notifyBroadcast(OperationCodes.CHANNEL_BRDCST + ""); + SM.Debug("Received from Apps -> UpdateZoneCH(" + radioMSG.zac.rgwID + "," + radioMSG.zac.gwID + "," + radioMSG.zac.zoneNr + "," + radioMSG.zac.channelNr + ")"); } - - AppParams.crtZoneAndChannel = rmsg.zac; - notifyBroadcast(OperationCodes.CHANNEL_BRDCST+""); - //radioActivity.UpdateZoneCH(rmsg.zac.rgwID, rmsg.zac.gwID, rmsg.zac.zoneNr, rmsg.zac.channelNr); - SM.Debug("Received from Apps -> UpdateZoneCH(" + rmsg.zac.rgwID + "," + rmsg.zac.gwID + "," + rmsg.zac.zoneNr + "," + rmsg.zac.channelNr + ")"); - } - - - - //list for SMS - if(AppParams.crtTab == AppParams.Tabs.radio) - { - SM.Debug("#### RadioActivity"); - // set crt activity to Radio - crtActivity = RADIO; - - SM.Debug("## " + (rmsg.RadioGWList!=null? "RadioGWList" + rmsg.RadioGWList.size() : "RadioGWList = null")); - SM.Debug("## " + (rmsg.zac!=null? "zac" + rmsg.zac.toString() : "zac = null")); - SM.Debug("## " + (rmsg.rStatus!=null? "rStatus" + rmsg.rStatus.toString() : "rStatus = null")); - - if(radioActivity!= null && rmsg.RadioGWList!=null) - { - radioActivity.UpdateRadios(rmsg.RadioGWList); - SM.Debug("Received from Apps -> UpdateRadios( count:" + rmsg.RadioGWList.size() + ")"); - } - - - - if(radioActivity != null &&rmsg.rStatus !=null) - { - - // update status in the crtRadio List - for(RadioGW radio: allRadios) { - if(radio.GW_ID == rmsg.rStatus.gwID && radio.ID == rmsg.rStatus.rgwID) - radio.isOnline = (rmsg.rStatus.status == 1 ? true : false); + + //list for SMS + if (AppParams.crtTab == AppParams.Tabs.radio) { + SM.Debug("#### RadioActivity"); + // set crt activity to Radio + setCrtActivity(RADIO_TAB_ID); + + SM.Debug("## " + (radioMSG.RadioGWList != null ? "RadioGWList" + radioMSG.RadioGWList.size() : "RadioGWList = null")); + SM.Debug("## " + (radioMSG.zac != null ? "zac" + radioMSG.zac : "zac = null")); + SM.Debug("## " + (radioMSG.rStatus != null ? "rStatus" + radioMSG.rStatus : "rStatus = null")); + + if (getRadioActivity() != null && radioMSG.RadioGWList != null) { + getRadioActivity().UpdateRadios(radioMSG.RadioGWList); + SM.Debug("Received from Apps -> UpdateRadios( count:" + radioMSG.RadioGWList.size() + ")"); } - - SM.Debug("Received from Apps -> UpdateRadioStatus(" + rmsg.rStatus.rgwID + "," + rmsg.rStatus.gwID + "," + rmsg.rStatus.status+ ")"); - if ((crtRadio != null)&&(crtRadio.GW_ID == rmsg.rStatus.gwID)&&(crtRadio.ID == rmsg.rStatus.rgwID)) - radioActivity.UpdateRadioStatus(rmsg.rStatus.status); - } - //incCall - if (radioActivity != null && rmsg.incCall !=null) - { - SM.Debug("Received from Apps -> UpdateBroadcastCall(" + rmsg.incCall.Imei + "," + rmsg.incCall.callType + "," + rmsg.incCall.groupId+ ")"); - - // check if radioID and radioGW_ID needs to be changed - if(crtRadio != null && (crtRadio.GW_ID != rmsg.incCall.gwID || crtRadio.ID != rmsg.incCall.rgwID)) { - - for(RadioGW radio: allRadios) { - if(radio.GW_ID == rmsg.incCall.gwID && radio.ID == rmsg.incCall.rgwID) { - crtRadio = radio; - notifyBroadcast(OperationCodes.RADIOID_CHANGED + ""); - break; + + if (getRadioActivity() != null && radioMSG.rStatus != null) { + // update status in the crtRadio List + for (RadioGW radio : getAllRadios()) { + if (radio.GW_ID == radioMSG.rStatus.gwID && radio.ID == radioMSG.rStatus.rgwID) + radio.isOnline = (radioMSG.rStatus.status == 1); + } + + SM.Debug("Received from Apps -> UpdateRadioStatus(" + radioMSG.rStatus.rgwID + "," + radioMSG.rStatus.gwID + "," + radioMSG.rStatus.status + ")"); + if ((getCrtRadio() != null) && (getCrtRadio().GW_ID == radioMSG.rStatus.gwID) && (getCrtRadio().ID == radioMSG.rStatus.rgwID)) + getRadioActivity().UpdateRadioStatus(radioMSG.rStatus.status); + } + //incCall + if (getRadioActivity() != null && radioMSG.incCall != null) { + SM.Debug("Received from Apps -> UpdateBroadcastCall(" + radioMSG.incCall.Imei + "," + radioMSG.incCall.callType + "," + radioMSG.incCall.groupId + ")"); + + // check if radioID and radioGW_ID needs to be changed + if (getCrtRadio() != null && (getCrtRadio().GW_ID != radioMSG.incCall.gwID || getCrtRadio().ID != radioMSG.incCall.rgwID)) { + + for (RadioGW radio : getAllRadios()) { + if (radio.GW_ID == radioMSG.incCall.gwID && radio.ID == radioMSG.incCall.rgwID) { + setCrtRadio(radio); + notifyBroadcast(OperationCodes.RADIOID_CHANGED + ""); + break; + } } } - } - - if(crtRadio != null) - { - if(rmsg.incCall.callStatus == 3) - { - inCall = false; + + if (getCrtRadio() != null) { + setInCall(radioMSG.incCall.callStatus != 3); + + getRadioActivity().UpdateBroadcastCall(radioMSG.incCall.Imei, radioMSG.incCall.callType, radioMSG.incCall.groupId, radioMSG.incCall.callStatus); } - else - inCall = true; - - radioActivity.UpdateBroadcastCall(rmsg.incCall.Imei,rmsg.incCall.callType,rmsg.incCall.groupId,rmsg.incCall.callStatus); + } - - } - } - else - { - if (rmsg.incCall !=null) - { - crtActivity = 0; - //incCall - update UI in Radio Activity - SM.Debug("Received from Apps -> UpdateBroadcastCall(" + rmsg.incCall.Imei + "," + rmsg.incCall.callType + "," + rmsg.incCall.groupId+ ")"); - - // check if radioID and radioGW_ID needs to be changed - if(crtRadio != null && (crtRadio.GW_ID != rmsg.incCall.gwID || crtRadio.ID != rmsg.incCall.rgwID)) { - - for(RadioGW radio: allRadios) { - if(radio.GW_ID == rmsg.incCall.gwID && radio.ID == rmsg.incCall.rgwID) { - crtRadio = radio; - notifyBroadcast(OperationCodes.RADIOID_CHANGED + ""); - break; + } else { + if (radioMSG.incCall != null) { + setCrtActivity(0); + //incCall - update UI in Radio Activity + SM.Debug("Received from Apps -> UpdateBroadcastCall(" + radioMSG.incCall.Imei + "," + radioMSG.incCall.callType + "," + radioMSG.incCall.groupId + ")"); + + // check if radioID and radioGW_ID needs to be changed + if (getCrtRadio() != null && (getCrtRadio().GW_ID != radioMSG.incCall.gwID || getCrtRadio().ID != radioMSG.incCall.rgwID)) { + + for (RadioGW radio : getAllRadios()) { + if (radio.GW_ID == radioMSG.incCall.gwID && radio.ID == radioMSG.incCall.rgwID) { + setCrtRadio(radio); + notifyBroadcast(OperationCodes.RADIOID_CHANGED + ""); + break; + } } } - } - - if (crtRadio != null) - { - if(rmsg.incCall.callStatus == 3) - { - inCall = false; - // update recordings list - if(AppParams.crtTab == AppParams.Tabs.recordings) - { - // no recording is playing - if(recordingsActivity != null && recordingsActivity.playingPosition < 0) - getRecordings(crtRadio.GW_ID, crtRadio.ID); - } + + if (getCrtRadio() != null) { + if (radioMSG.incCall.callStatus == 3) { + setInCall(false); + // update recordings list + if (AppParams.crtTab == AppParams.Tabs.recordings && getRecordingsActivity() != null && getRecordingsActivity().playingPosition < 0) { + // no recording is playing + getRecordings(getCrtRadio().GW_ID, getCrtRadio().ID); + } + } else + setInCall(true); + getRadioActivity().UpdateBroadcastCall(radioMSG.incCall.Imei, radioMSG.incCall.callType, radioMSG.incCall.groupId, radioMSG.incCall.callStatus); } - else - inCall = true; - radioActivity.UpdateBroadcastCall(rmsg.incCall.Imei,rmsg.incCall.callType,rmsg.incCall.groupId,rmsg.incCall.callStatus); } - - - } - - if(rmsg.RadioGWList!=null && radioActivity!=null) - radioActivity.UpdateRadios(rmsg.RadioGWList); - - if(rmsg.zac !=null && radioActivity!=null) { - radioActivity.UpdateZoneCH(rmsg.zac.rgwID, rmsg.zac.gwID, rmsg.zac.zoneNr, rmsg.zac.channelNr); - } - - if(rmsg.rStatus !=null && radioActivity!=null) - { - // update status in the allRadio List - for(RadioGW radio: allRadios) { - if(radio.GW_ID == rmsg.rStatus.gwID && radio.ID == rmsg.rStatus.rgwID) - radio.isOnline = (rmsg.rStatus.status == 1 ? true : false); + + if (radioMSG.RadioGWList != null && getRadioActivity() != null) + getRadioActivity().UpdateRadios(radioMSG.RadioGWList); + + if (radioMSG.zac != null && getRadioActivity() != null) { + getRadioActivity().UpdateZoneCH(radioMSG.zac.rgwID, radioMSG.zac.gwID, radioMSG.zac.zoneNr, radioMSG.zac.channelNr); + } + + if (radioMSG.rStatus != null && getRadioActivity() != null) { + // update status in the allRadio List + for (RadioGW radio : getAllRadios()) { + if (radio.GW_ID == radioMSG.rStatus.gwID && radio.ID == radioMSG.rStatus.rgwID) + radio.isOnline = (radioMSG.rStatus.status == 1); + } + + if ((getCrtRadio() != null) && (getCrtRadio().GW_ID == radioMSG.rStatus.gwID) && (getCrtRadio().ID == radioMSG.rStatus.rgwID)) + getRadioActivity().UpdateRadioStatus(radioMSG.rStatus.status); } - - if ((crtRadio != null)&&(crtRadio.GW_ID == rmsg.rStatus.gwID)&&(crtRadio.ID == rmsg.rStatus.rgwID)) - radioActivity.UpdateRadioStatus(rmsg.rStatus.status); } - - } - - - // save RadioList - if(rmsg.RadioGWList!=null) - { - allRadios = rmsg.RadioGWList; - if(crtRadio == null) - { - crtRadio = allRadios.get(0); - SM.Debug("rmsg set 0 crtRadio GW_ID:"+crtRadio.GW_ID+" ID:"+crtRadio.ID+")"); - - notifyBroadcast(OperationCodes.RADIOID_CHANGED+""); + + // save RadioList + if (radioMSG.RadioGWList != null) { + setAllRadios(radioMSG.RadioGWList); + if (getCrtRadio() == null) { + setCrtRadio(getAllRadios().get(0)); + SM.Debug("radioMSG set 0 crtRadio GW_ID:" + getCrtRadio().GW_ID + " ID:" + getCrtRadio().ID + ")"); + + notifyBroadcast(OperationCodes.RADIOID_CHANGED + ""); + } } - } - - // save crt Radio ID and GW - if(rmsg.zac !=null) - { - for(RadioGW radio: allRadios) { - if(radio.GW_ID == rmsg.zac.gwID && radio.ID == rmsg.zac.rgwID) - crtRadio = radio; + + // save crt Radio ID and GW + if (radioMSG.zac != null) { + for (RadioGW radio : getAllRadios()) { + if (radio.GW_ID == radioMSG.zac.gwID && radio.ID == radioMSG.zac.rgwID) + setCrtRadio(radio); + } + } + + if (AppParams.crtTab == AppParams.Tabs.recordings && getRecordingsActivity() != null && radioMSG.RadioGWList != null) { + SM.Debug("GetRecordings Request + crtRadio:" + getCrtRadio().toString()); + getRecordings(getCrtRadio().GW_ID, getCrtRadio().ID); } } - - if(AppParams.crtTab == AppParams.Tabs.recordings) - { - if(recordingsActivity != null && rmsg.RadioGWList!=null) - { - SM.Debug("GetRecordings Request + crtRadio:"+ crtRadio.toString()); - getRecordings(crtRadio.GW_ID, crtRadio.ID); - } - } - - - } - - // used when a unit is enabled / disabled - if(rmsg.suStatus !=null) { - SM.Debug("ENABLED/DISABLED " + rmsg.suStatus); - notifyBroadcast(OperationCodes.UNIT_STATUS_UPDATE+"", rmsg.suStatus.imei + "#" +rmsg.suStatus.status); - } - else - SM.Debug("SUStatus is null"); + // used when a unit is enabled / disabled + if (radioMSG.suStatus != null) { + SM.Debug("ENABLED/DISABLED " + radioMSG.suStatus); + notifyBroadcast(OperationCodes.UNIT_STATUS_UPDATE + "", radioMSG.suStatus.imei + "#" + radioMSG.suStatus.status); + } else + SM.Debug("SUStatus is null"); } @Override - public void alarmLiveRecv(TCPEvent event) { - TCPmsg msg= event.msg(); + public void alarmLiveReceived(TCPEvent event) { + TCPmsg msg = event.msg(); SM.Debug("Got alarmNew :" + msg.allData); - - String[] tempArr =msg.data.split("#"); + + String[] tempArr = msg.data.split("#"); SM.Debug("Unit imei:" + tempArr[0]); - String UnitIMEI =tempArr[0]; - //SM.Debug("Message:" + tempArr[1]); - + String unitIMEI = tempArr[0]; + //list for SMS - if(AppParams.crtTab == AppParams.Tabs.alarms) - { + if (AppParams.crtTab == AppParams.Tabs.alarms) { SM.Debug("currentActivity instanceof AlarmActivity - newSMS | " + tempArr[0] + " | " + tempArr[1]); getAlarms(AppParams.USERID); - } + } // if tab is not TextTab - if(tabHost.getCurrentTab() != 5) - { + if (tabHost.getCurrentTab() != 5) { // change Visual Elements - setImei(UnitIMEI); - switch (msg.opCode) - { - case 135: setMess("speed "+tempArr[1]); - break; - case 136: setMess("landmark "+tempArr[1]); - break; - case 137: setMess("zone "+tempArr[1]); - break; - case 138: setMess("emergency"); - break; - case 140: setMess("telemetry "+ tempArr[1]); - break; - default: - setMess("emergency"); - } - myHandler.post(UpdateResultsAlarm); - - if ((msg.opCode==138)&&(AppParams.crtTab == AppParams.Tabs.live)) - { - if(getSuperVehHash().get(Long.parseLong(UnitIMEI)) != null) - { + setImei(unitIMEI); + switch (msg.opCode) { + case 135: + setMess("speed " + tempArr[1]); + break; + case 136: + setMess("landmark " + tempArr[1]); + break; + case 137: + setMess("zone " + tempArr[1]); + break; + case 138: + setMess("emergency"); + break; + case 140: + setMess("telemetry " + tempArr[1]); + break; + default: + setMess("emergency"); + } + myHandler.post(updateResultsAlarm); + + if ((msg.opCode == 138) && (AppParams.crtTab == AppParams.Tabs.live)) { + SuperVehicle superVehicle = getSuperVehHash().get(Long.parseLong(unitIMEI)); + + if (superVehicle != null) { //if is not check i need to force check to put on the map - Boolean forceChecked =false; - if (!getSuperVehHash().get(Long.parseLong(UnitIMEI)).needUpdate) - { - getSuperVehHash().get(Long.parseLong(UnitIMEI)).needUpdate =true; - forceChecked =true; - } - try - { + boolean forceChecked = false; + if (!superVehicle.needUpdate) { + superVehicle.needUpdate = true; + forceChecked = true; + } + try { int x = 0; - if (forceChecked) - { - for (Vehicle veh : getAllVehicle()) - { - if (veh.imei.compareTo(UnitIMEI)==0) break; + if (forceChecked) { + for (Vehicle veh : getAllVehicle()) { + if (veh.imei.compareTo(unitIMEI) == 0) break; x++; - } - } - else x = -1; - if(liveActivity != null) - { - if (x!= getAllVehicle().size()) - liveActivity.emergencyAlarmReceived(x , getSuperVehHash().get(Long.parseLong(UnitIMEI)).lat, getSuperVehHash().get(Long.parseLong(UnitIMEI)).lng); + } + } else x = -1; + if (getLiveActivity() != null) { + if (x != getAllVehicle().size()) + getLiveActivity().emergencyAlarmReceived(x, superVehicle.lat, superVehicle.lng); else - liveActivity.emergencyAlarmReceived(-1, getSuperVehHash().get(Long.parseLong(UnitIMEI)).lat, getSuperVehHash().get(Long.parseLong(UnitIMEI)).lng); + getLiveActivity().emergencyAlarmReceived(-1, superVehicle.lat, superVehicle.lng); } - } - catch (Exception ex) - { - SM.Debug("Error load hash:"+ex.toString()); - } + } catch (Exception ex) { + SM.Debug(HASH_ERROR_MESSAGE + ex); + } } } } @@ -1925,26 +1682,25 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ @Override public void onRecordingsListReceived(TCPEvent event) { - TCPmsg msg= event.msg(); - RecordMSG Records= new RecordMSG(msg); + TCPmsg msg = event.msg(); + RecordMSG recordMSG = new RecordMSG(msg); SM.Debug("am primit lista cu Recording"); - + //list for SMS - if(AppParams.crtTab == AppParams.Tabs.recordings) - { - for(Recording rec: Records.recordList) - { + if (AppParams.crtTab == AppParams.Tabs.recordings) { + for (Recording rec : recordMSG.recordList) { // set the name to be displayed - if (rec.typeID==1) - rec.NameForDisplay = AppParams.USERNAME; - else { - if (getSuperVehHash().get((long)rec.subID)!=null) - rec.NameForDisplay = getSuperVehHash().get((long)rec.subID).name; + if (rec.typeID == 1) + rec.NameForDisplay = AppParams.USERNAME; + else { + SuperVehicle superVehicle = getSuperVehHash().get((long) rec.subID); + if (superVehicle != null) + rec.NameForDisplay = superVehicle.name; } } - // save recodings to AppParams - AppParams.recordings = Records.recordList; + // save recordings to AppParams + AppParams.recordings = recordMSG.recordList; // notify recordings were received notifyBroadcast(OperationCodes.RECORDINGS_LIST_REP + ""); @@ -1953,514 +1709,284 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ @Override public void onConnectionReplyReceived(TCPEvent event) { - + } @Override public void onContactsListReceived(TCPEvent event) { - // TODO Auto-generated method stub - + } @Override public void onTextMessagesListReceived(TCPEvent event) { - // TODO Auto-generated method stub - + } @Override - public void onTCPConnectionDown(boolean previousConnectionWasUP) { + public void onTCPConnectionDown(boolean previousWasConnectionUp) { // execute logout whenBackPressed(AppParams.ActivityResult.tcpDown); - + // send a broadcast notifyBroadcast(OperationCodes.TCP_CONNECTION_DOWN + ""); + } + + @Override + public void onTCPConnectionUp(boolean previousWasConnectionUp) { } @Override - public void onTCPConnectionUp(boolean previousConnectionWasUP) { - - } + public void onTCPConnectionStatusReceived(boolean isConnectionUp, boolean previousWasConnectionUp) { - @Override - public void onTCPConnectionStatusReceived(boolean isConnectionUp, boolean previuosWasConnectionUp) { - } @Override public void onPONGReceived() { - + } - - }); + + }); } // Create runnable for posting - public final Runnable showPopUpRUN = new Runnable() { - public void run() { - updateResultsInUi("realpha"); - } - }; - - // Create runnable for posting - final Runnable UpdateResultsAlarm = new Runnable() { - public void run() { - updateResultsAlarmInUi("realpha"); - } - }; - - public void updateResultsAlarmInUi(String animation) { - // Back in the UI thread - // set TextViews - if(tcp!=null && !AppParams.DEMO) - { - try - { - activePopupType= MsgType.ALARM; - imageViewPopUp.setImageResource(R.drawable.siren_on); - slideTabsText.setText(getString(R.string.newAlarm)); - if (getVehicle4Imei(getImei())!=null) - textViewNMFrom.setText(getString(R.string.from) + ": " + getVehicle4Imei(getImei()).name); - else textViewNMFrom.setText(getString(R.string.from) + ": " + getImei()); - textViewNMMessage.setText("TYPE: " + getMess()); + final Runnable updateResultsAlarm = () -> updateResultsAlarmInUi("realpha"); + + public void updateResultsAlarmInUi(String animation) { + // Back in the UI thread + // set TextViews + if (tcp != null && !AppParams.DEMO) { + try { + setActivePopupType(MsgType.ALARM); + imageViewPopUp.setImageResource(R.drawable.siren_on); + slideTabsText.setText(getString(R.string.newAlarm)); + Vehicle vehicle = getVehicle4Imei(getImei()); + if (vehicle != null) + textViewNMFrom.setText(String.format("%s: %s", getString(R.string.from), vehicle.name)); + else textViewNMFrom.setText(String.format("%s: %s", getString(R.string.from), getImei())); + textViewNMMessage.setText(String.format("TYPE: %s", getMess())); // show layout layoutNewMessage.setVisibility(View.VISIBLE); - - Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); - if(animation.equals("realpha")) - anim = AnimationUtils.loadAnimation(this, R.anim.realpha); - anim.reset(); - layoutNewMessage.clearAnimation(); - layoutNewMessage.startAnimation(anim); - - // create Notification - createNotification(AppParams.alertNotif); - } - catch (Exception ex) - { - SM.Debug("Erorr on update alarm:"+ex.toString()); - } - - - } - } - - - // Create runnable for posting - final Runnable UpdateResultsPoll = new Runnable() { - public void run() { - updateResultsPollInUi("realpha"); - } - }; - - public void updateResultsPollInUi(String animation) { - // Back in the UI thread - // set TextViews - String from = ""; - Vehicle fromVehicle = null; - if((fromVehicle = getVehicle4Imei(getImei())) != null) - from = fromVehicle.name; - - if(tcp!=null && !AppParams.DEMO) - { - activePopupType =MsgType.POLL; - imageViewPopUp.setImageResource(R.drawable.poll); - slideTabsText.setText("Poll Reply"); - textViewNMFrom.setText("From: " + from); - textViewNMMessage.setText(getMess()); - // show layout - layoutNewMessage.setVisibility(View.VISIBLE); - - Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); - if(animation.equals("realpha")) - anim = AnimationUtils.loadAnimation(this, R.anim.realpha); - anim.reset(); - layoutNewMessage.clearAnimation(); - layoutNewMessage.startAnimation(anim); - } - else if (AppParams.DEMO) - { - activePopupType =MsgType.POLL; - imageViewPopUp.setImageResource(R.drawable.poll); - slideTabsText.setText("Poll Reply"); - textViewNMFrom.setText("From: " + from); - textViewNMMessage.setText(getMess()); - // show layout - layoutNewMessage.setVisibility(View.VISIBLE); - /* - Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); - if(animation.equals("realpha")) - anim = AnimationUtils.loadAnimation(this, R.anim.realpha); - anim.reset(); - layoutNewMessage.clearAnimation(); - layoutNewMessage.startAnimation(anim); - */ - } - - // create Notification - createNotification(AppParams.pollNotif); - } - + Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); + if (animation.equals("realpha")) + anim = AnimationUtils.loadAnimation(this, R.anim.realpha); + anim.reset(); + layoutNewMessage.clearAnimation(); + layoutNewMessage.startAnimation(anim); + + // create Notification + createNotification(AppParams.alertNotif); + } catch (Exception ex) { + SM.Debug("Error on update alarm:" + ex); + } + } + } + // Create runnable for posting - final Runnable UpdateResults = new Runnable() { - public void run() { - updateResultsInUi("realpha"); - } - }; - - public void updateResultsInUi(String animation) { - // Back in the UI thread - // set TextViews - if(tcp!=null && !AppParams.DEMO) - { - activePopupType = MsgType.SMS; - imageViewPopUp.setImageResource(R.drawable.message); - slideTabsText.setText("New Message"); + final Runnable updateResultsPoll = () -> updateResultsPollInUi("realpha"); + + public void updateResultsPollInUi(String animation) { + // Back in the UI thread + // set TextViews + String from = ""; + Vehicle fromVehicle; + if ((fromVehicle = getVehicle4Imei(getImei())) != null) + from = fromVehicle.name; + + if (tcp != null && !AppParams.DEMO) { + setActivePopupType(MsgType.POLL); + imageViewPopUp.setImageResource(R.drawable.poll); + slideTabsText.setText(getString(R.string.newPoll)); + textViewNMFrom.setText(String.format("%s: %s", getString(R.string.from), from)); + textViewNMMessage.setText(getMess()); + // show layout + layoutNewMessage.setVisibility(View.VISIBLE); + + Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); + if (animation.equals("realpha")) + anim = AnimationUtils.loadAnimation(this, R.anim.realpha); + anim.reset(); + layoutNewMessage.clearAnimation(); + layoutNewMessage.startAnimation(anim); + } else if (AppParams.DEMO) { + setActivePopupType(MsgType.POLL); + imageViewPopUp.setImageResource(R.drawable.poll); + slideTabsText.setText(R.string.newPoll); + textViewNMFrom.setText(getString(R.string.from) + ": " + from); + textViewNMMessage.setText(getMess()); + // show layout + layoutNewMessage.setVisibility(View.VISIBLE); + } + + // create Notification + createNotification(AppParams.pollNotif); + } + + // Create runnable for posting + final Runnable updateResults = () -> updateResultsInUi("realpha"); + + public void updateResultsInUi(String animation) { + // Back in the UI thread + // set TextViews + if (tcp != null && !AppParams.DEMO) { + setActivePopupType(MsgType.SMS); + imageViewPopUp.setImageResource(R.drawable.message); + slideTabsText.setText("New Message"); textViewNMFrom.setText("From: " + getVehicle4Imei(getImei()).name); textViewNMMessage.setText("MSG: " + getMess()); // show layout layoutNewMessage.setVisibility(View.VISIBLE); - + Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); - if(animation.equals("realpha")) + if (animation.equals("realpha")) anim = AnimationUtils.loadAnimation(this, R.anim.realpha); - anim.reset(); - layoutNewMessage.clearAnimation(); - layoutNewMessage.startAnimation(anim); - } - else if(AppParams.DEMO) - { - setMess("i got your sms"); - activePopupType = MsgType.SMS; - imageViewPopUp.setImageResource(R.drawable.message); - slideTabsText.setText("New Message"); + anim.reset(); + layoutNewMessage.clearAnimation(); + layoutNewMessage.startAnimation(anim); + } else if (AppParams.DEMO) { + setMess("i got your sms"); + setActivePopupType(MsgType.SMS); + imageViewPopUp.setImageResource(R.drawable.message); + slideTabsText.setText("New Message"); textViewNMFrom.setText("From: " + getVehicle4Imei(getImei()).name); textViewNMMessage.setText("MSG: " + "i got your sms"); // show layout layoutNewMessage.setVisibility(View.VISIBLE); - - // create Notification - createNotification(AppParams.messageNotif); - /* - Animation anim = AnimationUtils.loadAnimation(this, R.anim.realpha); - layoutNewMessage.clearAnimation(); - layoutNewMessage.startAnimation(anim); - */ - } - - // create Notification - createNotification(AppParams.messageNotif); - } - public void createNotification(int icon) { - mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + // create Notification + createNotification(AppParams.messageNotif); + } + + // create Notification + createNotification(AppParams.messageNotif); + } + + public void createNotification(int icon) { + mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); String tickerText = "SafeMobile Dispatch: New Message from " + getImei(); String contentTitle = "New Message from " + getImei(); String contentText = "\"" + getMess() + "\""; - + Vehicle veh = getVehicle4Imei(getImei()); - - int icon_value = icon; - switch(icon) - { - case AppParams.messageNotif: - contentText = "\"" + getMess() + "\""; - contentTitle = "New Message from " + getImei(); - icon = R.drawable.message; - break; - case AppParams.pollNotif: - contentText = "\"" + getMess() + "\"" ; - contentTitle = "Poll Reply from " + (veh !=null ? getVehicle4Imei(getImei()).name : getImei()); - tickerText = "SafeMobile Dispatch: Poll Reply from " + (veh !=null ? getVehicle4Imei(getImei()).name : getImei()); - icon = R.drawable.poll; - break; + + int iconValue = icon; + switch (icon) { + case AppParams.messageNotif: + contentText = "\"" + getMess() + "\""; + contentTitle = "New Message from " + getImei(); + icon = R.drawable.message; + break; + case AppParams.pollNotif: + contentText = "\"" + getMess() + "\""; + contentTitle = "Poll Reply from " + (veh != null ? getVehicle4Imei(getImei()).name : getImei()); + tickerText = "SafeMobile Dispatch: Poll Reply from " + (veh != null ? getVehicle4Imei(getImei()).name : getImei()); + icon = R.drawable.poll; + break; case AppParams.alertNotif: - String vehName = getString(R.string.from) + ": " + getImei(); - if(veh!=null) - vehName = getString(R.string.from) + ": " + (veh !=null ? getVehicle4Imei(getImei()).name : getImei()); - contentText ="\"" + getMess() + "\""; - contentTitle = getString(R.string.newAlarm) + vehName; - tickerText = "SafeMobile Dispatch: " + getString(R.string.newAlarm) + vehName; - icon = R.drawable.alert; - break; + String vehName = getString(R.string.from) + ": " + getImei(); + if (veh != null) + vehName = getString(R.string.from) + ": " + getVehicle4Imei(getImei()).name; + contentText = "\"" + getMess() + "\""; + contentTitle = getString(R.string.newAlarm) + vehName; + tickerText = "SafeMobile Dispatch: " + getString(R.string.newAlarm) + vehName; + icon = R.drawable.alert; + break; + default: + throw new IllegalStateException("Unexpected value: " + icon); } - + Notification notification = new Notification(icon, tickerText, System.currentTimeMillis()); - + // set intent to be opened on NotificationClick - notificationIntent = new Intent(this, NotificationActivity.class); - notificationIntent.putExtra("key", icon_value); - + /* Notification */ + Intent notificationIntent = new Intent(this, NotificationActivity.class); + notificationIntent.putExtra("key", iconValue); + // cancel old notification mNotificationManager.cancel(icon); - + PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ACTIVITY_RESULT, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); - //notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); - - //notification.defaults |= Notification.DEFAULT_SOUND; + // flag that the notification will be closed when clicked - notification.flags |= Notification.FLAG_AUTO_CANCEL; - //notification.number = notificationNr++; // used for multiple notification (different numbers) - notification.number = 1; // the same notification will be shown; - notification.tickerText = tickerText; // notification text when arrives - notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.new_sms ); - // add notification to the manager - mNotificationManager.notify(icon, notification); - } - - - // return vehicle according to imei - private Vehicle getVehicle4Imei(String imei) - { + notification.flags |= Notification.FLAG_AUTO_CANCEL; + notification.number = 1; // the same notification will be shown; + notification.tickerText = tickerText; // notification text when arrives + notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.new_sms); + // add notification to the manager + mNotificationManager.notify(icon, notification); + } + + // return vehicle according to imei + private Vehicle getVehicle4Imei(String imei) { Vehicle veh = null; - for(Vehicle vehicle: getAllVehicle()) - //SM.Debug("Vehicle name:"+vehicle.name+" IMEI:"+vehicle.imei); - if(vehicle.imei.equals(imei)) + for (Vehicle vehicle : getAllVehicle()) + if (vehicle.imei.equals(imei)) veh = vehicle; return veh; } - - @Override - public void enableMenuButtons(boolean enable) - { - if(enable) - { - buttonAlarms.setEnabled(true); - buttonHistory.setEnabled(true); - buttonLive.setEnabled(true); - buttonRecordings.setEnabled(true); - buttonText.setEnabled(true); - buttonRadio.setEnabled(true); - buttonSetup.setEnabled(true); - } - else - { - // disable all buttons - buttonAlarms.setEnabled(false); - buttonHistory.setEnabled(false); - buttonLive.setEnabled(false); - buttonRecordings.setEnabled(false); - buttonText.setEnabled(false); - buttonRadio.setEnabled(false); - buttonSetup.setEnabled(false); - } - } - - // load settings - public void loadSettings() - { - try - { - // get Preferences for SafeDispatch - AppParams.prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE); - // get default IP - AppParams.IP = AppParams.prefs.getString("ip", "n/a"); - // get default communication port - AppParams.PORT = AppParams.prefs.getString("port", "n/a"); - // get default language - AppParams.LANGUAGE = AppParams.prefs.getString("language", "en"); - - SM.Debug("PORT: " + AppParams.PORT + " | IP: " + AppParams.IP); - } - catch(Exception ex) - { - Log.e("Exception", "loadSettings exception"); - } + @Override + public void enableMenuButtons(boolean enable) { + if (enable) { + buttonAlarms.setEnabled(true); + buttonHistory.setEnabled(true); + buttonLive.setEnabled(true); + buttonRecordings.setEnabled(true); + buttonText.setEnabled(true); + buttonRadio.setEnabled(true); + buttonSetup.setEnabled(true); + } else { + // disable all buttons + buttonAlarms.setEnabled(false); + buttonHistory.setEnabled(false); + buttonLive.setEnabled(false); + buttonRecordings.setEnabled(false); + buttonText.setEnabled(false); + buttonRadio.setEnabled(false); + buttonSetup.setEnabled(false); + } } - - @Override - public double best_zoom(double latMax, double latMin, double lngMax, double lngMin) - { - double height =400; - double width =400; - double dlat = Math.abs(latMax - latMin); - double dlon = Math.abs(lngMax - lngMin); - if(dlat == 0 && dlon == 0) - { - if ((latMax == latMin)&&(latMax ==0)&&(lngMax == lngMin)&&(lngMax ==0)) return 2; - //return 17; - } - // Center latitude in radians - double clat = Math.PI*(latMin + latMax)/360.; + // load settings + public void loadSettings() { + try { + // get Preferences for SafeDispatch + AppParams.prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE); + // get default IP + AppParams.IP = AppParams.prefs.getString("ip", "n/a"); + // get default communication port + AppParams.PORT = AppParams.prefs.getString("port", "n/a"); + // get default language + AppParams.LANGUAGE = AppParams.prefs.getString("language", "en"); - double C = 0.0000107288; - double z0 = Math.ceil(Math.log(dlat/(C*height))/0.693); - double z1 = Math.ceil(Math.log(dlon/(C*width*Math.cos(clat)))/0.693); + SM.Debug("PORT: " + AppParams.PORT + " | IP: " + AppParams.IP); + } catch (Exception ex) { + Log.e("Exception", "loadSettings exception"); + } + } - return (z1 > z0) ? (17-z1) : (17-z0); - } - - /* - public void getVehs() - { - boolean res = tcp.Write("0.0", "#21#"+AppParams.USERID+"#"); - if(res){ - SM.Debug("Message (getVehs) sent to app server"); - }else{ - SM.Debug("Could not send message(getVehs)!!"); + @Override + public double best_zoom(double latMax, double latMin, double lngMax, double lngMin) { + double height = 400; + double width = 400; + double dlat = Math.abs(latMax - latMin); + double dlon = Math.abs(lngMax - lngMin); + if (dlat == 0 && dlon == 0 && (latMax == latMin) && (latMax == 0) && (lngMax == lngMin) && (lngMax == 0)) { + return 2; } - } - - public void getLastPos() - { - boolean res = tcp.Write("0.0", "#25#"); - if(res){ - SM.Debug("Message (getLastPOS) sent to app server"); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - public void optionForUnit(int radioCode, int opCode, int scId, int value) - { - boolean res = tcp.Write("0.0", "#"+radioCode+"#"+opCode+"#" + scId+"#" +value + "#"); - if(res){ - SM.Debug("Message (optionForUnit) sent to app server radioCode:"+radioCode+ " opCode:"+opCode+ " scId:"+scId+ " value:"+value); - }else{ - SM.Debug("Could not send message(optionForUnit)!!"); - } - } - - public void getSMS4unit(int scId, long timeGMT) - { - boolean res = tcp.Write("0.0", "#22#"+scId+"#" +timeGMT+"#"); - if(res){ - SM.Debug("Message (getLastSMS) sent to app server"); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - public void getLastSMS() - { - boolean res = tcp.Write("0.0", "#23#"); - if(res){ - SM.Debug("Message (getLastSMS) sent to app server"); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - public void SendSMS(String seqID,int scId, String txt) - { - boolean res = tcp.Write(seqID, "#24#" + AppParams.USERID + "#" + scId + "#" + txt + "#"); - if(res){ - SM.Debug("Message (SendSMS) sent to app server scId:"+scId+ " txt:"+txt); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - public void SendAlarmACK(int alarm_id, int type) - { - boolean res = tcp.Write("0.0", "#28#" + alarm_id + "#" + type + "#"); - if(res){ - SM.Debug("Message (SendAlarmACK) sent to app server alarm_id:"+alarm_id+ " type:"+type); - }else{ - SM.Debug("Could not send message(SendAlarmACK)!!"); - } - } - - public void SendPlayRequest(long record_id) - { - boolean res = tcp.Write("0.0", "#18#" + record_id + "#"); - if(res){ - SM.Debug("Message (SendPlayRequest) sent to app server record_id:"+record_id); - }else{ - SM.Debug("Could not send message(SendPlayRequest)!!"); - } - } - - public void SendDekey() - { - boolean res = tcp.Write("0.0", "#30#160#" +crtRadio.GW_ID+"."+crtRadio.ID+ "#"); - if(res){ - SM.Debug("Message (SendDekey) sent to app server record_id"); - }else{ - SM.Debug("Could not send message(SendPlayRequest)!!"); - } - } - - public void getHistoryPos(int scId, long timeGMTStart, long timeGMTStop) - { - HistSeqID = "1."+Integer.toString((int) (System.currentTimeMillis() / 1000L)); - boolean res = tcp.Write(HistSeqID,"#26#"+scId+"#"+timeGMTStart+"#"+timeGMTStop+"#"); - if(res){ - SM.Debug("Message (getHistoryPos) sent to app server"); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - - public void RadioGetRadioList() - { - boolean res = tcp.Write("0.0", "#30#100#"); - if(res){ - SM.Debug("Message (RadioGetRadioList) sent to app server"); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - // if zoneNr=0 and channelNR =0 then function acts as GET - public void getSetZoneAndChannel(int gwID, int rgwID, int zoneNR, int channelNR) - { - 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)!!"); - } - } - - // send radioCode=30 - //Enable/Disable opcode=150 value(1/0) - //Remote monitor = 161 - //Poll = 154 - - - public void getRadioStatus(int gwID, int rgwID) - { - 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)!!"); - } - } - - public void getAlarms() - { - boolean res = tcp.Write("0.0", "#27#"); // = 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)!!"); - } - } - - - public void getRecordings() - { - boolean res = tcp.Write("0.0", "#29#"+AppParams.USERID+"#"+crtRadio.GW_ID+"#"+crtRadio.ID+"#"); - if(res){ - SM.Debug("Message (GetRecordings) sent to app server"); - }else{ - SM.Debug("Could not send message(GetRecordings)!!"); - } - } - */ - - - - - + // Center latitude in radians + double centerLat = Math.PI * (latMin + latMax) / 360.; + + double c = 0.0000107288; + double z0 = Math.ceil(Math.log(dlat / (c * height)) / 0.693); + double z1 = Math.ceil(Math.log(dlon / (c * width * Math.cos(centerLat))) / 0.693); + + return (z1 > z0) ? (17 - z1) : (17 - z0); + } + + //callType: //101 -allcall init //111 -allcall stop @@ -2468,135 +1994,127 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ //112 -prvcall stop //103 -grpcall init //113 -grpcall stop - public void SendPTT(int callType, int id, int gwID, int rgwid, long userID) - { - if(tcp!= null) - { + public void sendPTT(int callType, int id, int gwID, int rgwid, long userID) { + if (tcp != null) { try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); + Thread.currentThread().interrupt(); } - boolean res = tcp.Write("0.0", "#30#"+callType+"#"+gwID+"."+rgwid+"." + id+"#"+userID+"#"); - if(res){ - SM.Debug("Message (SendPTT) sent to app server"); - } - else{ - SM.Debug("Could not send message(SendPTT)!!"); + boolean response = tcp.Write("0.0", "#30#" + callType + "#" + gwID + "." + rgwid + "." + id + "#" + userID + "#"); + if (response) { + SM.Debug("Message (sendPTT) sent to app server"); + } else { + SM.Debug("Could not send message(sendPTT)!!"); } } - } - - - protected class ConnectTask extends AsyncTask - { + } + + protected class ConnectTask extends AsyncTask { @Override protected TCPhandler doInBackground(String... params) { - - switch(Integer.parseInt(params[0])) - { - case OperationCodes.TCP_CONNECTION_REQ: - - SM.Exception("TCP CONNECTION REQ!!!"); - if(myService!= null) { - tcp = myService.getTCPConnection(); - SM.Exception("TCP is not null!!!"); - } - break; - - case OperationCodes.GetVehicles: - getVehicles(Integer.parseInt(params[1])); - break; - - case OperationCodes.GetRadiosList: - getRadiosList(); - break; - - case OperationCodes.GetLastPositions: - getLastPositions(Integer.parseInt(params[1])); - break; - - case OperationCodes.GetLastSMS: - getLastSMSs(Integer.parseInt(params[1])); - break; - - case OperationCodes.GetRecentSMSs: - try - { - Long.parseLong(params[2]); - } - catch (Exception ignored) { - - } - getRecentSMSs(Integer.parseInt(params[1]), Long.parseLong(params[2])); - break; - - case OperationCodes.SEND_TM: - sendSMS(params[1], Integer.parseInt(params[2]), params[3]); - - case OperationCodes.Option4Unit: - try { - SM.Debug(params[1] + " | " + params[2] + " | " + params[3] + " | " + params[4]); - - setVehicleStatus(Integer.parseInt(params[1]), Integer.parseInt(params[2]), Integer.parseInt(params[3]), Integer.parseInt(params[4])); - } - catch(Exception ex) { SM.Exception("Paramas -> setVehicleStatus","EXCeption ex " + ex.toString()); } - break; - - case OperationCodes.GetAlarms: - getAlarms(Integer.parseInt(params[1])); - break; - - case OperationCodes.SendAlarmAcknoledge: - sendAlarmAcknowledge(Integer.parseInt(params[1]), Integer.parseInt(params[2]), params[3]); - break; - - case OperationCodes.GetHistoryPositions: - getHistoryPositions(Integer.parseInt(params[1]), Long.parseLong(params[2]), Long.parseLong(params[3])); - break; - + + switch (Integer.parseInt(params[0])) { + case OperationCodes.TCP_CONNECTION_REQ: + + SM.Exception("TCP CONNECTION REQ!!!"); + if (myService != null) { + tcp = myService.getTCPConnection(); + SM.Exception("TCP is not null!!!"); + } + break; + + case OperationCodes.GetVehicles: + getVehicles(Integer.parseInt(params[1])); + break; + + case OperationCodes.GetRadiosList: + getRadiosList(); + break; + + case OperationCodes.GetLastPositions: + getLastPositions(Integer.parseInt(params[1])); + break; + + case OperationCodes.GetLastSMS: + getLastSMSs(Integer.parseInt(params[1])); + break; + + case OperationCodes.GetRecentSMSs: + try { + Long.parseLong(params[2]); + } catch (Exception ignored) { + //ignored + } + getRecentSMSs(Integer.parseInt(params[1]), Long.parseLong(params[2])); + break; + + case OperationCodes.SEND_TM: + sendSMS(params[1], Integer.parseInt(params[2]), params[3]); + break; + + case OperationCodes.Option4Unit: + try { + SM.Debug(params[1] + " | " + params[2] + " | " + params[3] + " | " + params[4]); + + setVehicleStatus(Integer.parseInt(params[1]), Integer.parseInt(params[2]), Integer.parseInt(params[3]), Integer.parseInt(params[4])); + } catch (Exception ex) { + SM.Exception("Paramas -> setVehicleStatus", "EXCeption ex " + ex.toString()); + } + break; + + case OperationCodes.GetAlarms: + getAlarms(Integer.parseInt(params[1])); + break; + + case OperationCodes.SendAlarmAcknoledge: + sendAlarmAcknowledge(Integer.parseInt(params[1]), Integer.parseInt(params[2]), params[3]); + break; + + case OperationCodes.GetHistoryPositions: + getHistoryPositions(Integer.parseInt(params[1]), Long.parseLong(params[2]), Long.parseLong(params[3])); + break; + + default: + throw new IllegalStateException("Unexpected value: " + Integer.parseInt(params[0])); } return null; } - + } - - + + @Override - public void executeNetworkStuff(String [] params) { - new ConnectTask().execute(params); + public void executeNetworkStuff(String[] params) { + new ConnectTask().execute(params); } - - public class connectParserTask extends AsyncTask - { + + public class ConnectParserTask extends AsyncTask { @Override protected TCPhandler doInBackground(String... params) { - if(myService!= null) + if (myService != null) tcpParser = myService.getTCPmsgParser(); - - SM.Debug("connectParserTask","tcpParser is : " + tcpParser == null ? "null" : "not null"); + // add TCPParserListener - if(tcpParser!=null) - { - SM.Debug("## tcpParser != null ", "#### call tcpParserListener(") ; + if (tcpParser != null) { + SM.Debug("## tcpParser != null ", "#### call tcpParserListener("); tcpParserListener(); } return null; } } - - /* Display Toast messages*/ - @Override - public void displayToast(final String msg) - { - myHandler.post(() -> Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()); - } + + /* Display Toast messages*/ + @Override + public void displayToast(final String msg) { + myHandler.post(() -> Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()); + } @Override public void setRadioActivity(AbstractRadioActivity radioActivity) { - //this.radioActivity = radioActivity; } @@ -2608,104 +2126,87 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ @Override public void setMessagesActivity(AbstractMessagesActivity messageActivity) { - //this.messageActivity = messageActivity; } @Override public void unregisterReceivers(BroadcastReceiver receiver) { - if(mReceiver!=null) - this.unregisterReceiver(receiver); + this.unregisterReceiver(receiver); } @Override public void cancelNotification(int drawable) { - if(mNotificationManager!=null) + if (mNotificationManager != null) mNotificationManager.cancel(drawable); } @Override public void stopTCP() { - if(tcp != null) + if (tcp != null) tcp.Stop(); } @Override public void stopTCPParser() { - if(tcpParser != null) + if (tcpParser != null) tcpParser.Stop(); } @Override - public void recreateTCPConnection() - { - if(!AppParams.DEMO) - { - if(tcpParser!=null) + public void recreateTCPConnection() { + if (!AppParams.DEMO) { + if (tcpParser != null) tcpParser.clearMsgList(); - //showLoadingDialog("Getting users from database..."); - myHandler.post(new Runnable() { - @Override - public void run() { - if(myService != null) - { - myService.stopTCPConnection(); - myService.recreateTCPConnection(); - new ConnectTask().execute(new String[] {OperationCodes.TCP_CONNECTION_REQ + ""}); - - // add a new ITCPListener - tcpParser(); + myHandler.post(() -> { + if (myService != null) { + myService.stopTCPConnection(); + myService.recreateTCPConnection(); + new ConnectTask().execute(OperationCodes.TCP_CONNECTION_REQ + ""); - //tcp.updateTCPparameters(AppParams.IP, AppParams.PORT); - } - // recreate tcp - //myService.updateTCPparameters(AppParams.IP, AppParams.PORT); - //myService.recreateTCPConnection(); - //tcpInit(); + // add a new ITCPListener + tcpParser(); - SM.Debug("RECREATE TCP","IP: " + AppParams.IP + " | Port: " + AppParams.PORT); } + SM.Debug("RECREATE TCP", "IP: " + AppParams.IP + " | Port: " + AppParams.PORT); }); } } - + @Override public void removeITCPListener() { - if(tcpParser != null) + if (tcpParser != null) tcpParser.clearITCPListeners(); - //tcpParser.removeTCPListener(itcpListener); } - - - /** send a message to be broadcasted when a specific event happens - * every listener that is registered to the broadcast will be notified of these event - * @param action The type of action which will be notified - * @param object The object which will be passed through the intent + + + /** + * send a message to be broadcasted when a specific event happens + * every listener that is registered to the broadcast will be notified of these event + * + * @param action The type of action which will be notified */ - private void notifyBroadcast(String action) { - Intent intent = new Intent(); - intent.setAction(action); - //intent.putExtra("extra", extra); - getBaseContext().sendBroadcast(intent); - } - - // send a message to be broadcasted when a specific event happens + private void notifyBroadcast(String action) { + Intent intent = new Intent(); + intent.setAction(action); + getBaseContext().sendBroadcast(intent); + } + + // send a message to be broadcast when a specific event happens // every listener that is registered to the broadcast will be notified of these event private void notifyBroadcast(String action, Object object) { Intent intent = new Intent(); intent.setAction(action); - if(action == OperationCodes.UNIT_STATUS_UPDATE+"") - intent.putExtra("unitStatus", (String)object); - else if(action == OperationCodes.BLUETOOTH_TETHER+"") - intent.putExtra("tether", Boolean.parseBoolean((String)object)); + if (Objects.equals(action, OperationCodes.UNIT_STATUS_UPDATE + "")) + intent.putExtra("unitStatus", (String) object); + else if (Objects.equals(action, OperationCodes.BLUETOOTH_TETHER + "")) + intent.putExtra("tether", Boolean.parseBoolean((String) object)); else intent.putExtra("extra", new SerializedObject(object, action)); getBaseContext().sendBroadcast(intent); } - }