package fr.iutfbleau.dev45.wamster.tp04ex03_dimension;

import static android.view.MotionEvent.ACTION_DOWN;

import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;

public class Evenement implements View.OnTouchListener{

    private ScaleGestureDetector scaleGestureDetector;
    private GestureDetector gestureDetector;
    private DetecteZoom zoomListener;
    private DetecteClic clicListener;

    public Evenement(View v){
        this.zoomListener = new DetecteZoom();
        this.clicListener = new DetecteClic();
        this.scaleGestureDetector = new ScaleGestureDetector(v.getContext(), this.zoomListener);
        this.gestureDetector = new GestureDetector(v.getContext(), this.clicListener);
    }
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int action = event.getActionMasked();
        if (action == MotionEvent.ACTION_DOWN){
            this.zoomListener.resetMouvement();
        }
        if (v instanceof Rectangle){
            Rectangle rectangle = (Rectangle) v;
            this.zoomListener.setViewActuel(rectangle);
            this.clicListener.setViewActuel(rectangle);
        }
        this.gestureDetector.onTouchEvent(event);
        this.scaleGestureDetector.onTouchEvent(event);
        return true;
    }
}
