comparison src/com/five_ten_sg/connectbot/service/TerminalBridge.java @ 188:cf677a6f586d

use floating point font size, change size by scaling factor rather than linear addition
author Carl Byington <carl@five-ten-sg.com>
date Wed, 02 Jul 2014 16:10:20 -0700
parents 47412afe78dd
children ab6f64d1a24a
comparison
equal deleted inserted replaced
187:81f9ba83c0e9 188:cf677a6f586d
76 */ 76 */
77 @SuppressWarnings("deprecation") // for ClipboardManager 77 @SuppressWarnings("deprecation") // for ClipboardManager
78 public class TerminalBridge implements VDUDisplay { 78 public class TerminalBridge implements VDUDisplay {
79 public final static String TAG = "ConnectBot.TerminalBridge"; 79 public final static String TAG = "ConnectBot.TerminalBridge";
80 80
81 public final static int DEFAULT_FONT_SIZE = 10; 81 public final static float DEFAULT_FONT_SIZE = 10.0;
82 private final static int FONT_SIZE_STEP = 2; 82 private final static float FONT_SIZE_FACTOR = 1.1;
83 83
84 public Integer[] color; 84 public Integer[] color;
85 85
86 public int defaultFg = HostDatabase.DEFAULT_FG_COLOR; 86 public int defaultFg = HostDatabase.DEFAULT_FG_COLOR;
87 public int defaultBg = HostDatabase.DEFAULT_BG_COLOR; 87 public int defaultBg = HostDatabase.DEFAULT_BG_COLOR;
187 defaultPaint.setAntiAlias(true); 187 defaultPaint.setAntiAlias(true);
188 defaultPaint.setTypeface(Typeface.MONOSPACE); 188 defaultPaint.setTypeface(Typeface.MONOSPACE);
189 defaultPaint.setFakeBoldText(true); // more readable? 189 defaultPaint.setFakeBoldText(true); // more readable?
190 localOutput = new LinkedList<String>(); 190 localOutput = new LinkedList<String>();
191 fontSizeChangedListeners = new LinkedList<FontSizeChangedListener>(); 191 fontSizeChangedListeners = new LinkedList<FontSizeChangedListener>();
192 Integer defaultFontSize = Integer.parseInt(manager.prefs.getString(PreferenceConstants.DEFAULT_FONT_SIZE, "-1")); 192 float defaultFontSize = Float.parseFloat(manager.prefs.getString(PreferenceConstants.DEFAULT_FONT_SIZE, "-1"));
193 Log.i(TAG, "fontSize: " + this.fontSize + ", defaultFontSize: " + defaultFontSize); 193 Log.i(TAG, "fontSize: " + this.fontSize + ", defaultFontSize: " + defaultFontSize);
194 194
195 if (fontSize == -1) { 195 float hostFontSize;
196 if (defaultFontSize > 0 && host.getFontSize() == -1) 196 if (fontSize <= 0) {
197 if ((defaultFontSize > 0) && (host.getFontSize() <= 0))
197 hostFontSize = defaultFontSize; 198 hostFontSize = defaultFontSize;
198 else 199 else
199 hostFontSize = host.getFontSize(); 200 hostFontSize = host.getFontSize();
200 } 201 }
201 else 202 else
466 if (parent != null) parentChanged(parent); 467 if (parent != null) parentChanged(parent);
467 468
468 for (FontSizeChangedListener ofscl : fontSizeChangedListeners) 469 for (FontSizeChangedListener ofscl : fontSizeChangedListeners)
469 ofscl.onFontSizeChanged(size); 470 ofscl.onFontSizeChanged(size);
470 471
471 host.setFontSize((int) fontSize); 472 host.setFontSize(fontSize);
472 manager.hostdb.updateFontSize(host); 473 manager.hostdb.updateFontSize(host);
473 } 474 }
474 475
475 /** 476 /**
476 * Add an {@link FontSizeChangedListener} to the list of listeners for this 477 * Add an {@link FontSizeChangedListener} to the list of listeners for this
991 992
992 /** 993 /**
993 * 994 *
994 */ 995 */
995 public void increaseFontSize() { 996 public void increaseFontSize() {
996 setFontSize(fontSize + FONT_SIZE_STEP); 997 setFontSize(fontSize * FONT_SIZE_FACTOR);
997 } 998 }
998 999
999 /** 1000 /**
1000 * 1001 *
1001 */ 1002 */
1002 public void decreaseFontSize() { 1003 public void decreaseFontSize() {
1003 setFontSize(fontSize - FONT_SIZE_STEP); 1004 setFontSize(fontSize / FONT_SIZE_FACTOR);
1004 } 1005 }
1005 1006
1006 /** 1007 /**
1007 * Auto-size window back to default 1008 * Auto-size window back to default
1008 */ 1009 */
1009 public void resetSize(TerminalView parent) { 1010 public void resetSize(TerminalView parent) {
1010 this.forcedSize = false; 1011 this.forcedSize = false;
1011 Integer defaultFontSize = Integer.parseInt(manager.prefs.getString(PreferenceConstants.DEFAULT_FONT_SIZE, "-1")); 1012 float defaultFontSize = Float.parseFloat(manager.prefs.getString(PreferenceConstants.DEFAULT_FONT_SIZE, "-1"));
1012 1013
1013 if (this.fontSize != -1 && defaultFontSize > 0) 1014 if (defaultFontSize > 0)
1014 setFontSize(defaultFontSize); 1015 setFontSize(defaultFontSize);
1015 else 1016 else
1016 setFontSize(DEFAULT_FONT_SIZE); 1017 setFontSize(DEFAULT_FONT_SIZE);
1017 } 1018 }
1018 1019