Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
add sunrefreshview and modify sample's icon
Browse files Browse the repository at this point in the history
  • Loading branch information
LuMeng committed Jul 8, 2016
1 parent c072720 commit 508a445
Show file tree
Hide file tree
Showing 22 changed files with 311 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import lumenghz.com.pullrefresh.refresh_view.BaseRefreshView;
import lumenghz.com.pullrefresh.refresh_view.RocketRefreshView;
import lumenghz.com.pullrefresh.refresh_view.SunRefreshView;
import lumenghz.com.pullrefresh.util.Utils;

/**
Expand All @@ -30,10 +31,12 @@
*/
public class PullToRefreshView extends ViewGroup {
private static final int DRAG_MAX_DISTANCE = 120;
private static final int DRAW_MAX_DISTANCE_SUN = 140;
private static final float DRAG_RATE = .5f;
private static final float DECELERATE_INTERPOLATION_FACTOR = 2f;

public static final int STYPE_ROCKET = 0;
public static final int TYPE_ROCKET = 0;
public static final int TYPE_SUN = 1;
public static final int MAX_OFFSET_ANIMATION_DURATION = 700;

private static final int INVALID_POINTER = -1;
Expand Down Expand Up @@ -78,27 +81,38 @@ public PullToRefreshView(Context context) {
public PullToRefreshView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullToRefreshView);
final int type = a.getInteger(R.styleable.PullToRefreshView_lrefresh, STYPE_ROCKET);
final int type = a.getInteger(R.styleable.PullToRefreshView_lrefresh, TYPE_ROCKET);
a.recycle();

mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
mTotalDragDistance = Utils.convertDpToPixel(context, DRAG_MAX_DISTANCE);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

mRefreshView = new ImageView(context);

setRefreshStyle(type);
setRefreshStyle(context, type);

addView(mRefreshView);
setWillNotDraw(false);
ViewCompat.setChildrenDrawingOrderEnabled(this, true);
}

private void setRefreshStyle(int type) {
/**
* Set landscape's height dynamically because different landscape suitable different heights.
*
* @param context context
* @param type type of theme which chosen by user
* @see {@link #mTotalDragDistance = Utils.convertDpToPixel} in this method
*/
private void setRefreshStyle(Context context, int type) {
setRefreshing(false);
switch (type) {
case STYPE_ROCKET:
case TYPE_ROCKET:
mBaseRefreshView = new RocketRefreshView(getContext(), this);
mTotalDragDistance = Utils.convertDpToPixel(context, DRAG_MAX_DISTANCE);
break;
case TYPE_SUN:
mBaseRefreshView = new SunRefreshView(getContext(), this);
mTotalDragDistance = Utils.convertDpToPixel(context, DRAW_MAX_DISTANCE_SUN);
break;
default:
throw new InvalidParameterException("Type is not exists");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;

/**
* @author lumeng on 2016-06-16.
* [email protected]
*/
public class AnimationFractory {
public class AnimationFactory {
private static final int ANIMATION_FIRE_BURN_DURATION = 180;
private static final int ANIMATION_FIRE_SCALE_DURATION = 100;
private static final int ANIMATION_SUN_ROTATE_DURATION = 1000;

private static final Interpolator ACCELERATE_INTERPOLATOR = new AccelerateInterpolator();
private static final Interpolator DECELERATE_INTERPOLATOR = new AccelerateDecelerateInterpolator();
private static final Interpolator NORMAL_INTERPOLATOR = new LinearInterpolator();

Animation getFireScale(Animation animation) {
configureAnimation(animation,
Expand All @@ -38,6 +41,17 @@ Animation getFireBurn(Animation animation) {
return animation;
}

Animation getSunRotate(Animation animation) {
configureAnimation(animation,
NORMAL_INTERPOLATOR,
ANIMATION_SUN_ROTATE_DURATION,
0,
Animation.RESTART,
Animation.INFINITE);

return animation;
}

private void configureAnimation(Animation animation, Interpolator interpolator, int duration, int startOffset, int repeatMode, int repeatCount) {
animation.setInterpolator(interpolator);
animation.setDuration(duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.Build;

import lumenghz.com.pullrefresh.PullToRefreshView;
import lumenghz.com.pullrefresh.util.Utils;

/**
* @author lumeng on 2016-06-16.
Expand All @@ -31,6 +32,14 @@ protected Context getContext() {

public abstract void offsetTopAndBottom(int offset);

protected abstract void initialDimens(int viewWidth);

protected abstract void setupAnimations();

protected int getPixel(int dp) {
return Utils.convertDpToPixel(getContext(), dp);
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void invalidateDrawable(Drawable who) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public void run() {
});
}

private void initialDimens(int viewWidth) {
@Override
protected void initialDimens(int viewWidth) {
if (viewWidth <= 0 || viewWidth == mScreenWidth) return;
mScreenWidth = viewWidth;

Expand Down Expand Up @@ -267,8 +268,9 @@ public boolean isRunning() {
return false;
}

private void setupAnimations() {
AnimationFractory animationFractory = new AnimationFractory();
@Override
protected void setupAnimations() {
AnimationFactory animationFractory = new AnimationFactory();
mFireBurnAnimation = animationFractory.getFireBurn(new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
Expand Down
Loading

0 comments on commit 508a445

Please sign in to comment.