Skip to content

Commit de46ece

Browse files
committed
Merge pull request #2 from championswimmer/counterclockwise
Fixes Issue #1 : add option for counterclockwise rotation
2 parents 4ef5f45 + ee4cd61 commit de46ece

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies {
2626

2727
# Usage
2828

29-
In your Layout XML add this
29+
In your Layout XML add this (all the app:.... attributes are optional and have default values
3030

3131
```
3232
<org.lazysource.uberprogressview.UberProgressView
@@ -35,6 +35,7 @@ In your Layout XML add this
3535
app:fading_circle_color="@android:color/holo_red_dark"
3636
app:stationary_circle_color="@android:color/holo_red_dark"
3737
app:orbiting_circle_color="@android:color/holo_red_dark"
38+
app:direction="counterclockwise"
3839
app:orbiting_circle_radius="6dp"
3940
app:stationary_circle_radius="12dp" />
4041
@@ -47,6 +48,7 @@ In your Layout XML add this
4748
| stationary_circle_color | Color of the stationary circle in the center. | color | #29B6F6 |
4849
| orbiting_circle_radius | Radius of the orbiting circles. | dimension | 2dp |
4950
| stationary_circle_radius| Radius of the stationary circle in the center. | dimension | 4dp |
51+
| direction | Direction of rotation of outer dot | enum | clockwise |
5052

5153

5254
# Design Inspiration

uberprogressview/src/main/java/org/lazysource/uberprogressview/UberProgressView.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class UberProgressView extends View {
3737
private int stationaryCircleColor;
3838
private int fadingCircleColor;
3939
private int oribitingCircleColor;
40+
private int roationDirection;
4041

4142
// Animation calculation fields
4243
private float currentAnimationTime = 0;
@@ -77,6 +78,7 @@ private void init(Context context, AttributeSet attributeSet) {
7778
stationaryCircleColor = typedArray.getColor(R.styleable.UberProgressView_stationary_circle_color, Color.parseColor("#29B6F6"));
7879
fadingCircleColor = typedArray.getColor(R.styleable.UberProgressView_fading_circle_color, Color.parseColor("#29B6F6"));
7980
oribitingCircleColor = typedArray.getColor(R.styleable.UberProgressView_orbiting_circle_color, Color.parseColor("#29B6F6"));
81+
roationDirection = typedArray.getInt(R.styleable.UberProgressView_direction, 0);
8082
rStationary = typedArray.getDimension(R.styleable.UberProgressView_stationary_circle_radius, 12f);
8183
float orbitingCircleRadius = typedArray.getDimension(R.styleable.UberProgressView_orbiting_circle_radius, 6f);
8284
// In order to make sure the orbiting circles are at least 75% the
@@ -150,6 +152,7 @@ protected void onDraw(Canvas canvas) {
150152

151153
drawCircle(canvas, theta, mPaintOrbitingCircle1);
152154

155+
153156
if (theta > 15 && theta < 270) {
154157
drawCircle(canvas, theta - movementFactor1, mPaintOrbitingCircle2);
155158
}
@@ -177,11 +180,18 @@ protected void onWindowVisibilityChanged(int visibility) {
177180
private void drawCircle(Canvas canvas, float theta, Paint paint) {
178181

179182
double thetaInRadians = Math.toRadians(theta);
183+
float oribitingCX, oribitingCY;
180184

181-
float oribitingCX = cXStationary + (orbitPathDistanceFromCenter * (float) Math.cos(thetaInRadians));
182-
float oribitingCY = cYStationary + (orbitPathDistanceFromCenter * (float) Math.sin(thetaInRadians));
185+
if (roationDirection == 0) {
186+
oribitingCX = cXStationary + (orbitPathDistanceFromCenter * (float) Math.cos(thetaInRadians));
187+
oribitingCY = cYStationary + (orbitPathDistanceFromCenter * (float) Math.sin(thetaInRadians));
188+
} else {
189+
oribitingCX = cXStationary + (orbitPathDistanceFromCenter * (float) Math.sin(thetaInRadians));
190+
oribitingCY = cYStationary + (orbitPathDistanceFromCenter * (float) Math.cos(thetaInRadians));
191+
}
183192

184193
canvas.drawCircle(oribitingCX, oribitingCY, rOrbiting, paint);
194+
185195
}
186196

187197
private float getLagFactor(float K) {

uberprogressview/src/main/res/values/attrs.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<attr name="fading_circle_color" format="color" />
99
<attr name="orbiting_circle_color" format="color" />
1010
<attr name="animation_time" format="integer" />
11+
<attr name="direction" format="enum">
12+
<enum name="clockwise" value="0"/>
13+
<enum name="counterclockwise" value="1"/>
14+
</attr>
1115
</declare-styleable>
1216

1317
</resources>

0 commit comments

Comments
 (0)