Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom kbd fixes #1159

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions app/src/common/shared/com/igalia/wolvic/input/CustomKeyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import com.igalia.wolvic.input.Keyboard;
import android.view.KeyEvent;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -49,11 +48,9 @@ public CustomKeyboard (Context context, int layoutTemplateResId, CharSequence ch
int mDefaultHorizontalGap = getParentFieldInt(this, "mDefaultHorizontalGap");
int mDefaultVerticalGap = verticalGap >= 0 ? verticalGap : getParentFieldInt(this, "mDefaultVerticalGap");
int mDisplayWidth = getParentFieldInt(this, "mDisplayWidth");
ArrayList<Row> rows = null;
Object rowsObj = getParentFieldObject(this, "rows");
if (rowsObj != null && rowsObj instanceof ArrayList) {
rows = (ArrayList<Row>)rowsObj;
}
@SuppressWarnings("unchecked")
ArrayList<Row> rows = rowsObj instanceof ArrayList ? (ArrayList<Row>) rowsObj : null;

int rowsNum = (int)Math.ceil((characters.length()+0.1)/columns);
final int maxColumns = columns == -1 ? Integer.MAX_VALUE : columns;
Expand All @@ -69,7 +66,7 @@ public CustomKeyboard (Context context, int layoutTemplateResId, CharSequence ch
}
for (int i = 0; i < characters.length(); i++) {
char c = characters.charAt(i);
int rowIndex = (int)Math.floor(i/columns);
int rowIndex = i / columns;

final Key key = new Key(mRows[rowIndex]);

Expand All @@ -93,9 +90,7 @@ public CustomKeyboard (Context context, int layoutTemplateResId, CharSequence ch
if (keysObj != null && getFieldObject(mRows[rowIndex], "mKeys") instanceof ArrayList) {
@SuppressWarnings("unchecked")
ArrayList<Key> mKeys = (ArrayList<Key>) keysObj;
if (mKeys != null) {
mKeys.add(key);
}
mKeys.add(key);
}
int mTotalWidth = getParentFieldInt(this, "mTotalWidth");
if (x > mTotalWidth) {
Expand Down Expand Up @@ -147,8 +142,7 @@ public static Field getField(Class<?> clazz, String fieldName) {
Class<?> tmpClass = clazz;
do {
try {
Field f = tmpClass.getDeclaredField(fieldName);
return f;
return tmpClass.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
tmpClass = tmpClass.getSuperclass();
}
Expand Down Expand Up @@ -190,7 +184,7 @@ protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResou
@Override
public int[] getNearestKeys(int x, int y) {
List<Key> keys = getKeys();
Key[] mKeys = keys.toArray(new Key[keys.size()]);
Key[] mKeys = keys.toArray(new Key[0]);
int i = 0;
for (Key key : mKeys) {
if(key.isInside(x, y))
Expand Down