<commit_before>package inc.flide.vim8;

import android.content.Context;
import android.inputmethodservice.InputMethodService;
import android.os.IBinder;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;

import java.util.List;
import java.util.Map;

import inc.flide.vim8.keyboardHelpers.InputMethodServiceHelper;
import inc.flide.vim8.keyboardHelpers.KeyboardAction;
import inc.flide.vim8.preferences.SharedPreferenceHelper;
import inc.flide.vim8.structures.FingerPosition;
import inc.flide.vim8.views.NumberKeypadView;
import inc.flide.vim8.views.SelectionKeypadView;
import inc.flide.vim8.views.SymbolKeypadView;
import inc.flide.vim8.views.mainKeyboard.MainKeyboardView;

public class MainInputMethodService extends InputMethodService {

    private InputConnection inputConnection;
    private EditorInfo editorInfo;

    private MainKeyboardView mainKeyboardView;
    private NumberKeypadView numberKeypadView;
    private SelectionKeypadView selectionKeypadView;
    private SymbolKeypadView symbolKeypadView;
    private View currentKeypadView;

    private int shiftLockFlag;
    private int capsLockFlag;
    private int modifierFlags;

    private void setCurrentKeypadView(View view){
        this.currentKeypadView = view;
        currentKeypadView.invalidate();
        setInputView(currentKeypadView);
    }

    /**
     * Lifecycle of IME
     * <p>
     * 01.  InputMethodService Starts
     * 02.  onCreate()
     * 03.  onCreateInputView()
     * 04.  onCreateCandidateViews()
     * 05.  onStartInputViews()
     * 06.  Text input gets the current input method subtype
     * 07.  InputMethodManager#getCurrentInputMethodSubtype()
     * 08.  Text input has started
     * 09.  onCurrentInputMethodSubtypeChanged()
     * 10. Detect the current input method subtype has been changed -> can go to step 6
     * 11. onFinishInput() -> cursor can Move to an additional field -> step 5
     * 12. onDestroy()
     * 13. InputMethodService stops
     */

    @Override
    public View onCreateInputView() {
        numberKeypadView = new NumberKeypadView(this, null);
        selectionKeypadView = new SelectionKeypadView(this, null);
        symbolKeypadView = new SymbolKeypadView(this, null);
        mainKeyboardView = new MainKeyboardView(this, null);
        setCurrentKeypadView(mainKeyboardView);
        return currentKeypadView;
    }

    @Override
    public void onStartInput(EditorInfo attribute, boolean restarting) {
        super.onStartInput(attribute, restarting);
        this.inputConnection = getCurrentInputConnection();
    }

    @Override
    public void onBindInput() {
        inputConnection = getCurrentInputConnection();
    }

    @Override
    public void onStartInputView(EditorInfo info, boolean restarting) {
        super.onStartInputView(info, restarting);
        setCurrentKeypadView(mainKeyboardView);
        this.editorInfo = info;<commit_msg>#32 Display number keyboard when appropriate<commit_after>package inc.flide.vim8;

import android.content.Context;
import android.inputmethodservice.InputMethodService;
import android.os.IBinder;
import android.os.SystemClock;
import android.text.InputType;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;

import java.util.List;
import java.util.Map;

import inc.flide.vim8.keyboardHelpers.InputMethodServiceHelper;
import inc.flide.vim8.keyboardHelpers.KeyboardAction;
import inc.flide.vim8.preferences.SharedPreferenceHelper;
import inc.flide.vim8.structures.FingerPosition;
import inc.flide.vim8.views.NumberKeypadView;
import inc.flide.vim8.views.SelectionKeypadView;
import inc.flide.vim8.views.SymbolKeypadView;
import inc.flide.vim8.views.mainKeyboard.MainKeyboardView;

public class MainInputMethodService extends InputMethodService {

    private InputConnection inputConnection;
    private EditorInfo editorInfo;

    private MainKeyboardView mainKeyboardView;
    private NumberKeypadView numberKeypadView;
    private SelectionKeypadView selectionKeypadView;
    private SymbolKeypadView symbolKeypadView;
    private View currentKeypadView;

    private int shiftLockFlag;
    private int capsLockFlag;
    private int modifierFlags;

    private void setCurrentKeypadView(View view){
        this.currentKeypadView = view;
        currentKeypadView.invalidate();
        setInputView(currentKeypadView);
    }

    /**
     * Lifecycle of IME
     * <p>
     * 01.  InputMethodService Starts
     * 02.  onCreate()
     * 03.  onCreateInputView()
     * 04.  onCreateCandidateViews()
     * 05.  onStartInputViews()
     * 06.  Text input gets the current input method subtype
     * 07.  InputMethodManager#getCurrentInputMethodSubtype()
     * 08.  Text input has started
     * 09.  onCurrentInputMethodSubtypeChanged()
     * 10. Detect the current input method subtype has been changed -> can go to step 6
     * 11. onFinishInput() -> cursor can Move to an additional field -> step 5
     * 12. onDestroy()
     * 13. InputMethodService stops
     */

    @Override
    public View onCreateInputView() {
        numberKeypadView = new NumberKeypadView(this, null);
        selectionKeypadView = new SelectionKeypadView(this, null);
        symbolKeypadView = new SymbolKeypadView(this, null);
        mainKeyboardView = new MainKeyboardView(this, null);
        setCurrentKeypadView(mainKeyboardView);
        return currentKeypadView;
    }

    @Override
    public void onStartInput(EditorInfo attribute, boolean restarting) {
        super.onStartInput(attribute, restarting);
        this.inputConnection = getCurrentInputConnection();
    }

    @Override
    public void onBindInput() {
        inputConnection = getCurrentInputConnection();
    }

    @Override
    public void onStartInputView(EditorInfo info, boolean restarting) {
        super.onStartInputView(info, restarting);
        this.editorInfo = info;
        int inputType = this.editorInfo.inputType & InputType.TYPE_MASK_CLASS;
        switch (inputType) {
            case InputType.TYPE_CLASS_NUMBER:
            case InputType.TYPE_CLASS_PHONE:
            case InputType.TYPE_CLASS_DATETIME:
                switchToNumberPad();
                break;
            case InputType.TYPE_CLASS_TEXT:
            default:
                switchToMainKeypad();
                break;
        }
{'fraction_non_alphanumeric': 0.07585515958208101, 'fraction_numerical': 0.0108773436381852, 'mean_word_length': 3.6867873910127433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3631481', 'n_tokens_mistral': 2055, 'n_tokens_neox': 1919, 'n_words': 438}