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