Android Open Source - MYKey_SoftKeyboard Key Processor






From Project

Back to project page MYKey_SoftKeyboard.

License

The source code is released under:

Apache License

If you think the Android project MYKey_SoftKeyboard listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package key_process;
//  w  w w  .  j a va2  s . c o m
import com.android.mykey.*;

import key_process.*;
import korean_automata.*;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.view.KeyEvent;
import android.view.inputmethod.InputConnection;

public class KeyProcessor {
  private Buffer buffer;
  private KoreanAutomata korAt;
  private SoftKeyboard ime;
  private KeyboardView mInputView;
  private KeyInfo keyInfo;
  private int keyCode;
  private int inputCount;
  private boolean isRenew;
  private boolean isInitShift;
  
  private boolean isWordSeparator() {
    String tmpSeparators = ime.getWordSeparators();
    return tmpSeparators.contains(String.valueOf((char) keyCode));
  }


  public void processKey(int keyCode) {
    isInitShift = true;
    
    this.keyCode = keyCode;

    if (isWordSeparator()) {
      if (buffer.getComBuffLength() != 0)
        buffer.commitTyped();
      
      buffer.commitOther(keyCode);
      initAutomata();
    }
    else if (keyCode <= -1 && keyCode >= -8) {
      specialKey();
    }
    else if (keyCode / 1000 == 3) {
      koreanKey();
    }
    else if (keyCode / 1000 == 4){
      
    }
    else {
      otherKey();
    }
    
    
    if(isInitShift)
      ime.initKeyboardShifted();
  }
  
  
  

  private void specialKey() {
    final int KEYCODE_IME_PREFERENCE = -2;
    final int KEYCODE_MODE_CHANGE_TO_KOR = -6;
    final int KEYCODE_MODE_CHANGE_TO_ENG = -7;
    final int KEYCODE_MODE_CHANGE_TO_NUM = -8;
    final int KEYCODE_BLANK = -4;
    
    boolean isKorKeyboard = false;
    

    switch (keyCode) {
    case Keyboard.KEYCODE_DELETE:
      final int length = buffer.getComBuffLength();

      if (length > 1) {
        buffer.deleteComBuff();
        buffer.commitTyped();
      }
      else if (length > 0) {
        buffer.initBuffer();
        buffer.commitDelete();
      }
      else {
        buffer.commitKeyEvent(KeyEvent.KEYCODE_DEL);
        inputCount = 0;
      }
      break;

    case Keyboard.KEYCODE_SHIFT:
      isKorKeyboard = ime.handleShift();
      isInitShift = false;
      break;

    case KEYCODE_MODE_CHANGE_TO_KOR:
    case KEYCODE_MODE_CHANGE_TO_ENG:
    case KEYCODE_MODE_CHANGE_TO_NUM:
      ime.switchKeyboard(keyCode);
      buffer.commitTyped();
      break;

    case Keyboard.KEYCODE_CANCEL:
      buffer.commitTyped();
      ime.requestHideSelf(0);
      if (mInputView != null)
        mInputView.closing();
      break;

    case KEYCODE_BLANK:
      return;
      
    case KEYCODE_IME_PREFERENCE:
      ime.startImePreferenceActivity();
          return;
    }
    
    if(!isKorKeyboard)
      initAutomata();
  }

  
  private void koreanKey() {
    int korPhoneme = 0;
    boolean isFinal;

    isFinal = korAt.getIsFinalInput();
    
    korPhoneme = keyInfo.getPhoneme(keyCode, isFinal);
    
    
    if (keyInfo.isReentrance() || inputCount == 0){
      isRenew = false;
      buffer.appendPhoneme(korPhoneme);
    }
    else{
      isRenew = true;
      buffer.renewPhoneme(korPhoneme);
    }
    
    inputCount++;

    korAt.startCombine(isRenew);
  }

  
  private void otherKey() {
    
    if (keyCode == 32) {
      if (buffer.getComBuffLength() == 0){
        buffer.commitOther(keyCode);
      }else{
        buffer.commitTyped();
      }
    } 
    else {
      if(isAlpha() && mInputView.isShifted())
        keyCode = Character.toUpperCase(keyCode);
      
      buffer.commitOther(keyCode);
    }

    initAutomata();
  }
  
  
  private boolean isAlpha(){
    if (Character.isLetter(keyCode)) {
            return true;
        } else {
            return false;
        }
  }
  

  public KeyProcessor() {
    buffer = new Buffer();
    korAt = new KoreanAutomata(buffer);
    keyInfo = new KeyInfo();
  }

  
  public void initAutomata(SoftKeyboard ime, KeyboardView mInputView) {
    keyCode = 0;
    inputCount = 0;
    
    this.ime = ime;
    this.mInputView = mInputView;

    buffer.initBuffer(ime);
    korAt.initKoreaAutomataState();
    keyInfo.initKeyInfo();
    
  }
  
  private void initAutomata(){
    keyCode = 0;
    inputCount = 0;
    
    buffer.initBuffer();
    korAt.initKoreaAutomataState();
    keyInfo.initKeyInfo();
    
  }
  
  
  public void processText(CharSequence text){
    InputConnection ic = ime.getCurrentInputConnection();
    
    if (ic == null)
      return;
    
    if (buffer.getComBuffLength() > 0) {
      buffer.commitTyped();
    }
    
    ic.commitText(text, 0);
    ime.initKeyboardShifted();
  }
  
}




Java Source Code List

com.android.mykey.LatinKeyboardView.java
com.android.mykey.LatinKeyboard.java
com.android.mykey.SoftKeyboard.java
ime_preferences.ImePreferencesActivity.java
key_process.Buffer.java
key_process.FinalCombinationInfo.java
key_process.KeyInfo.java
key_process.KeyMap.java
key_process.KeyProcessor.java
korean_automata.CombinationState.java
korean_automata.KoreanAutomata.java
korean_automata.PhonemeCategoryConverter.java
korean_automata.Proc1.java
korean_automata.Proc2.java
korean_automata.Proc3.java
korean_automata.Proc4.java
korean_automata.StArea.java
korean_automata.StEmpty.java
korean_automata.StError.java
korean_automata.StFirstArea.java
korean_automata.StFirstVowelAndFirst.java
korean_automata.StFirstVowel.java
korean_automata.StFirst.java
korean_automata.StMultiFinal.java
korean_automata.StSingleFinalAndFirst.java
korean_automata.StSingleFinal.java
korean_automata.StVowel.java
korean_automata.VerifyComb.java
string_Key.StringKeyHandler.java
string_Key.StringKeyListAdapter.java
string_Key.StringKeyModifyActivity.java