Skip to content

Commit

Permalink
Java code styling + more consistent code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibolte committed Aug 6, 2015
1 parent 0f69b51 commit ed6373d
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public void run() {
};

public interface Callback {
public void onAnimationDone();
void onAnimationDone();

public void onAnimationStopped();
void onAnimationStopped();
}

public AVDWrapper(Animatable drawable,
Expand All @@ -44,7 +44,9 @@ public void stop() {
mDrawable.stop();
mHandler.removeCallbacks(mAnimationDoneRunnable);

if (mCallback != null) mCallback.onAnimationStopped();
if (mCallback != null) {
mCallback.onAnimationStopped();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void onEnterAnimationFinished() {
mProgressDownloadView.setVisibility(VISIBLE);
mProgressDownloadView.setProgress(mProgressDownloadView.getProgress());

//do further actions if necessary
// Do further actions if necessary
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class IntroView extends ImageView {
private static final String LOG_TAG = IntroView.class.getSimpleName();

public interface EnterAnimationListener {
public void onEnterAnimationFinished();
void onEnterAnimationFinished();
}

private EnterAnimationListener mListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package is.arontibo.library;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.animation.ObjectAnimator;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
Expand All @@ -15,10 +19,6 @@
import android.view.animation.DecelerateInterpolator;
import android.view.animation.OvershootInterpolator;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.animation.ObjectAnimator;

/**
* Created by thibaultguegan on 15/02/15.
*/
Expand Down Expand Up @@ -91,7 +91,7 @@ protected void onDraw(Canvas canvas) {

switch (mState) {
case STATE_WORKING:
//save and restore prevent the rest of the canvas to not be rotated
// Save and restore prevent the rest of the canvas to not be rotated
canvas.save();
float speed = (getProgress() - mTarget) / 20;
mBubbleAngle += speed * 10;
Expand Down Expand Up @@ -148,7 +148,7 @@ protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld) {
mHeight = yNew;
Log.d(LOG_TAG, String.format("width and height measured are %d and %d", mWidth, mHeight));

//call this if the enter animation is not used
// Call this if the enter animation is not used
//setPercentage(mProgress);
}

Expand Down Expand Up @@ -199,35 +199,35 @@ private void makePathBubble() {

Path path = new Path();

//down arrow
// Down arrow
path.moveTo(r.left + r.width() / 2 - arrowWidth / 2, r.top + r.height() - arrowHeight);
bubbleAnchorX = r.left + r.width() / 2;
bubbleAnchorY = r.top + r.height();
path.lineTo(bubbleAnchorX, bubbleAnchorY);
path.lineTo(r.left + r.width() / 2 + arrowWidth / 2, r.top + r.height() - arrowHeight);

//go to bottom-right
// Go to bottom-right
path.lineTo(r.left + r.width() - radius, r.top + r.height() - arrowHeight);

//bottom-right arc
// Bottom-right arc
path.arcTo(new RectF(r.left + r.width() - 2 * radius, r.top + r.height() - arrowHeight - 2 * radius, r.left + r.width(), r.top + r.height() - arrowHeight), 90, -90);

//go to upper-right
// Go to upper-right
path.lineTo(r.left + r.width(), r.top + arrowHeight);

//upper-right arc
// Upper-right arc
path.arcTo(new RectF(r.left + r.width() - 2 * radius, r.top, r.right, r.top + 2 * radius), 0, -90);

//go to upper-left
// Go to upper-left
path.lineTo(r.left + radius, r.top);

//upper-left arc
// Upper-left arc
path.arcTo(new RectF(r.left, r.top, r.left + 2 * radius, r.top + 2 * radius), 270, -90);

//go to bottom-left
// Go to bottom-left
path.lineTo(r.left, r.top + r.height() - arrowHeight - radius);

//bottom-left arc
// Bottom-left arc
path.arcTo(new RectF(r.left, r.top + r.height() - arrowHeight - 2 * radius, r.left + 2 * radius, r.top + r.height() - arrowHeight), 180, -90);

path.close();
Expand All @@ -249,8 +249,9 @@ private float calculateDeltaY() {
}

public void setPercentage(float newProgress) {
if (newProgress < 0 || newProgress > 100)
if (newProgress < 0 || newProgress > 100) {
throw new IllegalArgumentException("setPercentage not between 0 and 100");
}

mState = State.STATE_WORKING;
mTarget = newProgress;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package is.arontibo.library.VectorCompat;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorInflater;
import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.animation.ValueAnimator;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
Expand All @@ -16,14 +24,6 @@
import android.util.Log;
import android.util.Xml;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorInflater;
import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.animation.ValueAnimator;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public void setHotspot(float x, float y) {
/**
* Sets the bounds to which the hotspot is constrained, if they should be
* different from the drawable bounds.
*
* @param left
* @param top
* @param right
* @param bottom
*/
public void setHotspotBounds(int left, int top, int right, int bottom) {
}
Expand Down Expand Up @@ -91,7 +86,6 @@ PorterDuffColorFilter updateTintFilter(PorterDuffColorFilter tintFilter, ColorSt
/**
* Parses a {@link android.graphics.PorterDuff.Mode} from a tintMode
* attribute's enum value.
*
*/
public static PorterDuff.Mode parseTintMode(int value, PorterDuff.Mode defaultMode) {
switch (value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public final class Outline {
* Constructs an empty Outline. Call one of the setter methods to make
* the outline valid for use with a View.
*/
public Outline() {}
public Outline() {
}

/**
* Constructs an Outline with a copy of the data in src.
Expand Down Expand Up @@ -141,7 +142,9 @@ public void setRoundRect(int left, int top, int right, int bottom, float radius)
return;
}

if (mRect == null) mRect = new Rect();
if (mRect == null) {
mRect = new Rect();
}
mRect.set(left, top, right, bottom);
mRadius = radius;
mPath = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package is.arontibo.library.VectorCompat;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.animation.TypeEvaluator;
import com.nineoldandroids.animation.ValueAnimator;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
Expand All @@ -10,15 +19,6 @@
import android.view.InflateException;
import android.view.animation.AnimationUtils;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.animation.TypeEvaluator;
import com.nineoldandroids.animation.ValueAnimator;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;

Expand Down Expand Up @@ -57,7 +57,9 @@ public static Animator loadAnimator(Context c, Resources resources, Resources.Th
rnf.initCause(ex);
throw rnf;
} finally {
if (parser != null) parser.close();
if (parser != null) {
parser.close();
}
}
}

Expand Down Expand Up @@ -147,10 +149,10 @@ private static ObjectAnimator loadObjectAnimator(Context c, Resources res, Resou
* Creates a new animation whose parameters come from the specified context
* and attributes set.
*
* @param res The resources
* @param res The resources
* @param attrs The set of attributes holding the animation parameters
* @param anim Null if this is a ValueAnimator, otherwise this is an
* ObjectAnimator
* @param anim Null if this is a ValueAnimator, otherwise this is an
* ObjectAnimator
*/
private static ValueAnimator loadAnimator(Context c, Resources res, Resources.Theme theme,
AttributeSet attrs, ValueAnimator anim, float pathErrorScale)
Expand Down Expand Up @@ -196,10 +198,10 @@ private static ValueAnimator loadAnimator(Context c, Resources res, Resources.Th
}

/**
* @param anim The animator, must not be null
* @param arrayAnimator Incoming typed array for Animator's attributes.
* @param anim The animator, must not be null
* @param arrayAnimator Incoming typed array for Animator's attributes.
* @param arrayObjectAnimator Incoming typed array for Object Animator's
* attributes.
* attributes.
*/
private static void parseAnimatorFromTypeArray(ValueAnimator anim,
TypedArray arrayAnimator, TypedArray arrayObjectAnimator) {
Expand Down Expand Up @@ -242,7 +244,7 @@ private static void parseAnimatorFromTypeArray(ValueAnimator anim,
/**
* Setup the Animator to achieve path morphing.
*
* @param anim The target Animator which will be updated.
* @param anim The target Animator which will be updated.
* @param arrayAnimator TypedArray for the ValueAnimator.
* @return the PathDataEvaluator.
*/
Expand All @@ -262,11 +264,11 @@ private static TypeEvaluator setupAnimatorForPath(ValueAnimator anim,
+ " Can't morph from " + fromString + " to " + toString);
}
} else {
anim.setObjectValues((Object)nodesFrom);
anim.setObjectValues((Object) nodesFrom);
}
evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesFrom));
} else if (nodesTo != null) {
anim.setObjectValues((Object)nodesTo);
anim.setObjectValues((Object) nodesTo);
evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesTo));
}

Expand All @@ -280,9 +282,8 @@ private static TypeEvaluator setupAnimatorForPath(ValueAnimator anim,
/**
* Setup ObjectAnimator's property or values from pathData.
*
* @param anim The target Animator which will be updated.
* @param anim The target Animator which will be updated.
* @param arrayObjectAnimator TypedArray for the ObjectAnimator.
*
*/
private static void setupObjectAnimator(ValueAnimator anim, TypedArray arrayObjectAnimator) {
ObjectAnimator oa = (ObjectAnimator) anim;
Expand All @@ -305,7 +306,8 @@ private static class PathDataEvaluator implements TypeEvaluator<PathParser.PathD
* Care must be taken when using this option because on every evaluation
* a new <code>PathParser.PathDataNode[]</code> will be allocated.
*/
private PathDataEvaluator() {}
private PathDataEvaluator() {
}

/**
* Create a PathDataEvaluator that reuses <code>nodeArray</code> for every evaluate() call.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package is.arontibo.library.VectorCompat;


import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
Expand All @@ -26,9 +29,6 @@
import android.util.Log;
import android.util.Xml;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Stack;
Expand Down
9 changes: 5 additions & 4 deletions example/src/main/java/is/arontibo/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

public class MainActivity extends ActionBarActivity {

@InjectView(R.id.elastic_download_view) ElasticDownloadView mElasticDownloadView;
@InjectView(R.id.elastic_download_view)
ElasticDownloadView mElasticDownloadView;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -53,7 +54,7 @@ public void run() {
public void run() {
mElasticDownloadView.success();
}
}, 2*ProgressDownloadView.ANIMATION_DURATION_BASE);
}, 2 * ProgressDownloadView.ANIMATION_DURATION_BASE);

return true;
} else if (id == R.id.action_run_fail_animation) {
Expand All @@ -70,14 +71,14 @@ public void run() {
public void run() {
mElasticDownloadView.setProgress(45);
}
}, 2*ProgressDownloadView.ANIMATION_DURATION_BASE);
}, 2 * ProgressDownloadView.ANIMATION_DURATION_BASE);

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mElasticDownloadView.fail();
}
}, 3*ProgressDownloadView.ANIMATION_DURATION_BASE);
}, 3 * ProgressDownloadView.ANIMATION_DURATION_BASE);

return true;
}
Expand Down

0 comments on commit ed6373d

Please sign in to comment.