Skip to content
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
34 changes: 33 additions & 1 deletion CircleDisplay/src/com/philjay/circledisplay/CircleDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -157,6 +163,9 @@ protected void onDraw(Canvas canvas) {
else
drawText(canvas);
}

if (mColors !=null )
setColors(mValue * mPhase);
}

/**
Expand Down Expand Up @@ -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]);
}
}
2 changes: 2 additions & 0 deletions CircleDisplay/src/com/philjay/circledisplay/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ or create it in code:
- <code>setStepSize(float stepsize)</code>: 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.
- <code>setCustomText(String[] custom)</code>: 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).

- <code>setColors(int[] colors)</code>: 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:**
- <code>public void showValue(float toShow, float total, boolean animated)</code>: Shows the given value. A maximumvalue also needs to be provided. Set animated to true to animate the displaying of the value.

Expand All @@ -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);
```

Expand Down