/shell/src/com/google/marvin/shell/RunButton.java

http://eyes-free.googlecode.com/ · Java · 53 lines · 32 code · 10 blank · 11 comment · 8 complexity · 3ba49f3ac1487170affa049afc287f64 MD5 · raw file

  1. // Copyright 2011 Google Inc. All Rights Reserved.
  2. package com.google.marvin.shell;
  3. import android.content.Context;
  4. import android.util.AttributeSet;
  5. import android.view.MotionEvent;
  6. import android.widget.Button;
  7. import com.googlecode.eyesfree.utils.compat.MotionEventCompatUtils;
  8. /**
  9. * Standard button but with an OnHoverListener for compatibility with pre-ICS
  10. * devices.
  11. *
  12. * @author clchen@google.com (Charles Chen)
  13. */
  14. public class RunButton extends Button {
  15. public interface OnHoverListener {
  16. public void onHoverEnter();
  17. public void onHoverExit();
  18. }
  19. private OnHoverListener cb;
  20. /**
  21. * @param context
  22. * @param attrs
  23. */
  24. public RunButton(Context context, AttributeSet attrs) {
  25. super(context, attrs);
  26. }
  27. public void setOnHoverListener(OnHoverListener callback) {
  28. cb = callback;
  29. }
  30. public boolean onHoverEvent(MotionEvent event) {
  31. if (event.getAction() == MotionEventCompatUtils.ACTION_HOVER_ENTER) {
  32. if (cb != null) {
  33. cb.onHoverEnter();
  34. }
  35. }
  36. if (event.getAction() == MotionEventCompatUtils.ACTION_HOVER_EXIT) {
  37. if (cb != null) {
  38. cb.onHoverExit();
  39. }
  40. }
  41. return true;
  42. }
  43. }