Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../img/srcFileCovDistChart9.png 32% of files have more coverage
48   141   19   6
18   94   0,4   4
8     2,38  
2    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  HorizontalSlider       Line # 35 48 19 87,8% 0.8783784
  HorizontalSlider.OnSliderChangeListener       Line # 45 0 0 - -1.0
 
No Tests
 
1    /*
2    This file is part of Subsonic.
3   
4    Subsonic is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8   
9    Subsonic is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU General Public License for more details.
13   
14    You should have received a copy of the GNU General Public License
15    along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
16   
17    Copyright 2009 (C) Sindre Mehus
18    */
19    package net.sourceforge.subsonic.androidapp.util;
20   
21    import android.content.Context;
22    import android.graphics.Bitmap;
23    import android.graphics.BitmapFactory;
24    import android.graphics.Canvas;
25    import android.util.AttributeSet;
26    import android.view.MotionEvent;
27    import android.view.View;
28    import android.widget.ProgressBar;
29    import net.sourceforge.subsonic.androidapp.R;
30   
31    /**
32    * @author Sindre Mehus
33    * @version $Id$
34    */
 
35    public class HorizontalSlider extends ProgressBar {
36   
37    private final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.slider_knob);
38    private boolean slidingEnabled;
39    private OnSliderChangeListener listener;
40    private static final int PADDING = 2;
41    private boolean sliding;
42    private int sliderPosition;
43    private int startPosition;
44   
 
45    public interface OnSliderChangeListener {
46    void onSliderChanged(View view, int position, boolean inProgress);
47    }
48   
 
49  0 toggle public HorizontalSlider(Context context, AttributeSet attrs, int defStyle) {
50  0 super(context, attrs, defStyle);
51    }
52   
 
53  6 toggle public HorizontalSlider(Context context, AttributeSet attrs) {
54  6 super(context, attrs, android.R.attr.progressBarStyleHorizontal);
55    }
56   
 
57  0 toggle public HorizontalSlider(Context context) {
58  0 super(context);
59    }
60   
 
61  216 toggle public void setSlidingEnabled(boolean slidingEnabled) {
62  216 if (this.slidingEnabled != slidingEnabled) {
63  10 this.slidingEnabled = slidingEnabled;
64  10 invalidate();
65    }
66    }
67   
 
68  0 toggle public boolean isSlidingEnabled() {
69  0 return slidingEnabled;
70    }
71   
 
72  6 toggle public void setOnSliderChangeListener(OnSliderChangeListener listener) {
73  6 this.listener = listener;
74    }
75   
 
76  204 toggle @Override
77    protected void onDraw(Canvas canvas) {
78  204 super.onDraw(canvas);
79   
80  204 int max = getMax();
81  204 if (!slidingEnabled || max == 0) {
82  66 return;
83    }
84   
85  138 int paddingLeft = getPaddingLeft();
86  138 int paddingRight = getPaddingRight();
87  138 int paddingTop = getPaddingTop();
88  138 int paddingBottom = getPaddingBottom();
89   
90  138 int w = getWidth() - paddingLeft - paddingRight;
91  138 int h = getHeight() - paddingTop - paddingBottom;
92  138 int position = sliding ? sliderPosition : getProgress();
93   
94  138 int bitmapWidth = bitmap.getWidth();
95  138 int bitmapHeight = bitmap.getWidth();
96  138 float x = paddingLeft + w * ((float) position / max) - bitmapWidth / 2.0F;
97  138 x = Math.max(x, paddingLeft);
98  138 x = Math.min(x, paddingLeft + w - bitmapWidth);
99  138 float y = paddingTop + h / 2.0F - bitmapHeight / 2.0F;
100   
101  138 canvas.drawBitmap(bitmap, x, y, null);
102    }
103   
 
104  63 toggle @Override
105    public boolean onTouchEvent(MotionEvent event) {
106  63 if (!slidingEnabled) {
107  3 return false;
108    }
109   
110  60 int action = event.getAction();
111   
112  60 if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE) {
113   
114  56 if (action == MotionEvent.ACTION_DOWN) {
115  4 sliding = true;
116  4 startPosition = getProgress();
117    }
118   
119  56 float x = event.getX() - PADDING;
120  56 float width = getWidth() - 2 * PADDING;
121  56 sliderPosition = Math.round((float) getMax() * (x / width));
122  56 sliderPosition = Math.max(sliderPosition, 0);
123   
124  56 setProgress(Math.min(startPosition, sliderPosition));
125  56 setSecondaryProgress(Math.max(startPosition, sliderPosition));
126  56 if (listener != null) {
127  56 listener.onSliderChanged(this, sliderPosition, true);
128    }
129   
130  4 } else if (action == MotionEvent.ACTION_UP) {
131  4 sliding = false;
132  4 setProgress(sliderPosition);
133  4 setSecondaryProgress(0);
134  4 if (listener != null) {
135  4 listener.onSliderChanged(this, sliderPosition, false);
136    }
137    }
138   
139  60 return true;
140    }
141    }