1fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov/*
2fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov * Copyright (C) 2007 The Android Open Source Project
3fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov *
4fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov * Licensed under the Apache License, Version 2.0 (the "License");
5fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov * you may not use this file except in compliance with the License.
6fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov * You may obtain a copy of the License at
7fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov *
8fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov *      http://www.apache.org/licenses/LICENSE-2.0
9fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov *
10fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov * Unless required by applicable law or agreed to in writing, software
11fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov * distributed under the License is distributed on an "AS IS" BASIS,
12fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov * See the License for the specific language governing permissions and
14fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov * limitations under the License.
15fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov */
162ed21125970d986906ad3e55f1ab6f4d5ace364aDmitri Plotnikovpackage com.android.contacts.list;
17fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov
18fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikovimport android.view.View;
19fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikovimport android.widget.ListView;
20fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov
21a0233a048858f1593ea4924e9c5036f39aedbcddChiao Chengimport com.android.contacts.common.list.ContactListItemView;
22e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Chengimport com.android.contacts.widget.TextHighlightingAnimation;
23e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng
24fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov/**
25fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov * A {@link TextHighlightingAnimation} that redraws just the contact display name in a
26fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov * list item.
27fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov */
28fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikovpublic class ContactNameHighlightingAnimation extends TextHighlightingAnimation {
29fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    private final ListView mListView;
30d0567238d3c593caab88bb1c1892ccefa1d14ab5Dmitri Plotnikov    private boolean mSavedScrollingCacheEnabledFlag;
31fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov
32fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    public ContactNameHighlightingAnimation(ListView listView, int duration) {
33fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov        super(duration);
34fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov        this.mListView = listView;
35fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    }
36fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov
37fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    /**
38fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov     * Redraws all visible items of the list corresponding to contacts
39fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov     */
40fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    @Override
41fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    protected void invalidate() {
42fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov        int childCount = mListView.getChildCount();
43fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov        for (int i = 0; i < childCount; i++) {
44fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov            View itemView = mListView.getChildAt(i);
45fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov            if (itemView instanceof ContactListItemView) {
46fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov                final ContactListItemView view = (ContactListItemView)itemView;
47fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov                view.getNameTextView().invalidate();
48fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov            }
49fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov        }
50fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    }
51fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov
52fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    @Override
53fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    protected void onAnimationStarted() {
54d0567238d3c593caab88bb1c1892ccefa1d14ab5Dmitri Plotnikov        mSavedScrollingCacheEnabledFlag = mListView.isScrollingCacheEnabled();
55fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov        mListView.setScrollingCacheEnabled(false);
56fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    }
57fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov
58fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    @Override
59fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    protected void onAnimationEnded() {
60d0567238d3c593caab88bb1c1892ccefa1d14ab5Dmitri Plotnikov        mListView.setScrollingCacheEnabled(mSavedScrollingCacheEnabledFlag);
61fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov    }
62fda2edd3a6dc8dbdb2ae21e674f57ef3bd28f262Dmitri Plotnikov}
63