// Injects fields and methods
private void initial() {
if( _contact != null ) {
// name & title
if( _contact.countValues( Contact.NAME ) == 0 ) {
addItem( new ScriptField( FIELD_TITLE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_FIRSTNAME, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_LASTNAME, "", ScriptField.TYPE_STRING, false, false ) );
} else {
String[] name;
name = _contact.getStringArray( Contact.NAME, 0 );
addItem( new ScriptField( FIELD_TITLE,
( name[ Contact.NAME_PREFIX ] != null ) ? name[ Contact.NAME_PREFIX ] : "", ScriptField.TYPE_STRING,
false, false ) );
addItem( new ScriptField( FIELD_FIRSTNAME, ( name[ Contact.NAME_GIVEN ] != null ) ? name[ Contact.NAME_GIVEN ]
: "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_LASTNAME, ( name[ Contact.NAME_FAMILY ] != null ) ? name[ Contact.NAME_FAMILY ]
: "", ScriptField.TYPE_STRING, false, false ) );
}
// homeAddress & workAddress
AddressObject homeAddress = new AddressObject();
AddressObject workAddress = new AddressObject();
addItem( new ScriptField( FIELD_HOMEADDRESS, null, ScriptField.TYPE_SCRIPTABLE, false, false ) );
addItem( new ScriptField( FIELD_WORKADDRESS, null, ScriptField.TYPE_SCRIPTABLE, false, false ) );
int count = _contact.countValues( Contact.ADDR );
if( count > 0 ) {
for( int j = 0; j < count; j++ ) {
String[] address;
address = _contact.getStringArray( Contact.ADDR, j );
int attribute = _contact.getAttributes( Contact.ADDR, j );
if( Contact.ATTR_HOME == attribute ) {
populateAddressObject( homeAddress, address );
addItem( new ScriptField( FIELD_HOMEADDRESS, homeAddress, ScriptField.TYPE_SCRIPTABLE, false, false ) );
} else if( Contact.ATTR_WORK == attribute ) {
populateAddressObject( workAddress, address );
addItem( new ScriptField( FIELD_WORKADDRESS, workAddress, ScriptField.TYPE_SCRIPTABLE, false, false ) );
}
}
}
// email
addItem( new ScriptField( FIELD_EMAIL1, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_EMAIL2, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_EMAIL3, "", ScriptField.TYPE_STRING, false, false ) );
count = _contact.countValues( Contact.EMAIL );
if( count > 0 ) {
for( int j = 0; j < count; j++ ) {
String email = _contact.getString( Contact.EMAIL, j );
if( j == 0 ) {
addItem( new ScriptField( FIELD_EMAIL1, email, ScriptField.TYPE_STRING, false, false ) );
} else if( j == 1 ) {
addItem( new ScriptField( FIELD_EMAIL2, email, ScriptField.TYPE_STRING, false, false ) );
} else if( j == 2 ) {
addItem( new ScriptField( FIELD_EMAIL3, email, ScriptField.TYPE_STRING, false, false ) );
}
}
}
// company
if( _contact.countValues( Contact.ORG ) > 0 ) {
addItem( new ScriptField( FIELD_COMPANY, _contact.getString( Contact.ORG, 0 ), ScriptField.TYPE_STRING, false,
false ) );
} else {
addItem( new ScriptField( FIELD_COMPANY, "", ScriptField.TYPE_STRING, false, false ) );
}
// jobtitle
if( _contact.countValues( Contact.TITLE ) > 0 ) {
addItem( new ScriptField( FIELD_JOBTITLE, _contact.getString( Contact.TITLE, 0 ), ScriptField.TYPE_STRING, false,
false ) );
} else {
addItem( new ScriptField( FIELD_JOBTITLE, "", ScriptField.TYPE_STRING, false, false ) );
}
// phone
addItem( new ScriptField( FIELD_HOMEPHONE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_HOMEPHONE2, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_WORKPHONE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_WORKPHONE2, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_MOBILEPHONE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_MOBILEPHONE2, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_FAXPHONE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_FAXPHONE2, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_PAGERPHONE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_OTHERPHONE, "", ScriptField.TYPE_STRING, false, false ) );
count = _contact.countValues( Contact.TEL );
if( count > 0 ) {
for( int j = 0; j < count; j++ ) {
String tel = _contact.getString( Contact.TEL, j );
int attribute = _contact.getAttributes( Contact.TEL, j );
if( Contact.ATTR_HOME == attribute ) {
addItem( new ScriptField( FIELD_HOMEPHONE, tel, ScriptField.TYPE_STRING, false, false ) );
} else if( BlackBerryContact.ATTR_HOME2 == attribute ) {
addItem( new ScriptField( FIELD_HOMEPHONE2, tel, ScriptField.TYPE_STRING, false, false ) );
} else if( Contact.ATTR_WORK == attribute ) {
addItem( new ScriptField( FIELD_WORKPHONE, tel, ScriptField.TYPE_STRING, false, false ) );
} else if( BlackBerryContact.ATTR_WORK2 == attribute ) {
addItem( new ScriptField( FIELD_WORKPHONE2, tel, ScriptField.TYPE_STRING, false, false ) );
} else if( Contact.ATTR_MOBILE == attribute ) {
addItem( new ScriptField( FIELD_MOBILEPHONE, tel, ScriptField.TYPE_STRING, false, false ) );
} else if( Contact.ATTR_FAX == attribute ) {
addItem( new ScriptField( FIELD_FAXPHONE, tel, ScriptField.TYPE_STRING, false, false ) );
} else if( Contact.ATTR_PAGER == attribute ) {
addItem( new ScriptField( FIELD_PAGERPHONE, tel, ScriptField.TYPE_STRING, false, false ) );
} else if( Contact.ATTR_OTHER == attribute ) {
addItem( new ScriptField( FIELD_OTHERPHONE, tel, ScriptField.TYPE_STRING, false, false ) );
}
}
}
// note
if( _contact.countValues( Contact.NOTE ) > 0 ) {
addItem( new ScriptField( FIELD_NOTE, _contact.getString( Contact.NOTE, 0 ), ScriptField.TYPE_STRING, false,
false ) );
} else {
addItem( new ScriptField( FIELD_NOTE, "", ScriptField.TYPE_STRING, false, false ) );
}
// webpage
try {
if( _contact.countValues( Contact.URL ) > 0 ) {
addItem( new ScriptField( FIELD_WEBPAGE, _contact.getString( Contact.URL, 0 ), ScriptField.TYPE_STRING,
false, false ) );
} else {
addItem( new ScriptField( FIELD_WEBPAGE, "", ScriptField.TYPE_STRING, false, false ) );
}
} catch( UnsupportedFieldException e ) {
addItem( new ScriptField( FIELD_WEBPAGE, "", ScriptField.TYPE_STRING, false, false ) );
}
// birthday & anniiversary
if( _contact.countValues( Contact.BIRTHDAY ) > 0 ) {
addItem( new ScriptField( FIELD_BIRTHDAY, new Date( _contact.getDate( Contact.BIRTHDAY, 0 ) ),
ScriptField.TYPE_DATE, false, false ) );
} else {
addItem( new ScriptField( FIELD_BIRTHDAY, null, ScriptField.TYPE_DATE, false, false ) );
}
if( _contact.countValues( BlackBerryContact.ANNIVERSARY ) > 0 ) {
addItem( new ScriptField( FIELD_ANNIVERSARY, new Date( _contact.getDate( BlackBerryContact.ANNIVERSARY, 0 ) ),
ScriptField.TYPE_DATE, false, false ) );
} else {
addItem( new ScriptField( FIELD_ANNIVERSARY, null, ScriptField.TYPE_DATE, false, false ) );
}
// user
if( _contact.countValues( BlackBerryContact.USER1 ) > 0 ) {
addItem( new ScriptField( FIELD_USER1, _contact.getString( BlackBerryContact.USER1, 0 ), ScriptField.TYPE_STRING,
false, false ) );
} else {
addItem( new ScriptField( FIELD_USER1, "", ScriptField.TYPE_STRING, false, false ) );
}
if( _contact.countValues( BlackBerryContact.USER2 ) > 0 ) {
addItem( new ScriptField( FIELD_USER2, _contact.getString( BlackBerryContact.USER2, 0 ), ScriptField.TYPE_STRING,
false, false ) );
} else {
addItem( new ScriptField( FIELD_USER2, "", ScriptField.TYPE_STRING, false, false ) );
}
if( _contact.countValues( BlackBerryContact.USER3 ) > 0 ) {
addItem( new ScriptField( FIELD_USER3, _contact.getString( BlackBerryContact.USER3, 0 ), ScriptField.TYPE_STRING,
false, false ) );
} else {
addItem( new ScriptField( FIELD_USER3, "", ScriptField.TYPE_STRING, false, false ) );
}
if( _contact.countValues( BlackBerryContact.USER4 ) > 0 ) {
addItem( new ScriptField( FIELD_USER4, _contact.getString( BlackBerryContact.USER4, 0 ), ScriptField.TYPE_STRING,
false, false ) );
} else {
addItem( new ScriptField( FIELD_USER4, "", ScriptField.TYPE_STRING, false, false ) );
}
// pin
if( _contact.countValues( BlackBerryContact.PIN ) > 0 ) {
addItem( new ScriptField( FIELD_PIN, _contact.getString( BlackBerryContact.PIN, 0 ), ScriptField.TYPE_STRING,
false, false ) );
} else {
addItem( new ScriptField( FIELD_PIN, "", ScriptField.TYPE_STRING, false, false ) );
}
// uid
if( _contact.countValues( Contact.UID ) > 0 ) {
addItem( new ScriptField( FIELD_UID, _contact.getString( Contact.UID, 0 ), ScriptField.TYPE_STRING, true, false ) );
} else {
addItem( new ScriptField( FIELD_UID, "", ScriptField.TYPE_STRING, true, false ) );
}
// picture
if( _contact.countValues( Contact.PHOTO ) > 0 ) {
byte[] photoEncoded = _contact.getBinary( Contact.PHOTO, 0 );
String picture = "";
try {
picture = new String( photoEncoded, PICTURE_ENCODING );
} catch( UnsupportedEncodingException e ) {
}
addItem( new ScriptField( FIELD_PICTURE, picture, ScriptField.TYPE_STRING, true, false ) );
} else {
addItem( new ScriptField( FIELD_PICTURE, "", ScriptField.TYPE_STRING, true, false ) );
}
// categories
addItem( new ScriptField( FIELD_CATEGORIES, _contact.getCategories(), ScriptField.TYPE_SCRIPTABLE, false, false ) );
} else {
// name & title
addItem( new ScriptField( FIELD_TITLE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_FIRSTNAME, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_LASTNAME, "", ScriptField.TYPE_STRING, false, false ) );
// homeAddress & workAddress
addItem( new ScriptField( FIELD_HOMEADDRESS, null, ScriptField.TYPE_SCRIPTABLE, false, false ) );
addItem( new ScriptField( FIELD_WORKADDRESS, null, ScriptField.TYPE_SCRIPTABLE, false, false ) );
// email
addItem( new ScriptField( FIELD_EMAIL1, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_EMAIL2, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_EMAIL3, "", ScriptField.TYPE_STRING, false, false ) );
// company
addItem( new ScriptField( FIELD_COMPANY, "", ScriptField.TYPE_STRING, false, false ) );
// jobtitle
addItem( new ScriptField( FIELD_JOBTITLE, "", ScriptField.TYPE_STRING, false, false ) );
// phone
addItem( new ScriptField( FIELD_HOMEPHONE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_HOMEPHONE2, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_WORKPHONE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_WORKPHONE2, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_MOBILEPHONE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_MOBILEPHONE2, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_FAXPHONE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_FAXPHONE2, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_PAGERPHONE, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_OTHERPHONE, "", ScriptField.TYPE_STRING, false, false ) );
// note
addItem( new ScriptField( FIELD_NOTE, "", ScriptField.TYPE_STRING, false, false ) );
// webpage
addItem( new ScriptField( FIELD_WEBPAGE, "", ScriptField.TYPE_STRING, false, false ) );
// birthday & anniiversary
addItem( new ScriptField( FIELD_BIRTHDAY, null, ScriptField.TYPE_DATE, false, false ) );
addItem( new ScriptField( FIELD_ANNIVERSARY, null, ScriptField.TYPE_DATE, false, false ) );
// user
addItem( new ScriptField( FIELD_USER1, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_USER2, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_USER3, "", ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_USER4, "", ScriptField.TYPE_STRING, false, false ) );
// pin
addItem( new ScriptField( FIELD_PIN, "", ScriptField.TYPE_STRING, false, false ) );
// uid
addItem( new ScriptField( FIELD_UID, "", ScriptField.TYPE_STRING, true, false ) );
// picture
addItem( new ScriptField( FIELD_PICTURE, "", ScriptField.TYPE_STRING, true, false ) );
// categories
addItem( new ScriptField( FIELD_CATEGORIES, null, ScriptField.TYPE_SCRIPTABLE, false, false ) );
}
_save = new ContactSaveScriptableFunction();
_remove = new ContactRemoveScriptableFunction();
_setPicture = new ContactSetPictureScriptableFunction();
addItem( new ScriptField( METHOD_SAVE, _save, ScriptField.TYPE_SCRIPTABLE, true, true ) );
addItem( new ScriptField( METHOD_REMOVE, _remove, ScriptField.TYPE_SCRIPTABLE, true, true ) );
addItem( new ScriptField( METHOD_SETPICTURE, _setPicture, ScriptField.TYPE_SCRIPTABLE, true, true ) );
}