1st version that works
This commit is contained in:
@ -0,0 +1,264 @@
|
||||
package com.safemobile.activities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Timer;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.Contact;
|
||||
import com.safemobile.lib.radio.Channel;
|
||||
import com.safemobile.lib.radio.Emerg;
|
||||
import com.safemobile.lib.radio.IncCall;
|
||||
import com.safemobile.lib.radio.Zone;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
public abstract class AbstractRadioActivity extends Activity {
|
||||
|
||||
|
||||
/** Misc */
|
||||
public AbstractParentActivity parentTab;
|
||||
public Activity activity;
|
||||
public Context context;
|
||||
public boolean emergencyOn = false;
|
||||
public boolean pttONoff = false;
|
||||
public IncCall incCall;
|
||||
public String chMsg = "";
|
||||
public Emerg emerg;
|
||||
public Dialog dialogExternal;
|
||||
// only in PadRadio
|
||||
//public int radioID, GWID, zoneNR, chNR;
|
||||
|
||||
/** Handler */
|
||||
public Handler myHandler = new Handler();
|
||||
public Timer timerInCall, timerPTTOn, timerCallType;
|
||||
|
||||
/** Lists */
|
||||
//public ArrayList<String> allContactsNames = new ArrayList<String>();
|
||||
//public ArrayList<String> allGroupsNames = new ArrayList<String>();
|
||||
//public ArrayList<Integer> allContactsIDs = new ArrayList<Integer>();
|
||||
//public ArrayList<Integer> allGroupsIDs = new ArrayList<Integer>();
|
||||
//public ArrayList<Zone> crtZones = new ArrayList<Zone>();
|
||||
//public ArrayList<Channel> crtChannels = new ArrayList<Channel>();
|
||||
public ArrayAdapter<String> adapter;
|
||||
|
||||
|
||||
/** Methods */
|
||||
//public void onCreate(Bundle savedInstanceState) { };
|
||||
public abstract void startAudioHandler();
|
||||
public void PTTclick(int type) { };
|
||||
/*
|
||||
public abstract void updateRadioTCPdown();
|
||||
public abstract void UpdateRadios(ArrayList<RadioGW> radios);
|
||||
public abstract void UpdateCallTypeChanged(IncCall response);
|
||||
public abstract void UpdateZoneCH(int _radioID, int _GWID, int _zoneNR, int _chNR);
|
||||
public abstract void UpdateRadioStatus(int status);
|
||||
public abstract void UpdateIncCall (IncCall iCall);
|
||||
public abstract String updateUI(EnumCallState radioStatus);
|
||||
public abstract void UpdateEmerg (Emerg emerg);
|
||||
public abstract void onContactsUpdate();
|
||||
*/
|
||||
public abstract void sendPTTFromBlueTooth(boolean on);
|
||||
public abstract void ShowDialog(String title, String errorMsg);
|
||||
public abstract void stopAudioHandler();
|
||||
public abstract Object getAudioHandlerState();
|
||||
public abstract void initUDP();
|
||||
|
||||
|
||||
|
||||
/** Stop the timer that ends call after one minute */
|
||||
public void stopTimerInCall()
|
||||
{
|
||||
timerInCall.cancel();
|
||||
timerInCall.purge();
|
||||
timerInCall = null;
|
||||
}
|
||||
|
||||
|
||||
/** get Group Contact ID from Name */
|
||||
public long getGroupID4Name_old(String name)
|
||||
{
|
||||
try {
|
||||
ListIterator<Contact> it = AppParams.listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact ctc = it.next();
|
||||
// if searched name - return corresponding id
|
||||
if(ctc.name.equals(name) && ctc.contactType == Contact.GROUP)
|
||||
return ctc.id;
|
||||
}
|
||||
|
||||
long id = -1;
|
||||
|
||||
// try to get id from name because the id was manual dialed
|
||||
try {
|
||||
id = Long.parseLong(name);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/** get Private Contact ID from Name */
|
||||
public long getPrivateID4Name_old(String name)
|
||||
{
|
||||
try {
|
||||
ListIterator<Contact> it = AppParams.listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact ctc = it.next();
|
||||
// if searched name - return corresponding id
|
||||
if(ctc.name.equals(name) && ctc.contactType == Contact.PRIVATE)
|
||||
return ctc.id;
|
||||
}
|
||||
|
||||
long id = -1;
|
||||
|
||||
// try to get id from name because the id was manual dialed
|
||||
try {
|
||||
id = Long.parseLong(name);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** get Private Contact ID from Name */
|
||||
public String getName4PrivateID(long id)
|
||||
{
|
||||
try {
|
||||
ListIterator<Contact> it = AppParams.listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact ctc = it.next();
|
||||
// if searched name - return corresponding id
|
||||
if(ctc.id == id && ctc.contactType == Contact.PRIVATE)
|
||||
return ctc.name;
|
||||
}
|
||||
|
||||
return id+"";
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
return id+"";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** get Group Contact ID from Name */
|
||||
public String getName4GroupID(long id)
|
||||
{
|
||||
try {
|
||||
ListIterator<Contact> it = AppParams.listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact ctc = it.next();
|
||||
// if searched name - return corresponding id
|
||||
if(ctc.id == id && ctc.contactType == Contact.GROUP)
|
||||
return ctc.name;
|
||||
}
|
||||
|
||||
return id+"";
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
return id+"";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** get zone number from spinner zoneName */
|
||||
public int getNR4Zone_old(String zoneName)
|
||||
{
|
||||
for(Zone zone: AppParams.listZones)
|
||||
if(zone.ZoneName.equals(zoneName))
|
||||
return zone.id;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** get channel number from spinner chName */
|
||||
public int getNR4CH_old(String chName)
|
||||
{
|
||||
for(Channel ch: AppParams.crtZone.channelList)
|
||||
if(ch.chName.equals(chName))
|
||||
return ch.id;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/** get All Contacts Names */
|
||||
public static ArrayList<String> getAllContactsName(String type, ArrayList<Contact> listContacts)
|
||||
{
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
try {
|
||||
ListIterator<Contact> it = listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact contact = it.next();
|
||||
|
||||
if(type.equals("Call"))
|
||||
list.add(contact.name);
|
||||
else {
|
||||
if((type.equalsIgnoreCase("Private Call") && contact.contactType == Contact.PRIVATE) ||
|
||||
(type.equalsIgnoreCase("Group Call") && contact.contactType == Contact.GROUP))
|
||||
list.add(contact.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/** get All Contacts Names */
|
||||
public static ArrayList<Long> getAllContactsIDs(String type, ArrayList<Contact> listContacts)
|
||||
{
|
||||
ArrayList<Long> list = new ArrayList<Long>();
|
||||
|
||||
try
|
||||
{
|
||||
ListIterator<Contact> it = listContacts.listIterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
Contact contact = it.next();
|
||||
|
||||
if(type.equals("Call"))
|
||||
list.add((long)contact.id);
|
||||
|
||||
if((type.equalsIgnoreCase("Private Call") && contact.contactType == Contact.PRIVATE) ||
|
||||
(type.equalsIgnoreCase("Group Call") && contact.contactType == Contact.GROUP))
|
||||
list.add((long)contact.id);
|
||||
}
|
||||
|
||||
}
|
||||
catch (ConcurrentModificationException ex) {
|
||||
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/** Display a toast Message */
|
||||
public void displayToast(String msg)
|
||||
{
|
||||
parentTab.displayToast(msg);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user