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