Skip to content

Commit bcaf6c8

Browse files
committed
ANDROID: fix toast duration
1 parent ecf5f0a commit bcaf6c8

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/platform/android/jni/runtime.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,16 @@ void Runtime::alert(const char *title, const char *message) {
191191
_app->activity->vm->DetachCurrentThread();
192192
}
193193

194-
void Runtime::alert(const char *title, int duration) {
194+
void Runtime::alert(const char *title, bool longDuration) {
195195
logEntered();
196196

197197
JNIEnv *env;
198198
_app->activity->vm->AttachCurrentThread(&env, NULL);
199199
jstring titleString = env->NewStringUTF(title);
200200
jclass clazz = env->GetObjectClass(_app->activity->clazz);
201201
jmethodID method = env->GetMethodID(clazz, "showToast",
202-
"(Ljava/lang/String;I)V");
203-
env->CallVoidMethod(_app->activity->clazz, method, titleString, duration);
202+
"(Ljava/lang/String;Z)V");
203+
env->CallVoidMethod(_app->activity->clazz, method, titleString, longDuration);
204204
env->DeleteLocalRef(clazz);
205205
env->DeleteLocalRef(titleString);
206206
_app->activity->vm->DetachCurrentThread();

src/platform/android/jni/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct Runtime : public System {
2222
virtual ~Runtime();
2323

2424
void alert(const char *title, const char *message);
25-
void alert(const char *title, int duration = 5000);
25+
void alert(const char *title, bool longDuration=true);
2626
int ask(const char *title, const char *prompt, bool cancel);
2727
void clearSoundQueue();
2828
void construct();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,12 @@ public void onClick(DialogInterface dialog, int which) {}
301301
});
302302
}
303303

304-
public void showToast(final String message, final int duration) {
304+
public void showToast(final String message, final boolean longDurarion) {
305+
Log.i(TAG, "toast longDuration: " + longDurarion);
305306
final Activity activity = this;
306307
runOnUiThread(new Runnable() {
307308
public void run() {
309+
int duration = longDurarion ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
308310
Toast.makeText(activity, message, duration).show();
309311
}
310312
});

0 commit comments

Comments
 (0)