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 
17 package com.android.ex.chips.recipientchip;
18 
19 import com.android.ex.chips.RecipientEntry;
20 
21 import android.text.TextUtils;
22 
23 class 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 mDirectoryId;
31 
32     private final String mLookupKey;
33 
34     private final long mDataId;
35 
36     private final RecipientEntry mEntry;
37 
38     private boolean mSelected = false;
39 
40     private CharSequence mOriginalText;
41 
SimpleRecipientChip(final RecipientEntry entry)42     public SimpleRecipientChip(final RecipientEntry entry) {
43         mDisplay = entry.getDisplayName();
44         mValue = entry.getDestination().trim();
45         mContactId = entry.getContactId();
46         mDirectoryId = entry.getDirectoryId();
47         mLookupKey = entry.getLookupKey();
48         mDataId = entry.getDataId();
49         mEntry = entry;
50     }
51 
52     @Override
setSelected(final boolean selected)53     public void setSelected(final boolean selected) {
54         mSelected = selected;
55     }
56 
57     @Override
isSelected()58     public boolean isSelected() {
59         return mSelected;
60     }
61 
62     @Override
getDisplay()63     public CharSequence getDisplay() {
64         return mDisplay;
65     }
66 
67     @Override
getValue()68     public CharSequence getValue() {
69         return mValue;
70     }
71 
72     @Override
getContactId()73     public long getContactId() {
74         return mContactId;
75     }
76 
77     @Override
getDirectoryId()78     public Long getDirectoryId() {
79         return mDirectoryId;
80     }
81 
82     @Override
getLookupKey()83     public String getLookupKey() {
84         return mLookupKey;
85     }
86 
87     @Override
getDataId()88     public long getDataId() {
89         return mDataId;
90     }
91 
92     @Override
getEntry()93     public RecipientEntry getEntry() {
94         return mEntry;
95     }
96 
97     @Override
setOriginalText(final String text)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
getOriginalText()107     public CharSequence getOriginalText() {
108         return !TextUtils.isEmpty(mOriginalText) ? mOriginalText : mEntry.getDestination();
109     }
110 
111     @Override
toString()112     public String toString() {
113         return mDisplay + " <" + mValue + ">";
114     }
115 }