If you think the Android project hpush listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.hpush.views;
/*fromwww.java2s.com*/import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;
/**
* An extension of standard WebView that we can detect which direction user scrolled.
*
* @author Xinyue Zhao
*/publicfinalclass WebViewEx extends WebView {
/**
* A listener hooks the WebView when it scrolled.
*/private OnWebViewExScrolledListener mOnWebViewExScrolledListener;
public WebViewEx(Context context) {
super(context);
}
public WebViewEx(Context context, AttributeSet attrs) {
super(context, attrs);
}
public WebViewEx(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protectedvoid onScrollChanged(int l, int t, int oldl, int oldt) {
if (t > 0) {
if (mOnWebViewExScrolledListener != null) {
mOnWebViewExScrolledListener.onScrollChanged(t > oldt);
}
} else {
if (t == 0) {
if (mOnWebViewExScrolledListener != null) {
mOnWebViewExScrolledListener.onScrolledTop();
}
}
}
super.onScrollChanged(l, t, oldl, oldt);
}
/**
* Set listener hooks the WebView when it scrolled.
*
* @param onWebViewExScrolledListener
* The instance of listener.
*/publicvoid setOnWebViewExScrolledListener(OnWebViewExScrolledListener onWebViewExScrolledListener) {
mOnWebViewExScrolledListener = onWebViewExScrolledListener;
}
/**
* A listener hooks the WebView when it scrolled.
*
* @author Xinyue Zhao
*/publicinterface OnWebViewExScrolledListener {
/**
* Event fired when user scrolled the WebView.
*
* @param isUp
* True if user scrolled up, false then down.
*/void onScrollChanged(boolean isUp);
/**
* Event fired when user scrolled the WebView onto TOP.
*/void onScrolledTop();
}
}