16a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp/* 2194d427ebcfc2133bda410e0e4c399250d9a6066Scott Kennedy * Copyright (C) 2013 The Android Open Source Project 36a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * 46a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * Licensed under the Apache License, Version 2.0 (the "License"); 56a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * you may not use this file except in compliance with the License. 66a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * You may obtain a copy of the License at 76a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * 86a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * http://www.apache.org/licenses/LICENSE-2.0 96a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * 106a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * Unless required by applicable law or agreed to in writing, software 116a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * distributed under the License is distributed on an "AS IS" BASIS, 126a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * See the License for the specific language governing permissions and 146a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp * limitations under the License. 156a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp */ 166a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 17194d427ebcfc2133bda410e0e4c399250d9a6066Scott Kennedypackage com.android.ex.chips.recipientchip; 18194d427ebcfc2133bda410e0e4c399250d9a6066Scott Kennedy 19194d427ebcfc2133bda410e0e4c399250d9a6066Scott Kennedyimport com.android.ex.chips.RecipientEntry; 206a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 216a8c8d837e53897f19539e0c2455e3d5fc579b5emindypimport android.text.TextUtils; 226a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 23194d427ebcfc2133bda410e0e4c399250d9a6066Scott Kennedyclass SimpleRecipientChip implements BaseRecipientChip { 246a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp private final CharSequence mDisplay; 256a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 266a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp private final CharSequence mValue; 276a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 286a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp private final long mContactId; 296a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 307a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy private final Long mDirectoryId; 317a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy 327a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy private final String mLookupKey; 337a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy 346a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp private final long mDataId; 356a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 36194d427ebcfc2133bda410e0e4c399250d9a6066Scott Kennedy private final RecipientEntry mEntry; 376a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 386a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp private boolean mSelected = false; 396a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 406a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp private CharSequence mOriginalText; 416a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 42194d427ebcfc2133bda410e0e4c399250d9a6066Scott Kennedy public SimpleRecipientChip(final RecipientEntry entry) { 436a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp mDisplay = entry.getDisplayName(); 446a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp mValue = entry.getDestination().trim(); 456a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp mContactId = entry.getContactId(); 467a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy mDirectoryId = entry.getDirectoryId(); 477a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy mLookupKey = entry.getLookupKey(); 486a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp mDataId = entry.getDataId(); 496a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp mEntry = entry; 506a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp } 516a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 52f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy @Override 53194d427ebcfc2133bda410e0e4c399250d9a6066Scott Kennedy public void setSelected(final boolean selected) { 546a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp mSelected = selected; 556a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp } 566a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 57f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy @Override 586a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp public boolean isSelected() { 596a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp return mSelected; 606a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp } 616a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 62f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy @Override 636a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp public CharSequence getDisplay() { 646a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp return mDisplay; 656a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp } 666a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 67f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy @Override 686a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp public CharSequence getValue() { 696a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp return mValue; 706a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp } 716a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 72f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy @Override 736a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp public long getContactId() { 746a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp return mContactId; 756a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp } 766a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 77f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy @Override 787a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy public Long getDirectoryId() { 797a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy return mDirectoryId; 807a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy } 817a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy 827a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy @Override 837a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy public String getLookupKey() { 847a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy return mLookupKey; 857a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy } 867a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy 877a4e67708498ec46c2e9b3bad69d3807d88c064eScott Kennedy @Override 886a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp public long getDataId() { 896a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp return mDataId; 906a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp } 916a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 92f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy @Override 936a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp public RecipientEntry getEntry() { 946a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp return mEntry; 956a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp } 966a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 97f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy @Override 98194d427ebcfc2133bda410e0e4c399250d9a6066Scott Kennedy public void setOriginalText(final String text) { 99f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy if (TextUtils.isEmpty(text)) { 100f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy mOriginalText = text; 101f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy } else { 102f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy mOriginalText = text.trim(); 1036a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp } 1046a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp } 1056a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 106f7e202d8b83bfbd73ca47ba7843ebc4dd57c2fa4Scott Kennedy @Override 1076a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp public CharSequence getOriginalText() { 1086a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp return !TextUtils.isEmpty(mOriginalText) ? mOriginalText : mEntry.getDestination(); 1096a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp } 1106a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp 1116a8c8d837e53897f19539e0c2455e3d5fc579b5emindyp @Override 11278f38a09c9753c0ac1838ce0bfd3a6bc1a307ff7Scott Kennedy public String toString() { 11378f38a09c9753c0ac1838ce0bfd3a6bc1a307ff7Scott Kennedy return mDisplay + " <" + mValue + ">"; 11478f38a09c9753c0ac1838ce0bfd3a6bc1a307ff7Scott Kennedy } 115194d427ebcfc2133bda410e0e4c399250d9a6066Scott Kennedy}