Skip to content

Commit

Permalink
v1.0.1 新增支持 3 个锚点坐标绘制轮廓;
Browse files Browse the repository at this point in the history
  • Loading branch information
OCNYang committed Sep 25, 2018
1 parent bdda007 commit 05d23bb
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 64 deletions.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ContourView 轮廓背景控件

[![Version Code](https://img.shields.io/badge/Version%20Code-1.0.0-brightgreen.svg)](https://jcenter.bintray.com/com/ocnyang/)
[![Version Code](https://img.shields.io/badge/Version%20Code-1.0.1-brightgreen.svg)](https://jcenter.bintray.com/com/ocnyang/)

## 新控件发布,欢迎大家 Star

Expand Down Expand Up @@ -69,15 +69,15 @@
Gradle

dependencies{
compile 'com.ocnyang:contourview:1.0.0'
compile 'com.ocnyang:contourview:1.0.1'
}

Maven

<dependency>
<groupId>com.ocnyang</groupId>
<artifactId>contourview</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<type>pom</type>
</dependency>

Expand Down Expand Up @@ -133,3 +133,7 @@ Maven
Shader.TileMode.REPEAT);
contourViewBeach.setShader(radialGradient, linearGradient);
}

## 版本历史

* v1.0.1 新增支持 3 个锚点坐标绘制轮廓;
19 changes: 10 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.ocnyang.contourviewdemo"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
targetSdkVersion 28
versionCode 2
versionName "1.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -24,10 +24,11 @@ dependencies {
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:25.4.0'
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation project(':contourview')
compile 'de.hdodenhof:circleimageview:2.1.0'
implementation 'com.android.support:design:25.4.0'
// implementation 'com.ocnyang:contourview:1.0.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.android.support:design:28.0.0-rc02'
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

public class ContourActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -45,9 +44,9 @@ public void onClick(View view) {
private void initCustomContourView() {
ContourView contourViewCustom = (ContourView) findViewById(R.id.contourview_custom);
int width = getWidth();
int hight = 400;
int[] ints = {width / 2, 0, width, hight / 2, width / 2, hight, 0, hight / 2};
int[] intArr = new int[]{width / 2, hight / 4, width / 4 * 3, hight / 2, width / 2, hight / 4 * 3, width / 4, hight / 2};
int hight = 700;
int[] ints = {width / 2, 50, ((int) (width * 0.75)), hight / 2, ((int) (width * 0.35)), 350};
int[] intArr = new int[]{width / 5, hight / 3, width / 4 * 3, hight / 2, width / 2, ((int) (hight * 0.9)), width / 4, ((int) (hight * 0.75))};
contourViewCustom.setPoints(ints, intArr);
contourViewCustom.setShaderStartColor(getResources().getColor(R.color.startcolor));
contourViewCustom.setShaderEndColor(getResources().getColor(R.color.endcolor));
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/content_contour.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<com.ocnyang.contourview.ContourView
android:id="@+id/contourview_custom"
android:layout_width="match_parent"
android:layout_height="400dp"/>
android:layout_height="700px"/>

</LinearLayout>

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
classpath 'com.android.tools.build:gradle:3.1.3'

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
Expand Down
14 changes: 7 additions & 7 deletions contourview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
compileSdkVersion 28
buildToolsVersion "28.0.3"


defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0.0"
targetSdkVersion 28
versionCode 2
versionName "1.0.1"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand All @@ -30,11 +30,11 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})

implementation 'com.android.support:appcompat-v7:25.4.0'
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
testImplementation 'junit:junit:4.12'
}

version = "1.0.0"
version = "1.0.1"
def siteUrl = 'https://github.com/OCNYang/ContourView'
def gitUrl = 'https://github.com/OCNYang/ContourView.git'
group = "com.ocnyang"
Expand Down
103 changes: 70 additions & 33 deletions contourview/src/main/java/com/ocnyang/contourview/ContourView.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public class ContourView extends View {
}

public final static float SMOOTHNESS_DEF = 0.25F;
//smoothing coefficient: 0 ~ 1 recommended range: 0.15 ~ 0.3
/**
* smoothing coefficient: 0 ~ 1 recommended range: 0.15 ~ 0.3
*/
private float mSmoothness = 0.25F;

private int mShaderMode;
Expand Down Expand Up @@ -107,9 +109,9 @@ public ContourView(Context context, @Nullable AttributeSet attrs, int defStyleAt
mSmoothness = smn;
}

int shader_mode = typedArray.getInt(R.styleable.ContourView_shader_mode, SHADER_MODE_NULL);
mShaderMode = shader_mode;
if (SHADER_MODE_NULL != shader_mode) {
int shaderMode = typedArray.getInt(R.styleable.ContourView_shader_mode, SHADER_MODE_NULL);
mShaderMode = shaderMode;
if (SHADER_MODE_NULL != shaderMode) {
mShaderStartColor = typedArray.getColor(R.styleable.ContourView_shader_startcolor, Color.argb(90, 255, 255, 255));
mShaderEndColor = typedArray.getColor(R.styleable.ContourView_shader_endcolor, Color.argb(90, 255, 255, 255));
mShaderStyle = typedArray.getInt(R.styleable.ContourView_shader_style, SHADER_STYLE_LEFT_TO_BOTTOM);
Expand Down Expand Up @@ -140,52 +142,85 @@ protected void onDraw(Canvas canvas) {
mPointsList = PointsFactory.getPoints(mStyle, mW, mH);
}
int flag = 0;

drawcontour:
for (Point[] pts : mPointsList) {
++flag;
int length = pts.length;
if (length < 4) {
if (length < 3) {
continue drawcontour;
}
Path path = new Path();
int x_min = 0, y_min = 0, x_max = 0, y_max = 0;

for (int i = 0; i < length; i++) {
Point p_i, p_1i, p_i1, p_i2;
float ai_x, ai_y, bi_x, bi_y;

p_i = pts[i];
if (i == 0) {
path.moveTo(pts[0].x, pts[0].y);
x_max = x_min = pts[0].x;
y_min = y_max = pts[0].y;
p_1i = pts[length - 1];
p_i1 = pts[i + 1];
p_i2 = pts[i + 2];
} else if (i == length - 1) {
p_1i = pts[i - 1];
p_i1 = pts[0];
p_i2 = pts[1];
} else if (i == length - 2) {
p_1i = pts[i - 1];
p_i1 = pts[i + 1];
p_i2 = pts[0];
Point pI;
Point pI$1 = null;
Point pI_1 = null;
Point pI_2 = null;

float iControl1_X, iControl1_Y, iControl2_X, iControl2_Y;

pI = pts[i];
if (length == 3) {
switch (i) {
case 0:
path.moveTo(pts[0].x, pts[0].y);
x_max = x_min = pts[0].x;
y_min = y_max = pts[0].y;

pI$1 = pts[2];
pI_1 = pts[1];
pI_2 = pts[2];
break;
case 1:
pI$1 = pts[0];
pI_1 = pts[2];
pI_2 = pts[0];
break;
case 2:
pI$1 = pts[1];
pI_1 = pts[0];
pI_2 = pts[1];
break;
default:
break;
}
} else {
p_1i = pts[i - 1];
p_i1 = pts[i + 1];
p_i2 = pts[i + 2];
if (i == 0) {
path.moveTo(pts[0].x, pts[0].y);
x_max = x_min = pts[0].x;
y_min = y_max = pts[0].y;

pI$1 = pts[length - 1];
pI_1 = pts[i + 1];
pI_2 = pts[i + 2];
} else if (i == length - 1) {
pI$1 = pts[i - 1];
pI_1 = pts[0];
pI_2 = pts[1];
} else if (i == length - 2) {
pI$1 = pts[i - 1];
pI_1 = pts[i + 1];
pI_2 = pts[0];
} else {
pI$1 = pts[i - 1];
pI_1 = pts[i + 1];
pI_2 = pts[i + 2];
}
}

if (p_1i == null || p_i == null || p_i1 == null || p_i2 == null) {
if (pI$1 == null || pI == null || pI_1 == null || pI_2 == null) {
continue drawcontour;
}

ai_x = p_i.x + (p_i1.x - p_1i.x) * mSmoothness;
ai_y = p_i.y + (p_i1.y - p_1i.y) * mSmoothness;
iControl1_X = pI.x + ((pI_1.x - pI$1.x) * mSmoothness);
iControl1_Y = pI.y + ((pI_1.y - pI$1.y) * mSmoothness);

bi_x = p_i1.x - (p_i2.x - p_i.x) * mSmoothness;
bi_y = p_i1.y - (p_i2.y - p_i.y) * mSmoothness;
iControl2_X = pI_1.x - ((pI_2.x - pI.x) * mSmoothness);
iControl2_Y = pI_1.y - ((pI_2.y - pI.y) * mSmoothness);

path.cubicTo(ai_x, ai_y, bi_x, bi_y, p_i1.x, p_i1.y);
path.cubicTo(iControl1_X, iControl1_Y, iControl2_X, iControl2_Y, pI_1.x, pI_1.y);

if (pts[i].x < x_min) {
x_min = pts[i].x;
Expand Down Expand Up @@ -249,6 +284,8 @@ protected void onDraw(Canvas canvas) {
Shader.TileMode.REPEAT);
mPaint.setShader(linearGradient);
break;
default:
break;
}
}
}
Expand Down
Loading

0 comments on commit 05d23bb

Please sign in to comment.