UI: one line ExtraKeysView.
This commit is contained in:
parent
255163ff98
commit
999de06a62
@ -4,47 +4,40 @@ import android.content.Context;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.HapticFeedbackConstants;
|
import android.view.HapticFeedbackConstants;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.GridLayout;
|
import android.widget.HorizontalScrollView;
|
||||||
import android.widget.Toast;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ScrollView;
|
||||||
import android.widget.ToggleButton;
|
import android.widget.ToggleButton;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.neoterm.R;
|
|
||||||
import io.neoterm.backend.TerminalSession;
|
|
||||||
import io.neoterm.customize.NeoTermPath;
|
import io.neoterm.customize.NeoTermPath;
|
||||||
import io.neoterm.customize.font.FontManager;
|
|
||||||
import io.neoterm.customize.shortcut.ShortcutConfig;
|
import io.neoterm.customize.shortcut.ShortcutConfig;
|
||||||
import io.neoterm.customize.shortcut.ShortcutConfigParser;
|
import io.neoterm.customize.shortcut.ShortcutConfigParser;
|
||||||
import io.neoterm.preference.NeoTermPreference;
|
|
||||||
import io.neoterm.utils.FileUtils;
|
import io.neoterm.utils.FileUtils;
|
||||||
import io.neoterm.view.eks.ControlButton;
|
import io.neoterm.view.eks.ControlButton;
|
||||||
import io.neoterm.view.eks.ExtraButton;
|
import io.neoterm.view.eks.ExtraButton;
|
||||||
import io.neoterm.view.eks.StatedControlButton;
|
import io.neoterm.view.eks.StatedControlButton;
|
||||||
|
|
||||||
|
import static io.neoterm.view.eks.ExtraButton.KEY_CTRL;
|
||||||
|
import static io.neoterm.view.eks.ExtraButton.KEY_ESC;
|
||||||
|
import static io.neoterm.view.eks.ExtraButton.KEY_TAB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A view showing extra keys (such as Escape, Ctrl, Alt) not normally available on an Android soft
|
* A view showing extra keys (such as Escape, Ctrl, Alt) not normally available on an Android soft
|
||||||
* keyboard.
|
* keyboard.
|
||||||
*/
|
*/
|
||||||
public final class ExtraKeysView extends GridLayout {
|
public final class ExtraKeysView extends HorizontalScrollView {
|
||||||
public static final String KEY_ESC = "Esc";
|
|
||||||
public static final String KEY_TAB = "Tab";
|
|
||||||
public static final String KEY_CTRL = "Ctrl";
|
|
||||||
|
|
||||||
public static final ControlButton ESC = new ControlButton(KEY_ESC);
|
public static final ControlButton ESC = new ControlButton(KEY_ESC);
|
||||||
public static final ControlButton TAB = new ControlButton(KEY_TAB);
|
public static final ControlButton TAB = new ControlButton(KEY_TAB);
|
||||||
public static final StatedControlButton CTRL = new StatedControlButton(KEY_CTRL);
|
public static final StatedControlButton CTRL = new StatedControlButton(KEY_CTRL);
|
||||||
|
|
||||||
// public static final ControlButton ARROW_UP = new ControlButton("▲");
|
|
||||||
// public static final ControlButton ARROW_DOWN = new ControlButton("▼");
|
|
||||||
// public static final ControlButton ARROW_LEFT = new ControlButton("◀");
|
|
||||||
// public static final ControlButton ARROW_RIGHT = new ControlButton("▶");
|
|
||||||
|
|
||||||
public static final ControlButton ARROW_UP = new ControlButton("▲");
|
public static final ControlButton ARROW_UP = new ControlButton("▲");
|
||||||
public static final ControlButton ARROW_DOWN = new ControlButton("▼");
|
public static final ControlButton ARROW_DOWN = new ControlButton("▼");
|
||||||
public static final ControlButton ARROW_LEFT = new ControlButton("◀");
|
public static final ControlButton ARROW_LEFT = new ControlButton("◀");
|
||||||
@ -58,11 +51,21 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
|
|
||||||
public static final int NORMAL_TEXT_COLOR = 0xFFFFFFFF;
|
public static final int NORMAL_TEXT_COLOR = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
|
||||||
private List<ExtraButton> builtinExtraKeys;
|
private List<ExtraButton> builtinExtraKeys;
|
||||||
private List<ExtraButton> userDefinedExtraKeys;
|
private List<ExtraButton> userDefinedExtraKeys;
|
||||||
|
|
||||||
|
private LinearLayout contentView;
|
||||||
|
|
||||||
public ExtraKeysView(Context context, AttributeSet attrs) {
|
public ExtraKeysView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
setFillViewport(true);
|
||||||
|
contentView = new LinearLayout(context);
|
||||||
|
contentView.setGravity(Gravity.CENTER);
|
||||||
|
contentView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
contentView.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
contentView.setGravity(Gravity.LEFT);
|
||||||
|
addView(contentView);
|
||||||
builtinExtraKeys = new ArrayList<>(7);
|
builtinExtraKeys = new ArrayList<>(7);
|
||||||
userDefinedExtraKeys = new ArrayList<>(7);
|
userDefinedExtraKeys = new ArrayList<>(7);
|
||||||
loadDefaultBuiltinExtraKeys();
|
loadDefaultBuiltinExtraKeys();
|
||||||
@ -70,44 +73,6 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
updateButtons();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendKey(View view, String keyName) {
|
|
||||||
int keyCode = 0;
|
|
||||||
String chars = null;
|
|
||||||
switch (keyName) {
|
|
||||||
case KEY_ESC:
|
|
||||||
keyCode = KeyEvent.KEYCODE_ESCAPE;
|
|
||||||
break;
|
|
||||||
case KEY_TAB:
|
|
||||||
keyCode = KeyEvent.KEYCODE_TAB;
|
|
||||||
break;
|
|
||||||
case "▲":
|
|
||||||
keyCode = KeyEvent.KEYCODE_DPAD_UP;
|
|
||||||
break;
|
|
||||||
case "◀":
|
|
||||||
keyCode = KeyEvent.KEYCODE_DPAD_LEFT;
|
|
||||||
break;
|
|
||||||
case "▶":
|
|
||||||
keyCode = KeyEvent.KEYCODE_DPAD_RIGHT;
|
|
||||||
break;
|
|
||||||
case "▼":
|
|
||||||
keyCode = KeyEvent.KEYCODE_DPAD_DOWN;
|
|
||||||
break;
|
|
||||||
case "―":
|
|
||||||
chars = "-";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
chars = keyName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyCode > 0) {
|
|
||||||
view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
|
|
||||||
view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
|
|
||||||
} else {
|
|
||||||
TerminalView terminalView = (TerminalView) view.findViewById(R.id.terminal_view);
|
|
||||||
TerminalSession session = terminalView.getCurrentSession();
|
|
||||||
if (session != null) session.write(chars);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean readControlButton() {
|
public boolean readControlButton() {
|
||||||
return CTRL.readState();
|
return CTRL.readState();
|
||||||
@ -157,17 +122,17 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateButtons() {
|
public void updateButtons() {
|
||||||
removeAllViews();
|
for (final ExtraButton extraButton : builtinExtraKeys) {
|
||||||
List[] buttons = new List[]{userDefinedExtraKeys, builtinExtraKeys};
|
addExtraButton(extraButton);
|
||||||
|
}
|
||||||
|
for (final ExtraButton extraButton : userDefinedExtraKeys) {
|
||||||
|
addExtraButton(extraButton);
|
||||||
|
}
|
||||||
|
|
||||||
setRowCount(buttons[0].size() == 0 ? 1 : 2);
|
}
|
||||||
setColumnCount(buttons[1].size());
|
|
||||||
|
|
||||||
for (int row = 0; row < buttons.length; row++) {
|
private void addExtraButton(final ExtraButton extraButton) {
|
||||||
for (int col = 0; col < buttons[row].size(); col++) {
|
final Button button;
|
||||||
final ExtraButton extraButton = (ExtraButton) buttons[row].get(col);
|
|
||||||
|
|
||||||
Button button;
|
|
||||||
if (extraButton instanceof StatedControlButton) {
|
if (extraButton instanceof StatedControlButton) {
|
||||||
StatedControlButton btn = ((StatedControlButton) extraButton);
|
StatedControlButton btn = ((StatedControlButton) extraButton);
|
||||||
button = btn.toggleButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
button = btn.toggleButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||||
@ -175,43 +140,19 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
} else {
|
} else {
|
||||||
button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
button.setTypeface(FontManager.INSTANCE.getDefaultFont());
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Toast.makeText(getContext(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
button.setText(extraButton.buttonText);
|
button.setText(extraButton.buttonText);
|
||||||
button.setTextColor(NORMAL_TEXT_COLOR);
|
button.setTextColor(NORMAL_TEXT_COLOR);
|
||||||
button.setAllCaps(false);
|
button.setAllCaps(false);
|
||||||
|
|
||||||
final Button finalButton = button;
|
|
||||||
button.setOnClickListener(new OnClickListener() {
|
button.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
finalButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
button.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
||||||
View root = getRootView();
|
View root = getRootView();
|
||||||
extraButton.onClick(root);
|
extraButton.onClick(root);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
contentView.addView(button);
|
||||||
LayoutParams param = new LayoutParams();
|
|
||||||
param.height = param.width = 0;
|
|
||||||
param.rightMargin = param.topMargin = 0;
|
|
||||||
param.setGravity(Gravity.START);
|
|
||||||
|
|
||||||
float weight = 1.f;
|
|
||||||
if (NeoTermPreference.INSTANCE.loadBoolean(R.string.key_ui_wide_char_weigh_explicit, false)) {
|
|
||||||
weight = "▲▼◀▶".contains(extraButton.buttonText) ? 0.7f : 1.f;
|
|
||||||
}
|
|
||||||
param.columnSpec = GridLayout.spec(col, GridLayout.FILL, weight);
|
|
||||||
param.rowSpec = GridLayout.spec(row, GridLayout.FILL, 1.f);
|
|
||||||
button.setLayoutParams(param);
|
|
||||||
|
|
||||||
addView(button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,6 @@ public class ControlButton extends ExtraButton {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
ExtraKeysView.sendKey(view, buttonText);
|
sendKey(view, buttonText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,62 @@
|
|||||||
package io.neoterm.view.eks;
|
package io.neoterm.view.eks;
|
||||||
|
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import io.neoterm.R;
|
||||||
|
import io.neoterm.backend.TerminalSession;
|
||||||
|
import io.neoterm.view.TerminalView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kiva
|
* @author kiva
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class ExtraButton implements View.OnClickListener {
|
public abstract class ExtraButton implements View.OnClickListener {
|
||||||
|
public static final String KEY_ESC = "Esc";
|
||||||
|
public static final String KEY_TAB = "Tab";
|
||||||
|
public static final String KEY_CTRL = "Ctrl";
|
||||||
|
|
||||||
public String buttonText;
|
public String buttonText;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void onClick(View view);
|
public abstract void onClick(View view);
|
||||||
|
|
||||||
|
public static void sendKey(View view, String keyName) {
|
||||||
|
int keyCode = 0;
|
||||||
|
String chars = null;
|
||||||
|
switch (keyName) {
|
||||||
|
case KEY_ESC:
|
||||||
|
keyCode = KeyEvent.KEYCODE_ESCAPE;
|
||||||
|
break;
|
||||||
|
case KEY_TAB:
|
||||||
|
keyCode = KeyEvent.KEYCODE_TAB;
|
||||||
|
break;
|
||||||
|
case "▲":
|
||||||
|
keyCode = KeyEvent.KEYCODE_DPAD_UP;
|
||||||
|
break;
|
||||||
|
case "◀":
|
||||||
|
keyCode = KeyEvent.KEYCODE_DPAD_LEFT;
|
||||||
|
break;
|
||||||
|
case "▶":
|
||||||
|
keyCode = KeyEvent.KEYCODE_DPAD_RIGHT;
|
||||||
|
break;
|
||||||
|
case "▼":
|
||||||
|
keyCode = KeyEvent.KEYCODE_DPAD_DOWN;
|
||||||
|
break;
|
||||||
|
case "―":
|
||||||
|
chars = "-";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
chars = keyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyCode > 0) {
|
||||||
|
view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
|
||||||
|
view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
|
||||||
|
} else {
|
||||||
|
TerminalView terminalView = (TerminalView) view.findViewById(R.id.terminal_view);
|
||||||
|
TerminalSession session = terminalView.getCurrentSession();
|
||||||
|
if (session != null) session.write(chars);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -22,9 +22,9 @@ public class TextButton extends ExtraButton {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
ExtraKeysView.sendKey(view, buttonText);
|
sendKey(view, buttonText);
|
||||||
if (withEnter) {
|
if (withEnter) {
|
||||||
ExtraKeysView.sendKey(view, "\n");
|
sendKey(view, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
android:id="@+id/extra_keys"
|
android:id="@+id/extra_keys"
|
||||||
style="?android:buttonBarStyle"
|
style="?android:buttonBarStyle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/eks_height_two_line"
|
android:layout_height="@dimen/eks_height_one_line"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:background="@color/terminal_background"
|
android:background="@color/terminal_background"
|
||||||
android:orientation="horizontal" />
|
android:orientation="horizontal" />
|
||||||
|
@ -4,4 +4,5 @@
|
|||||||
<dimen name="text_margin">16dp</dimen>
|
<dimen name="text_margin">16dp</dimen>
|
||||||
<dimen name="eks_height">36dp</dimen>
|
<dimen name="eks_height">36dp</dimen>
|
||||||
<dimen name="eks_height_two_line">72dp</dimen>
|
<dimen name="eks_height_two_line">72dp</dimen>
|
||||||
|
<dimen name="eks_height_one_line">36dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user