Example usage for android.view.inputmethod InputConnection deleteSurroundingText

List of usage examples for android.view.inputmethod InputConnection deleteSurroundingText

Introduction

In this page you can find the example usage for android.view.inputmethod InputConnection deleteSurroundingText.

Prototype

boolean deleteSurroundingText(int beforeLength, int afterLength);

Source Link

Document

Delete beforeLength characters of text before the current cursor position, and delete afterLength characters of text after the current cursor position, excluding the selection.

Usage

From source file:com.volosyukivan.WiFiInputMethod.java

private void keyDel(InputConnection conn) {
    if (pressedKeys.contains(KeyEvent.KEYCODE_SHIFT_LEFT)) {
        cut(conn);//from  ww w  .jav  a  2  s  .c om
        return;
    }
    conn.deleteSurroundingText(0, 1);
    conn.commitText("", 0);
}

From source file:com.volosyukivan.WiFiInputMethod.java

boolean setText(String text) {
    // FIXME: need feedback if the input was lost
    InputConnection conn = getCurrentInputConnection();
    if (conn == null) {
        //      Debug.d("connection closed");
        return false;
    }//from  ww  w.  ja  v a 2 s  . co  m
    conn.beginBatchEdit();
    // FIXME: hack
    conn.deleteSurroundingText(100000, 100000);
    conn.commitText(text, text.length());
    conn.endBatchEdit();
    return true;
}

From source file:net.zhdev.ctrlvkeyboard.CtrlVKeyboard.java

/**
 * Inserts text in the current focused text editor if possible and if it is a valid one.
 *
 * @param text          the text to be inserted
 * @param clearBefore   whether the text editor should be cleared before inserting the text
 * @param endWithAction whether the IME action should be performed at the end
 * @return {@code true} if the text was inserted and the actions performed, {@code false}
 * otherwise/*from  www. jav  a 2s.  c om*/
 */
private boolean type(String text, boolean clearBefore, boolean endWithAction) {
    boolean result = false;

    if (text == null) {
        text = "";
    }

    EditorInfo info = getCurrentInputEditorInfo();

    if (info != null) {
        // If the view accepts text as input
        if ((info.inputType & EditorInfo.TYPE_MASK_CLASS) != EditorInfo.TYPE_NULL) {
            InputConnection ic = getCurrentInputConnection();

            if (ic != null) {
                boolean enterShouldHaveAction = true;
                ic.beginBatchEdit();
                if (endWithAction) {
                    enterShouldHaveAction = (info.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0;
                    if (!enterShouldHaveAction) {
                        text += "\n";
                    }
                }
                if (clearBefore) {
                    ic.deleteSurroundingText(Integer.MAX_VALUE, Integer.MAX_VALUE);
                }
                ic.commitText(text, 1);
                result = ic.endBatchEdit();

                if (result && endWithAction && enterShouldHaveAction) {
                    result = ic.performEditorAction(info.imeOptions & EditorInfo.IME_MASK_ACTION);
                }
            }
        }
    }
    return result;
}

From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java

@Override
public void onRelease(int primaryCode) {
    if (oppositeCase) {
        timer.cancel();/* w w  w.j  a  va  2 s.c om*/
        printedDifferent = false;
    }

    if (popupKeypress && (primaryCode == 32 || primaryCode == 126 || primaryCode == -5 || primaryCode == -1
            || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_1
            || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_2
            || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_3
            || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_4
            || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_5)) {

        kv.setPreviewEnabled(true);
    }

    if (printedCommaa) {
        if (autoSpacing) {
            InputConnection ic = getCurrentInputConnection();
            ic.deleteSurroundingText(1, 0);
        }

        if (allCaps) {
            caps = true;
            capsLock = false;
        } else {
            caps = false;
        }

        keyboard.setShifted(caps);
        kv.invalidateAllKeys();

        printedCommaa = false;
    }
}

From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java

@Override
public void onStartInputView(EditorInfo info, boolean restarting) {
    initializeKeyboard();/*from w  w w.  ja  v a 2  s .c o  m*/
    onRotate();

    if (mVoiceRecognitionTrigger != null) {
        mVoiceRecognitionTrigger.onStartInputView();
    }

    vbListenerPause = false;

    if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("random")) {
        Random rand = new Random();

        int randInt = rand.nextInt(25);

        switch (randInt) {
        case 1:
            kv.setBackgroundColor(getResources().getColor(R.color.white));
            break;
        case 2:
            kv.setBackgroundColor(getResources().getColor(R.color.black));
            break;
        case 3:
            kv.setBackgroundColor(getResources().getColor(R.color.purple));
            break;
        case 4:
            kv.setBackgroundColor(getResources().getColor(R.color.red));
            break;
        case 5:
            kv.setBackgroundColor(getResources().getColor(R.color.pink));
            break;
        case 6:
            kv.setBackgroundColor(getResources().getColor(R.color.blue));
            break;
        case 7:
            kv.setBackgroundColor(getResources().getColor(R.color.green));
            break;
        case 8:
            kv.setBackgroundColor(getResources().getColor(R.color.yellow));
            break;
        case 9:
            kv.setBackgroundColor(getResources().getColor(R.color.orange));
            break;
        case 10:
            kv.setBackgroundColor(getResources().getColor(R.color.grey));
            break;
        case 11:
            kv.setBackgroundColor(getResources().getColor(R.color.lightpurple));
            break;
        case 12:
            kv.setBackgroundColor(getResources().getColor(R.color.lightred));
            break;
        case 13:
            kv.setBackgroundColor(getResources().getColor(R.color.lightpink));
            break;
        case 14:
            kv.setBackgroundColor(getResources().getColor(R.color.lightblue));
            break;
        case 15:
            kv.setBackgroundColor(getResources().getColor(R.color.lightgreen));
            break;
        case 16:
            kv.setBackgroundColor(getResources().getColor(R.color.lightyellow));
            break;
        case 17:
            kv.setBackgroundColor(getResources().getColor(R.color.lightgrey));
            break;
        case 18:
            kv.setBackgroundColor(getResources().getColor(R.color.lightorange));
            break;
        case 19:
            kv.setBackgroundColor(getResources().getColor(R.color.darkpurple));
            break;
        case 20:
            kv.setBackgroundColor(getResources().getColor(R.color.darkorange));
            break;
        case 21:
            kv.setBackgroundColor(getResources().getColor(R.color.darkblue));
            break;
        case 22:
            kv.setBackgroundColor(getResources().getColor(R.color.darkgreen));
            break;
        case 23:
            kv.setBackgroundColor(getResources().getColor(R.color.darkred));
            break;
        case 24:
            kv.setBackgroundColor(getResources().getColor(R.color.darkyellow));
            break;
        case 25:
            kv.setBackgroundColor(getResources().getColor(R.color.darkpink));
            break;
        }
    }

    else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_1")) {
        kv.setBackgroundResource(R.drawable.pattern_1);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_2")) {
        kv.setBackgroundResource(R.drawable.pattern_2);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_3")) {
        kv.setBackgroundResource(R.drawable.pattern_3);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_4")) {
        kv.setBackgroundResource(R.drawable.pattern_4);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_5")) {
        kv.setBackgroundResource(R.drawable.pattern_5);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_6")) {
        kv.setBackgroundResource(R.drawable.pattern_6);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_7")) {
        kv.setBackgroundResource(R.drawable.pattern_7);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_8")) {
        kv.setBackgroundResource(R.drawable.pattern_8);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_9")) {
        kv.setBackgroundResource(R.drawable.pattern_9);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_10")) {
        kv.setBackgroundResource(R.drawable.pattern_10);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_11")) {
        kv.setBackgroundResource(R.drawable.pattern_11);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_12")) {
        kv.setBackgroundResource(R.drawable.pattern_12);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_13")) {
        kv.setBackgroundResource(R.drawable.pattern_13);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_14")) {
        kv.setBackgroundResource(R.drawable.pattern_14);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_15")) {
        kv.setBackgroundResource(R.drawable.pattern_15);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_16")) {
        kv.setBackgroundResource(R.drawable.pattern_16);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_17")) {
        kv.setBackgroundResource(R.drawable.pattern_17);

    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_1")) {
        kv.setBackgroundResource(R.drawable.nature_1);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_2")) {
        kv.setBackgroundResource(R.drawable.nature_2);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_3")) {
        kv.setBackgroundResource(R.drawable.nature_3);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_4")) {
        kv.setBackgroundResource(R.drawable.nature_4);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_5")) {
        kv.setBackgroundResource(R.drawable.nature_5);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_6")) {
        kv.setBackgroundResource(R.drawable.nature_6);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_7")) {
        kv.setBackgroundResource(R.drawable.nature_7);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_8")) {
        kv.setBackgroundResource(R.drawable.nature_8);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_9")) {
        kv.setBackgroundResource(R.drawable.nature_9);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_10")) {
        kv.setBackgroundResource(R.drawable.nature_10);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_11")) {
        kv.setBackgroundResource(R.drawable.nature_11);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_12")) {
        kv.setBackgroundResource(R.drawable.nature_12);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_13")) {
        kv.setBackgroundResource(R.drawable.nature_13);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_14")) {
        kv.setBackgroundResource(R.drawable.nature_14);

    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("black")) {
        kv.setBackgroundColor(getResources().getColor(R.color.black));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("white")) {
        kv.setBackgroundColor(getResources().getColor(R.color.white));

    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("transparent")) {
        kv.setBackgroundColor(getResources().getColor(R.color.transparent));

    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_1")) {
        kv.setBackgroundResource(R.drawable.gradient_1);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_2")) {
        kv.setBackgroundResource(R.drawable.gradient_2);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_3")) {
        kv.setBackgroundResource(R.drawable.gradient_3);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_4")) {
        kv.setBackgroundResource(R.drawable.gradient_4);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_5")) {
        kv.setBackgroundResource(R.drawable.gradient_5);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_6")) {
        kv.setBackgroundResource(R.drawable.gradient_6);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_7")) {
        kv.setBackgroundResource(R.drawable.gradient_7);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_8")) {
        kv.setBackgroundResource(R.drawable.gradient_8);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_9")) {
        kv.setBackgroundResource(R.drawable.gradient_9);
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_10")) {
        kv.setBackgroundResource(R.drawable.gradient_10);

    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("red")) {
        kv.setBackgroundColor(getResources().getColor(R.color.red));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pink")) {
        kv.setBackgroundColor(getResources().getColor(R.color.pink));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("purple")) {
        kv.setBackgroundColor(getResources().getColor(R.color.purple));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("blue")) {
        kv.setBackgroundColor(getResources().getColor(R.color.blue));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("green")) {
        kv.setBackgroundColor(getResources().getColor(R.color.green));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("yellow")) {
        kv.setBackgroundColor(getResources().getColor(R.color.yellow));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("orange")) {
        kv.setBackgroundColor(getResources().getColor(R.color.orange));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("grey")) {
        kv.setBackgroundColor(getResources().getColor(R.color.grey));

    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightred")) {
        kv.setBackgroundColor(getResources().getColor(R.color.lightred));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightpink")) {
        kv.setBackgroundColor(getResources().getColor(R.color.lightpink));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightpurple")) {
        kv.setBackgroundColor(getResources().getColor(R.color.lightpurple));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightblue")) {
        kv.setBackgroundColor(getResources().getColor(R.color.lightblue));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightgreen")) {
        kv.setBackgroundColor(getResources().getColor(R.color.lightgreen));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightyellow")) {
        kv.setBackgroundColor(getResources().getColor(R.color.lightyellow));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightorange")) {
        kv.setBackgroundColor(getResources().getColor(R.color.lightorange));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightgrey")) {
        kv.setBackgroundColor(getResources().getColor(R.color.lightgrey));

    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkred")) {
        kv.setBackgroundColor(getResources().getColor(R.color.darkred));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkpink")) {
        kv.setBackgroundColor(getResources().getColor(R.color.darkpink));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkpurple")) {
        kv.setBackgroundColor(getResources().getColor(R.color.darkpurple));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkblue")) {
        kv.setBackgroundColor(getResources().getColor(R.color.darkblue));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkgreen")) {
        kv.setBackgroundColor(getResources().getColor(R.color.darkgreen));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkyellow")) {
        kv.setBackgroundColor(getResources().getColor(R.color.darkyellow));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkorange")) {
        kv.setBackgroundColor(getResources().getColor(R.color.darkorange));
    } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkgrey")) {
        kv.setBackgroundColor(getResources().getColor(R.color.darkgrey));
    } else {
        String uploadString = Preferences.getDefaults("bgcolor", getApplicationContext());

        byte[] decodedString = Base64.decode(uploadString, Base64.URL_SAFE);
        Bitmap photo = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
        BitmapDrawable bdrawable = new BitmapDrawable(getApplication().getResources(), photo);
        kv.setBackgroundDrawable(bdrawable);
    }

    if (Preferences.getDefaults("autocapitalize", getApplicationContext()).equals("true")) {
        autoCapitalize = true;
    } else if (Preferences.getDefaults("autocapitalize", getApplicationContext()).equals("false")) {
        autoCapitalize = false;
    }

    if (Preferences.getDefaults("volumebuttons", getApplicationContext()).equals("true")) {
        volumeButtons = true;
    } else if (Preferences.getDefaults("volumebuttons", getApplicationContext()).equals("false")) {
        volumeButtons = false;
    }

    if (Preferences.getDefaults("allcaps", getApplicationContext()).equals("true")) {
        allCaps = true;
    } else if (Preferences.getDefaults("allcaps", getApplicationContext()).equals("false")) {
        allCaps = false;
    }

    if (Preferences.getDefaults("autospacing", getApplicationContext()).equals("true")) {
        autoSpacing = true;
    } else if (Preferences.getDefaults("autospacing", getApplicationContext()).equals("false")) {
        autoSpacing = false;
    }

    if (Preferences.getDefaults("changekeyboard", getApplicationContext()).equals("true")) {
        changeKeyboard = true;
    } else if (Preferences.getDefaults("changekeyboard", getApplicationContext()).equals("false")) {
        changeKeyboard = false;
    }

    if (Preferences.getDefaults("shakedelete", getApplicationContext()).equals("true")) {
        shakeDelete = true;
    } else if (Preferences.getDefaults("shakedelete", getApplicationContext()).equals("false")) {
        shakeDelete = false;
    }

    if (Preferences.getDefaults("doublespace", getApplicationContext()).equals("true")) {
        spaceDot = true;
    } else if (Preferences.getDefaults("doublespace", getApplicationContext()).equals("false")) {
        spaceDot = false;
    }

    if (Preferences.getDefaults("voiceinput", getApplicationContext()).equals("true")) {
        voiceInput = true;
    } else if (Preferences.getDefaults("voiceinout", getApplicationContext()).equals("false")) {
        voiceInput = false;
    }

    if (Preferences.getDefaults("popup", getApplicationContext()).equals("true")) {
        popupKeypress = true;
    } else if (Preferences.getDefaults("popup", getApplicationContext()).equals("false")) {
        popupKeypress = false;
    }

    if (Preferences.getDefaults("oppositecase", getApplicationContext()).equals("true")) {
        oppositeCase = true;
    } else if (Preferences.getDefaults("oppositecase", getApplicationContext()).equals("false")) {
        oppositeCase = false;
    }

    if (changeKeyboard) {
        MovementDetector.getInstance(getApplicationContext()).start();

        MovementDetector.getInstance(getApplicationContext()).addListener(new MovementDetector.Listener() {

            @Override
            public void onMotionDetected(SensorEvent event, float acceleration) {
                if (MovementDetector.direction[1].equals("LEFT")) {
                    playSwipeH();
                    onSwipeLeft();
                } else if (MovementDetector.direction[1].equals("RIGHT")) {
                    playSwipeH();
                    onSwipeRight();
                }

                if (MovementDetector.direction[0].equals("UP")) {
                    playSwipeV();
                    onSwipeUp();
                } else if (MovementDetector.direction[0].equals("DOWN")) {
                    playSwipeV();
                    onSwipeDown();
                }
            }
        });
    }

    keypresscounter1 = Preferences.getDefaults("keypresscounter1", getApplicationContext());
    keypresscounter2 = Preferences.getDefaults("keypresscounter2", getApplicationContext());
    keypresscounter3 = Preferences.getDefaults("keypresscounter3", getApplicationContext());

    keyPressCounter = Integer.parseInt(Preferences.getDefaults("keypresses", getApplicationContext()));

    time1 = Preferences.getDefaults("time1", getApplicationContext());
    time2 = Preferences.getDefaults("time2", getApplicationContext());
    time3 = Preferences.getDefaults("time3", getApplicationContext());

    time = Integer.parseInt(Preferences.getDefaults("time", getApplicationContext()));

    tTime = new CountDownTimer(60000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            time = time + 1;

            if (time > 300 && time <= 960 && time1.equals("false")) {
                NotificationManager notif = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard",
                        System.currentTimeMillis());
                PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0,
                        new Intent(getApplicationContext(), Home.class), 0);

                notify.setLatestEventInfo(getApplicationContext(), "Warming up!", "Type more than 360 seconds",
                        pending);
                notif.notify(0, notify);

                Preferences.setDefaults("time1", "true", getApplicationContext());
            } else if (time > 960 && time <= 3600 && time2.equals("false")) {
                NotificationManager notif = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard",
                        System.currentTimeMillis());
                PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0,
                        new Intent(getApplicationContext(), Home.class), 0);

                notify.setLatestEventInfo(getApplicationContext(), "Keep it up!", "Type more than 960 seconds",
                        pending);
                notif.notify(0, notify);

                Preferences.setDefaults("time2", "true", getApplicationContext());
            } else if (time > 3600 && time3.equals("false")) {
                NotificationManager notif = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard",
                        System.currentTimeMillis());
                PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0,
                        new Intent(getApplicationContext(), Home.class), 0);

                notify.setLatestEventInfo(getApplicationContext(), "Typing master!",
                        "Type more than 3600 seconds", pending);
                notif.notify(0, notify);

                Preferences.setDefaults("time3", "true", getApplicationContext());
            }

            Preferences.setDefaults("time", String.valueOf(time), getApplicationContext());
        }

        @Override
        public void onFinish() {
            tTime.start();
        }
    }.start();

    if (popupKeypress) {
        kv.setPreviewEnabled(true);
    } else {
        kv.setPreviewEnabled(false);
    }

    if (shakeDelete) {
        mShaker = new ShakeListener(this);
        mShaker.setOnShakeListener(new ShakeListener.OnShakeListener() {
            public void onShake() {
                InputConnection ic = getCurrentInputConnection();
                ic.deleteSurroundingText(500, 500);
            }
        });
    }

    super.onStartInputView(info, restarting);
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

public void revertLastWord() {
    final int length = mCommittedWord.length() + (mJustAddedAutoSpace ? 1 : 0);
    if (length > 0) {
        mAutoCorrectOn = false;//from  w  ww. j  a v a 2  s  . co m
        //note: typedWord may be empty
        final InputConnection ic = getCurrentInputConnection();
        mUndoCommitCursorPosition = UNDO_COMMIT_NONE;
        ic.beginBatchEdit();
        ic.deleteSurroundingText(length, 0);
        final CharSequence typedWord = mWord.getTypedWord();
        ic.setComposingText(typedWord/* mComposing */, 1);
        TextEntryState.backspace();
        ic.endBatchEdit();
        performUpdateSuggestions();
        if (mJustAutoAddedWord) {
            removeFromUserDictionary(typedWord.toString());
        }
        getInputView().revertPopTextOutOfKey();
    } else {
        sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
    }
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

private void removeTrailingSpace() {
    final InputConnection ic = getCurrentInputConnection();
    if (ic == null)
        return;/* ww w  . j a  v  a 2  s . c  o  m*/

    CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
    if (lastOne != null && lastOne.length() == 1 && lastOne.charAt(0) == KeyCodes.SPACE) {
        ic.deleteSurroundingText(1, 0);
    }
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

public void deleteLastCharactersFromInput(int countToDelete) {
    if (countToDelete == 0)
        return;//from  w ww  .  ja v a 2s . c  om

    final int currentLength = mWord.length();
    boolean shouldDeleteUsingCompletion;
    if (currentLength > 0) {
        shouldDeleteUsingCompletion = true;
        if (currentLength > countToDelete) {
            int deletesLeft = countToDelete;
            while (deletesLeft > 0) {
                mWord.deleteLast();
                deletesLeft--;
            }
        } else {
            mWord.reset();
        }
    } else {
        shouldDeleteUsingCompletion = false;
    }
    InputConnection ic = getCurrentInputConnection();
    if (ic != null) {
        if (mPredictionOn && shouldDeleteUsingCompletion) {
            ic.setComposingText(mWord.getTypedWord()/* mComposing */, 1);
        } else {
            ic.deleteSurroundingText(countToDelete, 0);
        }
    }
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

public void revertLastWord(boolean deleteChar) {
    final int length = mComposing.length();
    if (!mPredicting && length > 0) {
        final InputConnection ic = getCurrentInputConnection();
        mPredicting = true;//from   ww w .  j av  a  2 s  . c o  m
        mJustRevertedSeparator = ic.getTextBeforeCursor(1, 0);
        if (deleteChar)
            ic.deleteSurroundingText(1, 0);
        int toDelete = mCommittedLength;
        CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
        if (toTheLeft != null && toTheLeft.length() > 0 && isWordSeparator(toTheLeft.charAt(0))) {
            toDelete--;
        }
        ic.deleteSurroundingText(toDelete, 0);
        ic.setComposingText(mComposing, 1);
        TextEntryState.backspace();
        postUpdateSuggestions();
    } else {
        sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
        mJustRevertedSeparator = null;
    }
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

private void removeTrailingSpace() {
    final InputConnection ic = getCurrentInputConnection();
    if (ic == null)
        return;/*from   ww w . j  a  va 2 s  .  co  m*/

    CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
    if (lastOne != null && lastOne.length() == 1 && lastOne.charAt(0) == ASCII_SPACE) {
        ic.deleteSurroundingText(1, 0);
    }
}