package com.hilton.gitatouille;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.webkit.WebView;

public class CustomizedWebView extends WebView {
    private static final float EPISODE = 5.0f;
    private OnScrollListener mOnScrollListener;
    
    public CustomizedWebView(Context context) {
        super(context);
    }

    public CustomizedWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomizedWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    
    public void setScrollListener(OnScrollListener l) {
        mOnScrollListener = l;
    }
    
    private float mStartY = Float.NaN;
    private float mStartX = Float.NaN;
    private boolean mScrollingDown = false;
    private boolean mScrollingUp = false;
    
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        final float currentX = event.getX();
        final float currentY = event.getY();
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            mStartX = event.getX();
            mStartY = event.getY();
            break;
        case MotionEvent.ACTION_MOVE:
            if (Math.abs(currentX - mStartX) > EPISODE) {
                break;
            }
            if ((currentY - mStartY) > EPISODE) {
                if (!mScrollingDown) {
                    mScrollingDown = true;
                    mScrollingUp = false;
                    mOnScrollListener.scrollUp();
                }
            } else if ((mStartY - currentY) > EPISODE) {
                if (!mScrollingUp) {
                    mScrollingUp = true;
                    mScrollingDown = false;
                    mOnScrollListener.scrollDown();
                }
            }
            break;
        case MotionEvent.ACTION_UP:
            mScrollingDown = false;
            mScrollingUp = false;
            mStartY = Float.NaN;
            mStartX = Float.NaN;
            break;
        }
        return super.onTouchEvent(event);
    }
    
    public interface OnScrollListener {
        public void scrollDown();
        public void scrollUp();
    }
}
@@ -374,24 +374,46 @@
 r(context);%0A
+        initialize();%0A
     %7D%0A%0A    p
@@ -506,16 +506,38 @@
 attrs);%0A
+        initialize();%0A
     %7D%0A%0A 
@@ -658,16 +658,38 @@
 Style);%0A
+        initialize();%0A
     %7D%0A  
@@ -810,36 +810,24 @@
 loat mStartY
- = Float.NaN
 ;%0A    privat
@@ -837,36 +837,24 @@
 loat mStartX
- = Float.NaN
 ;%0A    privat
@@ -873,32 +873,24 @@
 crollingDown
- = false
 ;%0A    privat
@@ -907,32 +907,24 @@
 mScrollingUp
- = false
 ;%0A    %0A    @
@@ -1278,16 +1278,18 @@
 ON_MOVE:
+ %7B
 %0A       
@@ -1892,32 +1892,42 @@
          break;%0A
+        %7D%0A
         case Mot
@@ -1946,24 +1946,156 @@
 ION_UP:%0A    
+        initialize();%0A            break;%0A        %7D%0A        return super.onTouchEvent(event);%0A    %7D%0A%0A    private void initialize() %7B%0A
         mScr
@@ -2114,36 +2114,32 @@
  false;%0A        
-   
- 
 mScrollingUp = f
@@ -2144,36 +2144,32 @@
  false;%0A        
-    
 mStartY = Float.
@@ -2173,36 +2173,32 @@
 at.NaN;%0A        
-  
-  
 mStartX = Float.
@@ -2206,79 +2206,8 @@
 aN;%0A
-            break;%0A        %7D%0A        return super.onTouchEvent(event);%0A
     

Refactor the code.