/TalkBack/src/com/google/android/marvin/talkback/speechrules/RuleSeekBar.java

http://eyes-free.googlecode.com/ · Java · 58 lines · 28 code · 10 blank · 20 comment · 3 complexity · 9339abca001dca1ad286fed99f65b075 MD5 · raw file

  1. /*
  2. * Copyright (C) 2011 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * 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, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.google.android.marvin.talkback.speechrules;
  17. import android.content.Context;
  18. import android.view.accessibility.AccessibilityEvent;
  19. import android.view.accessibility.AccessibilityNodeInfo;
  20. import com.google.android.marvin.talkback.AccessibilityNodeInfoUtils;
  21. import com.google.android.marvin.talkback.R;
  22. /**
  23. * Formats speech for SeekBar widgets.
  24. *
  25. * @author alanv@google.com (Alan Viverette)
  26. */
  27. public class RuleSeekBar extends RuleDefault {
  28. private static final String SEPARATOR = " ";
  29. @Override
  30. public boolean accept(AccessibilityNodeInfo node) {
  31. return AccessibilityNodeInfoUtils
  32. .nodeMatchesClassByType(node, android.widget.SeekBar.class);
  33. }
  34. @Override
  35. public CharSequence
  36. format(Context context, AccessibilityNodeInfo node, AccessibilityEvent event) {
  37. final StringBuilder output = new StringBuilder();
  38. final CharSequence text = super.format(context, node, event);
  39. output.append(context.getString(R.string.template_seek_bar, text));
  40. output.append(SEPARATOR);
  41. if ((event != null) && (event.getItemCount() > 0)) {
  42. final int percent = (100 * event.getCurrentItemIndex()) / event.getItemCount();
  43. output.append(context.getString(R.string.template_percent, percent));
  44. output.append(SEPARATOR);
  45. }
  46. return output;
  47. }
  48. }