package com.jiuqi.njt.widget; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.webkit.WebView; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.ViewFlipper; import com.jiuqi.njt.R; /** * 等待界面的WebView * * @author malingya * */ public class WaitPageWebView extends WebView { private RelativeLayout waitlayout; float downXValue; long downTime; private ViewFlipper flipper; private float lastTouchX, lastTouchY; private boolean hasMoved = false; public WaitPageWebView(Context context) { super(context); } // public WaitPageWebView(Context context, ViewFlipper flipper) { // super(context); // LayoutInflater layoutInflater = (LayoutInflater) context // .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // View layout = layoutInflater.inflate(R.layout.waitpage, null); // waitlayout = (LinearLayout) layout.findViewById(R.id.waitlayout); // ProgressBar pBar = (ProgressBar) layout.findViewById(R.id.progressBar); // LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, // LayoutParams.FILL_PARENT, 0, 0); // addView(layout, layoutParams); // setWebChromeClient(new WebChromeClient()); // this.flipper = flipper; // } public WaitPageWebView(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater layoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.waitpage, null); waitlayout = (RelativeLayout) layout.findViewById(R.id.waitlayout); ProgressBar pBar = (ProgressBar) layout.findViewById(R.id.progressBar); LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 0, 0); addView(layout, layoutParams); setWebChromeClient(new WebChromeClient()); // gd = new GestureDetector(context, sogl); } public class WebChromeClient extends android.webkit.WebChromeClient { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { waitlayout.setVisibility(GONE); } else { if (waitlayout.getVisibility() == GONE) waitlayout.setVisibility(VISIBLE); } super.onProgressChanged(view, newProgress); } } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { LayoutParams lp = (LayoutParams) waitlayout.getLayoutParams(); lp.x = l; lp.y = t; waitlayout.setLayoutParams(lp); super.onScrollChanged(l, t, oldl, oldt); } // @Override // public boolean onTouchEvent(MotionEvent evt) { // boolean consumed = super.onTouchEvent(evt); // if (isClickable()) { // switch (evt.getAction()) { // // case MotionEvent.ACTION_DOWN: // lastTouchX = evt.getX(); // lastTouchY = evt.getY(); // downXValue = evt.getX(); // downTime = evt.getEventTime(); // hasMoved = false; // break; // // case MotionEvent.ACTION_MOVE: // hasMoved = moved(evt); // break; // // case MotionEvent.ACTION_UP: // float currentX = evt.getX(); // long currentTime = evt.getEventTime(); // float difference = Math.abs(downXValue - currentX); // long time = currentTime - downTime; // Log.i("Touch Event========", "Distance: " + difference // + "px Time: " + time + "ms"); // // if ((downXValue < currentX) // && (difference > 100 && (time < 220))) { // /** 跳到上一页 */ // this.flipper.setInAnimation(AnimationUtils.loadAnimation( // this.getContext(), R.anim.right_in)); // this.flipper.setOutAnimation(AnimationUtils.loadAnimation( // this.getContext(), R.anim.right_out)); //// this.loadUrl("http://www.douban.com"); // flipper.showPrevious(); // } // // /** X轴滑动间隔大于100,并且时候小于220ms,并且向X轴左标的目标滑动 */ // if ((downXValue > currentX) && (difference > 100) // && (time < 220)) { // /** 跳到下一页 */ // this.flipper.setInAnimation(AnimationUtils.loadAnimation( // this.getContext(), R.anim.left_in)); // this.flipper.setOutAnimation(AnimationUtils.loadAnimation( // this.getContext(), R.anim.left_out)); //// this.loadUrl("http://www.zhihu.com"); // flipper.showNext(); // } // break; // } // // } // // return consumed || isClickable(); // } // // private boolean moved(MotionEvent evt) { // // return hasMoved || Math.abs(evt.getX() - lastTouchX) > 10.0 // || Math.abs(evt.getY() - lastTouchY) > 10.0; // } }