diff options
author | Kenny Root <kenny@the-b.org> | 2015-08-23 22:48:01 -0700 |
---|---|---|
committer | Kenny Root <kenny@the-b.org> | 2015-08-23 22:48:01 -0700 |
commit | 84ac082cbd1e31ac1a5646bc9a733bb305781016 (patch) | |
tree | 82f69045d890a2501baca65f310a43684d516630 /app/src/main/java/org/connectbot/ConsoleActivity.java | |
parent | 2656c48899c6c2abc9ed51f9694968351673a040 (diff) | |
parent | 5f52f3ec4ce648e7afbcf5156ffa45a985956e0d (diff) | |
download | connectbot-84ac082cbd1e31ac1a5646bc9a733bb305781016.tar.gz connectbot-84ac082cbd1e31ac1a5646bc9a733bb305781016.tar.bz2 connectbot-84ac082cbd1e31ac1a5646bc9a733bb305781016.zip |
Merge pull request #147 from kruton/merge-hscroll
Merge hscroll change from @alescdb
Diffstat (limited to 'app/src/main/java/org/connectbot/ConsoleActivity.java')
-rw-r--r-- | app/src/main/java/org/connectbot/ConsoleActivity.java | 229 |
1 files changed, 192 insertions, 37 deletions
diff --git a/app/src/main/java/org/connectbot/ConsoleActivity.java b/app/src/main/java/org/connectbot/ConsoleActivity.java index 6f72783..9ac0c95 100644 --- a/app/src/main/java/org/connectbot/ConsoleActivity.java +++ b/app/src/main/java/org/connectbot/ConsoleActivity.java @@ -84,6 +84,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,7 +100,9 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne private static final int CLICK_TIME = 400; private static final float MAX_CLICK_DISTANCE = 25f; - private static final int KEYBOARD_DISPLAY_TIME = 1500; + 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; @@ -216,38 +219,143 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne } }; + 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) { + if (BuildConfig.DEBUG) { + 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; TerminalKeyListener handler = terminal.bridge.getKeyHandler(); - boolean hideKeys = true; + boolean hideKeys = false; - switch (v.getId()) { + switch (v.getId()) { case R.id.button_ctrl: handler.metaPress(TerminalKeyListener.OUR_CTRL_ON, true); + hideKeys = true; break; case R.id.button_esc: handler.sendEscape(); + hideKeys = true; break; case R.id.button_tab: handler.sendTab(); + hideKeys = true; break; + case R.id.button_up: handler.sendPressedKey(vt320.KEY_UP); - hideKeys = false; break; case R.id.button_down: handler.sendPressedKey(vt320.KEY_DOWN); - hideKeys = false; break; case R.id.button_left: handler.sendPressedKey(vt320.KEY_LEFT); - hideKeys = false; break; case R.id.button_right: handler.sendPressedKey(vt320.KEY_RIGHT); - hideKeys = false; + break; + + case R.id.button_home: + handler.sendPressedKey(vt320.KEY_HOME); + break; + case R.id.button_end: + handler.sendPressedKey(vt320.KEY_END); + break; + case R.id.button_pgup: + handler.sendPressedKey(vt320.KEY_PAGE_UP); + break; + case R.id.button_pgdn: + handler.sendPressedKey(vt320.KEY_PAGE_DOWN); + break; + + case R.id.button_f1: + handler.sendPressedKey(vt320.KEY_F1); + break; + case R.id.button_f2: + handler.sendPressedKey(vt320.KEY_F2); + break; + case R.id.button_f3: + handler.sendPressedKey(vt320.KEY_F3); + break; + case R.id.button_f4: + handler.sendPressedKey(vt320.KEY_F4); + break; + case R.id.button_f5: + handler.sendPressedKey(vt320.KEY_F5); + break; + case R.id.button_f6: + handler.sendPressedKey(vt320.KEY_F6); + break; + case R.id.button_f7: + handler.sendPressedKey(vt320.KEY_F7); + break; + case R.id.button_f8: + handler.sendPressedKey(vt320.KEY_F8); + break; + case R.id.button_f9: + handler.sendPressedKey(vt320.KEY_F9); + break; + case R.id.button_f10: + handler.sendPressedKey(vt320.KEY_F10); + break; + case R.id.button_f11: + handler.sendPressedKey(vt320.KEY_F11); + break; + case R.id.button_f12: + handler.sendPressedKey(vt320.KEY_F12); break; } @@ -257,6 +365,9 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne autoHideEmulatedKeys(); terminal.bridge.tryKeyVibrate(); + if (titleBarHide) { + actionBar.hide(); + } } /** @@ -447,10 +558,29 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne 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); + findViewById(R.id.button_pgdn).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f1).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f2).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f3).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f4).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f5).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f6).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f7).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f8).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f9).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f10).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f11).setOnClickListener(emulatedKeysListener); + findViewById(R.id.button_f12).setOnClickListener(emulatedKeysListener); + actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); @@ -466,6 +596,31 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne } }); + if (!hardKeyboard) { + // 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 = findViewById(R.id.button_f12).getRight(); + if (BuildConfig.DEBUG) { + Log.d(TAG, "smoothScrollBy(toEnd[" + xscroll + "])"); + } + keyboardScroll.smoothScrollBy(xscroll, 0); + keyboardScroll.postDelayed(new Runnable() { + @Override + public void run() { + if (BuildConfig.DEBUG) { + Log.d(TAG, "smoothScrollBy(toStart[" + (-xscroll) + "])"); + } + keyboardScroll.smoothScrollBy(-xscroll, 0); + } + }, 1000); + } + }, 1000); + } + tabs = (TabLayout) findViewById(R.id.tabs); if (tabs != null) tabs.setupWithViewPager(pager); @@ -787,26 +942,26 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne 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; } @@ -851,13 +1006,13 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne @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); } } |