Skip to content

Commit

Permalink
优化部分机型兼容性问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jenly1314 committed Sep 3, 2017
1 parent 32e3a4a commit 38222ef
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .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.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ RadarView for Android 是一个雷达扫描动画后,然后展示得分效果
<dependency>
<groupId>com.king.view</groupId>
<artifactId>radarview</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<type>pom</type>
</dependency>
```
### Gradle:
```gradle
compile 'com.king.view:radarview:1.0.1'
compile 'com.king.view:radarview:1.0.2'
```
### Lvy:
```lvy
<dependency org='com.king.view' name='radarview' rev='1.0.1'>
<dependency org='com.king.view' name='radarview' rev='1.0.2'>
<artifact name='$AID' ext='pom'></artifact>
</dependency>
```
Expand Down
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ publish {
userOrg = 'jenly'//bintray.com用户名
groupId = 'com.king.view'//jcenter上的路径
artifactId = 'radarview'//项目名称
publishVersion = '1.0.1'//版本号
publishVersion = '1.0.2'//版本号
desc = 'RadarView for Android'//描述
website = 'https://github.com/jenly1314/RadarView'//网站
}
30 changes: 22 additions & 8 deletions lib/src/main/java/com/king/view/radarview/RadarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The MIT License (MIT)
package com.king.view.radarview;

import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
Expand All @@ -31,6 +32,7 @@ The MIT License (MIT)
import android.graphics.Shader;
import android.graphics.SweepGradient;
import android.graphics.Typeface;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.text.TextUtils;
Expand Down Expand Up @@ -207,9 +209,17 @@ public RadarView(Context context, @Nullable AttributeSet attrs, int defStyleAttr
init(context,attrs);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public RadarView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr,defStyleRes);
init(context,attrs);
}



private void init(Context context,AttributeSet attrs) {

mPaint = new Paint();
mPaint =new Paint();
mMatrix = new Matrix();

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RadarView);
Expand Down Expand Up @@ -265,27 +275,31 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = measureHandler(widthMeasureSpec,defaultWidth);
int height = measureHandler(heightMeasureSpec,defaultHeight);

setMeasuredDimension(width,height);
//圆心坐标
mCircleCenterX = (getWidth() + getPaddingLeft() - getPaddingRight())/ 2.0f;
mCircleCenterY = (getHeight() + getPaddingTop() - getPaddingBottom())/ 2.0f;
mCircleCenterX = (width + getPaddingLeft() - getPaddingRight())/ 2.0f;
mCircleCenterY = (height + getPaddingTop() - getPaddingBottom())/ 2.0f;

//外圆半径
mRadius = (getWidth()- getPaddingLeft() - getPaddingRight() - mOutsideStrokeWidth) / 2.0f;
mRadius = (width - getPaddingLeft() - getPaddingRight() - mOutsideStrokeWidth) / 2.0f;
//内院的半径 为外援半径的1/3
mInsideRadius = mRadius / 3;

setMeasuredDimension(width,height);

}

private int measureHandler(int measureSpec,int defaultSize){

private int measureHandler(int measureSpec, int defaultSize){

int result = defaultSize;
int measureMode = MeasureSpec.getMode(measureSpec);
int measureSize = MeasureSpec.getSize(measureSpec);
if(measureMode == MeasureSpec.EXACTLY){
result = measureSize;
if(measureMode == MeasureSpec.UNSPECIFIED){
result = defaultSize;
}else if(measureMode == MeasureSpec.AT_MOST){
result = Math.min(defaultSize,measureSize);
}else{
result = measureSize;
}
return result;
}
Expand Down

0 comments on commit 38222ef

Please sign in to comment.