package cn.sharp.android.ncr.display;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.provider.Contacts;
import android.text.InputType;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import cn.sharp.android.ncr.MessageId;
import cn.sharp.android.ncr.R;
import cn.sharp.android.ncr.display.domain.Address;
import cn.sharp.android.ncr.display.domain.BaseDomain;
import cn.sharp.android.ncr.display.domain.Email;
import cn.sharp.android.ncr.display.domain.Organization;
import cn.sharp.android.ncr.display.domain.Phone;
import cn.sharp.android.ncr.display.domain.Url;
import cn.sharp.android.ncr.ocr.OCRItems;
public class ContactPerson {
private final static String TAG = "ContactPerson";
public final static int ITEM_NAME = 1;
public final static int ITEM_PHONE = 2;
public final static int ITEM_EMAIL = 3;
public final static int ITEM_ADDRESS = 4;
public final static int ITEM_ORG = 5;
public final static int ITEM_URL = 6;
public final static int ITEM_NOTE = 7;
public final static int TYPE_HOME = 1;
public final static int TYPE_WORK = 2;
public final static int TYPE_OTHER = 3;
public final static int TYPE_PAGER = 4;
public final static int TYPE_MOBILE = 5;
public final static int TYPE_FAX_HOME = 6;
public final static int TYPE_FAX_WORK = 7;
private long groupId;
private String name;
private List<Email> emails;
private List<Phone> phones;
private List<Organization> orgs;
private List<Address> addresses;
private List<Url> urls;
private String note;
public String typeHome, typeWork, typeOther, typePager, typeMobile,
typeFaxHome, typeFaxWork;
private int[] supportedItemTypes1;
private int[] supportedItemTypes2;
private int[] supportedItemTypes3;
private String[] supportedItemTypeStr1;
private String[] supportedItemTypeStr2;
private String[] supportedItemTypeStr3;
private OnSelectItemType onSelectItemType;
private ContentResolver contentResolver;
private SelectItemTypeListener onSelectTypeListener;
private RemoveItemListener removeItemListener;
private EditText nameView, noteView;
private ViewGroup phoneViewGroup, emailViewGroup, addressViewGroup,
orgViewGroup, urlViewGroup;
private Button itemType;
private EditText itemValue, itemValue2;
private ImageButton removeItem;
private LayoutInflater inflater;
/**
* remove all Context reference, or it will result in memory leak
*/
public void removeAllContextObject() {
onSelectItemType = null;
contentResolver = null;
onSelectTypeListener = null;
removeItemListener = null;
nameView = null;
noteView = null;
phoneViewGroup = emailViewGroup = addressViewGroup = orgViewGroup = urlViewGroup = null;
inflater = null;
itemType = null;
itemValue = null;
itemValue2 = null;
removeItem = null;
}
public void registerNewContext(Context context) {
init(context);
}
private void initPrimitiveObj() {
groupId = -1;
phones = new ArrayList<Phone>();
orgs = new ArrayList<Organization>();
emails = new ArrayList<Email>();
addresses = new ArrayList<Address>();
urls = new ArrayList<Url>();
supportedItemTypes1 = new int[] { TYPE_HOME, TYPE_WORK, TYPE_MOBILE,
TYPE_OTHER, TYPE_PAGER, TYPE_FAX_HOME, TYPE_FAX_WORK };
supportedItemTypes2 = new int[] { TYPE_WORK, TYPE_OTHER };
supportedItemTypes3 = new int[] { TYPE_WORK, TYPE_HOME, TYPE_OTHER };
supportedItemTypeStr1 = new String[] { typeHome, typeWork, typeMobile,
typeOther, typePager, typeFaxHome, typeFaxWork };
supportedItemTypeStr2 = new String[] { typeWork, typeOther };
supportedItemTypeStr3 = new String[] { typeWork, typeHome, typeOther };
onSelectTypeListener = new SelectItemTypeListener();
removeItemListener = new RemoveItemListener();
}
private void init(Context context) {
inflater = LayoutInflater.from(context);
contentResolver = context.getContentResolver();
Resources resources = context.getResources();
typeHome = resources.getString(R.string.type_home);
typeWork = resources.getString(R.string.type_work);
typeOther = resources.getString(R.string.type_other);
typePager = resources.getString(R.string.type_pager);
typeMobile = resources.getString(R.string.type_mobile);
typeFaxHome = resources.getString(R.string.type_fax_home);
typeFaxWork = resources.getString(R.string.type_fax_work);
}
public ContactPerson(Context context) {
init(context);
initPrimitiveObj();
}
public ContactPerson(Context context, OCRItems items) {
init(context);
initPrimitiveObj();
if (items.name != null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < items.name.length; i++) {
sb.append(items.name[i]);
}
name = sb.toString();
}
if (items.fax != null) {
for (int i = 0; i < items.fax.length; i++) {
Phone phone = new Phone();
phone.type = TYPE_FAX_WORK;
phone.value = items.fax[i];
phones.add(phone);
}
}
if (items.telephone != null) {
for (int i = 0; i < items.telephone.length; i++) {
Phone phone = new Phone();
phone.type = TYPE_MOBILE;
phone.value = items.telephone[i];
phones.add(phone);
}
}
if (items.cellphone != null) {
for (int i = 0; i < items.cellphone.length; i++) {
Phone phone = new Phone();
phone.type = TYPE_MOBILE;
phone.value = items.cellphone[i];
phones.add(phone);
}
}
if (items.organization != null) {
for (int i = 0; i < items.organization.length; i++) {
Organization org = new Organization();
org.company = items.organization[i];
org.type = TYPE_WORK;
if (items.department != null && items.department.length > i) {
org.company += "," + items.department[i];
}
if (items.title != null && items.title.length > i) {
org.title = items.title[i];
} else {
org.title = "";
}
orgs.add(org);
}
/**
* add the remained items.department fields
*/
if (items.department != null) {
for (int i = items.organization.length; i < items.department.length; i++) {
Organization org = new Organization();
org.company = items.department[i];
org.type = TYPE_WORK;
if (items.title != null && items.title.length > i) {
org.title = items.title[i];
} else {
org.title = "";
}
orgs.add(org);
}
}
} else if (items.department != null) {
/**
* if items.orgnization==null&&items.department!=null, treat
* items.department as org.company value
*/
for (int i = 0; i < items.department.length; i++) {
Organization org = new Organization();
org.company = items.department[i];
org.type = TYPE_WORK;
if (items.title != null && items.title.length > i) {
org.title = items.title[i];
} else {
org.title = "";
}
orgs.add(org);
}
}
if (items.email != null) {
for (int i = 0; i < items.email.length; i++) {
Email email = new Email();
email.type = TYPE_WORK;
email.value = items.email[i];
emails.add(email);
}
}
if (items.address != null) {
for (int i = 0; i < items.address.length; i++) {
Address address = new Address();
address.type = TYPE_WORK;
address.value = items.address[i];
addresses.add(address);
if (items.postcode != null && items.postcode.length > i) {
address.postcode = items.postcode[i];
} else {
address.postcode = "";
}
}
}
if (items.url != null) {
for (int i = 0; i < items.url.length; i++) {
Url url = new Url();
url.type = TYPE_WORK;
url.value = items.url[i];
urls.add(url);
}
}
}
/**
* bind the data to corresponding views
*
* @param nameView
* @param phoneViewG
GJZGRB
- 粉丝: 2974
- 资源: 7735
最新资源
- 使用群晖NAS搭建虚拟机
- 基于minifly的学习源码-本人耗时五年完善的稳定源码移植于minifly上,不带操作系统,直接操作寄存器,代码简洁明了,算法基于数学公式,便于学习数学知识
- 基于motorcad设计的外转子发电机,磁钢采用FB6B铁氧体 ,不等匝绕组,输出功率2.3KW 定子外径156 3200RPM,18极27槽永磁同步发电机(PMSG)设计案例.
- 电力电子、电机驱动、数字滤波器matlab simulink仿真模型实现及相关算法的C代码实现 配置C2000 DSP ADC DAC PWM定时器 中断等模块,提供simulink与DSP的联合仿
- 视觉系统程序,新能源电池检测 1、支持4个相机 2、实现Profinet网卡通信 3、实现日志功能 4、实现图像存储功能 5、实现电芯有无判断、电芯和端板涂胶检测
- 基于51单片机的电子时钟设计
- 西门子smart200与汇川变频器 Modbus RTU控制程序 步科触摸屏程序 振捣控制系统 汇川变频器手册
- C#上位机与西门子plc通信,实现伺服控制与数字量控制 提供C#源代码,plc测试程序
- 45.<资源>番茄钟3.0 无代码 C#例子 WPF例子
- stm32f103的Bootloader IAP串口升级stm32f103的Bootloader IAP串口升级st m32固件的学习资料,成熟产品方案已经用在批量产品上,资料包括上位机(电脑端)运行
- 基于Spark的电商用户行为分析系统-源码+课设论文(本科期末课程设计).zip
- Qt C++pdf阅读器源码 上下翻页 精美工具栏 支持ofd格式 1. 仿WPS界面 2. 预览PDF文件 3. 支持PDF预览放大,缩小 4. 支持目录预览查看 5. 支持目录点击跳转页查
- RDM(radis桌面工具)
- 西门子s7 200smart与3台台达VFD-M变频器通讯目标:用触摸屏和西门子smart 控制3台台达变频器通讯 器件:西门子s7 200 smart PLC,3台台达VFD-M变频器,昆仑通态触摸
- 基于51单片机的电子密码锁设计
- Qt5工业上位机源码 工业电子称 无线扫码器 串口的使用 Qt5.14可运行 Qt5工业上位机应用! 一套完整工程! 工业电子称使用, 无线扫码枪的使用, 串口的使用 使用Qt5.14 用QtCrea
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈