Home | History | Annotate | Download | only in recipientchip
      1 /*
      2  * Copyright (C) 2011 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 android.graphics.Canvas;
     20 import android.graphics.Rect;
     21 import android.graphics.drawable.Drawable;
     22 import android.text.style.DynamicDrawableSpan;
     23 import android.text.style.ImageSpan;
     24 
     25 import com.android.ex.chips.RecipientEntry;
     26 
     27 /**
     28  * VisibleRecipientChip defines an ImageSpan that contains information relevant to a
     29  * particular recipient and renders a background asset to go with it.
     30  */
     31 public class VisibleRecipientChip extends ImageSpan implements DrawableRecipientChip {
     32     private final SimpleRecipientChip mDelegate;
     33 
     34     public VisibleRecipientChip(final Drawable drawable, final RecipientEntry entry) {
     35         super(drawable, DynamicDrawableSpan.ALIGN_BOTTOM);
     36 
     37         mDelegate = new SimpleRecipientChip(entry);
     38     }
     39 
     40     @Override
     41     public void setSelected(final boolean selected) {
     42         mDelegate.setSelected(selected);
     43     }
     44 
     45     @Override
     46     public boolean isSelected() {
     47         return mDelegate.isSelected();
     48     }
     49 
     50     @Override
     51     public CharSequence getDisplay() {
     52         return mDelegate.getDisplay();
     53     }
     54 
     55     @Override
     56     public CharSequence getValue() {
     57         return mDelegate.getValue();
     58     }
     59 
     60     @Override
     61     public long getContactId() {
     62         return mDelegate.getContactId();
     63     }
     64 
     65     @Override
     66     public long getDataId() {
     67         return mDelegate.getDataId();
     68     }
     69 
     70     @Override
     71     public RecipientEntry getEntry() {
     72         return mDelegate.getEntry();
     73     }
     74 
     75     @Override
     76     public void setOriginalText(final String text) {
     77         mDelegate.setOriginalText(text);
     78     }
     79 
     80     @Override
     81     public CharSequence getOriginalText() {
     82         return mDelegate.getOriginalText();
     83     }
     84 
     85     @Override
     86     public boolean isGalContact() {
     87         return mDelegate.isGalContact();
     88     }
     89 
     90     @Override
     91     public Rect getBounds() {
     92         return getDrawable().getBounds();
     93     }
     94 
     95     @Override
     96     public void draw(final Canvas canvas) {
     97         getDrawable().draw(canvas);
     98     }
     99 
    100     @Override
    101     public String toString() {
    102         return mDelegate.toString();
    103     }
    104 }
    105