1 /*
2  * Copyright (C) 2016 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 
17 package com.android.dialer.app.list;
18 
19 import android.view.View;
20 import android.view.View.AccessibilityDelegate;
21 import android.view.ViewGroup;
22 import android.view.accessibility.AccessibilityEvent;
23 
24 /**
25  * AccessibilityDelegate that will filter out TYPE_WINDOW_CONTENT_CHANGED Used to suppress "Showing
26  * items x of y" from firing of ListView whenever it's content changes. AccessibilityEvent can only
27  * be rejected at a view's parent once it is generated, use addToParent() to add this delegate to
28  * the parent.
29  */
30 public class ContentChangedFilter extends AccessibilityDelegate {
31 
32   //the view we don't want TYPE_WINDOW_CONTENT_CHANGED to fire.
33   private View mView;
34 
ContentChangedFilter(View view)35   private ContentChangedFilter(View view) {
36     super();
37     mView = view;
38   }
39 
40   /** Add this delegate to the parent of @param view to filter out TYPE_WINDOW_CONTENT_CHANGED */
addToParent(View view)41   public static void addToParent(View view) {
42     View parent = (View) view.getParent();
43     parent.setAccessibilityDelegate(new ContentChangedFilter(view));
44   }
45 
46   @Override
onRequestSendAccessibilityEvent( ViewGroup host, View child, AccessibilityEvent event)47   public boolean onRequestSendAccessibilityEvent(
48       ViewGroup host, View child, AccessibilityEvent event) {
49     if (child == mView) {
50       if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
51         return false;
52       }
53     }
54     return super.onRequestSendAccessibilityEvent(host, child, event);
55   }
56 }
57