Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed refresh on color setters, stroke, point size, divider draw first and last #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public CustomGauge(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomGauge, 0, 0);

// stroke style
setStrokeWidth(a.getDimension(R.styleable.CustomGauge_gaugeStrokeWidth, 10));
setStrokeColor(a.getColor(R.styleable.CustomGauge_gaugeStrokeColor, ContextCompat.getColor(context, android.R.color.darker_gray)));
setStrokeCap(a.getString(R.styleable.CustomGauge_gaugeStrokeCap));
mStrokeWidth = a.getDimension(R.styleable.CustomGauge_gaugeStrokeWidth, 10);
mStrokeColor = a.getColor(R.styleable.CustomGauge_gaugeStrokeColor, ContextCompat.getColor(context, android.R.color.darker_gray));
mStrokeCap = a.getString(R.styleable.CustomGauge_gaugeStrokeCap);

// angel start and sweep (opposite direction 0, 270, 180, 90)
setStartAngel(a.getInt(R.styleable.CustomGauge_gaugeStartAngel, 0));
Expand All @@ -60,16 +60,16 @@ public CustomGauge(Context context, AttributeSet attrs) {
setEndValue(a.getInt(R.styleable.CustomGauge_gaugeEndValue, 1000));

// pointer size and color
setPointSize(a.getInt(R.styleable.CustomGauge_gaugePointSize, 0));
setPointStartColor(a.getColor(R.styleable.CustomGauge_gaugePointStartColor, ContextCompat.getColor(context, android.R.color.white)));
setPointEndColor(a.getColor(R.styleable.CustomGauge_gaugePointEndColor, ContextCompat.getColor(context, android.R.color.white)));
mPointSize = a.getInt(R.styleable.CustomGauge_gaugePointSize, 0);
mPointStartColor = a.getColor(R.styleable.CustomGauge_gaugePointStartColor, ContextCompat.getColor(context, android.R.color.white));
mPointEndColor = a.getColor(R.styleable.CustomGauge_gaugePointEndColor, ContextCompat.getColor(context, android.R.color.white));

// divider options
int dividerSize = a.getInt(R.styleable.CustomGauge_gaugeDividerSize, 0);
setDividerColor(a.getColor(R.styleable.CustomGauge_gaugeDividerColor, ContextCompat.getColor(context, android.R.color.white)));
mDividerColor = a.getColor(R.styleable.CustomGauge_gaugeDividerColor, ContextCompat.getColor(context, android.R.color.white));
int dividerStep = a.getInt(R.styleable.CustomGauge_gaugeDividerStep, 0);
setDividerDrawFirst(a.getBoolean(R.styleable.CustomGauge_gaugeDividerDrawFirst, true));
setDividerDrawLast(a.getBoolean(R.styleable.CustomGauge_gaugeDividerDrawLast, true));
mDividerDrawFirst = a.getBoolean(R.styleable.CustomGauge_gaugeDividerDrawFirst, true);
mDividerDrawLast = a.getBoolean(R.styleable.CustomGauge_gaugeDividerDrawLast, true);

// calculating one point sweep
mPointAngel = ((double) Math.abs(mSweepAngel) / (mEndValue - mStartValue));
Expand All @@ -90,13 +90,7 @@ private void init() {
mPaint.setColor(mStrokeColor);
mPaint.setStrokeWidth(mStrokeWidth);
mPaint.setAntiAlias(true);
if (!TextUtils.isEmpty(mStrokeCap)) {
if (mStrokeCap.equals("BUTT"))
mPaint.setStrokeCap(Paint.Cap.BUTT);
else if (mStrokeCap.equals("ROUND"))
mPaint.setStrokeCap(Paint.Cap.ROUND);
} else
mPaint.setStrokeCap(Paint.Cap.BUTT);
setStrokeCap(mStrokeCap, false);
mPaint.setStyle(Paint.Style.STROKE);
mRect = new RectF();

Expand Down Expand Up @@ -169,26 +163,46 @@ public float getStrokeWidth() {
return mStrokeWidth;
}

@SuppressWarnings("unused")
public void setStrokeWidth(float strokeWidth) {
mStrokeWidth = strokeWidth;
mPaint.setStrokeWidth(mStrokeWidth);
invalidate();
}

@SuppressWarnings("unused")
public int getStrokeColor() {
return mStrokeColor;
}

@SuppressWarnings("unused")
public void setStrokeColor(int strokeColor) {
mStrokeColor = strokeColor;
mStrokeColor = ContextCompat.getColor(getContext(), strokeColor);;
mPaint.setColor(mStrokeColor);
invalidate();
}

@SuppressWarnings("unused")
public String getStrokeCap() {
return mStrokeCap;
}

@SuppressWarnings("unused")
public void setStrokeCap(String strokeCap) {
setStrokeCap(strokeCap, true);
}

private void setStrokeCap(String strokeCap, boolean invalidate) {
mStrokeCap = strokeCap;
if (!TextUtils.isEmpty(mStrokeCap)) {
if (mStrokeCap.equals("BUTT"))
mPaint.setStrokeCap(Paint.Cap.BUTT);
else if (mStrokeCap.equals("ROUND"))
mPaint.setStrokeCap(Paint.Cap.ROUND);
} else
mPaint.setStrokeCap(Paint.Cap.BUTT);
if (invalidate)
invalidate();
}

@SuppressWarnings("unused")
Expand Down Expand Up @@ -232,53 +246,65 @@ public int getPointSize() {
return mPointSize;
}

@SuppressWarnings("unused")
public void setPointSize(int pointSize) {
mPointSize = pointSize;
invalidate();
}

@SuppressWarnings("unused")
public int getPointStartColor() {
return mPointStartColor;
}

@SuppressWarnings("unused")
public void setPointStartColor(int pointStartColor) {
mPointStartColor = pointStartColor;
mPointStartColor = ContextCompat.getColor(getContext(), pointStartColor);
invalidate();
}

@SuppressWarnings("unused")
public int getPointEndColor() {
return mPointEndColor;
}

@SuppressWarnings("unused")
public void setPointEndColor(int pointEndColor) {
mPointEndColor = pointEndColor;
mPointEndColor = ContextCompat.getColor(getContext(), pointEndColor);
invalidate();
}

@SuppressWarnings("unused")
public int getDividerColor() {
return mDividerColor;
}

@SuppressWarnings("unused")
public void setDividerColor(int dividerColor) {
mDividerColor = dividerColor;
mDividerColor = ContextCompat.getColor(getContext(), dividerColor);
invalidate();
}

@SuppressWarnings("unused")
public boolean isDividerDrawFirst() {
return mDividerDrawFirst;
}

@SuppressWarnings("unused")
public void setDividerDrawFirst(boolean dividerDrawFirst) {
mDividerDrawFirst = dividerDrawFirst;
invalidate();
}

@SuppressWarnings("unused")
public boolean isDividerDrawLast() {
return mDividerDrawLast;
}

@SuppressWarnings("unused")
public void setDividerDrawLast(boolean dividerDrawLast) {
mDividerDrawLast = dividerDrawLast;
invalidate();
}

}
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Simple gauge view
}

<span class="pl-en">dependencies</span> {
compile <span class="pl-s"><span class="pl-pds">'</span>pl.pawelkleczkowski.customgauge:CustomGauge:1.0.1<span class="pl-pds">'</span></span>
compile <span class="pl-s"><span class="pl-pds">'</span>pl.pawelkleczkowski.customgauge:CustomGauge:1.0.2<span class="pl-pds">'</span></span>
}</pre></div>
* Add "pl.pawelkleczkowski.customgauge.CustomGauge" view in your layout (example below)
* Find CustomGauge view in your activity and use methods "setValue()" and "getValue()" to manage view
Expand Down Expand Up @@ -58,16 +58,16 @@ Available view attributes:
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp"
gauge:pointStartColor="@color/Red"
gauge:pointEndColor="@color/Red"
gauge:pointSize="6"
gauge:startAngel="135"
gauge:strokeCap="ROUND"
gauge:strokeColor="@color/Gray"
gauge:strokeWidth="10dp"
gauge:startValue="0"
gauge:endValue="1000"
gauge:sweepAngel="270" />
app:gaugePointStartColor="@color/Red"
app:gaugePointEndColor="@color/Red"
app:gaugePointSize="6"
app:gaugeStartAngel="135"
app:gaugeStrokeCap="ROUND"
app:gaugeStrokeColor="@color/Gray"
app:gaugeStrokeWidth="10dp"
app:gaugeStartValue="0"
app:gaugeEndValue="1000"
app:gaugeSweepAngel="270" />

<pl.pawelkleczkowski.customgauge.CustomGauge
android:id="@+id/gauge2"
Expand All @@ -79,15 +79,15 @@ Available view attributes:
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
gauge:endValue="800"
gauge:pointEndColor="@color/DarkBlue"
gauge:pointStartColor="@color/LightSkyBlue"
gauge:startAngel="135"
gauge:startValue="200"
gauge:strokeCap="ROUND"
gauge:strokeColor="@color/Gray"
gauge:strokeWidth="10dp"
gauge:sweepAngel="270" />
app:gaugeEndValue="800"
app:gaugePointEndColor="@color/DarkBlue"
app:gaugePointStartColor="@color/LightSkyBlue"
app:gaugeStartAngel="135"
app:gaugeStartValue="200"
app:gaugeStrokeCap="ROUND"
app:gaugeStrokeColor="@color/Gray"
app:gaugeStrokeWidth="10dp"
app:gaugeSweepAngel="270" />

&nbsp;

Expand Down