diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java index 331c3db..afb3de2 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java @@ -21,6 +21,7 @@ import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.safemobile.lib.AppParams; import com.safemobile.lib.HistPos; +import com.safemobile.lib.OperationCodes; import com.safemobile.lib.SM; import com.safemobile.lib.Vehicle; @@ -38,6 +39,7 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall private Spinner spinnerVehicle; private ImageView changeMapType, checkTraffic, slideLayoutImage; private LinearLayout layoutTraffic, slidelayout, layoutVehicles; + private Date startDate, endDate; private ArrayList allVehicle = new ArrayList<>(); private ArrayList allVehicleNames = new ArrayList<>(); @@ -88,6 +90,9 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall // }); setDate(); + + parentTab.executeNetworkStuff(new String[] {OperationCodes.GetHistoryPositions + "", allVehicle.get(spinnerVehicle.getSelectedItemPosition()).sc_id + "", + (startDate.getTime()/ 1000L) + "", (endDate.getTime()/ 1000L) + ""}); } private void displayHistory(ArrayList demoPositions) { @@ -110,9 +115,9 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall private void setDate() { Calendar calendar = Calendar.getInstance(); - Date endDate = calendar.getTime(); + endDate = calendar.getTime(); calendar.add(Calendar.DATE, -1); - Date startDate = calendar.getTime(); + startDate = calendar.getTime(); LinearLayout layoutStartPicker = findViewById(R.id.layoutStartPicker); TextView textViewDate = findViewById(R.id.textViewStartDate); diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java index 2d6ef54..c5d37e1 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java @@ -1529,89 +1529,79 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ public void onHistoryPositionsReceived(TCPEvent event) { TCPmsg msg= event.msg(); SM.Debug("Got HistoryPos :" + msg.allData); - if (!dropAllData){ + if (!dropAllData) { HistPosmsg tmpHist= new HistPosmsg(msg); Boolean SendDataToMap =true; - try{ + 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) { + int all = Integer.parseInt(tmpHist.seqID.substring(tmpHist.seqID.indexOf('.') + 1)); + if (all != 0) { if (firstHistData) { try { for(int i=0;i) (o1, o2) -> { HistPos p1 = (HistPos) o1; HistPos p2 = (HistPos) o2; - if (p1.timeGMT 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); - } - - 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 (!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; } } - - if(crtRadio != null) - { - if(rmsg.incCall.callStatus == 3) - { - inCall = false; - } - 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; - } - } - } - - 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); - } - } - 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 ((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 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; - } - } - - 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); + AppParams.crtZoneAndChannel = rmsg.zac; + notifyBroadcast(OperationCodes.CHANNEL_BRDCST+""); + SM.Debug("Received from Apps -> UpdateZoneCH(" + rmsg.zac.rgwID + "," + rmsg.zac.gwID + "," + rmsg.zac.zoneNr + "," + rmsg.zac.channelNr + ")"); } - } - - - } - - // 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"); + + //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 : "zac = null")); + SM.Debug("## " + (rmsg.rStatus!=null? "rStatus" + rmsg.rStatus : "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; + } + + 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(crtRadio != null) { + if(rmsg.incCall.callStatus == 3) + inCall = false; + 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; + } + } + } + + 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); + } + } 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 ((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 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; + } + } + + 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"); } @Override @@ -1820,21 +1768,17 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ String[] tempArr =msg.data.split("#"); SM.Debug("Unit imei:" + tempArr[0]); String UnitIMEI =tempArr[0]; - //SM.Debug("Message:" + tempArr[1]); - + //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) - { + switch (msg.opCode) { case 135: setMess("speed "+tempArr[1]); break; case 136: setMess("landmark "+tempArr[1]); @@ -1850,40 +1794,31 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } myHandler.post(UpdateResultsAlarm); - if ((msg.opCode==138)&&(AppParams.crtTab == AppParams.Tabs.live)) - { - if(getSuperVehHash().get(Long.parseLong(UnitIMEI)) != null) - { + if ((msg.opCode==138)&&(AppParams.crtTab == AppParams.Tabs.live)) { + if(getSuperVehHash().get(Long.parseLong(UnitIMEI)) != 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) - { + if (!getSuperVehHash().get(Long.parseLong(UnitIMEI)).needUpdate) { getSuperVehHash().get(Long.parseLong(UnitIMEI)).needUpdate =true; forceChecked =true; } - try - { + try { int x = 0; - if (forceChecked) - { - for (Vehicle veh : getAllVehicle()) - { + if (forceChecked) { + for (Vehicle veh : getAllVehicle()) { if (veh.imei.compareTo(UnitIMEI)==0) break; x++; } - } - else x = -1; - if(liveActivity != null) - { + } 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 liveActivity.emergencyAlarmReceived(-1, getSuperVehHash().get(Long.parseLong(UnitIMEI)).lat, getSuperVehHash().get(Long.parseLong(UnitIMEI)).lng); } - } - catch (Exception ex) - { - SM.Debug("Error load hash:"+ex.toString()); + } catch (Exception ex) { + SM.Debug("Error load hash: "+ ex); } } } @@ -1897,19 +1832,16 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ 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: Records.recordList) { // set the name to be displayed - if (rec.typeID==1) + if (rec.typeID == 1) rec.NameForDisplay = AppParams.USERNAME; else { if (getSuperVehHash().get((long)rec.subID)!=null) rec.NameForDisplay = getSuperVehHash().get((long)rec.subID).name; } } - // save recodings to AppParams AppParams.recordings = Records.recordList; @@ -1920,19 +1852,17 @@ 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 @@ -1942,7 +1872,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // send a broadcast notifyBroadcast(OperationCodes.TCP_CONNECTION_DOWN + ""); - } @Override @@ -1959,31 +1888,17 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ 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"); - } - }; + final Runnable UpdateResultsAlarm = () -> updateResultsAlarmInUi("realpha"); public void updateResultsAlarmInUi(String animation) { // Back in the UI thread // set TextViews - if(tcp!=null && !AppParams.DEMO) - { - try - { + if(tcp!=null && !AppParams.DEMO) { + try { activePopupType= MsgType.ALARM; imageViewPopUp.setImageResource(R.drawable.siren_on); slideTabsText.setText(getString(R.string.newAlarm)); @@ -2003,35 +1918,25 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // create Notification createNotification(AppParams.alertNotif); + } catch (Exception ex) { + SM.Debug("Erorr on update alarm:"+ ex); } - 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"); - } - }; + final Runnable UpdateResultsPoll = () -> updateResultsPollInUi("realpha"); public void updateResultsPollInUi(String animation) { // Back in the UI thread // set TextViews String from = ""; - Vehicle fromVehicle = null; - if((fromVehicle = getVehicle4Imei(getImei())) != null) + Vehicle fromVehicle; + if ((fromVehicle = getVehicle4Imei(getImei())) != null) from = fromVehicle.name; - if(tcp!=null && !AppParams.DEMO) - { + if (tcp!=null && !AppParams.DEMO) { activePopupType =MsgType.POLL; imageViewPopUp.setImageResource(R.drawable.poll); slideTabsText.setText("Poll Reply"); @@ -2046,9 +1951,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ anim.reset(); layoutNewMessage.clearAnimation(); layoutNewMessage.startAnimation(anim); - } - else if (AppParams.DEMO) - { + } else if (AppParams.DEMO) { activePopupType =MsgType.POLL; imageViewPopUp.setImageResource(R.drawable.poll); slideTabsText.setText("Poll Reply"); @@ -2056,14 +1959,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ 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 @@ -2071,17 +1966,12 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } // Create runnable for posting - final Runnable UpdateResults = new Runnable() { - public void run() { - updateResultsInUi("realpha"); - } - }; + final Runnable UpdateResults = () -> updateResultsInUi("realpha"); public void updateResultsInUi(String animation) { // Back in the UI thread // set TextViews - if(tcp!=null && !AppParams.DEMO) - { + if(tcp!=null && !AppParams.DEMO) { activePopupType = MsgType.SMS; imageViewPopUp.setImageResource(R.drawable.message); slideTabsText.setText("New Message"); @@ -2096,9 +1986,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ anim.reset(); layoutNewMessage.clearAnimation(); layoutNewMessage.startAnimation(anim); - } - else if(AppParams.DEMO) - { + } else if(AppParams.DEMO) { setMess("i got your sms"); activePopupType = MsgType.SMS; imageViewPopUp.setImageResource(R.drawable.message); @@ -2110,11 +1998,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // create Notification createNotification(AppParams.messageNotif); - /* - Animation anim = AnimationUtils.loadAnimation(this, R.anim.realpha); - layoutNewMessage.clearAnimation(); - layoutNewMessage.startAnimation(anim); - */ } // create Notification @@ -2130,8 +2013,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ Vehicle veh = getVehicle4Imei(getImei()); int icon_value = icon; - switch(icon) - { + switch(icon) { case AppParams.messageNotif: contentText = "\"" + getMess() + "\""; contentTitle = "New Message from " + getImei(); @@ -2179,11 +2061,9 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // return vehicle according to imei - private Vehicle getVehicle4Imei(String 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)) veh = vehicle; return veh; @@ -2191,10 +2071,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ @Override - public void enableMenuButtons(boolean enable) - { - if(enable) - { + public void enableMenuButtons(boolean enable) { + if (enable) { buttonAlarms.setEnabled(true); buttonHistory.setEnabled(true); buttonLive.setEnabled(true); @@ -2202,9 +2080,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ buttonText.setEnabled(true); buttonRadio.setEnabled(true); buttonSetup.setEnabled(true); - } - else - { + } else { // disable all buttons buttonAlarms.setEnabled(false); buttonHistory.setEnabled(false); @@ -2217,10 +2093,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } // load settings - public void loadSettings() - { - try - { + public void loadSettings() { + try { // get Preferences for SafeDispatch AppParams.prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE); // get default IP @@ -2231,24 +2105,19 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ AppParams.LANGUAGE = AppParams.prefs.getString("language", "en"); SM.Debug("PORT: " + AppParams.PORT + " | IP: " + AppParams.IP); - } - catch(Exception ex) - { + } catch(Exception ex) { Log.e("Exception", "loadSettings exception"); } } @Override - public double best_zoom(double latMax, double latMin, double lngMax, double lngMin) - { + 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(dlat == 0 && dlon == 0) { if ((latMax == latMin)&&(latMax ==0)&&(lngMax == lngMin)&&(lngMax ==0)) return 2; - //return 17; } // Center latitude in radians @@ -2260,173 +2129,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ 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)!!"); - } - } - - 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 sc_id, int value) - { - boolean res = tcp.Write("0.0", "#"+radioCode+"#"+opCode+"#" + sc_id+"#" +value + "#"); - if(res){ - SM.Debug("Message (optionForUnit) sent to app server radioCode:"+radioCode+ " opCode:"+opCode+ " sc_id:"+sc_id+ " value:"+value); - }else{ - SM.Debug("Could not send message(optionForUnit)!!"); - } - } - - public void getSMS4unit(int sc_id, long timeGMT) - { - boolean res = tcp.Write("0.0", "#22#"+sc_id+"#" +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 sc_id, String txt) - { - boolean res = tcp.Write(seqID, "#24#" + AppParams.USERID + "#" + sc_id + "#" + txt + "#"); - if(res){ - SM.Debug("Message (SendSMS) sent to app server sc_id:"+sc_id+ " 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 sc_id, long timeGMTStart, long timeGMTStop) - { - HistSeqID = "1."+Integer.toString((int) (System.currentTimeMillis() / 1000L)); - boolean res = tcp.Write(HistSeqID,"#26#"+sc_id+"#"+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)!!"); - } - } - */ - - - - - //callType: //101 -allcall init @@ -2435,10 +2137,8 @@ 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) { @@ -2447,86 +2147,80 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ boolean res = tcp.Write("0.0", "#30#"+callType+"#"+gwID+"."+rgwid+"." + id+"#"+userID+"#"); if(res){ SM.Debug("Message (SendPTT) sent to app server"); - } - else{ + } 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])); - 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) { + + } + 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])); + break; + + case OperationCodes.GetHistoryPositions: + getHistoryPositions(Integer.parseInt(params[1]), Long.parseLong(params[2]), Long.parseLong(params[3])); + break; + } return null; } - } @@ -2555,8 +2249,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ /* Display Toast messages*/ @Override - public void displayToast(final String msg) - { + public void displayToast(final String msg) { myHandler.post(() -> Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()); } @@ -2607,37 +2300,22 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } @Override - public void recreateTCPConnection() - { - if(!AppParams.DEMO) - { + 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(new String[] {OperationCodes.TCP_CONNECTION_REQ + ""}); - //tcp.updateTCPparameters(AppParams.IP, AppParams.PORT); - } - // recreate tcp - //myService.updateTCPparameters(AppParams.IP, AppParams.PORT); - //myService.recreateTCPConnection(); - //tcpInit(); - - SM.Debug("RECREATE TCP","IP: " + AppParams.IP + " | Port: " + AppParams.PORT); + // add a new ITCPListener + tcpParser(); } + SM.Debug("RECREATE TCP","IP: " + AppParams.IP + " | Port: " + AppParams.PORT); }); - } } @@ -2645,7 +2323,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ public void removeITCPListener() { if(tcpParser != null) tcpParser.clearITCPListeners(); - //tcpParser.removeTCPListener(itcpListener); } @@ -2654,25 +2331,23 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ * @param action The type of action which will be notified * @param object The object which will be passed through the intent */ - private void notifyBroadcast(String action) { - Intent intent = new Intent(); - intent.setAction(action); - //intent.putExtra("extra", extra); - getBaseContext().sendBroadcast(intent); - } + private void notifyBroadcast(String action) { + Intent intent = new Intent(); + intent.setAction(action); + getBaseContext().sendBroadcast(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 private void notifyBroadcast(String action, Object object) { Intent intent = new Intent(); intent.setAction(action); - if(action == OperationCodes.UNIT_STATUS_UPDATE+"") + if(action.equals(OperationCodes.UNIT_STATUS_UPDATE + "")) intent.putExtra("unitStatus", (String)object); - else if(action == OperationCodes.BLUETOOTH_TETHER+"") + else if(action.equals(OperationCodes.BLUETOOTH_TETHER + "")) intent.putExtra("tether", Boolean.parseBoolean((String)object)); else intent.putExtra("extra", new SerializedObject(object, action)); getBaseContext().sendBroadcast(intent); } - -} +} \ No newline at end of file