EMMA Coverage Report (generated Thu Aug 06 10:53:00 CEST 2015)
[all classes][net.mandaria.tippytipper.widgets]

COVERAGE SUMMARY FOR SOURCE FILE [NumberPickerButton.java]

nameclass, %method, %block, %line, %
NumberPickerButton.java100% (1/1)56%  (5/9)59%  (43/73)62%  (15/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NumberPickerButton100% (1/1)56%  (5/9)59%  (43/73)62%  (15/24)
NumberPickerButton (Context): void 0%   (0/1)0%   (0/4)0%   (0/2)
NumberPickerButton (Context, AttributeSet, int): void 0%   (0/1)0%   (0/6)0%   (0/2)
onKeyUp (int, KeyEvent): boolean 0%   (0/1)0%   (0/13)0%   (0/3)
onTrackballEvent (MotionEvent): boolean 0%   (0/1)0%   (0/7)0%   (0/2)
NumberPickerButton (Context, AttributeSet): void 100% (1/1)100% (5/5)100% (2/2)
cancelLongpress (): void 100% (1/1)100% (16/16)100% (5/5)
cancelLongpressIfRequired (MotionEvent): void 100% (1/1)100% (11/11)100% (4/4)
onTouchEvent (MotionEvent): boolean 100% (1/1)100% (7/7)100% (2/2)
setNumberPicker (NumberPicker): void 100% (1/1)100% (4/4)100% (2/2)

1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17package net.mandaria.tippytipper.widgets;
18 
19import net.mandaria.tippytipper.R;
20import android.content.Context;
21import android.util.AttributeSet;
22import android.view.KeyEvent;
23import android.view.MotionEvent;
24import android.widget.ImageButton;
25 
26/**
27 * This class exists purely to cancel long click events.
28 */
29public class NumberPickerButton extends ImageButton {
30 
31    private NumberPicker mNumberPicker;
32    
33    public NumberPickerButton(Context context, AttributeSet attrs,
34            int defStyle) {
35        super(context, attrs, defStyle);
36    }
37 
38    public NumberPickerButton(Context context, AttributeSet attrs) {
39        super(context, attrs);
40    }
41 
42    public NumberPickerButton(Context context) {
43        super(context);
44    }
45    
46    public void setNumberPicker(NumberPicker picker) {
47        mNumberPicker = picker;
48    }
49    
50    @Override
51    public boolean onTouchEvent(MotionEvent event) {
52        cancelLongpressIfRequired(event);
53        return super.onTouchEvent(event);
54    }
55    
56    @Override
57    public boolean onTrackballEvent(MotionEvent event) {
58        cancelLongpressIfRequired(event);
59        return super.onTrackballEvent(event);
60    }
61    
62    @Override
63    public boolean onKeyUp(int keyCode, KeyEvent event) {
64        if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
65                || (keyCode == KeyEvent.KEYCODE_ENTER)) {
66            cancelLongpress();
67        }
68        return super.onKeyUp(keyCode, event);
69    }
70    
71    private void cancelLongpressIfRequired(MotionEvent event) {
72        if ((event.getAction() == MotionEvent.ACTION_CANCEL)
73                || (event.getAction() == MotionEvent.ACTION_UP)) {
74            cancelLongpress();
75        }
76    }
77 
78    private void cancelLongpress() {
79        if (R.id.increment == getId()) {
80            mNumberPicker.cancelIncrement();
81        } else if (R.id.decrement == getId()) {
82            mNumberPicker.cancelDecrement();
83        }
84    }
85}

[all classes][net.mandaria.tippytipper.widgets]
EMMA 2.0.5312 (C) Vladimir Roubtsov