diff options
Diffstat (limited to 'src/us/minak/IMEService.java')
-rw-r--r-- | src/us/minak/IMEService.java | 71 |
1 files changed, 54 insertions, 17 deletions
diff --git a/src/us/minak/IMEService.java b/src/us/minak/IMEService.java index acbe616..b99859c 100644 --- a/src/us/minak/IMEService.java +++ b/src/us/minak/IMEService.java @@ -1,3 +1,15 @@ +/* + ******************************************************************************** + * Copyright (c) 2012 Samsung Electronics, Inc. + * All rights reserved. + * + * This software is a confidential and proprietary information of Samsung + * Electronics, Inc. ("Confidential Information"). You shall not disclose such + * Confidential Information and shall use it only in accordance with the terms + * of the license agreement you entered into with Samsung Electronics. + ******************************************************************************** + */ + package us.minak; import java.util.Queue; @@ -6,39 +18,64 @@ import android.inputmethodservice.InputMethodService; import android.view.View; import android.view.inputmethod.EditorInfo; +/** + * Represent the application input service. + */ public class IMEService extends InputMethodService { - /** - * Loads the configuration. - */ - @Override - public void onInitializeInterface() { - // TODO - } + private IMEView mPenboardView; @Override public View onCreateInputView() { - final IMEView view = (IMEView) getLayoutInflater().inflate(R.layout.ime, null); + final IMEView penboardView = (IMEView) getLayoutInflater().inflate(R.layout.ime, null); - view.setOutput(new StringReciever() { + penboardView.setOnCharacterEnteredListener(new OnCharacterEnteredListener() { @Override - public void putString(String character) { + public void characterEntered(String character) { getCurrentInputConnection().commitText(character, 1); } }); - return view; + penboardView.setOnBackspacePressedListener(new OnBackspacePressedListener() { + @Override + public void backspacePressed(boolean isLongClick) { + if (isLongClick) { + deleteLastWord(); + } else { + getCurrentInputConnection().deleteSurroundingText(1, 0); + } + } + }); + + mPenboardView = penboardView; + return penboardView; } - /** - * Called to inform the input method that text input has started in an editor. - */ - public void onStartInput(EditorInfo info, boolean restarting) { - if (imeView != null) { - final Queue<Character> symbolsQueue = imeView.getSymbolsQueue(); + @Override + public void onStartInput(EditorInfo attribute, boolean restarting) { + if (mPenboardView != null) { + final Queue<Character> symbolsQueue = mPenboardView.getSymbolsQueue(); while (!symbolsQueue.isEmpty()) { final Character character = symbolsQueue.poll(); getCurrentInputConnection().commitText(String.valueOf(character), 1); } } } + + /** + * Deletes one word before the cursor. + */ + private void deleteLastWord() { + final int charactersToGet = 20; + final String splitRegexp = " "; + + // delete trailing spaces + while (getCurrentInputConnection().getTextBeforeCursor(1, 0).toString().equals(splitRegexp)) { + getCurrentInputConnection().deleteSurroundingText(1, 0); + } + + // delete last word letters + final String[] words = getCurrentInputConnection().getTextBeforeCursor(charactersToGet, 0).toString() + .split(splitRegexp); + getCurrentInputConnection().deleteSurroundingText(words[words.length - 1].length(), 0); + } } |