1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.contacts.model.dataitem; 18 19 import android.content.ContentValues; 20 import android.provider.ContactsContract; 21 import android.provider.ContactsContract.CommonDataKinds.Email; 22 import android.provider.ContactsContract.CommonDataKinds.Im; 23 24 /** 25 * Represents an IM data item, wrapping the columns in 26 * {@link ContactsContract.CommonDataKinds.Im}. 27 */ 28 public class ImDataItem extends DataItem { 29 30 private final boolean mCreatedFromEmail; 31 32 /* package */ ImDataItem(ContentValues values) { 33 super(values); 34 mCreatedFromEmail = false; 35 } 36 37 private ImDataItem(ContentValues values, boolean createdFromEmail) { 38 super(values); 39 mCreatedFromEmail = createdFromEmail; 40 } 41 42 public static ImDataItem createFromEmail(EmailDataItem item) { 43 ImDataItem im = new ImDataItem(new ContentValues(item.getContentValues()), true); 44 im.setMimeType(Im.CONTENT_ITEM_TYPE); 45 return im; 46 } 47 48 public String getData() { 49 if (mCreatedFromEmail) { 50 return getContentValues().getAsString(Email.DATA); 51 } else { 52 return getContentValues().getAsString(Im.DATA); 53 } 54 } 55 56 /** 57 * Values are one of Im.TYPE_* 58 */ 59 public int getType() { 60 return getContentValues().getAsInteger(Im.TYPE); 61 } 62 63 public String getLabel() { 64 return getContentValues().getAsString(Im.LABEL); 65 } 66 67 /** 68 * Values are one of Im.PROTOCOL_ 69 */ 70 public Integer getProtocol() { 71 return getContentValues().getAsInteger(Im.PROTOCOL); 72 } 73 74 public boolean isProtocolValid() { 75 return getProtocol() != null; 76 } 77 78 public String getCustomProtocol() { 79 return getContentValues().getAsString(Im.CUSTOM_PROTOCOL); 80 } 81 82 public int getChatCapability() { 83 Integer result = getContentValues().getAsInteger(Im.CHAT_CAPABILITY); 84 return result == null ? 0 : result; 85 } 86 87 public boolean isCreatedFromEmail() { 88 return mCreatedFromEmail; 89 } 90 } 91