package com.wpc.library.widget;
|
|
import android.content.Context;
|
import android.graphics.Canvas;
|
import android.os.Handler;
|
import android.os.Message;
|
import android.util.AttributeSet;
|
import android.util.Log;
|
import android.webkit.WebView;
|
|
public class TrendHeightWebView extends WebView {
|
private int lastContentHeight = 0;
|
private static final int MSG_CONTENT_CHANGE = 1;
|
private onContentChangeListener onContentChangeListener = null;
|
private Handler handler = new Handler() {
|
@Override
|
public void handleMessage(Message msg) {
|
switch (msg.what) {
|
case MSG_CONTENT_CHANGE:
|
if (onContentChangeListener != null) {
|
onContentChangeListener.onContentChange();
|
}
|
break;
|
}
|
}
|
};
|
|
|
public TrendHeightWebView(Context context) {
|
this(context, null);
|
}
|
|
public TrendHeightWebView(Context context, AttributeSet attrs) {
|
super(context, attrs);
|
}
|
|
@Override
|
protected void onDraw(Canvas canvas) {
|
super.onDraw(canvas);
|
if (getContentHeight() != lastContentHeight) {
|
handler.sendEmptyMessage(MSG_CONTENT_CHANGE);
|
lastContentHeight = getContentHeight();
|
Log.i("mResult", "contentChange height=" + getContentHeight());
|
}
|
|
}
|
|
|
public void setOnContentChangeListener(onContentChangeListener onContentChangeListener) {
|
this.onContentChangeListener = onContentChangeListener;
|
}
|
|
/**
|
* 监听内容高度发生变化
|
*/
|
public interface onContentChangeListener {
|
void onContentChange();
|
}
|
}
|