package com.safemobile.safedispatch; import android.app.Activity; import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; import android.graphics.Typeface; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; import android.widget.TextView; import com.safemobile.lib.AppParams; import com.safemobile.lib.OperationCodes; import com.safemobile.lib.SM; import com.safemobile.lib.Vehicle; import com.safemobile.lib.radio.Channel; import com.safemobile.lib.radio.RadioGW; import com.safemobile.lib.radio.Zone; import com.safemobile.lib.radio.Zone_and_channel; import com.safemobile.lib.sound.AudioHandle; import java.util.ArrayList; import java.util.Locale; /** * fix import */ public class RadioActivity extends Activity { /* Visual Elements */ private Button buttonPTT, buttonDKey; private RadioGroup radioGroupCallType; private RadioButton radioAll, radioGroup, radioPrivate; 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; private int calltype = 0; private int groupid = 0; private int callstatus = 0; /* Lists */ private ArrayList allVehicleNames = new ArrayList<>(); public ArrayList allVehicle = new ArrayList<>(); private final ArrayList allGroupsIDs = new ArrayList<>(); private final ArrayList allGroupsNames = new ArrayList<>(); private ArrayList crtZones = new ArrayList<>(); private ArrayList crtChannels = new ArrayList<>(); private final 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; private final int inCall = 1, hangTime = 2, callEnd = 3; private Bundle savedInstanceState; /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.savedInstanceState = savedInstanceState; // get parentTab parentTab = (TabLayoutActivity)getParent(); Locale locale = new Locale(AppParams.LANGUAGETMP); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); setContentView(R.layout.tabradio); // get context context = this; activity = this; allGroupsNames.add("1"); allGroupsNames.add("2"); allGroupsIDs.add(1); allGroupsIDs.add(2); //==================== // get visual elements //==================== // get buttons buttonPTT = findViewById(R.id.buttonPTT); buttonDKey = findViewById(R.id.buttonDKey); // get CallType Spinner layoutSpinnerCallType = findViewById(R.id.layoutSpinnerCallType); layoutSpinnerCallType.setOnClickListener(CallTypeListener); textViewCallType = findViewById(R.id.textViewCallType); // get status dot imageViewStatus = findViewById(R.id.imageViewStatus); layoutSpinnerChannel = findViewById(R.id.layoutSpinnerChannel); layoutSpinnerChannel.setOnClickListener(ChannelChangeListener); layoutSpinnerZone = findViewById(R.id.layoutSpinnerZone); layoutSpinnerZone.setOnClickListener(ZoneChangeListener); // get TextView from Spinner textViewChannel = findViewById(R.id.textViewChannel); textViewZone = findViewById(R.id.textViewZone); // get IP textViewIP = findViewById(R.id.textViewIP); textViewIP.setText(AppParams.IP); // get CallType radioGroupCallType = findViewById(R.id.radioGroupCallType); radioGroupCallType.setOnCheckedChangeListener(CallTypeChanged); // get radio buttons radioAll = findViewById(R.id.radioAll); radioGroup = findViewById(R.id.radioGroup); radioPrivate = findViewById(R.id.radioPrivate); // get channel textViewMessageChannel = findViewById(R.id.textViewMessageChannel); // get gateway textViewGateway = findViewById(R.id.textViewGateway); textViewGateway.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf")); textViewGateway.setTextSize(24); // get status textViewMessageStatus = findViewById(R.id.textViewMessageStatus); layoutGateway = findViewById(R.id.layoutGateway); layoutGateway.setOnClickListener(GatwayListener); // set button ptt listener buttonPTT.setOnClickListener(PTTClickListener); // set button DKey listener buttonDKey.setOnClickListener(DKeyClickListener); startAudioThread(); if(!AppParams.DEMO) UpdateEnableDisableButtons("offline"); // send current activity to parent parentTab.setRadioActivity(this); // register to be notified when an event is triggered registerBroadcastIntents(); } public Bundle getSavedInstanceState() { return savedInstanceState; } private void startAudioThread() { audioThread = new Thread(() -> { //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() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(getString(R.string.exit)) .setCancelable(false) .setNeutralButton(getString(R.string.logout), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.logout)) .setPositiveButton(getString(R.string.ext), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.exit)) .setNegativeButton(getString(R.string.cancel), (dialog, id) -> dialog.cancel()); AlertDialog alert = builder.create(); alert.show(); } @Override public void onPause() { super.onPause(); SM.Debug("onPause"); } @Override public void onResume() { super.onResume(); // get all vehicles from TabLayoutActivity if (!allVehicle.equals(parentTab.getAllVehicle())) { allVehicle = parentTab.getAllVehicle(); UpdateVehicle(); } if (AppParams.listRadios.size() == 0) GetGWRadios(); SM.Debug("onResume"); } private final OnClickListener GatwayListener = new OnClickListener() { @Override public void onClick(View v) { 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, (dialog, 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 final OnClickListener PTTClickListener = v -> { if (pttONoff) pttOffClick(); else pttOnClick(); }; private void pttOnClick() { //================ // 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 = 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 final OnClickListener DKeyClickListener = v -> SendDekey(); private final OnClickListener ChannelChangeListener = new OnClickListener() { @Override public void onClick(View v) { 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); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getString(R.string.selChannel)); builder.setAdapter(adapter , (dialog, 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(); } } }; private final 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); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getString(R.string.selZone)); builder.setAdapter(adapter , (dialog, which) -> { // send change to App onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, getNR4Zone(crtZones.get(which).ZoneName), 1); }); AlertDialog alert = builder.create(); alert.show(); } } }; private final OnClickListener CallTypeListener = new OnClickListener() { @Override public void onClick(View v) { if (parentTab.getCrtRadio() != null) { // 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 , (dialog, 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 final OnCheckedChangeListener CallTypeChanged = new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch(radioGroupCallType.getCheckedRadioButtonId()) { case R.id.radioAll : layoutSpinnerCallType.setVisibility(View.INVISIBLE); selectedCallType = ALLCall; break; case R.id.radioGroup : layoutSpinnerCallType.setVisibility(View.VISIBLE); textViewCallType.setText(allGroupsNames.get(0)); selectedCallType = GROUPCall; break; case R.id.radioPrivate : layoutSpinnerCallType.setVisibility(View.VISIBLE); if (allVehicleNames.size() > 0) textViewCallType.setText(allVehicleNames.get(0)); else textViewCallType.setText(""); selectedCallType = PRIVATECall; break; } } }; // called from ParentTabActivity public void UpdateRadios(ArrayList radios) { // save radios 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); } // Create runnable for posting final Runnable updateGatewaysRUN = this::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) 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) { // save received id's zoneNr and CHNR this.radioID = _radioID; this.GWID = _gwID; this.zoneNR = _zoneNR; this.chNR = _chNR; 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 = this::updateResultsInUi; private void updateResultsInUi() { 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)); // 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)); } 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++) { Zone zone = crtZones.get(i); zones.add(zone.ZoneName); if (zone.id == zoneNR) position = i; // save crt position in array } textViewZone.setText(zones.get(position)); // set channel ArrayList channel = new ArrayList<>(); crtChannels = parentTab.getCrtRadio().zoneList.get(position).channelList; // 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; } textViewChannel.setText(channel.get(position)); textViewMessageChannel.setText(channel.get(position)); } UpdateEnableDisableButtons("online"); imageViewStatus.setImageResource(R.drawable.status_online); } } // Radio Gateway changed from UI private void radioGWChanged(String newIP) { // get gateway id for (RadioGW radio:AppParams.listRadios) if (radio.IP.equals(newIP)) { UpdateEnableDisableButtons("offline"); 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(""); } 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) { // save received id's zoneNr and CHNR SM.Debug("Status: Imei: " + Imei+ " Calltype: "+Calltype+ " GroupID: "+GroupID+" CallStatus:"+CallStatus); this.imei = Imei; this.calltype = Calltype; this.groupid = GroupID; this.callstatus = CallStatus; myHandler.post(UpdateB); } final Runnable UpdateB = this::UpdateResultsBroadcastCall; private void UpdateResultsBroadcastCall() { SM.Debug("UpdateResultsBroadcastCall with Imei: " +imei+ " CallType:"+calltype+ " GroupID:"+groupid+" CallStatus:"+callstatus); if ((callstatus == inCall) || (callstatus== hangTime)) { // modify UI only when call is received, not in hangtime if (callstatus == inCall) { layoutGateway.setEnabled(false); String CallType = getString(R.string.AllCall); if (calltype == PRIVATECall) { CallType = getString(R.string.PrivateCall); SetCheck(radioPrivate); selectedCallType = PRIVATECall; } else if (calltype == GROUPCall) { CallType = getString(R.string.GroupCall) + "("+groupid+")"; SetCheck(radioGroup); selectedCallType = GROUPCall; textViewCallType.setText(groupid + ""); } else { SetCheck(radioAll); selectedCallType = ALLCall; } layoutSpinnerCallType.setVisibility( calltype != ALLCall ? View.VISIBLE : View.INVISIBLE); textViewMessageChannel.setText(CallType); if (parentTab.getSuperVehHash() != null) { if (parentTab.getSuperVehHash().containsKey(imei)) textViewMessageStatus.setText(parentTab.getSuperVehHash().get(imei).name); else textViewMessageStatus.setText("Imei: " + imei); } } if (callstatus == hangTime) { textViewMessageStatus.setText(getString(R.string.hangTime)); 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 == callEnd ) { if ((calltype == 0 && pttONoff) || selectedCallType == calltype) { layoutGateway.setEnabled(true); 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.setBackgroundResource(R.drawable.style_buttonptt); } parentTab.enableMenuButtons(true); 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 = this::updateResultsStatus; private void updateResultsStatus() { 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"); } 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")) { enableDisableRadioCallType(false); enableDisableSpinners(false); // enable Dkey button buttonDKey.setEnabled(true); // disable PTT buttonPTT.setEnabled(false); } else if (type.equals("disablePTT")) { enableDisableRadioCallType(false); enableDisableSpinners(false); // disable Dkey button buttonDKey.setEnabled(false); } else if (type.equals("enable")) { enableDisableRadioCallType(true); enableDisableSpinners(true); // disable Dkey button and enable PTT buttonDKey.setEnabled(false); buttonPTT.setEnabled(true); } else if(type.equals("online")) { enableDisableRadioCallType(true); enableDisableSpinners(true); // disable Dkey button buttonDKey.setEnabled(false); buttonPTT.setEnabled(true); textViewMessageStatus.setText(""); 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 // 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 if (groupName.equals(name)) return allGroupsIDs.get(i); i++; } return -1; } // get Private Contact ID from Name private int getPrivateImei4Name(String name) { for (Vehicle vehicle: allVehicle) { if (vehicle.name.equals(name)) return Integer.parseInt(vehicle.imei); } return -1; } // get zone number from spinner zoneName private int getNR4Zone(String zoneName) { for (Zone zone: crtZones) if (zone.ZoneName.equals(zoneName)) return zone.id; return -1; } // get channel number from spinner chName private int getNR4CH(String chName) { for (Channel ch: crtChannels) if (ch.chName.equals(chName)) 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) { SM.Debug("Request radio status 4 radioId: " + RadioID + " | GW_ID:" + GWID); parentTab.getRadioStatus(GWID,RadioID); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } //sendPTT //callType: //101 -allcall init //111 -allcall stop //102 -prvcall init //112 -prvcall stop //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 + ""); this.registerReceiver(mReceiver, intentFilter); 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) { final String action = intent.getAction(); // CHANNEL_BRDCST if (action.equals(OperationCodes.CHANNEL_BRDCST + "")) { Zone_and_channel zc = AppParams.crtZoneAndChannel; UpdateZoneCH(zc.rgwID, zc.gwID, zc.zoneNr, zc.channelNr); } // 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); } } }; }