Home | History | Annotate | Download | only in list
      1 package com.android.dialer.list;
      2 
      3 import android.view.View;
      4 import android.view.View.AccessibilityDelegate;
      5 import android.view.ViewGroup;
      6 import android.view.accessibility.AccessibilityEvent;
      7 
      8 /**
      9  * AccessibilityDelegate that will filter out TYPE_WINDOW_CONTENT_CHANGED
     10  * Used to suppress "Showing items x of y" from firing of ListView whenever it's content changes.
     11  * AccessibilityEvent can only be rejected at a view's parent once it is generated,
     12  * use addToParent() to add this delegate to the parent.
     13  */
     14 public class ContentChangedFilter extends AccessibilityDelegate {
     15   //the view we don't want TYPE_WINDOW_CONTENT_CHANGED to fire.
     16   private View mView;
     17 
     18   /**
     19    * Add this delegate to the parent of @param view to filter out TYPE_WINDOW_CONTENT_CHANGED
     20    */
     21   public static void addToParent(View view){
     22     View parent = (View) view.getParent();
     23     parent.setAccessibilityDelegate(new ContentChangedFilter(view));
     24   }
     25 
     26   private ContentChangedFilter(View view){
     27     super();
     28     mView = view;
     29   }
     30   @Override
     31   public boolean onRequestSendAccessibilityEvent (ViewGroup host, View child, AccessibilityEvent event){
     32     if(child == mView){
     33       if(event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED){
     34         return false;
     35       }
     36     }
     37     return super.onRequestSendAccessibilityEvent(host,child,event);
     38   }
     39 
     40 }
     41