blob: 2172c5e5d6da42c73241f3cfe1e027de32258fd6 [file] [log] [blame]
Wenyi Wang1fc3ef42016-01-14 18:21:40 -08001/*
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
17package com.android.contacts.callblocking;
18
19import android.view.View;
20import android.view.View.AccessibilityDelegate;
21import android.view.ViewGroup;
22import android.view.accessibility.AccessibilityEvent;
23
24/**
25 * AccessibilityDelegate that will filter out TYPE_WINDOW_CONTENT_CHANGED
26 * Used to suppress "Showing items x of y" from firing of ListView whenever it's content changes.
27 * AccessibilityEvent can only be rejected at a view's parent once it is generated,
28 * use addToParent() to add this delegate to the parent.
29 */
30public class ContentChangedFilter extends AccessibilityDelegate {
31 //the view we don't want TYPE_WINDOW_CONTENT_CHANGED to fire.
32 private View mView;
33
34 /**
35 * Add this delegate to the parent of @param view to filter out TYPE_WINDOW_CONTENT_CHANGED
36 */
37 public static void addToParent(View view){
38 View parent = (View) view.getParent();
39 parent.setAccessibilityDelegate(new ContentChangedFilter(view));
40 }
41
42 private ContentChangedFilter(View view){
43 super();
44 mView = view;
45 }
46
47 @Override
48 public boolean onRequestSendAccessibilityEvent (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}