Skip to content

Commit 63809ec

Browse files
committed
ANDROID: use system based font size
1 parent b427b97 commit 63809ec

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

ide/android/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<!-- This is the platform API where NativeActivity was introduced. -->
88
<uses-sdk android:minSdkVersion="9" />
99

10+
<!-- support large + xlarge screens to avoid compatibility mode -->
11+
<supports-screens android:largeScreens="true" />
12+
<supports-screens android:xlargeScreens="true" />
13+
1014
<!-- This .apk has Java code, so set hasCode to true. -->
1115
<application android:label="@string/app_name"
1216
android:hasCode="true"

src/platform/android/jni/runtime.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
#include "common/fs_socket_client.h"
2525

2626
#define WAIT_INTERVAL 10
27-
#define DEFAULT_FONT_SIZE 30
2827
#define MAIN_BAS "__main_bas__"
2928
#define CONFIG_FILE "/settings.txt"
3029
#define PATH_KEY "path"
31-
#define FONT_SCALE_KEY "fontScale"
30+
#define FONT_SCALE_KEY "fontScale2"
3231
#define SERVER_SOCKET_KEY "serverSocket"
3332
#define SERVER_TOKEN_KEY "serverToken"
3433

@@ -223,6 +222,17 @@ String Runtime::getString(const char *methodName) {
223222
return result;
224223
}
225224

225+
int Runtime::getInteger(const char *methodName) {
226+
JNIEnv *env;
227+
_app->activity->vm->AttachCurrentThread(&env, NULL);
228+
jclass clazz = env->GetObjectClass(_app->activity->clazz);
229+
jmethodID methodId = env->GetMethodID(clazz, methodName, "()I");
230+
jint result = env->CallIntMethod(_app->activity->clazz, methodId);
231+
env->DeleteLocalRef(clazz);
232+
_app->activity->vm->DetachCurrentThread();
233+
return result;
234+
}
235+
226236
int Runtime::getUnicodeChar(int keyCode, int metaState) {
227237
JNIEnv *env;
228238
_app->activity->vm->AttachCurrentThread(&env, NULL);
@@ -309,8 +319,11 @@ void Runtime::loadConfig() {
309319
String path;
310320
Properties profile;
311321

322+
int fontSize = getInteger("getStartupFontSize");
323+
trace("fontSize = %d", fontSize);
324+
312325
_output->setTextColor(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
313-
_output->setFontSize(DEFAULT_FONT_SIZE);
326+
_output->setFontSize(fontSize);
314327
_initialFontSize = _output->getFontSize();
315328

316329
path.append(_app->activity->internalDataPath);

src/platform/android/jni/runtime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ struct Runtime : public System {
2525
void clearSoundQueue();
2626
void construct();
2727
bool getUntrusted();
28-
String getString(const char *method);
28+
String getString(const char *methodName);
29+
int getInteger(const char *methodName);
2930
int getUnicodeChar(int keyCode, int metaState);
3031
void redraw() { _graphics->redraw(); }
3132
void handleKeyEvent(MAEvent &event);

src/platform/android/src/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@
3838
import android.content.Context;
3939
import android.content.DialogInterface;
4040
import android.content.Intent;
41+
import android.content.res.Resources;
4142
import android.graphics.Rect;
4243
import android.net.Uri;
4344
import android.os.Build;
4445
import android.os.Bundle;
4546
import android.util.Base64;
47+
import android.util.DisplayMetrics;
4648
import android.util.Log;
49+
import android.util.TypedValue;
4750
import android.view.InputDevice;
4851
import android.view.View;
4952
import android.view.inputmethod.InputMethodManager;
@@ -59,6 +62,7 @@ public class MainActivity extends NativeActivity {
5962
private static final String WEB_BAS = "web.bas";
6063
private static final String SCHEME_BAS = "qrcode.bas";
6164
private static final String SCHEME = "smallbasic://x/";
65+
private static final int BASE_FONT_SIZE = 20;
6266
private String _startupBas = null;
6367
private boolean _untrusted = false;
6468
private ExecutorService _audioExecutor = Executors.newSingleThreadExecutor();
@@ -108,6 +112,11 @@ public String getStartupBas() {
108112
return this._startupBas == null ? "" : this._startupBas;
109113
}
110114

115+
public int getStartupFontSize() {
116+
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
117+
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, BASE_FONT_SIZE, metrics);
118+
}
119+
111120
public int getUnicodeChar(int keyCode, int metaState) {
112121
int result = 0;
113122
InputDevice device = InputDevice.getDevice(InputDevice.getDeviceIds()[0]);

src/platform/common/ansiwidget.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
#define BUTTON_PADDING 10
5050
#define OVER_SCROLL 100
51-
51+
#define H_SCROLL_SIZE 5
5252
#define SWIPE_MAX_TIMER 3000
5353
#define SWIPE_DELAY_STEP 200
5454
#define SWIPE_MAX_DURATION 300
@@ -783,8 +783,9 @@ bool AnsiWidget::pointerMoveEvent(MAEvent &event) {
783783
if (vscroll < 0) {
784784
vscroll = 0;
785785
}
786-
if ((hscroll != _front->_scrollX && maxHScroll > 0 &&
787-
hscroll <= maxHScroll) ||
786+
if ((abs(hscroll - _front->_scrollX) > H_SCROLL_SIZE
787+
&& maxHScroll > 0
788+
&& hscroll <= maxHScroll) ||
788789
(vscroll != _front->_scrollY && maxVScroll > 0 &&
789790
vscroll < maxVScroll + OVER_SCROLL)) {
790791
_front->drawInto();

0 commit comments

Comments
 (0)