Skip to content

Commit

Permalink
-支持xml添加head foot
Browse files Browse the repository at this point in the history
  • Loading branch information
tohodog committed Jul 21, 2017
1 parent 20218e6 commit a8b6582
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ public QSRefreshLayout(Context context) {

public QSRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
initData();
post(new Runnable() {
@Override
public void run() {
initData();

}
});
}

private void initData() {
setHeadRefreshView(new CircleImageView(getContext()));
setFootRefreshView(new BarRefreshView(getContext()));
if (!ensureRefreshView()) {
setHeadRefreshView(new CircleImageView(getContext()));
setFootRefreshView(new BarRefreshView(getContext()));
}
}

public void setHeadRefreshView(IRefreshView headRefreshView) {
Expand Down Expand Up @@ -88,6 +96,31 @@ protected View ensureTarget() {
return mTarget;
}

protected boolean ensureRefreshView() {
boolean b = false;
if (getChildCount() > 0) {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (child instanceof IRefreshView) {
IRefreshView v = (IRefreshView) child;
if (!b) {
headRefreshView = v;
headRefreshView.isHeadView(true);
headRefreshView.getView().setVisibility(INVISIBLE);
isOpenHeadRefresh(true);
} else {
footRefreshView = v;
footRefreshView.isHeadView(false);
footRefreshView.getView().setVisibility(INVISIBLE);
isOpenFootRefresh(true);
}
b = true;
}
}
}
return b;
}

@Override
protected boolean canChildScrollUp() {
if (android.os.Build.VERSION.SDK_INT < 14) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import org.song.refreshlayout.IRefreshView;
Expand All @@ -20,8 +22,13 @@ public class AnimeRefreshView extends ImageView implements IRefreshView {
private int tempIndex;
private AnimationDrawable animationDrawable;


public AnimeRefreshView(Context context) {
super(context);
this(context, null);
}

public AnimeRefreshView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public void setDrawAnimes(int[] animes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

Expand All @@ -20,7 +21,11 @@ public class BarRefreshView extends View implements IRefreshView {
private SwipeProgressBar swipeProgressBar;

public BarRefreshView(Context context) {
super(context);
this(context, null);
}

public BarRefreshView(Context context, AttributeSet attrs) {
super(context, attrs);
float density = context.getResources().getDisplayMetrics().density;

swipeProgressBar = new SwipeProgressBar(this);
Expand All @@ -37,7 +42,7 @@ public void setColorScheme(int... color1) {
@Override//确定view大小
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
swipeProgressBar.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
swipeProgressBar.setBounds(0, 0, getMeasuredWidth(), height = getMeasuredHeight());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
Expand Down Expand Up @@ -40,7 +41,11 @@ public class CircleImageView extends ImageView implements IRefreshView {

@SuppressWarnings("deprecation")
public CircleImageView(Context context) {
super(context);
this(context, null);
}

public CircleImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

Expand Down Expand Up @@ -78,15 +83,17 @@ private void init() {
setLayoutParams(new ViewGroup.LayoutParams(diameter, diameter));
}

@Override//锁死view大小
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(diameter, diameter);
}

//设置大小
public void setRadius(int radius) {
this.radius = radius;
init();
}

private boolean elevationSupported() {
return android.os.Build.VERSION.SDK_INT >= 21;
}

public void setColorScheme(int... color1) {
materialProgressDrawable.setColorSchemeColors(color1);
}
Expand Down Expand Up @@ -197,6 +204,10 @@ public void isHeadView(boolean isHead) {

}

private boolean elevationSupported() {
return android.os.Build.VERSION.SDK_INT >= 21;
}


private class OvalShadow extends OvalShape {
private final RadialGradient mRadialGradient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -34,7 +35,11 @@ public class XMLRefreshView extends FrameLayout implements IRefreshView {
refreshed = "刷新完成";

public XMLRefreshView(Context context) {
super(context);
this(context, null);
}

public XMLRefreshView(Context context, AttributeSet attrs) {
super(context, attrs);
refreshView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.refresh, this, false);
refreshTV = (TextView) refreshView.findViewById(R.id.refresh_tv);
refreshIV = (ImageView) refreshView.findViewById(R.id.refresh_iv);
Expand Down Expand Up @@ -136,7 +141,7 @@ public void isHeadView(boolean isHead) {
dragging = isHead ? "下拉刷新" : "上拉刷新";
}

public void setBlackStyle(){
public void setBlackStyle() {

}

Expand Down
1 change: 1 addition & 0 deletions RefreshLayout/src/main/res/layout/refresh.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center"
android:layout_gravity="center"
android:orientation="horizontal">

<FrameLayout
Expand Down
5 changes: 5 additions & 0 deletions RefreshLayout/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="qsrefresh_head" type="id" />
<item name="qsrefresh_foot" type="id" />
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.animation.ObjectAnimator;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -34,7 +35,11 @@ public class ElemeRefreshView extends FrameLayout implements IRefreshView {
float density;

public ElemeRefreshView(Context context) {
super(context);
this(context, null);
}

public ElemeRefreshView(Context context, AttributeSet attrs) {
super(context, attrs);
density = context.getResources().getDisplayMetrics().density;
triggerDistance = (int) (density * 100);

Expand All @@ -45,8 +50,6 @@ public ElemeRefreshView(Context context) {
eleme_content_box = (ViewGroup) refreshView.findViewById(R.id.eleme_content_box);

addView(refreshView);


}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
Expand All @@ -25,8 +25,12 @@ public class JDRefreshView extends FrameLayout implements IRefreshView {
TextView jd_text;
int status;

public JDRefreshView(@NonNull Context context) {
super(context);
public JDRefreshView(Context context) {
this(context, null);
}

public JDRefreshView(Context context, AttributeSet attrs) {
super(context, attrs);
View refreshView = LayoutInflater.from(context).inflate(R.layout.refresh_jd, this, false);
jd_text = (TextView) refreshView.findViewById(R.id.jd_text);
jd_people = (ImageView) refreshView.findViewById(R.id.jd_people);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public class PlainRefreshDraw extends Drawable implements Drawable.Callback, Ani
private Random mRandom;
private boolean mEndOfRefreshing;



private int getTotalDragDistance;

private enum AnimationPart {
Expand Down Expand Up @@ -122,6 +124,10 @@ private void initiateDimens() {
mScreenWidth = mContext.getResources().getDisplayMetrics().widthPixels;
mJetTopOffset = getTotalDragDistance * 0.5f;
}
public void setGetTotalDragDistance(int getTotalDragDistance) {
this.getTotalDragDistance = getTotalDragDistance;
mJetTopOffset = getTotalDragDistance * 0.5f;
}

private void createBitmaps() {
mLeftClouds = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.clouds_left);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.song.qsrefreshlayout.refreshview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand All @@ -18,15 +19,24 @@ public class PlainRefreshView extends ImageView implements IRefreshView {
PlainRefreshDraw plainRefreshDraw;

public PlainRefreshView(Context context) {
super(context);
this(context, null);
}

public PlainRefreshView(Context context, AttributeSet attrs) {
super(context, attrs);
float density = context.getResources().getDisplayMetrics().density;
mTotalDragDistance = Math.round((float) 120 * density);
setLayoutParams(new ViewGroup.LayoutParams(-1, mTotalDragDistance));
setLayoutParams(new ViewGroup.LayoutParams(-1, mTotalDragDistance = Math.round((float) 120 * density)));

plainRefreshDraw = new PlainRefreshDraw(context, mTotalDragDistance);
plainRefreshDraw = new PlainRefreshDraw(getContext(), mTotalDragDistance);
setImageDrawable(plainRefreshDraw);
}

@Override//确定view大小
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
plainRefreshDraw.setGetTotalDragDistance(mTotalDragDistance = getMeasuredHeight());
}

@Override
public View getView() {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class SunRefreshDraw extends SunBaseRefreshDraw implements Animatable {

private static final Interpolator LINEAR_INTERPOLATOR = new LinearInterpolator();


private int getTotalDragDistance;

private Matrix mMatrix;
Expand Down Expand Up @@ -93,6 +94,13 @@ public void initiateDimens(int viewWidth) {
createBitmaps();
}

public void setGetTotalDragDistance(int getTotalDragDistance) {
this.getTotalDragDistance = getTotalDragDistance;
mTownInitialTopOffset = (getTotalDragDistance - mTownHeight * TOWN_INITIAL_SCALE);
mTownFinalTopOffset = (getTotalDragDistance - mTownHeight * TOWN_FINAL_SCALE);
mSunTopOffset = (getTotalDragDistance * 0.1f);
}

private void createBitmaps() {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.song.qsrefreshlayout.refreshview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
Expand All @@ -17,16 +18,26 @@ public class SunRefreshView extends ImageView implements IRefreshView {
int mTotalDragDistance;
SunRefreshDraw plainRefreshDraw;


public SunRefreshView(Context context) {
super(context);
this(context, null);
}

public SunRefreshView(Context context, AttributeSet attrs) {
super(context, attrs);
float density = context.getResources().getDisplayMetrics().density;
mTotalDragDistance = Math.round((float) 120 * density);
setLayoutParams(new ViewGroup.LayoutParams(-1, mTotalDragDistance));
setLayoutParams(new ViewGroup.LayoutParams(-1, mTotalDragDistance = Math.round((float) 120 * density)));

plainRefreshDraw = new SunRefreshDraw(context, mTotalDragDistance);
setImageDrawable(plainRefreshDraw);
}

@Override//确定view大小
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
plainRefreshDraw.setGetTotalDragDistance(mTotalDragDistance = getMeasuredHeight());
}

@Override
public View getView() {
return this;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_recyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:id="@+id/qs"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:background="#ffffff"
Expand Down

0 comments on commit a8b6582

Please sign in to comment.