Skip to content

Commit 99ea739

Browse files
committed
Reformat Code
1 parent 532d1f9 commit 99ea739

23 files changed

+763
-822
lines changed

AndroidCharts/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1+
<manifest
22
package="im.dacer.androidcharts">
33

44
<application>

AndroidCharts/src/main/java/im/dacer/androidcharts/BarView.java

Lines changed: 78 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,57 @@
77
import android.graphics.Rect;
88
import android.util.AttributeSet;
99
import android.view.View;
10-
1110
import java.util.ArrayList;
1211

1312
/**
1413
* Created by Dacer on 11/11/13.
1514
*/
1615
public class BarView extends View {
16+
private final int MINI_BAR_WIDTH;
17+
private final int BAR_SIDE_MARGIN;
18+
private final int TEXT_TOP_MARGIN;
19+
private final int TEXT_COLOR = Color.parseColor("#9B9A9B");
20+
private final int BACKGROUND_COLOR = Color.parseColor("#F6F6F6");
21+
private final int FOREGROUND_COLOR = Color.parseColor("#FC496D");
1722
private ArrayList<Float> percentList;
1823
private ArrayList<Float> targetPercentList;
1924
private Paint textPaint;
2025
private Paint bgPaint;
2126
private Paint fgPaint;
2227
private Rect rect;
2328
private int barWidth;
24-
// private boolean showSideMargin = true;
2529
private int bottomTextDescent;
2630
private boolean autoSetWidth = true;
2731
private int topMargin;
2832
private int bottomTextHeight;
2933
private ArrayList<String> bottomTextList = new ArrayList<String>();
30-
private final int MINI_BAR_WIDTH;
31-
private final int BAR_SIDE_MARGIN;
32-
private final int TEXT_TOP_MARGIN;
33-
private final int TEXT_COLOR = Color.parseColor("#9B9A9B");
34-
private final int BACKGROUND_COLOR = Color.parseColor("#F6F6F6");
35-
private final int FOREGROUND_COLOR = Color.parseColor("#FC496D");
36-
3734
private Runnable animator = new Runnable() {
38-
@Override
39-
public void run() {
40-
boolean needNewFrame = false;
41-
for (int i=0; i<targetPercentList.size();i++) {
42-
if (percentList.get(i) < targetPercentList.get(i)) {
43-
percentList.set(i,percentList.get(i)+0.02f);
44-
needNewFrame = true;
45-
} else if (percentList.get(i) > targetPercentList.get(i)){
46-
percentList.set(i,percentList.get(i)-0.02f);
47-
needNewFrame = true;
48-
}
49-
if(Math.abs(targetPercentList.get(i)-percentList.get(i))<0.02f){
50-
percentList.set(i,targetPercentList.get(i));
51-
}
35+
@Override public void run() {
36+
boolean needNewFrame = false;
37+
for (int i = 0; i < targetPercentList.size(); i++) {
38+
if (percentList.get(i) < targetPercentList.get(i)) {
39+
percentList.set(i, percentList.get(i) + 0.02f);
40+
needNewFrame = true;
41+
} else if (percentList.get(i) > targetPercentList.get(i)) {
42+
percentList.set(i, percentList.get(i) - 0.02f);
43+
needNewFrame = true;
5244
}
53-
if (needNewFrame) {
54-
postDelayed(this, 20);
45+
if (Math.abs(targetPercentList.get(i) - percentList.get(i)) < 0.02f) {
46+
percentList.set(i, targetPercentList.get(i));
5547
}
56-
invalidate();
48+
}
49+
if (needNewFrame) {
50+
postDelayed(this, 20);
51+
}
52+
invalidate();
5753
}
5854
};
5955

60-
public BarView(Context context){
61-
this(context,null);
56+
public BarView(Context context) {
57+
this(context, null);
6258
}
63-
public BarView(Context context, AttributeSet attrs){
59+
60+
public BarView(Context context, AttributeSet attrs) {
6461
super(context, attrs);
6562
bgPaint = new Paint();
6663
bgPaint.setAntiAlias(true);
@@ -70,9 +67,9 @@ public BarView(Context context, AttributeSet attrs){
7067
rect = new Rect();
7168
topMargin = MyUtils.dip2px(context, 5);
7269
int textSize = MyUtils.sp2px(context, 15);
73-
barWidth = MyUtils.dip2px(context,22);
74-
MINI_BAR_WIDTH = MyUtils.dip2px(context,22);
75-
BAR_SIDE_MARGIN = MyUtils.dip2px(context,22);
70+
barWidth = MyUtils.dip2px(context, 22);
71+
MINI_BAR_WIDTH = MyUtils.dip2px(context, 22);
72+
BAR_SIDE_MARGIN = MyUtils.dip2px(context, 22);
7673
TEXT_TOP_MARGIN = MyUtils.dip2px(context, 5);
7774
textPaint = new Paint();
7875
textPaint.setAntiAlias(true);
@@ -84,23 +81,24 @@ public BarView(Context context, AttributeSet attrs){
8481

8582
/**
8683
* dataList will be reset when called is method.
84+
*
8785
* @param bottomStringList The String ArrayList in the bottom.
8886
*/
89-
public void setBottomTextList(ArrayList<String> bottomStringList){
90-
// this.dataList = null;
87+
public void setBottomTextList(ArrayList<String> bottomStringList) {
88+
// this.dataList = null;
9189
this.bottomTextList = bottomStringList;
9290
Rect r = new Rect();
9391
bottomTextDescent = 0;
9492
barWidth = MINI_BAR_WIDTH;
95-
for(String s:bottomTextList){
96-
textPaint.getTextBounds(s,0,s.length(),r);
97-
if(bottomTextHeight<r.height()){
93+
for (String s : bottomTextList) {
94+
textPaint.getTextBounds(s, 0, s.length(), r);
95+
if (bottomTextHeight < r.height()) {
9896
bottomTextHeight = r.height();
9997
}
100-
if(autoSetWidth&&(barWidth<r.width())){
98+
if (autoSetWidth && (barWidth < r.width())) {
10199
barWidth = r.width();
102100
}
103-
if(bottomTextDescent<(Math.abs(r.bottom))){
101+
if (bottomTextDescent < (Math.abs(r.bottom))) {
104102
bottomTextDescent = Math.abs(r.bottom);
105103
}
106104
}
@@ -109,95 +107,93 @@ public void setBottomTextList(ArrayList<String> bottomStringList){
109107
}
110108

111109
/**
112-
*
113110
* @param list The ArrayList of Integer with the range of [0-max].
114111
*/
115-
public void setDataList(ArrayList<Integer> list, int max){
112+
public void setDataList(ArrayList<Integer> list, int max) {
116113
targetPercentList = new ArrayList<Float>();
117-
if(max == 0) max = 1;
114+
if (max == 0) max = 1;
118115

119-
for(Integer integer : list){
120-
targetPercentList.add(1-(float)integer/(float)max);
116+
for (Integer integer : list) {
117+
targetPercentList.add(1 - (float) integer / (float) max);
121118
}
122119

123120
// Make sure percentList.size() == targetPercentList.size()
124-
if(percentList.isEmpty() || percentList.size()<targetPercentList.size()){
125-
int temp = targetPercentList.size()-percentList.size();
126-
for(int i=0; i<temp;i++){
121+
if (percentList.isEmpty() || percentList.size() < targetPercentList.size()) {
122+
int temp = targetPercentList.size() - percentList.size();
123+
for (int i = 0; i < temp; i++) {
127124
percentList.add(1f);
128125
}
129-
} else if (percentList.size()>targetPercentList.size()){
130-
int temp = percentList.size()-targetPercentList.size();
131-
for(int i=0; i<temp;i++){
132-
percentList.remove(percentList.size()-1);
126+
} else if (percentList.size() > targetPercentList.size()) {
127+
int temp = percentList.size() - targetPercentList.size();
128+
for (int i = 0; i < temp; i++) {
129+
percentList.remove(percentList.size() - 1);
133130
}
134131
}
135132
setMinimumWidth(2);
136133
removeCallbacks(animator);
137134
post(animator);
138135
}
139136

140-
@Override
141-
protected void onDraw(Canvas canvas) {
137+
@Override protected void onDraw(Canvas canvas) {
142138
int i = 1;
143-
if(percentList != null && !percentList.isEmpty()){
144-
for(Float f:percentList){
145-
rect.set(BAR_SIDE_MARGIN*i+barWidth*(i-1),
146-
topMargin,
147-
(BAR_SIDE_MARGIN+barWidth)* i,
148-
getHeight()-bottomTextHeight-TEXT_TOP_MARGIN);
149-
canvas.drawRect(rect,bgPaint);
139+
if (percentList != null && !percentList.isEmpty()) {
140+
for (Float f : percentList) {
141+
rect.set(BAR_SIDE_MARGIN * i + barWidth * (i - 1), topMargin,
142+
(BAR_SIDE_MARGIN + barWidth) * i,
143+
getHeight() - bottomTextHeight - TEXT_TOP_MARGIN);
144+
canvas.drawRect(rect, bgPaint);
150145
/*rect.set(BAR_SIDE_MARGIN*i+barWidth*(i-1),
151146
topMargin+(int)((getHeight()-topMargin)*percentList.get(i-1)),
152147
(BAR_SIDE_MARGIN+barWidth)* i,
153148
getHeight()-bottomTextHeight-TEXT_TOP_MARGIN);*/
154-
/**
155-
* The correct total height is "getHeight()-topMargin-bottomTextHeight-TEXT_TOP_MARGIN",not "getHeight()-topMargin".
156-
* fix by [email protected] on 11/11/13.
157-
*/
158-
rect.set(BAR_SIDE_MARGIN*i+barWidth*(i-1),
159-
topMargin+(int)((getHeight()-topMargin-bottomTextHeight-TEXT_TOP_MARGIN)*percentList.get(i-1)),
160-
(BAR_SIDE_MARGIN+barWidth)* i,
161-
getHeight()-bottomTextHeight-TEXT_TOP_MARGIN);
162-
canvas.drawRect(rect,fgPaint);
149+
/**
150+
* The correct total height is "getHeight()-topMargin-bottomTextHeight-TEXT_TOP_MARGIN",not "getHeight()-topMargin".
151+
* fix by [email protected] on 11/11/13.
152+
*/
153+
rect.set(BAR_SIDE_MARGIN * i + barWidth * (i - 1), topMargin + (int) ((getHeight()
154+
- topMargin
155+
- bottomTextHeight
156+
- TEXT_TOP_MARGIN) * percentList.get(i - 1)),
157+
(BAR_SIDE_MARGIN + barWidth) * i,
158+
getHeight() - bottomTextHeight - TEXT_TOP_MARGIN);
159+
canvas.drawRect(rect, fgPaint);
163160
i++;
164161
}
165162
}
166163

167-
if(bottomTextList != null && !bottomTextList.isEmpty()){
164+
if (bottomTextList != null && !bottomTextList.isEmpty()) {
168165
i = 1;
169-
for(String s:bottomTextList){
170-
canvas.drawText(s,BAR_SIDE_MARGIN*i+barWidth*(i-1)+barWidth/2,
171-
getHeight()-bottomTextDescent,textPaint);
166+
for (String s : bottomTextList) {
167+
canvas.drawText(s, BAR_SIDE_MARGIN * i + barWidth * (i - 1) + barWidth / 2,
168+
getHeight() - bottomTextDescent, textPaint);
172169
i++;
173170
}
174171
}
175172
}
176173

177-
@Override
178-
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
174+
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
179175
int mViewWidth = measureWidth(widthMeasureSpec);
180176
int mViewHeight = measureHeight(heightMeasureSpec);
181-
setMeasuredDimension(mViewWidth,mViewHeight);
177+
setMeasuredDimension(mViewWidth, mViewHeight);
182178
}
183179

184-
private int measureWidth(int measureSpec){
180+
private int measureWidth(int measureSpec) {
185181
int preferred = 0;
186-
if(bottomTextList != null){
187-
preferred = bottomTextList.size()*(barWidth+BAR_SIDE_MARGIN);
182+
if (bottomTextList != null) {
183+
preferred = bottomTextList.size() * (barWidth + BAR_SIDE_MARGIN);
188184
}
189185
return getMeasurement(measureSpec, preferred);
190186
}
191187

192-
private int measureHeight(int measureSpec){
188+
private int measureHeight(int measureSpec) {
193189
int preferred = 222;
194190
return getMeasurement(measureSpec, preferred);
195191
}
196192

197-
private int getMeasurement(int measureSpec, int preferred){
193+
private int getMeasurement(int measureSpec, int preferred) {
198194
int specSize = MeasureSpec.getSize(measureSpec);
199195
int measurement;
200-
switch(MeasureSpec.getMode(measureSpec)){
196+
switch (MeasureSpec.getMode(measureSpec)) {
201197
case MeasureSpec.EXACTLY:
202198
measurement = specSize;
203199
break;
@@ -210,5 +206,4 @@ private int getMeasurement(int measureSpec, int preferred){
210206
}
211207
return measurement;
212208
}
213-
214209
}

AndroidCharts/src/main/java/im/dacer/androidcharts/ClockPieHelper.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
11
package im.dacer.androidcharts;
22

3-
43
/**
54
* Created by Dacer on 11/14/13.
65
*/
76
public class ClockPieHelper {
87

8+
int velocity = 5;
99
private float start;
1010
private float end;
1111
private float targetStart;
1212
private float targetEnd;
13-
int velocity = 5;
1413

15-
ClockPieHelper(float startDegree, float endDegree, ClockPieHelper targetPie){
14+
ClockPieHelper(float startDegree, float endDegree, ClockPieHelper targetPie) {
1615
start = startDegree;
1716
end = endDegree;
1817
targetStart = targetPie.getStart();
1918
targetEnd = targetPie.getEnd();
2019
}
2120

22-
public ClockPieHelper(int startHour, int startMin, int endHour, int endMin){
23-
start = 270+startHour*15+startMin*15/60;
24-
end = 270+endHour*15+endMin*15/60;
25-
while(end<start){
26-
end+=360;
21+
public ClockPieHelper(int startHour, int startMin, int endHour, int endMin) {
22+
start = 270 + startHour * 15 + startMin * 15 / 60;
23+
end = 270 + endHour * 15 + endMin * 15 / 60;
24+
while (end < start) {
25+
end += 360;
2726
}
2827
}
2928

30-
public ClockPieHelper(int startHour, int startMin, int startSec, int endHour, int endMin, int endSec){
31-
start = 270+startHour*15+startMin*15/60+startSec*15/3600;
32-
end = 270+endHour*15+endMin*15/60+endSec*15/3600;
33-
while(end<start){
34-
end+=360;
29+
public ClockPieHelper(int startHour, int startMin, int startSec, int endHour, int endMin,
30+
int endSec) {
31+
start = 270 + startHour * 15 + startMin * 15 / 60 + startSec * 15 / 3600;
32+
end = 270 + endHour * 15 + endMin * 15 / 60 + endSec * 15 / 3600;
33+
while (end < start) {
34+
end += 360;
3535
}
3636
}
3737

38-
ClockPieHelper setTarget(float targetStart,float targetEnd){
38+
ClockPieHelper setTarget(float targetStart, float targetEnd) {
3939
this.targetStart = targetStart;
4040
this.targetEnd = targetEnd;
4141
return this;
4242
}
4343

44-
ClockPieHelper setTarget(ClockPieHelper targetPie){
44+
ClockPieHelper setTarget(ClockPieHelper targetPie) {
4545
targetStart = targetPie.getStart();
4646
targetEnd = targetPie.getEnd();
4747
return this;
4848
}
4949

50-
boolean isAtRest(){
51-
return (start==targetStart)&&(end==targetEnd);
50+
boolean isAtRest() {
51+
return (start == targetStart) && (end == targetEnd);
5252
}
5353

54-
void update(){
54+
void update() {
5555
start = updateSelf(start, targetStart, velocity);
5656
end = updateSelf(end, targetEnd, velocity);
5757
}
5858

59-
public float getSweep(){
60-
return end-start;
59+
public float getSweep() {
60+
return end - start;
6161
}
6262

63-
public float getStart(){
63+
public float getStart() {
6464
return start;
6565
}
6666

67-
public float getEnd(){
67+
public float getEnd() {
6868
return end;
6969
}
7070

71-
private float updateSelf(float origin, float target, int velocity){
71+
private float updateSelf(float origin, float target, int velocity) {
7272
if (origin < target) {
7373
origin += velocity;
74-
} else if (origin > target){
75-
origin-= velocity;
74+
} else if (origin > target) {
75+
origin -= velocity;
7676
}
77-
if(Math.abs(target-origin)<velocity){
77+
if (Math.abs(target - origin) < velocity) {
7878
origin = target;
7979
}
8080
return origin;

0 commit comments

Comments
 (0)