Skip to content

Commit

Permalink
adjust code
Browse files Browse the repository at this point in the history
update version
update README
  • Loading branch information
qintong1 committed May 22, 2017
1 parent de84f44 commit 630a245
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
8 changes: 7 additions & 1 deletion README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Add dependencies in build.gradle.

```
dependencies {
compile 'com.qintong:insLoadingAnimation:0.9.1'
compile 'com.qintong:insLoadingAnimation:1.0.1'
}
```

Expand Down Expand Up @@ -87,6 +87,12 @@ java:
```
The default circle duration and rotate duration is 2000ms and 10000ms.

## Contact me

[Email](mailto:qintong5900@163.com)

[My Blog](http://www.jianshu.com/u/d2b8b611095d)

### License
```
Copyright 2017 Qin Tong
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ InsLoadingAnimation 是仿instagram和微博的头像点击进行加载的Androi

```
dependencies {
compile 'com.qintong:insLoadingAnimation:0.9.1'
compile 'com.qintong:insLoadingAnimation:1.0.1'
}
```

Expand Down Expand Up @@ -86,6 +86,12 @@ java:
```
默认的时间为2000ms和10000ms。

## 关于我

[Email](mailto:qintong5900@163.com)

[My Blog](http://www.jianshu.com/u/d2b8b611095d)

### 许可
```
Copyright 2017 Qin Tong
Expand Down
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 2
versionName "0.9.1"
versionCode 4
versionName "1.0.1"

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

Expand Down Expand Up @@ -39,7 +39,7 @@ publish {
userOrg = 'qintong000'
groupId = 'com.qintong'
artifactId = 'insLoadingAnimation'
publishVersion = '0.9.1'
publishVersion = '1.0.1'
desc = "Imitation of instagram and weibo loading animation "
website = siteUrl
}
23 changes: 14 additions & 9 deletions library/src/main/java/com/qintong/library/InsLoadingView.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class InsLoadingView extends ImageView {
private static String TAG = "InsLoadingView";
private static boolean DEBUG = BuildConfig.DEBUG;
private static final float ARC_WIDTH = 12;
private static final int MIN_WIDTH = 300;

public enum Status {LOADING, CLICKED, UNCLICKED}

Expand Down Expand Up @@ -57,6 +58,7 @@ public enum Status {LOADING, CLICKED, UNCLICKED}
private ValueAnimator mTouchAnim;
private int mStartColor = Color.parseColor("#FFF700C2");
private int mEndColor = Color.parseColor("#FFFFD900");
private int mClickedColor = Color.LTGRAY;
private float mScale = 1f;

public InsLoadingView(Context context) {
Expand Down Expand Up @@ -119,19 +121,15 @@ protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpe
width = Math.min(widthSpecSize, heightSpecSize);
} else {
width = Math.min(widthSpecSize, heightSpecSize);
width = Math.min(width, 300);
width = Math.min(width, MIN_WIDTH);
}
setMeasuredDimension(width, width);
}

@Override
protected synchronized void onDraw(Canvas canvas) {
canvas.scale(mScale, mScale, centerX(), centerY());
Paint bitmapPaint = new Paint();
setBitmapShader(bitmapPaint);
RectF rectF = new RectF(getWidth() * (1 - bitmapDia), getWidth() * (1 - bitmapDia),
getWidth() * bitmapDia, getHeight() * bitmapDia);
canvas.drawOval(rectF, bitmapPaint);
drawBitmap(canvas);
Paint paint = getPaint(getColor(0), getColor(360), 360);
switch (mStatus) {
case LOADING:
Expand All @@ -143,7 +141,7 @@ protected synchronized void onDraw(Canvas canvas) {
case CLICKED:
// TO DO
Paint paintClicked = new Paint();
paintClicked.setColor(Color.LTGRAY);
paintClicked.setColor(mClickedColor);
setPaintStroke(paintClicked);
drawCircle(canvas, paintClicked);
break;
Expand Down Expand Up @@ -279,6 +277,14 @@ public void onAnimationUpdate(ValueAnimator animation) {
startAnim();
}

private void drawBitmap(Canvas canvas) {
Paint bitmapPaint = new Paint();
setBitmapShader(bitmapPaint);
RectF rectF = new RectF(getWidth() * (1 - bitmapDia), getWidth() * (1 - bitmapDia),
getWidth() * bitmapDia, getHeight() * bitmapDia);
canvas.drawOval(rectF, bitmapPaint);
}

private void drawTrack(Canvas canvas, Paint paint) {
canvas.rotate(degress, centerX(), centerY());
canvas.rotate(ARC_WIDTH, centerX(), centerY());
Expand Down Expand Up @@ -388,9 +394,8 @@ private void setBitmapShader(Paint paint) {
}
Bitmap bitmap = drawableToBitmap(drawable);
BitmapShader tshader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
float scale = 1.0f;
int bSize = Math.min(bitmap.getWidth(), bitmap.getHeight());
scale = getWidth() * 1.0f / bSize;
float scale = getWidth() * 1.0f / bSize;
matrix.setScale(scale, scale);
if (bitmap.getWidth() > bitmap.getHeight()) {
matrix.postTranslate(-(bitmap.getWidth() * scale - getWidth()) / 2, 0);
Expand Down

0 comments on commit 630a245

Please sign in to comment.