package jp.gauzau.MikuMikuDroidmod;

import android.graphics.PointF;
import android.util.Log;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.OnScaleGestureListener;

public class CameraLocrotGestureListner extends SimpleOnGestureListener implements
        OnScaleGestureListener {

    private static final String TAG = "CameraLocrotGestureListner";
    
    private boolean mIsOnTranslate;
    private boolean mIsOnZoom;
    
    private float mZoomRate = 1;
    private float mPreviousZoomRate = 1;
    private final float[] mLocationRate = new float[] { 0, 0, 0 };
    private final float[] mPreviousLocationRate = new float[] { 0, 0, 0 };
    private final float[] mRotationRate = new float[] { 0, 0, 0 };
    private final float[] mPreviousRotationRate = new float[] { 0, 0, 0 };
    
    private final PointF mPreviousFocus = new PointF();
    private final PointF mFocusDiffRate = new PointF();
    
    private float mSmallerScreenWidth = 1;

    private final CoreLogic mCoreLogic;

    public CameraLocrotGestureListner(CoreLogic coreLogic) {
        mCoreLogic = coreLogic;
    }

    @Override
    public boolean onScale(ScaleGestureDetector detector) {
        if (!mIsOnTranslate && !mIsOnZoom) {
            float factor = detector.getScaleFactor();
            float changeRate = factor >= 1 ? factor : 1 / factor;
            if (changeRate > 1.3f) {
                Log.d(TAG, "Start zooming");
                mIsOnZoom = true;
            } else {
                mFocusDiffRate.set((detector.getFocusX() - mPreviousFocus.x)
                        / mSmallerScreenWidth, (detector.getFocusY() - mPreviousFocus.y)
                        / mSmallerScreenWidth);
                float movedDistanceRateSqr = mFocusDiffRate.x * mFocusDiffRate.x
                        + mFocusDiffRate.y * mFocusDiffRate.y;
                if (movedDistanceRateSqr > 0.1f) {
                    Log.d(TAG, "Start translating");
                    mIsOnTranslate = true;
                }
            }
        }
        if (mIsOnTranslate) {

        } else if(mIsOnZoom) {
            
        }
        return true;
    }

    @Override
    public boolean onScaleBegin(ScaleGestureDetector detector) {
        mPreviousFocus.set(detector.getFocusX(), detector.getFocusY());
        mSmallerScreenWidth = Math.min(mCoreLogic.getScreenWidth(), mCoreLogic
                .getScreenHeight());
        return true;
    }

    @Override
    public void onScaleEnd(ScaleGestureDetector detector) {
        mIsOnTranslate = mIsOnZoom = false;
    }

}

@@ -149,24 +149,58 @@
 eListener;%0D%0A
+import android.view.MotionEvent;%0D%0A
 import andro
@@ -487,20 +487,16 @@
 tner%22;%0D%0A
-    
 %0D%0A    pr
@@ -558,20 +558,16 @@
 nZoom;%0D%0A
-    
 %0D%0A    pr
@@ -924,20 +924,16 @@
 , 0 %7D;%0D%0A
-    
 %0D%0A    pr
@@ -1040,20 +1040,16 @@
 ntF();%0D%0A
-    
 %0D%0A    pr
@@ -1607,24 +1607,37 @@
            %7D
+%0D%0A           
  else %7B%0D%0A   
@@ -2218,24 +2218,337 @@
 anslate) %7B%0D%0A
+            // TODO: 3d%0D%0A            mLocationRate%5B0%5D = mPreviousLocationRate%5B0%5D%0D%0A                    + (detector.getFocusX() - mPreviousFocus.x) / mSmallerScreenWidth;%0D%0A            mLocationRate%5B1%5D = mPreviousLocationRate%5B1%5D%0D%0A                    + (detector.getFocusX() - mPreviousFocus.x) / mSmallerScreenWidth;
 %0D%0A        %7D 
@@ -2550,16 +2550,25 @@
    %7D
+%0D%0A       
  else if
 (mIs
@@ -2563,16 +2563,17 @@
  else if
+ 
 (mIsOnZo
@@ -2591,16 +2591,110 @@
         
+float factor = detector.getScaleFactor();%0D%0A            mZoomRate = mPreviousZoomRate * factor;
 %0D%0A      
@@ -3005,165 +3005,607 @@
 );%0D%0A
-        return true;%0D%0A    %7D%0D%0A%0D%0A    @Override%0D%0A    public void onScaleEnd(ScaleGestureDetector detector) %7B%0D%0A        mIsOnTranslate = mIsOnZoom = false;%0D%0A    %7D
+%0D%0A        mPreviousZoomRate = mZoomRate;%0D%0A        System.arraycopy(mLocationRate, 0, mPreviousLocationRate, 0, 3);%0D%0A        System.arraycopy(mRotationRate, 0, mPreviousRotationRate, 0, 3);%0D%0A        return true;%0D%0A    %7D%0D%0A%0D%0A    @Override%0D%0A    public void onScaleEnd(ScaleGestureDetector detector) %7B%0D%0A        mIsOnTranslate = mIsOnZoom = false;%0D%0A    %7D%0D%0A%0D%0A    @Override%0D%0A    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,%0D%0A            float distanceY) %7B%0D%0A        // TODO Auto-generated method stub%0D%0A        return super.onScroll(e1, e2, distanceX, distanceY);%0D%0A    %7D%0D%0A    %0D%0A    
 %0D%0A%0D%0A

Implement mock Location and Zoom