I'm working on a keyboard ( keyboard ) in Android Studio , but I've been stuck on how to place the superscripts to the keys ( see red circles in the image ), on the keyboard of the example image, on the Q place a 1, on the W a 2, also on the ',' place the microphone icon and over the point '.' place three characters ',!?' ( see image at the end ) How do I add those superscripts?
Are they added in the XML or are they added in Run Time in Java?
The XML code I have is the following.
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="0px"
android:keyHeight="60dp"
android:keyWidth="10%p"
android:verticalGap="0px">
<Row>
<Key
android:codes="49"
android:keyEdgeFlags="left"
android:keyLabel="1" />
<Key
android:codes="50"
android:keyLabel="2" />
<Key
android:codes="51"
android:keyLabel="3" />
<Key
android:codes="52"
android:keyLabel="4" />
<Key
android:codes="53"
android:keyLabel="5" />
<Key
android:codes="54"
android:keyLabel="6" />
<Key
android:codes="55"
android:keyLabel="7" />
<Key
android:codes="56"
android:keyLabel="8" />
<Key
android:codes="57"
android:keyLabel="9" />
<Key
android:codes="48"
android:keyEdgeFlags="right"
android:keyLabel="0" />
</Row>
<!--- Fila: 1 2 3 4 5 6 7 8 9 0 -->
<Row>
<Key android:keyLabel="q" android:codes="113" android:keyEdgeFlags="left" />
<Key android:keyLabel="w" android:codes="119" />
<Key android:keyLabel="e" android:codes="101" />
<Key android:keyLabel="r" android:codes="114" />
<Key android:keyLabel="t" android:codes="116" />
<Key android:keyLabel="y" android:codes="121" />
<Key android:keyLabel="u" android:codes="117" />
<Key android:keyLabel="i" android:codes="105" />
<Key android:keyLabel="o" android:codes="111" />
<Key android:keyLabel="p" android:codes="112" android:keyEdgeFlags="right" />
</Row> <!--- Fila q w e r t y u i o p -->
<Row>
<Key android:keyLabel="a" android:codes="97" android:keyEdgeFlags="left" />
<Key android:keyLabel="s" android:codes="115" />
<Key android:keyLabel="d" android:codes="100" />
<Key android:keyLabel="f" android:codes="102" />
<Key android:keyLabel="g" android:codes="103" />
<Key android:keyLabel="h" android:codes="104" />
<Key android:keyLabel="j" android:codes="106" />
<Key android:keyLabel="k" android:codes="107" />
<Key android:keyLabel="l" android:codes="108" />
<Key android:keyLabel="ñ" android:codes="164" />
<Key android:keyLabel="\# \@" android:codes="35,64" android:keyEdgeFlags="right" />
</Row> <!--- Fila a s d f g h j k l ñ #@-->
<Row>
<Key android:keyLabel="CAPS" android:codes="-1" android:keyEdgeFlags="left" />
<Key android:keyLabel="" android:codes="-1" android:iconPreview="@mipmap/ic_keyboard_capslock_black_24dp" android:keyIcon="@mipmap/ic_keyboard_capslock_black_24dp" />
<Key android:keyLabel="z" android:codes="122"/>
<Key android:keyLabel="x" android:codes="120"/>
<Key android:keyLabel="c" android:codes="99"/>
<Key android:keyLabel="v" android:codes="118"/>
<Key android:keyLabel="b" android:codes="98"/>
<Key android:keyLabel="n" android:codes="110"/>
<Key android:keyLabel="m" android:codes="109"/>
<Key android:keyLabel="," android:codes="46"/>
<Key android:keyLabel="." android:codes="108"/>
<Key android:keyLabel="\? ! :" android:codes="63,33,58" android:keyEdgeFlags="right"/>
</Row> <!--- Fila z x c v b n m -->
<Row android:rowEdgeFlags="bottom">
<Key android:keyLabel="," android:codes="44" android:keyWidth="10%p" android:keyEdgeFlags="left"/>
<Key android:keyLabel="/" android:codes="47" android:keyWidth="10%p"/>
<Key android:keyLabel="SPACE" android:codes="32" android:keyWidth="40%p" android:isRepeatable="true"/>
<Key android:keyLabel="DEL" android:codes="-5" android:keyWidth="20%p" android:isRepeatable="true"/>
<Key android:keyLabel="DONE" android:codes="-4" android:keyWidth="20%p" android:keyEdgeFlags="right"/>
</Row>
</Keyboard>
And the class in java:
package gmsoftware.tecladocrypgo;
import android.inputmethodservice.InputMethodService;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.media.AudioManager;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputConnection;
import java.security.Key;
public class CrypgoKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener {
private KeyboardView kv;
private Keyboard keyboard;
private boolean isCaps = false;
/**
* Create and return the view hierarchy used for the input area (such as
* a soft keyboard). This will be called once, when the input area is
* first displayed. You can return null to have no input area; the default
* implementation returns null.
* <p>
* <p>To control when the input view is displayed, implement
* {@link #onEvaluateInputViewShown()}.
* To change the input view after the first one is created by this
* function, use {@link #setInputView(View)}.
*/
@Override
public View onCreateInputView() {
kv = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard, null);
keyboard = new Keyboard (this,R.xml.qwerty);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
return kv;
}
/**
* Called when the user presses a key. This is sent before the {@link #onKey} is called.
* For keys that repeat, this is only called once.
*
* @param primaryCode the unicode of the key being pressed. If the touch is not on a valid
* key, the value will be zero.
*/
@Override
public void onPress(int primaryCode) {
}
/**
* Called when the user releases a key. This is sent after the {@link #onKey} is called.
* For keys that repeat, this is only called once.
*
* @param primaryCode the code of the key that was released
*/
@Override
public void onRelease(int primaryCode) {
}
/**
* Send a key press to the listener.
*
* @param primaryCode this is the key that was pressed
* @param keyCodes the codes for all the possible alternative keys
* with the primary code being the first. If the primary key code is
* a single character such as an alphabet or number or symbol, the alternatives
* will include other characters that may be on the same key or adjacent keys.
* These codes are useful to correct for accidental presses of a key adjacent to
*/
@Override
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection();
playClick(primaryCode);
switch (primaryCode){
case Keyboard.KEYCODE_DELETE:
ic.deleteSurroundingText(1,0);
break;
case Keyboard.KEYCODE_SHIFT:
isCaps = !isCaps;
keyboard.setShifted(isCaps);
kv.invalidateAllKeys();
break;
case Keyboard.KEYCODE_DONE:
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
break;
default:
char code = (char) primaryCode;
if (Character.isLetter(code) && isCaps)
code = Character.toUpperCase(code);
ic.commitText(String.valueOf(code),1);
}
}
private void playClick(int primaryCode) {
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
switch (primaryCode)
{
case 32:
am.playSoundEffect(AudioManager.FX_KEYPRESS_SPACEBAR);
break;
case Keyboard.KEYCODE_DONE:
case 10:
am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN);
break;
case Keyboard.KEYCODE_DELETE:
am.playSoundEffect(AudioManager.FX_KEYPRESS_DELETE);
break;
default:
am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD);
}
}
/**
* Sends a sequence of characters to the listener.
*
* @param text the sequence of characters to be displayed.
*/
@Override
public void onText(CharSequence text) {
}
/**
* Called when the user quickly moves the finger from right to left.
*/
@Override
public void swipeLeft() {
}
/**
* Called when the user quickly moves the finger from left to right.
*/
@Override
public void swipeRight() {
}
/**
* Called when the user quickly moves the finger from up to down.
*/
@Override
public void swipeDown() {
}
/**
* Called when the user quickly moves the finger from down to up.
*/
@Override
public void swipeUp() {
}
}
As an additional question, if you could also tell me how to add that layout in the red rectangle frame, it would be helpful.
Thank you very much everyone!