Skip to content

Commit c4eea62

Browse files
author
Chris Banes
committed
Tidy up and rename some enum values based on logical names (START/END) rather than TOP/BOTTOM.
1 parent 1b5a26e commit c4eea62

9 files changed

Lines changed: 88 additions & 73 deletions

File tree

library/res/values/attrs.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
<attr name="ptrHeaderSubTextColor" format="reference|color" />
99
<attr name="ptrMode">
1010
<flag name="disabled" value="0x0" />
11-
<flag name="pullDownFromTop" value="0x1" />
12-
<flag name="pullUpFromBottom" value="0x2" />
11+
<flag name="pullFromStart" value="0x1" />
12+
<flag name="pullFromEnd" value="0x2" />
1313
<flag name="both" value="0x3" />
1414
<flag name="manualOnly" value="0x4" />
15+
<!-- These last two are depreacted -->
16+
<flag name="pullDownFromTop" value="0x1" />
17+
<flag name="pullUpFromBottom" value="0x2" />
1518
</attr>
1619
<attr name="ptrShowIndicator" format="reference|boolean" />
1720
<attr name="ptrDrawable" format="reference" />
@@ -26,4 +29,4 @@
2629
</attr>
2730
</declare-styleable>
2831

29-
</resources>
32+
</resources>

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ void onPullToRefresh() {
232232

233233
if (getShowIndicatorInternal()) {
234234
switch (getCurrentMode()) {
235-
case PULL_UP_TO_REFRESH:
235+
case PULL_FROM_END:
236236
mIndicatorIvBottom.pullToRefresh();
237237
break;
238-
case PULL_DOWN_TO_REFRESH:
238+
case PULL_FROM_START:
239239
mIndicatorIvTop.pullToRefresh();
240240
break;
241241
}
@@ -256,10 +256,10 @@ void onReleaseToRefresh() {
256256

257257
if (getShowIndicatorInternal()) {
258258
switch (getCurrentMode()) {
259-
case PULL_UP_TO_REFRESH:
259+
case PULL_FROM_END:
260260
mIndicatorIvBottom.releaseToRefresh();
261261
break;
262-
case PULL_DOWN_TO_REFRESH:
262+
case PULL_FROM_START:
263263
mIndicatorIvTop.releaseToRefresh();
264264
break;
265265
}
@@ -315,7 +315,7 @@ private void addIndicatorViews() {
315315

316316
if (mode.showHeaderLoadingLayout() && null == mIndicatorIvTop) {
317317
// If the mode can pull down, and we don't have one set already
318-
mIndicatorIvTop = new IndicatorLayout(getContext(), Mode.PULL_DOWN_TO_REFRESH);
318+
mIndicatorIvTop = new IndicatorLayout(getContext(), Mode.PULL_FROM_START);
319319
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
320320
ViewGroup.LayoutParams.WRAP_CONTENT);
321321
params.rightMargin = getResources().getDimensionPixelSize(R.dimen.indicator_right_padding);
@@ -330,7 +330,7 @@ private void addIndicatorViews() {
330330

331331
if (mode.showFooterLoadingLayout() && null == mIndicatorIvBottom) {
332332
// If the mode can pull down, and we don't have one set already
333-
mIndicatorIvBottom = new IndicatorLayout(getContext(), Mode.PULL_UP_TO_REFRESH);
333+
mIndicatorIvBottom = new IndicatorLayout(getContext(), Mode.PULL_FROM_END);
334334
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
335335
ViewGroup.LayoutParams.WRAP_CONTENT);
336336
params.rightMargin = getResources().getDimensionPixelSize(R.dimen.indicator_right_padding);

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

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ public final State getState() {
181181

182182
/**
183183
* @deprecated Use the value from <code>getCurrentMode()</code> instead
184-
* @return true if the current mode is Mode.PULL_DOWN_TO_REFRESH
184+
* @return true if the current mode is Mode.PULL_FROM_START
185185
*/
186186
public final boolean hasPullFromTop() {
187-
return mCurrentMode == Mode.PULL_DOWN_TO_REFRESH;
187+
return mCurrentMode == Mode.PULL_FROM_START;
188188
}
189189

190190
@Override
@@ -258,14 +258,14 @@ public final boolean onInterceptTouchEvent(MotionEvent event) {
258258
mLastMotionX = x;
259259
mIsBeingDragged = true;
260260
if (mMode == Mode.BOTH) {
261-
mCurrentMode = Mode.PULL_DOWN_TO_REFRESH;
261+
mCurrentMode = Mode.PULL_FROM_START;
262262
}
263263
} else if (mMode.showFooterLoadingLayout() && diff <= -1f && isReadyForPullEnd()) {
264264
mLastMotionY = y;
265265
mLastMotionX = x;
266266
mIsBeingDragged = true;
267267
if (mMode == Mode.BOTH) {
268-
mCurrentMode = Mode.PULL_UP_TO_REFRESH;
268+
mCurrentMode = Mode.PULL_FROM_END;
269269
}
270270
}
271271
}
@@ -342,9 +342,9 @@ public final boolean onTouchEvent(MotionEvent event) {
342342

343343
} else if (null != mOnRefreshListener2) {
344344
setState(State.REFRESHING, true);
345-
if (mCurrentMode == Mode.PULL_DOWN_TO_REFRESH) {
345+
if (mCurrentMode == Mode.PULL_FROM_START) {
346346
mOnRefreshListener2.onPullDownToRefresh(this);
347-
} else if (mCurrentMode == Mode.PULL_UP_TO_REFRESH) {
347+
} else if (mCurrentMode == Mode.PULL_FROM_END) {
348348
mOnRefreshListener2.onPullUpToRefresh(this);
349349
}
350350
return true;
@@ -525,10 +525,10 @@ public final void setShowViewWhileRefreshing(boolean showView) {
525525
*/
526526
void onPullToRefresh() {
527527
switch (mCurrentMode) {
528-
case PULL_UP_TO_REFRESH:
528+
case PULL_FROM_END:
529529
mFooterLayout.pullToRefresh();
530530
break;
531-
case PULL_DOWN_TO_REFRESH:
531+
case PULL_FROM_START:
532532
mHeaderLayout.pullToRefresh();
533533
break;
534534
}
@@ -553,11 +553,11 @@ void onRefreshing(final boolean doScroll) {
553553
if (mShowViewWhileRefreshing) {
554554
switch (mCurrentMode) {
555555
case MANUAL_REFRESH_ONLY:
556-
case PULL_UP_TO_REFRESH:
556+
case PULL_FROM_END:
557557
smoothScrollTo(mFooterDimension);
558558
break;
559559
default:
560-
case PULL_DOWN_TO_REFRESH:
560+
case PULL_FROM_START:
561561
smoothScrollTo(-mHeaderDimension);
562562
break;
563563
}
@@ -576,10 +576,10 @@ void onRefreshing(final boolean doScroll) {
576576
*/
577577
void onReleaseToRefresh() {
578578
switch (mCurrentMode) {
579-
case PULL_UP_TO_REFRESH:
579+
case PULL_FROM_END:
580580
mFooterLayout.releaseToRefresh();
581581
break;
582-
case PULL_DOWN_TO_REFRESH:
582+
case PULL_FROM_START:
583583
mHeaderLayout.releaseToRefresh();
584584
break;
585585
}
@@ -874,7 +874,7 @@ protected void updateUIForMode() {
874874

875875
// If we're not using Mode.BOTH, set mCurrentMode to mMode, otherwise
876876
// set it to pull down
877-
mCurrentMode = (mMode != Mode.BOTH) ? mMode : Mode.PULL_DOWN_TO_REFRESH;
877+
mCurrentMode = (mMode != Mode.BOTH) ? mMode : Mode.PULL_FROM_START;
878878
}
879879

880880
private void addRefreshableView(Context context, T refreshableView) {
@@ -928,8 +928,8 @@ private void init(Context context, AttributeSet attrs) {
928928
addRefreshableView(context, mRefreshableView);
929929

930930
// We need to create now layouts now
931-
mHeaderLayout = createLoadingLayout(context, Mode.PULL_DOWN_TO_REFRESH, a);
932-
mFooterLayout = createLoadingLayout(context, Mode.PULL_UP_TO_REFRESH, a);
931+
mHeaderLayout = createLoadingLayout(context, Mode.PULL_FROM_START, a);
932+
mFooterLayout = createLoadingLayout(context, Mode.PULL_FROM_END, a);
933933

934934
// Styleables from XML
935935
if (a.hasValue(R.styleable.PullToRefresh_ptrHeaderBackground)) {
@@ -959,9 +959,9 @@ private void init(Context context, AttributeSet attrs) {
959959

960960
private boolean isReadyForPull() {
961961
switch (mMode) {
962-
case PULL_DOWN_TO_REFRESH:
962+
case PULL_FROM_START:
963963
return isReadyForPullStart();
964-
case PULL_UP_TO_REFRESH:
964+
case PULL_FROM_END:
965965
return isReadyForPullEnd();
966966
case BOTH:
967967
return isReadyForPullEnd() || isReadyForPullStart();
@@ -1010,11 +1010,11 @@ private void pullEvent() {
10101010
}
10111011

10121012
switch (mCurrentMode) {
1013-
case PULL_UP_TO_REFRESH:
1013+
case PULL_FROM_END:
10141014
newScrollValue = Math.round(Math.max(initialMotionValue - lastMotionValue, 0) / FRICTION);
10151015
itemDimension = mFooterDimension;
10161016
break;
1017-
case PULL_DOWN_TO_REFRESH:
1017+
case PULL_FROM_START:
10181018
default:
10191019
newScrollValue = Math.round(Math.min(initialMotionValue - lastMotionValue, 0) / FRICTION);
10201020
itemDimension = mHeaderDimension;
@@ -1026,10 +1026,10 @@ private void pullEvent() {
10261026
if (newScrollValue != 0) {
10271027
float scale = Math.abs(newScrollValue) / (float) itemDimension;
10281028
switch (mCurrentMode) {
1029-
case PULL_UP_TO_REFRESH:
1029+
case PULL_FROM_END:
10301030
mFooterLayout.onPullY(scale);
10311031
break;
1032-
case PULL_DOWN_TO_REFRESH:
1032+
case PULL_FROM_START:
10331033
mHeaderLayout.onPullY(scale);
10341034
break;
10351035
}
@@ -1188,8 +1188,7 @@ public static enum AnimationStyle {
11881188
*
11891189
* @param modeInt
11901190
* - int to map a Mode to
1191-
* @return Mode that modeInt maps to, or PULL_DOWN_TO_REFRESH by
1192-
* default.
1191+
* @return Mode that modeInt maps to, or ROTATE by default.
11931192
*/
11941193
static AnimationStyle mapIntToValue(int modeInt) {
11951194
switch (modeInt) {
@@ -1213,25 +1212,28 @@ LoadingLayout createLoadingLayout(Context context, Mode mode, int scrollDirectio
12131212
}
12141213

12151214
public static enum Mode {
1215+
12161216
/**
12171217
* Disable all Pull-to-Refresh gesture and Refreshing handling
12181218
*/
12191219
DISABLED(0x0),
12201220

12211221
/**
1222-
* Only allow the user to Pull Down from the top to refresh, this is the
1223-
* default.
1222+
* Only allow the user to Pull from the start of the Refreshable View to
1223+
* refresh. The start is either the Top or Left, depending on the
1224+
* scrolling direction.
12241225
*/
1225-
PULL_DOWN_TO_REFRESH(0x1),
1226+
PULL_FROM_START(0x1),
12261227

12271228
/**
1228-
* Only allow the user to Pull Up from the bottom to refresh.
1229+
* Only allow the user to Pull from the end of the Refreshable View to
1230+
* refresh. The start is either the Bottom or Right, depending on the
1231+
* scrolling direction.
12291232
*/
1230-
PULL_UP_TO_REFRESH(0x2),
1233+
PULL_FROM_END(0x2),
12311234

12321235
/**
1233-
* Allow the user to both Pull Down from the top, and Pull Up from the
1234-
* bottom to refresh.
1236+
* Allow the user to both Pull from the start, from the end to refresh.
12351237
*/
12361238
BOTH(0x3),
12371239

@@ -1242,15 +1244,24 @@ public static enum Mode {
12421244
*/
12431245
MANUAL_REFRESH_ONLY(0x4);
12441246

1247+
/**
1248+
* @deprecated Use {@link #PULL_FROM_START} from now on.
1249+
*/
1250+
public static Mode PULL_DOWN_TO_REFRESH = Mode.PULL_FROM_START;
1251+
1252+
/**
1253+
* @deprecated Use {@link #PULL_FROM_END} from now on.
1254+
*/
1255+
public static Mode PULL_UP_TO_REFRESH = Mode.PULL_FROM_END;
1256+
12451257
/**
12461258
* Maps an int to a specific mode. This is needed when saving state, or
12471259
* inflating the view from XML where the mode is given through a attr
12481260
* int.
12491261
*
12501262
* @param modeInt
12511263
* - int to map a Mode to
1252-
* @return Mode that modeInt maps to, or PULL_DOWN_TO_REFRESH by
1253-
* default.
1264+
* @return Mode that modeInt maps to, or PULL_FROM_START by default.
12541265
*/
12551266
static Mode mapIntToValue(final int modeInt) {
12561267
for (Mode value : Mode.values()) {
@@ -1264,7 +1275,7 @@ static Mode mapIntToValue(final int modeInt) {
12641275
}
12651276

12661277
static Mode getDefaultMode() {
1267-
return Mode.PULL_DOWN_TO_REFRESH;
1278+
return Mode.PULL_FROM_START;
12681279
}
12691280

12701281
private int mIntValue;
@@ -1285,14 +1296,14 @@ boolean permitsPullToRefresh() {
12851296
* @return true if this mode wants the Loading Layout Header to be shown
12861297
*/
12871298
boolean showHeaderLoadingLayout() {
1288-
return this == PULL_DOWN_TO_REFRESH || this == BOTH;
1299+
return this == PULL_FROM_START || this == BOTH;
12891300
}
12901301

12911302
/**
12921303
* @return true if this mode wants the Loading Layout Footer to be shown
12931304
*/
12941305
boolean showFooterLoadingLayout() {
1295-
return this == PULL_UP_TO_REFRESH || this == BOTH || this == MANUAL_REFRESH_ONLY;
1306+
return this == PULL_FROM_END || this == BOTH || this == MANUAL_REFRESH_ONLY;
12961307
}
12971308

12981309
int getIntValue() {
@@ -1342,10 +1353,10 @@ public static interface OnPullEventListener<V extends View> {
13421353
* @param state
13431354
* - The new state of View.
13441355
* @param direction
1345-
* - One of {@link Mode#PULL_UP_TO_REFRESH} or
1346-
* {@link Mode#PULL_UP_TO_REFRESH} depending on which
1347-
* direction the user is pulling. Only useful when
1348-
* <var>state</var> is {@link State#PULL_TO_REFRESH} or
1356+
* - One of {@link Mode#PULL_FROM_START} or
1357+
* {@link Mode#PULL_FROM_END} depending on which direction
1358+
* the user is pulling. Only useful when <var>state</var> is
1359+
* {@link State#PULL_TO_REFRESH} or
13491360
* {@link State#RELEASE_TO_REFRESH}.
13501361
*/
13511362
public void onPullEvent(final PullToRefreshBase<V> refreshView, State state, Mode direction);
@@ -1360,8 +1371,8 @@ public static interface OnPullEventListener<V extends View> {
13601371
public static interface OnRefreshListener<V extends View> {
13611372

13621373
/**
1363-
* onRefresh will be called for both Pull Down from top, and Pull Up
1364-
* from Bottom
1374+
* onRefresh will be called for both a Pull from start, and Pull from
1375+
* end
13651376
*/
13661377
public void onRefresh(final PullToRefreshBase<V> refreshView);
13671378

@@ -1375,16 +1386,17 @@ public static interface OnRefreshListener<V extends View> {
13751386
* @author Chris Banes
13761387
*/
13771388
public static interface OnRefreshListener2<V extends View> {
1389+
// TODO These methods need renaming to START/END rather than DOWN/UP
13781390

13791391
/**
1380-
* onPullDownToRefresh will be called only when the user has Pulled Down
1381-
* from the top, and released.
1392+
* onPullDownToRefresh will be called only when the user has Pulled from
1393+
* the start, and released.
13821394
*/
13831395
public void onPullDownToRefresh(final PullToRefreshBase<V> refreshView);
13841396

13851397
/**
1386-
* onPullUpToRefresh will be called only when the user has Pulled Up
1387-
* from the bottom, and released.
1398+
* onPullUpToRefresh will be called only when the user has Pulled from
1399+
* the end, and released.
13881400
*/
13891401
public void onPullUpToRefresh(final PullToRefreshBase<V> refreshView);
13901402

0 commit comments

Comments
 (0)