Skip to content

Commit 6229d04

Browse files
committed
chore: allow user define extra key bar position
1 parent 3466399 commit 6229d04

File tree

6 files changed

+164
-56
lines changed

6 files changed

+164
-56
lines changed

app/src/main/java/com/termux/shared/termux/extrakeys/ExtraKeysView.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.termux.shared.termux.extrakeys;
22

3+
import static com.termux.x11.MainActivity.*;
4+
35
import android.annotation.SuppressLint;
46
import android.content.Context;
57
import android.graphics.Color;
@@ -34,6 +36,7 @@
3436
import androidx.annotation.NonNull;
3537
import androidx.annotation.Nullable;
3638

39+
import com.termux.x11.MainActivity;
3740
import com.termux.x11.utils.TermuxX11ExtraKeys;
3841

3942
/**
@@ -291,15 +294,19 @@ public void reload() {
291294
state.buttons = new ArrayList<>();
292295

293296
removeAllViews();
297+
if (mPopupWindow != null)
298+
dismissPopup();
294299

295300
ExtraKeyButton[][] buttons = extraKeysInfo.getMatrix();
296301

297302
setRowCount(buttons.length);
298303
setColumnCount(maximumLength(buttons));
299304

305+
boolean reverseRows = MainActivity.getInstance().getPagerPosition() == PAGER_POSITION_TOP;
306+
300307
for (int row = 0; row < buttons.length; row++) {
301308
for (int col = 0; col < buttons[row].length; col++) {
302-
final ExtraKeyButton buttonInfo = buttons[row][col];
309+
final ExtraKeyButton buttonInfo = buttons[reverseRows ? buttons.length - 1 - row : row][col];
303310

304311
Button button;
305312
if (isSpecialButton(buttonInfo)) {
@@ -338,13 +345,14 @@ public boolean hasFocusStateSpecified() {
338345
case MotionEvent.ACTION_MOVE:
339346
if (buttonInfo.popup != null) {
340347
// Show popup on swipe up
341-
if (mPopupWindow == null && event.getY() < 0) {
348+
if (mPopupWindow == null && (reverseRows ? (event.getY() > 0) : (event.getY() < 0))) {
342349
stopScheduledExecutors();
343350
view.setBackgroundColor(mButtonBackgroundColor);
344351
showPopup(view, buttonInfo.popup);
345352
}
346-
if (mPopupWindow != null && event.getY() > 0) {
353+
if (mPopupWindow != null && (reverseRows ? (event.getY() < 0) : (event.getY() > 0))) {
347354
view.setBackgroundColor(mButtonActiveBackgroundColor);
355+
android.util.Log.d("QEQEQWE", "reverseRows " + reverseRows);
348356
dismissPopup();
349357
}
350358
}
@@ -484,8 +492,9 @@ public void run() {
484492
}
485493

486494
void showPopup(View view, ExtraKeyButton extraButton) {
487-
int width = view.getMeasuredWidth();
488-
int height = view.getMeasuredHeight();
495+
int pos = MainActivity.getInstance().getPagerPosition();
496+
int width = pos == PAGER_POSITION_TOP || pos == PAGER_POSITION_BOTTOM ? view.getMeasuredWidth() : view.getMeasuredHeight();
497+
int height = pos == PAGER_POSITION_TOP || pos == PAGER_POSITION_BOTTOM ? view.getMeasuredHeight() : view.getMeasuredWidth();
489498
Button button;
490499
if (isSpecialButton(extraButton)) {
491500
button = createSpecialButton(extraButton.key, false);
@@ -510,7 +519,12 @@ void showPopup(View view, ExtraKeyButton extraButton) {
510519
mPopupWindow.setContentView(button);
511520
mPopupWindow.setOutsideTouchable(true);
512521
mPopupWindow.setFocusable(false);
513-
mPopupWindow.showAsDropDown(view, 0, -2 * height);
522+
switch (pos) {
523+
case PAGER_POSITION_TOP: mPopupWindow.showAsDropDown(view, 0, 0); break;
524+
case PAGER_POSITION_BOTTOM: mPopupWindow.showAsDropDown(view, 0, -2 * height); break;
525+
case PAGER_POSITION_LEFT: mPopupWindow.showAsDropDown(view, 0, -width); break;
526+
case PAGER_POSITION_RIGHT: mPopupWindow.showAsDropDown(view, -width, -height -width); break;
527+
}
514528
}
515529

516530
public void dismissPopup() {

0 commit comments

Comments
 (0)