<commit_before>package mobtex.listener;
//#if android
import flash.Lib;

import openfl.utils.JNI;

class VirtualKeyboardStateListener {
    static var savedInstance;

    var callbacks:Array<OnVirtualKeyboardChangeListener>;
    //if virtual keyboard state changes -> sends a signal to all registered callbacks
    private function sendCallBack(state:Bool, diffScreen:Float){
        trace("Callback send at " + Date.now().getTime());
        for(callback in callbacks){
            if(state){
                callback.onKeyboardUp(diffScreen);
            }else{
                callback.onKeyboardDown(diffScreen);
            }
        }
    }

    //return a saved instance of VirtualKeyboardStateListener
    public static function getInstance():VirtualKeyboardStateListener{
        if(savedInstance == null){
            savedInstance = new VirtualKeyboardStateListener();
        }
        return savedInstance;
    }


    //private to prevent multiple instances
    private function new() {
        callbacks = new Array<OnVirtualKeyboardChangeListener>();
        var jni_enable_listener:Dynamic = JNI.createStaticMethod("mobtex/android/ANVirtualKeyboardListener", "enableListener", "(Lorg/haxe/nme/HaxeObject;)I");
        var returnValue:Int = jni_enable_listener(this);
        if(returnValue == 1){
            trace("Enabled keyboard listener.");
        }else{
            trace("Wasn't able to set keyboard listener.");
        }
    }

    public function addCallback(callback:OnVirtualKeyboardChangeListener){
        callbacks.push(callback);
        trace("Current callback stack length: " + callbacks.length);
    }

    public function removeCallback(callback:OnVirtualKeyboardChangeListener){
        callbacks.remove(callback);
        trace("Current callback stack length: " + callbacks.length);
    }


    //gets called by JNI when keyboard state changes
    public function onVirtualKeyboardChange(overlayScreenY:Float){
        trace("Listener: virtual keyboard changed " + overlayScreenY);
        //if screen diff is higher than 1/3 of the screen -> virtual keyboard is up
        sendCallBack(overlayScreenY > Lib.current.stage.stageWidth/0.3, overlayScreenY);
    }
}

interface OnVirtualKeyboardChangeListener {
    function onKeyboardUp(remainingScreenY:Float):Void;
    function onKeyboardDown(remainingScreenY:Float):Void;
}
//#end
<commit_msg>Traces will only be shown if compiled with the following flag: -Dtrace<commit_after>package mobtex.listener;
//#if android
import flash.Lib;

import openfl.utils.JNI;

class VirtualKeyboardStateListener {
    static var savedInstance;

    var callbacks:Array<OnVirtualKeyboardChangeListener>;
    //if virtual keyboard state changes -> sends a signal to all registered callbacks
    private function sendCallBack(state:Bool, diffScreen:Float){
        #if trace
        trace("Callback send at " + Date.now().getTime());
        #end
        for(callback in callbacks){
            if(state){
                callback.onKeyboardUp(diffScreen);
            }else{
                callback.onKeyboardDown(diffScreen);
            }
        }
    }

    //return a saved instance of VirtualKeyboardStateListener
    public static function getInstance():VirtualKeyboardStateListener{
        if(savedInstance == null){
            savedInstance = new VirtualKeyboardStateListener();
        }
        return savedInstance;
    }


    //private to prevent multiple instances
    private function new() {
        callbacks = new Array<OnVirtualKeyboardChangeListener>();
        var jni_enable_listener:Dynamic = JNI.createStaticMethod("mobtex/android/ANVirtualKeyboardListener", "enableListener", "(Lorg/haxe/nme/HaxeObject;)I");
        var returnValue:Int = jni_enable_listener(this);
        if(returnValue == 1){
            #if trace
            trace("Enabled keyboard listener.");
            #end
        }else{
            #if trace
            trace("Wasn't able to set keyboard listener.");
            #end
        }
    }

    public function addCallback(callback:OnVirtualKeyboardChangeListener){
        callbacks.push(callback);
        #if trace
        trace("Current callback stack length: " + callbacks.length);
        #end
    }

    public function removeCallback(callback:OnVirtualKeyboardChangeListener){
        callbacks.remove(callback);
        #if trace
        trace("Current callback stack length: " + callbacks.length);
        #end
    }


    //gets called by JNI when keyboard state changes
    public function onVirtualKeyboardChange(overlayScreenY:Float){
        #if trace
        trace("Listener: virtual keyboard changed " + overlayScreenY);
        #end
        //if screen diff is higher than 1/3 of the screen -> virtual keyboard is up
        sendCallBack(overlayScreenY > Lib.current.stage.stageWidth/0.3, overlayScreenY);
    }
}

interface OnVirtualKeyboardChangeListener {
    function onKeyboardUp(remainingScreenY:Float):Void;
    function onKeyboardDown(remainingScreenY:Float):Void;
}
//#end

{'fraction_non_alphanumeric': 0.0891542288557214, 'fraction_numerical': 0.001990049751243781, 'mean_word_length': 2.9234972677595628, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '5560151', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1283, 'n_words': 325}