Skip to content

Commit dbaadb2

Browse files
author
Chris Banes
committed
Move FrameLayout layout callback to separate file
1 parent 2aad9d5 commit dbaadb2

3 files changed

Lines changed: 53 additions & 25 deletions

File tree

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
import android.widget.FrameLayout;
3535
import android.widget.LinearLayout;
3636

37+
import com.handmark.pulltorefresh.library.internal.CallbackFrameLayout.OnSizeChangedListener;
3738
import com.handmark.pulltorefresh.library.internal.FlipLoadingLayout;
3839
import com.handmark.pulltorefresh.library.internal.LoadingLayout;
39-
import com.handmark.pulltorefresh.library.internal.LoadingLayout.OnSizeChangedListener;
4040
import com.handmark.pulltorefresh.library.internal.RotateLoadingLayout;
4141
import com.handmark.pulltorefresh.library.internal.Utils;
4242
import com.handmark.pulltorefresh.library.internal.ViewCompat;
@@ -910,20 +910,28 @@ protected final void refreshLoadingViewsSize() {
910910
}
911911

912912
protected final void refreshRefreshableViewSize(int width, int height) {
913+
if (DEBUG) {
914+
Log.d(LOG_TAG, String.format("refreshRefreshableViewSize. W: %d, H: %d", width, height));
915+
}
916+
913917
// We need to set the Height of the Refreshable View to the same as
914918
// this layout
915919
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mRefreshableViewWrapper.getLayoutParams();
916920

917921
switch (getPullToRefreshScrollDirection()) {
918922
case HORIZONTAL:
919-
lp.width = width;
923+
if (lp.weight != width) {
924+
lp.width = width;
925+
mRefreshableViewWrapper.requestLayout();
926+
}
920927
break;
921928
case VERTICAL:
922-
default:
923-
lp.height = height;
929+
if (lp.height != height) {
930+
lp.height = height;
931+
mRefreshableViewWrapper.requestLayout();
932+
}
924933
break;
925934
}
926-
mRefreshableViewWrapper.requestLayout();
927935
}
928936

929937
/**
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.handmark.pulltorefresh.library.internal;
2+
3+
import android.content.Context;
4+
import android.util.AttributeSet;
5+
import android.view.View;
6+
import android.widget.FrameLayout;
7+
8+
public class CallbackFrameLayout extends FrameLayout {
9+
10+
private OnSizeChangedListener mSizeChangedListener;
11+
12+
public CallbackFrameLayout(Context context) {
13+
super(context);
14+
}
15+
16+
public CallbackFrameLayout(Context context, AttributeSet attrs) {
17+
super(context, attrs);
18+
}
19+
20+
@Override
21+
public final void onSizeChanged(int w, int h, int oldw, int oldh) {
22+
super.onSizeChanged(w, h, oldw, oldh);
23+
24+
if (null != mSizeChangedListener) {
25+
mSizeChangedListener.onSizeChanged(this, w, h);
26+
}
27+
}
28+
29+
public void setOnSizeChangedListener(OnSizeChangedListener listener) {
30+
mSizeChangedListener = listener;
31+
}
32+
33+
public static interface OnSizeChangedListener {
34+
void onSizeChanged(View view, int newWidth, int newHeight);
35+
}
36+
37+
}

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import com.handmark.pulltorefresh.library.R;
4242

4343
@SuppressLint("ViewConstructor")
44-
public abstract class LoadingLayout extends FrameLayout implements ILoadingLayout {
44+
public abstract class LoadingLayout extends CallbackFrameLayout implements ILoadingLayout {
4545

4646
static final String LOG_TAG = "PullToRefresh-LoadingLayout";
4747

@@ -64,8 +64,6 @@ public abstract class LoadingLayout extends FrameLayout implements ILoadingLayou
6464
private CharSequence mRefreshingLabel;
6565
private CharSequence mReleaseLabel;
6666

67-
private OnSizeChangedListener mSizeChangedListener;
68-
6967
public LoadingLayout(Context context, final Mode mode, final Orientation scrollDirection, TypedArray attrs) {
7068
super(context);
7169
mMode = mode;
@@ -185,11 +183,13 @@ public LoadingLayout(Context context, final Mode mode, final Orientation scrollD
185183
public final void setHeight(int height) {
186184
ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) getLayoutParams();
187185
lp.height = height;
186+
requestLayout();
188187
}
189188

190189
public final void setWidth(int width) {
191190
ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) getLayoutParams();
192191
lp.width = width;
192+
requestLayout();
193193
}
194194

195195
public final int getContentHeight() {
@@ -221,15 +221,6 @@ public final void onPull(float scaleOfLayout) {
221221
}
222222
}
223223

224-
@Override
225-
public final void onSizeChanged(int w, int h, int oldw, int oldh) {
226-
super.onSizeChanged(w, h, oldw, oldh);
227-
228-
if (null != mSizeChangedListener) {
229-
mSizeChangedListener.onSizeChanged(this, w, h);
230-
}
231-
}
232-
233224
public final void pullToRefresh() {
234225
if (null != mHeaderText) {
235226
mHeaderText.setText(mPullLabel);
@@ -301,10 +292,6 @@ public final void setLoadingDrawable(Drawable imageDrawable) {
301292
onLoadingDrawableSet(imageDrawable);
302293
}
303294

304-
public void setOnSizeChangedListener(OnSizeChangedListener sizeChangedListener) {
305-
mSizeChangedListener = sizeChangedListener;
306-
}
307-
308295
public void setPullLabel(CharSequence pullLabel) {
309296
mPullLabel = pullLabel;
310297
}
@@ -396,8 +383,4 @@ private void setTextColor(ColorStateList color) {
396383
}
397384
}
398385

399-
public static interface OnSizeChangedListener {
400-
void onSizeChanged(View view, int newWidth, int newHeight);
401-
}
402-
403386
}

0 commit comments

Comments
 (0)