这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.termux.shared.termux.extrakeys;

import static com.termux.x11.MainActivity.*;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
Expand Down Expand Up @@ -34,6 +36,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.termux.x11.MainActivity;
import com.termux.x11.utils.TermuxX11ExtraKeys;

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

removeAllViews();
if (mPopupWindow != null)
dismissPopup();

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

setRowCount(buttons.length);
setColumnCount(maximumLength(buttons));

boolean reverseRows = MainActivity.getInstance().getPagerPosition() == PAGER_POSITION_TOP;

for (int row = 0; row < buttons.length; row++) {
for (int col = 0; col < buttons[row].length; col++) {
final ExtraKeyButton buttonInfo = buttons[row][col];
final ExtraKeyButton buttonInfo = buttons[reverseRows ? buttons.length - 1 - row : row][col];

Button button;
if (isSpecialButton(buttonInfo)) {
Expand Down Expand Up @@ -338,12 +345,12 @@ public boolean hasFocusStateSpecified() {
case MotionEvent.ACTION_MOVE:
if (buttonInfo.popup != null) {
// Show popup on swipe up
if (mPopupWindow == null && event.getY() < 0) {
if (mPopupWindow == null && (reverseRows ? (event.getY() > 0) : (event.getY() < 0))) {
stopScheduledExecutors();
view.setBackgroundColor(mButtonBackgroundColor);
showPopup(view, buttonInfo.popup);
}
if (mPopupWindow != null && event.getY() > 0) {
if (mPopupWindow != null && (reverseRows ? (event.getY() < 0) : (event.getY() > 0))) {
view.setBackgroundColor(mButtonActiveBackgroundColor);
dismissPopup();
}
Expand Down Expand Up @@ -484,8 +491,9 @@ public void run() {
}

void showPopup(View view, ExtraKeyButton extraButton) {
int width = view.getMeasuredWidth();
int height = view.getMeasuredHeight();
int pos = MainActivity.getInstance().getPagerPosition();
int width = pos == PAGER_POSITION_TOP || pos == PAGER_POSITION_BOTTOM ? view.getMeasuredWidth() : view.getMeasuredHeight();
int height = pos == PAGER_POSITION_TOP || pos == PAGER_POSITION_BOTTOM ? view.getMeasuredHeight() : view.getMeasuredWidth();
Button button;
if (isSpecialButton(extraButton)) {
button = createSpecialButton(extraButton.key, false);
Expand All @@ -510,7 +518,12 @@ void showPopup(View view, ExtraKeyButton extraButton) {
mPopupWindow.setContentView(button);
mPopupWindow.setOutsideTouchable(true);
mPopupWindow.setFocusable(false);
mPopupWindow.showAsDropDown(view, 0, -2 * height);
switch (pos) {
case PAGER_POSITION_TOP: mPopupWindow.showAsDropDown(view, 0, 0); break;
case PAGER_POSITION_BOTTOM: mPopupWindow.showAsDropDown(view, 0, -2 * height); break;
case PAGER_POSITION_LEFT: mPopupWindow.showAsDropDown(view, 0, -width); break;
case PAGER_POSITION_RIGHT: mPopupWindow.showAsDropDown(view, -width, -height -width); break;
}
}

public void dismissPopup() {
Expand Down
Loading