222 | * it should be between (0-20] ,else well be ignore. 223 | *
224 | * @param degreeBetweenMark degree between two marks. 225 | */ 226 | public void setDegreeBetweenMark(int degreeBetweenMark) { 227 | if (degreeBetweenMark <= 0 || degreeBetweenMark > 20) 228 | return; 229 | this.degreeBetweenMark = degreeBetweenMark; 230 | invalidate(); 231 | } 232 | 233 | public float getMarkWidth() { 234 | return markWidth; 235 | } 236 | 237 | public void setMarkWidth(float markWidth) { 238 | this.markWidth = markWidth; 239 | markPaint.setStrokeWidth(markWidth); 240 | invalidate(); 241 | } 242 | 243 | public int getRayColor() { 244 | return rayColor; 245 | } 246 | 247 | public void setRayColor(int rayColor) { 248 | this.rayColor = rayColor; 249 | rayPaint.setColor(rayColor); 250 | updateBackgroundBitmap(); 251 | invalidate(); 252 | } 253 | 254 | /** 255 | * this Speedometer doesn't use this method. 256 | * @return {@code Color.TRANSPARENT} always. 257 | */ 258 | @Deprecated 259 | @Override 260 | public int getIndicatorColor() { 261 | return Color.TRANSPARENT; 262 | } 263 | 264 | /** 265 | * this Speedometer doesn't use this method. 266 | * @param indicatorColor nothing. 267 | */ 268 | @Deprecated 269 | @Override 270 | public void setIndicatorColor(int indicatorColor) { 271 | } 272 | 273 | /** 274 | * this Speedometer doesn't use this method. 275 | * @return {@code Color.TRANSPARENT} always. 276 | */ 277 | @Deprecated 278 | @Override 279 | public int getCenterCircleColor() { 280 | return Color.TRANSPARENT; 281 | } 282 | 283 | /** 284 | * this Speedometer doesn't use this method. 285 | * @param centerCircleColor nothing. 286 | */ 287 | @Deprecated 288 | @Override 289 | public void setCenterCircleColor(int centerCircleColor) { 290 | } 291 | } 292 | -------------------------------------------------------------------------------- /BuleTouthDemo/speedviewlib/src/main/java/com/github/anastr/speedviewlib/SpeedView.java: -------------------------------------------------------------------------------- 1 | package com.github.anastr.speedviewlib; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.graphics.Path; 8 | import android.graphics.RectF; 9 | import android.util.AttributeSet; 10 | 11 | import com.github.anastr.speedviewlib.components.Indicators.NormalIndicator; 12 | 13 | /** 14 | * this Library build By Anas Altair 15 | * see it on GitHub 16 | */ 17 | public class SpeedView extends Speedometer { 18 | 19 | private Path markPath = new Path(); 20 | private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG), 21 | speedometerPaint = new Paint(Paint.ANTI_ALIAS_FLAG), 22 | markPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 23 | private RectF speedometerRect = new RectF(); 24 | 25 | public SpeedView(Context context) { 26 | this(context, null); 27 | } 28 | 29 | public SpeedView(Context context, AttributeSet attrs) { 30 | this(context, attrs, 0); 31 | } 32 | 33 | public SpeedView(Context context, AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | init(); 36 | } 37 | 38 | @Override 39 | protected void defaultValues() { 40 | super.setIndicator(new NormalIndicator(getContext())); 41 | super.setBackgroundCircleColor(Color.TRANSPARENT); 42 | } 43 | 44 | private void init() { 45 | speedometerPaint.setStyle(Paint.Style.STROKE); 46 | markPaint.setStyle(Paint.Style.STROKE); 47 | } 48 | 49 | @Override 50 | protected void onSizeChanged(int w, int h, int oldW, int oldH) { 51 | super.onSizeChanged(w, h, oldW, oldH); 52 | 53 | updateBackgroundBitmap(); 54 | } 55 | 56 | private void initDraw() { 57 | speedometerPaint.setStrokeWidth(getSpeedometerWidth()); 58 | markPaint.setColor(getMarkColor()); 59 | paint.setColor(getCenterCircleColor()); 60 | } 61 | 62 | @Override 63 | protected void onDraw(Canvas canvas) { 64 | super.onDraw(canvas); 65 | initDraw(); 66 | 67 | drawSpeedUnitText(canvas); 68 | 69 | drawIndicator(canvas); 70 | canvas.drawCircle(getSize()/2f, getSize()/2f, getWidthPa()/12f, paint); 71 | 72 | drawNotes(canvas); 73 | } 74 | 75 | @Override 76 | protected void updateBackgroundBitmap() { 77 | Canvas c = createBackgroundBitmapCanvas(); 78 | initDraw(); 79 | 80 | float markH = getSizePa()/28f; 81 | markPath.reset(); 82 | markPath.moveTo(getSize()/2f, getPadding()); 83 | markPath.lineTo(getSize()/2f, markH + getPadding()); 84 | markPaint.setStrokeWidth(markH/3f); 85 | 86 | float risk = getSpeedometerWidth()/2f + getPadding(); 87 | speedometerRect.set(risk, risk, getSize() -risk, getSize() -risk); 88 | 89 | speedometerPaint.setColor(getHighSpeedColor()); 90 | c.drawArc(speedometerRect, getStartDegree(), getEndDegree()- getStartDegree(), false, speedometerPaint); 91 | speedometerPaint.setColor(getMediumSpeedColor()); 92 | c.drawArc(speedometerRect, getStartDegree() 93 | , (getEndDegree()- getStartDegree())*getMediumSpeedOffset(), false, speedometerPaint); 94 | speedometerPaint.setColor(getLowSpeedColor()); 95 | c.drawArc(speedometerRect, getStartDegree() 96 | , (getEndDegree()- getStartDegree())*getLowSpeedOffset(), false, speedometerPaint); 97 | 98 | c.save(); 99 | c.rotate(90f + getStartDegree(), getSize()/2f, getSize()/2f); 100 | float everyDegree = (getEndDegree() - getStartDegree()) * .111f; 101 | for (float i = getStartDegree(); i < getEndDegree()-(2f*everyDegree); i+=everyDegree) { 102 | c.rotate(everyDegree, getSize()/2f, getSize()/2f); 103 | c.drawPath(markPath, markPaint); 104 | } 105 | c.restore(); 106 | 107 | drawDefMinMaxSpeedPosition(c); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /BuleTouthDemo/speedviewlib/src/main/java/com/github/anastr/speedviewlib/TubeSpeedometer.java: -------------------------------------------------------------------------------- 1 | package com.github.anastr.speedviewlib; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.EmbossMaskFilter; 8 | import android.graphics.Paint; 9 | import android.graphics.RectF; 10 | import android.os.Build; 11 | import android.util.AttributeSet; 12 | 13 | /** 14 | * this Library build By Anas Altair 15 | * see it on GitHub 16 | */ 17 | public class TubeSpeedometer extends Speedometer { 18 | 19 | private Paint tubePaint = new Paint(Paint.ANTI_ALIAS_FLAG) 20 | ,tubeBacPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 21 | private RectF speedometerRect = new RectF(); 22 | 23 | private int speedometerColor = Color.parseColor("#757575"); 24 | 25 | private boolean withEffects3D = true; 26 | 27 | public TubeSpeedometer(Context context) { 28 | this(context, null); 29 | } 30 | 31 | public TubeSpeedometer(Context context, AttributeSet attrs) { 32 | this(context, attrs, 0); 33 | } 34 | 35 | public TubeSpeedometer(Context context, AttributeSet attrs, int defStyleAttr) { 36 | super(context, attrs, defStyleAttr); 37 | init(); 38 | initAttributeSet(context, attrs); 39 | } 40 | 41 | @Override 42 | protected void defaultValues() { 43 | super.setLowSpeedColor(Color.parseColor("#00BCD4")); 44 | super.setMediumSpeedColor(Color.parseColor("#FFC107")); 45 | super.setHighSpeedColor(Color.parseColor("#F44336")); 46 | super.setSpeedometerWidth(dpTOpx(40f)); 47 | super.setBackgroundCircleColor(Color.TRANSPARENT); 48 | } 49 | 50 | private void init() { 51 | tubePaint.setStyle(Paint.Style.STROKE); 52 | tubeBacPaint.setStyle(Paint.Style.STROKE); 53 | 54 | if (Build.VERSION.SDK_INT >= 11) 55 | setLayerType(LAYER_TYPE_SOFTWARE, null); 56 | } 57 | 58 | private void initAttributeSet(Context context, AttributeSet attrs) { 59 | if (attrs == null) { 60 | initAttributeValue(); 61 | return; 62 | } 63 | TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AwesomeSpeedometer, 0, 0); 64 | 65 | speedometerColor = a.getColor(R.styleable.TubeSpeedometer_speedometerColor, speedometerColor); 66 | withEffects3D = a.getBoolean(R.styleable.TubeSpeedometer_withEffects3D, withEffects3D); 67 | a.recycle(); 68 | initAttributeValue(); 69 | } 70 | 71 | private void initAttributeValue() { 72 | tubeBacPaint.setColor(speedometerColor); 73 | tubePaint.setColor(getLowSpeedColor()); 74 | } 75 | 76 | @Override 77 | protected void onSizeChanged(int w, int h, int oldW, int oldH) { 78 | super.onSizeChanged(w, h, oldW, oldH); 79 | 80 | updateEmboss(); 81 | updateBackgroundBitmap(); 82 | } 83 | 84 | private void updateEmboss() { 85 | if (isInEditMode()) 86 | return; 87 | if (!withEffects3D) { 88 | tubePaint.setMaskFilter(null); 89 | tubeBacPaint.setMaskFilter(null); 90 | return; 91 | } 92 | EmbossMaskFilter embossMaskFilter = new EmbossMaskFilter( 93 | new float[] { .5f, 1f, 1f }, .6f, 3f, pxTOdp(getSpeedometerWidth())*.35f); 94 | tubePaint.setMaskFilter(embossMaskFilter); 95 | EmbossMaskFilter embossMaskFilterBac = new EmbossMaskFilter( 96 | new float[] { -.5f, -1f, 0f }, .6f, 1f, pxTOdp(getSpeedometerWidth())*.35f); 97 | tubeBacPaint.setMaskFilter(embossMaskFilterBac); 98 | } 99 | 100 | @Override 101 | protected void onSectionChangeEvent(byte oldSection, byte newSection) { 102 | super.onSectionChangeEvent(oldSection, newSection); 103 | if (newSection == LOW_SECTION) 104 | tubePaint.setColor(getLowSpeedColor()); 105 | else if (newSection == MEDIUM_SECTION) 106 | tubePaint.setColor(getMediumSpeedColor()); 107 | else 108 | tubePaint.setColor(getHighSpeedColor()); 109 | } 110 | 111 | private void initDraw() { 112 | tubePaint.setStrokeWidth(getSpeedometerWidth()); 113 | tubeBacPaint.setStrokeWidth(getSpeedometerWidth()); 114 | } 115 | 116 | @Override 117 | protected void onDraw(Canvas canvas) { 118 | super.onDraw(canvas); 119 | initDraw(); 120 | 121 | float sweepAngle = (getEndDegree() - getStartDegree())*getOffsetSpeed(); 122 | canvas.drawArc(speedometerRect, getStartDegree(), sweepAngle, false, tubePaint); 123 | 124 | drawSpeedUnitText(canvas); 125 | drawIndicator(canvas); 126 | drawNotes(canvas); 127 | } 128 | 129 | @Override 130 | protected void updateBackgroundBitmap() { 131 | Canvas c = createBackgroundBitmapCanvas(); 132 | initDraw(); 133 | 134 | float risk = getSpeedometerWidth()/2f + getPadding(); 135 | speedometerRect.set(risk, risk, getSize() -risk, getSize() -risk); 136 | 137 | c.drawArc(speedometerRect, getStartDegree(), getEndDegree()- getStartDegree(), false, tubeBacPaint); 138 | 139 | drawDefMinMaxSpeedPosition(c); 140 | } 141 | 142 | public int getSpeedometerColor() { 143 | return speedometerColor; 144 | } 145 | 146 | public void setSpeedometerColor(int speedometerColor) { 147 | this.speedometerColor = speedometerColor; 148 | updateBackgroundBitmap(); 149 | invalidate(); 150 | } 151 | 152 | public boolean isWithEffects3D() { 153 | return withEffects3D; 154 | } 155 | 156 | public void setWithEffects3D(boolean withEffects3D) { 157 | this.withEffects3D = withEffects3D; 158 | updateEmboss(); 159 | updateBackgroundBitmap(); 160 | invalidate(); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /BuleTouthDemo/speedviewlib/src/main/java/com/github/anastr/speedviewlib/components/Indicators/ImageIndicator.java: -------------------------------------------------------------------------------- 1 | package com.github.anastr.speedviewlib.components.Indicators; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.RectF; 8 | 9 | /** 10 | * this Library build By Anas Altair 11 | * see it on GitHub 12 | */ 13 | @SuppressWarnings("unused,WeakerAccess") 14 | public class ImageIndicator extends Indicator7 | * this Library build By Anas Altair 8 | * see it on GitHub 9 | */ 10 | public interface OnSectionChangeListener { 11 | /** 12 | * Notification that the section has changed. 13 | * 14 | * @param oldSection where indicator came from. 15 | * @param newSection where indicator move to. 16 | */ 17 | void onSectionChangeListener(byte oldSection, byte newSection); 18 | } 19 | -------------------------------------------------------------------------------- /BuleTouthDemo/speedviewlib/src/main/java/com/github/anastr/speedviewlib/util/OnSpeedChangeListener.java: -------------------------------------------------------------------------------- 1 | package com.github.anastr.speedviewlib.util; 2 | 3 | import com.github.anastr.speedviewlib.Speedometer; 4 | 5 | /** 6 | * A callback that notifies clients when the speed has been 7 | * changed (just when speed change in integer). 8 | *
9 | * this Library build By Anas Altair
10 | * see it on GitHub
11 | */
12 | public interface OnSpeedChangeListener {
13 | /**
14 | * Notification that the speed has changed.
15 | *
16 | * @param speedometer the speedometer who change.
17 | * @param isSpeedUp if speed increase.
18 | * @param isByTremble true if speed has changed by Tremble.
19 | */
20 | void onSpeedChange(Speedometer speedometer, boolean isSpeedUp, boolean isByTremble);
21 | }
22 |
--------------------------------------------------------------------------------
/BuleTouthDemo/speedviewlib/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |