2014년 3월 3일 월요일

[Android] TextEdit 원하는 언어의 IME 띄워주기.


TextEdit에서 원하는 IME를 출력시키려면?


인터넷을 찾아보면,
   EditText lotId_input = (EditText) findViewById(R.id.lotStatus_lotId);
   lotId_input.setPrivateImeOptions("defaultInputmode=english; ");

이런식으로 나오는데, 동작안됨.
>> IME가 지원을 하지 않기 때문.

## OpenSource 키보드를 확인해보자..
 Kandroid에서 공유된 오픈소스 키보드다.
 https://code.google.com/p/hangulkeyboard/source/checkout
 여기를 확인해보면, onStartInput 함수에서 EditorInfo attribute 값을 주목하자.

>> 소스를 커스터마이즈 해서, 옵션이 들어가면 키보드를 변경하는 루틴을 추가하면
     될 것이라 예상 된다.

SoftKeyboard.java

    /**
     * This is the main point where we do our initialization of the input method
     * to begin operating on an application.  At this point we have been
     * bound to the client, and are now receiving all of the detailed information
     * about the target of our edits.
     */
    @Override public void onStartInput(EditorInfo attribute, boolean restarting) {
        super.onStartInput(attribute, restarting);
/*      
        Log.i("Hangul", "onStartInput");
*/
        clearHangul();
        clearSejong();
        previousCurPos = -1;      
     
        // Reset our state.  We want to do this even if restarting, because
        // the underlying state of the text editor could have changed in any way.
        mComposing.setLength(0);
        updateCandidates();
     
        if (!restarting) {
            // Clear shift states.
            mMetaState = 0;
        }
     
        mPredictionOn = false;
        mCompletionOn = false;
        mCompletions = null;
     
        // We are now going to initialize our state based on the type of
        // text being edited.
        switch (attribute.inputType&EditorInfo.TYPE_MASK_CLASS) {
            case EditorInfo.TYPE_CLASS_NUMBER:
            case EditorInfo.TYPE_CLASS_DATETIME:
                // Numbers and dates default to the symbols keyboard, with
                // no extra features.
                mCurKeyboard = mSymbolsKeyboard;
                break;
             
            case EditorInfo.TYPE_CLASS_PHONE:
                // Phones will also default to the symbols keyboard, though
                // often you will want to have a dedicated phone keyboard.
                mCurKeyboard = mSymbolsKeyboard;
                break;
             
            case EditorInfo.TYPE_CLASS_TEXT:
                // This is general text editing.  We will default to the
                // normal alphabetic keyboard, and assume that we should
                // be doing predictive text (showing candidates as the
                // user types).
                mCurKeyboard = mQwertyKeyboard;
                mPredictionOn = true;
             
                // We now look for a few special variations of text that will
                // modify our behavior.
                int variation = attribute.inputType &  EditorInfo.TYPE_MASK_VARIATION;
                if (variation == EditorInfo.TYPE_TEXT_VARIATION_PASSWORD ||
                        variation == EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
                    // Do not display predictions / what the user is typing
                    // when they are entering a password.
                    mPredictionOn = false;
                }
             
                if (variation == EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
                        || variation == EditorInfo.TYPE_TEXT_VARIATION_URI
                        || variation == EditorInfo.TYPE_TEXT_VARIATION_FILTER) {
                    // Our predictions are not useful for e-mail addresses
                    // or URIs.
                    mPredictionOn = false;
                }
             
                if ((attribute.inputType&EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
                    // If this is an auto-complete text view, then our predictions
                    // will not be shown and instead we will allow the editor
                    // to supply their own.  We only show the editor's
                    // candidates when in fullscreen mode, otherwise relying
                    // own it displaying its own UI.
                    mPredictionOn = false;
                    mCompletionOn = isFullscreenMode();
                }
             
                // We also want to look at the current state of the editor
                // to decide whether our alphabetic keyboard should start out
                // shifted.
                updateShiftKeyState(attribute);
                break;
             
            default:
                // For all unknown input types, default to the alphabetic
                // keyboard with no special features.
                mCurKeyboard = mQwertyKeyboard;
                updateShiftKeyState(attribute);
        }
     
        // Update the label on the enter key, depending on what the application
        // says it will do.
        mCurKeyboard.setImeOptions(getResources(), attribute.imeOptions);
     
    }






참고:
http://effectiveprogramming.tistory.com/11
http://android-developers.blogspot.kr/2009/04/creating-input-method.html


# 본 게시물의 View수가 많은 것 같아서 해결책을 덧붙여본다.
  InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        String inputId = "";
        List<InputMethodInfo> inputMethodInfos = imm.getInputMethodList();
        for ( InputMethodInfo inputMethodInfo : inputMethodInfos ) {
            if ( inputMethodInfo.getId().contains(keyType)){          
                inputId = inputMethodInfo.getId();
                break;
            }
        }

INPUT_METHOD_SERVICE를 이용해서, 시스템에 설치된 키보드의 ID를 가져온다.

   imm.setInputMethod(null, inputId);

setInputMethod함수로 해당 아이디를 지정하면, 기본 IME가 변경된다.



댓글 없음:

댓글 쓰기