package com.example.mysmartlab

import android.app.ActivityOptions
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.View
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.example.mysmartlab.databinding.ActivitySpam1Binding
import kotlin.math.*

class ActivitySpam1 : AppCompatActivity(), GestureDetector.OnGestureListener,
    View.OnTouchListener {

    private lateinit var gestureDetector: GestureDetector
    private lateinit var binding: ActivitySpam1Binding


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivitySpam1Binding.inflate(layoutInflater)
        setContentView(binding.root)
binding.btnSkip1.setOnClickListener{
    startActivity(Intent(this, ActivitySpam2::class.java))
}
        gestureDetector = GestureDetector(this, this)
    }
    override fun onTouchEvent(event: MotionEvent?): Boolean {
        return if (gestureDetector.onTouchEvent(event!!)) {
            true
        } else {
            return super.onTouchEvent(event)
        }
    }

    override fun onDown(e: MotionEvent): Boolean {
        return false
    }

    override fun onShowPress(e: MotionEvent) {
    }

    override fun onSingleTapUp(e: MotionEvent): Boolean {
        return false
    }

    override fun onScroll(
        e1: MotionEvent?,
        e2: MotionEvent,
        distanceX: Float,
        distanceY: Float
    ): Boolean {
        return false
    }


    override fun onLongPress(e: MotionEvent) {
        return
    }

    override fun onFling(
        e1: MotionEvent?,
        e2: MotionEvent,
        velocityX: Float,
        velocityY: Float
    ): Boolean {
        val diffY = e2?.y?.minus(e1?.y ?: 0f) ?: 0f
        val diffX = e2?.x?.minus(e1?.x ?: 0f) ?: 0f
        if (abs(diffX) > abs(diffY)) {
            if (abs(diffX) > 100 && abs(velocityX) > 100) {
                if (diffX < 0) {
                    startActivity(Intent(this@ActivitySpam1, ActivitySpam2::class.java))
                }
            }
        }
        return true
    }

    override fun onTouch(v: View?, event: MotionEvent?): Boolean {
        TODO("Not yet implemented")
    }
}





