<commit_before>package net.momodalo.app.vimtouch;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.GestureDetector;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.graphics.Canvas;
import android.os.Handler;

import jackpal.androidterm.emulatorview.ColorScheme;
import jackpal.androidterm.emulatorview.EmulatorView;
import jackpal.androidterm.emulatorview.TermSession;

public class TermView extends EmulatorView implements
        GestureDetector.OnGestureListener,
        ScaleGestureDetector.OnScaleGestureListener {
    private TermSession mSession;
    private int mTopRow = 0; //we don't use termnial scroll
    private GestureDetector mGestureDetector;
    private ScaleGestureDetector mScaleDetector;

    private static final int FLING_REFRESH_PERIOD = 50;
    private static final int SCREEN_CHECK_PERIOD = 1000;
    private static final int CURSOR_BLINK_PERIOD = 1000;

    public TermView(Context context, TermSession session, DisplayMetrics metrics) {
        super(context, session, metrics);
        mSession = session;
        mGestureDetector = new GestureDetector(this);
        mScaleDetector = new ScaleGestureDetector(context, this);
    }

    public void updatePrefs(TermSettings settings, ColorScheme scheme) {
        if (scheme == null) {
            scheme = new ColorScheme(settings.getColorScheme());
        }

        setTextSize(settings.getFontSize());
        setCursorStyle(settings.getCursorStyle(), settings.getCursorBlink());
        setUseCookedIME(settings.useCookedIME());
        setColorScheme(scheme);
        setBackKeyCharacter(settings.getBackKeyCharacter());
        setControlKeyCode(settings.getControlKeyCode());
        setFnKeyCode(settings.getFnKeyCode());
    }

    public void updatePrefs(TermSettings settings) {
        updatePrefs(settings, null);
    }

    // Begin GestureDetector.OnGestureListener methods
    /**
     * Our message handler class. Implements a periodic callback.
     */
    private final Handler mHandler = new Handler();

    public void onLongPress(MotionEvent e) {
        setZoom(true);
        invalidate();
    }

    public boolean onScroll(MotionEvent e1, MotionEvent e2,
            float distanceX, float distanceY) {
        /*
        distanceY += mScrollRemainder;
        int deltaRows = (int) (distanceY / getCharacterHeight());
        mScrollRemainder = distanceY - deltaRows * getCharacterHeight();
        mTopRow =
            Math.min(0, Math.max(-(mTranscriptScreen
                    .getActiveTranscriptRows()), mTopRow + deltaRows));
        */
        invalidate();
        return true;
    }

    float mScaleSpan = (float)-1.0;
    float mPreviousSpan = (float)-1.0;
    

    public boolean onScale(ScaleGestureDetector detector) {
        try{
            float span = detector.getCurrentSpan();
            if(mScaleSpan > span){
                float diff = mPreviousSpan - span;
                if( diff > getCharacterHeight()) {
                    String line = Integer.toString((int)(diff/getCharacterHeight()));
                    mSession.write(line+"dd");
                    mPreviousSpan = span;
                }else if (-diff > getCharacterHeight() ){
                    String line = Integer.toString((int)(-diff/getCharacterHeight()));
                    mSession.write(line+"u");
                    mPreviousSpan = span;
                }
            }else{
                float diff = span - mPreviousSpan;
                if( diff > getCharacterHeight()) {
                    String line = Integer.toString((int)(diff/getCharacterHeight()));
                    mSession.write(line+"p");
                    mPreviousSpan = span;
                }else if (-diff > getCharacterHeight() ){
                    String line = Integer.toString((int)(-diff/getCharacterHeight()));
                    mSession.write(line+"u");
                    mPreviousSpan = span;
                }
            }
        } catch (Exception e){
        }
        Exec.updateScreen();
        return true;
    }

    public boolean onScaleBegin(ScaleGestureDetector detector){
        mScaleSpan = detector.getCurrentSpan();;
        mPreviousSpan = mScaleSpan;
        setZoom(false);
        return true;
    }

    public void onScaleEnd(ScaleGestureDetector detector){
        /*
        try{
            mSession.write('z');
            if(mScaleSpan > detector.getCurrentSpan())
                mSession.write('c');
            else
                mSession.write('o');
            mTermOut.flush();
        } catch (IOException e){
        }
        Exec.updateScreen();
        */
        mScaleSpan = (float)-1.0;
    }

    private float mVelocity = 0;

    private Runnable mFlingRun = new Runnable() {
        public void run() {
            Exec.scrollBy((int)mVelocity);
            Exec.updateScreen();<commit_msg>add send ESC for single TAP<commit_after>package net.momodalo.app.vimtouch;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.GestureDetector;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.graphics.Canvas;
import android.os.Handler;

import jackpal.androidterm.emulatorview.ColorScheme;
import jackpal.androidterm.emulatorview.EmulatorView;
import jackpal.androidterm.emulatorview.TermSession;

public class TermView extends EmulatorView implements
        GestureDetector.OnGestureListener,
        ScaleGestureDetector.OnScaleGestureListener {
    private TermSession mSession;
    private int mTopRow = 0; //we don't use termnial scroll
    private GestureDetector mGestureDetector;
    private ScaleGestureDetector mScaleDetector;

    private static final int FLING_REFRESH_PERIOD = 50;
    private static final int SCREEN_CHECK_PERIOD = 1000;
    private static final int CURSOR_BLINK_PERIOD = 1000;

    public TermView(Context context, TermSession session, DisplayMetrics metrics) {
        super(context, session, metrics);
        mSession = session;
        mGestureDetector = new GestureDetector(this);
        mScaleDetector = new ScaleGestureDetector(context, this);
    }

    public void updatePrefs(TermSettings settings, ColorScheme scheme) {
        if (scheme == null) {
            scheme = new ColorScheme(settings.getColorScheme());
        }

        setTextSize(settings.getFontSize());
        setCursorStyle(settings.getCursorStyle(), settings.getCursorBlink());
        setUseCookedIME(settings.useCookedIME());
        setColorScheme(scheme);
        setBackKeyCharacter(settings.getBackKeyCharacter());
        setControlKeyCode(settings.getControlKeyCode());
        setFnKeyCode(settings.getFnKeyCode());
    }

    public void updatePrefs(TermSettings settings) {
        updatePrefs(settings, null);
    }

    // Begin GestureDetector.OnGestureListener methods
    /**
     * Our message handler class. Implements a periodic callback.
     */
    private final Handler mHandler = new Handler();

    public void onLongPress(MotionEvent e) {
        setZoom(true);
        invalidate();
    }

    public boolean onScroll(MotionEvent e1, MotionEvent e2,
            float distanceX, float distanceY) {
        /*
        distanceY += mScrollRemainder;
        int deltaRows = (int) (distanceY / getCharacterHeight());
        mScrollRemainder = distanceY - deltaRows * getCharacterHeight();
        mTopRow =
            Math.min(0, Math.max(-(mTranscriptScreen
                    .getActiveTranscriptRows()), mTopRow + deltaRows));
        */
        invalidate();
        return true;
    }

    float mScaleSpan = (float)-1.0;
    float mPreviousSpan = (float)-1.0;
    

    public boolean onScale(ScaleGestureDetector detector) {
        try{
            float span = detector.getCurrentSpan();
            if(mScaleSpan > span){
                float diff = mPreviousSpan - span;
                if( diff > getCharacterHeight()) {
                    String line = Integer.toString((int)(diff/getCharacterHeight()));
                    mSession.write(line+"dd");
                    mPreviousSpan = span;
                }else if (-diff > getCharacterHeight() ){
                    String line = Integer.toString((int)(-diff/getCharacterHeight()));
                    mSession.write(line+"u");
                    mPreviousSpan = span;
                }
            }else{
                float diff = span - mPreviousSpan;
                if( diff > getCharacterHeight()) {
                    String line = Integer.toString((int)(diff/getCharacterHeight()));
                    mSession.write(line+"p");
                    mPreviousSpan = span;
                }else if (-diff > getCharacterHeight() ){
                    String line = Integer.toString((int)(-diff/getCharacterHeight()));
                    mSession.write(line+"u");
                    mPreviousSpan = span;
                }
            }
        } catch (Exception e){
        }
        Exec.updateScreen();
        return true;
    }

    public boolean onScaleBegin(ScaleGestureDetector detector){
        mScaleSpan = detector.getCurrentSpan();;
        mPreviousSpan = mScaleSpan;
        setZoom(false);
        return true;
    }

    public void onScaleEnd(ScaleGestureDetector detector){
        /*
        try{
            mSession.write('z');
            if(mScaleSpan > detector.getCurrentSpan())
                mSession.write('c');
            else
                mSession.write('o');
            mTermOut.flush();
        } catch (IOException e){
        }
        Exec.updateScreen();
        */
        mScaleSpan = (float)-1.0;
    }

    public boolean onSingleTapUp(MotionEvent ev) {
        mSession.write(27);
        return true;
    }

    private float mVelocity = 0;

    private Runnable mFlingRun = new Runnable() {
        public void run() {
            Exec.scrollBy((int)mVelocity);
            Exec.updateScreen();
{'fraction_non_alphanumeric': 0.09495109178934888, 'fraction_numerical': 0.004347396502321905, 'mean_word_length': 2.2767886047264487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '7048764', 'n_tokens_mistral': 2777, 'n_tokens_neox': 2606, 'n_words': 567}