mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 03:05:18 +08:00
ExtraKeys: fix so app doesn't crash if ctrl/alt aren't in extrakeys
Otherwise we get: AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.widget.CompoundButton.isChecked()' on a null object reference AndroidRuntime: at com.termux.app.ExtraKeysView.b(SourceFile:128)
This commit is contained in:
committed by
Fredrik Fornwall
parent
b51dd4f558
commit
b3eabd9bad
@@ -101,37 +101,49 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
private ToggleButton controlButton;
|
private ToggleButton controlButton;
|
||||||
private ToggleButton altButton;
|
private ToggleButton altButton;
|
||||||
private ToggleButton fnButton;
|
private ToggleButton fnButton;
|
||||||
|
private boolean hasControlButton = false;
|
||||||
|
private boolean hasAltButton = false;
|
||||||
|
private boolean hasFnButton = false;
|
||||||
private ScheduledExecutorService scheduledExecutor;
|
private ScheduledExecutorService scheduledExecutor;
|
||||||
private PopupWindow popupWindow;
|
private PopupWindow popupWindow;
|
||||||
private int longPressCount;
|
private int longPressCount;
|
||||||
|
|
||||||
public boolean readControlButton() {
|
public boolean readControlButton() {
|
||||||
|
boolean result = false;
|
||||||
|
if (hasControlButton) {
|
||||||
if (controlButton.isPressed()) return true;
|
if (controlButton.isPressed()) return true;
|
||||||
boolean result = controlButton.isChecked();
|
result = controlButton.isChecked();
|
||||||
if (result) {
|
if (result) {
|
||||||
controlButton.setChecked(false);
|
controlButton.setChecked(false);
|
||||||
controlButton.setTextColor(TEXT_COLOR);
|
controlButton.setTextColor(TEXT_COLOR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readAltButton() {
|
public boolean readAltButton() {
|
||||||
|
boolean result = false;
|
||||||
|
if (hasAltButton) {
|
||||||
if (altButton.isPressed()) return true;
|
if (altButton.isPressed()) return true;
|
||||||
boolean result = altButton.isChecked();
|
result = altButton.isChecked();
|
||||||
if (result) {
|
if (result) {
|
||||||
altButton.setChecked(false);
|
altButton.setChecked(false);
|
||||||
altButton.setTextColor(TEXT_COLOR);
|
altButton.setTextColor(TEXT_COLOR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readFnButton() {
|
public boolean readFnButton() {
|
||||||
|
boolean result = false;
|
||||||
|
if (hasFnButton) {
|
||||||
if (fnButton.isPressed()) return true;
|
if (fnButton.isPressed()) return true;
|
||||||
boolean result = fnButton.isChecked();
|
result = fnButton.isChecked();
|
||||||
if (result) {
|
if (result) {
|
||||||
fnButton.setChecked(false);
|
fnButton.setChecked(false);
|
||||||
fnButton.setTextColor(TEXT_COLOR);
|
fnButton.setTextColor(TEXT_COLOR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,7 +171,7 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reload(final String[][] buttons) {
|
void reload(final String[][] buttons) {
|
||||||
altButton = controlButton = null;
|
altButton = controlButton = fnButton = null;
|
||||||
removeAllViews();
|
removeAllViews();
|
||||||
|
|
||||||
int mx = 0;
|
int mx = 0;
|
||||||
@@ -179,14 +191,17 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
Button button;
|
Button button;
|
||||||
switch (buttonText) {
|
switch (buttonText) {
|
||||||
case "CTRL":
|
case "CTRL":
|
||||||
|
hasControlButton = true;
|
||||||
button = controlButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
button = controlButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||||
button.setClickable(true);
|
button.setClickable(true);
|
||||||
break;
|
break;
|
||||||
case "ALT":
|
case "ALT":
|
||||||
|
hasAltButton = true;
|
||||||
button = altButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
button = altButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||||
button.setClickable(true);
|
button.setClickable(true);
|
||||||
break;
|
break;
|
||||||
case "FN":
|
case "FN":
|
||||||
|
hasFnButton = true;
|
||||||
button = fnButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
button = fnButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||||
button.setClickable(true);
|
button.setClickable(true);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user