-
Notifications
You must be signed in to change notification settings - Fork 403
/
MainActivity.kt
93 lines (82 loc) · 2.71 KB
/
MainActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.google.firebase.example.testlab.kotlin
import android.provider.Settings
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.google.android.libraries.cloudtesting.screenshots.ScreenShotter
import java.io.FileNotFoundException
class MainActivity : AppCompatActivity() {
companion object {
private const val TAG = "MainActivity"
}
private fun checkEnvironment() {
// [START ftl_check_env]
val testLabSetting = Settings.System.getString(contentResolver, "firebase.test.lab")
if ("true" == testLabSetting) {
// Do something when running in Test Lab
// ...
}
// [END ftl_check_env]
}
private fun gameCheckIntent() {
// [START ftl_game_check_intent]
val launchIntent = intent
if (launchIntent.action == "com.google.intent.action.TEST_LOOP") {
val scenario = launchIntent.getIntExtra("scenario", 0)
// Code to handle your game loop here
}
// [END ftl_game_check_intent]
}
private fun gameFinish() {
val yourActivity = this
// [START ftl_game_finish]
yourActivity.finish()
// [END ftl_game_finish]
}
private fun gameOutputFile() {
// [START ftl_game_output_file]
val launchIntent = intent
val logFile = launchIntent.data
logFile?.let {
Log.i(TAG, "Log file ${it.encodedPath}")
// ...
}
// [END ftl_game_output_file]
}
@Throws(FileNotFoundException::class)
private fun gameOutputFileDescriptor() {
// [START ftl_game_output_fd]
val launchIntent = intent
val logFile = launchIntent.data
var fd = -1
logFile?.let {
Log.i(TAG, "Log file ${it.encodedPath}")
fd = try {
contentResolver
.openAssetFileDescriptor(logFile, "w")!!
.parcelFileDescriptor
.fd
} catch (e: FileNotFoundException) {
e.printStackTrace()
-1
} catch (e: NullPointerException) {
e.printStackTrace()
-1
}
}
// C++ code invoked here.
// native_function(fd);
// [END ftl_game_output_fd]
}
private fun gameScenario() {
// [START ftl_game_scenario]
val launchIntent = intent
val scenario = launchIntent.getIntExtra("scenario", 0)
// [END ftl_game_scenario]
}
private fun takeScreenshot() {
val activity = this
// [START ftl_take_screenshot]
ScreenShotter.takeScreenshot("main_screen_2", activity)
// [END ftl_take_screenshot]
}
}