Merge "Remove unused class: TextWithHighlightingAnimation"
diff --git a/src/com/android/contacts/list/ContactNameHighlightingAnimation.java b/src/com/android/contacts/list/ContactNameHighlightingAnimation.java
deleted file mode 100644
index 46fe88b..0000000
--- a/src/com/android/contacts/list/ContactNameHighlightingAnimation.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2007 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.contacts.list;
-
-import android.view.View;
-import android.widget.ListView;
-
-import com.android.contacts.common.list.ContactListItemView;
-import com.android.contacts.widget.TextHighlightingAnimation;
-
-/**
- * A {@link TextHighlightingAnimation} that redraws just the contact display name in a
- * list item.
- */
-public class ContactNameHighlightingAnimation extends TextHighlightingAnimation {
- private final ListView mListView;
- private boolean mSavedScrollingCacheEnabledFlag;
-
- public ContactNameHighlightingAnimation(ListView listView, int duration) {
- super(duration);
- this.mListView = listView;
- }
-
- /**
- * Redraws all visible items of the list corresponding to contacts
- */
- @Override
- protected void invalidate() {
- int childCount = mListView.getChildCount();
- for (int i = 0; i < childCount; i++) {
- View itemView = mListView.getChildAt(i);
- if (itemView instanceof ContactListItemView) {
- final ContactListItemView view = (ContactListItemView)itemView;
- view.getNameTextView().invalidate();
- }
- }
- }
-
- @Override
- protected void onAnimationStarted() {
- mSavedScrollingCacheEnabledFlag = mListView.isScrollingCacheEnabled();
- mListView.setScrollingCacheEnabled(false);
- }
-
- @Override
- protected void onAnimationEnded() {
- mListView.setScrollingCacheEnabled(mSavedScrollingCacheEnabledFlag);
- }
-}
diff --git a/src/com/android/contacts/widget/TextHighlightingAnimation.java b/src/com/android/contacts/widget/TextHighlightingAnimation.java
deleted file mode 100644
index d269276..0000000
--- a/src/com/android/contacts/widget/TextHighlightingAnimation.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright (C) 2010 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.contacts.widget;
-
-import android.database.CharArrayBuffer;
-import android.graphics.Color;
-import android.os.Handler;
-import android.text.TextPaint;
-import android.text.style.CharacterStyle;
-import android.view.animation.AccelerateInterpolator;
-import android.view.animation.DecelerateInterpolator;
-
-import com.android.contacts.common.format.FormatUtils;
-import com.android.internal.R;
-
-/**
- * An animation that alternately dims and brightens the non-highlighted portion of text.
- */
-public abstract class TextHighlightingAnimation implements Runnable, TextWithHighlightingFactory {
-
- private static final int MAX_ALPHA = 255;
- private static final int MIN_ALPHA = 50;
-
- private AccelerateInterpolator ACCELERATE_INTERPOLATOR = new AccelerateInterpolator();
- private DecelerateInterpolator DECELERATE_INTERPOLATOR = new DecelerateInterpolator();
-
- private final static DimmingSpan[] sEmptySpans = new DimmingSpan[0];
-
- /**
- * Frame rate expressed a number of millis between frames.
- */
- private static final long FRAME_RATE = 50;
-
- private DimmingSpan mDimmingSpan;
- private Handler mHandler;
- private boolean mAnimating;
- private boolean mDimming;
- private long mTargetTime;
- private final int mDuration;
-
- /**
- * A Spanned that highlights a part of text by dimming another part of that text.
- */
- public class TextWithHighlightingImpl implements TextWithHighlighting {
-
- private final DimmingSpan[] mSpans;
- private boolean mDimmingEnabled;
- private CharArrayBuffer mText;
- private int mDimmingSpanStart;
- private int mDimmingSpanEnd;
- private String mString;
-
- public TextWithHighlightingImpl() {
- mSpans = new DimmingSpan[] { mDimmingSpan };
- }
-
- public void setText(CharArrayBuffer baseText, CharArrayBuffer highlightedText) {
- mText = baseText;
-
- // TODO figure out a way to avoid string allocation
- mString = new String(mText.data, 0, mText.sizeCopied);
-
- int index = FormatUtils.overlapPoint(baseText, highlightedText);
-
- if (index == 0 || index == -1) {
- mDimmingEnabled = false;
- } else {
- mDimmingEnabled = true;
- mDimmingSpanStart = 0;
- mDimmingSpanEnd = index;
- }
- }
-
- @SuppressWarnings("unchecked")
- public <T> T[] getSpans(int start, int end, Class<T> type) {
- if (mDimmingEnabled) {
- return (T[])mSpans;
- } else {
- return (T[])sEmptySpans;
- }
- }
-
- public int getSpanStart(Object tag) {
- // We only have one span - no need to check the tag parameter
- return mDimmingSpanStart;
- }
-
- public int getSpanEnd(Object tag) {
- // We only have one span - no need to check the tag parameter
- return mDimmingSpanEnd;
- }
-
- public int getSpanFlags(Object tag) {
- // String is immutable - flags not needed
- return 0;
- }
-
- public int nextSpanTransition(int start, int limit, Class type) {
- // Never called since we only have one span
- return 0;
- }
-
- public char charAt(int index) {
- return mText.data[index];
- }
-
- public int length() {
- return mText.sizeCopied;
- }
-
- public CharSequence subSequence(int start, int end) {
- // Never called - implementing for completeness
- return new String(mText.data, start, end);
- }
-
- @Override
- public String toString() {
- return mString;
- }
- }
-
- /**
- * A Span that modifies alpha of the default foreground color.
- */
- private static class DimmingSpan extends CharacterStyle {
- private int mAlpha;
-
- public void setAlpha(int alpha) {
- mAlpha = alpha;
- }
-
- @Override
- public void updateDrawState(TextPaint ds) {
-
- // Only dim the text in the basic state; not selected, focused or pressed
- int[] states = ds.drawableState;
- if (states != null) {
- int count = states.length;
- for (int i = 0; i < count; i++) {
- switch (states[i]) {
- case R.attr.state_pressed:
- case R.attr.state_selected:
- case R.attr.state_focused:
- // We can simply return, because the supplied text
- // paint is already configured with defaults.
- return;
- }
- }
- }
-
- int color = ds.getColor();
- color = Color.argb(mAlpha, Color.red(color), Color.green(color), Color.blue(color));
- ds.setColor(color);
- }
- }
-
- /**
- * Constructor.
- */
- public TextHighlightingAnimation(int duration) {
- mDuration = duration;
- mHandler = new Handler();
- mDimmingSpan = new DimmingSpan();
- mDimmingSpan.setAlpha(MAX_ALPHA);
- }
-
- /**
- * Returns a Spanned that can be used by a text view to show text with highlighting.
- */
- public TextWithHighlightingImpl createTextWithHighlighting() {
- return new TextWithHighlightingImpl();
- }
-
- /**
- * Override and invalidate (redraw) TextViews showing {@link TextWithHighlightingImpl}.
- */
- protected abstract void invalidate();
-
- /**
- * Starts the highlighting animation, which will dim portions of text.
- */
- public void startHighlighting() {
- startAnimation(true);
- }
-
- /**
- * Starts un-highlighting animation, which will brighten the dimmed portions of text
- * to the brightness level of the rest of text.
- */
- public void stopHighlighting() {
- startAnimation(false);
- }
-
- /**
- * Called when the animation starts.
- */
- protected void onAnimationStarted() {
- }
-
- /**
- * Called when the animation has stopped.
- */
- protected void onAnimationEnded() {
- }
-
- private void startAnimation(boolean dim) {
- if (mDimming != dim) {
- mDimming = dim;
- long now = System.currentTimeMillis();
- if (!mAnimating) {
- mAnimating = true;
- mTargetTime = now + mDuration;
- onAnimationStarted();
- mHandler.post(this);
- } else {
-
- // If we have started dimming, reverse the direction and adjust the target
- // time accordingly.
- mTargetTime = (now + mDuration) - (mTargetTime - now);
- }
- }
- }
-
- /**
- * Animation step.
- */
- public void run() {
- long now = System.currentTimeMillis();
- long timeLeft = mTargetTime - now;
- if (timeLeft < 0) {
- mDimmingSpan.setAlpha(mDimming ? MIN_ALPHA : MAX_ALPHA);
- mAnimating = false;
- onAnimationEnded();
- return;
- }
-
- // Start=1, end=0
- float virtualTime = (float)timeLeft / mDuration;
- if (mDimming) {
- float interpolatedTime = DECELERATE_INTERPOLATOR.getInterpolation(virtualTime);
- mDimmingSpan.setAlpha((int)(MIN_ALPHA + (MAX_ALPHA-MIN_ALPHA) * interpolatedTime));
- } else {
- float interpolatedTime = ACCELERATE_INTERPOLATOR.getInterpolation(virtualTime);
- mDimmingSpan.setAlpha((int)(MIN_ALPHA + (MAX_ALPHA-MIN_ALPHA) * (1-interpolatedTime)));
- }
-
- invalidate();
-
- // Repeat
- mHandler.postDelayed(this, FRAME_RATE);
- }
-}
diff --git a/src/com/android/contacts/widget/TextWithHighlighting.java b/src/com/android/contacts/widget/TextWithHighlighting.java
deleted file mode 100644
index 3a32b02..0000000
--- a/src/com/android/contacts/widget/TextWithHighlighting.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2010 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.contacts.widget;
-
-import android.database.CharArrayBuffer;
-import android.text.Spanned;
-
-/**
- * A Spanned that highlights a part of text by dimming another part of that text.
- */
-public interface TextWithHighlighting extends Spanned {
- void setText(CharArrayBuffer baseText, CharArrayBuffer highlightedText);
-}
diff --git a/src/com/android/contacts/widget/TextWithHighlightingFactory.java b/src/com/android/contacts/widget/TextWithHighlightingFactory.java
deleted file mode 100644
index ee5744d..0000000
--- a/src/com/android/contacts/widget/TextWithHighlightingFactory.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2010 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.contacts.widget;
-
-/**
- * A factory for text fields with animated highlighting.
- */
-public interface TextWithHighlightingFactory {
- TextWithHighlighting createTextWithHighlighting();
-}
diff --git a/tests/src/com/android/contacts/format/TestTextWithHighlightingFactory.java b/tests/src/com/android/contacts/format/TestTextWithHighlightingFactory.java
deleted file mode 100644
index 9dbd364..0000000
--- a/tests/src/com/android/contacts/format/TestTextWithHighlightingFactory.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.contacts.format;
-
-import android.database.CharArrayBuffer;
-import android.graphics.Typeface;
-import android.test.suitebuilder.annotation.SmallTest;
-import android.text.SpannableStringBuilder;
-import android.text.style.StyleSpan;
-
-import com.android.contacts.widget.TextWithHighlighting;
-import com.android.contacts.widget.TextWithHighlightingFactory;
-
-/** A factory for {@link TextWithHighlighting} that wraps its parts in italics. */
-@SmallTest
-public final class TestTextWithHighlightingFactory implements TextWithHighlightingFactory {
- /** A {@link TextWithHighlighting} implementation that wraps its parts in italics. */
- private final static class TestTextWithHighlighting extends SpannableStringBuilder
- implements TextWithHighlighting {
- @Override
- public void setText(CharArrayBuffer baseText, CharArrayBuffer highlightedText) {
- append(new String(baseText.data, 0, baseText.sizeCopied));
- append(' ');
- append(new String(highlightedText.data, 0, highlightedText.sizeCopied));
- setSpan(new StyleSpan(Typeface.ITALIC), 0, baseText.sizeCopied, 0);
- setSpan(new StyleSpan(Typeface.ITALIC), baseText.sizeCopied + 1,
- baseText.sizeCopied + 1 + highlightedText.sizeCopied, 0);
- }
- }
-
- @Override
- public TextWithHighlighting createTextWithHighlighting() {
- return new TestTextWithHighlighting();
- }
-}