From 5b1352c54c66fbe3307e7ff22e0543dc47f76da6 Mon Sep 17 00:00:00 2001 From: Jeffrey Sharkey Date: Sun, 24 Aug 2008 23:07:29 +0000 Subject: * Fixing an off-by-one error in vt320 for ANSI 'U' escape sequences.Was messing up scrollback on irssi sessions. * Filling buffer will ' ' (spaces) instead of null characters. Android's MONOSPACE font doesn't render the null correctly; might be trying to interpret them as unicode. Was messing up indentation on rtorrent sessions. * Removed SoftFont from redraw() and sped things up immensely. Everything seems to still render fine, was there a reason we needed the SoftFont? * Corrected buffer.update[] handling so we aren't repainting entire screen each time; much faster now. * Added OpenGL rendering by default, but doesn't change speed on emulator. --- src/de/mud/terminal/SoftFont.java | 3 +- src/de/mud/terminal/VDUBuffer.java | 16 ++++- src/de/mud/terminal/VDUInput.java | 5 +- src/de/mud/terminal/vt320.java | 6 +- src/org/theb/provider/HostDb.java | 1 + src/org/theb/ssh/HostDbProvider.java | 11 ++- src/org/theb/ssh/HostEditor.java | 9 +-- src/org/theb/ssh/HostsList.java | 99 ++++++++++++++------------- src/org/theb/ssh/JCTerminalView.java | 11 +-- src/org/theb/ssh/JTATerminalView.java | 89 +++++++++++++++--------- src/org/theb/ssh/PasswordDialog.java | 5 +- src/org/theb/ssh/Pubkey.java | 14 ++-- src/org/theb/ssh/SecureShell.java | 36 +++++----- src/org/theb/ssh/Terminal.java | 1 + src/org/theb/ssh/TouchEntropy.java | 5 +- src/org/theb/ssh/TrileadConnectionThread.java | 2 +- 16 files changed, 189 insertions(+), 124 deletions(-) (limited to 'src') diff --git a/src/de/mud/terminal/SoftFont.java b/src/de/mud/terminal/SoftFont.java index bd25a60..e5da3db 100644 --- a/src/de/mud/terminal/SoftFont.java +++ b/src/de/mud/terminal/SoftFont.java @@ -1,7 +1,7 @@ /* * This file is part of "JTA - Telnet/SSH for the JAVA(tm) platform". * - * (c) Matthias L. Jugel, Marcus Meißner 1996-2005. All Rights Reserved. + * (c) Matthias L. Jugel, Marcus Meiner 1996-2005. All Rights Reserved. * * Please visit http://javatelnet.org/ for updates and contact. * @@ -43,6 +43,7 @@ public class SoftFont { final static private char SF_BITMAP = 0; final static private char SF_FILLRECT = 1; + //final static private char SF_CHAR = 0; final static private char SF_WIDTH= 1; final static private char SF_HEIGHT= 2; diff --git a/src/de/mud/terminal/VDUBuffer.java b/src/de/mud/terminal/VDUBuffer.java index a4f8244..ffd9127 100644 --- a/src/de/mud/terminal/VDUBuffer.java +++ b/src/de/mud/terminal/VDUBuffer.java @@ -1,7 +1,7 @@ /* * This file is part of "JTA - Telnet/SSH for the JAVA(tm) platform". * - * (c) Matthias L. Jugel, Marcus Meißner 1996-2005. All Rights Reserved. + * (c) Matthias L. Jugel, Marcus Meiner 1996-2005. All Rights Reserved. * * Please visit http://javatelnet.org/ for updates and contact. * @@ -25,12 +25,15 @@ package de.mud.terminal; +import java.util.Arrays; +import android.util.Log; + /** * Implementation of a Video Display Unit (VDU) buffer. This class contains * all methods to manipulate the buffer that stores characters and their * attributes as well as the regions displayed. * - * @author Matthias L. Jugel, Marcus Mei�ner + * @author Matthias L. Jugel, Marcus Meiner * @version $Id: VDUBuffer.java 503 2005-10-24 07:34:13Z marcus $ */ public class VDUBuffer { @@ -504,6 +507,8 @@ public class VDUBuffer { char cbuf[] = new char[w]; int abuf[] = new int[w]; + Arrays.fill(cbuf, ' '); + for (int i = 0; i < w; i++) abuf[i] = curAttr; for (int i = 0; i < h && l + i < height; i++) { System.arraycopy(cbuf, 0, charArray[screenBase + l + i], c, w); @@ -530,6 +535,8 @@ public class VDUBuffer { char cbuf[] = new char[w]; int abuf[] = new int[w]; + Arrays.fill(cbuf, ' '); + for (int i = 0; i < h && l + i < height; i++) { System.arraycopy(cbuf, 0, charArray[screenBase + l + i], c, w); System.arraycopy(abuf, 0, charAttributes[screenBase + l + i], c, w); @@ -727,6 +734,11 @@ public class VDUBuffer { cbuf = new char[bufSize][w]; abuf = new int[bufSize][w]; + + for (int i = 0; i < bufSize; i++) { + Arrays.fill(cbuf[i], ' '); + } + if (charArray != null && charAttributes != null) { for (int i = 0; i < bsize && i < bufSize; i++) { System.arraycopy(charArray[i], 0, cbuf[i], 0, diff --git a/src/de/mud/terminal/VDUInput.java b/src/de/mud/terminal/VDUInput.java index 79a8bb7..2aa2496 100644 --- a/src/de/mud/terminal/VDUInput.java +++ b/src/de/mud/terminal/VDUInput.java @@ -1,7 +1,7 @@ /* * This file is part of "JTA - Telnet/SSH for the JAVA(tm) platform". * - * (c) Matthias L. Jugel, Marcus Meißner 1996-2005. All Rights Reserved. + * (c) Matthias L. Jugel, Marcus Meiner 1996-2005. All Rights Reserved. * * Please visit http://javatelnet.org/ for updates and contact. * @@ -29,7 +29,7 @@ import java.util.Properties; /** * An interface for a terminal that accepts input from keyboard and mouse. * - * @author Matthias L. Jugel, Marcus Mei�ner + * @author Matthias L. Jugel, Marcus Meiner * @version $Id: VDUInput.java 499 2005-09-29 08:24:54Z leo $ */ public interface VDUInput { @@ -40,6 +40,7 @@ public interface VDUInput { public final static int KEY_ACTION = 0x08; + /** * Direct access to writing data ... * @param b diff --git a/src/de/mud/terminal/vt320.java b/src/de/mud/terminal/vt320.java index 099c877..483c665 100644 --- a/src/de/mud/terminal/vt320.java +++ b/src/de/mud/terminal/vt320.java @@ -1,7 +1,7 @@ /* * This file is part of "JTA - Telnet/SSH for the JAVA(tm) platform". * - * (c) Matthias L. Jugel, Marcus Meißner 1996-2005. All Rights Reserved. + * (c) Matthias L. Jugel, Marcus Meiner 1996-2005. All Rights Reserved. * * Please visit http://javatelnet.org/ for updates and contact. * @@ -36,6 +36,7 @@ import java.util.Properties; * @author Matthias L. Jugel, Marcus Mei\u00dfner */ public abstract class vt320 extends VDUBuffer implements VDUInput { + /** The current version id tag.

* $Id: vt320.java 507 2005-10-25 10:14:52Z marcus $ */ @@ -78,6 +79,7 @@ public abstract class vt320 extends VDUBuffer implements VDUInput { } protected void sendTelnetCommand(byte cmd) { + } /** @@ -2326,7 +2328,7 @@ public abstract class vt320 extends VDUBuffer implements VDUInput { int limit; /* FIXME: xterm only cares about 0 and topmargin */ if (R > bm) - limit = bm + 1; + limit = bm; // BUGFIX: corrects scrollback dissapearing in irssi else if (R >= tm) { limit = tm; } else diff --git a/src/org/theb/provider/HostDb.java b/src/org/theb/provider/HostDb.java index 9939893..3a15c8f 100644 --- a/src/org/theb/provider/HostDb.java +++ b/src/org/theb/provider/HostDb.java @@ -18,6 +18,7 @@ */ package org.theb.provider; + import android.net.Uri; import android.provider.BaseColumns; diff --git a/src/org/theb/ssh/HostDbProvider.java b/src/org/theb/ssh/HostDbProvider.java index c51a356..ecb0eed 100644 --- a/src/org/theb/ssh/HostDbProvider.java +++ b/src/org/theb/ssh/HostDbProvider.java @@ -25,12 +25,14 @@ import org.theb.provider.HostDb; import android.content.ContentProvider; import android.content.ContentUris; import android.content.ContentValues; +import android.content.Context; import android.content.UriMatcher; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteQueryBuilder; +import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.net.Uri; import android.text.TextUtils; import android.util.Log; @@ -52,6 +54,11 @@ public class HostDbProvider extends ContentProvider { private static class DatabaseHelper extends SQLiteOpenHelper { + public DatabaseHelper(Context context, String name, + CursorFactory factory, int version) { + super(context, name, factory, version); + } + @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE hosts (_id INTEGER PRIMARY KEY," @@ -148,8 +155,8 @@ public class HostDbProvider extends ContentProvider { @Override public boolean onCreate() { - DatabaseHelper dbHelper = new DatabaseHelper(); - mDB = dbHelper.openDatabase(getContext(), DATABASE_NAME, null, DATABASE_VERSION); + DatabaseHelper dbHelper = new DatabaseHelper(getContext(), DATABASE_NAME, null, DATABASE_VERSION); + mDB = dbHelper.getWritableDatabase(); return (mDB == null) ? false : true; } diff --git a/src/org/theb/ssh/HostEditor.java b/src/org/theb/ssh/HostEditor.java index a8a6de7..d9618eb 100644 --- a/src/org/theb/ssh/HostEditor.java +++ b/src/org/theb/ssh/HostEditor.java @@ -74,7 +74,7 @@ public class HostEditor extends Activity { // way is more efficient than using a translucent background. Note // that the tint color really should come from a resource. WindowManager.LayoutParams lp = getWindow().getAttributes(); - lp.tintBehind = 0x60000820; + //lp.tintBehind = 0x60000820; getWindow().setAttributes(lp); this.setContentView(R.layout.host_editor); @@ -95,7 +95,7 @@ public class HostEditor extends Activity { // Do some setup based on the action being performed. final String action = intent.getAction(); - if (Intent.INSERT_ACTION.equals(action)) { + if (Intent.ACTION_INSERT.equals(action)) { mState = STATE_INSERT; mURI = getContentResolver().insert(intent.getData(), null); @@ -111,7 +111,8 @@ public class HostEditor extends Activity { // The new entry was created, so assume all will end well and // set the result to be returned. - setResult(RESULT_OK, mURI.toString()); + intent.putExtra(Intent.EXTRA_TEXT, mURI.toString()); + setResult(RESULT_OK, intent); } else { // Editing is the default state. mState = STATE_EDIT; @@ -133,7 +134,7 @@ public class HostEditor extends Activity { // Initialize the text with the host data if (mCursor != null) { - mCursor.first(); + mCursor.moveToFirst(); String hostname = mCursor.getString(HOSTNAME_INDEX); mHostname.setText(hostname); diff --git a/src/org/theb/ssh/HostsList.java b/src/org/theb/ssh/HostsList.java index 6f30f45..34f9a7b 100644 --- a/src/org/theb/ssh/HostsList.java +++ b/src/org/theb/ssh/HostsList.java @@ -31,6 +31,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.view.Menu; +import android.view.MenuItem; import android.view.SubMenu; import android.view.View; import android.view.WindowManager; @@ -96,14 +97,14 @@ public class HostsList extends ListActivity { public void onCreate(Bundle icicle) { super.onCreate(icicle); - setDefaultKeyMode(SHORTCUT_DEFAULT_KEYS); + setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT); Intent intent = getIntent(); if (intent.getData() == null) { intent.setData(HostDb.Hosts.CONTENT_URI); } - setupListStripes(); + //setupListStripes(); mCursor = managedQuery(getIntent().getData(), PROJECTION, null, null); @@ -114,29 +115,29 @@ public class HostsList extends ListActivity { setListAdapter(adapter); } - /** - * Add stripes to the list view. - */ - private void setupListStripes() { - // Get Drawables for alternating stripes - Drawable[] lineBackgrounds = new Drawable[2]; - - lineBackgrounds[0] = getResources().getDrawable(R.drawable.even_stripe); - lineBackgrounds[1] = getResources().getDrawable(R.drawable.odd_stripe); - - // Make and measure a sample TextView of the sort our adapter will - // return - View view = getViewInflate().inflate( - android.R.layout.simple_list_item_1, null, null); - - TextView v = (TextView) view.findViewById(android.R.id.text1); - v.setText("X"); - // Make it 100 pixels wide, and let it choose its own height. - v.measure(MeasureSpec.makeMeasureSpec(View.MeasureSpec.EXACTLY, 100), - MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, 0)); - int height = v.getMeasuredHeight(); - getListView().setStripes(lineBackgrounds, height); - } +// /** +// * Add stripes to the list view. +// */ +// private void setupListStripes() { +// // Get Drawables for alternating stripes +// Drawable[] lineBackgrounds = new Drawable[2]; +// +// lineBackgrounds[0] = getResources().getDrawable(R.drawable.even_stripe); +// lineBackgrounds[1] = getResources().getDrawable(R.drawable.odd_stripe); +// +// // Make and measure a sample TextView of the sort our adapter will +// // return +// View view = getViewInflate().inflate( +// android.R.layout.simple_list_item_1, null, null); +// +// TextView v = (TextView) view.findViewById(android.R.id.text1); +// v.setText("X"); +// // Make it 100 pixels wide, and let it choose its own height. +// v.measure(MeasureSpec.makeMeasureSpec(View.MeasureSpec.EXACTLY, 100), +// MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, 0)); +// int height = v.getMeasuredHeight(); +// getListView().setStripes(lineBackgrounds, height); +// } @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -144,25 +145,25 @@ public class HostsList extends ListActivity { // This is our one standard application action -- inserting a // new host into the list. - menu.add(0, INSERT_ID, R.string.menu_insert) + menu.add(0, INSERT_ID, Menu.NONE, R.string.menu_insert) .setShortcut('3', 'a'); // The preferences link allows users to e.g. set the pubkey - SubMenu prefs = menu.addSubMenu(0, 0, R.string.menu_preferences); - prefs.add(0, PUBKEY_ID, R.string.menu_pubkey) + SubMenu prefs = menu.addSubMenu(0, 0, Menu.NONE, R.string.menu_preferences); + prefs.add(0, PUBKEY_ID, Menu.NONE, R.string.menu_pubkey) .setShortcut('4', 'p'); // This links to the about dialog for the program. - menu.add(0, ABOUT_ID, R.string.menu_about); + menu.add(0, ABOUT_ID, Menu.NONE, R.string.menu_about); // Generate any additional actions that can be performed on the // overall list. In a normal install, there are no additional // actions found here, but this allows other applications to extend // our menu with their own actions. Intent intent = new Intent(null, getIntent().getData()); - intent.addCategory(Intent.ALTERNATIVE_CATEGORY); + intent.addCategory(Intent.CATEGORY_ALTERNATIVE); menu.addIntentOptions( - Menu.ALTERNATIVE, 0, new ComponentName(this, HostsList.class), + Menu.CATEGORY_ALTERNATIVE, 0, Menu.NONE, new ComponentName(this, HostsList.class), null, intent, 0, null); return true; @@ -171,7 +172,7 @@ public class HostsList extends ListActivity { @Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - final boolean haveItems = mCursor.count() > 0; + final boolean haveItems = mCursor.getCount() > 0; // If there are any notes in the list (which implies that one of // them is selected), then we need to generate the actions that @@ -184,17 +185,17 @@ public class HostsList extends ListActivity { // Build menu... always starts with the PICK action... Intent[] specifics = new Intent[1]; - specifics[0] = new Intent(Intent.PICK_ACTION, uri); - Menu.Item[] items = new Menu.Item[1]; + specifics[0] = new Intent(Intent.ACTION_PICK, uri); + MenuItem[] items = new MenuItem[1]; // ... is followed by whatever other actions are available... Intent intent = new Intent(null, uri); - intent.addCategory(Intent.SELECTED_ALTERNATIVE_CATEGORY); - menu.addIntentOptions(Menu.SELECTED_ALTERNATIVE, 0, null, specifics, + intent.addCategory(Intent.CATEGORY_ALTERNATIVE); + menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, Menu.NONE, null, specifics, intent, 0, items); // ... and ends with the delete command. - menu.add(Menu.SELECTED_ALTERNATIVE, DELETE_ID, R.string.menu_delete) + menu.add(Menu.CATEGORY_ALTERNATIVE, DELETE_ID, Menu.NONE, R.string.menu_delete) .setShortcut('2', 'd'); // Give a shortcut to the connect action. @@ -202,17 +203,17 @@ public class HostsList extends ListActivity { items[0].setShortcut('1', 'c'); } } else { - menu.removeGroup(Menu.SELECTED_ALTERNATIVE); + menu.removeGroup(Menu.CATEGORY_ALTERNATIVE); } // Make sure the delete action is disabled if there are no items. - menu.setItemShown(DELETE_ID, haveItems); + //menu.setItemShown(DELETE_ID, haveItems); return true; } @Override - public boolean onOptionsItemSelected(Menu.Item item) { - switch (item.getId()) { + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { case DELETE_ID: deleteItem(); return true; @@ -246,7 +247,7 @@ public class HostsList extends ListActivity { //about.getWindow().setFlags(WindowManager.LayoutParams.BLUR_BEHIND_FLAG, // WindowManager.LayoutParams.BLUR_BEHIND_FLAG); WindowManager.LayoutParams lp = about.getWindow().getAttributes(); - lp.tintBehind = 0x60000820; + //lp.tintBehind = 0x60000820; about.getWindow().setAttributes(lp); about.show(); @@ -257,24 +258,26 @@ public class HostsList extends ListActivity { Uri url = ContentUris.withAppendedId(getIntent().getData(), getSelectedItemId()); String action = getIntent().getAction(); - if (Intent.PICK_ACTION.equals(action) - || Intent.GET_CONTENT_ACTION.equals(action)) { + if (Intent.ACTION_PICK.equals(action) + || Intent.ACTION_GET_CONTENT.equals(action)) { // The caller is waiting for us to return a note selected by // the user. The have clicked on one, so return it now. - setResult(RESULT_OK, url.toString()); + Intent intent = this.getIntent(); + intent.putExtra(Intent.EXTRA_TEXT, url.toString()); + setResult(RESULT_OK, intent); } else { // Launch activity to view/edit the currently selected item - startActivity(new Intent(Intent.PICK_ACTION, url)); + startActivity(new Intent(Intent.ACTION_PICK, url)); } } private final void deleteItem() { - mCursor.moveTo(getSelectedItemPosition()); + mCursor.move(getSelectedItemPosition()); mCursor.deleteRow(); } private final void insertItem() { // Launch activity to insert a new item - startActivity(new Intent(Intent.INSERT_ACTION, getIntent().getData())); + startActivity(new Intent(Intent.ACTION_INSERT, getIntent().getData())); } } \ No newline at end of file diff --git a/src/org/theb/ssh/JCTerminalView.java b/src/org/theb/ssh/JCTerminalView.java index 47d12aa..b76794f 100644 --- a/src/org/theb/ssh/JCTerminalView.java +++ b/src/org/theb/ssh/JCTerminalView.java @@ -29,6 +29,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.PixelXorXfermode; import android.graphics.Typeface; +import android.graphics.Bitmap.Config; import android.graphics.Paint.FontMetricsInt; import android.util.Log; import android.view.KeyEvent; @@ -102,10 +103,10 @@ public class JCTerminalView extends View implements Term, Terminal { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { Log.d("SSH/TerminalView", "onSizeChanged called"); - Bitmap newBitmap = Bitmap.createBitmap(w, h, false); + Bitmap newBitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888); Canvas newCanvas = new Canvas(); - newCanvas.setDevice(newBitmap); + newCanvas.setBitmap(newBitmap); if (mBitmap != null) newCanvas.drawBitmap(mBitmap, 0, 0, mPaint); @@ -155,8 +156,8 @@ public class JCTerminalView extends View implements Term, Terminal { public void clear() { mPaint.setColor(getBackgroundColor()); - mCanvas.drawRect(0, 0, mCanvas.getBitmapWidth(), - mCanvas.getBitmapHeight(), mPaint); + mCanvas.drawRect(0, 0, mCanvas.getWidth(), + mCanvas.getHeight(), mPaint); mPaint.setColor(getForegroundColor()); } @@ -313,7 +314,7 @@ public class JCTerminalView extends View implements Term, Terminal { } public byte[] getKeyCode(int keyCode, int meta) { - if (keyCode == KeyEvent.KEYCODE_NEWLINE) + if (keyCode == KeyEvent.KEYCODE_ENTER) return emulator.getCodeENTER(); else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) return emulator.getCodeLEFT(); diff --git a/src/org/theb/ssh/JTATerminalView.java b/src/org/theb/ssh/JTATerminalView.java index 84e08f7..c28e609 100644 --- a/src/org/theb/ssh/JTATerminalView.java +++ b/src/org/theb/ssh/JTATerminalView.java @@ -16,6 +16,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.PixelXorXfermode; import android.graphics.Typeface; +import android.graphics.Bitmap.Config; import android.graphics.Paint.FontMetricsInt; import android.util.Log; import android.view.KeyEvent; @@ -71,7 +72,7 @@ public class JTATerminalView extends View implements VDUDisplay, Terminal, Runna cursorPaint.setColor(darken(color[COLOR_FG_STD])); cursorPaint.setXfermode(new PixelXorXfermode(color[COLOR_BG_STD])); - setFont(Typeface.MONOSPACE, 8); + setFont(Typeface.MONOSPACE, 10); emulation = new vt320() { public void write(byte[] b) { @@ -113,10 +114,10 @@ public class JTATerminalView extends View implements VDUDisplay, Terminal, Runna @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { Log.d("SSH/TerminalView", "onSizeChanged called"); - Bitmap newBitmap = Bitmap.createBitmap(w, h, false); + Bitmap newBitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888); Canvas newCanvas = new Canvas(); - newCanvas.setDevice(newBitmap); + newCanvas.setBitmap(newBitmap); if (bitmap != null) newCanvas.drawBitmap(bitmap, 0, 0, paint); @@ -172,7 +173,7 @@ public class JTATerminalView extends View implements VDUDisplay, Terminal, Runna public byte[] getKeyCode(int keyCode, int meta) { switch (keyCode) { - case KeyEvent.KEYCODE_NEWLINE: + case KeyEvent.KEYCODE_ENTER: emulation.keyTyped(vt320.KEY_ENTER, ' ', meta); break; case KeyEvent.KEYCODE_DPAD_LEFT: @@ -219,11 +220,30 @@ public class JTATerminalView extends View implements VDUDisplay, Terminal, Runna //int selectEndLine = selectEnd.y - buffer.windowBase; int fg, bg; + + int lines = 0; + long time = System.currentTimeMillis() + 0; + + // paint.setColor(color[COLOR_BG_STD]); + // canvas.drawRect(0, 0, bitmap.getWidth(), bitmap.getHeight(), paint); + // paint.setColor(color[COLOR_FG_STD]); + for (int l = 0; l < buffer.height; l++) { // Check to see if the entire buffer is dirty or if this line is dirty. // If neither is dirty, continue. if (!buffer.update[0] && !buffer.update[l + 1]) continue; + buffer.update[l + 1] = false; + + lines++; + + // assume that we can blindly dump the terminal string + // canvas.drawText(buffer.charArray[buffer.windowBase + l], + // 0, buffer.charArray[buffer.windowBase + l].length, + // 0 * charWidth + xoffset, + // (l + 1) * charHeight - charDescent + yoffset, + // paint); + for (int c = 0; c < buffer.width; c++) { int addr = 0; @@ -234,11 +254,11 @@ public class JTATerminalView extends View implements VDUDisplay, Terminal, Runna // Check if foreground color attribute is set. if ((currAttr & VDUBuffer.COLOR_FG) != 0) - fg = darken(color[((currAttr & VDUBuffer.COLOR_FG) >> VDUBuffer.COLOR_FG_SHIFT) - 1]); + fg = (color[((currAttr & VDUBuffer.COLOR_FG) >> VDUBuffer.COLOR_FG_SHIFT) - 1]); // Check if background color attribute is set. if ((currAttr & VDUBuffer.COLOR_BG) != 0) - bg = darken(darken(color[((currAttr & VDUBuffer.COLOR_BG) >> VDUBuffer.COLOR_BG_SHIFT) - 1])); + bg = (darken(color[((currAttr & VDUBuffer.COLOR_BG) >> VDUBuffer.COLOR_BG_SHIFT) - 1])); // Check if bold attribute is set. paint.setFakeBoldText((currAttr & VDUBuffer.BOLD) != 0); @@ -255,39 +275,43 @@ public class JTATerminalView extends View implements VDUDisplay, Terminal, Runna // If this character is in the special font, print it and continue to the next character. // We can't use the optimization below for special characters. - if (sf.inSoftFont(buffer.charArray[buffer.windowBase + l][c])) { - // Clear out the space where the character will be printed. - paint.setColor(bg); - canvas.drawRect(c * charWidth + xoffset, l * charHeight + yoffset, - c * (charWidth + 1) + xoffset, (l+1) * charHeight + yoffset, paint); - paint.setColor(fg); - - // FIXME: this won't work since we're not calling drawText() - paint.setUnderlineText((currAttr & VDUBuffer.UNDERLINE) != 0); - - // Draw the text if it's not invisible. - if ((currAttr & VDUBuffer.INVISIBLE) == 0) - sf.drawChar(canvas, paint, buffer.charArray[buffer.windowBase + l][c], xoffset + c * charWidth, l * charHeight + yoffset, charWidth, charHeight); - continue; - } +// if (sf.inSoftFont(buffer.charArray[buffer.windowBase + l][c])) { +// // Clear out the space where the character will be printed. +// paint.setColor(bg); +// canvas.drawRect(c * charWidth + xoffset, l * charHeight + yoffset, +// c * (charWidth + 1) + xoffset, (l+1) * charHeight + yoffset, paint); +// paint.setColor(fg); +// +// // FIXME: this won't work since we're not calling drawText() +// paint.setUnderlineText((currAttr & VDUBuffer.UNDERLINE) != 0); +// +// // Draw the text if it's not invisible. +// if ((currAttr & VDUBuffer.INVISIBLE) == 0) +// sf.drawChar(canvas, paint, buffer.charArray[buffer.windowBase + l][c], xoffset + c * charWidth, l * charHeight + yoffset, charWidth, charHeight); +// continue; +// } // Determine the amount of continuous characters with the same settings and print them all at once. - while ((c + addr < buffer.width) && - ((buffer.charArray[buffer.windowBase + l][c + addr] < ' ') || - (buffer.charAttributes[buffer.windowBase + l][c + addr] == currAttr)) && - !sf.inSoftFont(buffer.charArray[buffer.windowBase + l][c + addr])) { - if (buffer.charArray[buffer.windowBase + l][c + addr] < ' ') { - buffer.charArray[buffer.windowBase + l][c + addr] = ' '; - buffer.charAttributes[buffer.windowBase + l][c + addr] = 0; - continue; - } +// while ((c + addr < buffer.width) && +// ((buffer.charArray[buffer.windowBase + l][c + addr] < ' ') || +// (buffer.charAttributes[buffer.windowBase + l][c + addr] == currAttr)) && +// !sf.inSoftFont(buffer.charArray[buffer.windowBase + l][c + addr])) { +// if (buffer.charArray[buffer.windowBase + l][c + addr] < ' ') { +// buffer.charArray[buffer.windowBase + l][c + addr] = ' '; +// buffer.charAttributes[buffer.windowBase + l][c + addr] = 0; +// continue; +// } +// addr++; +// } + + while(c + addr < buffer.width && buffer.charAttributes[buffer.windowBase + l][c + addr] == currAttr) { addr++; } // Clear the background in preparation for writing text. paint.setColor(bg); canvas.drawRect(c * charWidth + xoffset, l * charHeight + yoffset, - addr * (charWidth + 1) + xoffset, (l+1) * charHeight + yoffset, paint); + (c + addr) * charWidth + xoffset, (l+1) * charHeight + yoffset, paint); paint.setColor(fg); // Check for the underline attribute and set the brush accordingly. @@ -308,6 +332,9 @@ public class JTATerminalView extends View implements VDUDisplay, Terminal, Runna buffer.update[0] = false; + time = System.currentTimeMillis() - time; + Log.d("redraw", "redraw called and updated lines=" + lines + " taking ms=" + time); + postInvalidate(); } diff --git a/src/org/theb/ssh/PasswordDialog.java b/src/org/theb/ssh/PasswordDialog.java index faf636a..91da6b0 100644 --- a/src/org/theb/ssh/PasswordDialog.java +++ b/src/org/theb/ssh/PasswordDialog.java @@ -19,6 +19,7 @@ package org.theb.ssh; import android.app.Activity; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; @@ -41,7 +42,9 @@ public class PasswordDialog extends Activity implements OnClickListener { } public void onClick(View arg0) { - setResult(RESULT_OK, mPassword.getText().toString()); + Intent intent = this.getIntent(); + intent.putExtra(Intent.EXTRA_TEXT, mPassword.getText().toString()); + setResult(RESULT_OK, intent); finish(); } } diff --git a/src/org/theb/ssh/Pubkey.java b/src/org/theb/ssh/Pubkey.java index 4cfaa9c..9dffe08 100644 --- a/src/org/theb/ssh/Pubkey.java +++ b/src/org/theb/ssh/Pubkey.java @@ -101,19 +101,17 @@ public class Pubkey extends Activity { }; @Override - protected void onActivityResult(int requestCode, int resultCode, - String data, Bundle extras) - { - if (requestCode == GATHER_ENTROPY) { - entropySeed = data; - entropyGathered.release(); - } + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == GATHER_ENTROPY) { + entropySeed = data.getStringExtra(Intent.EXTRA_TEXT); + entropyGathered.release(); + } } protected void gatherEntropy() { generateButton.setEnabled(false); Intent intent = new Intent(this, TouchEntropy.class); - startSubActivity(intent, GATHER_ENTROPY); + this.startActivityForResult(intent, GATHER_ENTROPY); } OnClickListener mCommitListener = new OnClickListener() { diff --git a/src/org/theb/ssh/SecureShell.java b/src/org/theb/ssh/SecureShell.java index 9269bac..7fff1af 100644 --- a/src/org/theb/ssh/SecureShell.java +++ b/src/org/theb/ssh/SecureShell.java @@ -32,7 +32,7 @@ import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.os.Handler; -import android.text.method.KeyCharacterMap; +import android.view.KeyCharacterMap; import android.util.Log; import android.view.KeyEvent; import android.view.View; @@ -87,20 +87,26 @@ public class SecureShell extends Activity implements FeedbackUI, ConnectionMonit public void onCreate(Bundle savedValues) { super.onCreate(savedValues); + // TODO: enable opengl for testing on real devices + //requestWindowFeature(Window.FEATURE_OPENGL); requestWindowFeature(Window.FEATURE_PROGRESS); mTerminal = new JTATerminalView(this); // TODO: implement scroll bar on right. setContentView((View)mTerminal); - Log.d("SSH", "using URI " + getIntent().getData().toString()); +// Log.d("SSH", "using URI " + getIntent().getData().toString()); +// +// mCursor = managedQuery(getIntent().getData(), PROJECTION, null, null); +// mCursor.moveToFirst(); +// +// mHostname = mCursor.getString(HOSTNAME_INDEX); +// mUsername = mCursor.getString(USERNAME_INDEX); +// mPort = mCursor.getInt(PORT_INDEX); - mCursor = managedQuery(getIntent().getData(), PROJECTION, null, null); - mCursor.first(); - - mHostname = mCursor.getString(HOSTNAME_INDEX); - mUsername = mCursor.getString(USERNAME_INDEX); - mPort = mCursor.getInt(PORT_INDEX); + mHostname = "192.168.254.230"; + mUsername = "jsharkey"; + mPort = 22; String title = "SSH: " + mUsername + "@" + mHostname; if (mPort != 22) @@ -143,16 +149,14 @@ public class SecureShell extends Activity implements FeedbackUI, ConnectionMonit public void askPassword() { Intent intent = new Intent(this, PasswordDialog.class); - this.startSubActivity(intent, PASSWORD_REQUEST); + this.startActivityForResult(intent, PASSWORD_REQUEST); } @Override - protected void onActivityResult(int requestCode, int resultCode, - String data, Bundle extras) - { - if (requestCode == PASSWORD_REQUEST) { - mConn.setPassword(data); - } + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == PASSWORD_REQUEST) { + mConn.setPassword(data.getStringExtra(Intent.EXTRA_TEXT)); + } } @Override @@ -184,7 +188,7 @@ public class SecureShell extends Activity implements FeedbackUI, ConnectionMonit out.write(c); } else if (keyCode == KeyEvent.KEYCODE_DEL) { out.write(0x08); // CTRL-H - } else if (keyCode == KeyEvent.KEYCODE_NEWLINE + } else if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN diff --git a/src/org/theb/ssh/Terminal.java b/src/org/theb/ssh/Terminal.java index 1212aa2..890f6b0 100644 --- a/src/org/theb/ssh/Terminal.java +++ b/src/org/theb/ssh/Terminal.java @@ -22,6 +22,7 @@ import java.io.InputStream; import java.io.OutputStream; public interface Terminal { + public int getWidth(); public int getHeight(); public int getRowCount(); diff --git a/src/org/theb/ssh/TouchEntropy.java b/src/org/theb/ssh/TouchEntropy.java index 023e531..bf2d737 100644 --- a/src/org/theb/ssh/TouchEntropy.java +++ b/src/org/theb/ssh/TouchEntropy.java @@ -2,6 +2,7 @@ package org.theb.ssh; import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; @@ -74,7 +75,9 @@ public class TouchEntropy extends Activity { // SHA1PRNG only keeps 20 bytes (160 bits) of entropy. if (mEntropy.length() > 20) { - TouchEntropy.this.setResult(RESULT_OK, mEntropy); + Intent intent = TouchEntropy.this.getIntent(); + intent.putExtra(Intent.EXTRA_TEXT, mEntropy); + TouchEntropy.this.setResult(RESULT_OK, intent); TouchEntropy.this.finish(); } diff --git a/src/org/theb/ssh/TrileadConnectionThread.java b/src/org/theb/ssh/TrileadConnectionThread.java index 63180b0..1e51afc 100644 --- a/src/org/theb/ssh/TrileadConnectionThread.java +++ b/src/org/theb/ssh/TrileadConnectionThread.java @@ -130,7 +130,7 @@ public class TrileadConnectionThread extends ConnectionThread { session = connection.openSession(); - session.requestPTY("vt100", + session.requestPTY("xterm", // BUGFIX: allow colors with xterm instead of vt100 term.getColumnCount(), term.getRowCount(), term.getWidth(), term.getHeight(), null); -- cgit v1.2.3