Created
February 6, 2015 13:02
-
-
Save alorma/7a9fe52082bbce7b2be6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ObservableWebView extends WebView { | |
public ObservableWebView(Context context) { | |
this(context, null); | |
} | |
public ObservableWebView(Context context, AttributeSet attrs) { | |
this(context, attrs, 0); | |
} | |
public ObservableWebView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
isInEditMode(); | |
} | |
public OnBottomReachedListener mOnBottomReachedListener = null; | |
private int mMinDistance = 0; | |
/** | |
* Set the listener which will be called when the WebView is scrolled to within some | |
* margin of the bottom. | |
* | |
* @param bottomReachedListener | |
* @param allowedDifference | |
*/ | |
public void setOnBottomReachedListener(OnBottomReachedListener bottomReachedListener, int allowedDifference) { | |
mOnBottomReachedListener = bottomReachedListener; | |
mMinDistance = allowedDifference; | |
} | |
/** | |
* Implement this interface if you want to be notified when the WebView has scrolled to the bottom. | |
*/ | |
public interface OnBottomReachedListener { | |
void onBottomReached(View v); | |
} | |
@Override | |
protected void onScrollChanged(int left, int top, int oldLeft, int oldTop) { | |
if (mOnBottomReachedListener != null) { | |
if ((getContentHeight() - (top + getHeight())) <= (getContentHeight() / 2)) { | |
mOnBottomReachedListener.onBottomReached(this); | |
} | |
} | |
super.onScrollChanged(left, top, oldLeft, oldTop); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment