Skip to content

Commit 35789c3

Browse files
committed
ANDROID: sound command now supports non-background play
1 parent 861e553 commit 35789c3

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,17 +417,21 @@ public void run() {
417417
}).start();
418418
}
419419

420-
public void playTone(int frq, int dur, int vol) {
420+
public void playTone(int frq, int dur, int vol, boolean bgplay) {
421421
float volume = (vol / 100f);
422422
final Sound sound = new Sound(frq, dur, volume);
423-
_sounds.add(sound);
424-
_audioExecutor.execute(new Runnable() {
425-
@Override
426-
public void run() {
427-
sound.play();
428-
_sounds.remove(sound);
429-
}
430-
});
423+
if (bgplay) {
424+
_sounds.add(sound);
425+
_audioExecutor.execute(new Runnable() {
426+
@Override
427+
public void run() {
428+
sound.play();
429+
_sounds.remove(sound);
430+
}
431+
});
432+
} else {
433+
sound.play();
434+
}
431435
}
432436

433437
public boolean removeLocationUpdates() {

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/Sound.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@ class Sound {
1919
private final int _dur;
2020
private boolean _silent;
2121

22-
public Sound(int frq, int dur, float vol) {
22+
Sound(int frq, int dur, float vol) {
2323
this._sound = generateTone(frq, dur);
2424
this._volume = vol;
2525
this._dur = dur;
2626
this._silent = false;
2727
}
2828

29-
public boolean isSilent() {
30-
return _silent;
31-
}
32-
33-
public void play() {
29+
void play() {
3430
if (!_silent) {
3531
try {
3632
AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
@@ -48,7 +44,7 @@ public void play() {
4844
}
4945
}
5046

51-
public void setSilent(boolean silent) {
47+
void setSilent(boolean silent) {
5248
this._silent = silent;
5349
}
5450

src/platform/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.3.0'
8+
classpath 'com.android.tools.build:gradle:3.3.1'
99
classpath "com.github.ben-manes:gradle-versions-plugin:0.20.0"
1010
}
1111
}

src/platform/android/jni/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LOCAL_PATH := $(JNI_PATH)
1515
include $(CLEAR_VARS)
1616
LOCAL_MODULE := smallbasic
1717
LOCAL_CFLAGS := -DHAVE_CONFIG_H=1 -DLODEPNG_NO_COMPILE_CPP \
18-
-DPIXELFORMAT_RGBA8888
18+
-DPIXELFORMAT_RGBA8888 -Wno-unknown-pragmas
1919
LOCAL_C_INCLUDES := $(SB_HOME) $(SB_HOME)/src \
2020
$(FREETYPE_HOME)/freetype/include/freetype2 \
2121
$(FREETYPE_HOME)/freetype/include/freetype2/freetype

src/platform/android/jni/runtime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,8 @@ void Runtime::playTone(int frq, int dur, int vol, bool bgplay) {
738738
JNIEnv *env;
739739
_app->activity->vm->AttachCurrentThread(&env, NULL);
740740
jclass clazz = env->GetObjectClass(_app->activity->clazz);
741-
jmethodID methodId = env->GetMethodID(clazz, "playTone", "(III)V");
742-
env->CallVoidMethod(_app->activity->clazz, methodId, frq, dur, vol);
741+
jmethodID methodId = env->GetMethodID(clazz, "playTone", "(IIIZ)V");
742+
env->CallVoidMethod(_app->activity->clazz, methodId, frq, dur, vol, bgplay);
743743
env->DeleteLocalRef(clazz);
744744
_app->activity->vm->DetachCurrentThread();
745745
}

src/ui/textedit.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,15 +1227,16 @@ void TextEditInput::editEnter() {
12271227

12281228
// check whether the previous line was a comment
12291229
char *buf = lineText(prevLineStart);
1230+
int length = strlen(buf);
12301231
int pos = 0;
12311232
while (buf && (buf[pos] == ' ' || buf[pos] == '\t')) {
12321233
pos++;
12331234
}
1234-
if ((buf[pos] == '#' || buf[pos] == '\'') && indent + 2 < LINE_BUFFER_SIZE) {
1235+
if (length > 2 && (buf[pos] == '#' || buf[pos] == '\'') && indent + 2 < LINE_BUFFER_SIZE) {
12351236
spaces[indent] = buf[pos];
12361237
spaces[++indent] = ' ';
12371238
spaces[++indent] = '\0';
1238-
} else if (strncasecmp(buf + pos, "rem", 3) == 0) {
1239+
} else if (length > 4 && strncasecmp(buf + pos, "rem", 3) == 0) {
12391240
indent = strlcat(spaces, "rem ", LINE_BUFFER_SIZE);
12401241
}
12411242
free(buf);

0 commit comments

Comments
 (0)