Skip to content

Dev #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Dev #34

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
buildscript {
repositories {
jcenter()
maven {
url "https://jcenter.bintray.com"
}
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/com/baoyz/widget/ArcDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ArcDrawable extends RefreshDrawable{
private int mLevel;

ArcDrawable(Context context, PullRefreshLayout layout) {
super(context, layout);
super(layout);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Color.RED);
}
Expand Down Expand Up @@ -110,7 +110,7 @@ protected void onBoundsChange(Rect bounds) {
}

@Override
public void draw(Canvas canvas) {
public void onDraw(Canvas canvas) {
canvas.save();
// canvas.translate(0, mTop);
drawRing(canvas);
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/com/baoyz/widget/CirclesDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CirclesDrawable extends RefreshDrawable implements Runnable {
private Rect mBounds;

public CirclesDrawable(Context context, PullRefreshLayout layout) {
super(context, layout);
super(layout);
}

@Override
Expand Down Expand Up @@ -198,7 +198,7 @@ private void resetColor(ProgressStates currentState) {
}

@Override
public void draw(Canvas canvas) {
public void onDraw(Canvas canvas) {
if (mCurrentState != null) {
canvas.save();
canvas.translate(mBounds.width() / 2 - mDrawWidth / 2, mTop);
Expand Down
53 changes: 29 additions & 24 deletions library/src/main/java/com/baoyz/widget/MaterialDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class MaterialDrawable extends RefreshDrawable implements Animatable {
private static final Interpolator END_CURVE_INTERPOLATOR = new EndCurveInterpolator();
private static final Interpolator START_CURVE_INTERPOLATOR = new StartCurveInterpolator();
private static final Interpolator EASE_INTERPOLATOR = new AccelerateDecelerateInterpolator();
private Rect mRect;
private boolean isRunning;

@Retention(RetentionPolicy.CLASS)
@IntDef({LARGE, DEFAULT})
Expand Down Expand Up @@ -151,7 +153,7 @@ class MaterialDrawable extends RefreshDrawable implements Animatable {
private int mDiameter;

public MaterialDrawable(Context context, PullRefreshLayout parent) {
super(context, parent);
super(parent);
mParent = parent;
mResources = context.getResources();

Expand Down Expand Up @@ -205,8 +207,8 @@ public OvalShadow(int shadowRadius, int circleDiameter) {

@Override
public void draw(Canvas canvas, Paint paint) {
final int x = MaterialDrawable.this.getBounds().centerX();
final int y = MaterialDrawable.this.getBounds().centerY();
final int x = mRect.centerX();
final int y = mRect.centerY();
canvas.drawCircle(x, y, (mCircleDiameter / 2 + mShadowRadius),
mShadowPaint);
canvas.drawCircle(x, y, (mCircleDiameter / 2), paint);
Expand Down Expand Up @@ -287,13 +289,12 @@ public void setBackgroundColor(int color) {
public void setPercent(float percent) {
if (percent < .4f)
return;
percent = (percent - .4f) / .6f;
percent = (percent - .4f) / .6f * 1.2f;
setAlpha((int) (MAX_ALPHA * percent));
showArrow(true);
float strokeStart = ((percent) * .8f);
setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, percent));
setArrowScale(Math.min(1f, percent));
float rotation = percent < .8f ? 0 : (percent - .8f) / .2f * .25f;
float rotation = percent > MAX_PROGRESS_ANGLE ? (percent - MAX_PROGRESS_ANGLE) * .9f : 0;
setProgressRotation(rotation);
}

Expand Down Expand Up @@ -326,8 +327,8 @@ public void offsetTopAndBottom(int offset) {
// }

@Override
public void draw(Canvas c) {
Rect bounds = getBounds();
public void onDraw(Canvas c) {
Rect bounds = mRect;
final int saveCount = c.save();
c.translate(0, mTop);
mCircle.draw(c);
Expand All @@ -340,14 +341,16 @@ public void draw(Canvas c) {
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);

int w = bounds.width();
int top = bounds.top;
mRect = new Rect(w / 2 - mDiameter / 2, top, w / 2 + mDiameter / 2, mDiameter + top);
}

@Override
public void setBounds(int left, int top, int right, int bottom) {
int w = right - left;
super.setBounds(w / 2 - mDiameter / 2, top, w / 2 + mDiameter / 2, mDiameter + top);
}
// @Override
// public void setBounds(int left, int top, int right, int bottom) {
// int w = right - left;
// super.setBounds(w / 2 - mDiameter / 2, top, w / 2 + mDiameter / 2, mDiameter + top);
// }

private int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getContext().getResources().getDisplayMetrics());
Expand Down Expand Up @@ -385,19 +388,12 @@ public int getOpacity() {

@Override
public boolean isRunning() {
final ArrayList<Animation> animators = mAnimators;
final int N = animators.size();
for (int i = 0; i < N; i++) {
final Animation animator = animators.get(i);
if (animator.hasStarted() && !animator.hasEnded()) {
return true;
}
}
return false;
return isRunning;
}

@Override
public void start() {
isRunning = true;
mAnimation.reset();
mRing.storeOriginals();
// Already showing some part of the ring
Expand All @@ -417,6 +413,7 @@ public void stop() {
mRing.setShowArrow(false);
mRing.setColorIndex(0);
mRing.resetOriginals();
isRunning = false;
}

private void setupAnimators() {
Expand All @@ -425,6 +422,10 @@ private void setupAnimators() {
public void applyTransformation(float interpolatedTime, Transformation t) {
// shrink back down and complete a full rotation before starting other circles
// Rotation goes between [0..1].
if (!isRunning) {
mParent.clearAnimation();
return;
}
float targetRotation = (float) (Math.floor(ring.getStartingRotation()
/ MAX_PROGRESS_ARC) + 1f);
final float startTrim = ring.getStartingStartTrim()
Expand Down Expand Up @@ -462,6 +463,10 @@ public void onAnimationRepeat(Animation animation) {
public void applyTransformation(float interpolatedTime, Transformation t) {
// The minProgressArc is calculated from 0 to create an angle that
// matches the stroke width.
if (!isRunning) {
mParent.clearAnimation();
return;
}
final float minProgressArc = (float) Math.toRadians(ring.getStrokeWidth()
/ (2 * Math.PI * ring.getCenterRadius()));
final float startingEndTrim = ring.getStartingEndTrim();
Expand Down
Loading