Skip to content

Commit 0769fe5

Browse files
author
b.ergashev
committed
fix #1
1 parent 17519fa commit 0769fe5

File tree

11 files changed

+46
-180
lines changed

11 files changed

+46
-180
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77

88
defaultConfig {
99
applicationId "com.ebr163.fillableview"
10-
minSdkVersion 14
10+
minSdkVersion project.ext.minSdkVersion
1111
targetSdkVersion project.ext.targetSdkVersion
1212
versionCode 1
1313
versionName "1.0"

app/src/androidTest/java/com/ebr163/fillableview/ExampleInstrumentedTest.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
package="com.ebr163.fillableview">
45

56
<application
@@ -8,7 +9,8 @@
89
android:label="@string/app_name"
910
android:roundIcon="@mipmap/ic_launcher_round"
1011
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
12+
android:theme="@style/AppTheme"
13+
tools:ignore="GoogleAppIndexingWarning">
1214
<activity android:name=".MainActivity">
1315
<intent-filter>
1416
<action android:name="android.intent.action.MAIN" />

app/src/main/java/com/ebr163/fillableview/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
public class MainActivity extends AppCompatActivity {
1919

20-
private Random rnd = new Random();
20+
private final Random rnd = new Random();
2121
private FilledView filledViewLeft;
2222

2323
@Override

app/src/main/res/layout/activity_start.xml

Lines changed: 0 additions & 35 deletions
This file was deleted.

app/src/test/java/com/ebr163/fillableview/ExampleUnitTest.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ allprojects {
2020
buildToolsVersion = "28.0.3"
2121
androidX = "1.1.0-alpha05"
2222
constrainLayout = "1.1.3"
23+
minSdkVersion = 19
2324
}
2425
}
2526

view/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ android {
66
buildToolsVersion project.ext.buildToolsVersion
77

88
defaultConfig {
9-
minSdkVersion 14
9+
minSdkVersion project.ext.minSdkVersion
1010
targetSdkVersion project.ext.targetSdkVersion
1111
versionCode 2
1212
versionName "1.1"

view/src/androidTest/java/com/ebr163/view/ExampleInstrumentedTest.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

view/src/main/java/com/ebr163/view/FilledView.java

Lines changed: 39 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import android.graphics.Path;
99
import android.graphics.Rect;
1010
import android.graphics.RectF;
11-
import android.graphics.Region;
1211
import android.util.AttributeSet;
1312
import android.view.View;
1413

@@ -23,7 +22,7 @@ public class FilledView extends View {
2322
public enum StartMode {
2423
LEFT(0), TOP(1), RIGHT(2), BOTTOM(3);
2524

26-
private int mode;
25+
private final int mode;
2726

2827
StartMode(int mode) {
2928
this.mode = mode;
@@ -41,19 +40,19 @@ public int getMode() {
4140
private int textSize;
4241
private boolean isShowBorder;
4342
private int borderSize = 1;
44-
45-
private final Path textPath = new Path();
46-
private final Path croppedProgressPath = new Path();
47-
private final Path croppedTextPath = new Path();
48-
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
4943
private int width;
5044
private int height;
5145
private float percent = 0.1F;
52-
private Path progressStrokePath = new Path();
53-
private Rect textBounds = new Rect();
5446

55-
private final Region region = new Region();
56-
private final Region textRegion = new Region();
47+
private final RectF rectF = new RectF();
48+
private final Path textPath = new Path();
49+
private final Path croppedTextPath = new Path();
50+
private final Path progressPath = new Path();
51+
private final Path croppedProgressPath = new Path();
52+
private final Path progressStrokePath = new Path();
53+
54+
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
55+
private final Rect textBounds = new Rect();
5756

5857
public FilledView(Context context) {
5958
this(context, null);
@@ -133,52 +132,37 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
133132
if (text != null) {
134133
paint.getTextPath(text, 0, text.length(), cx, cy, textPath);
135134
}
136-
progressStrokePath = getRoundRectPath(0, 0, width, height, radius);
137-
138-
computePaths();
135+
initRoundRectPath(0, 0, width, height, radius);
136+
createPaths();
139137
setMeasuredDimension(width, height);
140138
}
141139

142-
private Path getRoundRectPath(float left, float top, float right, float bottom, float radius) {
143-
region.set((int) left, (int) top, (int) right, (int) bottom);
144-
Path roundRectPath = new Path();
145-
RectF rectF = new RectF();
146-
rectF.set(left + borderSize, top + borderSize, right - borderSize, bottom - borderSize);
147-
roundRectPath.addRoundRect(rectF, radius, radius, Path.Direction.CCW);
148-
region.setPath(roundRectPath, region);
149-
return region.getBoundaryPath();
150-
}
151-
152-
public void computeCroppedProgressPath() {
140+
private void createPaths() {
153141
if (startPosition == StartMode.RIGHT.getMode()) {
154-
region.set((int) (width * (1F - percent)), 0, width, height);
142+
setRectPath(progressPath, width * (1F - percent), 0, width, height);
155143
} else if (startPosition == StartMode.LEFT.getMode()) {
156-
region.set(0, 0, (int) (width * percent), height);
144+
setRectPath(progressPath, 0, 0, width * percent, height);
157145
} else if (startPosition == StartMode.TOP.getMode()) {
158-
region.set(0, 0, width, (int) (height * percent));
146+
setRectPath(progressPath, 0, 0, width, height * percent);
159147
} else if (startPosition == StartMode.BOTTOM.getMode()) {
160-
region.set(0, (int) (height * (1F - percent)), width, height);
148+
setRectPath(progressPath, 0, height * (1F - percent), width, height);
161149
}
162-
region.setPath(progressStrokePath, region);
163-
textRegion.setPath(textPath, region);
164-
region.op(textRegion, Region.Op.DIFFERENCE);
165-
croppedProgressPath.rewind();
166-
region.getBoundaryPath(croppedProgressPath);
150+
croppedProgressPath.op(progressPath, textPath, Path.Op.DIFFERENCE);
151+
croppedProgressPath.op(progressStrokePath, Path.Op.INTERSECT);
152+
153+
croppedTextPath.op(textPath, progressPath, Path.Op.DIFFERENCE);
167154
}
168155

169-
public void computeCroppedTextPath() {
170-
if (startPosition == StartMode.RIGHT.getMode()) {
171-
region.set(0, 0, (int) (width * (1F - percent)), height);
172-
} else if (startPosition == StartMode.LEFT.getMode()) {
173-
region.set((int) (width * percent), 0, width, height);
174-
} else if (startPosition == StartMode.TOP.getMode()) {
175-
region.set(0, (int) (height * percent), width, height);
176-
} else if (startPosition == StartMode.BOTTOM.getMode()) {
177-
region.set(0, 0, width, (int) (height * (1F - percent)));
178-
}
179-
textRegion.setPath(textPath, region);
180-
croppedTextPath.rewind();
181-
textRegion.getBoundaryPath(croppedTextPath);
156+
private void initRoundRectPath(float left, float top, float right, float bottom, float radius) {
157+
progressStrokePath.reset();
158+
rectF.set(left + borderSize, top + borderSize, right - borderSize, bottom - borderSize);
159+
progressStrokePath.addRoundRect(rectF, radius, radius, Path.Direction.CW);
160+
}
161+
162+
public void setRectPath(Path path, float left, float top, float right, float bottom) {
163+
rectF.set(left, top, right, bottom);
164+
path.rewind();
165+
path.addRect(rectF, Path.Direction.CW);
182166
}
183167

184168
@Override
@@ -200,7 +184,7 @@ protected void onDraw(Canvas canvas) {
200184
public void setProgress(float percent) {
201185
if (percent >= 0f && percent <= 1F) {
202186
this.percent = percent;
203-
computePaths();
187+
createPaths();
204188
invalidate();
205189
}
206190
}
@@ -215,8 +199,8 @@ public void setText(String text) {
215199
requestLayout();
216200
}
217201

218-
public void showBorder(boolean flag) {
219-
isShowBorder = flag;
202+
public void showBorder(boolean isShowBorder) {
203+
this.isShowBorder = isShowBorder;
220204
invalidate();
221205
}
222206

@@ -230,13 +214,13 @@ public void setRadius(int radius) {
230214
requestLayout();
231215
}
232216

233-
public void setStartMode(StartMode startPosition) {
234-
this.startPosition = startPosition.getMode();
217+
public void setBorderSize(int borderSize){
218+
this.borderSize = borderSize;
235219
requestLayout();
236220
}
237221

238-
private void computePaths() {
239-
computeCroppedProgressPath();
240-
computeCroppedTextPath();
222+
public void setStartMode(StartMode startPosition) {
223+
this.startPosition = startPosition.getMode();
224+
requestLayout();
241225
}
242226
}

view/src/test/java/com/ebr163/view/ExampleUnitTest.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)