2022-03-24 09:18:49 +00:00
|
|
|
package com.safemobile.safedispatch;
|
2022-03-10 14:31:03 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-03-14 09:53:00 +00:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
public class RadioActivity extends Activity {
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
/* 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;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
/* Misc */
|
|
|
|
private TabLayoutActivity parentTab;
|
|
|
|
private Context context;
|
|
|
|
private Activity activity;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
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 */
|
2022-05-03 07:44:37 +00:00
|
|
|
private ArrayList<String> allVehicleNames = new ArrayList<>();
|
|
|
|
public ArrayList<Vehicle> allVehicle = new ArrayList<>();
|
2022-03-10 14:31:03 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private final ArrayList<Integer> allGroupsIDs = new ArrayList<>();
|
|
|
|
private final ArrayList<String> allGroupsNames = new ArrayList<>();
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private ArrayList<Zone> crtZones = new ArrayList<>();
|
|
|
|
private ArrayList<Channel> crtChannels = new ArrayList<>();
|
|
|
|
private final ArrayList<String> allGWsIP = new ArrayList<>();
|
2022-03-10 14:31:03 +00:00
|
|
|
private ArrayAdapter<String> adapter;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// Need handler for callbacks to the UI thread
|
|
|
|
private final Handler myHandler = new Handler();
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
public Thread audioThread;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
//PTT
|
|
|
|
private AudioHandle audioH = null;
|
|
|
|
private final int ALLCall = 101, PRIVATECall = 102, GROUPCall = 103;
|
|
|
|
private int selectedID=0, selectedCallType = 101;
|
2022-05-03 07:44:37 +00:00
|
|
|
private Boolean pttONoff = false;
|
2022-04-08 14:54:45 +00:00
|
|
|
private final int inCall = 1, hangTime = 2, callEnd = 3;
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private Bundle savedInstanceState;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
/** Called when the activity is first created. */
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
this.savedInstanceState = savedInstanceState;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
// get parentTab
|
2022-03-10 14:31:03 +00:00
|
|
|
parentTab = (TabLayoutActivity)getParent();
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
Locale locale = new Locale(AppParams.LANGUAGETMP);
|
|
|
|
Locale.setDefault(locale);
|
|
|
|
Configuration config = new Configuration();
|
|
|
|
config.locale = locale;
|
2022-03-14 09:53:00 +00:00
|
|
|
getBaseContext().getResources().updateConfiguration(config,
|
2022-03-10 14:31:03 +00:00
|
|
|
getBaseContext().getResources().getDisplayMetrics());
|
2022-03-14 09:53:00 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
setContentView(R.layout.tabradio);
|
|
|
|
// get context
|
|
|
|
context = this;
|
|
|
|
activity = this;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
allGroupsNames.add("1");
|
|
|
|
allGroupsNames.add("2");
|
|
|
|
allGroupsIDs.add(1);
|
|
|
|
allGroupsIDs.add(2);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
//====================
|
2022-03-10 14:31:03 +00:00
|
|
|
// get visual elements
|
2022-04-08 14:54:45 +00:00
|
|
|
//====================
|
|
|
|
|
|
|
|
// get buttons
|
2022-05-03 07:44:37 +00:00
|
|
|
buttonPTT = findViewById(R.id.buttonPTT);
|
|
|
|
buttonDKey = findViewById(R.id.buttonDKey);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get CallType Spinner
|
2022-05-03 07:44:37 +00:00
|
|
|
layoutSpinnerCallType = findViewById(R.id.layoutSpinnerCallType);
|
2022-03-10 14:31:03 +00:00
|
|
|
layoutSpinnerCallType.setOnClickListener(CallTypeListener);
|
2022-05-03 07:44:37 +00:00
|
|
|
textViewCallType = findViewById(R.id.textViewCallType);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get status dot
|
2022-05-03 07:44:37 +00:00
|
|
|
imageViewStatus = findViewById(R.id.imageViewStatus);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
layoutSpinnerChannel = findViewById(R.id.layoutSpinnerChannel);
|
2022-03-10 14:31:03 +00:00
|
|
|
layoutSpinnerChannel.setOnClickListener(ChannelChangeListener);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
layoutSpinnerZone = findViewById(R.id.layoutSpinnerZone);
|
2022-03-10 14:31:03 +00:00
|
|
|
layoutSpinnerZone.setOnClickListener(ZoneChangeListener);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get TextView from Spinner
|
2022-05-03 07:44:37 +00:00
|
|
|
textViewChannel = findViewById(R.id.textViewChannel);
|
|
|
|
textViewZone = findViewById(R.id.textViewZone);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
// get IP
|
2022-05-03 07:44:37 +00:00
|
|
|
textViewIP = findViewById(R.id.textViewIP);
|
2022-03-10 14:31:03 +00:00
|
|
|
textViewIP.setText(AppParams.IP);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get CallType
|
2022-05-03 07:44:37 +00:00
|
|
|
radioGroupCallType = findViewById(R.id.radioGroupCallType);
|
2022-03-10 14:31:03 +00:00
|
|
|
radioGroupCallType.setOnCheckedChangeListener(CallTypeChanged);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
// get radio buttons
|
2022-05-03 07:44:37 +00:00
|
|
|
radioAll = findViewById(R.id.radioAll);
|
|
|
|
radioGroup = findViewById(R.id.radioGroup);
|
|
|
|
radioPrivate = findViewById(R.id.radioPrivate);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
// get channel
|
2022-05-03 07:44:37 +00:00
|
|
|
textViewMessageChannel = findViewById(R.id.textViewMessageChannel);
|
2022-04-08 14:54:45 +00:00
|
|
|
// get gateway
|
2022-05-03 07:44:37 +00:00
|
|
|
textViewGateway = findViewById(R.id.textViewGateway);
|
2022-03-10 14:31:03 +00:00
|
|
|
textViewGateway.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
|
|
|
|
textViewGateway.setTextSize(24);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
// get status
|
2022-05-03 07:44:37 +00:00
|
|
|
textViewMessageStatus = findViewById(R.id.textViewMessageStatus);
|
|
|
|
layoutGateway = findViewById(R.id.layoutGateway);
|
2022-04-08 14:54:45 +00:00
|
|
|
layoutGateway.setOnClickListener(GatwayListener);
|
|
|
|
|
|
|
|
// set button ptt listener
|
2022-03-10 14:31:03 +00:00
|
|
|
buttonPTT.setOnClickListener(PTTClickListener);
|
2022-04-08 14:54:45 +00:00
|
|
|
// set button DKey listener
|
2022-03-10 14:31:03 +00:00
|
|
|
buttonDKey.setOnClickListener(DKeyClickListener);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
startAudioThread();
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
if(!AppParams.DEMO)
|
|
|
|
UpdateEnableDisableButtons("offline");
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
// send current activity to parent
|
2022-03-23 11:07:40 +00:00
|
|
|
parentTab.setRadioActivity(this);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// register to be notified when an event is triggered
|
|
|
|
registerBroadcastIntents();
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
public Bundle getSavedInstanceState() {
|
|
|
|
return savedInstanceState;
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
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());
|
2022-04-08 14:54:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
audioThread.start();
|
|
|
|
}
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
@Override
|
2022-05-03 07:44:37 +00:00
|
|
|
public void onBackPressed() {
|
2022-03-10 14:31:03 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setMessage(getString(R.string.exit))
|
|
|
|
.setCancelable(false)
|
2022-05-03 07:44:37 +00:00
|
|
|
.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());
|
2022-03-10 14:31:03 +00:00
|
|
|
AlertDialog alert = builder.create();
|
|
|
|
alert.show();
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
@Override
|
2022-05-03 07:44:37 +00:00
|
|
|
public void onPause() {
|
2022-03-10 14:31:03 +00:00
|
|
|
super.onPause();
|
|
|
|
SM.Debug("onPause");
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
@Override
|
2022-05-03 07:44:37 +00:00
|
|
|
public void onResume() {
|
2022-03-10 14:31:03 +00:00
|
|
|
super.onResume();
|
|
|
|
// get all vehicles from TabLayoutActivity
|
2022-05-03 07:44:37 +00:00
|
|
|
if (!allVehicle.equals(parentTab.getAllVehicle())) {
|
2022-03-15 13:51:30 +00:00
|
|
|
allVehicle = parentTab.getAllVehicle();
|
2022-04-08 14:54:45 +00:00
|
|
|
UpdateVehicle();
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
if (AppParams.listRadios.size() == 0)
|
2022-03-10 14:31:03 +00:00
|
|
|
GetGWRadios();
|
|
|
|
SM.Debug("onResume");
|
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private final OnClickListener GatwayListener = new OnClickListener() {
|
2022-04-08 14:54:45 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2022-05-03 07:44:37 +00:00
|
|
|
adapter = new ArrayAdapter<>(
|
2022-04-08 14:54:45 +00:00
|
|
|
context, R.layout.template_simple_list_item,
|
|
|
|
allGWsIP);
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
builder.setTitle("Select RadioGW");
|
|
|
|
builder.setAdapter(adapter,
|
2022-05-03 07:44:37 +00:00
|
|
|
(dialog, which) -> {
|
|
|
|
// change gateway
|
|
|
|
//textViewGateway.setText(allGWsIP.get(which));
|
|
|
|
// change visual if selected another radioGW
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
radioGWChanged(allGWsIP.get(which));
|
2022-04-08 14:54:45 +00:00
|
|
|
});
|
|
|
|
AlertDialog alert = builder.create();
|
|
|
|
alert.show();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private final OnClickListener PTTClickListener = v -> {
|
|
|
|
if (pttONoff)
|
|
|
|
pttOffClick();
|
|
|
|
else
|
|
|
|
pttOnClick();
|
2022-03-10 14:31:03 +00:00
|
|
|
};
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private void pttOnClick() {
|
2022-04-08 14:54:45 +00:00
|
|
|
//================
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private void pttOffClick() {
|
|
|
|
String chanMsg, statMsg = "";
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
// 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)
|
2022-03-10 14:31:03 +00:00
|
|
|
audioH.soundNeeded = false;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
buttonPTT.setText(getString(R.string.PTT));
|
2022-03-14 09:53:00 +00:00
|
|
|
buttonPTT.setBackgroundResource(R.drawable.style_buttonptt);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
chanMsg = textViewChannel.getText().toString();
|
|
|
|
textViewMessageChannel.setText(chanMsg);
|
|
|
|
textViewMessageStatus.setText(statMsg);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// change status image
|
|
|
|
imageViewStatus.setImageResource(R.drawable.status_online);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// enable buttons
|
|
|
|
UpdateEnableDisableButtons("enable");
|
|
|
|
parentTab.enableMenuButtons(true);
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private final OnClickListener DKeyClickListener = v -> SendDekey();
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private final OnClickListener ChannelChangeListener = new OnClickListener() {
|
2022-03-10 14:31:03 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2022-05-03 07:44:37 +00:00
|
|
|
if (parentTab.getCrtRadio() != null) {
|
2022-03-10 14:31:03 +00:00
|
|
|
// display dialog with adapter
|
2022-05-03 07:44:37 +00:00
|
|
|
ArrayList<String> tmp = new ArrayList<>();
|
2022-03-10 14:31:03 +00:00
|
|
|
for(Channel ch: crtChannels)
|
|
|
|
tmp.add(ch.chName);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, R.layout.template_simple_list_item, tmp);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
builder.setTitle(getString(R.string.selChannel));
|
2022-05-03 07:44:37 +00:00
|
|
|
builder.setAdapter(adapter , (dialog, which) -> {
|
|
|
|
// change Channel in Display
|
|
|
|
//textViewMessageChannel.setText(crtChannels.get(which).chName);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
// set channel name
|
|
|
|
//textViewChannel.setText(crtChannels.get(which).chName);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
// send change to App
|
|
|
|
onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, getNR4Zone(textViewZone.getText().toString()), getNR4CH(crtChannels.get(which).chName));
|
2022-03-10 14:31:03 +00:00
|
|
|
});
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
AlertDialog alert = builder.create();
|
|
|
|
alert.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private final OnClickListener ZoneChangeListener = new OnClickListener() {
|
2022-03-10 14:31:03 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2022-05-03 07:44:37 +00:00
|
|
|
if (parentTab.getCrtRadio() !=null) {
|
2022-03-10 14:31:03 +00:00
|
|
|
// display dialog with adapter
|
2022-05-03 07:44:37 +00:00
|
|
|
ArrayList<String> tmp = new ArrayList<>();
|
2022-03-10 14:31:03 +00:00
|
|
|
for(Zone zone: crtZones)
|
|
|
|
tmp.add(zone.ZoneName);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, R.layout.template_simple_list_item, tmp);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
|
|
builder.setTitle(getString(R.string.selZone));
|
2022-05-03 07:44:37 +00:00
|
|
|
builder.setAdapter(adapter , (dialog, which) -> {
|
|
|
|
// send change to App
|
|
|
|
onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, getNR4Zone(crtZones.get(which).ZoneName), 1);
|
2022-03-10 14:31:03 +00:00
|
|
|
});
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
AlertDialog alert = builder.create();
|
|
|
|
alert.show();
|
|
|
|
}
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
};
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private final OnClickListener CallTypeListener = new OnClickListener() {
|
2022-03-10 14:31:03 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2022-05-03 07:44:37 +00:00
|
|
|
if (parentTab.getCrtRadio() != null) {
|
2022-03-10 14:31:03 +00:00
|
|
|
// create spinner selected
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
2022-05-03 07:44:37 +00:00
|
|
|
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;
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
builder.setAdapter(adapter , (dialog, which) -> {
|
|
|
|
switch(radioGroupCallType.getCheckedRadioButtonId()) {
|
2022-04-08 14:54:45 +00:00
|
|
|
case R.id.radioGroup :
|
2022-03-10 14:31:03 +00:00
|
|
|
// set adapter and title
|
|
|
|
textViewCallType.setText(allGroupsNames.get(which));
|
|
|
|
break;
|
2022-04-08 14:54:45 +00:00
|
|
|
case R.id.radioPrivate :
|
2022-03-10 14:31:03 +00:00
|
|
|
textViewCallType.setText(allVehicleNames.get(which));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
AlertDialog alert = builder.create();
|
|
|
|
alert.show();
|
|
|
|
}
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
};
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private final OnCheckedChangeListener CallTypeChanged = new OnCheckedChangeListener() {
|
2022-03-10 14:31:03 +00:00
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
2022-05-03 07:44:37 +00:00
|
|
|
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("");
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
selectedCallType = PRIVATECall;
|
|
|
|
break;
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// called from ParentTabActivity
|
2022-05-03 07:44:37 +00:00
|
|
|
public void UpdateRadios(ArrayList<RadioGW> radios) {
|
2022-03-10 14:31:03 +00:00
|
|
|
// save radios
|
|
|
|
AppParams.listRadios = radios;
|
2022-03-23 11:07:40 +00:00
|
|
|
if(parentTab.getCrtRadio() == null)
|
|
|
|
parentTab.setCrtRadio(AppParams.listRadios.get(0));
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// if crtRadio not exists anymore
|
2022-03-23 11:07:40 +00:00
|
|
|
if(!AppParams.listRadios.contains(parentTab.getCrtRadio()))
|
|
|
|
parentTab.setCrtRadio(AppParams.listRadios.get(0));
|
2022-03-10 14:31:03 +00:00
|
|
|
|
2022-03-23 11:07:40 +00:00
|
|
|
SM.Debug(parentTab.getCrtRadio().toString());
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get status for selected Radio
|
2022-03-23 11:07:40 +00:00
|
|
|
ReqRadioStatus(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID);
|
2022-03-10 14:31:03 +00:00
|
|
|
// get selected Zone and CH
|
2022-03-23 11:07:40 +00:00
|
|
|
onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, 0,0);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
myHandler.post(updateGatewaysRUN);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create runnable for posting
|
2022-05-03 07:44:37 +00:00
|
|
|
final Runnable updateGatewaysRUN = this::updateGateways;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
public void updateGateways() {
|
2022-03-10 14:31:03 +00:00
|
|
|
// get all radio IP
|
|
|
|
allGWsIP.clear();
|
2022-05-03 07:44:37 +00:00
|
|
|
for (RadioGW radio: AppParams.listRadios)
|
2022-03-10 14:31:03 +00:00
|
|
|
allGWsIP.add(radio.IP);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-23 11:07:40 +00:00
|
|
|
textViewGateway.setText(parentTab.getCrtRadio().IP);
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// modify privateCall Adapter after resume if Vehicle List Modified
|
2022-05-03 07:44:37 +00:00
|
|
|
public void UpdateVehicle() {
|
|
|
|
allVehicleNames = new ArrayList<>();
|
|
|
|
if (allVehicle!=null)
|
2022-03-10 14:31:03 +00:00
|
|
|
for(Vehicle vehicle: allVehicle)
|
|
|
|
allVehicleNames.add(vehicle.name);
|
2022-04-08 14:54:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private RadioGW getRadioGW(int _radioID, int _gwID) {
|
|
|
|
for (RadioGW radio: AppParams.listRadios) {
|
2022-04-08 14:54:45 +00:00
|
|
|
if (radio.GW_ID == _gwID && radio.ID == _radioID)
|
|
|
|
return radio;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private ArrayList<Channel> getChannels(int zoneNR) {
|
2022-04-08 14:54:45 +00:00
|
|
|
for(Zone zone : parentTab.getCrtRadio().zoneList) {
|
|
|
|
if (zone.id == zoneNR)
|
|
|
|
return zone.channelList;
|
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
return new ArrayList<>();
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// called from ParentTabActivity to set radioID, GWID, zoneNR and chNR
|
2022-05-03 07:44:37 +00:00
|
|
|
public void UpdateZoneCH(int _radioID, int _gwID, int _zoneNR, int _chNR) {
|
2022-03-10 14:31:03 +00:00
|
|
|
// save received id's zoneNr and CHNR
|
|
|
|
this.radioID = _radioID;
|
2022-04-08 14:54:45 +00:00
|
|
|
this.GWID = _gwID;
|
2022-03-10 14:31:03 +00:00
|
|
|
this.zoneNR = _zoneNR;
|
|
|
|
this.chNR = _chNR;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
SM.Debug("am primit: " + _radioID + "," + _gwID + "," + _zoneNR + "," + _chNR);
|
|
|
|
|
|
|
|
// get RadioGw
|
|
|
|
RadioGW radioGW = getRadioGW(_radioID, _gwID);
|
2022-05-03 07:44:37 +00:00
|
|
|
if (radioGW == null)
|
2022-04-08 14:54:45 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// set current radio
|
|
|
|
parentTab.setCrtRadio(radioGW);
|
|
|
|
// set current zones
|
|
|
|
crtZones = radioGW.zoneList;
|
|
|
|
// set current channels
|
|
|
|
crtChannels = getChannels(_zoneNR);
|
|
|
|
|
|
|
|
myHandler.post(UpdateResultsZoneChannelRUN);
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// Create runnable for posting
|
2022-05-03 07:44:37 +00:00
|
|
|
final Runnable UpdateResultsZoneChannelRUN = this::updateResultsInUi;
|
2022-03-10 14:31:03 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private void updateResultsInUi() {
|
|
|
|
if (AppParams.listRadios.size() > 0) {
|
2022-03-23 11:07:40 +00:00
|
|
|
textViewGateway.setText(parentTab.getCrtRadio().IP);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get all radio IP
|
|
|
|
allGWsIP.clear();
|
2022-05-03 07:44:37 +00:00
|
|
|
for (RadioGW radio: AppParams.listRadios)
|
2022-03-10 14:31:03 +00:00
|
|
|
allGWsIP.add(radio.IP);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// set spinners and text
|
2022-05-03 07:44:37 +00:00
|
|
|
if (parentTab.getCrtRadio() == null) {
|
2022-03-23 11:07:40 +00:00
|
|
|
parentTab.setCrtRadio(AppParams.listRadios.get(0));
|
2022-03-10 14:31:03 +00:00
|
|
|
textViewGateway.setText(allGWsIP.get(0));
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// set zone
|
2022-05-03 07:44:37 +00:00
|
|
|
ArrayList<String> zones = new ArrayList<>();
|
2022-03-23 11:07:40 +00:00
|
|
|
crtZones = parentTab.getCrtRadio().zoneList;
|
2022-03-10 14:31:03 +00:00
|
|
|
for(Zone zone: crtZones)
|
|
|
|
zones.add(zone.ZoneName);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
textViewZone.setText(zones.get(0));
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// set channel
|
2022-05-03 07:44:37 +00:00
|
|
|
ArrayList<String> channel = new ArrayList<>();
|
2022-03-23 11:07:40 +00:00
|
|
|
crtChannels = parentTab.getCrtRadio().zoneList.get(0).channelList;
|
2022-03-10 14:31:03 +00:00
|
|
|
for(Channel ch: crtChannels)
|
|
|
|
channel.add(ch.chName);
|
2022-05-03 07:44:37 +00:00
|
|
|
textViewChannel.setText(channel.get(0));
|
|
|
|
} else {
|
|
|
|
for (RadioGW radio: AppParams.listRadios)
|
|
|
|
if (radio.ID == radioID && radio.GW_ID == GWID)
|
2022-03-23 11:07:40 +00:00
|
|
|
parentTab.setCrtRadio(radio);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get zones for adapter
|
2022-05-03 07:44:37 +00:00
|
|
|
ArrayList<String> zones = new ArrayList<>();
|
2022-03-23 11:07:40 +00:00
|
|
|
crtZones = parentTab.getCrtRadio().zoneList;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
int position = 0;
|
|
|
|
// get selected Zone
|
2022-05-03 07:44:37 +00:00
|
|
|
for (int i=0; i< crtZones.size(); i++) {
|
2022-03-10 14:31:03 +00:00
|
|
|
Zone zone = crtZones.get(i);
|
|
|
|
zones.add(zone.ZoneName);
|
2022-05-03 07:44:37 +00:00
|
|
|
if (zone.id == zoneNR)
|
2022-03-10 14:31:03 +00:00
|
|
|
position = i; // save crt position in array
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
textViewZone.setText(zones.get(position));
|
2022-03-10 14:31:03 +00:00
|
|
|
|
|
|
|
// set channel
|
2022-05-03 07:44:37 +00:00
|
|
|
ArrayList<String> channel = new ArrayList<>();
|
2022-03-23 11:07:40 +00:00
|
|
|
crtChannels = parentTab.getCrtRadio().zoneList.get(position).channelList;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get current channel
|
2022-04-08 14:54:45 +00:00
|
|
|
position = 0;
|
2022-05-03 07:44:37 +00:00
|
|
|
for (int i=0; i< crtChannels.size(); i++) {
|
2022-03-10 14:31:03 +00:00
|
|
|
Channel ch = crtChannels.get(i);
|
|
|
|
channel.add(ch.chName);
|
|
|
|
if(ch.id == chNR)
|
2022-04-08 14:54:45 +00:00
|
|
|
position = i;
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
textViewChannel.setText(channel.get(position));
|
|
|
|
textViewMessageChannel.setText(channel.get(position));
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
|
|
|
UpdateEnableDisableButtons("online");
|
|
|
|
imageViewStatus.setImageResource(R.drawable.status_online);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Radio Gateway changed from UI
|
2022-05-03 07:44:37 +00:00
|
|
|
private void radioGWChanged(String newIP) {
|
2022-03-10 14:31:03 +00:00
|
|
|
// get gateway id
|
2022-05-03 07:44:37 +00:00
|
|
|
for (RadioGW radio:AppParams.listRadios)
|
|
|
|
if (radio.IP.equals(newIP)) {
|
2022-03-10 14:31:03 +00:00
|
|
|
UpdateEnableDisableButtons("offline");
|
|
|
|
onZoneCHChange(radio.ID, radio.GW_ID,0,0); // get zone and channel for crt radio
|
2022-03-23 11:07:40 +00:00
|
|
|
parentTab.setCrtRadio(radio);
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
textViewGateway.setText(newIP);
|
|
|
|
imageViewStatus.setImageResource(R.drawable.status_offline);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// clear Spinners
|
2022-04-08 14:54:45 +00:00
|
|
|
ClearSpinners();
|
|
|
|
// reset adapter for spinners
|
|
|
|
ResetAdaptersForSpinners();
|
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private void ClearSpinners() {
|
2022-03-10 14:31:03 +00:00
|
|
|
textViewZone.setText("");
|
|
|
|
textViewChannel.setText("");
|
|
|
|
textViewMessageChannel.setText("");
|
2022-04-08 14:54:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private void ResetAdaptersForSpinners() {
|
|
|
|
crtChannels = new ArrayList<>();
|
|
|
|
crtZones = new ArrayList<>();
|
2022-04-08 14:54:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private void SetCheck(RadioButton radioButton) {
|
2022-04-08 14:54:45 +00:00
|
|
|
radioPrivate.setChecked(radioPrivate == radioButton );
|
|
|
|
radioGroup.setChecked(radioGroup == radioButton );
|
|
|
|
radioAll.setChecked(radioAll == radioButton );
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// broadcastCall from ParentTabActivity to set radio status
|
2022-05-03 07:44:37 +00:00
|
|
|
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);
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
final Runnable UpdateB = this::UpdateResultsBroadcastCall;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private void UpdateResultsBroadcastCall() {
|
2022-03-10 14:31:03 +00:00
|
|
|
SM.Debug("UpdateResultsBroadcastCall with Imei: " +imei+ " CallType:"+calltype+ " GroupID:"+groupid+" CallStatus:"+callstatus);
|
2022-05-03 07:44:37 +00:00
|
|
|
if ((callstatus == inCall) || (callstatus== hangTime)) {
|
2022-03-10 14:31:03 +00:00
|
|
|
// modify UI only when call is received, not in hangtime
|
2022-05-03 07:44:37 +00:00
|
|
|
if (callstatus == inCall) {
|
2022-03-10 14:31:03 +00:00
|
|
|
layoutGateway.setEnabled(false);
|
|
|
|
String CallType = getString(R.string.AllCall);
|
2022-05-03 07:44:37 +00:00
|
|
|
if (calltype == PRIVATECall) {
|
2022-03-10 14:31:03 +00:00
|
|
|
CallType = getString(R.string.PrivateCall);
|
2022-04-08 14:54:45 +00:00
|
|
|
SetCheck(radioPrivate);
|
2022-03-10 14:31:03 +00:00
|
|
|
selectedCallType = PRIVATECall;
|
2022-05-03 07:44:37 +00:00
|
|
|
} else if (calltype == GROUPCall) {
|
2022-03-10 14:31:03 +00:00
|
|
|
CallType = getString(R.string.GroupCall) + "("+groupid+")";
|
2022-04-08 14:54:45 +00:00
|
|
|
SetCheck(radioGroup);
|
2022-03-10 14:31:03 +00:00
|
|
|
selectedCallType = GROUPCall;
|
2022-04-08 14:54:45 +00:00
|
|
|
textViewCallType.setText(groupid + "");
|
2022-05-03 07:44:37 +00:00
|
|
|
} else {
|
2022-04-08 14:54:45 +00:00
|
|
|
SetCheck(radioAll);
|
2022-03-10 14:31:03 +00:00
|
|
|
selectedCallType = ALLCall;
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
layoutSpinnerCallType.setVisibility( calltype != ALLCall ? View.VISIBLE : View.INVISIBLE);
|
|
|
|
textViewMessageChannel.setText(CallType);
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
if (parentTab.getSuperVehHash() != null) {
|
|
|
|
if (parentTab.getSuperVehHash().containsKey(imei))
|
|
|
|
textViewMessageStatus.setText(parentTab.getSuperVehHash().get(imei).name);
|
2022-04-08 14:54:45 +00:00
|
|
|
else
|
2022-05-03 07:44:37 +00:00
|
|
|
textViewMessageStatus.setText("Imei: " + imei);
|
2022-04-08 14:54:45 +00:00
|
|
|
}
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
if (callstatus == hangTime) {
|
|
|
|
textViewMessageStatus.setText(getString(R.string.hangTime));
|
|
|
|
|
|
|
|
buttonPTT.setEnabled(true);
|
|
|
|
buttonDKey.setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
if (parentTab.getCrtActivity() == parentTab.RADIO_TAB_ID && selectedCallType == calltype)
|
2022-03-10 14:31:03 +00:00
|
|
|
parentTab.enableMenuButtons(false);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
if (selectedCallType == calltype)
|
2022-03-23 11:07:40 +00:00
|
|
|
parentTab.setInCall(true);
|
2022-05-03 07:44:37 +00:00
|
|
|
} else if (callstatus == callEnd ) {
|
|
|
|
if ((calltype == 0 && pttONoff) || selectedCallType == calltype) {
|
2022-03-10 14:31:03 +00:00
|
|
|
layoutGateway.setEnabled(true);
|
|
|
|
textViewMessageChannel.setText(textViewChannel.getText());
|
|
|
|
textViewMessageStatus.setText(" ");
|
|
|
|
imageViewStatus.setImageResource(R.drawable.status_online);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
// stop sound
|
2022-05-03 07:44:37 +00:00
|
|
|
if (audioH!=null)
|
2022-03-10 14:31:03 +00:00
|
|
|
audioH.StopSound();
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// disable buttons
|
|
|
|
UpdateEnableDisableButtons("enable");
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
if (pttONoff) {
|
2022-03-10 14:31:03 +00:00
|
|
|
pttONoff= false;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
if (audioH!=null)
|
2022-03-10 14:31:03 +00:00
|
|
|
audioH.soundNeeded = false;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
buttonPTT.setText(getString(R.string.PTT));
|
2022-03-14 09:53:00 +00:00
|
|
|
buttonPTT.setBackgroundResource(R.drawable.style_buttonptt);
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
|
|
|
parentTab.enableMenuButtons(true);
|
2022-04-08 14:54:45 +00:00
|
|
|
parentTab.setInCall(false);
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// called from ParentTabActivity to set radio status
|
2022-05-03 07:44:37 +00:00
|
|
|
public void UpdateRadioStatus (int status) {
|
2022-03-10 14:31:03 +00:00
|
|
|
// save received id's zoneNr and CHNR
|
|
|
|
this.rStatus = status;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
SM.Debug("rStatus: " + rStatus );
|
|
|
|
myHandler.post(UpdateRadioS);
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
final Runnable UpdateRadioS = this::updateResultsStatus;
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private void updateResultsStatus() {
|
2022-04-08 14:54:45 +00:00
|
|
|
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");
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private void enableDisableRadioCallType(boolean enabled) {
|
2022-04-08 14:54:45 +00:00
|
|
|
radioGroupCallType.setEnabled(enabled);
|
|
|
|
radioAll.setEnabled(enabled);
|
|
|
|
radioGroup.setEnabled(enabled);
|
|
|
|
radioPrivate.setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
private void enableDisableSpinners(boolean enabled) {
|
2022-04-08 14:54:45 +00:00
|
|
|
layoutSpinnerZone.setEnabled(enabled);
|
|
|
|
layoutSpinnerChannel.setEnabled(enabled);
|
|
|
|
layoutSpinnerCallType.setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2022-05-03 07:44:37 +00:00
|
|
|
public void UpdateEnableDisableButtons(String type) {
|
|
|
|
if (type.equals("disableIncCall")) {
|
2022-04-08 14:54:45 +00:00
|
|
|
enableDisableRadioCallType(false);
|
|
|
|
enableDisableSpinners(false);
|
|
|
|
|
|
|
|
// enable Dkey button
|
2022-03-10 14:31:03 +00:00
|
|
|
buttonDKey.setEnabled(true);
|
2022-04-08 14:54:45 +00:00
|
|
|
// disable PTT
|
2022-03-10 14:31:03 +00:00
|
|
|
buttonPTT.setEnabled(false);
|
2022-05-03 07:44:37 +00:00
|
|
|
} else if (type.equals("disablePTT")) {
|
2022-04-08 14:54:45 +00:00
|
|
|
enableDisableRadioCallType(false);
|
|
|
|
enableDisableSpinners(false);
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// disable Dkey button
|
|
|
|
buttonDKey.setEnabled(false);
|
2022-05-03 07:44:37 +00:00
|
|
|
} else if (type.equals("enable")) {
|
2022-04-08 14:54:45 +00:00
|
|
|
enableDisableRadioCallType(true);
|
|
|
|
enableDisableSpinners(true);
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// disable Dkey button and enable PTT
|
|
|
|
buttonDKey.setEnabled(false);
|
|
|
|
buttonPTT.setEnabled(true);
|
2022-05-03 07:44:37 +00:00
|
|
|
} else if(type.equals("online")) {
|
2022-04-08 14:54:45 +00:00
|
|
|
enableDisableRadioCallType(true);
|
|
|
|
enableDisableSpinners(true);
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// disable Dkey button
|
|
|
|
buttonDKey.setEnabled(false);
|
|
|
|
buttonPTT.setEnabled(true);
|
|
|
|
textViewMessageStatus.setText("");
|
2022-04-08 14:54:45 +00:00
|
|
|
parentTab.enableMenuButtons(true);
|
2022-05-03 07:44:37 +00:00
|
|
|
} else if (type.equals("offline")) {
|
2022-04-08 14:54:45 +00:00
|
|
|
enableDisableRadioCallType(false);
|
|
|
|
enableDisableSpinners(false);
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// disable Dkey button
|
|
|
|
buttonDKey.setEnabled(false);
|
2022-04-08 14:54:45 +00:00
|
|
|
// disable PTT button
|
2022-03-10 14:31:03 +00:00
|
|
|
buttonPTT.setEnabled(false);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// reset zone and channel text
|
|
|
|
textViewZone.setText("");
|
|
|
|
textViewChannel.setText("");
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
parentTab.enableMenuButtons(true); //enable menu buttons
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// reset status icon
|
|
|
|
imageViewStatus.setImageResource(R.drawable.status_offline);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// reset screen messages
|
|
|
|
textViewMessageChannel.setText("");
|
|
|
|
textViewMessageStatus.setText(getString(R.string.offline));
|
2022-04-08 14:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get Group Contact ID from Name
|
2022-05-03 07:44:37 +00:00
|
|
|
private int getGroupID4Name(String name) {
|
2022-03-10 14:31:03 +00:00
|
|
|
int i = 0;
|
2022-05-03 07:44:37 +00:00
|
|
|
for (String groupName: allGroupsNames) {
|
2022-03-10 14:31:03 +00:00
|
|
|
// if searched name - return corresponding id
|
2022-05-03 07:44:37 +00:00
|
|
|
if (groupName.equals(name))
|
2022-03-10 14:31:03 +00:00
|
|
|
return allGroupsIDs.get(i);
|
|
|
|
i++;
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get Private Contact ID from Name
|
2022-05-03 07:44:37 +00:00
|
|
|
private int getPrivateImei4Name(String name) {
|
|
|
|
for (Vehicle vehicle: allVehicle) {
|
|
|
|
if (vehicle.name.equals(name))
|
2022-04-08 14:54:45 +00:00
|
|
|
return Integer.parseInt(vehicle.imei);
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get zone number from spinner zoneName
|
2022-05-03 07:44:37 +00:00
|
|
|
private int getNR4Zone(String zoneName) {
|
|
|
|
for (Zone zone: crtZones)
|
|
|
|
if (zone.ZoneName.equals(zoneName))
|
2022-03-10 14:31:03 +00:00
|
|
|
return zone.id;
|
|
|
|
return -1;
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// get channel number from spinner chName
|
2022-05-03 07:44:37 +00:00
|
|
|
private int getNR4CH(String chName) {
|
|
|
|
for (Channel ch: crtChannels)
|
|
|
|
if (ch.chName.equals(chName))
|
2022-03-10 14:31:03 +00:00
|
|
|
return ch.id;
|
|
|
|
return -1;
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// send GetGWRadios to AppServer
|
2022-05-03 07:44:37 +00:00
|
|
|
private void GetGWRadios() {
|
2022-03-10 14:31:03 +00:00
|
|
|
parentTab.getRadiosList();
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// send Dekey to AppServer
|
2022-05-03 07:44:37 +00:00
|
|
|
private void SendDekey() {
|
|
|
|
if (parentTab.getCrtRadio() != null)
|
2022-03-23 11:07:40 +00:00
|
|
|
parentTab.sendDekey(parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID);
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// send change Channel and Zone message to AppServer
|
2022-05-03 07:44:37 +00:00
|
|
|
private void onZoneCHChange(int RadioID, int GWID, int zone, int ch) {
|
2022-03-10 14:31:03 +00:00
|
|
|
SM.Debug("Changed Z: " + zone + " | Channel: " + ch);
|
|
|
|
parentTab.getSetZoneAndChannel(GWID,RadioID,zone,ch);
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// request radio status
|
2022-05-03 07:44:37 +00:00
|
|
|
private void ReqRadioStatus(int RadioID, int GWID) {
|
2022-03-10 14:31:03 +00:00
|
|
|
SM.Debug("Request radio status 4 radioId: " + RadioID + " | GW_ID:" + GWID);
|
|
|
|
parentTab.getRadioStatus(GWID,RadioID);
|
|
|
|
try {
|
|
|
|
Thread.sleep(500);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
|
|
|
//sendPTT
|
|
|
|
//callType:
|
|
|
|
//101 -allcall init
|
|
|
|
//111 -allcall stop
|
|
|
|
//102 -prvcall init
|
|
|
|
//112 -prvcall stop
|
|
|
|
//103 -grpcall init
|
|
|
|
//113 -grpcall stop
|
2022-05-03 07:44:37 +00:00
|
|
|
public void SendPTT(int callType, int id,int gwid, int rgwid,long userID) {
|
2022-03-23 11:07:40 +00:00
|
|
|
SM.Debug("sendPTT callType:"+callType);
|
|
|
|
parentTab.sendPTT(callType, id,gwid,rgwid,userID);
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
/** Register for broadcasts */
|
|
|
|
private void registerBroadcastIntents() {
|
2022-04-08 14:54:45 +00:00
|
|
|
IntentFilter intentFilter = new IntentFilter(OperationCodes.CHANNEL_BRDCST + "");
|
2022-03-10 14:31:03 +00:00
|
|
|
this.registerReceiver(mReceiver, intentFilter);
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
intentFilter = new IntentFilter(OperationCodes.RADIOID_CHANGED + "");
|
2022-03-10 14:31:03 +00:00
|
|
|
this.registerReceiver(mReceiver, intentFilter);
|
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
//The BroadcastReceiver that listens for Notification broadcasts
|
|
|
|
public final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
final String action = intent.getAction();
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
// CHANNEL_BRDCST
|
|
|
|
if (action.equals(OperationCodes.CHANNEL_BRDCST + "")) {
|
2022-03-10 14:31:03 +00:00
|
|
|
Zone_and_channel zc = AppParams.crtZoneAndChannel;
|
2022-04-08 14:54:45 +00:00
|
|
|
UpdateZoneCH(zc.rgwID, zc.gwID, zc.zoneNr, zc.channelNr);
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
2022-04-08 14:54:45 +00:00
|
|
|
|
|
|
|
// RADIOID_CHANGED
|
|
|
|
if (action.equals(OperationCodes.RADIOID_CHANGED + "")) {
|
2022-03-23 11:07:40 +00:00
|
|
|
textViewGateway.setText(parentTab.getCrtRadio().IP);
|
|
|
|
textViewChannel.setText(parentTab.getCrtRadio().getChannelName());
|
|
|
|
textViewZone.setText(parentTab.getCrtRadio().getZoneName());
|
2022-04-08 14:54:45 +00:00
|
|
|
|
2022-03-10 14:31:03 +00:00
|
|
|
// update UI
|
|
|
|
myHandler.post(UpdateResultsZoneChannelRUN);
|
2022-03-23 11:07:40 +00:00
|
|
|
radioGWChanged(parentTab.getCrtRadio().IP);
|
2022-03-10 14:31:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|