Skip to content

Commit

Permalink
Prevent keyboard popup-keys group from wrapping to two lines
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed May 14, 2019
1 parent 114f710 commit 82e76fd
Showing 1 changed file with 8 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,44 +315,18 @@ public void onLongPress(Keyboard.Key popupKey) {
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);

boolean rightAligned = false;
int maxCharsPerLine = MAX_CHARS_PER_LINE_LONG;
float totalWidth = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardWidth());
totalWidth -= mKeyboardView.getPaddingLeft() + mKeyboardView.getPaddingRight();
float keyX = popupKey.x + WidgetPlacement.convertDpToPixel(getContext(), mKeyWidth * 0.5f);
boolean rightAligned = keyX >= totalWidth * 0.5f;
Log.e(LOGTAG, "Makelele: " + totalWidth + " " + keyX);
StringBuilder popupCharacters = new StringBuilder(popupKey.popupCharacters);
switch (popupKey.codes[0]) {
case 110: {
rightAligned = true;
maxCharsPerLine = MAX_CHARS_PER_LINE_SHORT;
}
break;
case 33:
case 63:
case 98:
case 104:
case 105:
case 106:
case 107:
case 108:
case 109:
case 111:
case 112:
case 117:
case 187:{
rightAligned = true;
maxCharsPerLine = MAX_CHARS_PER_LINE_LONG;
}
default: {
float totalWidth = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardWidth());
rightAligned = (float)popupKey.x > totalWidth * 0.5f;
maxCharsPerLine = MAX_CHARS_PER_LINE_LONG;
}

}

if (rightAligned) {
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params.rightMargin = mKeyboardView.getWidth() - popupKey.x - mKeyWidth - mKeyboardNumericView.getPaddingRight();
if (popupCharacters.length() > maxCharsPerLine) {
popupCharacters.insert(maxCharsPerLine - 1, popupCharacters.charAt(0));
if (popupCharacters.length() > MAX_CHARS_PER_LINE_LONG) {
popupCharacters.insert(MAX_CHARS_PER_LINE_LONG - 1, popupCharacters.charAt(0));
popupCharacters.replace(0,1, String.valueOf(popupCharacters.charAt(popupCharacters.length()-1)));
popupCharacters.deleteCharAt(popupCharacters.length()-1);
} else {
Expand All @@ -364,7 +338,7 @@ public void onLongPress(Keyboard.Key popupKey) {
params.topMargin = popupKey.y + mKeyboardPopupTopMargin + mKeyboardView.getPaddingTop();

CustomKeyboard popupKeyboard = new CustomKeyboard(getContext(), popupKey.popupResId,
popupCharacters, maxCharsPerLine, 0, getContext().getResources().getDimensionPixelSize(R.dimen.keyboard_vertical_gap));
popupCharacters, MAX_CHARS_PER_LINE_LONG, 0, getContext().getResources().getDimensionPixelSize(R.dimen.keyboard_vertical_gap));
mPopupKeyboardview.setKeyboard(popupKeyboard);
mPopupKeyboardview.setLayoutParams(params);
mPopupKeyboardview.setShifted(mIsCapsLock);
Expand Down

0 comments on commit 82e76fd

Please sign in to comment.