Skip to content

Commit

Permalink
release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaopan committed Jan 3, 2016
1 parent 65cd08b commit 3979fe3
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 77 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2015 Peng fei Pan <sky@xiaopan.me>
Copyright 2016 Peng fei Pan <sky@xiaopan.me>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ SpiderWebScoreView

|Name|介绍|对应方法|缺省值|
|:--|:--|:--|:--|
|dimensionCount|设置蛛网图形有多少个角|会在setScores(float, float[])方法中根据scores的长度来覆盖此参数|5|
|angleCount|设置蛛网图形有多少个角|会在setScores(float, float[])方法中根据scores的长度来覆盖此参数|5|
|hierarchyCount|设置蛛网图形有多少层|setHierarchyCount(int)|5|
|maxScore|最大分值|setScores(float, float[])方法的第一个参数就是maxScore|10f|
|lineColor|蛛网线条的颜色|setLineColor(int)|0xFF000000|
Expand All @@ -138,7 +138,7 @@ CircularLayout

License
-------
Copyright (C) 2015 Peng fei Pan <sky@xiaopan.me>
Copyright (C) 2016 Peng fei Pan <sky@xiaopan.me>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Peng fei Pan <sky@xiaopan.me>
Copyright (C) 2016 Peng fei Pan <sky@xiaopan.me>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Peng fei Pan <sky@xiaopan.me>
* Copyright (C) 2016 Peng fei Pan <sky@xiaopan.me>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
8 changes: 4 additions & 4 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
app:dimensionCount="3"
app:angleCount="3"
app:hierarchyCount="3" />

<me.xiaopan.swsv.CircularLayout
Expand Down Expand Up @@ -120,7 +120,7 @@
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
app:dimensionCount="6"/>
app:angleCount="6"/>

<me.xiaopan.swsv.CircularLayout
android:id="@+id/layout_mainActivity_circular5"
Expand Down Expand Up @@ -201,7 +201,7 @@
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
app:dimensionCount="8"
app:angleCount="8"
app:hierarchyCount="8" />

<me.xiaopan.swsv.CircularLayout
Expand Down Expand Up @@ -272,7 +272,7 @@
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
app:dimensionCount="12"
app:angleCount="12"
app:hierarchyCount="8" />

<me.xiaopan.swsv.CircularLayout
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/score.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Peng fei Pan <sky@xiaopan.me>
Copyright (C) 2016 Peng fei Pan <sky@xiaopan.me>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Peng fei Pan <sky@xiaopan.me>
Copyright (C) 2016 Peng fei Pan <sky@xiaopan.me>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Peng fei Pan <sky@xiaopan.me>
Copyright (C) 2016 Peng fei Pan <sky@xiaopan.me>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Peng fei Pan <sky@xiaopan.me>
Copyright (C) 2016 Peng fei Pan <sky@xiaopan.me>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion spiderwebscoreview/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Peng fei Pan <sky@xiaopan.me>
Copyright (C) 2016 Peng fei Pan <sky@xiaopan.me>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Peng fei Pan <sky@xiaopan.me>
* Copyright (C) 2016 Peng fei Pan <sky@xiaopan.me>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,14 +36,11 @@ public class CircularLayout extends ViewGroup {
private static final int LOCATION_WEST_NORTH = 7;
private static final int LOCATION_WEST_SOUTH = 8;

private float offsetAngle; // 偏移角度,有助于让整个图形左右对称
private int spacing; // 子View与圆环之间的间距

private float centerX; // 中心点X坐标
private float centerY; // 中心点Y坐标
private float radius; // 半径
private float averageAngle; // 平均角度

private int childCount; // 子View个数

public CircularLayout(Context context) {
Expand Down Expand Up @@ -102,8 +99,6 @@ private void reset(){
centerX = viewWidth / 2;
centerY = viewHeight / 2;
radius = Math.min(viewWidth, viewHeight) / 2;
averageAngle = childCount > 0 ? 360 / childCount : 0;
offsetAngle = averageAngle > 0 && childCount % 2 == 0 ? averageAngle / 2 : 0;
}

@Override
Expand All @@ -122,6 +117,8 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
int childViewMeasuredHeight;
float childViewLeft;
float childViewTop;
float averageAngle = childCount > 0 ? 360 / childCount : 0;
float offsetAngle = averageAngle > 0 && childCount % 2 == 0 ? averageAngle / 2 : 0; // 偏移角度,有助于让整个图形左右对称
for (int position = 0, size = getChildCount(); position < size; position++) {
childView = getChildAt(position);
nextAngle = offsetAngle + (position * averageAngle);
Expand Down Expand Up @@ -212,16 +209,6 @@ private int calculateLocationByAngle(float angle) {
}
}

/**
* 设置偏移角度,默认会根据子View个数计算偏移角度,保证整个图形左右对称
* @param offsetAngle 偏移角度
*/
@SuppressWarnings("unused")
public void setOffsetAngle(float offsetAngle) {
this.offsetAngle = offsetAngle;
requestLayout();
}

/**
* 设置内容和圆圈之间的距离,默认为8dp
* @param spacing 内容和圆圈之间的距离
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Peng fei Pan <sky@xiaopan.me>
* Copyright (C) 2016 Peng fei Pan <sky@xiaopan.me>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,27 +28,24 @@
* 蛛网评分图,支持任意条边以及任意层级
*/
public class SpiderWebScoreView extends View {
private int dimensionCount = 5; // 整个蛛网分几个维度(几有个维度就有几个角,就是几边形)
private int angleCount = 5; // 整个蛛网有几个角
private int hierarchyCount = 5; // 整个蛛网分多少层(例如最大分数是10分,分5层,那么每层就代表2分)
private float maxScore = 10f; // 最大分数
private float offsetAngle = 0; // 偏移角度,有助于让整个图形左右对称
private int lineColor = 0xFF000000; // 蛛网线条的颜色
private float lineWidth = -1; // 蛛网线条的宽度

private float maxScore = 10f; // 最大分数
private float[] scores; // 分数列表
private int scoreColor = 0x80F65801; // 分数图形的颜色
private int scoreStrokeColor = 0xFFF65801; // 分数图形描边的颜色
private float scoreStrokeWidth = -1; // 分数图形描边的宽度
private boolean disableScoreStroke; // 禁用分数图形的描边
private float[] scores; // 分数列表
private Paint scorePaint;
private Paint scoreStrokePaint;

private float centerX; // 中心点X坐标
private float centerY; // 中心点Y坐标
private float radius; // 整个蛛网图的半径
private float averageRadius; // 每层平均半径
private float averageAngle; // 每个维度的平均角度

private Paint linePaint;
private Paint scorePaint;
private Paint scoreStrokePaint;
private Path path;

public SpiderWebScoreView(Context context) {
Expand All @@ -75,7 +72,7 @@ private void init(Context context, AttributeSet attrs) {
linePaint.setColor(lineColor);
linePaint.setStyle(Paint.Style.STROKE);
linePaint.setAntiAlias(true);
if(lineWidth >= 0){
if(lineWidth > 0){
linePaint.setStrokeWidth(lineWidth);
}

Expand All @@ -88,9 +85,9 @@ private void init(Context context, AttributeSet attrs) {

if(isInEditMode()){
float[] randomScoreArray = new float[]{7.0f, 8.0f, 5.0f, 5.0f, 8.0f};
float[] testScores = new float[dimensionCount];
float[] testScores = new float[angleCount];
int index = 0;
for(int w = 0; w < dimensionCount; w++){
for(int w = 0; w < angleCount; w++){
testScores[w] = randomScoreArray[index++% randomScoreArray.length];
}
setScores(10f, testScores);
Expand All @@ -100,7 +97,7 @@ private void init(Context context, AttributeSet attrs) {
private void parseAttrs(Context context, AttributeSet attrs){
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SpiderWebScoreView);

setDimensionCount(typedArray.getInt(R.styleable.SpiderWebScoreView_dimensionCount, dimensionCount));
setAngleCount(typedArray.getInt(R.styleable.SpiderWebScoreView_angleCount, angleCount));
setHierarchyCount(typedArray.getInt(R.styleable.SpiderWebScoreView_hierarchyCount, hierarchyCount));
setMaxScore(typedArray.getFloat(R.styleable.SpiderWebScoreView_maxScore, maxScore));

Expand All @@ -114,25 +111,22 @@ private void parseAttrs(Context context, AttributeSet attrs){
typedArray.recycle();
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
reset();
}

private void reset(){
if(dimensionCount != 0 && hierarchyCount != 0){
if(angleCount != 0 && hierarchyCount != 0){
int viewWidth = getWidth();
int viewHeight = getHeight();
centerX = viewWidth / 2;
centerY = viewHeight / 2;
radius = Math.min(viewWidth, viewHeight) / 2;
averageRadius = radius / hierarchyCount;
averageAngle = 360 / dimensionCount;
offsetAngle = averageAngle > 0 && dimensionCount % 2 == 0 ? averageAngle / 2 : 0;
}
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
reset();
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Expand All @@ -147,6 +141,7 @@ protected void onDraw(Canvas canvas) {
* @param canvas Canvas
*/
private void drawAllHierarchy(Canvas canvas) {
float averageRadius = radius / hierarchyCount;
for(int w = 0; w < hierarchyCount; w++){
drawHierarchyByRadius(canvas, averageRadius *(w+1));
}
Expand All @@ -164,7 +159,9 @@ private void drawHierarchyByRadius(Canvas canvas, float currentRadius) {
float nextRadians;
float nextPointX;
float nextPointY;
for (int position = 0; position < dimensionCount; position++) {
float averageAngle = 360 / angleCount;
float offsetAngle = averageAngle > 0 && angleCount % 2 == 0 ? averageAngle / 2 : 0;
for (int position = 0; position < angleCount; position++) {
nextAngle = offsetAngle + (position * averageAngle);
nextRadians = (float) Math.toRadians(nextAngle);
nextPointX = (float) (centerX + Math.sin(nextRadians) * currentRadius);
Expand All @@ -190,7 +187,9 @@ private void drawAllLine(Canvas canvas){
float nextRadians;
float nextPointX;
float nextPointY;
for(int position = 0; position < dimensionCount; position++){
float averageAngle = 360 / angleCount;
float offsetAngle = averageAngle > 0 && angleCount % 2 == 0 ? averageAngle / 2 : 0;
for(int position = 0; position < angleCount; position++){
nextAngle = offsetAngle + (position * averageAngle);
nextRadians = (float) Math.toRadians(nextAngle);
nextPointX = (float) (centerX + Math.sin(nextRadians) * radius);
Expand All @@ -216,7 +215,9 @@ private void drawScore(Canvas canvas){
float nextPointX;
float nextPointY;
float currentRadius;
for (int position = 0; position < dimensionCount; position++) {
float averageAngle = 360 / angleCount;
float offsetAngle = averageAngle > 0 && angleCount % 2 == 0 ? averageAngle / 2 : 0;
for (int position = 0; position < angleCount; position++) {
currentRadius = (scores[position] / maxScore) * radius;
nextAngle = offsetAngle + (position * averageAngle);
nextRadians = (float) Math.toRadians(nextAngle);
Expand All @@ -240,7 +241,7 @@ private void drawScore(Canvas canvas){
scoreStrokePaint.setColor(scoreStrokeColor);
scoreStrokePaint.setStyle(Paint.Style.STROKE);
scoreStrokePaint.setAntiAlias(true);
if(scoreStrokeWidth >= 0){
if(scoreStrokeWidth > 0){
scoreStrokePaint.setStrokeWidth(scoreStrokeWidth);
}
}
Expand All @@ -250,13 +251,13 @@ private void drawScore(Canvas canvas){

/**
* 设置蛛网有多少个角
* @param dimensionCount 蛛网有多少个角
* @param angleCount 蛛网有多少个角
*/
private void setDimensionCount(int dimensionCount) {
if(dimensionCount <= 2){
throw new IllegalArgumentException("dimensionCount Can not be less than or equal to 2");
private void setAngleCount(int angleCount) {
if(angleCount <= 2){
throw new IllegalArgumentException("angleCount Can not be less than or equal to 2");
}
this.dimensionCount = dimensionCount;
this.angleCount = angleCount;
reset();
postInvalidate();
}
Expand All @@ -283,7 +284,7 @@ public void setScores(float maxScore, float[] scores) {
}
setMaxScore(maxScore);
this.scores = scores;
this.dimensionCount = scores.length;
this.angleCount = scores.length;
reset();
postInvalidate();
}
Expand Down Expand Up @@ -325,17 +326,6 @@ public void setLineWidth(float lineWidth) {
postInvalidate();
}

/**
* 设置偏移角度,默认会根据子View个数计算偏移角度,保证整个图形左右对称
* @param offsetAngle 偏移角度
*/
@SuppressWarnings("unused")
public void setOffsetAngle(float offsetAngle) {
offsetAngle %= 360;
this.offsetAngle = offsetAngle;
postInvalidate();
}

/**
* 设置分数图形的颜色
* @param scoreColor 分数图形的颜色
Expand Down
4 changes: 2 additions & 2 deletions spiderwebscoreview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Peng fei Pan <sky@xiaopan.me>
Copyright (C) 2016 Peng fei Pan <sky@xiaopan.me>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@

<resources>
<declare-styleable name="SpiderWebScoreView">
<attr name="dimensionCount" format="integer"/>
<attr name="angleCount" format="integer"/>
<attr name="hierarchyCount" format="integer"/>
<attr name="maxScore" format="float"/>
<attr name="lineColor" format="color"/>
Expand Down

0 comments on commit 3979fe3

Please sign in to comment.