<commit_before>package me.bemind.glitchappcore.glitch

import android.graphics.Bitmap
import android.graphics.Canvas
import android.util.Log
import me.bemind.glitch.Effect
import me.bemind.glitch.Glitcher
import android.content.Context
import android.os.Bundle
import android.support.v4.view.GestureDetectorCompat
import android.view.GestureDetector
import android.view.MotionEvent
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import me.bemind.glitch.Motion
import me.bemind.glitch.TypeEffect
import me.bemind.glitchappcore.GlitchyBaseActivity


/**
 * Created by angelomoroni on 14/04/17.
 */

interface IGlitchPresenter{

    var effectON : Boolean

    var effectProgress : Int

    var effect : Effect

    val typeEffect : TypeEffect

    var glitchView : IGlitchView?

    var restore: Boolean

    var canvas: Canvas?

    fun onDraw(canvas: Canvas?,scale:Boolean = false)

    fun onTouchEvent(event:MotionEvent?) :Boolean

    fun saveEffect()

    fun initEffect(bitmap: Bitmap?,effect:Effect)

    fun saveInstanceState(glitchyBaseActivity: GlitchyBaseActivity,outState: Bundle?)

    fun restoreSavedInstanceState(glitchyBaseActivity: GlitchyBaseActivity, savedInstanceState:Bundle?)

    fun initEffect(bitmap: Bitmap?, restore: Boolean)

    fun clearEffect()
    fun makeEffect(progress: Int)


    //effects
    fun anaglyph(canvas: Canvas?,progress:Int = 20)
    fun ghost(canvas: Canvas?,x:Int,y:Int,motion: Motion)
    fun glitch(canvas: Canvas?)
    fun webp(canvas: Canvas?)
    fun swap(canvas: Canvas?)
    fun noise(canvas: Canvas?)


}

class GlitchPresenter(val context: Context) : IGlitchPresenter, GestureDetector.OnGestureListener {



    private val EFFECT_PROGRESS_K: String? = "eef_pro_k"
    private val EFFECT_K: String? = "effect_k"
    private val EFFECT_ON_K: String? = "eef_on_k"

    var volatileBitmap: Bitmap? = null

    override var glitchView: IGlitchView? = null
        set(value) {
            field = value
        }

    override var effectON: Boolean = false

    override var restore: Boolean = false

    val glitchLogic = GlitchLogic()

    val glithce =  Glitcher

    override var effectProgress = 0

    private var scaledFactory: Float = 1f

    override var canvas: Canvas? = null

    var gestureDetector : GestureDetectorCompat? = null

    val viewCoords = IntArray(2)

    //touch properties
    private var touchX = 0
    private var touchY = 0
    private var startTouchX = 0
    private var startTouchY = 0
    private var motion: Motion = Motion.NONE
    //end touch properties

    val setImageAction = {
        b : Bitmap? -> glitchView?.setImageBitmap(b,true) //volatile
        glitchView?.showLoader(false)
        volatileBitmap = b


    }

    override var effect  = Effect.BASE
        set(value) {
            field = value
            glitchView?.invalidateGlitchView()
        }

    override val typeEffect: TypeEffect
        get() = when (effect){
            Effect.GLITCH -> TypeEffect.JPEG
            Effect.WEBP -> TypeEffect.JPEG
            Effect.SWAP -> TypeEffect.JPEG
            Effect.NOISE -> TypeEffect.JPEG
            Effect.ANAGLYPH -> TypeEffect.CANVAS
            Effect.GHOST -> TypeEffect.CANVAS
            else -> TypeEffect.NONE
        }

    init {
        gestureDetector = GestureDetectorCompat(context,this)
    }

    override fun anaglyph(canvas: Canvas?, progress: Int) {
        //glitchLogic.anaglyph(canvas, progress)

        glithce.anaglyphCanvas(canvas,progress)
    }

    override fun ghost(canvas: Canvas?, x: Int, y: Int, motion: Motion) {
        glithce.ghostCanvas(canvas,x,y,motion)
    }



    override fun glitch(canvas: Canvas?) {
        observeImage({
            glithce.corruption(glithce.baseBitmap)
        },setImageAction)

    }

    override fun swap(canvas: Canvas?) {
        observeImage({
            glithce.swap(glithce.baseBitmap)
        },setImageAction)<commit_msg>init ghost effect in glitch presenter<commit_after>package me.bemind.glitchappcore.glitch

import android.graphics.Bitmap
import android.graphics.Canvas
import android.util.Log
import me.bemind.glitch.Effect
import me.bemind.glitch.Glitcher
import android.content.Context
import android.os.Bundle
import android.support.v4.view.GestureDetectorCompat
import android.view.GestureDetector
import android.view.MotionEvent
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import me.bemind.glitch.Motion
import me.bemind.glitch.TypeEffect
import me.bemind.glitchappcore.GlitchyBaseActivity


/**
 * Created by angelomoroni on 14/04/17.
 */

interface IGlitchPresenter{

    var effectON : Boolean

    var effectProgress : Int

    var effect : Effect

    val typeEffect : TypeEffect

    var glitchView : IGlitchView?

    var restore: Boolean

    var canvas: Canvas?

    fun onDraw(canvas: Canvas?,scale:Boolean = false)

    fun onTouchEvent(event:MotionEvent?) :Boolean

    fun saveEffect()

    fun initEffect(bitmap: Bitmap?,effect:Effect)

    fun saveInstanceState(glitchyBaseActivity: GlitchyBaseActivity,outState: Bundle?)

    fun restoreSavedInstanceState(glitchyBaseActivity: GlitchyBaseActivity, savedInstanceState:Bundle?)

    fun initEffect(bitmap: Bitmap?, restore: Boolean)

    fun clearEffect()
    fun makeEffect(progress: Int)


    //effects
    fun anaglyph(canvas: Canvas?,progress:Int = 20)
    fun ghost(canvas: Canvas?,x:Int,y:Int,motion: Motion)
    fun glitch(canvas: Canvas?)
    fun webp(canvas: Canvas?)
    fun swap(canvas: Canvas?)
    fun noise(canvas: Canvas?)


}

class GlitchPresenter(val context: Context) : IGlitchPresenter, GestureDetector.OnGestureListener {



    private val EFFECT_PROGRESS_K: String? = "eef_pro_k"
    private val EFFECT_K: String? = "effect_k"
    private val EFFECT_ON_K: String? = "eef_on_k"

    var volatileBitmap: Bitmap? = null

    override var glitchView: IGlitchView? = null
        set(value) {
            field = value
        }

    override var effectON: Boolean = false

    override var restore: Boolean = false

    val glitchLogic = GlitchLogic()

    val glithce =  Glitcher

    override var effectProgress = 0

    private var scaledFactory: Float = 1f

    override var canvas: Canvas? = null

    var gestureDetector : GestureDetectorCompat? = null

    val viewCoords = IntArray(2)

    //touch properties
    private var touchX = -1
    private var touchY = -1
    private var startTouchX = 0
    private var startTouchY = 0
    private var motion: Motion = Motion.NONE
    //end touch properties

    val setImageAction = {
        b : Bitmap? -> glitchView?.setImageBitmap(b,true) //volatile
        glitchView?.showLoader(false)
        volatileBitmap = b


    }

    override var effect  = Effect.BASE
        set(value) {
            field = value
            glitchView?.invalidateGlitchView()
        }

    override val typeEffect: TypeEffect
        get() = when (effect){
            Effect.GLITCH -> TypeEffect.JPEG
            Effect.WEBP -> TypeEffect.JPEG
            Effect.SWAP -> TypeEffect.JPEG
            Effect.NOISE -> TypeEffect.JPEG
            Effect.ANAGLYPH -> TypeEffect.CANVAS
            Effect.GHOST -> TypeEffect.CANVAS
            else -> TypeEffect.NONE
        }

    init {
        gestureDetector = GestureDetectorCompat(context,this)
    }

    override fun anaglyph(canvas: Canvas?, progress: Int) {
        //glitchLogic.anaglyph(canvas, progress)

        glithce.anaglyphCanvas(canvas,progress)
    }

    override fun ghost(canvas: Canvas?, x: Int, y: Int, motion: Motion) {
        if(touchX>-1) {
            glithce.ghostCanvas(canvas, x, y, motion)
        }
    }



    override fun glitch(canvas: Canvas?) {
        observeImage({
            glithce.corruption(glithce.baseBitmap)
        },setImageAction)

    }

    override fun swap(canvas: Canvas?) {
        observeImage({
            glithce.swap(glithce.baseBitmap)
        },setImageAction)
{'fraction_non_alphanumeric': 0.08666584127770212, 'fraction_numerical': 0.0040856753745202425, 'mean_word_length': 2.9424109321620304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5834571', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2415, 'n_words': 576}