| 1 |
extends Node2D |
| 2 |
|
| 3 |
var _plugin_name = "GodotAppInstrumentedTestPlugin" |
| 4 |
var _android_plugin |
| 5 |
|
| 6 |
func _ready(): |
| 7 |
if Engine.has_singleton(_plugin_name): |
| 8 |
_android_plugin = Engine.get_singleton(_plugin_name) |
| 9 |
_android_plugin.connect("launch_tests", _launch_tests) |
| 10 |
_android_plugin.connect("update_quit_on_go_back", _update_quit_on_go_back) |
| 11 |
else: |
| 12 |
printerr("Couldn't find plugin " + _plugin_name) |
| 13 |
get_tree().quit() |
| 14 |
|
| 15 |
func _launch_tests(test_label: String) -> void: |
| 16 |
var test_instance: BaseTest = null |
| 17 |
match test_label: |
| 18 |
"javaclasswrapper_tests": |
| 19 |
test_instance = JavaClassWrapperTests.new() |
| 20 |
"file_access_tests": |
| 21 |
test_instance = FileAccessTests.new() |
| 22 |
|
| 23 |
if test_instance: |
| 24 |
test_instance.__reset_tests() |
| 25 |
test_instance.run_tests() |
| 26 |
var incomplete_tests = test_instance._test_started - test_instance._test_completed |
| 27 |
_android_plugin.onTestsCompleted(test_label, test_instance._test_completed, test_instance._test_assert_failures + incomplete_tests) |
| 28 |
else: |
| 29 |
_android_plugin.onTestsFailed(test_label, "Unable to launch tests") |
| 30 |
|
| 31 |
|
| 32 |
func _update_quit_on_go_back(quit_on_go_back: bool) -> void: |
| 33 |
get_tree().quit_on_go_back = quit_on_go_back |
| 34 |
|
| 35 |
|
| 36 |
func _on_plugin_toast_button_pressed() -> void: |
| 37 |
if _android_plugin: |
| 38 |
_android_plugin.helloWorld() |
| 39 |
|
| 40 |
func _on_vibration_button_pressed() -> void: |
| 41 |
var android_runtime = Engine.get_singleton("AndroidRuntime") |
| 42 |
if android_runtime: |
| 43 |
print("Checking if the device supports vibration") |
| 44 |
var vibrator_service = android_runtime.getApplicationContext().getSystemService("vibrator") |
| 45 |
if vibrator_service: |
| 46 |
if vibrator_service.hasVibrator(): |
| 47 |
print("Vibration is supported on device! Vibrating now...") |
| 48 |
var VibrationEffect = JavaClassWrapper.wrap("android.os.VibrationEffect") |
| 49 |
var effect = VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE) |
| 50 |
vibrator_service.vibrate(effect) |
| 51 |
else: |
| 52 |
printerr("Vibration is not supported on device") |
| 53 |
else: |
| 54 |
printerr("Unable to retrieve the vibrator service") |
| 55 |
else: |
| 56 |
printerr("Couldn't find AndroidRuntime singleton") |
| 57 |
|
| 58 |
func _on_gd_script_toast_button_pressed() -> void: |
| 59 |
var android_runtime = Engine.get_singleton("AndroidRuntime") |
| 60 |
if android_runtime: |
| 61 |
var activity = android_runtime.getActivity() |
| 62 |
|
| 63 |
var toastCallable = func (): |
| 64 |
var ToastClass = JavaClassWrapper.wrap("android.widget.Toast") |
| 65 |
ToastClass.makeText(activity, "Toast from GDScript", ToastClass.LENGTH_LONG).show() |
| 66 |
|
| 67 |
activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(toastCallable)) |