Merge branch 'master' of git.oschina.net:lody/neoterm
# Conflicts: # app/src/main/java/io/neoterm/view/ExtraKeysView.java
This commit is contained in:
commit
f9e033352f
@ -4,36 +4,35 @@ import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridLayout;
|
||||
import android.widget.HorizontalScrollView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.neoterm.R;
|
||||
import io.neoterm.backend.TerminalSession;
|
||||
import io.neoterm.customize.NeoTermPath;
|
||||
import io.neoterm.customize.font.FontManager;
|
||||
import io.neoterm.customize.shortcut.ShortcutConfig;
|
||||
import io.neoterm.customize.shortcut.ShortcutConfigParser;
|
||||
import io.neoterm.preference.NeoTermPreference;
|
||||
import io.neoterm.utils.FileUtils;
|
||||
import io.neoterm.view.eks.ControlButton;
|
||||
import io.neoterm.view.eks.ExtraButton;
|
||||
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
|
||||
* keyboard.
|
||||
*/
|
||||
public final class ExtraKeysView extends GridLayout {
|
||||
public static final String KEY_ESC = "Esc";
|
||||
public static final String KEY_TAB = "Tab";
|
||||
public static final String KEY_CTRL = "Ctrl";
|
||||
public final class ExtraKeysView extends HorizontalScrollView {
|
||||
|
||||
public static final ControlButton ESC = new ControlButton(KEY_ESC);
|
||||
public static final ControlButton TAB = new ControlButton(KEY_TAB);
|
||||
@ -52,11 +51,21 @@ public final class ExtraKeysView extends GridLayout {
|
||||
|
||||
public static final int NORMAL_TEXT_COLOR = 0xFFFFFFFF;
|
||||
|
||||
|
||||
private List<ExtraButton> builtinExtraKeys;
|
||||
private List<ExtraButton> userDefinedExtraKeys;
|
||||
|
||||
private LinearLayout contentView;
|
||||
|
||||
public ExtraKeysView(Context context, AttributeSet 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);
|
||||
userDefinedExtraKeys = new ArrayList<>(7);
|
||||
loadDefaultBuiltinExtraKeys();
|
||||
@ -64,44 +73,6 @@ public final class ExtraKeysView extends GridLayout {
|
||||
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() {
|
||||
return CTRL.readState();
|
||||
@ -151,56 +122,37 @@ public final class ExtraKeysView extends GridLayout {
|
||||
}
|
||||
|
||||
public void updateButtons() {
|
||||
removeAllViews();
|
||||
List[] buttons = new List[]{userDefinedExtraKeys, builtinExtraKeys};
|
||||
|
||||
setRowCount(buttons[0].size() == 0 ? 1 : 2);
|
||||
setColumnCount(buttons[1].size());
|
||||
|
||||
for (int row = 0; row < buttons.length; row++) {
|
||||
for (int col = 0; col < buttons[row].size(); col++) {
|
||||
final ExtraButton extraButton = (ExtraButton) buttons[row].get(col);
|
||||
|
||||
Button button;
|
||||
if (extraButton instanceof StatedControlButton) {
|
||||
StatedControlButton btn = ((StatedControlButton) extraButton);
|
||||
button = btn.toggleButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||
button.setClickable(true);
|
||||
} else {
|
||||
button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||
}
|
||||
|
||||
button.setTypeface(FontManager.INSTANCE.getDefaultFont());
|
||||
button.setText(extraButton.buttonText);
|
||||
button.setTextColor(NORMAL_TEXT_COLOR);
|
||||
button.setAllCaps(false);
|
||||
|
||||
final Button finalButton = button;
|
||||
button.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finalButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
||||
View root = getRootView();
|
||||
extraButton.onClick(root);
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
for (final ExtraButton extraButton : builtinExtraKeys) {
|
||||
addExtraButton(extraButton);
|
||||
}
|
||||
for (final ExtraButton extraButton : userDefinedExtraKeys) {
|
||||
addExtraButton(extraButton);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addExtraButton(final ExtraButton extraButton) {
|
||||
final Button button;
|
||||
if (extraButton instanceof StatedControlButton) {
|
||||
StatedControlButton btn = ((StatedControlButton) extraButton);
|
||||
button = btn.toggleButton = new ToggleButton(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||
button.setClickable(true);
|
||||
} else {
|
||||
button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||
}
|
||||
button.setText(extraButton.buttonText);
|
||||
button.setTextColor(NORMAL_TEXT_COLOR);
|
||||
button.setAllCaps(false);
|
||||
|
||||
button.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
button.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
||||
View root = getRootView();
|
||||
extraButton.onClick(root);
|
||||
}
|
||||
});
|
||||
contentView.addView(button);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,6 @@ public class ControlButton extends ExtraButton {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
ExtraKeysView.sendKey(view, buttonText);
|
||||
sendKey(view, buttonText);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,62 @@
|
||||
package io.neoterm.view.eks;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
|
||||
import io.neoterm.R;
|
||||
import io.neoterm.backend.TerminalSession;
|
||||
import io.neoterm.view.TerminalView;
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
@Override
|
||||
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
|
||||
public void onClick(View view) {
|
||||
ExtraKeysView.sendKey(view, buttonText);
|
||||
sendKey(view, buttonText);
|
||||
if (withEnter) {
|
||||
ExtraKeysView.sendKey(view, "\n");
|
||||
sendKey(view, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
android:id="@+id/extra_keys"
|
||||
style="?android:buttonBarStyle"
|
||||
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:background="@color/terminal_background"
|
||||
android:orientation="horizontal" />
|
||||
|
@ -4,4 +4,5 @@
|
||||
<dimen name="text_margin">16dp</dimen>
|
||||
<dimen name="eks_height">36dp</dimen>
|
||||
<dimen name="eks_height_two_line">72dp</dimen>
|
||||
<dimen name="eks_height_one_line">36dp</dimen>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user