/TalkBack/src/com/google/android/marvin/talkback/AccessibilityEventCompatUtils.java

http://eyes-free.googlecode.com/ · Java · 52 lines · 16 code · 6 blank · 30 comment · 0 complexity · 8293a1dda6b90867c7811a12171344e5 MD5 · raw file

  1. /*
  2. * Copyright (C) 2011 Google Inc.
  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;
  17. import android.view.accessibility.AccessibilityEvent;
  18. import java.lang.reflect.Method;
  19. /**
  20. * Provides backward-compatible access to method in {@link AccessibilityEvent}.
  21. *
  22. * @author alanv@google.com (Alan Viverette)
  23. */
  24. public class AccessibilityEventCompatUtils {
  25. private static final Class<?> CLASS_AccessibilityEvent = AccessibilityEvent.class;
  26. private static final Method METHOD_getMaxScrollX = CompatUtils.getMethod(
  27. CLASS_AccessibilityEvent, "getMaxScrollX");
  28. private static final Method METHOD_getMaxScrollY = CompatUtils.getMethod(
  29. CLASS_AccessibilityEvent, "getMaxScrollY");
  30. /**
  31. * Gets the max scroll offset of the source left edge in pixels.
  32. *
  33. * @return The max scroll.
  34. */
  35. public static int getMaxScrollX(AccessibilityEvent receiver) {
  36. return (Integer) CompatUtils.invoke(receiver, -1, METHOD_getMaxScrollX);
  37. }
  38. /**
  39. * Gets the max scroll offset of the source top edge in pixels.
  40. *
  41. * @return The max scroll.
  42. */
  43. public static int getMaxScrollY(AccessibilityEvent receiver) {
  44. return (Integer) CompatUtils.invoke(receiver, -1, METHOD_getMaxScrollY);
  45. }
  46. }