• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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.printspooler.widget;
18 
19 import static android.view.accessibility.Flags.triStateChecked;
20 
21 import android.content.Context;
22 import android.util.AttributeSet;
23 import android.view.accessibility.AccessibilityEvent;
24 import android.view.accessibility.AccessibilityNodeInfo;
25 import android.widget.CompoundButton;
26 import android.widget.LinearLayout;
27 
28 /**
29  * This class represents the frame of page in the print preview list
30  * that contains the page and a footer.
31  */
32 public final class PreviewPageFrame extends LinearLayout {
PreviewPageFrame(Context context, AttributeSet attrs)33     public PreviewPageFrame(Context context, AttributeSet attrs) {
34         super(context, attrs);
35     }
36 
37     @Override
getAccessibilityClassName()38     public CharSequence getAccessibilityClassName() {
39         return CompoundButton.class.getName();
40     }
41 
42     @Override
performClick()43     public boolean performClick() {
44         final boolean result = super.performClick();
45         // This widget is incorrectly using the notion of "selection"
46         // to represent checked state. We can't send this event in
47         // setSelected() because setSelected() is called when this widget
48         // is not attached.
49         if (triStateChecked()) {
50             notifyViewAccessibilityStateChangedIfNeeded(
51                     AccessibilityEvent.CONTENT_CHANGE_TYPE_CHECKED);
52         }
53         return result;
54     }
55 
56     @Override
onInitializeAccessibilityEvent(AccessibilityEvent event)57     public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
58         super.onInitializeAccessibilityEvent(event);
59         event.setChecked(isSelected());
60     }
61 
62     @Override
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)63     public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
64         super.onInitializeAccessibilityNodeInfo(info);
65         info.setSelected(false);
66         info.setCheckable(true);
67         if (triStateChecked()) {
68             info.setChecked(isSelected() ? AccessibilityNodeInfo.CHECKED_STATE_TRUE :
69                     AccessibilityNodeInfo.CHECKED_STATE_FALSE);
70         } else {
71             info.setChecked(isSelected());
72         }
73     }
74 }
75