Development issue/problem:

I followed the examples on developer.android.com about input methods and played with the example SoftKeyboard application. Together they provide more than enough information to create a simple keyboard.

What I don’t see in the API is the possibility to create alternative/multiple characters for each available key on the standard keyboard (LatinIME Keyboard).

The image above is the result of a long press on the button. If you press and hold the key, you can fill the popup window with alternative characters.

You can also give some keys a tooltip that asks the user to press and hold a key to get a pop-up menu.

So far I haven’t found a source of information on how this happens, I hope someone can give me a head start and in the meantime I will follow the source code of the embedded keyboard and see if I can reverse-engineer it.

Edit: It would be useful if the developer.android.com link to LatinIME Keyboard did not contain a link to a sheep image with the LatinIME.java source code.

Editor in Chief 2 : More than anything else, this is the sequence that I think is a common LongPress action to display a popup keyboard in KeyboardView.java:

onTouchEvent()
onModifiedTouchEvent()
mHandkler.handleMessage() with MSG_LONGPRESS
openPopupIfRequired()
onLongPress()

Editor in Chief 3 :

I still haven’t figured out how to add the suggested labels to the buttons. The answer says it’s not embedded in the API, and I haven’t found any code that does. However, the keyboard in version 2.3.4 (API 10) shows that this functionality has been implemented:

I would like to understand how this happens in the computer world, but you don’t see it anywhere in the onDraw() method – which leads me to believe that it is written outside the KeyboardView element. However, I can’t find the presentation file used to display the KeyboardView item on the built-in keyboard – if someone knows where to find it, it might give me the hint I need.

Edition 4 : The key question in the overview has been moved here because it is a bit off topic:

How do I deactivate the preview window of the SoftKeyboard keyboard?

How can I solve this problem?

Solution 1:

Introducing an alternative pop-up window with a :

PopupCharacters and PopupKeyboard must be defined for each key that must have a popup keyboard:

/res/xml/[keyboard].xml

PopupKeyboard is an XML representation of the keyboard used in popup and contains alternative keys:

/res/xml/keyboard_popup_template.xml

Alternating the style of the pop-up buttons :

If you want to change the layout/style of the popup (default @android:layout/ keyboard_popup_keyboard.xml), you can specify the android:popupLayout attribute that points to the layout file:

Implementation of the Key Preview :

The only solution I could come up with to show a preview of the keys (without completely rewriting the KeyboardView source code) is the following:

Wrap a label with a certain height by multiplying the key height by the number of lines. In this tag I simply created a LinearLayout to store the lines, then a LinearLayout for each line containing a TextView with a weight equal to the %p value specified for each line:

And class:

Which brings us to the following:

Give here a description of the image

I won’t be satisfied until I can implement it together with the system keyboard!

Solution 2:

After my own attempt to program a programmable keyboard, I realized:

  • Nice/Bling functions usually require an extension of KeyboardView and even the writing of a large part of the character code. Unfortunately, you can’t do this by bypassing some important methods, because almost everything is private. You can look at it (and borrow a code) :
    • (base)/core/java/android/input methodology service/KeyboardView.java (android core code repo)
    • (apps)/othere/LatinIME/LatinKeyboardView.java (Android core apps repo)

Note that the sheep on android.kernel.org tells you that the repo is closed because of hacks, but that there are code mirrors elsewhere (unfortunately the links have been lost).

  • The basic keyboard view does not support dummy key labels, you need to encode your keyboard view to replace the onDraw() method.

Let’s see what you can do:

  • You can circumvent this problem by providing images for the keys: Use the xml. Unfortunately, you will probably get bad results for e-mail with this method (resolution problems).
  • You can use (and customize the appearance of) the pop-up keyboard that appears when you type for a long time.

Explain the keyboard template res/xml/kbd_popup_template.xml :

Specify the values of the strings that contain the keys you want to have on this keyboard res/values/strings.xml :

àáââäåæ

Then use both when defining the keyboard layout:

  • You can also double, triple and triple tap… function to create variables for the key pressed. To do this, just use the Android key code list :

 

gives 97=’a’ for a single tap, 224=’à’ for a double tap and 230=’æ’ for a triple tap.

The time to take into account double-tapping is set to 800 ms in the Android source code. Unfortunately this value is hard coded (and in my opinion a bit too high).

Note that in the case of double printing, the letter a is always sent first and then the letter a in the second printing. Some requests will not be granted.

Solution 3:

The pop-up keyboard with the close-key is annoying if we only have one pop-up character.
An easier way is to override the onLongPress method of the KeyboardView class as follows.

Above definition
secure boolean onLongPress(Key key) {
if (key.codes[0] == ‘1’) {
getOnKeyboardActionListener().onKey(‘!’, null);
returns where;
}
}.

Solution 4:

If you want text above the test, you can do this in your class’s onDraw() method, which replaces KeyboardView.

@Override
public blank onDraw(Canvas) {
super.onDraw(Canvas);

Paint paint = new Paint();paint.setTextAlign(Paint.Align.CENTER);paint.setTextSize(18);paint.setColor(Color.WHITE);//Received all keys and draw them as you wantList keys = getKeyboard().getKeys();for(Keyboard.Key key : keys) {if(key.label != null) {

if (key.label.toString().equals(q) || key.label.toString().equals(Q))
canvas.drawText(String.valueOf(1), key.x + (key.width / 2) + 10, key.y + 25, paint) ;

Otherwise if (key.label.toString().equals(w) || key.label.toString().equals(W))
canvas.drawText(String.valueOf(2), key.x + (key.width / 2) + 10, key.y + 25, paint) ;

Otherwise if (key.label.toString().equals(e) || key.label.toString().equals(E))
canvas.drawText(String.valueOf(3), key.x + (key.width / 2) + 10, key.y + 25, paint) ;

Otherwise if (key.label.toString().equals(r) || key.label.toString().equals(R))
canvas.drawText(String.valueOf(4), key.x + (key.width / 2) + 10, key.y + 25, paint) ;

Otherwise if (key.label.toString().equals(t) || key.label.toString().equals(T))
canvas.drawText(String.valueOf(5), key.x + (key.width / 2) + 10, key.y + 25, paint) ;

Otherwise if (key.label.toString().equals(y) || key.label.toString().equals(Y))
canvas.drawText(String.valueOf(6), key.x + (key.width / 2) + 10, key.y + 25, paint) ;

otherwise if (key.label.toString().equals(u) || key.label.toString().equals(U))
canvas.drawText(String.valueOf(7), key.x + (key.width / 2) + 10, key.y + 25, paint) ;

Otherwise if (key.label.toString().equals(i) || key.label.toString().equals(I))
canvas.drawText(String.valueOf(8), key.x + (key.width / 2) + 10, key.y + 25, paint) ;

Otherwise if (key.label.toString().equals(o) || key.label.toString().equals(o))
canvas.drawText(String.valueOf(9), key.x + (key.width / 2) + 10, key.y + 25, paint) ;

Otherwise if (key.label.toString().equals(p) || key.label.toString().equals(P))
canvas.drawText(String.valueOf(0), key.x + (key.width / 2) + 10, key.y + 25, paint) ;

otherwise
{}
}
}
}

Solution No 5:

For those who are trying to shut down the popup keyboard by clicking outside their viewing window, I had the chance to put a TouchListener on the KeyboardView in a class that extends the InputMethodService.

Your publicIME class extends InputMethodService{
@Override
public View onCreateInputView() {
mInputView = (LatinKeyboardView) getLayoutInflater().inflate(R.layout.input, null);
setLatinKeyboard(mQwertyKeyboard) ;

mInputView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent)) {

if(motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
mInputView.close(); // Close the pop-up keyboard when it is displayed
}
return false;
}
}) ;

reverse mInputView;
}
// The rest of the name
}

Solution No 6:

If you want text above the test, you can do that in the onDraw() method of your class that expands KeyboardView I’ve done something like this, maybe it can help someone

Give here a description of the image

@Override
public blank onDraw(Canvas) {
super.onDraw(Canvas) ;
Log.d(LatinKeyboardView, onDraw) ;

Paint paint = new paint();
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(30);
paint.setColor(Color.LTGRAY) ;

Key list = getKeyboard().getKeys();
for (Key: keys) {
if (key.label != invalid) {
switch (key.codes[0]) {

//qQQ
suitcase 81 :
suitcase 113 :
suitcase 1602 :
suitcase 1618 :
canvas.drawText (String.valueOf(1), key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
break;
//wW
case 87 :
case 119 :
case 1608 :
case 1572 :
canvas.drawText(String.valueOf(2), key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
break ;

//eE
suitcase 69 :
suitcase 101 :
suitcase 1593 :
suitcase 1617 :
canvas.drawText (String.valueOf(3), key.x + (key.width – keyXAxis), key.y + keyYAxis, paint) ;
break ;

//rRR
suitcase 82:
suitcase 114:
suitcase 1585:
suitcase 1681:
canvas.drawText (String.valueOf(4), key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
break;
//tT
suitcase 84:
suitcase 116:
suitcase 1578:
suitcase 1657:
canvas.drawText (string.valueOf(5), key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
break;
//yY
case 89 :
case 121 :
case 1746 :
case 1552 :
canvas.drawText(string.valueOf(6), key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
break;
//uU
case 85 :
case 117 :
case 1569 :
case 1574 :
canvas.drawText(string.valueOf(7), key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
pause;
//iI
case 73: cover
105: cover
1740:
case 1648:
canvas.drawText(String.valueOf(8), key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
break;
//oO
case 79 :
case 111 :
case 1729 :
case 1731 :
canvas.drawText(String.valueOf(9), key.x + (key.width – keyXAxis), key.y + keyYAxis, paint) ;
break ;

//pPP
suitcase 80 :
suitcase 112 :
suitcase 1662 :
suitcase 1615 :
canvas.drawText (String.valueOf(0), key.x + (key.width – keyXAxis), key.y + keyYAxis, paint) ;
break ;

//aA
suitcase 65 :
suitcase 97 :
suitcase 1575 :
suitcase 1570 :
canvas.drawText(@, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint) ;
pause ;

//sSS
suitcase 83 :
suitcase 115 :
suitcase 1587 :
suitcase 1589 :
canvas.drawText(#, key.x + (key.width – keyXAxis), key.y + asY key, paint);
break;
//dD
suitcase 68 :
suitcase 100 :
suitcase 1583 :
suitcase 1672 :
canvas.drawText($, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
break ;

//fF
suitcase 70 :
suitcase 102 :
suitcase 1601 :
suitcase 1613 :
canvas.drawText (%, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint) ;
break ;

//gG
suitcase 71:
suitcase 103:
suitcase 1711:
suitcase 1594:
canvas.drawText (&, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
break;
//h9
suitcase 72:
suitcase 104:
suitcase 1726:
suitcase 1581:
canvas.drawText(-, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint) ;
break ;
//dd
suitcase 74 :
suitcase 106 :
suitcase 1580 :
suitcase 1590 :
canvas.drawText(+, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint) ;
break ;

//kKKK
Case 75 : Case
107 : 1. Housing
1705 : Case
1582:
canvas.drawText(, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
pause ;

//lL
suitcase 76: suitcase
108: suitcase
1604:
suitcase 1614:
canvas.drawText(), key.x + (key.width – keyXAxis), key.y + asY key, paint);
pause;
//zZ
suitcase 90 :
suitcase 122 :
suitcase 1586 :
suitcase 1584 :
canvas.drawText(*, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
pause ;

//xX
suitcase 88 :
suitcase 120 :
suitcase 1588 :
suitcase 1679 :
canvas.drawText(, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint) ;
break ;

//cC
suitcase 67 : suitcase
99 :
suitcase 1670 :
suitcase 1579 :
canvas.drawText(‘, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint) ;
break ;

//vV
suitcase 86 :
suitcase 118 :
suitcase 1591 :
suitcase 1592 :
canvas.drawText( :, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint) ;
break ;

//bB
suitcase 66 :
suitcase 98 :
suitcase 1576 :
suitcase 1616 :
canvas.drawText( ;, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint) ;
break ;

//nN
suitcase 78 :
suitcase 110 :
suitcase 1606 :
suitcase 1722 :
canvas.drawText(!, key.x + (key.width – keyXAxis), key.y + keyY-axis, paint);
break;
//mM
suitcase 77 :
suitcase 109 :
suitcase 1605 :
suitcase 1611 :
canvas.drawText(?, key.x + (key.width – keyXAxis), key.y + keyYAxis, paint);
break ;

}

}

}
}

to fix these axes according to your choice

int keyXAxis = 25 ;
int keyYAxis = 50 ;

Solution No 7:

That’s what I did based on the answers given here:

The public class MyKeyboardView extends KeyboardView {
private Key.Key longPressedKey = null ;

public MyKeyboardView(Context, AttributeSet attrs) {
super(context, attrs);
}

public MyKeyboardView(Context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
public blank onDraw(Canvas) {
super.onDraw(Canvas canvas) ;

Paint paint = new paint();
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(35);
paint.setColor(Color.BLACK);
//Get get all the keys and draw what you want
List keys = getKeyboard().getKeys();
for (Keyboard.key : keys) {
as (key.popupCharacters != null && key.popupCharacters.length() > 0) {
canvas.drawText(key.popupCharacters.toString(), key.x + (key.width / 2) + 10, key.y + 30, paint);
}
}
}.

@Bull definition
secure boolean onLongPress(Keyboard.key) {
as (key.popupCharacters != null && key.popupCharacters.length() > 0)
longPressedKey = key;
returns super.onLongPress(key);
}.

General Boolean control
onTouchEvent(event MotionEvent) {
super.onTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_UP) {
if (longPressedKey != null) {
// TODO : Try to determine which key is highest when popupCharacters
getOnKeyboardActionListener().onKey((longPressedKey.popupCharacters.charAt(0)), null);
dismissalPopupKeyboard();
longPressedKey=zero;
}
}
gives true; // Required to get the following events (ACTION_MOVE, ACTION_UP)
}.

private void dismissPopupKeyboard() {
// Since KeyboardView.dismissPopupKeyboard() is private, we do this trick (KeyboardView.click() calls dismissPopupKeyboard()).
// TODO : Do it like a normal person. We have to make the popup ourselves, just like the keyboard.
onClick(new view(getContext());
}

и

If you are using KeyboardView, change it to MyKeyboardView, with this additional parameter – android:[email protected]/keyboard_popup_keyboard

And it is keyboard_popup_keyboard.xml (important that there is no undone button).

Good luck!

You May Also Like

Black Screen Issues in Windows 10 [Simple Guide]

Perhaps the biggest problem is the black screen error message that occurs…

Apple releases iOS 14.4 and iPadOS 14.4 to the Public

Beta testers received iOS 14.4 RC and iPadOS 14.4 RC last week.…

How to play Snowsted Royale Arcade Multiplayer 2D Shooter on PC (Windows/Mac)

Snowsted Royale is an action-adventure game in which we will participate in…

ASUS TUF Dash F15 (2021) Specs: Full Specifications

ASUS TUF Dash F15 (Intel 11th generation H series) specifications The ASUS…