1db169187dea4602e4ad32058762d23d474753fd0Stephen Hines/* 2db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* Copyright (C) 2015 Samsung System LSI 3db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* Licensed under the Apache License, Version 2.0 (the "License"); 4db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* you may not use this file except in compliance with the License. 5db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* You may obtain a copy of the License at 6db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* 7db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* http://www.apache.org/licenses/LICENSE-2.0 8db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* 9db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* Unless required by applicable law or agreed to in writing, software 10db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* distributed under the License is distributed on an "AS IS" BASIS, 11db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* See the License for the specific language governing permissions and 13db169187dea4602e4ad32058762d23d474753fd0Stephen Hines* limitations under the License. 14db169187dea4602e4ad32058762d23d474753fd0Stephen Hines*/ 15db169187dea4602e4ad32058762d23d474753fd0Stephen Hinespackage com.android.bluetooth.map; 16db169187dea4602e4ad32058762d23d474753fd0Stephen Hines 17a2dd52f0710c214e00c1a13e25116e1af5eec77aJean-Luc Brouilletimport java.io.IOException; 18a2dd52f0710c214e00c1a13e25116e1af5eec77aJean-Luc Brouilletimport java.io.UnsupportedEncodingException; 19a2dd52f0710c214e00c1a13e25116e1af5eec77aJean-Luc Brouilletimport java.text.ParseException; 20a2dd52f0710c214e00c1a13e25116e1af5eec77aJean-Luc Brouilletimport java.text.SimpleDateFormat; 21a2dd52f0710c214e00c1a13e25116e1af5eec77aJean-Luc Brouilletimport java.util.Date; 22a2dd52f0710c214e00c1a13e25116e1af5eec77aJean-Luc Brouillet 23a2dd52f0710c214e00c1a13e25116e1af5eec77aJean-Luc Brouilletimport org.xmlpull.v1.XmlPullParser; 247a66e6cbb1ae32cd56b19822c4e66560deb857dbShih-wei Liaoimport org.xmlpull.v1.XmlPullParserException; 2597e50993c70083fdedb4f1dd2c487aa55c6f60cfDavid Grossimport org.xmlpull.v1.XmlSerializer; 2697e50993c70083fdedb4f1dd2c487aa55c6f60cfDavid Gross 277a66e6cbb1ae32cd56b19822c4e66560deb857dbShih-wei Liaoimport android.util.Log; 2833cda5cf335afc6aa2dbe02062bc9e6649e1f87cDavid Gross 29e32af52d4be2bb80783404d99fa338b1143dbc9aDavid Grossimport com.android.bluetooth.SignedLongLong; 307a66e6cbb1ae32cd56b19822c4e66560deb857dbShih-wei Liao 31b730e239619a546d93e5926ea92d698ab77ec7f6Stephen Hinespublic class BluetoothMapConvoContactElement 32b730e239619a546d93e5926ea92d698ab77ec7f6Stephen Hines implements Comparable<BluetoothMapConvoContactElement> { 33b730e239619a546d93e5926ea92d698ab77ec7f6Stephen Hines 34b730e239619a546d93e5926ea92d698ab77ec7f6Stephen Hines public static final long CONTACT_ID_TYPE_SMS_MMS = 1; 3518a38a3fc6fad8355891b771dd3c6537fa8699ecTobias Grosser public static final long CONTACT_ID_TYPE_EMAIL = 2; 36b730e239619a546d93e5926ea92d698ab77ec7f6Stephen Hines public static final long CONTACT_ID_TYPE_IM = 3; 37c72c4ddfcd79c74f70713da91a69569451b5c19eZonr Chang 387ae3a828fade4e30f7940415949f33ac1f15dc77Stephen Hines private static final String XML_ATT_PRIORITY = "priority"; 39b730e239619a546d93e5926ea92d698ab77ec7f6Stephen Hines private static final String XML_ATT_PRESENCE_STATUS = "presence_status"; 40cd5b657c39a348bd7652a19c5be5035e9df44a42Tobias Grosser private static final String XML_ATT_PRESENCE_AVAILABILITY = "presence_availability"; 41b730e239619a546d93e5926ea92d698ab77ec7f6Stephen Hines private static final String XML_ATT_X_BT_UID = "x_bt_uid"; 42806075b3a54af826fea78490fb213d8a0784138eTobias Grosser private static final String XML_ATT_LAST_ACTIVITY = "last_activity"; 43c72c4ddfcd79c74f70713da91a69569451b5c19eZonr Chang private static final String XML_ATT_CHAT_STATE = "chat_state"; 444e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala private static final String XML_ATT_NAME = "name"; 454e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala private static final String XML_ATT_DISPLAY_NAME = "display_name"; 464e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala private static final String XML_ATT_UCI = "x_bt_uci"; 479fa4d4480252ecfe08c97bc35888360b1e19ec99David Gross protected static final String XML_TAG_CONVOCONTACT = "convocontact"; 484e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala private static final String TAG = "BluetoothMapConvoContactElement"; 494e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala private static final boolean D = false; 504e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala private static final boolean V = false; 514e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala 52bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes private String mUci = null; 537a66e6cbb1ae32cd56b19822c4e66560deb857dbShih-wei Liao private String mName = null; 547a66e6cbb1ae32cd56b19822c4e66560deb857dbShih-wei Liao private String mDisplayName = null; 55db169187dea4602e4ad32058762d23d474753fd0Stephen Hines private String mPresenceStatus = null; 567a66e6cbb1ae32cd56b19822c4e66560deb857dbShih-wei Liao private int mPresenceAvailability = -1; 57354d1c132ad7e1ff6fdb0da95443245848a0601fStephen Hines private int mPriority = -1; 589c5263e00d89dfdd25d3a1706eb319e8529ec604Stephen Hines private long mLastActivity = -1; 59797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross private SignedLongLong mBtUid = null; 60797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross private int mChatState = -1; 61797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross 62797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross public static BluetoothMapConvoContactElement createFromMapContact(MapContact contact, 63797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross String address) { 64797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross BluetoothMapConvoContactElement newElement = new BluetoothMapConvoContactElement(); 65797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross newElement.mUci = address; 66797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross // TODO: For now we use the ID as BT-UID 67797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross newElement.mBtUid = new SignedLongLong(contact.getId(),0); 68797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross newElement.mDisplayName = contact.getName(); 69797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross return newElement; 70797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross } 71797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross 72797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross public BluetoothMapConvoContactElement(String uci, String name, String displayName, 73797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross String presenceStatus, int presenceAvailability, long lastActivity, int chatState, 74797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross int priority, String btUid) { 75797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross this.mUci = uci; 76797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross this.mName = name; 77797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross this.mDisplayName = displayName; 78797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross this.mPresenceStatus = presenceStatus; 79797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross this.mPresenceAvailability = presenceAvailability; 80797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross this.mLastActivity = lastActivity; 81797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross this.mChatState = chatState; 82797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross this.mPresenceStatus = presenceStatus; 83797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross this.mPriority = priority; 84797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross if(btUid != null) { 85797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross try { 86797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross this.mBtUid = SignedLongLong.fromString(btUid); 87797b51672914cbe3f3b75e99df7ee7c25560dab7David Gross } catch (UnsupportedEncodingException e) { 887a66e6cbb1ae32cd56b19822c4e66560deb857dbShih-wei Liao Log.w(TAG,e); 894e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala } 9033cda5cf335afc6aa2dbe02062bc9e6649e1f87cDavid Gross } 91db169187dea4602e4ad32058762d23d474753fd0Stephen Hines } 92db169187dea4602e4ad32058762d23d474753fd0Stephen Hines 9333cda5cf335afc6aa2dbe02062bc9e6649e1f87cDavid Gross public BluetoothMapConvoContactElement() { 9497e50993c70083fdedb4f1dd2c487aa55c6f60cfDavid Gross // TODO Auto-generated constructor stub 95e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 96e32af52d4be2bb80783404d99fa338b1143dbc9aDavid Gross 97e32af52d4be2bb80783404d99fa338b1143dbc9aDavid Gross public String getPresenceStatus() { 98e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return mPresenceStatus; 99e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 100e44a3525b9703739534c3b62d7d1af4c95649a38David Gross 101e44a3525b9703739534c3b62d7d1af4c95649a38David Gross public String getDisplayName() { 102e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return mDisplayName; 103e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 104e44a3525b9703739534c3b62d7d1af4c95649a38David Gross 105e44a3525b9703739534c3b62d7d1af4c95649a38David Gross public void setDisplayName(String displayName) { 106e44a3525b9703739534c3b62d7d1af4c95649a38David Gross this.mDisplayName = displayName; 107e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 108e44a3525b9703739534c3b62d7d1af4c95649a38David Gross 109e44a3525b9703739534c3b62d7d1af4c95649a38David Gross public void setPresenceStatus(String presenceStatus) { 110e44a3525b9703739534c3b62d7d1af4c95649a38David Gross this.mPresenceStatus = presenceStatus; 111e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 112e44a3525b9703739534c3b62d7d1af4c95649a38David Gross 113e44a3525b9703739534c3b62d7d1af4c95649a38David Gross public int getPresenceAvailability() { 114e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return mPresenceAvailability; 115e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 116e44a3525b9703739534c3b62d7d1af4c95649a38David Gross 117e44a3525b9703739534c3b62d7d1af4c95649a38David Gross public void setPresenceAvailability(int presenceAvailability) { 118e44a3525b9703739534c3b62d7d1af4c95649a38David Gross this.mPresenceAvailability = presenceAvailability; 119e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 120e44a3525b9703739534c3b62d7d1af4c95649a38David Gross 121e44a3525b9703739534c3b62d7d1af4c95649a38David Gross public int getPriority() { 122e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return mPriority; 12333cda5cf335afc6aa2dbe02062bc9e6649e1f87cDavid Gross } 124bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes 125bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes public void setPriority(int priority) { 126bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes this.mPriority = priority; 127bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes } 1284e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala 1294e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala public String getName() { 1304e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala return mName; 131bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes } 1329fa4d4480252ecfe08c97bc35888360b1e19ec99David Gross 133e32af52d4be2bb80783404d99fa338b1143dbc9aDavid Gross public void setName(String name) { 134db169187dea4602e4ad32058762d23d474753fd0Stephen Hines this.mName = name; 13597e50993c70083fdedb4f1dd2c487aa55c6f60cfDavid Gross } 13697e50993c70083fdedb4f1dd2c487aa55c6f60cfDavid Gross 13725eb586bb055ae07c7e82a2b1bdbd6936641580cStephen Hines public String getBtUid() { 13825eb586bb055ae07c7e82a2b1bdbd6936641580cStephen Hines return mBtUid.toHexString(); 13925eb586bb055ae07c7e82a2b1bdbd6936641580cStephen Hines } 140cc366e573e31f43a6101fd6e04b90c6afdc3b7a7Stephen Hines 1412b04086acbef6520ae2c54a868b1271abf053122Stephen Hines public void setBtUid(SignedLongLong btUid) { 1422b04086acbef6520ae2c54a868b1271abf053122Stephen Hines this.mBtUid = btUid; 1432b04086acbef6520ae2c54a868b1271abf053122Stephen Hines } 144bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes 145db169187dea4602e4ad32058762d23d474753fd0Stephen Hines public int getChatState() { 146bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes return mChatState; 147db169187dea4602e4ad32058762d23d474753fd0Stephen Hines } 148db169187dea4602e4ad32058762d23d474753fd0Stephen Hines 149db169187dea4602e4ad32058762d23d474753fd0Stephen Hines public void setChatState(int chatState) { 150bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes this.mChatState = chatState; 151bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes } 152db169187dea4602e4ad32058762d23d474753fd0Stephen Hines 153db169187dea4602e4ad32058762d23d474753fd0Stephen Hines public void setChatState(String chatState) { 154db169187dea4602e4ad32058762d23d474753fd0Stephen Hines this.mChatState = Integer.valueOf(chatState); 155db169187dea4602e4ad32058762d23d474753fd0Stephen Hines } 156db169187dea4602e4ad32058762d23d474753fd0Stephen Hines 157db169187dea4602e4ad32058762d23d474753fd0Stephen Hines 158db169187dea4602e4ad32058762d23d474753fd0Stephen Hines public String getLastActivityString() { 159db169187dea4602e4ad32058762d23d474753fd0Stephen Hines SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss"); 160db169187dea4602e4ad32058762d23d474753fd0Stephen Hines Date date = new Date(mLastActivity); 161db169187dea4602e4ad32058762d23d474753fd0Stephen Hines return format.format(date); // Format to YYYYMMDDTHHMMSS local time 162db169187dea4602e4ad32058762d23d474753fd0Stephen Hines } 1637ae3a828fade4e30f7940415949f33ac1f15dc77Stephen Hines 1647ae3a828fade4e30f7940415949f33ac1f15dc77Stephen Hines public void setLastActivity(long dateTime) { 1657ae3a828fade4e30f7940415949f33ac1f15dc77Stephen Hines this.mLastActivity = dateTime; 1667ae3a828fade4e30f7940415949f33ac1f15dc77Stephen Hines } 1676e9e89d1ed049ec931bb1000948c12698e6c5484Stephen Hines 168db169187dea4602e4ad32058762d23d474753fd0Stephen Hines public void setLastActivity(String lastActivity) throws ParseException { 169cc366e573e31f43a6101fd6e04b90c6afdc3b7a7Stephen Hines SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss"); 170cc366e573e31f43a6101fd6e04b90c6afdc3b7a7Stephen Hines Date date = format.parse(lastActivity); 171db169187dea4602e4ad32058762d23d474753fd0Stephen Hines this.mLastActivity = date.getTime(); 172900c6c1f08f7c572125d7d39abe0f0f9eafbfa14Chris Wailes } 1731bd9f627fa0affb457507e86b0b6684c695fe726Stephen Hines 1741bd9f627fa0affb457507e86b0b6684c695fe726Stephen Hines public void setContactId(String uci) { 1751bd9f627fa0affb457507e86b0b6684c695fe726Stephen Hines this.mUci = uci; 176db169187dea4602e4ad32058762d23d474753fd0Stephen Hines } 177db169187dea4602e4ad32058762d23d474753fd0Stephen Hines 178db169187dea4602e4ad32058762d23d474753fd0Stephen Hines public String getContactId(){ 179db169187dea4602e4ad32058762d23d474753fd0Stephen Hines return mUci; 180db169187dea4602e4ad32058762d23d474753fd0Stephen Hines } 181db169187dea4602e4ad32058762d23d474753fd0Stephen Hines 182db169187dea4602e4ad32058762d23d474753fd0Stephen Hines public int compareTo(BluetoothMapConvoContactElement e) { 183db169187dea4602e4ad32058762d23d474753fd0Stephen Hines if (this.mLastActivity < e.mLastActivity) { 184db169187dea4602e4ad32058762d23d474753fd0Stephen Hines return 1; 185db169187dea4602e4ad32058762d23d474753fd0Stephen Hines } else if (this.mLastActivity > e.mLastActivity) { 186db169187dea4602e4ad32058762d23d474753fd0Stephen Hines return -1; 187db169187dea4602e4ad32058762d23d474753fd0Stephen Hines } else { 188429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray return 0; 189429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray } 190429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray } 191429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray 192429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray /* Encode the MapConvoContactElement into the StringBuilder reference. 193429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray * Here we have taken the choice not to report empty attributes, to reduce the 194429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray * amount of data to be transfered over BT. */ 195429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray public void encode(XmlSerializer xmlConvoElement) 196429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray throws IllegalArgumentException, IllegalStateException, IOException 197429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray { 198429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray // construct the XML tag for a single contact in the convolisting element. 199429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray xmlConvoElement.startTag(null, XML_TAG_CONVOCONTACT); 200429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray if(mUci != null) { 201429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray xmlConvoElement.attribute(null, XML_ATT_UCI, mUci); 202429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray } 203429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray if(mDisplayName != null) { 204429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray xmlConvoElement.attribute(null, XML_ATT_DISPLAY_NAME, 205429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray BluetoothMapUtils.stripInvalidChars(mDisplayName)); 206429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray } 207429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray if(mName != null) { 208429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray xmlConvoElement.attribute(null, XML_ATT_NAME, 209429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray BluetoothMapUtils.stripInvalidChars(mName)); 210429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray } 211429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray if(mChatState != -1) { 212429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray xmlConvoElement.attribute(null, XML_ATT_CHAT_STATE, String.valueOf(mChatState)); 213429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray } 214429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray if(mLastActivity != -1) { 215429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray xmlConvoElement.attribute(null, XML_ATT_LAST_ACTIVITY, 216429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray this.getLastActivityString()); 217429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray } 218429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray if(mBtUid != null) { 219429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray xmlConvoElement.attribute(null, XML_ATT_X_BT_UID, mBtUid.toHexString()); 220429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray } 221429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray if(mPresenceAvailability != -1) { 222429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray xmlConvoElement.attribute(null, XML_ATT_PRESENCE_AVAILABILITY, 223429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray String.valueOf(mPresenceAvailability)); 224429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray } 2252b04086acbef6520ae2c54a868b1271abf053122Stephen Hines if(mPresenceStatus != null) { 2267b6629024395bf085ca64fcd5c69d2ded95e8d18Tobias Grosser xmlConvoElement.attribute(null, XML_ATT_PRESENCE_STATUS, mPresenceStatus); 2277b6629024395bf085ca64fcd5c69d2ded95e8d18Tobias Grosser } 2287b6629024395bf085ca64fcd5c69d2ded95e8d18Tobias Grosser if(mPriority != -1) { 2297b6629024395bf085ca64fcd5c69d2ded95e8d18Tobias Grosser xmlConvoElement.attribute(null, XML_ATT_PRIORITY, String.valueOf(mPriority)); 2307b6629024395bf085ca64fcd5c69d2ded95e8d18Tobias Grosser } 2317b6629024395bf085ca64fcd5c69d2ded95e8d18Tobias Grosser 232b730e239619a546d93e5926ea92d698ab77ec7f6Stephen Hines xmlConvoElement.endTag(null, XML_TAG_CONVOCONTACT); 2332b04086acbef6520ae2c54a868b1271abf053122Stephen Hines } 2342b04086acbef6520ae2c54a868b1271abf053122Stephen Hines 235bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes 2362b04086acbef6520ae2c54a868b1271abf053122Stephen Hines /** 237b730e239619a546d93e5926ea92d698ab77ec7f6Stephen Hines * Call this function to create a BluetoothMapConvoContactElement. Will consume the end-tag. 238bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes * @param parser must point into XML_TAG_CONVERSATION tag, hence attributes can be read. 2392b04086acbef6520ae2c54a868b1271abf053122Stephen Hines * @return 240bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes * @throws IOException 241429d94acbc64480d4f75233b66b4824cdc8b19c0Tim Murray * @throws XmlPullParserException 2422b04086acbef6520ae2c54a868b1271abf053122Stephen Hines */ 243b730e239619a546d93e5926ea92d698ab77ec7f6Stephen Hines public static BluetoothMapConvoContactElement createFromXml(XmlPullParser parser) 244bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes throws ParseException, XmlPullParserException, IOException { 2452b04086acbef6520ae2c54a868b1271abf053122Stephen Hines int count = parser.getAttributeCount(); 2462b04086acbef6520ae2c54a868b1271abf053122Stephen Hines BluetoothMapConvoContactElement newElement; 2472b04086acbef6520ae2c54a868b1271abf053122Stephen Hines if(count<1) { 2482b04086acbef6520ae2c54a868b1271abf053122Stephen Hines throw new IllegalArgumentException(XML_TAG_CONVOCONTACT + 2492b04086acbef6520ae2c54a868b1271abf053122Stephen Hines " is not decorated with attributes"); 2502b04086acbef6520ae2c54a868b1271abf053122Stephen Hines } 251097ca14d8b6908d0e5b7f8f38011cad4fb94bc26Chris Wailes newElement = new BluetoothMapConvoContactElement(); 252bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes for (int i = 0; i<count; i++) { 253e44a3525b9703739534c3b62d7d1af4c95649a38David Gross String attributeName = parser.getAttributeName(i).trim(); 254bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes String attributeValue = parser.getAttributeValue(i); 255e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if(attributeName.equalsIgnoreCase(XML_ATT_UCI)) { 256e44a3525b9703739534c3b62d7d1af4c95649a38David Gross newElement.mUci = attributeValue; 257e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } else if(attributeName.equalsIgnoreCase(XML_ATT_NAME)) { 258e44a3525b9703739534c3b62d7d1af4c95649a38David Gross newElement.mName = attributeValue; 259e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } else if(attributeName.equalsIgnoreCase(XML_ATT_DISPLAY_NAME)) { 260e44a3525b9703739534c3b62d7d1af4c95649a38David Gross newElement.mDisplayName = attributeValue; 261e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } else if(attributeName.equalsIgnoreCase(XML_ATT_CHAT_STATE)) { 262097ca14d8b6908d0e5b7f8f38011cad4fb94bc26Chris Wailes newElement.setChatState(attributeValue); 263097ca14d8b6908d0e5b7f8f38011cad4fb94bc26Chris Wailes } else if(attributeName.equalsIgnoreCase(XML_ATT_LAST_ACTIVITY)) { 264db169187dea4602e4ad32058762d23d474753fd0Stephen Hines newElement.setLastActivity(attributeValue); 265e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } else if(attributeName.equalsIgnoreCase(XML_ATT_X_BT_UID)) { 266e44a3525b9703739534c3b62d7d1af4c95649a38David Gross newElement.setBtUid(SignedLongLong.fromString(attributeValue)); 267db169187dea4602e4ad32058762d23d474753fd0Stephen Hines } else if(attributeName.equalsIgnoreCase(XML_ATT_PRESENCE_AVAILABILITY)) { 268db169187dea4602e4ad32058762d23d474753fd0Stephen Hines newElement.mPresenceAvailability = Integer.parseInt(attributeValue); 269e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } else if(attributeName.equalsIgnoreCase(XML_ATT_PRESENCE_STATUS)) { 270e44a3525b9703739534c3b62d7d1af4c95649a38David Gross newElement.setPresenceStatus(attributeValue); 271e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } else if(attributeName.equalsIgnoreCase(XML_ATT_PRIORITY)) { 272e44a3525b9703739534c3b62d7d1af4c95649a38David Gross newElement.setPriority(Integer.parseInt(attributeValue)); 273e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } else { 274e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if(D) Log.i(TAG,"Unknown XML attribute: " + parser.getAttributeName(i)); 275e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 276e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 277e44a3525b9703739534c3b62d7d1af4c95649a38David Gross parser.nextTag(); // Consume the end-tag 278e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return newElement; 279e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 280e44a3525b9703739534c3b62d7d1af4c95649a38David Gross 281e44a3525b9703739534c3b62d7d1af4c95649a38David Gross @Override 282e44a3525b9703739534c3b62d7d1af4c95649a38David Gross public boolean equals(Object obj) { 283e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if (this == obj) { 2841d93a190e62ec1588b4724ca8759216b2d0b76d7David Gross return true; 285e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 286e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if (obj == null) { 287e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return false; 288e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 289e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if (getClass() != obj.getClass()) { 290e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return false; 291e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 292e44a3525b9703739534c3b62d7d1af4c95649a38David Gross BluetoothMapConvoContactElement other = (BluetoothMapConvoContactElement) obj; 293e44a3525b9703739534c3b62d7d1af4c95649a38David Gross/* As we use equals only for test, we don't compare auto assigned values 294e44a3525b9703739534c3b62d7d1af4c95649a38David Gross * if (mBtUid == null) { 295e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if (other.mBtUid != null) { 296e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return false; 297e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 298e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } else if (!mBtUid.equals(other.mBtUid)) { 299e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return false; 300e44a3525b9703739534c3b62d7d1af4c95649a38David Gross }*/ 301e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if (mChatState != other.mChatState) { 302e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return false; 303e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 304e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if (mDisplayName == null) { 305e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if (other.mDisplayName != null) { 306e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return false; 307db169187dea4602e4ad32058762d23d474753fd0Stephen Hines } 3081d93a190e62ec1588b4724ca8759216b2d0b76d7David Gross } else if (!mDisplayName.equals(other.mDisplayName)) { 3091d93a190e62ec1588b4724ca8759216b2d0b76d7David Gross return false; 310db169187dea4602e4ad32058762d23d474753fd0Stephen Hines } 311e44a3525b9703739534c3b62d7d1af4c95649a38David Gross/* As we use equals only for test, we don't compare auto assigned values 312e44a3525b9703739534c3b62d7d1af4c95649a38David Gross * if (mId == null) { 313e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if (other.mId != null) { 314e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return false; 315e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 316e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } else if (!mId.equals(other.mId)) { 317e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return false; 318e44a3525b9703739534c3b62d7d1af4c95649a38David Gross }*/ 319e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if (mLastActivity != other.mLastActivity) { 320e44a3525b9703739534c3b62d7d1af4c95649a38David Gross return false; 321e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 322e32af52d4be2bb80783404d99fa338b1143dbc9aDavid Gross if (mName == null) { 323e44a3525b9703739534c3b62d7d1af4c95649a38David Gross if (other.mName != null) { 324bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes return false; 325bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes } 3264e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala } else if (!mName.equals(other.mName)) { 327bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes return false; 328e44a3525b9703739534c3b62d7d1af4c95649a38David Gross } 3294e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala if (mPresenceAvailability != other.mPresenceAvailability) { 3304e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala return false; 3314e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala } 3328ae4607d2dc5bc655d0c9225565d36ce2ebfc798Tobias Grosser if (mPresenceStatus == null) { 3338ae4607d2dc5bc655d0c9225565d36ce2ebfc798Tobias Grosser if (other.mPresenceStatus != null) { 3344e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala return false; 335357b58691936bef425bd315c13a2d8019d7e9c7eTobias Grosser } 336357b58691936bef425bd315c13a2d8019d7e9c7eTobias Grosser } else if (!mPresenceStatus.equals(other.mPresenceStatus)) { 337357b58691936bef425bd315c13a2d8019d7e9c7eTobias Grosser return false; 338357b58691936bef425bd315c13a2d8019d7e9c7eTobias Grosser } 3395010f641d1df6bc3447646ca7ef837410fb9b3dcChris Wailes if (mPriority != other.mPriority) { 340357b58691936bef425bd315c13a2d8019d7e9c7eTobias Grosser return false; 3414e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala } 342bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes return true; 3434e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala } 344bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes 345bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes} 3464e7a50685ae18a24087f6f2a51c604e71fab69e2Matt Wala 347bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes 348bdbff6e600b0d834e4770f65c7d2df93d7ef305cChris Wailes