Skip to content

Commit a2fba34

Browse files
author
Chris Banes
committed
Move some more attrs to be deprecated, replacing with start/end attrs
1 parent 9c6bc53 commit a2fba34

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

library/res/values/attrs.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<resources>
33

44
<declare-styleable name="PullToRefresh">
5-
<attr name="ptrAdapterViewBackground" format="reference|color" />
5+
<attr name="ptrRefreshableViewBackground" format="reference|color" />
66
<attr name="ptrHeaderBackground" format="reference|color" />
77
<attr name="ptrHeaderTextColor" format="reference|color" />
88
<attr name="ptrHeaderSubTextColor" format="reference|color" />
@@ -12,21 +12,27 @@
1212
<flag name="pullFromEnd" value="0x2" />
1313
<flag name="both" value="0x3" />
1414
<flag name="manualOnly" value="0x4" />
15+
1516
<!-- These last two are depreacted -->
1617
<flag name="pullDownFromTop" value="0x1" />
1718
<flag name="pullUpFromBottom" value="0x2" />
1819
</attr>
1920
<attr name="ptrShowIndicator" format="reference|boolean" />
2021
<attr name="ptrDrawable" format="reference" />
21-
<attr name="ptrDrawableTop" format="reference" />
22-
<attr name="ptrDrawableBottom" format="reference" />
22+
<attr name="ptrDrawableStart" format="reference" />
23+
<attr name="ptrDrawableEnd" format="reference" />
2324
<attr name="ptrOverScroll" format="reference|boolean" />
2425
<attr name="ptrHeaderTextAppearance" format="reference" />
2526
<attr name="ptrSubHeaderTextAppearance" format="reference" />
2627
<attr name="ptrAnimationStyle">
2728
<flag name="rotate" value="0x0" />
2829
<flag name="flip" value="0x1" />
2930
</attr>
31+
32+
<!-- Deprecated -->
33+
<attr name="ptrAdapterViewBackground" format="reference|color" />
34+
<attr name="ptrDrawableTop" format="reference" />
35+
<attr name="ptrDrawableBottom" format="reference" />
3036
</declare-styleable>
3137

3238
</resources>

library/src/com/handmark/pulltorefresh/library/PullToRefreshBase.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.handmark.pulltorefresh.library.internal.LoadingLayout;
3939
import com.handmark.pulltorefresh.library.internal.RotateLoadingLayout;
4040
import com.handmark.pulltorefresh.library.internal.SDK16;
41+
import com.handmark.pulltorefresh.library.internal.Utils;
4142

4243
public abstract class PullToRefreshBase<T extends View> extends LinearLayout implements IPullToRefresh<T> {
4344

@@ -935,12 +936,20 @@ private void init(Context context, AttributeSet attrs) {
935936
setBackgroundDrawable(background);
936937
}
937938
}
938-
if (a.hasValue(R.styleable.PullToRefresh_ptrAdapterViewBackground)) {
939+
940+
if (a.hasValue(R.styleable.PullToRefresh_ptrRefreshableViewBackground)) {
941+
Drawable background = a.getDrawable(R.styleable.PullToRefresh_ptrRefreshableViewBackground);
942+
if (null != background) {
943+
mRefreshableView.setBackgroundDrawable(background);
944+
}
945+
} else if (a.hasValue(R.styleable.PullToRefresh_ptrAdapterViewBackground)) {
946+
Utils.warnDeprecation("ptrAdapterViewBackground", "ptrRefreshableViewBackground");
939947
Drawable background = a.getDrawable(R.styleable.PullToRefresh_ptrAdapterViewBackground);
940948
if (null != background) {
941949
mRefreshableView.setBackgroundDrawable(background);
942950
}
943951
}
952+
944953
if (a.hasValue(R.styleable.PullToRefresh_ptrOverScroll)) {
945954
mOverScrollEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrOverScroll, true);
946955
}

library/src/com/handmark/pulltorefresh/library/internal/LoadingLayout.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.graphics.drawable.AnimationDrawable;
2424
import android.graphics.drawable.Drawable;
2525
import android.text.TextUtils;
26+
import android.util.Log;
2627
import android.util.TypedValue;
2728
import android.view.Gravity;
2829
import android.view.LayoutInflater;
@@ -41,6 +42,8 @@
4142

4243
@SuppressLint("ViewConstructor")
4344
public abstract class LoadingLayout extends LinearLayout {
45+
46+
static final String LOG_TAG = "PullToRefresh-LoadingLayout";
4447

4548
static final Interpolator ANIMATION_INTERPOLATOR = new LinearInterpolator();
4649

@@ -138,10 +141,24 @@ public LoadingLayout(Context context, final Mode mode, final int scrollDirection
138141

139142
// Check Specific Drawable from Attrs, these overrite the generic
140143
// drawable attr above
141-
if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableTop) && mode == Mode.PULL_FROM_START) {
142-
imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableTop);
143-
} else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableBottom) && mode == Mode.PULL_FROM_END) {
144-
imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableTop);
144+
switch (mode) {
145+
case PULL_FROM_START:
146+
if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableStart)) {
147+
imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableStart);
148+
} else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableTop)) {
149+
Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart");
150+
imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableTop);
151+
}
152+
break;
153+
154+
case PULL_FROM_END:
155+
if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableEnd)) {
156+
imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableEnd);
157+
} else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableBottom)) {
158+
Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd");
159+
imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableBottom);
160+
}
161+
break;
145162
}
146163

147164
// If we don't have a user defined drawable, load the default
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.handmark.pulltorefresh.library.internal;
2+
3+
import android.util.Log;
4+
5+
public class Utils {
6+
7+
static final String LOG_TAG = "PullToRefresh";
8+
9+
public static void warnDeprecation(String depreacted, String replacement) {
10+
Log.w(LOG_TAG, "You're using the deprecated " + depreacted + " attr, please switch over to " + replacement);
11+
}
12+
13+
}

0 commit comments

Comments
 (0)