11package com .termux .shared .termux .extrakeys ;
22
3+ import static com .termux .x11 .MainActivity .*;
4+
35import android .annotation .SuppressLint ;
46import android .content .Context ;
57import android .graphics .Color ;
3436import androidx .annotation .NonNull ;
3537import androidx .annotation .Nullable ;
3638
39+ import com .termux .x11 .MainActivity ;
3740import 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