Home | History | Annotate | Download | only in dataitem
      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.common.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     public String getLabel() {
     57         return getContentValues().getAsString(Im.LABEL);
     58     }
     59 
     60     /**
     61      * Values are one of Im.PROTOCOL_
     62      */
     63     public Integer getProtocol() {
     64         return getContentValues().getAsInteger(Im.PROTOCOL);
     65     }
     66 
     67     public boolean isProtocolValid() {
     68         return getProtocol() != null;
     69     }
     70 
     71     public String getCustomProtocol() {
     72         return getContentValues().getAsString(Im.CUSTOM_PROTOCOL);
     73     }
     74 
     75     public int getChatCapability() {
     76         Integer result = getContentValues().getAsInteger(Im.CHAT_CAPABILITY);
     77         return result == null ? 0 : result;
     78     }
     79 
     80     public boolean isCreatedFromEmail() {
     81         return mCreatedFromEmail;
     82     }
     83 }
     84