Skip to content

Commit 1ce8d18

Browse files
committed
add attrs prefix
1 parent 942a3a0 commit 1ce8d18

File tree

14 files changed

+61
-191
lines changed

14 files changed

+61
-191
lines changed

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
33
android {
44
compileSdkVersion 21
55
buildToolsVersion "21.0.2"
6-
resourcePrefix "pullrefreshlayout"
6+
resourcePrefix "refresh"
77

88
defaultConfig {
99
minSdkVersion 8
@@ -28,7 +28,7 @@ dependencies {
2828
apply plugin: 'com.github.dcendents.android-maven'
2929
apply plugin: 'com.jfrog.bintray'
3030

31-
version = "1.1.0"
31+
version = "2.0.0"
3232
def siteUrl = 'https://github.com/baoyongzhang/android-PullRefreshLayout'
3333
def gitUrl = 'https://github.com/baoyongzhang/android-PullRefreshLayout.git'
3434
group = "com.baoyz.pullrefreshlayout"

library/src/main/java/com/baoyz/widget/PullRefreshLayout.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
import android.content.Context;
44
import android.content.res.TypedArray;
5-
import android.graphics.Canvas;
6-
import android.graphics.drawable.Drawable;
5+
import android.graphics.Color;
76
import android.support.v4.view.MotionEventCompat;
87
import android.support.v4.view.ViewCompat;
98
import android.util.AttributeSet;
10-
import android.util.Log;
119
import android.util.TypedValue;
1210
import android.view.MotionEvent;
1311
import android.view.View;
@@ -36,6 +34,7 @@ public class PullRefreshLayout extends ViewGroup {
3634
public static final int STYLE_CIRCLES = 1;
3735
public static final int STYLE_WATER_DROP = 2;
3836
public static final int STYLE_RING = 3;
37+
public static final int STYLE_SMARTISAN = 4;
3938

4039
private View mTarget;
4140
private ImageView mRefreshView;
@@ -66,9 +65,10 @@ public PullRefreshLayout(Context context) {
6665

6766
public PullRefreshLayout(Context context, AttributeSet attrs) {
6867
super(context, attrs);
69-
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullRefreshLayout);
70-
final int type = a.getInteger(R.styleable.PullRefreshLayout_type, STYLE_MATERIAL);
71-
final int colorsId = a.getResourceId(R.styleable.PullRefreshLayout_colors, R.array.google_colors);
68+
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.refresh_PullRefreshLayout);
69+
final int type = a.getInteger(R.styleable.refresh_PullRefreshLayout_refreshType, STYLE_MATERIAL);
70+
final int colorsId = a.getResourceId(R.styleable.refresh_PullRefreshLayout_refreshColors, 0);
71+
final int colorId = a.getResourceId(R.styleable.refresh_PullRefreshLayout_refreshColor, 0);
7272
a.recycle();
7373

7474
mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
@@ -78,21 +78,33 @@ public PullRefreshLayout(Context context, AttributeSet attrs) {
7878
mDurationToCorrectPosition = defaultDuration;
7979
mSpinnerFinalOffset = mTotalDragDistance = dp2px(DRAG_MAX_DISTANCE);
8080

81+
if (colorsId > 0) {
82+
mColorSchemeColors = context.getResources().getIntArray(colorsId);
83+
} else {
84+
mColorSchemeColors = new int[]{Color.rgb(0xC9, 0x34, 0x37), Color.rgb(0x37, 0x5B, 0xF1), Color.rgb(0xF7, 0xD2, 0x3E), Color.rgb(0x34, 0xA3, 0x50)};
85+
}
86+
87+
if (colorId > 0) {
88+
mColorSchemeColors = new int[]{context.getResources().getColor(colorId)};
89+
}
90+
8191
mRefreshView = new ImageView(context);
82-
mColorSchemeColors = context.getResources().getIntArray(colorsId);
8392
setRefreshStyle(type);
84-
// mRefreshDrawable.setColorSchemeColors(new int[]{Color.rgb(0xC9, 0x34, 0x37), Color.rgb(0x37, 0x5B, 0xF1), Color.rgb(0xF7, 0xD2, 0x3E), Color.rgb(0x34, 0xA3, 0x50)});
8593
mRefreshView.setVisibility(View.GONE);
8694
addView(mRefreshView, 0);
8795
setWillNotDraw(false);
8896
ViewCompat.setChildrenDrawingOrderEnabled(this, true);
8997
}
9098

91-
public void setColorSchemeColors(int[] colorSchemeColors) {
99+
public void setColorSchemeColors(int... colorSchemeColors) {
92100
mColorSchemeColors = colorSchemeColors;
93101
mRefreshDrawable.setColorSchemeColors(colorSchemeColors);
94102
}
95103

104+
public void setColor(int color) {
105+
setColorSchemeColors(color);
106+
}
107+
96108
public void setRefreshStyle(int type) {
97109
setRefreshing(false);
98110
switch (type) {
@@ -108,6 +120,9 @@ public void setRefreshStyle(int type) {
108120
case STYLE_RING:
109121
mRefreshDrawable = new RingDrawable(getContext(), this);
110122
break;
123+
case STYLE_SMARTISAN:
124+
mRefreshDrawable = new SmartisanDrawable(getContext(), this);
125+
break;
111126
default:
112127
throw new InvalidParameterException("Type does not exist");
113128
}
@@ -402,6 +417,7 @@ public void onAnimationEnd(Animation animation) {
402417
private Animation.AnimationListener mToStartListener = new Animation.AnimationListener() {
403418
@Override
404419
public void onAnimationStart(Animation animation) {
420+
mRefreshDrawable.stop();
405421
}
406422

407423
@Override
@@ -410,7 +426,7 @@ public void onAnimationRepeat(Animation animation) {
410426

411427
@Override
412428
public void onAnimationEnd(Animation animation) {
413-
mRefreshDrawable.stop();
429+
// mRefreshDrawable.stop();
414430
mRefreshView.setVisibility(View.GONE);
415431
mCurrentOffsetTop = mTarget.getTop();
416432
}

library/src/main/java/com/baoyz/widget/RingDrawable.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.content.Context;
44
import android.graphics.Canvas;
5-
import android.graphics.Color;
65
import android.graphics.Paint;
76
import android.graphics.Path;
87
import android.graphics.Rect;
@@ -21,8 +20,6 @@ class RingDrawable extends RefreshDrawable {
2120
private RectF mBounds;
2221
private int mWidth;
2322
private int mHeight;
24-
private int mTop;
25-
private int mOffsetTop;
2623
private Paint mPaint;
2724
private Path mPath;
2825
private float mAngle;
@@ -36,6 +33,7 @@ class RingDrawable extends RefreshDrawable {
3633
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
3734
mPaint.setStyle(Paint.Style.STROKE);
3835
mPaint.setStrokeWidth(dp2px(3));
36+
mPaint.setStrokeCap(Paint.Cap.ROUND);
3937
mPath = new Path();
4038
}
4139

@@ -52,8 +50,6 @@ public void setColorSchemeColors(int[] colorSchemeColors) {
5250

5351
@Override
5452
public void offsetTopAndBottom(int offset) {
55-
mTop += offset;
56-
mOffsetTop += offset;
5753
invalidateSelf();
5854
}
5955

library/src/main/res/values/attrs.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<declare-styleable name="PullRefreshLayout">
4-
<attr name="type" format="enum">
3+
<declare-styleable name="refresh_PullRefreshLayout">
4+
<attr name="refreshType" format="enum">
55
<enum name="material" value="0" />
66
<enum name="circles" value="1" />
77
<enum name="water_drop" value="2" />
88
<enum name="ring" value="3" />
9+
<enum name="smartisan" value="4" />
910
</attr>
10-
<attr name="colors" format="reference"/>
11+
<attr name="refreshColors" format="reference"/>
12+
<attr name="refreshColor" format="reference"/>
1113
</declare-styleable>
1214
</resources>

library/src/main/res/values/colors.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

library/src/main/res/values/strings.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

sample/src/main/java/com/baoyz/pullrefreshlayout/sample/ArcDrawable.java

Lines changed: 0 additions & 147 deletions
This file was deleted.

sample/src/main/java/com/baoyz/pullrefreshlayout/sample/ListViewActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
106106
case R.id.action_ring:
107107
layout.setRefreshStyle(PullRefreshLayout.STYLE_RING);
108108
return true;
109+
case R.id.action_smartisan:
110+
layout.setRefreshStyle(PullRefreshLayout.STYLE_SMARTISAN);
111+
return true;
109112
}
110113

111114
return super.onOptionsItemSelected(item);

sample/src/main/java/com/baoyz/pullrefreshlayout/sample/RecyclerViewActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
105105
case R.id.action_ring:
106106
layout.setRefreshStyle(PullRefreshLayout.STYLE_RING);
107107
return true;
108+
case R.id.action_smartisan:
109+
layout.setRefreshStyle(PullRefreshLayout.STYLE_SMARTISAN);
110+
return true;
108111
}
109112

110113
return super.onOptionsItemSelected(item);

sample/src/main/java/com/baoyz/pullrefreshlayout/sample/ScrollViewActivity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.baoyz.pullrefreshlayout.sample;
22

33
import android.app.Activity;
4-
import android.content.Intent;
4+
import android.graphics.Color;
55
import android.os.Bundle;
6-
import android.view.View;
76

87
import com.baoyz.widget.PullRefreshLayout;
8+
import com.baoyz.widget.SmartisanDrawable;
99

1010
public class ScrollViewActivity extends Activity {
1111

@@ -29,8 +29,8 @@ public void run() {
2929
}, 3000);
3030
}
3131
});
32-
33-
layout.setRefreshDrawable(new ArcDrawable(this, layout));
32+
layout.setColorSchemeColors(Color.GRAY);
33+
layout.setRefreshDrawable(new SmartisanDrawable(this, layout));
3434
}
3535

3636
}

0 commit comments

Comments
 (0)