diff --git a/CircleDisplay/src/com/philjay/circledisplay/CircleDisplay.java b/CircleDisplay/src/com/philjay/circledisplay/CircleDisplay.java index b76a3bf..c52eb0b 100644 --- a/CircleDisplay/src/com/philjay/circledisplay/CircleDisplay.java +++ b/CircleDisplay/src/com/philjay/circledisplay/CircleDisplay.java @@ -92,6 +92,12 @@ public class CircleDisplay extends View implements OnGestureListener { /** object animator for doing the drawing animations */ private ObjectAnimator mDrawAnimator; + /** This represents the total number of colors in mColors arrays */ + private int mNoOfColors; + + /** array that contains values for the arc colors */ + private int[] mColors; + public CircleDisplay(Context context) { super(context); init(); @@ -157,6 +163,9 @@ protected void onDraw(Canvas canvas) { else drawText(canvas); } + + if (mColors !=null ) + setColors(mValue * mPhase); } /** @@ -816,4 +825,27 @@ public void onShowPress(MotionEvent e) { // TODO Auto-generated method stub } -} + + /** + * Sets an array of colors to set the color for the arc/bar to change with the value as it progresses. + * You can either use Color.COLORNAME as a parameter or getColor(resid) + * @param colors + */ + public void setColors(int[] colors) { + this.mNoOfColors = colors.length; + this.mColors = colors; + } + + /** + * If the colors array isn't null, the maximum value will be divide by the number of colors to give each color equal amount of value + * @param val + */ + + private void setColors(float val) { + float mEqualPart = mMaxValue/ mNoOfColors; + int index = (int) (val/mEqualPart); + if (index == mNoOfColors) + index-=1; + mArcPaint.setColor(mColors[index]); + } +} \ No newline at end of file diff --git a/CircleDisplay/src/com/philjay/circledisplay/MainActivity.java b/CircleDisplay/src/com/philjay/circledisplay/MainActivity.java index f1727fc..7bb8173 100644 --- a/CircleDisplay/src/com/philjay/circledisplay/MainActivity.java +++ b/CircleDisplay/src/com/philjay/circledisplay/MainActivity.java @@ -8,6 +8,7 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.graphics.Color; import com.philjay.circledisplay.CircleDisplay.SelectionListener; @@ -30,6 +31,7 @@ protected void onCreate(Bundle savedInstanceState) { mCircleDisplay.setTouchEnabled(true); mCircleDisplay.setUnit("%"); mCircleDisplay.setStepSize(0.5f); + mCircleDisplay.setColors(new int[]{Color.RED, Color.YELLOW, Color.GREEN}); mCircleDisplay.showValue(75f, 100f, true); } diff --git a/README.md b/README.md index 2fafec1..e37b9be 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,8 @@ or create it in code: - setStepSize(float stepsize): Sets the stepsize (minimum selection interval) of the circle display, default 1f. It is recommended to make this value not higher than 1/5 of the maximum selectable value, and not lower than 1/200 of the maximum selectable value. For example, if a maximum of 100 has been chosen, a stepsize between 0.5 and 20 is recommended. - setCustomText(String[] custom): Sets an array of custom Strings to be drawn instead of the actual value in the center of the CircleDisplay. If set to null, the custom text will be reset and the value will be drawn. Make sure the length of the array corresponds with the maximum number of steps (maxvalue / stepsize). - + - setColors(int[] colors): Sets an array of colors to set the color for the arc/bar to change with the value as it progresses. You can either use Color.COLORNAME as a parameter or getColor(resid). + **Showing stuff:** - public void showValue(float toShow, float total, boolean animated): Shows the given value. A maximumvalue also needs to be provided. Set animated to true to animate the displaying of the value. @@ -81,6 +82,7 @@ default 1f. It is recommended to make this value not higher than 1/5 of the maxi cd.setUnit("%"); cd.setStepSize(0.5f); // cd.setCustomText(...); // sets a custom array of text + cd.setColors(new int[]{Color.RED, Color.YELLOW, Color.GREEN}); cd.showValue(75f, 100f, true); ```