1 /* 2 * Copyright (C) 2011 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.ex.chips; 18 19 import android.graphics.drawable.Drawable; 20 import android.text.TextUtils; 21 import android.text.style.DynamicDrawableSpan; 22 import android.text.style.ImageSpan; 23 24 /** 25 * RecipientChip defines an ImageSpan that contains information relevant to a 26 * particular recipient. 27 */ 28 /* package */class RecipientChip extends ImageSpan { 29 private final CharSequence mDisplay; 30 31 private final CharSequence mValue; 32 33 private final long mContactId; 34 35 private final long mDataId; 36 37 private RecipientEntry mEntry; 38 39 private boolean mSelected = false; 40 41 private CharSequence mOriginalText; 42 43 public RecipientChip(Drawable drawable, RecipientEntry entry, int offset) { 44 super(drawable, DynamicDrawableSpan.ALIGN_BOTTOM); 45 mDisplay = entry.getDisplayName(); 46 mValue = entry.getDestination().trim(); 47 mContactId = entry.getContactId(); 48 mDataId = entry.getDataId(); 49 mEntry = entry; 50 } 51 52 /** 53 * Set the selected state of the chip. 54 * @param selected 55 */ 56 public void setSelected(boolean selected) { 57 mSelected = selected; 58 } 59 60 /** 61 * Return true if the chip is selected. 62 */ 63 public boolean isSelected() { 64 return mSelected; 65 } 66 67 /** 68 * Get the text displayed in the chip. 69 */ 70 public CharSequence getDisplay() { 71 return mDisplay; 72 } 73 74 /** 75 * Get the text value this chip represents. 76 */ 77 public CharSequence getValue() { 78 return mValue; 79 } 80 81 /** 82 * Get the id of the contact associated with this chip. 83 */ 84 public long getContactId() { 85 return mContactId; 86 } 87 88 /** 89 * Get the id of the data associated with this chip. 90 */ 91 public long getDataId() { 92 return mDataId; 93 } 94 95 /** 96 * Get associated RecipientEntry. 97 */ 98 public RecipientEntry getEntry() { 99 return mEntry; 100 } 101 102 public void setOriginalText(String text) { 103 if (!TextUtils.isEmpty(text)) { 104 text = text.trim(); 105 } 106 mOriginalText = text; 107 } 108 109 public CharSequence getOriginalText() { 110 return !TextUtils.isEmpty(mOriginalText) ? mOriginalText : mEntry.getDestination(); 111 } 112 } 113