aboutsummaryrefslogtreecommitdiffstats
path: root/app/src
diff options
context:
space:
mode:
authoralescdb <alescdb@users.noreply.github.com>2015-08-22 16:27:22 +0200
committeralescdb <alescdb@users.noreply.github.com>2015-08-22 16:27:22 +0200
commit3f7146bf87b79cc6fd48cf79b65933199e24e9ba (patch)
tree7ca49ca7d085ea43cd7b581e1f528c1893d24a0b /app/src
parentad3dbb4abfe61a0993c33e01c342397a7e0d8cce (diff)
downloadconnectbot-3f7146bf87b79cc6fd48cf79b65933199e24e9ba.tar.gz
connectbot-3f7146bf87b79cc6fd48cf79b65933199e24e9ba.tar.bz2
connectbot-3f7146bf87b79cc6fd48cf79b65933199e24e9ba.zip
Scroll keyboard back a forth to give a hint to user about the scrollable keyboard.
Handle repeatable arrow keys (easily extendable to other keys if needed).
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/org/connectbot/ConsoleActivity.java140
-rw-r--r--app/src/main/res/layout-large/act_console.xml46
-rw-r--r--app/src/main/res/layout/act_console.xml156
3 files changed, 210 insertions, 132 deletions
diff --git a/app/src/main/java/org/connectbot/ConsoleActivity.java b/app/src/main/java/org/connectbot/ConsoleActivity.java
index 294b8f3..ef47794 100644
--- a/app/src/main/java/org/connectbot/ConsoleActivity.java
+++ b/app/src/main/java/org/connectbot/ConsoleActivity.java
@@ -83,6 +83,7 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
+import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
@@ -99,6 +100,8 @@ public class ConsoleActivity extends Activity implements BridgeDisconnectedListe
private static final int CLICK_TIME = 400;
private static final float MAX_CLICK_DISTANCE = 25f;
private static final int KEYBOARD_DISPLAY_TIME = 3000;
+ private static final int KEYBOARD_REPEAT_INITIAL = 500;
+ private static final int KEYBOARD_REPEAT = 100;
protected ViewPager pager = null;
protected TabLayout tabs = null;
@@ -215,6 +218,59 @@ public class ConsoleActivity extends Activity implements BridgeDisconnectedListe
}
};
+ protected Handler keyRepeatHandler = new Handler();
+
+
+ /**
+ * Handle repeatable virtual keys and touch events
+ */
+ public class KeyRepeater implements Runnable, OnTouchListener {
+ private View mView;
+ private Handler mHandler;
+ private boolean mDown;
+
+ public KeyRepeater(Handler handler, View view) {
+ mView = view;
+ mHandler = handler;
+ mView.setOnTouchListener(this);
+ mDown = false;
+ }
+
+ @Override
+ public void run() {
+ mDown = true;
+ mHandler.removeCallbacks(this);
+ mHandler.postDelayed(this, KEYBOARD_REPEAT);
+ onEmulatedKeyClicked(mView);
+ }
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ Log.d(TAG, "KeyRepeater.onTouch(" + v.getId() + ", " +
+ event.getAction() + ", " +
+ event.getActionIndex() + ", " +
+ event.getActionMasked() + ");");
+ switch (event.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ mDown = false;
+ mHandler.postDelayed(this, KEYBOARD_REPEAT_INITIAL);
+ return (true);
+
+ case MotionEvent.ACTION_CANCEL:
+ keyRepeatHandler.removeCallbacks(this);
+ return (true);
+
+ case MotionEvent.ACTION_UP:
+ keyRepeatHandler.removeCallbacks(this);
+ if (!mDown) {
+ onEmulatedKeyClicked(mView);
+ }
+ return (true);
+ }
+ return false;
+ }
+ }
+
private void onEmulatedKeyClicked(View v) {
TerminalView terminal = adapter.getCurrentTerminalView();
if (terminal == null) return;
@@ -222,7 +278,7 @@ public class ConsoleActivity extends Activity implements BridgeDisconnectedListe
TerminalKeyListener handler = terminal.bridge.getKeyHandler();
boolean hideKeys = false;
- switch (v.getId()) {
+ switch (v.getId()) {
case R.id.button_ctrl:
handler.metaPress(TerminalKeyListener.OUR_CTRL_ON, true);
hideKeys = true;
@@ -499,10 +555,12 @@ public class ConsoleActivity extends Activity implements BridgeDisconnectedListe
findViewById(R.id.button_ctrl).setOnClickListener(emulatedKeysListener);
findViewById(R.id.button_esc).setOnClickListener(emulatedKeysListener);
findViewById(R.id.button_tab).setOnClickListener(emulatedKeysListener);
- findViewById(R.id.button_up).setOnClickListener(emulatedKeysListener);
- findViewById(R.id.button_down).setOnClickListener(emulatedKeysListener);
- findViewById(R.id.button_left).setOnClickListener(emulatedKeysListener);
- findViewById(R.id.button_right).setOnClickListener(emulatedKeysListener);
+
+ new KeyRepeater(keyRepeatHandler, findViewById(R.id.button_up));
+ new KeyRepeater(keyRepeatHandler, findViewById(R.id.button_down));
+ new KeyRepeater(keyRepeatHandler, findViewById(R.id.button_left));
+ new KeyRepeater(keyRepeatHandler, findViewById(R.id.button_right));
+
findViewById(R.id.button_home).setOnClickListener(emulatedKeysListener);
findViewById(R.id.button_end).setOnClickListener(emulatedKeysListener);
findViewById(R.id.button_pgup).setOnClickListener(emulatedKeysListener);
@@ -520,6 +578,7 @@ public class ConsoleActivity extends Activity implements BridgeDisconnectedListe
findViewById(R.id.button_f11).setOnClickListener(emulatedKeysListener);
findViewById(R.id.button_f12).setOnClickListener(emulatedKeysListener);
+
actionBar = ActionBarWrapper.getActionBar(this);
actionBar.setDisplayHomeAsUpEnabled(true);
if (titleBarHide) {
@@ -534,6 +593,25 @@ public class ConsoleActivity extends Activity implements BridgeDisconnectedListe
}
});
+ // Show virtual keyboard and scroll back and forth
+ final HorizontalScrollView keyboardScroll = (HorizontalScrollView) findViewById(R.id.keyboard_hscroll);
+ showEmulatedKeys();
+ keyboardScroll.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ final int xscroll = keyboardScroll.getMaxScrollAmount();
+ Log.d(TAG, "smoothScrollBy(1)");
+ keyboardScroll.smoothScrollBy(xscroll, 0);
+ keyboardScroll.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ Log.d(TAG, "smoothScrollBy(2)");
+ keyboardScroll.smoothScrollBy(-xscroll, 0);
+ }
+ }, 1000);
+ }
+ }, 1000);
+
tabs = (TabLayout) findViewById(R.id.tabs);
if (tabs != null)
tabs.setupWithViewPager(pager);
@@ -855,26 +933,26 @@ public class ConsoleActivity extends Activity implements BridgeDisconnectedListe
final View resizeView = inflater.inflate(R.layout.dia_resize, null, false);
new AlertDialog.Builder(ConsoleActivity.this)
- .setView(resizeView)
- .setPositiveButton(R.string.button_resize, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- int width, height;
- try {
- width = Integer.parseInt(((EditText) resizeView
- .findViewById(R.id.width))
- .getText().toString());
- height = Integer.parseInt(((EditText) resizeView
- .findViewById(R.id.height))
- .getText().toString());
- } catch (NumberFormatException nfe) {
- // TODO change this to a real dialog where we can
- // make the input boxes turn red to indicate an error.
- return;
+ .setView(resizeView)
+ .setPositiveButton(R.string.button_resize, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ int width, height;
+ try {
+ width = Integer.parseInt(((EditText) resizeView
+ .findViewById(R.id.width))
+ .getText().toString());
+ height = Integer.parseInt(((EditText) resizeView
+ .findViewById(R.id.height))
+ .getText().toString());
+ } catch (NumberFormatException nfe) {
+ // TODO change this to a real dialog where we can
+ // make the input boxes turn red to indicate an error.
+ return;
+ }
+
+ terminalView.forceSize(width, height);
}
-
- terminalView.forceSize(width, height);
- }
- }).setNegativeButton(android.R.string.cancel, null).create().show();
+ }).setNegativeButton(android.R.string.cancel, null).create().show();
return true;
}
@@ -919,13 +997,13 @@ public class ConsoleActivity extends Activity implements BridgeDisconnectedListe
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case android.R.id.home:
- Intent intent = new Intent(this, HostListActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
- return true;
- default:
- return super.onOptionsItemSelected(item);
+ case android.R.id.home:
+ Intent intent = new Intent(this, HostListActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ startActivity(intent);
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
}
}
diff --git a/app/src/main/res/layout-large/act_console.xml b/app/src/main/res/layout-large/act_console.xml
index 1f8c51f..ea40714 100644
--- a/app/src/main/res/layout-large/act_console.xml
+++ b/app/src/main/res/layout-large/act_console.xml
@@ -26,27 +26,27 @@
android:background="#ff000000">
<android.support.v7.widget.Toolbar
+ android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:id="@+id/toolbar"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:background="#222222"
android:textAppearance="?android:attr/textAppearanceMedium"
- app:tabIndicatorColor="@android:color/white"
- android:background="#222222"/>
+ app:tabIndicatorColor="@android:color/white"/>
<TextView
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:text="@string/terminal_no_hosts_connected"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ android:layout_below="@id/toolbar"
android:gravity="center"
- android:layout_below="@id/toolbar"/>
+ android:text="@string/terminal_no_hosts_connected"
+ android:textAppearance="?android:attr/textAppearanceMedium"/>
<android.support.v4.view.ViewPager
android:id="@+id/console_flip"
@@ -60,29 +60,29 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
- android:padding="5dip"
android:background="#80000000"
android:fadingEdge="horizontal"
android:fadingEdgeLength="25dip"
+ android:padding="5dip"
android:visibility="gone"
>
<TextView
android:id="@+id/console_password_instructions"
+ android:layout_width="fill_parent"
android:layout_height="wrap_content"
+ android:layout_marginBottom="5dip"
android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_width="fill_parent"
android:visibility="gone"
- android:layout_marginBottom="5dip"
/>
<EditText
android:id="@+id/console_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
+ android:layout_below="@+id/console_password_instructions"
android:password="true"
android:singleLine="true"
- android:layout_below="@+id/console_password_instructions"
/>
</RelativeLayout>
@@ -92,46 +92,46 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
- android:padding="5dip"
android:background="#80000000"
android:fadingEdge="horizontal"
android:fadingEdgeLength="25dip"
+ android:padding="5dip"
android:visibility="gone"
>
<TextView
android:id="@+id/console_prompt"
- android:layout_height="wrap_content"
android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<Button
android:id="@+id/console_prompt_no"
- android:text="@string/button_no"
- android:paddingTop="5dip"
- android:paddingBottom="10dip"
- android:paddingLeft="40dip"
- android:paddingRight="40dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/console_prompt"
android:clickable="false"
+ android:paddingBottom="10dip"
+ android:paddingLeft="40dip"
+ android:paddingRight="40dip"
+ android:paddingTop="5dip"
+ android:text="@string/button_no"
/>
<Button
android:id="@+id/console_prompt_yes"
- android:text="@string/button_yes"
- android:paddingTop="5dip"
- android:paddingBottom="10dip"
- android:paddingLeft="40dip"
- android:paddingRight="40dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_toLeftOf="@+id/console_prompt_no"
android:layout_below="@+id/console_prompt"
+ android:layout_toLeftOf="@+id/console_prompt_no"
+ android:paddingBottom="10dip"
+ android:paddingLeft="40dip"
+ android:paddingRight="40dip"
+ android:paddingTop="5dip"
+ android:text="@string/button_yes"
/>
</RelativeLayout>
diff --git a/app/src/main/res/layout/act_console.xml b/app/src/main/res/layout/act_console.xml
index a734882..8d29942 100644
--- a/app/src/main/res/layout/act_console.xml
+++ b/app/src/main/res/layout/act_console.xml
@@ -19,104 +19,104 @@
-->
<RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#ff000000">
-
- <TextView
- android:id="@android:id/empty"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:text="@string/terminal_no_hosts_connected"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:gravity="center"/>
+ android:background="#ff000000">
+
+ <TextView
+ android:id="@android:id/empty"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:gravity="center"
+ android:text="@string/terminal_no_hosts_connected"
+ android:textAppearance="?android:attr/textAppearanceMedium"/>
<android.support.v4.view.ViewPager
- android:id="@+id/console_flip"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- />
+ android:id="@+id/console_flip"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ />
<RelativeLayout
- android:id="@+id/console_password_group"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:padding="5dip"
- android:background="#80000000"
- android:fadingEdge="horizontal"
- android:fadingEdgeLength="25dip"
- android:visibility="gone"
- >
-
- <TextView
- android:id="@+id/console_password_instructions"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ android:id="@+id/console_password_group"
android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:background="#80000000"
+ android:fadingEdge="horizontal"
+ android:fadingEdgeLength="25dip"
+ android:padding="5dip"
android:visibility="gone"
- android:layout_marginBottom="5dip"
- />
+ >
+
+ <TextView
+ android:id="@+id/console_password_instructions"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="5dip"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:visibility="gone"
+ />
<EditText
- android:id="@+id/console_password"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:password="true"
- android:singleLine="true"
- android:layout_below="@+id/console_password_instructions"
- />
+ android:id="@+id/console_password"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@+id/console_password_instructions"
+ android:password="true"
+ android:singleLine="true"
+ />
</RelativeLayout>
<RelativeLayout
- android:id="@+id/console_boolean_group"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:padding="5dip"
- android:background="#80000000"
- android:fadingEdge="horizontal"
- android:fadingEdgeLength="25dip"
- android:visibility="gone"
- >
+ android:id="@+id/console_boolean_group"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:background="#80000000"
+ android:fadingEdge="horizontal"
+ android:fadingEdgeLength="25dip"
+ android:padding="5dip"
+ android:visibility="gone"
+ >
<TextView
- android:id="@+id/console_prompt"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:textAppearance="?android:attr/textAppearanceMedium"
- />
+ android:id="@+id/console_prompt"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ />
<Button
- android:id="@+id/console_prompt_no"
- android:text="@string/button_no"
- android:paddingTop="5dip"
- android:paddingBottom="10dip"
- android:paddingLeft="40dip"
- android:paddingRight="40dip"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentEnd="true"
- android:layout_alignParentRight="true"
- android:layout_below="@+id/console_prompt"
- android:clickable="false"
- />
+ android:id="@+id/console_prompt_no"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentEnd="true"
+ android:layout_alignParentRight="true"
+ android:layout_below="@+id/console_prompt"
+ android:clickable="false"
+ android:paddingBottom="10dip"
+ android:paddingLeft="40dip"
+ android:paddingRight="40dip"
+ android:paddingTop="5dip"
+ android:text="@string/button_no"
+ />
<Button
- android:id="@+id/console_prompt_yes"
- android:text="@string/button_yes"
- android:paddingTop="5dip"
- android:paddingBottom="10dip"
- android:paddingLeft="40dip"
- android:paddingRight="40dip"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toLeftOf="@+id/console_prompt_no"
- android:layout_below="@+id/console_prompt"
- />
+ android:id="@+id/console_prompt_yes"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@+id/console_prompt"
+ android:layout_toLeftOf="@+id/console_prompt_no"
+ android:paddingBottom="10dip"
+ android:paddingLeft="40dip"
+ android:paddingRight="40dip"
+ android:paddingTop="5dip"
+ android:text="@string/button_yes"
+ />
</RelativeLayout>