SimpleRecipientChip.java revision 194d427ebcfc2133bda410e0e4c399250d9a6066
1/* 2 * Copyright (C) 2013 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 17package com.android.ex.chips.recipientchip; 18 19import com.android.ex.chips.RecipientEntry; 20 21import android.text.TextUtils; 22 23class SimpleRecipientChip implements BaseRecipientChip { 24 private final CharSequence mDisplay; 25 26 private final CharSequence mValue; 27 28 private final long mContactId; 29 30 private final long mDataId; 31 32 private final RecipientEntry mEntry; 33 34 private boolean mSelected = false; 35 36 private CharSequence mOriginalText; 37 38 public SimpleRecipientChip(final RecipientEntry entry) { 39 mDisplay = entry.getDisplayName(); 40 mValue = entry.getDestination().trim(); 41 mContactId = entry.getContactId(); 42 mDataId = entry.getDataId(); 43 mEntry = entry; 44 } 45 46 @Override 47 public void setSelected(final boolean selected) { 48 mSelected = selected; 49 } 50 51 @Override 52 public boolean isSelected() { 53 return mSelected; 54 } 55 56 @Override 57 public CharSequence getDisplay() { 58 return mDisplay; 59 } 60 61 @Override 62 public CharSequence getValue() { 63 return mValue; 64 } 65 66 @Override 67 public long getContactId() { 68 return mContactId; 69 } 70 71 @Override 72 public long getDataId() { 73 return mDataId; 74 } 75 76 @Override 77 public RecipientEntry getEntry() { 78 return mEntry; 79 } 80 81 @Override 82 public void setOriginalText(final String text) { 83 if (TextUtils.isEmpty(text)) { 84 mOriginalText = text; 85 } else { 86 mOriginalText = text.trim(); 87 } 88 } 89 90 @Override 91 public CharSequence getOriginalText() { 92 return !TextUtils.isEmpty(mOriginalText) ? mOriginalText : mEntry.getDestination(); 93 } 94 95 @Override 96 public String toString() { 97 return mDisplay + " <" + mValue + ">"; 98 } 99}