aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/org/connectbot
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2015-03-27 20:13:28 +0000
committerKenny Root <kenny@the-b.org>2015-03-27 20:13:28 +0000
commitb8e17fe94360ea131a3425f759e60977547d3d58 (patch)
tree010861e2d30c83d9d851d113a1f0ba757e27655c /app/src/main/java/org/connectbot
parent2f67031a6bba2c222d23a642bf6dcf82355b1c1f (diff)
parent8a9540082db537752dde396c8e163cd1a9b503ef (diff)
downloadconnectbot-b8e17fe94360ea131a3425f759e60977547d3d58.tar.gz
connectbot-b8e17fe94360ea131a3425f759e60977547d3d58.tar.bz2
connectbot-b8e17fe94360ea131a3425f759e60977547d3d58.zip
Merge branch 'master' into gradle-conversion
Diffstat (limited to 'app/src/main/java/org/connectbot')
-rw-r--r--app/src/main/java/org/connectbot/service/FontSizeChangedListener.java6
-rw-r--r--app/src/main/java/org/connectbot/service/TerminalBridge.java86
-rw-r--r--app/src/main/java/org/connectbot/util/HostDatabase.java40
3 files changed, 74 insertions, 58 deletions
diff --git a/app/src/main/java/org/connectbot/service/FontSizeChangedListener.java b/app/src/main/java/org/connectbot/service/FontSizeChangedListener.java
index eb1c33d..56b9971 100644
--- a/app/src/main/java/org/connectbot/service/FontSizeChangedListener.java
+++ b/app/src/main/java/org/connectbot/service/FontSizeChangedListener.java
@@ -24,8 +24,8 @@ package org.connectbot.service;
public interface FontSizeChangedListener {
/**
- * @param size
- * new font size
+ * @param sizeDp
+ * new font size in dp
*/
- void onFontSizeChanged(float size);
+ void onFontSizeChanged(float sizeDp);
}
diff --git a/app/src/main/java/org/connectbot/service/TerminalBridge.java b/app/src/main/java/org/connectbot/service/TerminalBridge.java
index 47390d1..15b9d73 100644
--- a/app/src/main/java/org/connectbot/service/TerminalBridge.java
+++ b/app/src/main/java/org/connectbot/service/TerminalBridge.java
@@ -61,8 +61,9 @@ import de.mud.terminal.vt320;
public class TerminalBridge implements VDUDisplay {
public final static String TAG = "ConnectBot.TerminalBridge";
- public final static int DEFAULT_FONT_SIZE = 10;
+ public final static int DEFAULT_FONT_SIZE_DP = 10;
private final static int FONT_SIZE_STEP = 2;
+ private final float displayDensity;
public Integer[] color;
@@ -107,7 +108,7 @@ public class TerminalBridge implements VDUDisplay {
public int charHeight = -1;
private int charTop = -1;
- private float fontSize = -1;
+ private float fontSizeDp = -1;
private final List<FontSizeChangedListener> fontSizeChangedListeners;
@@ -143,6 +144,8 @@ public class TerminalBridge implements VDUDisplay {
emulation = null;
manager = null;
+ displayDensity = 1f;
+
defaultPaint = new Paint();
selectionArea = new SelectionArea();
@@ -169,6 +172,8 @@ public class TerminalBridge implements VDUDisplay {
emulation = manager.getEmulation();
scrollback = manager.getScrollback();
+ this.displayDensity = manager.getResources().getDisplayMetrics().density;
+
// create prompt helper to relay password and hostkey requests up to gui
promptHelper = new PromptHelper(this);
@@ -182,10 +187,11 @@ public class TerminalBridge implements VDUDisplay {
fontSizeChangedListeners = new LinkedList<FontSizeChangedListener>();
- int hostFontSize = host.getFontSize();
- if (hostFontSize <= 0)
- hostFontSize = DEFAULT_FONT_SIZE;
- setFontSize(hostFontSize);
+ int hostFontSizeDp = host.getFontSize();
+ if (hostFontSizeDp <= 0) {
+ hostFontSizeDp = DEFAULT_FONT_SIZE_DP;
+ }
+ setFontSize(hostFontSizeDp);
// create terminal buffer and handle outgoing data
// this is probably status reply information
@@ -384,7 +390,7 @@ public class TerminalBridge implements VDUDisplay {
relayThread.start();
// force font-size to make sure we resizePTY as needed
- setFontSize(fontSize);
+ setFontSize(fontSizeDp);
// finally send any post-login string, if requested
injectString(host.getPostLogin());
@@ -480,13 +486,18 @@ public class TerminalBridge implements VDUDisplay {
/**
* Request a different font size. Will make call to parentChanged() to make
* sure we resize PTY if needed.
+ *
+ * @param sizeDp Size of font in dp
*/
- /* package */ final void setFontSize(float size) {
- if (size <= 0.0)
+ /* package */ final void setFontSize(float sizeDp) {
+ if (sizeDp <= 0.0) {
return;
+ }
+
+ final int fontSizePx = (int) (sizeDp * this.displayDensity + 0.5f);
- defaultPaint.setTextSize(size);
- fontSize = size;
+ defaultPaint.setTextSize(fontSizePx);
+ fontSizeDp = sizeDp;
// read new metrics to get exact pixel dimensions
FontMetrics fm = defaultPaint.getFontMetrics();
@@ -498,13 +509,15 @@ public class TerminalBridge implements VDUDisplay {
charHeight = (int) Math.ceil(fm.descent - fm.top);
// refresh any bitmap with new font size
- if (parent != null)
+ if (parent != null) {
parentChanged(parent);
+ }
- for (FontSizeChangedListener ofscl : fontSizeChangedListeners)
- ofscl.onFontSizeChanged(size);
+ for (FontSizeChangedListener ofscl : fontSizeChangedListeners) {
+ ofscl.onFontSizeChanged(sizeDp);
+ }
- host.setFontSize((int) fontSize);
+ host.setFontSize((int) sizeDp);
manager.hostdb.updateFontSize(host);
forcedSize = false;
@@ -771,51 +784,52 @@ public class TerminalBridge implements VDUDisplay {
/**
* Resize terminal to fit [rows]x[cols] in screen of size [width]x[height]
- * @param rows
- * @param cols
- * @param width
- * @param height
+ *
+ * @param rows desired number of text rows
+ * @param cols desired numbor of text colums
+ * @param width width of screen in pixels
+ * @param height height of screen in pixels
*/
public synchronized void resizeComputed(int cols, int rows, int width, int height) {
- float size = 8.0f;
+ float sizeDp = 8.0f;
float step = 8.0f;
float limit = 0.125f;
int direction;
- while ((direction = fontSizeCompare(size, cols, rows, width, height)) < 0)
- size += step;
+ while ((direction = fontSizeCompare(sizeDp, cols, rows, width, height)) < 0)
+ sizeDp += step;
if (direction == 0) {
- Log.d("fontsize", String.format("Found match at %f", size));
+ Log.d("fontsize", String.format("Found match at %f", sizeDp));
return;
}
step /= 2.0f;
- size -= step;
+ sizeDp -= step;
- while ((direction = fontSizeCompare(size, cols, rows, width, height)) != 0
+ while ((direction = fontSizeCompare(sizeDp, cols, rows, width, height)) != 0
&& step >= limit) {
step /= 2.0f;
if (direction > 0) {
- size -= step;
+ sizeDp -= step;
} else {
- size += step;
+ sizeDp += step;
}
}
if (direction > 0)
- size -= step;
+ sizeDp -= step;
this.columns = cols;
this.rows = rows;
- setFontSize(size);
+ setFontSize(sizeDp);
forcedSize = true;
}
- private int fontSizeCompare(float size, int cols, int rows, int width, int height) {
+ private int fontSizeCompare(float sizeDp, int cols, int rows, int width, int height) {
// read new metrics to get exact pixel dimensions
- defaultPaint.setTextSize(size);
+ defaultPaint.setTextSize((int) (sizeDp * this.displayDensity + 0.5f));
FontMetrics fm = defaultPaint.getFontMetrics();
float[] widths = new float[1];
@@ -823,7 +837,7 @@ public class TerminalBridge implements VDUDisplay {
int termWidth = (int) widths[0] * cols;
int termHeight = (int) Math.ceil(fm.descent - fm.top) * rows;
- Log.d("fontsize", String.format("font size %f resulted in %d x %d", size, termWidth, termHeight));
+ Log.d("fontsize", String.format("font size %fdp resulted in %d x %d", sizeDp, termWidth, termHeight));
// Check to see if it fits in resolution specified.
if (termWidth > width || termHeight > height)
@@ -1003,16 +1017,16 @@ public class TerminalBridge implements VDUDisplay {
}
/**
- *
+ * Convenience function to increase the font size by a given step.
*/
public void increaseFontSize() {
- setFontSize(fontSize + FONT_SIZE_STEP);
+ setFontSize(fontSizeDp + FONT_SIZE_STEP);
}
/**
- *
+ * Convenience function to decrease the font size by a given step.
*/
public void decreaseFontSize() {
- setFontSize(fontSize - FONT_SIZE_STEP);
+ setFontSize(fontSizeDp - FONT_SIZE_STEP);
}
}
diff --git a/app/src/main/java/org/connectbot/util/HostDatabase.java b/app/src/main/java/org/connectbot/util/HostDatabase.java
index cc0fd0c..d1d87c7 100644
--- a/app/src/main/java/org/connectbot/util/HostDatabase.java
+++ b/app/src/main/java/org/connectbot/util/HostDatabase.java
@@ -47,7 +47,7 @@ public class HostDatabase extends RobustSQLiteOpenHelper {
public final static String TAG = "ConnectBot.HostDatabase";
public final static String DB_NAME = "hosts";
- public final static int DB_VERSION = 23;
+ public final static int DB_VERSION = 24;
public final static String TABLE_HOSTS = "hosts";
public final static String FIELD_HOST_NICKNAME = "nickname";
@@ -140,9 +140,14 @@ public class HostDatabase extends RobustSQLiteOpenHelper {
public static final Object[] dbLock = new Object[0];
+ /** Used during upgrades from DB version 23 to 24. */
+ private final float displayDensity;
+
public HostDatabase(Context context) {
super(context, DB_NAME, null, DB_VERSION);
+ this.displayDensity = context.getResources().getDisplayMetrics().density;
+
getWritableDatabase().close();
}
@@ -264,12 +269,15 @@ public class HostDatabase extends RobustSQLiteOpenHelper {
case 22:
db.execSQL("ALTER TABLE " + TABLE_HOSTS
+ " ADD COLUMN " + FIELD_HOST_QUICKDISCONNECT + " TEXT DEFAULT '" + Boolean.toString(false) + "'");
+ case 23:
+ db.execSQL("UPDATE " + TABLE_HOSTS
+ + " SET " + FIELD_HOST_FONTSIZE + " = " + FIELD_HOST_FONTSIZE + " / " + displayDensity);
}
}
/**
* Touch a specific host to update its "last connected" field.
- * @param nickname Nickname field of host to update
+ * @param host host to update
*/
public void touchHost(HostBean host) {
long now = System.currentTimeMillis() / 1000;
@@ -358,8 +366,7 @@ public class HostDatabase extends RobustSQLiteOpenHelper {
}
/**
- * @param hosts
- * @param c
+ * @param c cursor to read from
*/
private List<HostBean> createHostBeans(Cursor c) {
List<HostBean> hosts = new LinkedList<HostBean>();
@@ -414,8 +421,8 @@ public class HostDatabase extends RobustSQLiteOpenHelper {
}
/**
- * @param c
- * @return
+ * @param c cursor with zero or more hosts
+ * @return the first host from the cursor or {@code null} if none.
*/
private HostBean getFirstHostBean(Cursor c) {
HostBean host = null;
@@ -430,13 +437,8 @@ public class HostDatabase extends RobustSQLiteOpenHelper {
}
/**
- * @param nickname
- * @param protocol
- * @param username
- * @param hostname
- * @param hostname2
- * @param port
- * @return
+ * @param selection parameters describing the desired host
+ * @return host matching selection or {@code null}.
*/
public HostBean findHost(Map<String, String> selection) {
StringBuilder selectionBuilder = new StringBuilder();
@@ -481,8 +483,8 @@ public class HostDatabase extends RobustSQLiteOpenHelper {
}
/**
- * @param hostId
- * @return
+ * @param hostId host id for the host
+ * @return host matching the hostId or {@code null} if none match
*/
public HostBean findHostById(long hostId) {
HostBean host;
@@ -502,10 +504,10 @@ public class HostDatabase extends RobustSQLiteOpenHelper {
/**
* Record the given hostkey into database under this nickname.
- * @param hostname
- * @param port
- * @param hostkeyalgo
- * @param hostkey
+ * @param hostname hostname to match
+ * @param port port to match
+ * @param hostkeyalgo algorithm for host key
+ * @param hostkey the bytes of the host key itself
*/
public void saveKnownHost(String hostname, int port, String hostkeyalgo, byte[] hostkey) {
ContentValues values = new ContentValues();