Home | History | Annotate | Download | only in list
      1 /*
      2  * Copyright (C) 2007 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 package com.android.contacts.list;
     17 
     18 import android.view.View;
     19 import android.widget.ListView;
     20 
     21 import com.android.contacts.common.list.ContactListItemView;
     22 import com.android.contacts.widget.TextHighlightingAnimation;
     23 
     24 /**
     25  * A {@link TextHighlightingAnimation} that redraws just the contact display name in a
     26  * list item.
     27  */
     28 public class ContactNameHighlightingAnimation extends TextHighlightingAnimation {
     29     private final ListView mListView;
     30     private boolean mSavedScrollingCacheEnabledFlag;
     31 
     32     public ContactNameHighlightingAnimation(ListView listView, int duration) {
     33         super(duration);
     34         this.mListView = listView;
     35     }
     36 
     37     /**
     38      * Redraws all visible items of the list corresponding to contacts
     39      */
     40     @Override
     41     protected void invalidate() {
     42         int childCount = mListView.getChildCount();
     43         for (int i = 0; i < childCount; i++) {
     44             View itemView = mListView.getChildAt(i);
     45             if (itemView instanceof ContactListItemView) {
     46                 final ContactListItemView view = (ContactListItemView)itemView;
     47                 view.getNameTextView().invalidate();
     48             }
     49         }
     50     }
     51 
     52     @Override
     53     protected void onAnimationStarted() {
     54         mSavedScrollingCacheEnabledFlag = mListView.isScrollingCacheEnabled();
     55         mListView.setScrollingCacheEnabled(false);
     56     }
     57 
     58     @Override
     59     protected void onAnimationEnded() {
     60         mListView.setScrollingCacheEnabled(mSavedScrollingCacheEnabledFlag);
     61     }
     62 }
     63