Android Keyboard - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Keyboard class.

This code example shows how to use the following methods:getKeys
        if (keyboard == null)
            throw new NullPointerException();
        mCorrectionX = (int)correctionX;
        mCorrectionY = (int)correctionY;
        mKeyboard = keyboard;
        List<Key> keys = mKeyboard.getKeys();
        Key[] array = keys.toArray(new Key[keys.size()]);
        mKeys = array;
        return array;
    } 
 
    protected int getTouchX(int x) {
        return x + mCorrectionX;
    } 
 
    protected int getTouchY(int y) {
        return y + mCorrectionY;
    } 
 
    protected Key[] getKeys() {
5
CodeRank
This code example shows how to use the following methods:getHeight, getMinWidth
 
    @Override 
    public void setKeyboard(Keyboard k) {
        super.setKeyboard(k);
        // One-seventh of the keyboard width seems like a reasonable threshold 
        mJumpThresholdSquare = k.getMinWidth() / 7;
        mJumpThresholdSquare *= mJumpThresholdSquare;
        // Assuming there are 4 rows, this is the coordinate of the last row 
        mLastRowY = (k.getHeight() * 3) / 4;
        setKeyboardLocal(k);
    } 
 
    @Override 
    protected boolean onLongPress(Key key) {
        if (key.codes[0] == Keyboard.KEYCODE_MODE_CHANGE) {
            getOnKeyboardActionListener().onKey(KEYCODE_OPTIONS, null);
            return true; 
        } else if (key.codes[0] == Keyboard.KEYCODE_SHIFT) {
            getOnKeyboardActionListener().onKey(KEYCODE_SHIFT_LONGPRESS, null);
            invalidateAllKeys();
4
CodeRank
This code example shows how to use the following methods:
	}; 
	 
	public MyKeyboard(Activity host, int viewId, int layoutId){
		mHostActivity = host;
		mKeyboardView = (KeyboardView) mHostActivity.findViewById(viewId);
		mKeyboardView.setKeyboard(new Keyboard(mHostActivity, layoutId));
		mKeyboardView.setPreviewEnabled(false); // NOTE Do not show the preview
												// balloons 
		mKeyboardView.setOnKeyboardActionListener(mOnKeyboardActionListener);
		// Hide the standard keyboard initially 
		mHostActivity.getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);	
	} 
 
	/** Returns whether the CustomKeyboard is visible. */ 
	public boolean isCustomKeyboardVisible() { 
		return mKeyboardView.getVisibility() == View.VISIBLE;
	} 
	 
	/** 
4
CodeRank
This code example shows how to use the following methods:setShifted
     * @return true if the shift key state changed, false if there was no change 
     * @see KeyboardView#isShifted() 
     */ 
    public boolean setShifted(boolean shifted) {
        if (mKeyboard != null) {
            if (mKeyboard.setShifted(shifted)) {
                // The whole keyboard probably needs to be redrawn 
                invalidateAllKeys(); 
                return true; 
            } 
        } 
        return false; 
    } 
 
    /** 
     * Returns the state of the shift key of the keyboard, if any. 
     * @return true if the shift is in a pressed state, false otherwise. If there is 
     * no shift key on the keyboard or there is no keyboard attached, it returns false. 
     * @see KeyboardView#setShifted(boolean) 
     */ 
2
CodeRank
This code example shows how to use the following methods:
	private Keyboard mKeyboard;
 
	public MyKeyboard(Activity host, int viewid, int layoutid) {
		this.mHostActivity = host;
		mKeyboardView= (KeyboardView)mHostActivity.findViewById(viewid);
        mKeyboardView.setKeyboard(new Keyboard(mHostActivity, layoutid));
        mKeyboard = mKeyboardView.getKeyboard();
        mKeyboardView.setPreviewEnabled(false); // NOTE Do not show the preview balloons
        mKeyboardView.setOnKeyboardActionListener(this);
        // Hide the standard keyboard initially 
        mHostActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
	} 
	 
 
 
	@Override 
	public void onKey(int primaryCode, int[] arg1) {
		View focusCurrent = mHostActivity.getWindow().getCurrentFocus();
	    if( focusCurrent==null || focusCurrent.getClass()!=MyEditText.class ) return;
	    MyEditText edittext = (MyEditText) focusCurrent;
4
CodeRank
This code example shows how to use the following methods:setShifted
				current = mSymbolsKeyboard;
			} 
			mInputView.setKeyboard(current);
			if (current == mSymbolsKeyboard) {
				// shouldn't this check the input connection state? 
				current.setShifted(false);
			} 
		} 
		return; 
// Original: 
/* 
		if (isWordSeparator(primaryCode)) { 
			// Handle separator 
			if (mComposing.length() > 0) { 
				commitTyped(); 
			} 
			sendKey(primaryCode); 
			updateShiftKeyState(getCurrentInputEditorInfo()); 
		} else if (primaryCode == Keyboard.KEYCODE_DELETE) { 
			handleBackspace(); 
3
CodeRank
This code example shows how to use the following methods:setShifted
 
 
 
	public boolean setShifted(boolean shifted) {
    	if (this.keyboard != null) {
            if (this.keyboard.setShifted(shifted)) {
                // The whole keyboard probably needs to be redrawn 
                invalidateAllKeys(); 
                return true; 
            } 
            invalidateAllKeys(); 
        } 
        return false; 
	} 
 
	public boolean isShifted() { 
		 
    	if (this.keyboard != null) {
            return this.keyboard.isShifted();
        } 
2
CodeRank
This code example shows how to use the following methods:setShifted
 
 
 
	public boolean setShifted(boolean shifted) {
    	if (this.keyboard != null) {
            if (this.keyboard.setShifted(shifted)) {
                //redraw keyboard 
                invalidateAllKeys(); 
                return true; 
            } 
            invalidateAllKeys(); 
        } 
        return false; 
	} 
 
	public boolean isShifted() { 
		 
    	if (this.keyboard != null) {
            return this.keyboard.isShifted();
        } 
2
CodeRank
This code example shows how to use the following methods:setShifted
            } else { 
                current = mSymbolsKeyboard;
            } 
            mInputView.setKeyboard(current);
            if (current == mSymbolsKeyboard) {
                current.setShifted(false);
            } 
        } else { 
            handleCharacter(primaryCode, keyCodes);
        } 
    } 
 
    public void onText(CharSequence text) {
        InputConnection ic = getCurrentInputConnection();
        if (ic == null)
            return; 
        ic.beginBatchEdit();
        if (mComposing.length() > 0) {
            commitTyped(ic);
        } 
3
CodeRank
This code example shows how to use the following methods:setShifted
            } else { 
                current = mSymbolsKeyboard;
            } 
            mKeyboardView.setKeyboard(current);
            if (current == mSymbolsKeyboard) {
                current.setShifted(false);
            } 
        } else { 
            handleCharacter(primaryCode, keyCodes);
        } 
    } 
     
    public void onText(CharSequence text) {
        InputConnection ic = getCurrentInputConnection();
        if (ic == null) return;
        ic.beginBatchEdit();
        if (mComposing.length() > 0) {
            commitTyped(ic);
        } 
        ic.commitText(text, 0);
3
CodeRank

Related Android Keyboard Questions & Answers:

See Code Examples for Android Keyboard Methods: