Skip to content

Commit

Permalink
Add option to change Gauge Background color
Browse files Browse the repository at this point in the history
Add option to enable/disable animation of needle in Half Gauge view
  • Loading branch information
Gruzer committed Jul 10, 2020
1 parent 4fd21fb commit 8df7310
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ fastlane/readme.md
.idea/copyright/Evstafiev_Konstantin_Apache2_0.xml
.idea/misc.xml
.idea/modules.xml
.idea/jarRepositories.xml
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class AbstractGauge extends View {
private double maxValue = 100;
private Paint needleColor;
private Paint gaugeBackGround;
private int gaugeBGColor = Color.parseColor("#EAEAEA");
private Paint textPaint;
private float rectTop = 0;
private float rectLeft = 0;
Expand Down Expand Up @@ -123,7 +124,7 @@ protected Paint getNeedlePaint() {
protected Paint getGaugeBackGround() {
if (gaugeBackGround == null) {
gaugeBackGround = new Paint();
gaugeBackGround.setColor(Color.parseColor("#EAEAEA"));
gaugeBackGround.setColor(gaugeBGColor);
gaugeBackGround.setAntiAlias(true);
gaugeBackGround.setStyle(Paint.Style.STROKE);
// gaugeBackGround.setShadowLayer(15.0f,0f,5.0f,0X50000000);
Expand Down Expand Up @@ -181,10 +182,10 @@ protected int getCalculateValuePercentage(double min, double max, double value)
return getCalculateValuePercentageUseCaseOne(min, max, value);
} else if (min < 0 && max < 0 && min > max) {
return getCalculateValuePercentageUseCaseTwo(min, max, value);
} else if ((min>=0 && max<0) || (min<0 && max >=0)) {
} else if ((min >= 0 && max < 0) || (min < 0 && max >= 0)) {
if (min > max) {
return getCalculateValuePercentageUseCaseThree(min, max, value);
} else if(min < max) {
} else if (min < max) {
return getCalculateValuePercentageUseCaseFoure(min, max, value);
}

Expand Down Expand Up @@ -359,4 +360,14 @@ public boolean isUseRangeBGColor() {
public void setUseRangeBGColor(boolean useRangeBGColor) {
this.useRangeBGColor = useRangeBGColor;
}

public void setGaugeBackGroundColor(int color) {
this.gaugeBackGround.setColor(color);
this.gaugeBGColor = color;
}

public int getGaugeBackgroundColor(){
return this.gaugeBGColor;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class HalfGauge extends AbstractGauge {
private Handler handler = new Handler();
private boolean enableBackGroundShadow = true;
private boolean enableNeedleShadow = true;
private boolean enableAnimation = true;


private Runnable runnable = new Runnable() {
Expand Down Expand Up @@ -171,7 +172,7 @@ private float calculateSweepAngle(double from, double to) {
}

public int getNeedleAngle() {
if (needleAngleNext != null) {
if (needleAngleNext != null && enableAnimation) {
if (needleAngleNext != currentAngle) {
if (needleAngleNext < currentAngle)
currentAngle--;
Expand Down Expand Up @@ -226,4 +227,22 @@ public boolean isEnableNeedleShadow() {
public void setEnableNeedleShadow(boolean enableNeedleShadow) {
this.enableNeedleShadow = enableNeedleShadow;
}

/**
* Enable or disable animation for needle
* true will enable animation
* false will disable animation
* @param enableAnimation [boolean]
*/
public void enableAnimation(boolean enableAnimation){
this.enableAnimation = enableAnimation;
}

/**
* Check if animation enable or disable for needle
* @return boolean value
*/
public boolean isEnableAnimation() {
return enableAnimation;
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Apr 05 14:29:44 IDT 2020
#Fri Jul 10 16:11:00 IDT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

0 comments on commit 8df7310

Please sign in to comment.