blob: 533f53f856eda8676b72da22b79403922a3cd8a4 [file] [log] [blame]
Scott Kennedy194d4272013-03-06 22:06:45 -08001/*
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
Scott Kennedy7a4e6772013-11-21 14:31:33 -080030 private final Long mDirectoryId;
31
32 private final String mLookupKey;
33
Scott Kennedy194d4272013-03-06 22:06:45 -080034 private final long mDataId;
35
36 private final RecipientEntry mEntry;
37
38 private boolean mSelected = false;
39
40 private CharSequence mOriginalText;
41
42 public SimpleRecipientChip(final RecipientEntry entry) {
43 mDisplay = entry.getDisplayName();
44 mValue = entry.getDestination().trim();
45 mContactId = entry.getContactId();
Scott Kennedy7a4e6772013-11-21 14:31:33 -080046 mDirectoryId = entry.getDirectoryId();
47 mLookupKey = entry.getLookupKey();
Scott Kennedy194d4272013-03-06 22:06:45 -080048 mDataId = entry.getDataId();
49 mEntry = entry;
50 }
51
52 @Override
53 public void setSelected(final boolean selected) {
54 mSelected = selected;
55 }
56
57 @Override
58 public boolean isSelected() {
59 return mSelected;
60 }
61
62 @Override
63 public CharSequence getDisplay() {
64 return mDisplay;
65 }
66
67 @Override
68 public CharSequence getValue() {
69 return mValue;
70 }
71
72 @Override
73 public long getContactId() {
74 return mContactId;
75 }
76
77 @Override
Scott Kennedy7a4e6772013-11-21 14:31:33 -080078 public Long getDirectoryId() {
79 return mDirectoryId;
80 }
81
82 @Override
83 public String getLookupKey() {
84 return mLookupKey;
85 }
86
87 @Override
Scott Kennedy194d4272013-03-06 22:06:45 -080088 public long getDataId() {
89 return mDataId;
90 }
91
92 @Override
93 public RecipientEntry getEntry() {
94 return mEntry;
95 }
96
97 @Override
98 public void setOriginalText(final String text) {
99 if (TextUtils.isEmpty(text)) {
100 mOriginalText = text;
101 } else {
102 mOriginalText = text.trim();
103 }
104 }
105
106 @Override
107 public CharSequence getOriginalText() {
108 return !TextUtils.isEmpty(mOriginalText) ? mOriginalText : mEntry.getDestination();
109 }
110
111 @Override
Scott Kennedy194d4272013-03-06 22:06:45 -0800112 public String toString() {
113 return mDisplay + " <" + mValue + ">";
114 }
115}