aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2009-01-23 21:33:38 +0000
committerKenny Root <kenny@the-b.org>2009-01-23 21:33:38 +0000
commitb6393bcc8d7b82b7f2704d8c208b33f4c0b9691a (patch)
treea2e7075bb3895700a2a47f205b03fabc5f739971 /src
parent57e18e62290cfaceea2e183a248f60d7c555625c (diff)
downloadconnectbot-b6393bcc8d7b82b7f2704d8c208b33f4c0b9691a.tar.gz
connectbot-b6393bcc8d7b82b7f2704d8c208b33f4c0b9691a.tar.bz2
connectbot-b6393bcc8d7b82b7f2704d8c208b33f4c0b9691a.zip
Make input status indicators more easily discernible
Diffstat (limited to 'src')
-rw-r--r--src/org/connectbot/TerminalView.java92
-rw-r--r--src/org/connectbot/service/FontSizeChangedListener.java17
-rw-r--r--src/org/connectbot/service/TerminalBridge.java28
3 files changed, 101 insertions, 36 deletions
diff --git a/src/org/connectbot/TerminalView.java b/src/org/connectbot/TerminalView.java
index ad5009a..4250e0a 100644
--- a/src/org/connectbot/TerminalView.java
+++ b/src/org/connectbot/TerminalView.java
@@ -19,15 +19,17 @@
package org.connectbot;
import org.connectbot.bean.SelectionArea;
+import org.connectbot.service.FontSizeChangedListener;
import org.connectbot.service.TerminalBridge;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
-import android.graphics.Color;
+import android.graphics.Matrix;
import android.graphics.Paint;
+import android.graphics.Path;
import android.graphics.PixelXorXfermode;
-import android.util.Log;
+import android.graphics.RectF;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Toast;
@@ -39,16 +41,18 @@ import android.widget.Toast;
*
* @author jsharkey
*/
-public class TerminalView extends View {
+public class TerminalView extends View implements FontSizeChangedListener {
private final Context context;
public final TerminalBridge bridge;
private final Paint paint;
private final Paint cursorPaint;
- private final Paint cursorDecorationPaint;
// Cursor paints to distinguish modes
- private float[] ctrlLines, altLines, shiftLines;
+ private Path ctrlCursor, altCursor, shiftCursor;
+ private RectF tempSrc, tempDst;
+ private Matrix scaleMatrix;
+ private static final Matrix.ScaleToFit scaleType = Matrix.ScaleToFit.FILL;
private Toast notification = null;
private String lastNotification = null;
@@ -67,10 +71,37 @@ public class TerminalView extends View {
cursorPaint = new Paint();
cursorPaint.setColor(bridge.color[TerminalBridge.COLOR_FG_STD]);
cursorPaint.setXfermode(new PixelXorXfermode(bridge.color[TerminalBridge.COLOR_BG_STD]));
-
- cursorDecorationPaint = new Paint();
- cursorDecorationPaint.setColor(Color.BLACK);
- //cursorDecorationPaint.setXfermode(new PixelXorXfermode(bridge.color[TerminalBridge.COLOR_FG_STD]));
+ cursorPaint.setAntiAlias(true);
+
+ /*
+ * Set up our cursor indicators on a 1x1 Path object which we can later
+ * transform to our character width and height
+ */
+ // TODO make this into a resource somehow
+ shiftCursor = new Path();
+ shiftCursor.lineTo(0.5f, 0.33f);
+ shiftCursor.lineTo(1.0f, 0.0f);
+ shiftCursor.close();
+
+ altCursor = new Path();
+ altCursor.moveTo(0.0f, 1.0f);
+ altCursor.lineTo(0.5f, 0.66f);
+ altCursor.lineTo(1.0f, 1.0f);
+ altCursor.close();
+
+ ctrlCursor = new Path();
+ ctrlCursor.moveTo(0.0f, 0.25f);
+ ctrlCursor.lineTo(1.0f, 0.5f);
+ ctrlCursor.lineTo(0.0f, 0.75f);
+ ctrlCursor.close();
+
+ // For creating the transform when the terminal resizes
+ tempSrc = new RectF();
+ tempSrc.set(0.0f, 0.0f, 1.0f, 1.0f);
+ tempDst = new RectF();
+ scaleMatrix = new Matrix();
+
+ bridge.addFontSizeChangedListener(this);
// connect our view up to the bridge
setOnKeyListener(bridge);
@@ -85,27 +116,12 @@ public class TerminalView extends View {
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
bridge.parentChanged(this);
+ }
- // Make a triangle shape pointing down on the top
- shiftLines = new float[] {
- 0.0f, 0.0f, bridge.charWidth / 2.0f, bridge.charHeight / 3.0f,
- bridge.charWidth / 2.0f, bridge.charHeight / 3.0f, bridge.charWidth, 0.0f,
- bridge.charWidth, 0.0f, 0.0f, 0.0f,
- };
-
- // Make a triangle shape pointing up on the bottom
- altLines = new float[] {
- 0.0f, bridge.charHeight, bridge.charWidth / 2.0f, (bridge.charHeight / 3.0f) * 2.0f,
- bridge.charWidth / 2.0f, (bridge.charHeight / 3.0f) * 2.0f, bridge.charWidth, bridge.charHeight,
- bridge.charWidth, bridge.charHeight, 0.0f, bridge.charHeight,
- };
-
- // Make a triangle shape pointing right in the middle
- ctrlLines = new float[] {
- 0.0f, bridge.charHeight / 4.0f, bridge.charWidth, bridge.charHeight / 2.0f,
- bridge.charWidth, bridge.charHeight / 2.0f, 0.0f, (bridge.charHeight / 3.0f) * 2.0f,
- 0.0f, (bridge.charHeight / 4.0f) * 3.0f, 0.0f, bridge.charHeight / 4.0f,
- };
+ public void onFontSizeChanged(float size) {
+ // Create a scale matrix to scale our 1x1 representation of the cursor
+ tempDst.set(0.0f, 0.0f, bridge.charWidth, bridge.charHeight);
+ scaleMatrix.setRectToRect(tempSrc, tempDst, scaleType);
}
@Override
@@ -131,14 +147,16 @@ public class TerminalView extends View {
canvas.clipRect(0, 0, bridge.charWidth, bridge.charHeight);
canvas.drawPaint(cursorPaint);
+ // Make sure we scale our decorations to the correct size.
+ canvas.concat(scaleMatrix);
+
int metaState = bridge.getMetaState();
- Log.d("cursor", "Meta state: " + metaState);
if ((metaState & TerminalBridge.META_SHIFT_ON) == TerminalBridge.META_SHIFT_ON)
- canvas.drawLines(shiftLines, cursorPaint);
+ canvas.drawPath(shiftCursor, cursorPaint);
if ((metaState & TerminalBridge.META_ALT_ON) == TerminalBridge.META_ALT_ON)
- canvas.drawLines(altLines, cursorPaint);
+ canvas.drawPath(altCursor, cursorPaint);
if ((metaState & TerminalBridge.META_CTRL_ON) == TerminalBridge.META_CTRL_ON)
- canvas.drawLines(ctrlLines, cursorPaint);
+ canvas.drawPath(ctrlCursor, cursorPaint);
// Restore previous clip region
canvas.restore();
@@ -147,13 +165,15 @@ public class TerminalView extends View {
// draw any highlighted area
if (bridge.isSelectingForCopy()) {
SelectionArea area = bridge.getSelectionArea();
- canvas.drawRect(
+ canvas.save(Canvas.CLIP_SAVE_FLAG);
+ canvas.clipRect(
area.getLeft() * bridge.charWidth,
area.getTop() * bridge.charHeight,
(area.getRight() + 1) * bridge.charWidth,
- (area.getBottom() + 1) * bridge.charHeight,
- cursorPaint
+ (area.getBottom() + 1) * bridge.charHeight
);
+ canvas.drawPaint(cursorPaint);
+ canvas.restore();
}
}
}
diff --git a/src/org/connectbot/service/FontSizeChangedListener.java b/src/org/connectbot/service/FontSizeChangedListener.java
new file mode 100644
index 0000000..a357b6c
--- /dev/null
+++ b/src/org/connectbot/service/FontSizeChangedListener.java
@@ -0,0 +1,17 @@
+/**
+ *
+ */
+package org.connectbot.service;
+
+/**
+ * @author Kenny Root
+ *
+ */
+public interface FontSizeChangedListener {
+
+ /**
+ * @param size
+ * new font size
+ */
+ public void onFontSizeChanged(float size);
+}
diff --git a/src/org/connectbot/service/TerminalBridge.java b/src/org/connectbot/service/TerminalBridge.java
index 94b1647..f75b1a3 100644
--- a/src/org/connectbot/service/TerminalBridge.java
+++ b/src/org/connectbot/service/TerminalBridge.java
@@ -167,6 +167,8 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
private float fontSize = -1;
+ private List<FontSizeChangedListener> fontSizeChangedListeners;
+
private List<String> localOutput;
/**
@@ -269,6 +271,8 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
localOutput = new LinkedList<String>();
+ fontSizeChangedListeners = new LinkedList<FontSizeChangedListener>();
+
setFontSize(DEFAULT_FONT_SIZE);
// create terminal buffer and handle outgoing data
@@ -1122,6 +1126,30 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
// refresh any bitmap with new font size
if(parent != null)
parentChanged(parent);
+
+ for (FontSizeChangedListener ofscl : fontSizeChangedListeners)
+ ofscl.onFontSizeChanged(size);
+ }
+
+ /**
+ * Add an {@link FontSizeChangedListener} to the list of listeners for this
+ * bridge.
+ *
+ * @param listener
+ * listener to add
+ */
+ public void addFontSizeChangedListener(FontSizeChangedListener listener) {
+ fontSizeChangedListeners.add(listener);
+ }
+
+ /**
+ * Remove an {@link FontSizeChangedListener} from the list of listeners for
+ * this bridge.
+ *
+ * @param listener
+ */
+ public void removeFontSizeChangedListener(FontSizeChangedListener listener) {
+ fontSizeChangedListeners.remove(listener);
}
/**