Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
anastr committed Dec 20, 2016
1 parent e2eb995 commit 87b12ed
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 57 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Dynamic Speedometer, Gauge for Android. **amazing**, **powerful**, and _multi sh

`minSdkVersion=11`

Library Size just ~ 24 Kb.
Library Size just ~ 34 Kb.

[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-SpeedView-blue.svg?style=true)](https://android-arsenal.com/details/1/4169)
[![API](https://img.shields.io/badge/API-+11-red.svg?style=flat)](#)
Expand All @@ -14,6 +14,8 @@ Library Size just ~ 24 Kb.
<img src="/images/AwesomeSpeedometer.gif" width="30%" /><br/>
<img src="/images/RaySpeedometer.gif" width="30%" />
<img src="/images/PointerSpeedometer.gif" width="30%" />
<img src="/images/TubeSpeedometer.gif" width="30%" />
<img src="/images/ImageSpeedometer.gif" width="30%" />

# Download

Expand All @@ -22,7 +24,7 @@ Library Size just ~ 24 Kb.
```gradle
dependencies {
compile 'com.github.anastr:speedviewlib:1.1.1'
compile 'com.github.anastr:speedviewlib:1.1.2'
}
```
Expand All @@ -33,7 +35,7 @@ for **maven**
<dependency>
<groupId>com.github.anastr</groupId>
<artifactId>speedviewlib</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<type>pom</type>
</dependency>
```
Expand Down Expand Up @@ -66,7 +68,7 @@ for more control, see The most important methods at [Get Started - Wiki](https:/
and also you can see **advanced usage** in [Usage - Wiki](https://github.com/anastr/SpeedView/wiki/Usage) and [Work With Notes - Wiki](https://github.com/anastr/SpeedView/wiki/Notes).<br>
<img src="/images/usage/StartEndDegree.png" width="40%" />
<img src="/images/usage/WorkWithNote.gif" width="35%" />
we have 5 Speedometers : <br>
we have 7 Speedometers : <br>
======================
Name | Screenshot
--- | ---
Expand All @@ -75,6 +77,8 @@ Name | Screenshot
[3. AwesomeSpeedometer - Wiki](https://github.com/anastr/SpeedView/wiki/3.-AwesomeSpeedometer) | <img src="/images/AwesomeSpeedometer.png" width="25%" />
[4. RaySpeedometer - Wiki](https://github.com/anastr/SpeedView/wiki/4.-RaySpeedometer) | <img src="/images/RaySpeedometer.png" width="25%" />
[5. PointerSpeedometer - Wiki](https://github.com/anastr/SpeedView/wiki/5.-PointerSpeedometer) | <img src="/images/PointerSpeedometer.png" width="25%" />
[6. TubeSpeedometer - Wiki](https://github.com/anastr/SpeedView/wiki/6.-TubeSpeedometer) | <img src="/images/TubeSpeedometer.png" width="25%" />
[7. ImageSpeedometer - Wiki](https://github.com/anastr/SpeedView/wiki/7.-ImageSpeedometer) | <img src="/images/ImageSpeedometer.png" width="25%" />

## Coming Soon ...
i well try to draw this Speedometer.
Expand Down
Binary file added images/ImageSpeedometer.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ImageSpeedometer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/TubeSpeedometer.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/TubeSpeedometer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions speedviewlib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

group = 'com.github.anastr'
version = '1.1.1'
version = '1.1.2'

bintray {
user = properties.getProperty("bintray.user")
Expand All @@ -59,10 +59,10 @@ bintray {
name = 'SpeedView'

version {
name = '1.1.1'
name = '1.1.2'
desc = 'Speedometer UI for Android'
released = new Date()
vcsTag = '1.1.1'
vcsTag = '1.1.2'
}

licenses = ['Apache-2.0']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ private void initAttributeValue() {
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
super.onSizeChanged(w, h, oldW, oldH);

float risk = getSpeedometerWidth()/2f + padding;
float risk = getSpeedometerWidth()/2f + getPadding();
speedometerRect.set(risk, risk, w -risk, h -risk);

float markH = getHeightPa()/22f;
markPath.reset();
markPath.moveTo(w/2f, padding);
markPath.lineTo(w/2f, markH + padding);
markPath.moveTo(w/2f, getPadding());
markPath.lineTo(w/2f, markH + getPadding());
markPaint.setStrokeWidth(markH/5f);

trianglesPath.reset();
trianglesPath.moveTo(w/2f, padding + getHeightPa()/20f);
trianglesPath.lineTo(w/2f -(w/40f), padding);
trianglesPath.lineTo(w/2f +(w/40f), padding);
trianglesPath.moveTo(w/2f, getPadding() + getHeightPa()/20f);
trianglesPath.lineTo(w/2f -(w/40f), getPadding());
trianglesPath.lineTo(w/2f +(w/40f), getPadding());

updateGradient();
updateBackgroundBitmap();
Expand Down Expand Up @@ -151,7 +151,7 @@ protected Bitmap updateBackgroundBitmap() {
initDraw();
backgroundBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(backgroundBitmap);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - padding, circleBackPaint);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - getPadding(), circleBackPaint);

c.drawArc(speedometerRect, 0f, 360f, false, ringPaint);

Expand All @@ -162,7 +162,7 @@ protected Bitmap updateBackgroundBitmap() {
if (i % 40 == 0) {
c.drawPath(trianglesPath, trianglesPaint);
c.drawText(String.format(getLocale(), "%d", (int)getSpeedAtDegree(i + getStartDegree()))
, getWidth()/2f, getHeightPa()/20f +textPaint.getTextSize() + padding, textPaint);
, getWidth()/2f, getHeightPa()/20f +textPaint.getTextSize() + getPadding(), textPaint);
}
else {
if (i % 20 == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ private void initAttributeValue() {
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
super.onSizeChanged(w, h, oldW, oldH);

float risk = getSpeedometerWidth()/2f + padding;
float risk = getSpeedometerWidth()/2f + getPadding();
speedometerRect.set(risk, risk, w -risk, h -risk);

float markH = getHeightPa()/28f;
markPath.reset();
markPath.moveTo(w/2f, padding);
markPath.lineTo(w/2f, markH + padding);
markPath.moveTo(w/2f, getPadding());
markPath.lineTo(w/2f, markH + getPadding());
markPaint.setStrokeWidth(markH/3f);

float smallMarkH = getHeightPa()/20f;
smallMarkPath.reset();
smallMarkPath.moveTo(w/2f, getSpeedometerWidth() + padding);
smallMarkPath.lineTo(w/2f, getSpeedometerWidth() + padding + smallMarkH);
smallMarkPath.moveTo(w/2f, getSpeedometerWidth() + getPadding());
smallMarkPath.lineTo(w/2f, getSpeedometerWidth() + getPadding() + smallMarkH);
smallMarkPaint.setStrokeWidth(3);

updateBackgroundBitmap();
Expand All @@ -127,8 +127,8 @@ protected void onDraw(Canvas canvas) {
float speedTextPadding = dpTOpx(1);
float unitTextPadding = dpTOpx(1f);
float unitW = unitTextPadding + unitTextPaint.measureText(getUnit()) + 5;
speedBackgroundRect.top = getHeightPa()*.9f + padding - Math.max(speedTextPaint.getTextSize(), unitTextPaint.getTextSize());
speedBackgroundRect.bottom = getHeightPa()*.9f + padding + 4f;
speedBackgroundRect.top = getHeightPa()*.9f + getPadding() - Math.max(speedTextPaint.getTextSize(), unitTextPaint.getTextSize());
speedBackgroundRect.bottom = getHeightPa()*.9f + getPadding() + 4f;
if (isSpeedometerTextRightToLeft()) {
unitTextPaint.setTextAlign(Paint.Align.RIGHT);
speedBackgroundRect.left = getWidth()/2f - unitW;
Expand All @@ -146,9 +146,9 @@ protected void onDraw(Canvas canvas) {
canvas.drawRect(speedBackgroundRect, speedBackgroundPaint);

canvas.drawText(speedText
, getWidth()/2f - speedTextPadding, getHeightPa()*.9f + padding, speedTextPaint);
, getWidth()/2f - speedTextPadding, getHeightPa()*.9f + getPadding(), speedTextPaint);
canvas.drawText(getUnit()
, getWidth()/2f + unitTextPadding, getHeightPa()*.9f + padding, unitTextPaint);
, getWidth()/2f + unitTextPadding, getHeightPa()*.9f + getPadding(), unitTextPaint);

drawNotes(canvas);
}
Expand All @@ -160,7 +160,7 @@ protected Bitmap updateBackgroundBitmap() {
initDraw();
backgroundBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(backgroundBitmap);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - padding, circleBackPaint);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - getPadding(), circleBackPaint);

speedometerPaint.setColor(getHighSpeedColor());
c.drawArc(speedometerRect, getStartDegree(), getEndDegree()- getStartDegree(), false, speedometerPaint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void onDraw(Canvas canvas) {
else
speedTextPaint.setTextAlign(Paint.Align.RIGHT);
canvas.drawText(getSpeedText()
, getWidth()/2f - speedTextPadding, getHeightPa()*.9f + padding, speedTextPaint);
, getWidth()/2f - speedTextPadding, getHeightPa()*.9f + getPadding(), speedTextPaint);

drawNotes(canvas);
}
Expand All @@ -77,7 +77,7 @@ protected Bitmap updateBackgroundBitmap() {
return null;
backgroundBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(backgroundBitmap);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - padding, circleBackPaint);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - getPadding(), circleBackPaint);

if (imageSpeedometer != null) {
imageSpeedometer.setBounds(getPadding(), getPadding()
Expand All @@ -94,7 +94,7 @@ protected Bitmap updateBackgroundBitmap() {
unitTextPaint.setTextAlign(Paint.Align.LEFT);

c.drawText(getUnit()
, getWidth()/2f + unitTextPadding, getHeightPa()*.9f + padding, unitTextPaint);
, getWidth()/2f + unitTextPadding, getHeightPa()*.9f + getPadding(), unitTextPaint);

return backgroundBitmap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ private void initAttributeValue() {
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
super.onSizeChanged(w, h, oldW, oldH);

float risk = getSpeedometerWidth()/2f + dpTOpx(8) + padding;
float risk = getSpeedometerWidth()/2f + dpTOpx(8) + getPadding();
speedometerRect.set(risk, risk, w -risk, h -risk);

markPath.reset();
markPath.moveTo(w/2f, getSpeedometerWidth() + dpTOpx(8) + dpTOpx(4) + padding);
markPath.lineTo(w/2f, getSpeedometerWidth() + dpTOpx(8) + dpTOpx(4) + padding + w/60);
markPath.moveTo(w/2f, getSpeedometerWidth() + dpTOpx(8) + dpTOpx(4) + getPadding());
markPath.lineTo(w/2f, getSpeedometerWidth() + dpTOpx(8) + dpTOpx(4) + getPadding() + w/60);

updateRadial();
updateBackgroundBitmap();
Expand All @@ -123,9 +123,9 @@ protected void onDraw(Canvas canvas) {

canvas.save();
canvas.rotate(90 + getDegree(), getWidth()/2f, getHeight()/2f);
canvas.drawCircle(getWidth()/2f, getSpeedometerWidth()/2f + dpTOpx(8) + padding
canvas.drawCircle(getWidth()/2f, getSpeedometerWidth()/2f + dpTOpx(8) + getPadding()
, getSpeedometerWidth()/2f + dpTOpx(8), pointerBackPaint);
canvas.drawCircle(getWidth()/2f, getSpeedometerWidth()/2f + dpTOpx(8) + padding
canvas.drawCircle(getWidth()/2f, getSpeedometerWidth()/2f + dpTOpx(8) + getPadding()
, getSpeedometerWidth()/2f + dpTOpx(1), pointerPaint);
canvas.restore();

Expand All @@ -146,7 +146,7 @@ protected void onDraw(Canvas canvas) {
else
speedTextPaint.setTextAlign(Paint.Align.RIGHT);
canvas.drawText(getSpeedText()
, getWidth()/2f - speedTextPadding, getHeightPa()*.9f + padding, speedTextPaint);
, getWidth()/2f - speedTextPadding, getHeightPa()*.9f + getPadding(), speedTextPaint);

drawNotes(canvas);
}
Expand All @@ -158,7 +158,7 @@ protected Bitmap updateBackgroundBitmap() {
initDraw();
backgroundBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(backgroundBitmap);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - padding, circleBackPaint);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - getPadding(), circleBackPaint);

c.save();
c.rotate(90f + getStartDegree(), getWidth()/2f, getHeight()/2f);
Expand All @@ -180,7 +180,7 @@ protected Bitmap updateBackgroundBitmap() {
unitTextPaint.setTextAlign(Paint.Align.LEFT);

c.drawText(getUnit()
, getWidth()/2f + unitTextPadding, getHeightPa()*.9f + padding, unitTextPaint);
, getWidth()/2f + unitTextPadding, getHeightPa()*.9f + getPadding(), unitTextPaint);

return backgroundBitmap;
}
Expand All @@ -203,7 +203,7 @@ private SweepGradient updateSweep() {
private void updateRadial() {
int centerColor = Color.argb(160, Color.red(pointerColor), Color.green(pointerColor), Color.blue(pointerColor));
int edgeColor = Color.argb(10, Color.red(pointerColor), Color.green(pointerColor), Color.blue(pointerColor));
RadialGradient pointerGradient = new RadialGradient(getWidth()/2f, getSpeedometerWidth()/2f + dpTOpx(8) + padding
RadialGradient pointerGradient = new RadialGradient(getWidth()/2f, getSpeedometerWidth()/2f + dpTOpx(8) + getPadding()
, getSpeedometerWidth()/2f + dpTOpx(8), new int[]{centerColor, edgeColor}
, new float[]{.4f, 1f}, Shader.TileMode.CLAMP);
pointerBackPaint.setShader(pointerGradient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,22 @@ protected void onSizeChanged(int w, int h, int oldW, int oldH) {
speedometerRect.set(risk, risk, w -risk, h -risk);

markPath.reset();
markPath.moveTo(w/2f, padding);
markPath.lineTo(w/2f, getSpeedometerWidth() + padding);
markPath.moveTo(w/2f, getPadding());
markPath.lineTo(w/2f, getSpeedometerWidth() + getPadding());

ray1Path.reset();
ray1Path.moveTo(w/2f, h/2f);
ray1Path.lineTo(w/2f, getHeightPa()/3.2f + padding); ray1Path.moveTo(w/2f, getHeightPa()/3.2f + padding);
ray1Path.lineTo(w/2.2f, getHeightPa()/3f + padding); ray1Path.moveTo(w/2.2f, getHeightPa()/3f + padding);
ray1Path.lineTo(w/2.1f, getHeightPa()/4.5f + padding);
ray1Path.lineTo(w/2f, getHeightPa()/3.2f + getPadding());
ray1Path.moveTo(w/2f, getHeightPa()/3.2f + getPadding());
ray1Path.lineTo(w/2.2f, getHeightPa()/3f + getPadding());
ray1Path.moveTo(w/2.2f, getHeightPa()/3f + getPadding());
ray1Path.lineTo(w/2.1f, getHeightPa()/4.5f + getPadding());

ray2Path.reset();
ray2Path.moveTo(w/2f, h/2f);
ray2Path.lineTo(w/2f, getHeightPa()/3.2f + padding); ray2Path.moveTo(w/2f, getHeightPa()/3.2f + padding);
ray2Path.lineTo(w/2.2f, getHeightPa()/3.8f + padding); ray2Path.moveTo(w/2f, getHeightPa()/3.2f + padding);
ray2Path.lineTo(w/1.8f, getHeightPa()/3.8f + padding);
ray2Path.lineTo(w/2f, getHeightPa()/3.2f + getPadding()); ray2Path.moveTo(w/2f, getHeightPa()/3.2f + getPadding());
ray2Path.lineTo(w/2.2f, getHeightPa()/3.8f + getPadding()); ray2Path.moveTo(w/2f, getHeightPa()/3.2f + getPadding());
ray2Path.lineTo(w/1.8f, getHeightPa()/3.8f + getPadding());

updateBackgroundBitmap();
}
Expand Down Expand Up @@ -179,7 +181,7 @@ protected Bitmap updateBackgroundBitmap() {
return null;
backgroundBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(backgroundBitmap);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - padding, circleBackPaint);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - getPadding(), circleBackPaint);

c.save();
for (int i=0; i<6; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ private void init() {
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
super.onSizeChanged(w, h, oldW, oldH);

float risk = getSpeedometerWidth()/2f + padding;
float risk = getSpeedometerWidth()/2f + getPadding();
speedometerRect.set(risk, risk, w -risk, h -risk);

float markH = getHeightPa()/28f;
markPath.reset();
markPath.moveTo(w/2f, padding);
markPath.lineTo(w/2f, markH + padding);
markPath.moveTo(w/2f, getPadding());
markPath.lineTo(w/2f, markH + getPadding());
markPaint.setStrokeWidth(markH/3f);

updateBackgroundBitmap();
Expand Down Expand Up @@ -85,7 +85,7 @@ protected void onDraw(Canvas canvas) {
else
speedTextPaint.setTextAlign(Paint.Align.RIGHT);
canvas.drawText(getSpeedText()
, getWidth()/2f - speedTextPadding, getHeightPa()*.9f + padding, speedTextPaint);
, getWidth()/2f - speedTextPadding, getHeightPa()*.9f + getPadding(), speedTextPaint);

drawNotes(canvas);
}
Expand All @@ -97,7 +97,7 @@ protected Bitmap updateBackgroundBitmap() {
initDraw();
backgroundBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(backgroundBitmap);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - padding, circleBackPaint);
c.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f - getPadding(), circleBackPaint);

speedometerPaint.setColor(getHighSpeedColor());
c.drawArc(speedometerRect, getStartDegree(), getEndDegree()- getStartDegree(), false, speedometerPaint);
Expand Down Expand Up @@ -128,7 +128,7 @@ protected Bitmap updateBackgroundBitmap() {
unitTextPaint.setTextAlign(Paint.Align.LEFT);

c.drawText(getUnit()
, getWidth()/2f + unitTextPadding, getHeightPa()*.9f + padding, unitTextPaint);
, getWidth()/2f + unitTextPadding, getHeightPa()*.9f + getPadding(), unitTextPaint);

return backgroundBitmap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;
Expand Down Expand Up @@ -106,7 +107,7 @@ public void onAnimationRepeat(Animator animation) {
/** to contain all drawing that doesn't change */
protected Bitmap backgroundBitmap;
protected Paint backgroundBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
protected int padding = 0;
private int padding = 0;

/** low speed area, started from {@link #startDegree} */
private int lowSpeedPercent = 60;
Expand Down Expand Up @@ -277,6 +278,9 @@ public float pxTOdp(float px) {

private void updatePadding() {
padding = Math.max(Math.max(getPaddingLeft(), getPaddingRight()), Math.max(getPaddingTop(), getPaddingBottom()));
super.setPadding(padding, padding, padding, padding);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
super.setPaddingRelative(padding, padding, padding, padding);
indicator.noticePaddingChange(padding);
}

Expand Down
Loading

0 comments on commit 87b12ed

Please sign in to comment.