PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://eyes-free.googlecode.com/
Java | 53 lines | 32 code | 10 blank | 11 comment | 8 complexity | 86fa5f43431f762fdeef63d55b731f6d MD5 | raw file
 1// Copyright 2011 Google Inc. All Rights Reserved.
 2
 3package com.google.marvin.talkingdialer;
 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}