diff --git a/libSafeMobile/src/main/java/com/safemobile/lib/RadioMSG.java b/libSafeMobile/src/main/java/com/safemobile/lib/RadioMSG.java index 9e2f70c..a5f6e5c 100644 --- a/libSafeMobile/src/main/java/com/safemobile/lib/RadioMSG.java +++ b/libSafeMobile/src/main/java/com/safemobile/lib/RadioMSG.java @@ -15,7 +15,7 @@ public class RadioMSG extends TCPmsg { public int rOpcode; public String payload=""; - public ArrayList RadioGWList=null; + public ArrayList RadioGWList = null; //zone and channel; public Zone_and_channel zac= null; @@ -35,7 +35,9 @@ public class RadioMSG extends TCPmsg { // Contacts list public ArrayList contacts; - + + + public RadioMSG(TCPmsg tcp) { super(tcp); String date4parsing = super.data; @@ -47,148 +49,34 @@ public class RadioMSG extends TCPmsg { switch(rOpcode) { - case 200: - { - RadioGWList = new ArrayList(); - String[] tempArr = payload.split(";"); - - int count = 0; - for(int i =0; i 3 ) { + + rgw.ID = Integer.parseInt(radioFields[0].trim()); + rgw.GW_ID = Integer.parseInt(radioFields[1].trim()); + rgw.IMEI = radioFields[2]; + rgw.IP = radioFields[3]; + } + + return rgw; + } + + private Zone parseZone(String buffer) + { + Zone zone = new Zone(); + String[] zoneFields = buffer.split(":"); + + if( zoneFields.length > 2 ) { + + zone.dbID = Integer.parseInt(zoneFields[0].trim()); + zone.id = Integer.parseInt(zoneFields[1].trim()); + zone.ZoneName = zoneFields[2]; + } + + return zone; + } + + private Channel parseChannel(String buffer) + { + Channel channel = new Channel(); + String[] channelFields = buffer.split("/"); + + if( channelFields.length > 2 ) { + + channel.dbID = Integer.parseInt(channelFields[0].trim()); + channel.id = Integer.parseInt(channelFields[1].trim()); + channel.chName = channelFields[2].trim(); + } + + return channel; + } + + private String[] getChannelList(String zone) + { + String[] zoneArr = zone.split(":"); + if ( zoneArr.length > 3) + return zoneArr[3].split(","); + + return null; + } + + + private String[] getZoneList(String gw) + { + String[] zoneArr = gw.split("&"); + if ( zoneArr.length > 4) + return zoneArr[4].split("@"); + + return null; + } + + private ArrayList getRadioGWList() + { + ArrayList radioGWList = new ArrayList(); + String[] radioGWArr = payload.split(";"); + + for(int i=0; i < radioGWArr.length; i++) + { + RadioGW rgw = parseRadioGW(radioGWArr[i]); + String[] zoneArr = getZoneList(radioGWArr[i]); + if( zoneArr == null) + continue; + + for(int j=0; j < zoneArr.length; j++) + { + + Zone zone = parseZone(zoneArr[j]); + String[] channelArr = getChannelList(zoneArr[j]); + if( channelArr == null) + continue; + + for(int k =0; k < channelArr.length; k++) + { + Channel channel = parseChannel(channelArr[k]); + + //add channel to zone + zone.channelList.add(channel); + } + + //add zone to radio GW + rgw.zoneList.add(zone); + } + + radioGWList.add(rgw); + + } + + return radioGWList; + } + + private Zone_and_channel parse_CHANNEL_BRDCST(String payload) { + Zone_and_channel zacObj = new Zone_and_channel(); + + try { + + String[] tempArr = payload.split("&"); + + String[] gwID_and_rgwID = tempArr[0].split("/"); + zacObj.gwID = Integer.parseInt(gwID_and_rgwID[0].trim()); + zacObj.rgwID = Integer.parseInt(gwID_and_rgwID[1].trim()); + + String[] zoneNr_and_channelNr = tempArr[1].split("/"); + zacObj.zoneNr = Integer.parseInt(zoneNr_and_channelNr[0].trim()); + zacObj.channelNr = Integer.parseInt(zoneNr_and_channelNr[1].trim()); + + } catch (Exception e) { + SM.Debug("Cmd 204 error:"+e.toString()); + + } + + return zacObj; + + } + + private IncCall parse_CALL_STATUS_BRDCST(String payload) + { + IncCall incCallObj = new IncCall(); + + try { + + incCallObj.opCode = rOpcode; + String[] tempArr = payload.split("&"); + + String[] gwID_and_rgwID_imei = tempArr[0].split("/"); + incCallObj.gwID = Integer.parseInt(gwID_and_rgwID_imei[0]); + incCallObj.rgwID = Integer.parseInt(gwID_and_rgwID_imei[1]); + incCallObj.Imei = Long.parseLong(gwID_and_rgwID_imei[2]); + + incCallObj.callStatus = Integer.parseInt(tempArr[1]); + incCallObj.callType = Integer.parseInt(tempArr[2]); + incCallObj.groupId = Integer.parseInt(tempArr[3]); + if (tempArr.length > 4 ) + incCallObj.userID = Integer.parseInt(tempArr[4]); + + + } catch (Exception e) { + SM.Debug("Cmd 125, 126 error:"+e.toString()); + } + + return incCallObj; + } + + private RadioStatus parse_RADIO_STATUS_REP(String payload) + { + RadioStatus radioStatus = new RadioStatus(); + + try + { + String[] tempArr = payload.split("&"); + + if(tempArr.length == 4 || tempArr.length == 5) { + + radioStatus.status = 1; + radioStatus.incCall.callStatus = Integer.parseInt(tempArr[0]); + radioStatus.incCall.callType = Integer.parseInt(tempArr[1]); + radioStatus.incCall.Imei = Integer.parseInt(tempArr[2]); + radioStatus.incCall.callerID = Integer.parseInt(tempArr[2]); + radioStatus.incCall.groupId = Integer.parseInt(tempArr[3]); + radioStatus.incCall.callDestID = Integer.parseInt(tempArr[3]); + + if(tempArr.length == 5) + radioStatus.incCall.userID = Integer.parseInt(tempArr[4]); + } + else { + String[] gwID_and_rgwID = tempArr[0].split("/"); + radioStatus.gwID = Integer.parseInt(gwID_and_rgwID[0]); + radioStatus.rgwID = Integer.parseInt(gwID_and_rgwID[1]); + radioStatus.status = Integer.parseInt(tempArr[1]); + } + } + catch (Exception e) { + SM.Debug("Cmd 199 error:"+e.toString()); + } + + return radioStatus; + + } + + private Emerg parse_EMERGENCY_REP(String payload) + { + Emerg emergObj = new Emerg(); + + try { + + String[] tempArr = payload.split("/"); + + emergObj.function = Integer.parseInt(tempArr[0]); + emergObj.status = Integer.parseInt(tempArr[1]); + + // emerg.userID = Integer.parseInt(tempArr[2]); + + } catch (Exception e) { + SM.Debug("Cmd 230 error:"+e.toString()); + } + + return emergObj; + } + + private SUstatus parse_UNIT_STATUS_UPDATE(String payload) + { + SUstatus suStatusObj = new SUstatus(); + + try { + + String[] tempArr = payload.split("&"); + + suStatusObj.imei = Integer.parseInt(tempArr[0]); + suStatusObj.status = Integer.parseInt(tempArr[1]); + + } catch (Exception e) { + SM.Debug("Cmd 250 error:"+e.toString()); + } + + return suStatusObj; + + } + + private IncCall parse_CALL_TYPE_REP(String payload) + { + IncCall incCallObj = new IncCall(); + + try { + + incCallObj.opCode = rOpcode; + String[] tempArr = payload.split("/"); + incCallObj.callType = Integer.parseInt(tempArr[0]); + incCallObj.callStatus = Integer.parseInt(tempArr[1]); + + SM.Debug("GOT CHANGE CALL TYPE MSG", incCallObj.opCode + " # " + incCallObj.callType + " # " + incCallObj.callStatus); + } catch (Exception e) { + SM.Debug("Cmd 115,116,117 error:"+e.toString()); + } + + return incCallObj; + } + } diff --git a/libSafeMobile/src/main/java/com/safemobile/services/TCPmsgParser.java b/libSafeMobile/src/main/java/com/safemobile/services/TCPmsgParser.java index c1e15e4..b15c032 100644 --- a/libSafeMobile/src/main/java/com/safemobile/services/TCPmsgParser.java +++ b/libSafeMobile/src/main/java/com/safemobile/services/TCPmsgParser.java @@ -227,7 +227,8 @@ public class TCPmsgParser implements Runnable { if (TCPhandler.msgList == null) continue; if(!TCPhandler.msgList.isEmpty()) { - try { + + try { _msg = TCPhandler.msgList.poll(); if(_msg == null) continue; @@ -235,27 +236,32 @@ public class TCPmsgParser implements Runnable { continue; //parse the rest of the message; - switch(_msg.opCode) { - case 40:{ + + switch(_msg.opCode) + { + case 40: /* login */{ _fireLoginEvent(); break; - } + } - case 41:{ + case 41: /* vehicle */ { _fireVehEvent(); break; } - case 42:{ + + case 42: /* Text Message */{ _fireSMSEvent(); break; } - case 43:{ + + case 43: /* Last text message */ { _fireLastSMSEvent(); break; } + case OperationCodes.TM_ACK: case OperationCodes.TM_ACK_SD: { _fireSMSconfirm(); @@ -265,24 +271,25 @@ public class TCPmsgParser implements Runnable { case OperationCodes.RECEIVED_TM:{ _fireNewSMS(); break; - } + } - case 45:{ + case 45: /* last position */ { _fireLastPos(); break; } - case 131:{ + case 131: /* gps */ { _fireGPSEvent(); break; } - case 231:{ + case 231: /* pool */ { _firePOLLEvent(); break; } - case 50:{ + + case 50: /* radio */ { _fireRadioEvent(); break; } @@ -297,12 +304,14 @@ public class TCPmsgParser implements Runnable { break; } - case 47:{ + + case 47: /* alert list */ { _fireAlarmList(); break; } - case 48:{ + + case 48: /* alert ack */ { _fireAlarmACK(); break; } @@ -359,8 +368,10 @@ public class TCPmsgParser implements Runnable { default: break; + } - } catch(Exception ex) { + } + catch(Exception ex) { try { if(TCPhandler.msgList.size() > 0) _msg = TCPhandler.msgList.remove(0); @@ -370,6 +381,7 @@ public class TCPmsgParser implements Runnable { } } } + SM.Debug("TCPmsgParser listen thread stoped."); } diff --git a/safeDispatch/src/main/java/com/safemobile/lib/sound/AudioHandle.java b/safeDispatch/src/main/java/com/safemobile/lib/sound/AudioHandle.java index a164224..fef94af 100644 --- a/safeDispatch/src/main/java/com/safemobile/lib/sound/AudioHandle.java +++ b/safeDispatch/src/main/java/com/safemobile/lib/sound/AudioHandle.java @@ -24,6 +24,7 @@ public class AudioHandle implements Runnable{ private UDPclient udp; private TcpAudioClient tcp; private int audioport = 50001; + public int typeUDP; public AudioHandle(String IP, int _typeUDP) @@ -89,7 +90,7 @@ public class AudioHandle implements Runnable{ t_micListner.start(); - if(typeUDP==1) + if(typeUDP == 1) { udp.addUDPListener(new IUDPListener() { @@ -99,7 +100,7 @@ public class AudioHandle implements Runnable{ byte[] data = event.data(); int len = event.len(); SM.Debug("recv b:"+len+" data.length:"+data.length); - if(data!=null) + if(data != null) PlaySound(data, len); } @@ -141,20 +142,22 @@ public class AudioHandle implements Runnable{ if (soundNeeded) { //SM.Debug("sending b:"+bRead); - if(typeUDP==1) - { - tempBuffer = new byte[512];//128];//invers3.bufferSize]; - bRead = recDev.read(tempBuffer, 0, 512);// 128);//invers3.bufferSize); + if(typeUDP == 1) + { + int size = 512; // 2048 + + tempBuffer = new byte[size]; + bRead = recDev.read(tempBuffer, 0, size); + udp.Send(tempBuffer,bRead); SM.Debug("UDP sending b:"+bRead); } else { - tempBuffer = new byte[2048];//128];//invers3.bufferSize]; - bRead = recDev.read(tempBuffer, 0, 2048);// 128);//invers3.bufferSize); - /* - tempBuffer = new byte[16384];//128];//invers3.bufferSize]; - bRead = recDev.read(tempBuffer, 0,16384);// 128);//invers3.bufferSize);*/ + int size = 1024; // + tempBuffer = new byte[size]; + bRead = recDev.read(tempBuffer, 0, size); + tcp.send(tempBuffer,bRead); SM.Debug("TCP sending b:"+bRead); } diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/RadioActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/RadioActivity.java index 701c25b..8dcf236 100644 --- a/safeDispatch/src/main/java/com/safemobile/safedispatch/RadioActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/RadioActivity.java @@ -34,6 +34,7 @@ import com.safemobile.lib.radio.Zone_and_channel; import com.safemobile.lib.sound.AudioHandle; import java.util.ArrayList; +import java.util.Hashtable; import java.util.Locale; /** @@ -41,7 +42,7 @@ import java.util.Locale; */ public class RadioActivity extends Activity { - + /* Visual Elements */ private Button buttonPTT, buttonDKey; private RadioGroup radioGroupCallType; @@ -49,12 +50,12 @@ public class RadioActivity extends Activity { private LinearLayout layoutGateway, layoutSpinnerChannel, layoutSpinnerZone, layoutSpinnerCallType; private TextView textViewMessageChannel, textViewMessageStatus, textViewGateway, textViewChannel, textViewZone, textViewIP, textViewCallType; private ImageView imageViewStatus; - + /* Misc */ private TabLayoutActivity parentTab; private Context context; private Activity activity; - + private int radioID, GWID, zoneNR, chNR; private int rStatus = 0; private long imei = 0; @@ -69,33 +70,35 @@ public class RadioActivity extends Activity { private ArrayList allContactsIDs = new ArrayList(); private ArrayList allGroupsIDs = new ArrayList(); private ArrayList allGroupsNames = new ArrayList(); - + private ArrayList crtZones = new ArrayList(); private ArrayList crtChannels = new ArrayList(); private ArrayList allGWsIP = new ArrayList(); private ArrayAdapter adapter; - + // Need handler for callbacks to the UI thread private final Handler myHandler = new Handler(); - + public Thread audioThread; - + //PTT private AudioHandle audioH = null; private final int ALLCall = 101, PRIVATECall = 102, GROUPCall = 103; private int selectedID=0, selectedCallType = 101; private Boolean pttONoff = false, FIRST = true; - + private final int inCall = 1, hangTime = 2, callEnd = 3; + public Bundle savedInstanceState; - - + + /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.savedInstanceState = savedInstanceState; - // get parentTab + + // get parentTab parentTab = (TabLayoutActivity)getParent(); - + Locale locale = new Locale(AppParams.LANGUAGETMP); Locale.setDefault(locale); Configuration config = new Configuration(); @@ -107,141 +110,106 @@ public class RadioActivity extends Activity { // get context context = this; activity = this; - + allGroupsNames.add("1"); allGroupsNames.add("2"); allGroupsIDs.add(1); allGroupsIDs.add(2); - - if(AppParams.DEMO) - { - allGWsIP.add("192.168.1.40"); - allGWsIP.add("192.168.1.60"); - } + + + //==================== // get visual elements + //==================== + + // get buttons buttonPTT = (Button) findViewById(R.id.buttonPTT); buttonDKey = (Button) findViewById(R.id.buttonDKey); + // get CallType Spinner layoutSpinnerCallType = (LinearLayout) findViewById(R.id.layoutSpinnerCallType); layoutSpinnerCallType.setOnClickListener(CallTypeListener); textViewCallType = (TextView) findViewById(R.id.textViewCallType); - + // get status dot imageViewStatus = (ImageView) findViewById(R.id.imageViewStatus); - + layoutSpinnerChannel = (LinearLayout) findViewById(R.id.layoutSpinnerChannel); layoutSpinnerChannel.setOnClickListener(ChannelChangeListener); - //spinnerChannel.setOnItemClickListener(ChannelChangeListener); + layoutSpinnerZone = (LinearLayout) findViewById(R.id.layoutSpinnerZone); layoutSpinnerZone.setOnClickListener(ZoneChangeListener); + // get TextView from Spinner textViewChannel = (TextView) findViewById(R.id.textViewChannel); textViewZone = (TextView) findViewById(R.id.textViewZone); - + + // get IP textViewIP = (TextView) findViewById(R.id.textViewIP); textViewIP.setText(AppParams.IP); - + // get CallType radioGroupCallType = (RadioGroup) findViewById(R.id.radioGroupCallType); radioGroupCallType.setOnCheckedChangeListener(CallTypeChanged); + + // get radio buttons radioAll = (RadioButton) findViewById(R.id.radioAll); radioGroup = (RadioButton) findViewById(R.id.radioGroup); radioPrivate = (RadioButton) findViewById(R.id.radioPrivate); - - + + // get channel textViewMessageChannel = (TextView) findViewById(R.id.textViewMessageChannel); + // get gateway textViewGateway = (TextView) findViewById(R.id.textViewGateway); textViewGateway.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf")); textViewGateway.setTextSize(24); - - + + // get status textViewMessageStatus = (TextView) findViewById(R.id.textViewMessageStatus); layoutGateway = (LinearLayout) findViewById(R.id.layoutGateway); - layoutGateway.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - adapter = new ArrayAdapter( - context, R.layout.template_simple_list_item, - allGWsIP); + layoutGateway.setOnClickListener(GatwayListener); - AlertDialog.Builder builder = new AlertDialog.Builder( - context); - builder.setTitle("Select RadioGW"); - builder.setAdapter(adapter, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // change gateway - //textViewGateway.setText(allGWsIP.get(which)); - // change visual if selected another radioGW - if(!AppParams.DEMO) - radioGWChanged(allGWsIP.get(which)); - else - { - textViewGateway.setText(allGWsIP.get(which)); - textViewZone.setText("Zone 1"); - textViewChannel.setText("Channel 1"); - textViewMessageChannel.setText("Channel 1"); - if(which == 0) - UpdateEnableDisableButtons("online"); - else - UpdateEnableDisableButtons("offline"); - } - } - }); - AlertDialog alert = builder.create(); - alert.show(); - } - }); - - // set button listener + // set button ptt listener buttonPTT.setOnClickListener(PTTClickListener); + // set button DKey listener buttonDKey.setOnClickListener(DKeyClickListener); - //disable DKey button - //buttonDKey.setEnabled(false); - /* - //hide PTT button - buttonPTT.setVisibility(View.GONE); - */ - - audioThread = new Thread(new Runnable() { - - @Override - public void run() { - //start audio - try{ - if(audioH == null && !AppParams.IP.equalsIgnoreCase("n/a")) - audioH = new AudioHandle(AppParams.IP,0); - } - catch(Exception ex) - { - SM.Exception("#### audioH exception! ####"); - SM.Exception(ex.toString()); - } - } - }); - - audioThread.start(); - + + + startAudioThread(); + if(!AppParams.DEMO) UpdateEnableDisableButtons("offline"); - else - { - textViewZone.setText("Zone 1"); - textViewChannel.setText("Channel 1"); - textViewMessageChannel.setText("Channel 1"); - textViewIP.setText("89.33.56.51"); - textViewGateway.setText("192.168.1.40"); - imageViewStatus.setImageResource(R.drawable.status_online); - } - - // send current activity to parrent + + + // send current activity to parent parentTab.setRadioActivity(this); - + // register to be notified when an event is triggered registerBroadcastIntents(); } - + + private void startAudioThread() + { + audioThread = new Thread(new Runnable() { + + @Override + public void run() { + //start audio + try{ + if(audioH == null && !AppParams.IP.equalsIgnoreCase("n/a")) + audioH = new AudioHandle(AppParams.IP,0); + } + catch(Exception ex) + { + SM.Exception("#### audioH exception! ####"); + SM.Exception(ex.toString()); + } + } + }); + + audioThread.start(); + + } + @Override public void onBackPressed() { @@ -266,15 +234,15 @@ public class RadioActivity extends Activity { AlertDialog alert = builder.create(); alert.show(); } - - + + @Override public void onPause() { super.onPause(); SM.Debug("onPause"); } - + @Override public void onResume() { @@ -283,149 +251,163 @@ public class RadioActivity extends Activity { if(!allVehicle.equals(parentTab.getAllVehicle())) { allVehicle = parentTab.getAllVehicle(); - UpdateVehicle(); + UpdateVehicle(); + } - /* - // first request made from TabLiveActivity -> tabHost.setCurrentTab(3); //tabHost.setCurrentTab(0); AND tcpConnection change on first init - if(FIRST) - { - FIRST = false; - } - else - */ if(AppParams.listRadios.size() == 0) GetGWRadios(); SM.Debug("onResume"); } - private OnClickListener PTTClickListener = new OnClickListener() { + private OnClickListener GatwayListener = new OnClickListener() { + @Override public void onClick(View v) { - SM.Debug("Make call calltype:"+selectedCallType + " id:"+selectedID); - // get selectedID - if(selectedCallType == GROUPCall) - selectedID = getGroupID4Name(textViewCallType.getText().toString()); - else if (selectedCallType == PRIVATECall) - selectedID = getPrivateImei4Name(textViewCallType.getText().toString()); - else - selectedID = -1; - - //showDialog("PTT Click"); - if(!pttONoff) - { - String chanMsg = "", statMsg = ""; - if(parentTab.getCrtRadio() != null) - SendPTT(selectedCallType, selectedID, parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID,AppParams.USERID); - // flag in Call - parentTab.setInCall(true); - pttONoff= true; - if(audioH!=null) - audioH.soundNeeded = true; - - buttonPTT.setText(getString(R.string.PTToff)); - buttonPTT.setBackgroundResource(R.drawable.style_buttonptt_green); - // change text in Screen according to callType - switch(selectedCallType) - { - case PRIVATECall : chanMsg = getString(R.string.PrivateCall); statMsg = textViewCallType.getText().toString(); break; - case GROUPCall : chanMsg = getString(R.string.GroupCall); statMsg = textViewCallType.getText().toString(); break; - case ALLCall : chanMsg = getString(R.string.AllCall); statMsg = ""; break; - } - textViewMessageChannel.setText(chanMsg); - textViewMessageStatus.setText(statMsg); - // change status image - imageViewStatus.setImageResource(R.drawable.status_idle); - // disable buttons - UpdateEnableDisableButtons("disablePTT"); - parentTab.enableMenuButtons(false); - } - else - { - //if(selectedCallType != PRIVATECall) - { - pttOffClick(); - } - /*else - { - buttonPTT.setEnabled(false); - buttonPTT.setText("PTT"); - buttonPTT.setBackgroundResource(R.layout.style_buttonptt); - - textViewMessageStatus.setText("Hang Time"); - - // if private call was made, wait 2 seconds before enable call - new Thread(new Runnable() { - public void run() - { - try { - Thread.sleep(4000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - myHandler.post(UpdatepttOffClickRUN); - } - }).start(); - }*/ - } + adapter = new ArrayAdapter( + context, R.layout.template_simple_list_item, + allGWsIP); + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Select RadioGW"); + builder.setAdapter(adapter, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // change gateway + //textViewGateway.setText(allGWsIP.get(which)); + // change visual if selected another radioGW + + radioGWChanged(allGWsIP.get(which)); + + } + }); + AlertDialog alert = builder.create(); + alert.show(); } }; - + + + private OnClickListener PTTClickListener = new OnClickListener() { + @Override + + public void onClick(View v) { + + if (pttONoff) + pttOffClick(); + else + pttOnClick(); + } + }; + final Runnable UpdatepttOffClickRUN = new Runnable() { public void run() { pttOffClick(); } }; - - private void pttOffClick() + + + private void pttOnClick() { - String chanMsg = "", statMsg = ""; - if(!AppParams.DEMO) - SendPTT(selectedCallType+10, 1, parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID,AppParams.USERID); - pttONoff= false; + //================ + // get selectedID + //================ + if(selectedCallType == GROUPCall) + selectedID = getGroupID4Name(textViewCallType.getText().toString()); + else if (selectedCallType == PRIVATECall) + selectedID = getPrivateImei4Name(textViewCallType.getText().toString()); + else + selectedID = -1; + + + // send start the call + if(parentTab.getCrtRadio() != null) + SendPTT(selectedCallType, selectedID, parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID,AppParams.USERID); + + // flag in Call + parentTab.setInCall(true); + pttONoff= true; + // start sound if(audioH!=null) - audioH.soundNeeded = false; - buttonPTT.setText(getString(R.string.PTT)); - buttonPTT.setBackgroundResource(R.drawable.style_buttonptt); - // change text in Screen - /* - if(rStatus == 1) - statMsg = "Online!"; - else - statMsg = "Offline!"; - */ - chanMsg = textViewChannel.getText().toString(); + audioH.soundNeeded = true; + + buttonPTT.setText(getString(R.string.PTToff)); + buttonPTT.setBackgroundResource(R.drawable.style_buttonptt_green); + + // change text in Screen according to callType + String chanMsg = "", statMsg = ""; + switch(selectedCallType) + { + case PRIVATECall : chanMsg = getString(R.string.PrivateCall); statMsg = textViewCallType.getText().toString(); break; + case GROUPCall : chanMsg = getString(R.string.GroupCall); statMsg = textViewCallType.getText().toString(); break; + case ALLCall : chanMsg = getString(R.string.AllCall); statMsg = ""; break; + } textViewMessageChannel.setText(chanMsg); textViewMessageStatus.setText(statMsg); + // change status image + imageViewStatus.setImageResource(R.drawable.status_idle); + + //=================== + // disable buttons + //=================== + UpdateEnableDisableButtons("disablePTT"); + parentTab.enableMenuButtons(false); + + } + + private void pttOffClick() + { + String chanMsg = "", statMsg = ""; + + // send stop the call + if(parentTab.getCrtRadio() != null) + SendPTT(selectedCallType + 10, selectedID, parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID,AppParams.USERID); + + // stop sound + pttONoff = false; + if(audioH != null) + audioH.soundNeeded = false; + + + buttonPTT.setText(getString(R.string.PTT)); + buttonPTT.setBackgroundResource(R.drawable.style_buttonptt); + + + chanMsg = textViewChannel.getText().toString(); + textViewMessageChannel.setText(chanMsg); + textViewMessageStatus.setText(statMsg); + // change status image imageViewStatus.setImageResource(R.drawable.status_online); + // enable buttons UpdateEnableDisableButtons("enable"); parentTab.enableMenuButtons(true); + } - + private OnClickListener DKeyClickListener = new OnClickListener() { @Override - public void onClick(View v) + public void onClick(View v) { SendDekey(); - //showDialog("DKey Click"); } }; - + private OnClickListener ChannelChangeListener = new OnClickListener() { - + @Override public void onClick(View v) { - if(parentTab.getCrtRadio() !=null) + + if(parentTab.getCrtRadio() != null) { // display dialog with adapter ArrayList tmp = new ArrayList(); for(Channel ch: crtChannels) tmp.add(ch.chName); - - ArrayAdapter adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, tmp); - + + ArrayAdapter adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, tmp); + AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getString(R.string.selChannel)); builder.setAdapter(adapter , new DialogInterface.OnClickListener() { @@ -433,74 +415,35 @@ public class RadioActivity extends Activity { public void onClick(DialogInterface dialog, int which) { // change Channel in Display //textViewMessageChannel.setText(crtChannels.get(which).chName); - + // set channel name //textViewChannel.setText(crtChannels.get(which).chName); - + // send change to App onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, getNR4Zone(textViewZone.getText().toString()), getNR4CH(crtChannels.get(which).chName)); } }); - - AlertDialog alert = builder.create(); - alert.show(); - } - - if(AppParams.DEMO) - { - // display dialog with adapter - final ArrayList tmp = new ArrayList(); - if(textViewZone.getText().equals("Zone 1")) - { - tmp.add("Channel 1"); - tmp.add("Channel 2"); - tmp.add("Channel 3"); - tmp.add("Channel 4"); - } - else - { - tmp.add("Ch1 "); - tmp.add("Ch2"); - tmp.add("Ch3"); - } - - ArrayAdapter adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, tmp); - - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(getString(R.string.selChannel)); - builder.setAdapter(adapter , new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // change Channel in Display - textViewMessageChannel.setText(tmp.get(which)); - textViewChannel.setText(tmp.get(which)); - - // set channel name - //textViewChannel.setText(crtChannels.get(which).chName); - - // send change to App - } - }); - + AlertDialog alert = builder.create(); alert.show(); } } }; - + private OnClickListener ZoneChangeListener = new OnClickListener() { - + @Override public void onClick(View v) { + if(parentTab.getCrtRadio() !=null) { // display dialog with adapter ArrayList tmp = new ArrayList(); for(Zone zone: crtZones) tmp.add(zone.ZoneName); - - ArrayAdapter adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, tmp); - + + ArrayAdapter adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, tmp); + AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getString(R.string.selZone)); builder.setAdapter(adapter , new DialogInterface.OnClickListener() { @@ -508,163 +451,97 @@ public class RadioActivity extends Activity { public void onClick(DialogInterface dialog, int which) { // set zone name //textViewZone.setText(crtZones.get(which).ZoneName); - + // send change to App //onZoneCHChange(parentTab.crtRadio.ID, parentTab.crtRadio.GW_ID, getNR4Zone(crtZones.get(which).ZoneName), getNR4CH(textViewChannel.getText().toString())); onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, getNR4Zone(crtZones.get(which).ZoneName), 1); } }); - - AlertDialog alert = builder.create(); - alert.show(); - } - if(AppParams.DEMO) - { - // display dialog with adapter - final ArrayList tmp = new ArrayList(); - tmp.add("Zone 1"); - tmp.add("Zone 2"); - - ArrayAdapter adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, tmp); - - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(getString(R.string.selZone)); - builder.setAdapter(adapter , new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // set zone name - textViewZone.setText(tmp.get(which)); - if(textViewZone.getText().equals("Zone 1")) - { - textViewChannel.setText("Channel 1"); - textViewMessageChannel.setText("Channel 1"); - } - else - { - textViewChannel.setText("Ch1"); - textViewMessageChannel.setText("Ch1"); - } - // 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); - } - }); - + AlertDialog alert = builder.create(); alert.show(); } + } - }; - + }; + private OnClickListener CallTypeListener = new OnClickListener() { - + @Override public void onClick(View v) { - if(parentTab.getCrtRadio() !=null) + + + if(parentTab.getCrtRadio() != null) { // create spinner selected AlertDialog.Builder builder = new AlertDialog.Builder(context); switch(radioGroupCallType.getCheckedRadioButtonId()) { - case R.id.radioGroup : + case R.id.radioGroup : // set adapter and title - adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, allGroupsNames); + adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, allGroupsNames); builder.setTitle(getString(R.string.selectGroup)); break; - case R.id.radioPrivate : + case R.id.radioPrivate : // set adapter and title - adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, allVehicleNames); + adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, allVehicleNames); builder.setTitle(getString(R.string.selectVehicle)); break; } - + builder.setAdapter(adapter , new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch(radioGroupCallType.getCheckedRadioButtonId()) { - case R.id.radioGroup : + case R.id.radioGroup : // set adapter and title textViewCallType.setText(allGroupsNames.get(which)); break; - case R.id.radioPrivate : + case R.id.radioPrivate : textViewCallType.setText(allVehicleNames.get(which)); break; } } }); - - AlertDialog alert = builder.create(); - alert.show(); - } - else if (AppParams.DEMO) - { - // create spinner selected - AlertDialog.Builder builder = new AlertDialog.Builder(context); - switch(radioGroupCallType.getCheckedRadioButtonId()) - { - case R.id.radioGroup : - // set adapter and title - adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, allGroupsNames); - builder.setTitle(getString(R.string.selectGroup)); - break; - case R.id.radioPrivate : - // set adapter and title - adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, allVehicleNames); - builder.setTitle(getString(R.string.selectVehicle)); - break; - } - - builder.setAdapter(adapter , new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch(radioGroupCallType.getCheckedRadioButtonId()) - { - case R.id.radioGroup : - // set adapter and title - textViewCallType.setText(allGroupsNames.get(which)); - break; - case R.id.radioPrivate : - textViewCallType.setText(allVehicleNames.get(which)); - break; - } - } - }); - + AlertDialog alert = builder.create(); alert.show(); } + } - }; - + }; + private OnCheckedChangeListener CallTypeChanged = new OnCheckedChangeListener() { - + @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch(radioGroupCallType.getCheckedRadioButtonId()) { - case R.id.radioAll : + case R.id.radioAll : layoutSpinnerCallType.setVisibility(View.INVISIBLE); selectedCallType = ALLCall; break; - case R.id.radioGroup : - layoutSpinnerCallType.setVisibility(View.VISIBLE); + case R.id.radioGroup : + layoutSpinnerCallType.setVisibility(View.VISIBLE); textViewCallType.setText(allGroupsNames.get(0)); selectedCallType = GROUPCall; break; - case R.id.radioPrivate : + case R.id.radioPrivate : + layoutSpinnerCallType.setVisibility(View.VISIBLE); if(allVehicleNames.size() > 0) textViewCallType.setText(allVehicleNames.get(0)); else textViewCallType.setText(""); + selectedCallType = PRIVATECall; break; } } }; - - + + public void showDialog(String errorMsg) { Dialog dialog = new Dialog(context); @@ -675,12 +552,12 @@ public class RadioActivity extends Activity { TextView text = dialog.findViewById(R.id.text); ImageView image = dialog.findViewById(R.id.image); - + image.setImageResource(R.mipmap.ic_launcher); text.setText(errorMsg); dialog.show(); } - + // called from ParentTabActivity public void UpdateRadios(ArrayList radios) { @@ -688,16 +565,19 @@ public class RadioActivity extends Activity { AppParams.listRadios = radios; if(parentTab.getCrtRadio() == null) parentTab.setCrtRadio(AppParams.listRadios.get(0)); + // if crtRadio not exists anymore if(!AppParams.listRadios.contains(parentTab.getCrtRadio())) parentTab.setCrtRadio(AppParams.listRadios.get(0)); SM.Debug(parentTab.getCrtRadio().toString()); + + // get status for selected Radio ReqRadioStatus(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID); // get selected Zone and CH onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, 0,0); - + myHandler.post(updateGatewaysRUN); } @@ -708,113 +588,135 @@ public class RadioActivity extends Activity { updateGateways(); } }; - - + + public void updateGateways() { // get all radio IP allGWsIP.clear(); for(RadioGW radio: AppParams.listRadios) allGWsIP.add(radio.IP); + textViewGateway.setText(parentTab.getCrtRadio().IP); } - - + + // modify privateCall Adapter after resume if Vehicle List Modified public void UpdateVehicle() { - + allVehicleNames = new ArrayList(); - if(allVehicle!=null) + if( allVehicle!=null ) for(Vehicle vehicle: allVehicle) allVehicleNames.add(vehicle.name); - + } - + + private RadioGW getRadioGW(int _radioID, int _gwID) + { + for(RadioGW radio: AppParams.listRadios) { + if (radio.GW_ID == _gwID && radio.ID == _radioID) + return radio; + } + + return null; + } + + private ArrayList getChannels(int zoneNR) + { + for(Zone zone : parentTab.getCrtRadio().zoneList) { + if (zone.id == zoneNR) + return zone.channelList; + } + + return new ArrayList(); + } + // called from ParentTabActivity to set radioID, GWID, zoneNR and chNR - public void UpdateZoneCH(int _radioID, int _GWID, int _zoneNR, int _chNR) + public void UpdateZoneCH(int _radioID, int _gwID, int _zoneNR, int _chNR) { boolean cmdForMe =false; // save received id's zoneNr and CHNR this.radioID = _radioID; - this.GWID = _GWID; + this.GWID = _gwID; this.zoneNR = _zoneNR; this.chNR = _chNR; - - SM.Debug("am primit: " + _radioID + "," + _GWID + "," + _zoneNR + "," + _chNR); - - 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.setCrtRadio(radio); - crtZones = radio.zoneList; - cmdForMe = true; - } - } - if (cmdForMe) - { - for(Zone zone: parentTab.getCrtRadio().zoneList) - if(zone.id == _zoneNR) - crtChannels = zone.channelList; - // update UI - myHandler.post(UpdateResultsZoneChannelRUN); - } + + SM.Debug("am primit: " + _radioID + "," + _gwID + "," + _zoneNR + "," + _chNR); + + // get RadioGw + RadioGW radioGW = getRadioGW(_radioID, _gwID); + if( radioGW == null) { + return; + } + + // set current radio + parentTab.setCrtRadio(radioGW); + // set current zones + crtZones = radioGW.zoneList; + // set current channels + crtChannels = getChannels(_zoneNR); + + myHandler.post(UpdateResultsZoneChannelRUN); + } - + // Create runnable for posting final Runnable UpdateResultsZoneChannelRUN = new Runnable() { public void run() { updateResultsInUi(); } }; - + private void updateResultsInUi() { - if(AppParams.listRadios.size()>0) + if(AppParams.listRadios.size() > 0) { textViewGateway.setText(parentTab.getCrtRadio().IP); - + // get all radio IP allGWsIP.clear(); for(RadioGW radio: AppParams.listRadios) allGWsIP.add(radio.IP); - + // set spinners and text if(parentTab.getCrtRadio() == null) { parentTab.setCrtRadio(AppParams.listRadios.get(0)); textViewGateway.setText(allGWsIP.get(0)); + // set zone ArrayList zones = new ArrayList(); crtZones = parentTab.getCrtRadio().zoneList; for(Zone zone: crtZones) zones.add(zone.ZoneName); - + textViewZone.setText(zones.get(0).toString()); //spinnerZone.setAdapter(new ArrayAdapter(context, R.layout.template_simple_list_item, zones)); //spinnerZone.setSelection(0); + // set channel ArrayList channel = new ArrayList(); crtChannels = parentTab.getCrtRadio().zoneList.get(0).channelList; for(Channel ch: crtChannels) channel.add(ch.chName); textViewChannel.setText(channel.get(0).toString()); + //spinnerChannel.setAdapter(new ArrayAdapter(context, R.layout.template_simple_list_item, channel)); //if(spinnerChannel.getSelectedItemPosition() !=0) - // spinnerChannel.setSelection(0); + // spinnerChannel.setSelection(0); } else { for(RadioGW radio: AppParams.listRadios) if(radio.ID == radioID && radio.GW_ID == GWID) parentTab.setCrtRadio(radio); + // get zones for adapter ArrayList zones = new ArrayList(); crtZones = parentTab.getCrtRadio().zoneList; + int position = 0; // get selected Zone for(int i=0; i< crtZones.size(); i++) @@ -824,20 +726,23 @@ public class RadioActivity extends Activity { if(zone.id == zoneNR) position = i; // save crt position in array } + textViewZone.setText(zones.get(position).toString()); // set channel ArrayList channel = new ArrayList(); crtChannels = parentTab.getCrtRadio().zoneList.get(position).channelList; - position = 0; + // get current channel + position = 0; for(int i=0; i< crtChannels.size(); i++) { Channel ch = crtChannels.get(i); channel.add(ch.chName); if(ch.id == chNR) - position = i; + position = i; } + textViewChannel.setText(channel.get(position).toString()); textViewMessageChannel.setText(channel.get(position).toString()); } @@ -849,7 +754,7 @@ public class RadioActivity extends Activity { // Radio Gateway changed from UI private void radioGWChanged(String newIP) { - + // get gateway id for(RadioGW radio:AppParams.listRadios) if(radio.IP.equals(newIP)) @@ -858,21 +763,38 @@ public class RadioActivity extends Activity { onZoneCHChange(radio.ID, radio.GW_ID,0,0); // get zone and channel for crt radio parentTab.setCrtRadio(radio); } + textViewGateway.setText(newIP); - imageViewStatus.setImageResource(R.drawable.status_offline); - + // clear Spinners + ClearSpinners(); + // reset adapter for spinners + ResetAdaptersForSpinners(); + + } + + private void ClearSpinners() + { textViewZone.setText(""); textViewChannel.setText(""); textViewMessageChannel.setText(""); - // reset adapter for spinners + } + + private void ResetAdaptersForSpinners() + { crtChannels = new ArrayList(); crtZones = new ArrayList(); + } + + private void SetCheck(RadioButton radioButton) + { + radioPrivate.setChecked(radioPrivate == radioButton ); + radioGroup.setChecked(radioGroup == radioButton ); + radioAll.setChecked(radioAll == radioButton ); } - - + // broadcastCall from ParentTabActivity to set radio status public void UpdateBroadcastCall(long Imei,int Calltype,int GroupID,int CallStatus) { @@ -880,90 +802,92 @@ public class RadioActivity extends Activity { SM.Debug("Status: Imei: " + Imei+ " Calltype: "+Calltype+ " GroupID: "+GroupID+" CallStatus:"+CallStatus); this.imei = Imei; this.calltype = Calltype; - this.groupid = GroupID; - this.callstatus =CallStatus; + this.groupid = GroupID; + this.callstatus = CallStatus; + myHandler.post(UpdateB); } - + final Runnable UpdateB = new Runnable() { public void run() { UpdateResultsBroadcastCall(); } }; - + private void UpdateResultsBroadcastCall() { SM.Debug("UpdateResultsBroadcastCall with Imei: " +imei+ " CallType:"+calltype+ " GroupID:"+groupid+" CallStatus:"+callstatus); - if ((callstatus==1)||(callstatus==2)) + if ((callstatus == inCall) || (callstatus== hangTime)) { // modify UI only when call is received, not in hangtime - if(callstatus == 1) + if(callstatus == inCall) { layoutGateway.setEnabled(false); String CallType = getString(R.string.AllCall); - if (calltype==102) + if (calltype == PRIVATECall ) { CallType = getString(R.string.PrivateCall); - radioPrivate.setChecked(true); - radioAll.setChecked(false); - radioGroup.setChecked(false); + SetCheck(radioPrivate); selectedCallType = PRIVATECall; - textViewCallType.setText(parentTab.getSuperVehHash().get((long)imei).name); - layoutSpinnerCallType.setVisibility(View.VISIBLE); + } - else if (calltype==103) + else if (calltype == GROUPCall) { CallType = getString(R.string.GroupCall) + "("+groupid+")"; - - radioPrivate.setChecked(false); - radioAll.setChecked(false); - radioGroup.setChecked(true); + SetCheck(radioGroup); selectedCallType = GROUPCall; - textViewCallType.setText(groupid+""); - layoutSpinnerCallType.setVisibility(View.VISIBLE); + textViewCallType.setText(groupid + ""); + } - - if(CallType.equals(getString(R.string.AllCall))) + else { - radioPrivate.setChecked(false); - radioAll.setChecked(true); - radioGroup.setChecked(false); + SetCheck(radioAll); selectedCallType = ALLCall; - layoutSpinnerCallType.setVisibility(View.INVISIBLE); + } - - textViewMessageChannel.setText(CallType); + + layoutSpinnerCallType.setVisibility( calltype != ALLCall ? View.VISIBLE : View.INVISIBLE); + textViewMessageChannel.setText(CallType); + + + if ( parentTab.getSuperVehHash() != null) { + if (parentTab.getSuperVehHash().containsKey((long) imei)) + textViewMessageStatus.setText(parentTab.getSuperVehHash().get((long) imei).name); + else + textViewMessageStatus.setText("Imei: " + Long.toString(imei)); + } } - if (callstatus==1) - { - if (parentTab.getSuperVehHash().get((long)imei)!=null) - textViewMessageStatus.setText(parentTab.getSuperVehHash().get((long)imei).name); - else - textViewMessageStatus.setText("Imei: "+Long.toString(imei)); - } - else if(selectedCallType == calltype) - textViewMessageStatus.setText(getString(R.string.hangTime)); + + if (callstatus == hangTime) { + textViewMessageStatus.setText(getString(R.string.hangTime)); + + buttonPTT.setEnabled(true); + buttonDKey.setEnabled(false); + } + // change UI only if call types equals - if(selectedCallType == calltype) - { - imageViewStatus.setImageResource(R.drawable.status_idle); - - // disable buttons - UpdateEnableDisableButtons("disableIncCall"); - } +// if(selectedCallType == calltype) +// { +// imageViewStatus.setImageResource(R.drawable.status_idle); +// // disable buttons +// UpdateEnableDisableButtons("disableIncCall"); +// } + // enable PTT button and disable DKey when HangTime - if(callstatus==2 && selectedCallType == calltype) - { - buttonPTT.setEnabled(true); - buttonDKey.setEnabled(false); - } +// if(callstatus == hangTime && selectedCallType == calltype) +// { +// buttonPTT.setEnabled(true); +// buttonDKey.setEnabled(false); +// } + if(parentTab.getCrtActivity() == parentTab.RADIO_TAB_ID && selectedCallType == calltype) parentTab.enableMenuButtons(false); + if(selectedCallType == calltype) parentTab.setInCall(true); - + } - else if (callstatus==3) + else if (callstatus == callEnd ) { if((calltype == 0 && pttONoff == true) || selectedCallType == calltype) { @@ -971,163 +895,144 @@ public class RadioActivity extends Activity { textViewMessageChannel.setText(textViewChannel.getText()); textViewMessageStatus.setText(" "); imageViewStatus.setImageResource(R.drawable.status_online); + + // stop sound if(audioH!=null) audioH.StopSound(); - + // disable buttons UpdateEnableDisableButtons("enable"); + if(pttONoff) { pttONoff= false; + if(audioH!=null) audioH.soundNeeded = false; - buttonPTT.setText(getString(R.string.PTT)); + + + buttonPTT.setText(getString(R.string.PTT)); buttonPTT.setBackgroundResource(R.drawable.style_buttonptt); } parentTab.enableMenuButtons(true); - - parentTab.setInCall(false); + parentTab.setInCall(false); } } } - + // called from ParentTabActivity to set radio status public void UpdateRadioStatus (int status) { // save received id's zoneNr and CHNR this.rStatus = status; - + SM.Debug("rStatus: " + rStatus ); myHandler.post(UpdateRadioS); } - + final Runnable UpdateRadioS = new Runnable() { public void run() { updateResultsStatus(); } }; - + private void updateResultsStatus() { - SM.Debug("updateResultsStatusUI with Status: " + (rStatus == 1? "ONLINE" : "OFFLINE")); - //textViewGateway.setText(crtRadio.IP); - if(rStatus == 1) - { - imageViewStatus.setImageResource(R.drawable.status_online); - //textViewMessageStatus.setText("Online!!!"); - UpdateEnableDisableButtons("online"); - } - else - { - imageViewStatus.setImageResource(R.drawable.status_offline); - //textViewMessageStatus.setText("Offline!!!"); - UpdateEnableDisableButtons("offline"); - } - + SM.Debug("updateResultsStatusUI with Status: " + (rStatus == 1? "ONLINE" : "OFFLINE")); + + imageViewStatus.setImageResource( (rStatus == 1 ) ? R.drawable.status_online : R.drawable.status_offline); + UpdateEnableDisableButtons( (rStatus == 1 ) ? "online" : "offline"); } - - - public void UpdateEnableDisableButtons(String type) - { - if(type.equals("disableIncCall")) + + + private void enableDisableRadioCallType(boolean enabled) + { + radioGroupCallType.setEnabled(enabled); + radioAll.setEnabled(enabled); + radioGroup.setEnabled(enabled); + radioPrivate.setEnabled(enabled); + } + + private void enableDisableSpinners(boolean enabled) + { + layoutSpinnerZone.setEnabled(enabled); + layoutSpinnerChannel.setEnabled(enabled); + layoutSpinnerCallType.setEnabled(enabled); + } + + public void UpdateEnableDisableButtons(String type) + { + if(type.equals("disableIncCall")) { - radioGroupCallType.setEnabled(false); - radioAll.setEnabled(false); - radioGroup.setEnabled(false); - radioPrivate.setEnabled(false); - - // disable spinners - layoutSpinnerZone.setEnabled(false); - layoutSpinnerChannel.setEnabled(false); - layoutSpinnerCallType.setEnabled(false); - - // enable Dkey button and disable PTT + enableDisableRadioCallType(false); + enableDisableSpinners(false); + + // enable Dkey button buttonDKey.setEnabled(true); + // disable PTT buttonPTT.setEnabled(false); } else if (type.equals("disablePTT")) { - radioGroupCallType.setEnabled(false); - radioAll.setEnabled(false); - radioGroup.setEnabled(false); - radioPrivate.setEnabled(false); - - // disable spinners - layoutSpinnerZone.setEnabled(false); - layoutSpinnerChannel.setEnabled(false); - layoutSpinnerCallType.setEnabled(false); - + + enableDisableRadioCallType(false); + enableDisableSpinners(false); + // disable Dkey button buttonDKey.setEnabled(false); } else if (type.equals("enable")) { - radioGroupCallType.setEnabled(true); - radioAll.setEnabled(true); - radioGroup.setEnabled(true); - radioPrivate.setEnabled(true); - - // enable spinners - layoutSpinnerZone.setEnabled(true); - layoutSpinnerChannel.setEnabled(true); - layoutSpinnerCallType.setEnabled(true); - + enableDisableRadioCallType(true); + enableDisableSpinners(true); + // disable Dkey button and enable PTT buttonDKey.setEnabled(false); buttonPTT.setEnabled(true); } else if(type.equals("online")) - { - radioGroupCallType.setEnabled(true); - radioAll.setEnabled(true); - radioGroup.setEnabled(true); - radioPrivate.setEnabled(true); - - // enable spinners - layoutSpinnerZone.setEnabled(true); - layoutSpinnerChannel.setEnabled(true); - layoutSpinnerCallType.setEnabled(true); - + { + enableDisableRadioCallType(true); + enableDisableSpinners(true); + // disable Dkey button buttonDKey.setEnabled(false); buttonPTT.setEnabled(true); textViewMessageStatus.setText(""); - parentTab.enableMenuButtons(true); - } - else if (type.equals("offline")) - { - radioGroupCallType.setEnabled(false); - radioAll.setEnabled(false); - radioGroup.setEnabled(false); - radioPrivate.setEnabled(false); - - // disable spinners - layoutSpinnerZone.setEnabled(false); - layoutSpinnerChannel.setEnabled(false); - layoutSpinnerCallType.setEnabled(false); - + parentTab.enableMenuButtons(true); + } + else if (type.equals("offline")) + { + enableDisableRadioCallType(false); + enableDisableSpinners(false); + + // disable Dkey button buttonDKey.setEnabled(false); + // disable PTT button buttonPTT.setEnabled(false); + // reset zone and channel text textViewZone.setText(""); textViewChannel.setText(""); - parentTab.enableMenuButtons(true); //enable menu buttons - + + parentTab.enableMenuButtons(true); //enable menu buttons + // reset status icon imageViewStatus.setImageResource(R.drawable.status_offline); + // reset screen messages textViewMessageChannel.setText(""); textViewMessageStatus.setText(getString(R.string.offline)); - } - } - - + } + } + + // get Group Contact ID from Name private int getGroupID4Name(String name) { int i = 0; - + for (String groupName: allGroupsNames) { // if searched name - return corresponding id @@ -1135,26 +1040,22 @@ public class RadioActivity extends Activity { return allGroupsIDs.get(i); i++; } - + return -1; } - + // get Private Contact ID from Name private int getPrivateImei4Name(String name) { - int i = 0; - for (String vehicleName:allVehicleNames) + for(Vehicle vehicle: allVehicle) { - // if searched name - return corresponding id - if(vehicleName.equals(name)) - return Integer.parseInt(allVehicle.get(i).imei); - - i++; + if(vehicle.name.equals(name)) + return Integer.parseInt(vehicle.imei); } - + return -1; } - + // get zone number from spinner zoneName private int getNR4Zone(String zoneName) { @@ -1163,7 +1064,7 @@ public class RadioActivity extends Activity { return zone.id; return -1; } - + // get channel number from spinner chName private int getNR4CH(String chName) { @@ -1172,27 +1073,27 @@ public class RadioActivity extends Activity { return ch.id; return -1; } - + // send GetGWRadios to AppServer private void GetGWRadios() { parentTab.getRadiosList(); } - + // send Dekey to AppServer private void SendDekey() { if(parentTab.getCrtRadio() != null) parentTab.sendDekey(parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID); } - + // send change Channel and Zone message to AppServer private void onZoneCHChange(int RadioID, int GWID, int zone, int ch) { SM.Debug("Changed Z: " + zone + " | Channel: " + ch); parentTab.getSetZoneAndChannel(GWID,RadioID,zone,ch); } - + // request radio status private void ReqRadioStatus(int RadioID, int GWID) { @@ -1203,7 +1104,7 @@ public class RadioActivity extends Activity { } catch (InterruptedException e) { e.printStackTrace(); } - + } //sendPTT //callType: @@ -1214,42 +1115,49 @@ public class RadioActivity extends Activity { //103 -grpcall init //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); } - - - + + + /** Register for broadcasts */ private void registerBroadcastIntents() { - IntentFilter intentFilter = new IntentFilter(OperationCodes.CHANNEL_BRDCST+""); + IntentFilter intentFilter = new IntentFilter(OperationCodes.CHANNEL_BRDCST + ""); this.registerReceiver(mReceiver, intentFilter); - intentFilter = new IntentFilter(OperationCodes.RADIOID_CHANGED+""); + + intentFilter = new IntentFilter(OperationCodes.RADIOID_CHANGED + ""); this.registerReceiver(mReceiver, intentFilter); } - + //The BroadcastReceiver that listens for Notification broadcasts public final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { //SM.Debug("### NOTIFICATION ###", "Radio: " + intent.getAction()); - + final String action = intent.getAction(); - if (action.equals(OperationCodes.CHANNEL_BRDCST+"")) { + + // CHANNEL_BRDCST + if (action.equals(OperationCodes.CHANNEL_BRDCST + "")) { + Zone_and_channel zc = AppParams.crtZoneAndChannel; - UpdateZoneCH(zc.rgwID, zc.gwID, zc.zoneNr, zc.channelNr); + UpdateZoneCH(zc.rgwID, zc.gwID, zc.zoneNr, zc.channelNr); } - else if (action.equals(OperationCodes.RADIOID_CHANGED+"")) { + + // RADIOID_CHANGED + if (action.equals(OperationCodes.RADIOID_CHANGED + "")) { + textViewGateway.setText(parentTab.getCrtRadio().IP); textViewChannel.setText(parentTab.getCrtRadio().getChannelName()); textViewZone.setText(parentTab.getCrtRadio().getZoneName()); - + // update UI myHandler.post(UpdateResultsZoneChannelRUN); radioGWChanged(parentTab.getCrtRadio().IP); } } }; - + } \ No newline at end of file diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java index 6ef16a8..478f8da 100644 --- a/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java @@ -10,19 +10,13 @@ import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.res.Configuration; import android.graphics.Color; -import android.net.ConnectivityManager; -import android.net.Network; -import android.net.NetworkCapabilities; -import android.net.NetworkRequest; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.text.Editable; import android.text.InputType; -import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; @@ -120,17 +114,6 @@ public class SDMobileActivity extends Activity { super.onCreate(savedInstanceState); SM.Debug("##### onCREATE ##### with LANGUAGE " + AppParams.LANGUAGETMP); - ConnectivityManager connectivityManager = - (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - connectivityManager.registerDefaultNetworkCallback(networkCallback); - } else { - NetworkRequest request = new NetworkRequest.Builder() - .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build(); - connectivityManager.registerNetworkCallback(request, networkCallback); - } - AppParams.theme = AppParams.Theme.SAFEDISPATCH; if (AppParams.theme == AppParams.Theme.SAFENET) this.setTheme(R.style.Theme_Safenet); @@ -182,37 +165,16 @@ public class SDMobileActivity extends Activity { ImageView imageLoading = (ImageView) findViewById(R.id.imageLoading); imageLoading.setBackgroundResource(R.drawable.loading); + // language imageLanguage = (ImageView) findViewById(R.id.imageLanguage); - - // change spinner icon and selected language according to tmpLanguage - switch (AppParams.LANGUAGETMP) { - case "en": - imageLanguage.setImageResource(R.drawable.en); - break; - case "de": - imageLanguage.setImageResource(R.drawable.de); - break; - case "tr": - imageLanguage.setImageResource(R.drawable.tr); - break; - case "ro": - imageLanguage.setImageResource(R.drawable.ro); - break; - case "es": - imageLanguage.setImageResource(R.drawable.es); - break; - case "ru": - imageLanguage.setImageResource(R.drawable.ru); - break; - default: - throw new IllegalStateException("Unexpected value: " + AppParams.LANGUAGETMP); - } - imageLanguage.setOnClickListener(LanguageListener); + setLanguageIcon(); + // username and password etUsername = (EditText) findViewById(R.id.etUsername); etPassword = (EditText) findViewById(R.id.etPassword); + // login button btLogin = (Button) findViewById(R.id.btLogin); btLogin.setOnClickListener(arg0 -> { @@ -304,6 +266,35 @@ public class SDMobileActivity extends Activity { } } + + private void setLanguageIcon() + { + // change spinner icon and selected language according to tmpLanguage + switch (AppParams.LANGUAGETMP) { + case "en": + imageLanguage.setImageResource(R.drawable.en); + break; + case "de": + imageLanguage.setImageResource(R.drawable.de); + break; + case "tr": + imageLanguage.setImageResource(R.drawable.tr); + break; + case "ro": + imageLanguage.setImageResource(R.drawable.ro); + break; + case "es": + imageLanguage.setImageResource(R.drawable.es); + break; + case "ru": + imageLanguage.setImageResource(R.drawable.ru); + break; + default: + throw new IllegalStateException("Unexpected value: " + AppParams.LANGUAGETMP); + } + + } + @Override public void onBackPressed() { if (loadingDialog.isShowing()) @@ -541,22 +532,6 @@ public class SDMobileActivity extends Activity { SM.Debug("##### onRESUME #####"); } - private final ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() { - @Override - public void onAvailable(Network network) { - // network available - Log.v("NetworkAvailability", "available"); - if (tcp != null && !tcp.isConnectionUP) - saveIPandRestartTCP(AppParams.IP, AppParams.PORT); - } - - @Override - public void onLost(Network network) { - // network unavailable - Log.v("NetworkAvailability", "unavailable"); - } - }; - private void startTabActivity(long userID) { // good login - load activity diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/TabLayoutActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/TabLayoutActivity.java index 3f463eb..d7e508b 100644 --- a/safeDispatch/src/main/java/com/safemobile/safedispatch/TabLayoutActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/TabLayoutActivity.java @@ -59,7 +59,7 @@ import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; import android.app.Dialog; -import android.app.NotificationChannel; +import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; @@ -74,7 +74,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.net.Uri; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -95,14 +94,13 @@ import android.widget.Toast; import android.widget.TabHost.TabSpec; import androidx.annotation.NonNull; -import androidx.core.app.NotificationCompat; -import androidx.core.app.NotificationManagerCompat; public class TabLayoutActivity extends AbstractSDParentActivity { /* Misc */ private Resources res; private Context context; + private Activity activity; public static final int RADIO_TAB_ID = 4; private static final String HASH_ERROR_MESSAGE = "Error load hash: "; @@ -357,55 +355,58 @@ public class TabLayoutActivity extends AbstractSDParentActivity { getBaseContext().getResources().getDisplayMetrics()); setContentView(R.layout.tabpanel); + context = this; + activity = this; + res = getResources(); // Resource object to get Drawables - 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); - } - } +// 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 @@ -418,353 +419,64 @@ public class TabLayoutActivity extends AbstractSDParentActivity { slideTabsText = findViewById(R.id.slideTabsText); imageViewPopUp = findViewById(R.id.imageViewPopUp); imageViewClose = findViewById(R.id.imageViewClose); - if (AppParams.DEMO) - imageViewClose.setVisibility(View.VISIBLE); + +// if (AppParams.DEMO) +// imageViewClose.setVisibility(View.VISIBLE); tabHost = getTabHost(); // The activity TabHost tabHost.setTag("Tab Panel"); /* Tab */ + TabWidget tabWidget = findViewById(android.R.id.tabs); tabWidget.setVisibility(View.GONE); - Intent[] intent = new Intent[8]; - TabSpec[] tabSpecs = new TabSpec[8]; - - // add live tab - try { - intent[0] = new Intent(context, LiveActivity.class); - tabSpecs[0] = tabHost.newTabSpec(LIVE) - .setIndicator(LIVE, res.getDrawable(R.drawable.ic_tab_live_selected)) - .setContent(intent[0]); - } 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)) - .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)) - .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)) - .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)) - .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)) - .setContent(intent[4]); - - // add setup tab - intent[5] = new Intent(context, SetupActivity.class); - 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(ABOUT) - .setIndicator(ABOUT, res.getDrawable(AppParams.DEMO ? R.drawable.icon_demo : R.mipmap.ic_launcher)) - .setContent(intent[6]); - - // add history tab - try { - intent[7] = new Intent(context, HistoryActivity.class); - tabSpecs[7] = tabHost.newTabSpec(HISTORY) - .setIndicator(HISTORY, res.getDrawable(R.drawable.ic_tab_history_selected)) - .setContent(intent[7]); - } 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)) - .setContent(intent[1]); - } - + TabSpec[] tabSpecs = populateTabs(); // add tab in tabHost for (TabSpec tab : tabSpecs) { if (tabHost != null) tabHost.addTab(tab); } - LinearLayout layoutMenu = findViewById(R.id.layoutMenu); + LinearLayout layoutMenu = findViewById(R.id.layoutMenu); // get slide Menu layout image ImageView imageViewSlideMenu = findViewById(R.id.imageViewSlideMenu); // get Live Button buttonLive = findViewById(R.id.buttonLive); - buttonLive.setOnClickListener(v -> { - if (!buttonLive.isSelected()) { - // select button - buttonLive.setSelected(true); - // deselect other buttons - buttonAlarms.setSelected(false); - buttonHistory.setSelected(false); - buttonRadio.setSelected(false); - buttonRecordings.setSelected(false); - buttonSetup.setSelected(false); - buttonText.setSelected(false); - // select tab - tabHost.setCurrentTabByTag(LIVE); - AppParams.crtTab = AppParams.Tabs.live; - } - }); + buttonLive.setOnClickListener(buttonLiveClickListener); // get History Button buttonHistory = findViewById(R.id.buttonHistory); - buttonHistory.setOnClickListener(v -> { - if (!buttonHistory.isSelected()) { - // select button - buttonHistory.setSelected(true); - // deselect other buttons - buttonAlarms.setSelected(false); - buttonLive.setSelected(false); - buttonRadio.setSelected(false); - buttonRecordings.setSelected(false); - buttonSetup.setSelected(false); - buttonText.setSelected(false); - // select tab - tabHost.setCurrentTabByTag(HISTORY); - AppParams.crtTab = AppParams.Tabs.history; - } - }); + buttonHistory.setOnClickListener(buttonHistoryClickListener); // get Text Button buttonText = findViewById(R.id.buttonText); - buttonText.setOnClickListener(v -> { - if (!buttonText.isSelected()) { - // 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 tab - tabHost.setCurrentTabByTag(TEXT); - AppParams.crtTab = AppParams.Tabs.message; - - if (AppParams.DEMO && getMessageActivity().getAllVehicle().isEmpty()) { - // 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 tab - tabHost.setCurrentTabByTag(TEXT); - AppParams.crtTab = AppParams.Tabs.message; - - if (AppParams.DEMO && getMessageActivity().getAllVehicle().isEmpty()) { - getMessageActivity().updateVehicles(getAllVehicle()); - getMessageActivity().updateSMS(getDemoSmsList()); - } - } - } - }); + buttonText.setOnClickListener(buttonTextClickListener); // get Radio Button buttonRadio = findViewById(R.id.buttonRadio); if (NO_SOUND) buttonRadio.setVisibility(View.GONE); - buttonRadio.setOnClickListener(v -> { - if (!buttonRadio.isSelected()) { - - // check audio permission - IPermissionModule permissionModule = new PermissionModule(); - AuthorizationStatus audioAuthorizationStatus = permissionModule.getAuthorizationStatus(this, AuthorizationCode.RECORD_AUDIO); - if (audioAuthorizationStatus != AuthorizationStatus.AUTHORIZE) { - permissionModule.requestAuthorization(this, AuthorizationCode.RECORD_AUDIO); - return; - } - - // 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(); - } - } - }); + buttonRadio.setOnClickListener(buttonRadioClickListener); // 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().getAllRecordings() != null && getRecordingsActivity().getAllRecordings().isEmpty()) { - ArrayList listRecordings = new ArrayList<>(); - Recording rec = new Recording(); - rec.userWhoWasCalled = "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.userWhoWasCalled = "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.userWhoWasCalled = "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); - } - } - }); + buttonRecordings.setOnClickListener(buttonRecordingsClickListener); // 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); - } - } - }); + buttonAlarms.setOnClickListener(buttonAlarmsClickListener); //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; - } - }); + buttonSetup.setOnClickListener(buttonSetupClickListener); // 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)); - dialog.setContentView(R.layout.dialog); - ImageView image = dialog.findViewById(R.id.image); - image.setImageResource(AppParams.DEMO ? R.drawable.icon_demo : R.mipmap.ic_launcher); - TextView text = dialog.findViewById(R.id.text); - TextView text2 = dialog.findViewById(R.id.text2); - 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(); - }); + buttonLogo.setOnClickListener(buttonLogoClickListener); + imageViewClose.setOnTouchListener((v, event) -> { layoutNewMessage.setVisibility(View.GONE); @@ -780,39 +492,31 @@ public class TabLayoutActivity extends AbstractSDParentActivity { 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); } +// 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; - } + + layoutMenu.setVisibility(isMenuVisible ? View.GONE : View.VISIBLE); + imageViewSlideMenu.setImageResource(isMenuVisible ? R.drawable.arrow_left : R.drawable.arrow_right); + isMenuVisible = !isMenuVisible; + }); + // got to tab - tabHost.setCurrentTabByTag(RADIO); + //tabHost.setCurrentTabByTag(RADIO); + tabHost.setCurrentTabByTag(LIVE); buttonLive.setSelected(true); - AppParams.crtTab = AppParams.Tabs.live; //start TCP timer @@ -831,10 +535,10 @@ public class TabLayoutActivity extends AbstractSDParentActivity { buttonRecordings.setVisibility(View.GONE); } - if (AppParams.DEMO && getLiveActivity() != null) { - getLiveActivity().vehiclesReceived(getAllVehicle()); - demoPositionsList(); - } +// if (AppParams.DEMO && getLiveActivity() != null) { +// getLiveActivity().vehiclesReceived(getAllVehicle()); +// demoPositionsList(); +// } if (!AppParams.DEMO) { Timer t = new Timer(); @@ -877,23 +581,20 @@ public class TabLayoutActivity extends AbstractSDParentActivity { } }; + 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 button + selectButton(buttonText); // select text tab tabHost.setCurrentTabByTag(TEXT); + // save text as current tab AppParams.crtTab = AppParams.Tabs.message; + Vehicle vehicle = getVehicle4Imei(getImei()); if (vehicle != null) getMessageActivity().setScId(vehicle.sc_id); @@ -907,18 +608,14 @@ public class TabLayoutActivity extends AbstractSDParentActivity { 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 + + // select Alarms button + selectButton(buttonAlarms); + // select Alarms tab tabHost.setCurrentTabByTag(ALARMS); + // save Alarms as current tab AppParams.crtTab = AppParams.Tabs.alarms; + // disable notification if (mNotificationManager != null) mNotificationManager.cancel(R.drawable.alert); @@ -926,18 +623,14 @@ public class TabLayoutActivity extends AbstractSDParentActivity { 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 Live button + selectButton(buttonLive); // select tab tabHost.setCurrentTabByTag(LIVE); + // save Live as current tab AppParams.crtTab = AppParams.Tabs.live; + // disable notification if (mNotificationManager != null) mNotificationManager.cancel(R.drawable.poll); @@ -1087,12 +780,462 @@ public class TabLayoutActivity extends AbstractSDParentActivity { getLiveActivity().refreshMap(); } + private void selectButton(ImageButton imageButton) { + + buttonText.setSelected(buttonText == imageButton); + buttonAlarms.setSelected(buttonAlarms == imageButton); + buttonLive.setSelected(buttonLive == imageButton); + buttonRadio.setSelected(buttonRadio == imageButton); + buttonRecordings.setSelected(buttonRecordings == imageButton); + buttonSetup.setSelected(buttonSetup == imageButton); + buttonHistory.setSelected(buttonHistory == imageButton); + + } + + private TabSpec[] populateTabs() + { + + Intent[] intent = new Intent[8]; + TabSpec[] tabSpecs = new TabSpec[8]; + + // add live tab + try { + intent[0] = new Intent(context, LiveActivity.class); + tabSpecs[0] = tabHost.newTabSpec(LIVE) + .setIndicator(LIVE, res.getDrawable(R.drawable.ic_tab_live_selected)) + .setContent(intent[0]); + } 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)) + .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)) + .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)) + .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)) + .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)) + .setContent(intent[4]); + + // add setup tab + intent[5] = new Intent(context, SetupActivity.class); + 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(ABOUT) + .setIndicator(ABOUT, res.getDrawable(AppParams.DEMO ? R.drawable.icon_demo : R.mipmap.ic_launcher)) + .setContent(intent[6]); + + // add history tab + try { + intent[7] = new Intent(context, HistoryActivity.class); + tabSpecs[7] = tabHost.newTabSpec(HISTORY) + .setIndicator(HISTORY, res.getDrawable(R.drawable.ic_tab_history_selected)) + .setContent(intent[7]); + } 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)) + .setContent(intent[1]); + } + + return tabSpecs; + } + + + private View.OnClickListener buttonLiveClickListener = new View.OnClickListener() { + + @Override + public void onClick(View v) { + + if (!buttonLive.isSelected()) { + // select Live button + selectButton(buttonLive); + // select tab + tabHost.setCurrentTabByTag(LIVE); + AppParams.crtTab = AppParams.Tabs.live; + } + } + }; + + + private View.OnClickListener buttonTextClickListener = new View.OnClickListener() { + + @Override + public void onClick(View v) { + + if (!buttonText.isSelected()) { + // select Text button + selectButton(buttonText); + // select TEXT tab + tabHost.setCurrentTabByTag(TEXT); + // save Text tab + AppParams.crtTab = AppParams.Tabs.message; + +// if (AppParams.DEMO && getMessageActivity().getAllVehicle().isEmpty()) { +// +// // select Text button +// selectButton(buttonText); +// // select TEXT tab +// tabHost.setCurrentTabByTag(TEXT); +// // save Text tab +// AppParams.crtTab = AppParams.Tabs.message; +// +// if (AppParams.DEMO && getMessageActivity().getAllVehicle().isEmpty()) { +// getMessageActivity().updateVehicles(getAllVehicle()); +// getMessageActivity().updateSMS(getDemoSmsList()); +// } +// } + } + } + }; + + + private View.OnClickListener buttonRecordingslickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + + if (!buttonRecordings.isSelected()) { + + // select Recordings button + selectButton(buttonRecordings); + // select tab + tabHost.setCurrentTabByTag(RECORDINGS); + AppParams.crtTab = AppParams.Tabs.recordings; + +// if (AppParams.DEMO) +// { +// if( getRecordingsActivity() != null && getRecordingsActivity().getAllRecordings() != null && getRecordingsActivity().getAllRecordings().isEmpty()) { +// +// ArrayList listRecordings = new ArrayList<>(); +// Recording rec = new Recording(); +// rec.userWhoWasCalled = "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.userWhoWasCalled = "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.userWhoWasCalled = "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); +// } +// } + } + } + }; + + + private View.OnClickListener buttonAlarmslickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + + if (!buttonAlarms.isSelected()) { + // select button + selectButton(buttonAlarms); + // select tab + tabHost.setCurrentTabByTag(ALARMS); + AppParams.crtTab = AppParams.Tabs.alarms; + +// if (AppParams.DEMO) { +// if (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); +// } +// } + } + + } +}; + + + private View.OnClickListener buttonHistoryClickListener = new View.OnClickListener() { + + @Override + public void onClick(View v) { + + if (!buttonHistory.isSelected()) { + + // select History button + selectButton(buttonHistory); + // select History tab + tabHost.setCurrentTabByTag(HISTORY); + // save History tab + AppParams.crtTab = AppParams.Tabs.history; + } + } + }; + + + private View.OnClickListener buttonRadioClickListener = new View.OnClickListener() { + + @Override + public void onClick(View v) { + + if (!buttonRadio.isSelected()) { + + // check audio permission + IPermissionModule permissionModule = new PermissionModule(); + AuthorizationStatus audioAuthorizationStatus = permissionModule.getAuthorizationStatus(activity, AuthorizationCode.RECORD_AUDIO); + if (audioAuthorizationStatus != AuthorizationStatus.AUTHORIZE) { + permissionModule.requestAuthorization(activity, AuthorizationCode.RECORD_AUDIO); + return; + } + + // select Radio button + selectButton(buttonRadio); + // select Radio tab + tabHost.setCurrentTabByTag(RADIO); + // save Radio tab + AppParams.crtTab = AppParams.Tabs.radio; + + RadioActivity radioActivity = getRadioActivity(); + if (radioActivity != null && radioActivity.allVehicle != null && radioActivity.allVehicle.isEmpty()) { + radioActivity.allVehicle = getAllVehicle(); + radioActivity.UpdateVehicle(); + } + } + + } + }; + + + private View.OnClickListener buttonRecordingsClickListener = new View.OnClickListener() { + + @Override + public void onClick(View v) { + + if (!buttonRecordings.isSelected()) { + + // select button + selectButton(buttonRecordings); + // select Recordings tab + tabHost.setCurrentTabByTag(RECORDINGS); + // save Recordings tab + AppParams.crtTab = AppParams.Tabs.recordings; + +// if (AppParams.DEMO) { +// +// if (getRecordingsActivity() != null && getRecordingsActivity().getAllRecordings() != null && getRecordingsActivity().getAllRecordings().isEmpty()) { +// +// ArrayList listRecordings = new ArrayList<>(); +// Recording rec = new Recording(); +// rec.userWhoWasCalled = "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.userWhoWasCalled = "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.userWhoWasCalled = "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); +// } +// } + } + } + }; + + + private View.OnClickListener buttonAlarmsClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + + if (!buttonAlarms.isSelected()) { + // select button + selectButton(buttonAlarms); + // select tab + tabHost.setCurrentTabByTag(ALARMS); + AppParams.crtTab = AppParams.Tabs.alarms; + +// if (AppParams.DEMO) { +// if (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); +// } +// } + } + } + }; + + + private View.OnClickListener buttonSetupClickListener = new View.OnClickListener(){ + + @Override + public void onClick(View v) { + if (!buttonSetup.isSelected()) { + + // select Setup button + selectButton(buttonSetup); + // select Setup tab + tabHost.setCurrentTabByTag(SETTINGS); + // save Setup tab + AppParams.crtTab = AppParams.Tabs.setup; + } + } + + }; + + + private View.OnClickListener buttonLogoClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + + // create dialog + final Dialog dialog = new Dialog(context); + dialog.setTitle(AppParams.DEMO ? getString(R.string.app_name_demo) : getString(R.string.app_name)); + dialog.setContentView(R.layout.dialog); + ImageView image = dialog.findViewById(R.id.image); + image.setImageResource(AppParams.DEMO ? R.drawable.icon_demo : R.mipmap.ic_launcher); + TextView text = dialog.findViewById(R.id.text); + TextView text2 = dialog.findViewById(R.id.text2); + 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(); + } + }; + private Runnable timerTick = new Runnable() { public void run() { //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)); @@ -1103,15 +1246,20 @@ public class TabLayoutActivity extends AbstractSDParentActivity { layoutNewMessage.setVisibility(View.VISIBLE); // hide close button imageViewClose.setVisibility(View.INVISIBLE); + try { if (lastTcpStatus) getRadioActivity().UpdateEnableDisableButtons("offline"); } catch (Exception ex) { SM.Debug(ex.toString()); } + + } else { + if (getAllVehicle().isEmpty()) new ConnectTask().execute(OperationCodes.GetVehicles + "", AppParams.USERID + ""); + if (getRadioActivity() != null && AppParams.listRadios.isEmpty()) new ConnectTask().execute(OperationCodes.GetRadiosList + ""); @@ -1229,12 +1377,12 @@ public class TabLayoutActivity extends AbstractSDParentActivity { SMSmsg sms = new SMSmsg(msg); SM.Debug("am primit lista cu primele SMSuri"); - //list for SMS + //list for text message tab if (AppParams.crtTab == AppParams.Tabs.message && getMessageActivity() != null) { getMessageActivity().updateSMS(sms.smsList); } } catch (Exception ex) { - SM.Debug("Error on smsReceived:" + ex); + SM.Debug("Error on smsReceived:" + ex.toString()); } } @@ -1243,9 +1391,12 @@ public class TabLayoutActivity extends AbstractSDParentActivity { VehMSG vMSG = new VehMSG(msg); SM.Debug("### Vehicle Received ###", "Received " + vMSG.vehList.size() + " vehicles"); - //list for live + // ============================= + // list for live tab + // ============================= 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); @@ -1256,15 +1407,19 @@ public class TabLayoutActivity extends AbstractSDParentActivity { } catch (Exception ex) { SM.Debug(HASH_ERROR_MESSAGE + ex); } + if (getLiveActivity() != null) getLiveActivity().vehiclesReceived(vMSG.vehList); + } else if (isFirstGetVehicles) { // set vehicles to liveActivity getLiveActivity().vehiclesReceived(vMSG.vehList); isFirstGetVehicles = false; } - //list for SMS + // ============================= + // list for text message tab + // ============================= if (AppParams.crtTab == AppParams.Tabs.message) { SM.Debug("currentActivity instanceof MessagesActivity"); if (getMessageActivity() != null) @@ -1422,6 +1577,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity { } catch (Exception ex) { SM.Debug(HASH_ERROR_MESSAGE + ex); } + runOnUiThread(new Runnable() { public void run() { DialogService dialogService = new DialogService(); @@ -1465,7 +1621,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity { 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)); + int all = Integer.parseInt(tmpHist.seqID.substring(tmpHist.seqID.indexOf('.') + 1, tmpHist.seqID.length())); if (all != 0) { if (Boolean.TRUE.equals(getFirstHistoryData())) { try { @@ -1531,6 +1687,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity { 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 @@ -1546,8 +1703,11 @@ public class TabLayoutActivity extends AbstractSDParentActivity { SM.Debug("Received from Apps -> UpdateZoneCH(" + radioMSG.zac.rgwID + "," + radioMSG.zac.gwID + "," + radioMSG.zac.zoneNr + "," + radioMSG.zac.channelNr + ")"); } - //list for SMS + // ============================= + // for radio tab + // ============================= if (AppParams.crtTab == AppParams.Tabs.radio) { + SM.Debug("#### RadioActivity"); // set crt activity to Radio setCrtActivity(RADIO_TAB_ID); @@ -1561,8 +1721,9 @@ public class TabLayoutActivity extends AbstractSDParentActivity { SM.Debug("Received from Apps -> UpdateRadios( count:" + radioMSG.RadioGWList.size() + ")"); } + // update status in the crtRadio List 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); @@ -1572,6 +1733,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity { 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 + ")"); @@ -1590,7 +1752,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity { if (getCrtRadio() != null) { setInCall(radioMSG.incCall.callStatus != 3); - getRadioActivity().UpdateBroadcastCall(radioMSG.incCall.Imei, radioMSG.incCall.callType, radioMSG.incCall.groupId, radioMSG.incCall.callStatus); } @@ -1614,6 +1775,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity { } if (getCrtRadio() != null) { + if (radioMSG.incCall.callStatus == 3) { setInCall(false); // update recordings list @@ -1623,17 +1785,21 @@ public class TabLayoutActivity extends AbstractSDParentActivity { } } else setInCall(true); + getRadioActivity().UpdateBroadcastCall(radioMSG.incCall.Imei, radioMSG.incCall.callType, radioMSG.incCall.groupId, radioMSG.incCall.callStatus); } } + // update radios if (radioMSG.RadioGWList != null && getRadioActivity() != null) getRadioActivity().UpdateRadios(radioMSG.RadioGWList); + // update zones if (radioMSG.zac != null && getRadioActivity() != null) { getRadioActivity().UpdateZoneCH(radioMSG.zac.rgwID, radioMSG.zac.gwID, radioMSG.zac.zoneNr, radioMSG.zac.channelNr); } + // update radio status if (radioMSG.rStatus != null && getRadioActivity() != null) { // update status in the allRadio List for (RadioGW radio : getAllRadios()) { @@ -1648,6 +1814,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity { // save RadioList if (radioMSG.RadioGWList != null) { + setAllRadios(radioMSG.RadioGWList); if (getCrtRadio() == null) { setCrtRadio(getAllRadios().get(0)); @@ -1659,6 +1826,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity { // 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); @@ -1681,6 +1849,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity { @Override public void alarmLiveReceived(TCPEvent event) { + TCPmsg msg = event.msg(); SM.Debug("Got alarmNew :" + msg.allData); @@ -1688,61 +1857,75 @@ public class TabLayoutActivity extends AbstractSDParentActivity { SM.Debug("Unit imei:" + tempArr[0]); String unitIMEI = tempArr[0]; - - // 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 140: - setMess("telemetry " + tempArr[1]); - break; - default: -// 138 - setMess("emergency"); + //============== + // alarms tab + //============== + if (AppParams.crtTab == AppParams.Tabs.alarms) { + SM.Debug("currentActivity instanceof AlarmActivity - newSMS | " + tempArr[0] + " | " + tempArr[1]); + getAlarms(AppParams.USERID); } - myHandler.post(updateResultsAlarm); - if ((msg.opCode == 138) && (AppParams.crtTab == AppParams.Tabs.live)) { - SuperVehicle superVehicle = getSuperVehHash().get(Long.parseLong(unitIMEI)); + // if tab is not TextTab + if (tabHost.getCurrentTab() != 5 /* Text tab */) { + // 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 (superVehicle != null) { - //if is not check i need to force check to put on the map - 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; - x++; - } - } else x = -1; - if (getLiveActivity() != null) { - if (x != getAllVehicle().size()) - getLiveActivity().emergencyAlarmReceived(x, superVehicle.lat, superVehicle.lng); - else - getLiveActivity().emergencyAlarmReceived(-1, superVehicle.lat, superVehicle.lng); + //============ + // live tab + //============ + + 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 (!superVehicle.needUpdate) { + superVehicle.needUpdate = true; + forceChecked = true; + } + + try { + int x = 0; + if (forceChecked) { + for (Vehicle veh : getAllVehicle()) { + if (veh.imei.compareTo(unitIMEI) == 0) break; + x++; + } + } else x = -1; + if (getLiveActivity() != null) { + if (x != getAllVehicle().size()) + getLiveActivity().emergencyAlarmReceived(x, superVehicle.lat, superVehicle.lng); + else + getLiveActivity().emergencyAlarmReceived(-1, superVehicle.lat, superVehicle.lng); + } + } catch (Exception ex) { + SM.Debug(HASH_ERROR_MESSAGE + ex); } - } catch (Exception ex) { - SM.Debug(HASH_ERROR_MESSAGE + ex); } } } - - //list for SMS - if (AppParams.crtTab == AppParams.Tabs.alarms) - getAlarms(AppParams.USERID); } @Override @@ -1751,9 +1934,11 @@ public class TabLayoutActivity extends AbstractSDParentActivity { RecordMSG recordMSG = new RecordMSG(msg); SM.Debug("am primit lista cu Recording"); - //list for SMS + //recordings tab if (AppParams.crtTab == AppParams.Tabs.recordings) { + for (Recording rec : recordMSG.getRecordList()) { + SuperVehicle superVehicle = getSuperVehHash().get((long) rec.subID); // set the name to be displayed switch (rec.callType) { @@ -1882,11 +2067,13 @@ public class TabLayoutActivity extends AbstractSDParentActivity { 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); @@ -1895,6 +2082,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity { if (animation.equals("realpha")) anim = AnimationUtils.loadAnimation(this, R.anim.realpha); anim.reset(); + layoutNewMessage.clearAnimation(); layoutNewMessage.startAnimation(anim); @@ -1932,15 +2120,16 @@ public class TabLayoutActivity extends AbstractSDParentActivity { 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); } +// 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); @@ -1967,19 +2156,20 @@ public class TabLayoutActivity extends AbstractSDParentActivity { 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); } +// 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); +// } // create Notification createNotification(AppParams.messageNotif); @@ -1987,7 +2177,10 @@ public class TabLayoutActivity extends AbstractSDParentActivity { public void createNotification(int icon) { mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - String contentTitle, contentText; + String tickerText = "SafeMobile Dispatch: New Message from " + getImei(); + String contentTitle = "New Message from " + getImei(); + String contentText = "\"" + getMess() + "\""; + Vehicle veh = getVehicle4Imei(getImei()); int iconValue = icon; @@ -2000,6 +2193,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity { 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: @@ -2008,81 +2202,54 @@ public class TabLayoutActivity extends AbstractSDParentActivity { vehName = getString(R.string.from) + ": " + getVehicle4Imei(getImei()).name; contentText = "\"" + getMess() + "\""; contentTitle = getString(R.string.newAlarm) + vehName; - icon = R.drawable.arrow_down; + 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 /* Notification */ - Intent intent = new Intent(this, NotificationActivity.class); - intent.putExtra("key", iconValue); + Intent notificationIntent = new Intent(this, NotificationActivity.class); + notificationIntent.putExtra("key", iconValue); // cancel old notification mNotificationManager.cancel(icon); - PendingIntent pendingIntent = PendingIntent.getActivity(context, NOTIFICATION_ACTIVITY_RESULT, intent, PendingIntent.FLAG_CANCEL_CURRENT); - createNotificationChannel(icon, contentTitle, contentText, pendingIntent); + PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ACTIVITY_RESULT, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); + + // flag that the notification will be closed when clicked + 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); } - private void createNotificationChannel(int icon, String title, String text, PendingIntent pendingIntent) { - // Create the NotificationChannel, but only on API 26+ because - // the NotificationChannel class is new and not in the support library - String notificationChannelID = String.valueOf(icon); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - CharSequence name = "Notification Channel"; - int importance = NotificationManager.IMPORTANCE_HIGH; - NotificationChannel channel = new NotificationChannel(notificationChannelID, name, importance); - // Register the channel with the system; you can't change the importance - // or other notification behaviors after this - NotificationManager notificationManager = getSystemService(NotificationManager.class); - notificationManager.createNotificationChannel(channel); - } - - - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, notificationChannelID) - .setSmallIcon(icon) - .setContentTitle(title) - .setContentText(text) - .setPriority(NotificationCompat.PRIORITY_DEFAULT) - .setAutoCancel(true) - .setContentIntent(pendingIntent); - - NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context); - managerCompat.notify(icon, builder.build()); - } - - // return vehicle according to imei private Vehicle getVehicle4Imei(String imei) { - Vehicle veh = null; + for (Vehicle vehicle : getAllVehicle()) if (vehicle.imei.equals(imei)) - veh = vehicle; - return veh; + return vehicle; + + return null; } @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); - } + public void enableMenuButtons(boolean enabled) { + + buttonAlarms.setEnabled(enabled); + buttonHistory.setEnabled(enabled); + buttonLive.setEnabled(enabled); + buttonRecordings.setEnabled(enabled); + buttonText.setEnabled(enabled); + buttonRadio.setEnabled(enabled); + buttonSetup.setEnabled(enabled); } // load settings @@ -2197,7 +2364,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity { 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); + SM.Exception("Paramas -> setVehicleStatus", "EXCeption ex " + ex.toString()); } break; @@ -2228,6 +2395,21 @@ public class TabLayoutActivity extends AbstractSDParentActivity { new ConnectTask().execute(params); } + public class ConnectParserTask extends AsyncTask { + @Override + protected TCPhandler doInBackground(String... params) { + if (myService != null) + tcpParser = myService.getTCPmsgParser(); + + // add TCPParserListener + if (tcpParser != null) { + SM.Debug("## tcpParser != null ", "#### call tcpParserListener("); + tcpParserListener(); + } + return null; + } + } + /* Display Toast messages*/ @Override public void displayToast(final String msg) { @@ -2337,8 +2519,10 @@ public class TabLayoutActivity extends AbstractSDParentActivity { super.onRequestPermissionsResult(requestCode, permissions, grantResults); SM.Debug("onRequestPermissionsResult", "[requestCode] " + requestCode); + String permission = ""; switch (requestCode) { case PermissionModule.RECORD_AUDIO_PERMISSION_REQUEST_CODE: + permission = Manifest.permission.RECORD_AUDIO; break; default: throw new IllegalStateException("Unexpected value: " + requestCode); @@ -2389,9 +2573,10 @@ public class TabLayoutActivity extends AbstractSDParentActivity { private void waitForUserInput(Boolean result) { if (result) { + final int requestCode = 1202; //navigate to application's settings String action = ProviderSettingsHelper.getAction(ProviderSettingsStatus.APPLICATION_DETAILS); - if (action == null || action.equals("")) + if (action == null || action == "") return; boolean isActionApplicationDetailsSettings = action.equals(ProviderSettingsHelper.ACTION_APPLICATION_DETAILS_SETTINGS); diff --git a/safeDispatch/src/main/res/layout/main.xml b/safeDispatch/src/main/res/layout/main.xml index 8a7bf95..cd848c7 100644 --- a/safeDispatch/src/main/res/layout/main.xml +++ b/safeDispatch/src/main/res/layout/main.xml @@ -150,18 +150,18 @@ android:enabled="true" android:textColor="#000000" android:layout_marginBottom="5sp" /> - - + +