package fr.iutfbleau.dev45.wamster.tp04ex02_grille;

import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;

public class DetecteGeste extends GestureDetector.SimpleOnGestureListener {
    private static final int LONG_PRESS_TIME = 500;
    private View actualView;
    private long tempsPression;

    public void setView(View v){
        this.actualView = v;
    }

    @Override
    public boolean onDown(MotionEvent e) {
        this.tempsPression = System.currentTimeMillis();
        return true;
    }
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        this.actualView.setBackgroundColor(Carre.TRANSPARENT);
        Log.v("test","Fling");
        return true;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        if (System.currentTimeMillis() - this.tempsPression < DetecteGeste.LONG_PRESS_TIME) {
            this.actualView.setBackgroundColor(Carre.BLEU);
            Log.v("test","Single Tap");
            return true;
        }
        return false;
    }

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        this.actualView.setBackgroundColor(Carre.VIOLET);
        Log.v("test","Double Tap");
        return true;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        this.actualView.setBackgroundColor(Carre.JAUNE);
        Log.v("test","Long Press");
    }
}
