10a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp/* 2f1d0416bad440e015c8f09c3827acc19d939d71aScott Kennedy * Copyright (C) 2013 The Android Open Source Project 30a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * 40a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * Licensed under the Apache License, Version 2.0 (the "License"); 50a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * you may not use this file except in compliance with the License. 60a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * You may obtain a copy of the License at 70a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * 80a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * http://www.apache.org/licenses/LICENSE-2.0 90a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * 100a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * Unless required by applicable law or agreed to in writing, software 110a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * distributed under the License is distributed on an "AS IS" BASIS, 120a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * See the License for the specific language governing permissions and 140a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp * limitations under the License. 150a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp */ 160a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 17f1d0416bad440e015c8f09c3827acc19d939d71aScott Kennedypackage com.android.ex.chips.recipientchip; 18f1d0416bad440e015c8f09c3827acc19d939d71aScott Kennedy 19f1d0416bad440e015c8f09c3827acc19d939d71aScott Kennedyimport com.android.ex.chips.RecipientEntry; 200a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 210a9b6b9d977cb4a51a5920721eb3f594e35aca98mindypimport android.text.TextUtils; 220a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 23f1d0416bad440e015c8f09c3827acc19d939d71aScott Kennedyclass SimpleRecipientChip implements BaseRecipientChip { 240a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp private final CharSequence mDisplay; 250a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 260a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp private final CharSequence mValue; 270a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 280a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp private final long mContactId; 290a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 300a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp private final long mDataId; 310a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 32f1d0416bad440e015c8f09c3827acc19d939d71aScott Kennedy private final RecipientEntry mEntry; 330a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 340a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp private boolean mSelected = false; 350a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 360a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp private CharSequence mOriginalText; 370a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 38f1d0416bad440e015c8f09c3827acc19d939d71aScott Kennedy public SimpleRecipientChip(final RecipientEntry entry) { 390a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp mDisplay = entry.getDisplayName(); 400a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp mValue = entry.getDestination().trim(); 410a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp mContactId = entry.getContactId(); 420a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp mDataId = entry.getDataId(); 430a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp mEntry = entry; 440a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp } 450a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 46e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy @Override 47f1d0416bad440e015c8f09c3827acc19d939d71aScott Kennedy public void setSelected(final boolean selected) { 480a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp mSelected = selected; 490a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp } 500a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 51e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy @Override 520a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp public boolean isSelected() { 530a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp return mSelected; 540a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp } 550a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 56e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy @Override 570a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp public CharSequence getDisplay() { 580a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp return mDisplay; 590a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp } 600a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 61e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy @Override 620a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp public CharSequence getValue() { 630a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp return mValue; 640a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp } 650a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 66e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy @Override 670a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp public long getContactId() { 680a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp return mContactId; 690a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp } 700a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 71e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy @Override 720a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp public long getDataId() { 730a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp return mDataId; 740a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp } 750a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 76e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy @Override 770a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp public RecipientEntry getEntry() { 780a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp return mEntry; 790a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp } 800a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 81e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy @Override 82f1d0416bad440e015c8f09c3827acc19d939d71aScott Kennedy public void setOriginalText(final String text) { 83e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy if (TextUtils.isEmpty(text)) { 84e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy mOriginalText = text; 85e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy } else { 86e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy mOriginalText = text.trim(); 870a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp } 880a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp } 890a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 90e5d82228c1960115e31f67eb6a3a254d6902e3c5Scott Kennedy @Override 910a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp public CharSequence getOriginalText() { 920a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp return !TextUtils.isEmpty(mOriginalText) ? mOriginalText : mEntry.getDestination(); 930a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp } 940a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp 950a9b6b9d977cb4a51a5920721eb3f594e35aca98mindyp @Override 963e8176df16950c067bcb1b37e62b2fc07d74065aScott Kennedy public boolean isGalContact() { 973e8176df16950c067bcb1b37e62b2fc07d74065aScott Kennedy return mEntry.isGalContact(); 983e8176df16950c067bcb1b37e62b2fc07d74065aScott Kennedy } 993e8176df16950c067bcb1b37e62b2fc07d74065aScott Kennedy 1003e8176df16950c067bcb1b37e62b2fc07d74065aScott Kennedy @Override 101211ae63525c02ec914ef020af625ea4e7d8a3b29Scott Kennedy public String toString() { 102211ae63525c02ec914ef020af625ea4e7d8a3b29Scott Kennedy return mDisplay + " <" + mValue + ">"; 103211ae63525c02ec914ef020af625ea4e7d8a3b29Scott Kennedy } 104f1d0416bad440e015c8f09c3827acc19d939d71aScott Kennedy}