diff options
author | Alice Yang <alice@google.com> | 2013-03-13 17:18:52 -0700 |
---|---|---|
committer | Alice Yang <alice@google.com> | 2013-03-13 17:18:52 -0700 |
commit | 4aa10b1bc14290397756b05e97ff9bc8a3b7564b (patch) | |
tree | 0a82e828153f83190ab6b640644889ee56316c8e /chips/src/com/android/ex/chips/recipientchip | |
parent | 5ee4f94a5a4edfd18a69fbdc89786caec4cf3371 (diff) | |
parent | f1d0416bad440e015c8f09c3827acc19d939d71a (diff) | |
download | android_frameworks_ex-4aa10b1bc14290397756b05e97ff9bc8a3b7564b.tar.gz android_frameworks_ex-4aa10b1bc14290397756b05e97ff9bc8a3b7564b.tar.bz2 android_frameworks_ex-4aa10b1bc14290397756b05e97ff9bc8a3b7564b.zip |
Merge remote-tracking branch 'goog/jb-ub-mail-ur9' into merge
Merge UR8 into MR2.
Change-Id: Ia04852cf84c05ab2ee4898662d347a06d40e5f11
Diffstat (limited to 'chips/src/com/android/ex/chips/recipientchip')
5 files changed, 412 insertions, 0 deletions
diff --git a/chips/src/com/android/ex/chips/recipientchip/BaseRecipientChip.java b/chips/src/com/android/ex/chips/recipientchip/BaseRecipientChip.java new file mode 100644 index 0000000..a080ee7 --- /dev/null +++ b/chips/src/com/android/ex/chips/recipientchip/BaseRecipientChip.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ex.chips.recipientchip; + +import com.android.ex.chips.RecipientEntry; + +/** + * BaseRecipientChip defines an object that contains information relevant to a + * particular recipient. + */ +interface BaseRecipientChip { + + /** + * Set the selected state of the chip. + */ + void setSelected(boolean selected); + + /** + * Return true if the chip is selected. + */ + boolean isSelected(); + + /** + * Get the text displayed in the chip. + */ + CharSequence getDisplay(); + + /** + * Get the text value this chip represents. + */ + CharSequence getValue(); + + /** + * Get the id of the contact associated with this chip. + */ + long getContactId(); + + /** + * Get the id of the data associated with this chip. + */ + long getDataId(); + + /** + * Get associated RecipientEntry. + */ + RecipientEntry getEntry(); + + /** + * Set the text in the edittextview originally associated with this chip + * before any reverse lookups. + */ + void setOriginalText(String text); + + /** + * Set the text in the edittextview originally associated with this chip + * before any reverse lookups. + */ + CharSequence getOriginalText(); +} diff --git a/chips/src/com/android/ex/chips/recipientchip/DrawableRecipientChip.java b/chips/src/com/android/ex/chips/recipientchip/DrawableRecipientChip.java new file mode 100644 index 0000000..396a8ac --- /dev/null +++ b/chips/src/com/android/ex/chips/recipientchip/DrawableRecipientChip.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ex.chips.recipientchip; + +import android.graphics.Canvas; +import android.graphics.Rect; + +/** + * RecipientChip defines a drawable object that contains information relevant to a + * particular recipient. + */ +public interface DrawableRecipientChip extends BaseRecipientChip { + /** + * Get the bounds of the chip; may be 0,0 if it is not visibly rendered. + */ + Rect getBounds(); + + /** + * Draw the chip. + */ + void draw(Canvas canvas); +} diff --git a/chips/src/com/android/ex/chips/recipientchip/InvisibleRecipientChip.java b/chips/src/com/android/ex/chips/recipientchip/InvisibleRecipientChip.java new file mode 100644 index 0000000..0380a81 --- /dev/null +++ b/chips/src/com/android/ex/chips/recipientchip/InvisibleRecipientChip.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ex.chips.recipientchip; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Rect; +import android.text.style.ReplacementSpan; + +import com.android.ex.chips.RecipientEntry; + +/** + * RecipientChip defines a span that contains information relevant to a + * particular recipient. + */ +public class InvisibleRecipientChip extends ReplacementSpan implements DrawableRecipientChip { + private final SimpleRecipientChip mDelegate; + + public InvisibleRecipientChip(final RecipientEntry entry) { + super(); + + mDelegate = new SimpleRecipientChip(entry); + } + + @Override + public void setSelected(final boolean selected) { + mDelegate.setSelected(selected); + } + + @Override + public boolean isSelected() { + return mDelegate.isSelected(); + } + + @Override + public CharSequence getDisplay() { + return mDelegate.getDisplay(); + } + + @Override + public CharSequence getValue() { + return mDelegate.getValue(); + } + + @Override + public long getContactId() { + return mDelegate.getContactId(); + } + + @Override + public long getDataId() { + return mDelegate.getDataId(); + } + + @Override + public RecipientEntry getEntry() { + return mDelegate.getEntry(); + } + + @Override + public void setOriginalText(final String text) { + mDelegate.setOriginalText(text); + } + + @Override + public CharSequence getOriginalText() { + return mDelegate.getOriginalText(); + } + + @Override + public void draw(final Canvas canvas, final CharSequence text, final int start, final int end, + final float x, final int top, final int y, final int bottom, final Paint paint) { + // Do nothing. + } + + @Override + public int getSize(final Paint paint, final CharSequence text, final int start, final int end, + final Paint.FontMetricsInt fm) { + return 0; + } + + @Override + public Rect getBounds() { + return new Rect(0, 0, 0, 0); + } + + @Override + public void draw(final Canvas canvas) { + // do nothing. + } +} diff --git a/chips/src/com/android/ex/chips/recipientchip/SimpleRecipientChip.java b/chips/src/com/android/ex/chips/recipientchip/SimpleRecipientChip.java new file mode 100644 index 0000000..c04b3be --- /dev/null +++ b/chips/src/com/android/ex/chips/recipientchip/SimpleRecipientChip.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ex.chips.recipientchip; + +import com.android.ex.chips.RecipientEntry; + +import android.text.TextUtils; + +class SimpleRecipientChip implements BaseRecipientChip { + private final CharSequence mDisplay; + + private final CharSequence mValue; + + private final long mContactId; + + private final long mDataId; + + private final RecipientEntry mEntry; + + private boolean mSelected = false; + + private CharSequence mOriginalText; + + public SimpleRecipientChip(final RecipientEntry entry) { + mDisplay = entry.getDisplayName(); + mValue = entry.getDestination().trim(); + mContactId = entry.getContactId(); + mDataId = entry.getDataId(); + mEntry = entry; + } + + @Override + public void setSelected(final boolean selected) { + mSelected = selected; + } + + @Override + public boolean isSelected() { + return mSelected; + } + + @Override + public CharSequence getDisplay() { + return mDisplay; + } + + @Override + public CharSequence getValue() { + return mValue; + } + + @Override + public long getContactId() { + return mContactId; + } + + @Override + public long getDataId() { + return mDataId; + } + + @Override + public RecipientEntry getEntry() { + return mEntry; + } + + @Override + public void setOriginalText(final String text) { + if (TextUtils.isEmpty(text)) { + mOriginalText = text; + } else { + mOriginalText = text.trim(); + } + } + + @Override + public CharSequence getOriginalText() { + return !TextUtils.isEmpty(mOriginalText) ? mOriginalText : mEntry.getDestination(); + } + + @Override + public String toString() { + return mDisplay + " <" + mValue + ">"; + } +}
\ No newline at end of file diff --git a/chips/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java b/chips/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java new file mode 100644 index 0000000..acade7f --- /dev/null +++ b/chips/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ex.chips.recipientchip; + +import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.text.style.DynamicDrawableSpan; +import android.text.style.ImageSpan; + +import com.android.ex.chips.RecipientEntry; + +/** + * VisibleRecipientChip defines an ImageSpan that contains information relevant to a + * particular recipient and renders a background asset to go with it. + */ +public class VisibleRecipientChip extends ImageSpan implements DrawableRecipientChip { + private final SimpleRecipientChip mDelegate; + + public VisibleRecipientChip(final Drawable drawable, final RecipientEntry entry) { + super(drawable, DynamicDrawableSpan.ALIGN_BOTTOM); + + mDelegate = new SimpleRecipientChip(entry); + } + + @Override + public void setSelected(final boolean selected) { + mDelegate.setSelected(selected); + } + + @Override + public boolean isSelected() { + return mDelegate.isSelected(); + } + + @Override + public CharSequence getDisplay() { + return mDelegate.getDisplay(); + } + + @Override + public CharSequence getValue() { + return mDelegate.getValue(); + } + + @Override + public long getContactId() { + return mDelegate.getContactId(); + } + + @Override + public long getDataId() { + return mDelegate.getDataId(); + } + + @Override + public RecipientEntry getEntry() { + return mDelegate.getEntry(); + } + + @Override + public void setOriginalText(final String text) { + mDelegate.setOriginalText(text); + } + + @Override + public CharSequence getOriginalText() { + return mDelegate.getOriginalText(); + } + + @Override + public Rect getBounds() { + return getDrawable().getBounds(); + } + + @Override + public void draw(final Canvas canvas) { + getDrawable().draw(canvas); + } + + @Override + public String toString() { + return mDelegate.toString(); + } +} |