mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Changed: Replace extra-keys Button with MaterialButton
This commit is contained in:
@@ -25,13 +25,13 @@ import android.view.MotionEvent;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewConfiguration;
|
import android.view.ViewConfiguration;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.GridLayout;
|
import android.widget.GridLayout;
|
||||||
import android.widget.PopupWindow;
|
import android.widget.PopupWindow;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.android.material.button.MaterialButton;
|
||||||
import com.termux.shared.termux.terminal.io.TerminalExtraKeys;
|
import com.termux.shared.termux.terminal.io.TerminalExtraKeys;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,23 +86,23 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
* @param buttonInfo The {@link ExtraKeyButton} for the button that was clicked.
|
* @param buttonInfo The {@link ExtraKeyButton} for the button that was clicked.
|
||||||
* The button may be a {@link ExtraKeyButton#KEY_MACRO} set which can be
|
* The button may be a {@link ExtraKeyButton#KEY_MACRO} set which can be
|
||||||
* checked with a call to {@link ExtraKeyButton#isMacro()}.
|
* checked with a call to {@link ExtraKeyButton#isMacro()}.
|
||||||
* @param button The {@link Button} that was clicked.
|
* @param button The {@link MaterialButton} that was clicked.
|
||||||
*/
|
*/
|
||||||
void onExtraKeyButtonClick(View view, ExtraKeyButton buttonInfo, Button button);
|
void onExtraKeyButtonClick(View view, ExtraKeyButton buttonInfo, MaterialButton button);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called by {@link ExtraKeysView} when a button is clicked so that the client
|
* This is called by {@link ExtraKeysView} when a button is clicked so that the client
|
||||||
* can perform any hepatic feedback. This is only called in the {@link Button.OnClickListener}
|
* can perform any hepatic feedback. This is only called in the {@link MaterialButton.OnClickListener}
|
||||||
* and not for every repeat. Its also called for {@link #mSpecialButtons}.
|
* and not for every repeat. Its also called for {@link #mSpecialButtons}.
|
||||||
*
|
*
|
||||||
* @param view The view that was clicked.
|
* @param view The view that was clicked.
|
||||||
* @param buttonInfo The {@link ExtraKeyButton} for the button that was clicked.
|
* @param buttonInfo The {@link ExtraKeyButton} for the button that was clicked.
|
||||||
* @param button The {@link Button} that was clicked.
|
* @param button The {@link MaterialButton} that was clicked.
|
||||||
* @return Return {@code true} if the client handled the feedback, otherwise {@code false}
|
* @return Return {@code true} if the client handled the feedback, otherwise {@code false}
|
||||||
* so that {@link ExtraKeysView#performExtraKeyButtonHapticFeedback(View, ExtraKeyButton, Button)}
|
* so that {@link ExtraKeysView#performExtraKeyButtonHapticFeedback(View, ExtraKeyButton, MaterialButton)}
|
||||||
* can handle it depending on system settings.
|
* can handle it depending on system settings.
|
||||||
*/
|
*/
|
||||||
boolean performExtraKeyButtonHapticFeedback(View view, ExtraKeyButton buttonInfo, Button button);
|
boolean performExtraKeyButtonHapticFeedback(View view, ExtraKeyButton buttonInfo, MaterialButton button);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of keys for which auto repeat of key should be triggered if its extra keys button
|
* The list of keys for which auto repeat of key should be triggered if its extra keys button
|
||||||
* is long pressed. This is done by calling {@link IExtraKeysView#onExtraKeyButtonClick(View, ExtraKeyButton, Button)}
|
* is long pressed. This is done by calling {@link IExtraKeysView#onExtraKeyButtonClick(View, ExtraKeyButton, MaterialButton)}
|
||||||
* every {@link #mLongPressRepeatDelay} seconds after {@link #mLongPressTimeout} has passed.
|
* every {@link #mLongPressRepeatDelay} seconds after {@link #mLongPressTimeout} has passed.
|
||||||
* The default keys are defined by {@link ExtraKeysConstants#PRIMARY_REPETITIVE_KEYS}.
|
* The default keys are defined by {@link ExtraKeysConstants#PRIMARY_REPETITIVE_KEYS}.
|
||||||
*/
|
*/
|
||||||
@@ -326,7 +326,7 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
if (longPressDuration >= MIN_LONG_PRESS_DURATION && longPressDuration <= MAX_LONG_PRESS_DURATION) {
|
if (longPressDuration >= MIN_LONG_PRESS_DURATION && longPressDuration <= MAX_LONG_PRESS_DURATION) {
|
||||||
mLongPressTimeout = longPressDuration;
|
mLongPressTimeout = longPressDuration;
|
||||||
} else {
|
} else {
|
||||||
mLongPressTimeout = FALLBACK_LONG_PRESS_DURATION;
|
mLongPressTimeout = FALLBACK_LONG_PRESS_DURATION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,12 +382,12 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
for (int col = 0; col < buttons[row].length; col++) {
|
for (int col = 0; col < buttons[row].length; col++) {
|
||||||
final ExtraKeyButton buttonInfo = buttons[row][col];
|
final ExtraKeyButton buttonInfo = buttons[row][col];
|
||||||
|
|
||||||
Button button;
|
MaterialButton button;
|
||||||
if (isSpecialButton(buttonInfo)) {
|
if (isSpecialButton(buttonInfo)) {
|
||||||
button = createSpecialButton(buttonInfo.getKey(), true);
|
button = createSpecialButton(buttonInfo.getKey(), true);
|
||||||
if (button == null) return;
|
if (button == null) return;
|
||||||
} else {
|
} else {
|
||||||
button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
button = new MaterialButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
button.setText(buttonInfo.getDisplay());
|
button.setText(buttonInfo.getDisplay());
|
||||||
@@ -566,12 +566,12 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
void showPopup(View view, ExtraKeyButton extraButton) {
|
void showPopup(View view, ExtraKeyButton extraButton) {
|
||||||
int width = view.getMeasuredWidth();
|
int width = view.getMeasuredWidth();
|
||||||
int height = view.getMeasuredHeight();
|
int height = view.getMeasuredHeight();
|
||||||
Button button;
|
MaterialButton button;
|
||||||
if (isSpecialButton(extraButton)) {
|
if (isSpecialButton(extraButton)) {
|
||||||
button = createSpecialButton(extraButton.getKey(), false);
|
button = createSpecialButton(extraButton.getKey(), false);
|
||||||
if (button == null) return;
|
if (button == null) return;
|
||||||
} else {
|
} else {
|
||||||
button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
button = new MaterialButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||||
button.setTextColor(mButtonTextColor);
|
button.setTextColor(mButtonTextColor);
|
||||||
}
|
}
|
||||||
button.setText(extraButton.getDisplay());
|
button.setText(extraButton.getDisplay());
|
||||||
@@ -631,11 +631,11 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Button createSpecialButton(String buttonKey, boolean needUpdate) {
|
public MaterialButton createSpecialButton(String buttonKey, boolean needUpdate) {
|
||||||
SpecialButtonState state = mSpecialButtons.get(SpecialButton.valueOf(buttonKey));
|
SpecialButtonState state = mSpecialButtons.get(SpecialButton.valueOf(buttonKey));
|
||||||
if (state == null) return null;
|
if (state == null) return null;
|
||||||
state.setIsCreated(true);
|
state.setIsCreated(true);
|
||||||
Button button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
MaterialButton button = new MaterialButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||||
button.setTextColor(state.isActive ? mButtonActiveTextColor : mButtonTextColor);
|
button.setTextColor(state.isActive ? mButtonActiveTextColor : mButtonTextColor);
|
||||||
if (needUpdate) {
|
if (needUpdate) {
|
||||||
state.buttons.add(button);
|
state.buttons.add(button);
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package com.termux.shared.termux.extrakeys;
|
package com.termux.shared.termux.extrakeys;
|
||||||
|
|
||||||
import android.widget.Button;
|
import com.google.android.material.button.MaterialButton;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -16,7 +16,7 @@ public class SpecialButtonState {
|
|||||||
* state is read. */
|
* state is read. */
|
||||||
boolean isLocked = false;
|
boolean isLocked = false;
|
||||||
|
|
||||||
List<Button> buttons = new ArrayList<>();
|
List<MaterialButton> buttons = new ArrayList<>();
|
||||||
|
|
||||||
ExtraKeysView mExtraKeysView;
|
ExtraKeysView mExtraKeysView;
|
||||||
|
|
||||||
|
@@ -2,10 +2,10 @@ package com.termux.shared.termux.terminal.io;
|
|||||||
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.google.android.material.button.MaterialButton;
|
||||||
import com.termux.shared.termux.extrakeys.ExtraKeyButton;
|
import com.termux.shared.termux.extrakeys.ExtraKeyButton;
|
||||||
import com.termux.shared.termux.extrakeys.ExtraKeysView;
|
import com.termux.shared.termux.extrakeys.ExtraKeysView;
|
||||||
import com.termux.shared.termux.extrakeys.SpecialButton;
|
import com.termux.shared.termux.extrakeys.SpecialButton;
|
||||||
@@ -23,7 +23,7 @@ public class TerminalExtraKeys implements ExtraKeysView.IExtraKeysView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onExtraKeyButtonClick(View view, ExtraKeyButton buttonInfo, Button button) {
|
public void onExtraKeyButtonClick(View view, ExtraKeyButton buttonInfo, MaterialButton button) {
|
||||||
if (buttonInfo.isMacro()) {
|
if (buttonInfo.isMacro()) {
|
||||||
String[] keys = buttonInfo.getKey().split(" ");
|
String[] keys = buttonInfo.getKey().split(" ");
|
||||||
boolean ctrlDown = false;
|
boolean ctrlDown = false;
|
||||||
@@ -70,7 +70,7 @@ public class TerminalExtraKeys implements ExtraKeysView.IExtraKeysView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean performExtraKeyButtonHapticFeedback(View view, ExtraKeyButton buttonInfo, Button button) {
|
public boolean performExtraKeyButtonHapticFeedback(View view, ExtraKeyButton buttonInfo, MaterialButton button) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user