From 9759a0c23ad865f6815b9af01a611ca38984f865 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Thu, 2 Jul 2009 06:03:34 +0000 Subject: Allow tap on screen to bring up an icon to open the software keyboard when the hardware keyboard is hidden git-svn-id: https://connectbot.googlecode.com/svn/trunk/connectbot@348 df292f66-193f-0410-a5fc-6d59da041ff2 --- AndroidManifest.xml | 2 +- res/anim/fade_out.xml | 8 ---- res/anim/fade_out_delayed.xml | 8 ++++ res/anim/fade_stay_hidden.xml | 14 +++---- res/anim/keyboard_fade_in.xml | 6 +++ res/anim/keyboard_fade_out.xml | 6 +++ res/drawable/keyboard_icon.png | Bin 0 -> 3326 bytes res/layout/act_console.xml | 12 ++++++ src/org/connectbot/ConsoleActivity.java | 66 +++++++++++++++++++++++++++++--- 9 files changed, 100 insertions(+), 22 deletions(-) delete mode 100644 res/anim/fade_out.xml create mode 100644 res/anim/fade_out_delayed.xml create mode 100644 res/anim/keyboard_fade_in.xml create mode 100644 res/anim/keyboard_fade_out.xml create mode 100644 res/drawable/keyboard_icon.png diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 3d67214..7bc7a96 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionCode="156"> diff --git a/res/anim/fade_out_delayed.xml b/res/anim/fade_out_delayed.xml new file mode 100644 index 0000000..ab7703c --- /dev/null +++ b/res/anim/fade_out_delayed.xml @@ -0,0 +1,8 @@ + + diff --git a/res/anim/fade_stay_hidden.xml b/res/anim/fade_stay_hidden.xml index bfda0d3..a48621a 100644 --- a/res/anim/fade_stay_hidden.xml +++ b/res/anim/fade_stay_hidden.xml @@ -1,7 +1,7 @@ - + + diff --git a/res/anim/keyboard_fade_in.xml b/res/anim/keyboard_fade_in.xml new file mode 100644 index 0000000..f1ceea7 --- /dev/null +++ b/res/anim/keyboard_fade_in.xml @@ -0,0 +1,6 @@ + + diff --git a/res/anim/keyboard_fade_out.xml b/res/anim/keyboard_fade_out.xml new file mode 100644 index 0000000..3c57404 --- /dev/null +++ b/res/anim/keyboard_fade_out.xml @@ -0,0 +1,6 @@ + + diff --git a/res/drawable/keyboard_icon.png b/res/drawable/keyboard_icon.png new file mode 100644 index 0000000..9205d8b Binary files /dev/null and b/res/drawable/keyboard_icon.png differ diff --git a/res/layout/act_console.xml b/res/layout/act_console.xml index 6dc0968..4d5fd7c 100644 --- a/res/layout/act_console.xml +++ b/res/layout/act_console.xml @@ -118,4 +118,16 @@ + + diff --git a/src/org/connectbot/ConsoleActivity.java b/src/org/connectbot/ConsoleActivity.java index bd66b3b..6f59a57 100644 --- a/src/org/connectbot/ConsoleActivity.java +++ b/src/org/connectbot/ConsoleActivity.java @@ -61,8 +61,10 @@ import android.view.View.OnKeyListener; import android.view.View.OnTouchListener; import android.view.animation.Animation; import android.view.animation.AnimationUtils; +import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; +import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; @@ -77,6 +79,10 @@ public class ConsoleActivity extends Activity { protected static final int REQUEST_EDIT = 1; + private static final int CLICK_TIME = 250; + private static final float MAX_CLICK_DISTANCE = 25f; + private static final int KEYBOARD_DISPLAY_TIME = 1250; + protected ViewFlipper flip = null; protected TerminalManager bound = null; protected LayoutInflater inflater = null; @@ -98,7 +104,13 @@ public class ConsoleActivity extends Activity { private TextView empty; - private Animation slide_left_in, slide_left_out, slide_right_in, slide_right_out, fade_stay_hidden, fade_out; + private Animation slide_left_in, slide_left_out, slide_right_in, slide_right_out, fade_stay_hidden, fade_out_delayed; + + private Animation keyboard_fade_in, keyboard_fade_out; + private ImageView keyboardButton; + private float lastX, lastY; + + private InputMethodManager inputManager; private MenuItem disconnect, copy, paste, portForward, resize; @@ -107,6 +119,8 @@ public class ConsoleActivity extends Activity { private boolean forcedOrientation; + private Handler handler = new Handler(); + private ServiceConnection connection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { bound = ((TerminalManager.TerminalBinder) service).getService(); @@ -170,7 +184,7 @@ public class ConsoleActivity extends Activity { try { // show the requested bridge if found, also fade out overlay flip.setDisplayedChild(requestedIndex); - flip.getCurrentView().findViewById(R.id.terminal_overlay).startAnimation(fade_out); + flip.getCurrentView().findViewById(R.id.terminal_overlay).startAnimation(fade_out_delayed); } catch (NullPointerException npe) { Log.d(TAG, "View went away when we were about to display it", npe); } @@ -375,9 +389,26 @@ public class ConsoleActivity extends Activity { slide_right_in = AnimationUtils.loadAnimation(this, R.anim.slide_right_in); slide_right_out = AnimationUtils.loadAnimation(this, R.anim.slide_right_out); - fade_out = AnimationUtils.loadAnimation(this, R.anim.fade_out); + fade_out_delayed = AnimationUtils.loadAnimation(this, R.anim.fade_out_delayed); fade_stay_hidden = AnimationUtils.loadAnimation(this, R.anim.fade_stay_hidden); + // Preload animation for keyboard button + keyboard_fade_in = AnimationUtils.loadAnimation(this, R.anim.keyboard_fade_in); + keyboard_fade_out = AnimationUtils.loadAnimation(this, R.anim.keyboard_fade_out); + + inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + keyboardButton = (ImageView) findViewById(R.id.keyboard_button); + keyboardButton.setOnClickListener(new OnClickListener() { + public void onClick(View view) { + View flip = findCurrentView(R.id.console_flip); + if (flip == null) + return; + + inputManager.showSoftInput(flip, InputMethodManager.SHOW_FORCED); + keyboardButton.setVisibility(View.GONE); + } + }); + // detect fling gestures to switch between terminals final GestureDetector detect = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { private float totalY = 0; @@ -530,8 +561,31 @@ public class ConsoleActivity extends Activity { copySource.redraw(); return true; } + } - + Configuration config = getResources().getConfiguration(); + + if (event.getAction() == MotionEvent.ACTION_DOWN) { + lastX = event.getX(); + lastY = event.getY(); + } else if (event.getAction() == MotionEvent.ACTION_UP + && config.hardKeyboardHidden != Configuration.KEYBOARDHIDDEN_NO + && keyboardButton.getVisibility() == View.GONE + && event.getEventTime() - event.getDownTime() < CLICK_TIME + && Math.abs(event.getX() - lastX) < MAX_CLICK_DISTANCE + && Math.abs(event.getY() - lastY) < MAX_CLICK_DISTANCE) { + keyboardButton.startAnimation(keyboard_fade_in); + keyboardButton.setVisibility(View.VISIBLE); + + handler.postDelayed(new Runnable() { + public void run() { + if (keyboardButton.getVisibility() == View.GONE) + return; + + keyboardButton.startAnimation(keyboard_fade_out); + keyboardButton.setVisibility(View.GONE); + } + }, KEYBOARD_DISPLAY_TIME); } // pass any touch events back to detector @@ -797,7 +851,7 @@ public class ConsoleActivity extends Activity { // show overlay on new slide and start fade overlay = findCurrentView(R.id.terminal_overlay); if (overlay != null) - overlay.startAnimation(fade_out); + overlay.startAnimation(fade_out_delayed); } updatePromptVisible(); @@ -825,7 +879,7 @@ public class ConsoleActivity extends Activity { // show overlay on new slide and start fade overlay = findCurrentView(R.id.terminal_overlay); if (overlay != null) - overlay.startAnimation(fade_out); + overlay.startAnimation(fade_out_delayed); } updatePromptVisible(); -- cgit v1.2.3