1st version that works
This commit is contained in:
94
libSafeMobile/src/main/java/com/safemobile/lib/Contact.java
Normal file
94
libSafeMobile/src/main/java/com/safemobile/lib/Contact.java
Normal file
@ -0,0 +1,94 @@
|
||||
package com.safemobile.lib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Contact {
|
||||
public int dbID = 0;
|
||||
public long id = 0;
|
||||
public String name = "";
|
||||
public int contactType = 0;
|
||||
public int parentDB_ID = 0;
|
||||
|
||||
public static final int PRIVATE = 1;
|
||||
public static final int GROUP = 2;
|
||||
public static final int ALL = 3;
|
||||
public static final int ZONE = 4;
|
||||
public static final int CHANNEL = 5;
|
||||
|
||||
|
||||
|
||||
public Contact()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Contact(long _id, String _name, int _contactType, int dbID, int parentDB_id)
|
||||
{
|
||||
id = _id;
|
||||
name = _name;
|
||||
contactType = _contactType;
|
||||
this.dbID = dbID;
|
||||
this.parentDB_ID = parentDB_id;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return id + ". " + name + " [" + getContactType(contactType) + "]";
|
||||
}
|
||||
|
||||
|
||||
private String getContactType(int contactType) {
|
||||
switch(contactType) {
|
||||
case PRIVATE: return "PRIVATE";
|
||||
case GROUP: return "GROUP";
|
||||
case ALL: return "ALL CALL";
|
||||
case ZONE: return "ZONE";
|
||||
case CHANNEL: return "CHANNEL";
|
||||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<Contact> parseTCPMsg(String msg) {
|
||||
|
||||
ArrayList<Contact> contacts = new ArrayList<Contact>();
|
||||
try
|
||||
{
|
||||
msg = msg.replace("#", "");
|
||||
// split payload to get contacts
|
||||
|
||||
// split contact by /
|
||||
String[] contArr = msg.split("/");
|
||||
Contact ct = new Contact();
|
||||
ct.dbID = Integer.parseInt(contArr[0]);
|
||||
ct.id = Long.parseLong(contArr[1]);
|
||||
ct.name = contArr[2];
|
||||
ct.contactType = Integer.parseInt(contArr[4]);
|
||||
ct.parentDB_ID = Integer.parseInt(contArr[3]);
|
||||
|
||||
contacts.add(ct);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
SM.Exception("Exception parse Contacts", ex.toString());
|
||||
}
|
||||
|
||||
return contacts;
|
||||
/*
|
||||
int id = 1;
|
||||
|
||||
// this will select the type
|
||||
switch(AppParams.APPLICATION_TYPE * 10 + id) {
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public static String getNameForRadioID(ArrayList<Contact> listUnits, long radioID) {
|
||||
for(Contact ctc: listUnits)
|
||||
if(ctc.id == radioID && (ctc.contactType == Contact.PRIVATE))
|
||||
return ctc.name;
|
||||
|
||||
// if contact wasn't found I should return it's radioID
|
||||
return radioID+"";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user