Created
December 22, 2015 23:54
-
-
Save eddieberklee/c4b0b80786b7caff43b5 to your computer and use it in GitHub Desktop.
Android Colored Half Hour Arcs around a Circle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int[] colors = new int[]{ | |
| getResources().getColor(R.color.flatui_red_1), | |
| getResources().getColor(R.color.flatui_red_2), | |
| getResources().getColor(R.color.flatui_orange_1), | |
| getResources().getColor(R.color.flatui_orange_2), | |
| getResources().getColor(R.color.flatui_yellow_1), | |
| getResources().getColor(R.color.flatui_yellow_2), | |
| getResources().getColor(R.color.flatui_green_1), | |
| getResources().getColor(R.color.flatui_green_2), | |
| getResources().getColor(R.color.flatui_blue_1), | |
| getResources().getColor(R.color.flatui_blue_2), | |
| getResources().getColor(R.color.flatui_purple_1), | |
| getResources().getColor(R.color.flatui_purple_2), | |
| getResources().getColor(R.color.flatui_red_1), | |
| getResources().getColor(R.color.flatui_red_2), | |
| getResources().getColor(R.color.flatui_orange_1), | |
| getResources().getColor(R.color.flatui_orange_2), | |
| getResources().getColor(R.color.flatui_yellow_1), | |
| getResources().getColor(R.color.flatui_yellow_2), | |
| getResources().getColor(R.color.flatui_green_1), | |
| getResources().getColor(R.color.flatui_green_2), | |
| getResources().getColor(R.color.flatui_blue_1), | |
| getResources().getColor(R.color.flatui_blue_2), | |
| getResources().getColor(R.color.flatui_purple_1), | |
| getResources().getColor(R.color.flatui_purple_2), | |
| }; | |
| int NUM_HALF_HOURS = 12 * 2; | |
| Path[] mHourPaths; | |
| mHourPaths = new Path[NUM_HALF_HOURS]; | |
| Path hourPath = new Path(); | |
| hourPath.setFillType(Path.FillType.EVEN_ODD); | |
| RectF fullCircleRect = new RectF(0, 0, getWidth(), getHeight()); | |
| int centerX = getWidth() / 2; | |
| int centerY = getHeight() / 2; | |
| for (int halfHour = 0; halfHour < NUM_HALF_HOURS; halfHour++) { | |
| // circle drawing starts at 3 oclock so need to adjust | |
| float halfHourAngle = 360f / NUM_HALF_HOURS; | |
| float quarterHourAngle = halfHourAngle / 2; | |
| float hourAngle = halfHourAngle * halfHour - quarterHourAngle; | |
| hourAngle = (hourAngle + 360f * 3 / 4) % 360; // make up for mathematical vs clock degrees | |
| hourPath.addArc(fullCircleRect, hourAngle, halfHourAngle); // hourSweepAngle covers 2 of these quarter hour sections = 1 half hour section | |
| hourPath.lineTo(centerX, centerY); | |
| hourPath.close(); | |
| highlightPaint.setColor(colors[halfHour]); | |
| canvas.drawPath(hourPath, highlightPaint); | |
| mHourPaths[halfHour] = new Path(hourPath); | |
| hourPath.reset(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment