PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

/ime/latinime/src/com/googlecode/eyesfree/inputmethod/latin/tutorial/ContentButton.java

http://eyes-free.googlecode.com/
Java | 69 lines | 32 code | 9 blank | 28 comment | 4 complexity | c7e4a79e288eb7030f63521a3d2b31be MD5 | raw file
 1/*
 2 * Copyright (C) 2011 Google Inc.
 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.googlecode.eyesfree.inputmethod.latin.tutorial;
18
19import android.content.Context;
20import android.text.TextUtils;
21import android.util.AttributeSet;
22import android.view.View;
23import android.view.accessibility.AccessibilityEvent;
24import android.widget.Button;
25
26/**
27 * This class extends the {@link Button} widget by modifying the
28 * {@link Button#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} method
29 * and giving preference to the widget's content description. See
30 * {@link #setContentDescription(CharSequence)} for more on content
31 * descriptions.
32 *
33 * @author alanv@google.com (Alan Viverette)
34 */
35public class ContentButton extends Button {
36    public ContentButton(Context context) {
37        super(context);
38    }
39
40    public ContentButton(Context context, AttributeSet attrs) {
41        super(context, attrs);
42    }
43
44    public ContentButton(Context context, AttributeSet attrs, int defStyle) {
45        super(context, attrs, defStyle);
46    }
47
48    @Override
49    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
50        if (!isShown()) {
51            return false;
52        }
53
54        CharSequence content = getContentDescription();
55
56        // HACKHACK: If the content description has been set to an empty
57        // string, this will prevent TalkBack from speaking anything. We
58        // have to set the event type to _FOCUSED because _CLICKED events
59        // always speak "clicked".
60        if (content != null && TextUtils.isEmpty(content)) {
61            event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
62            event.setClassName(View.class.getName());
63            event.setPackageName(View.class.getPackage().getName());
64            return true;
65        }
66
67        return super.dispatchPopulateAccessibilityEvent(event);
68    }
69}