-
Notifications
You must be signed in to change notification settings - Fork 401
/
MainActivity.java
101 lines (86 loc) · 3.06 KB
/
MainActivity.java
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
94
95
96
97
98
99
100
101
package com.google.firebase.example.testlab;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import com.google.android.libraries.cloudtesting.screenshots.ScreenShotter;
import java.io.FileNotFoundException;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void checkEnvironment() {
// [START ftl_check_env]
String testLabSetting = Settings.System.getString(getContentResolver(), "firebase.test.lab");
if ("true".equals(testLabSetting)) {
// Do something when running in Test Lab
// ...
}
// [END ftl_check_env]
}
public void gameCheckIntent() {
// [START ftl_game_check_intent]
Intent launchIntent = getIntent();
if(launchIntent.getAction().equals("com.google.intent.action.TEST_LOOP")) {
int scenario = launchIntent.getIntExtra("scenario", 0);
// Code to handle your game loop here
}
// [END ftl_game_check_intent]
}
public void gameFinish() {
Activity yourActivity = this;
// [START ftl_game_finish]
yourActivity.finish();
// [END ftl_game_finish]
}
public void gameOutputFile() {
// [START ftl_game_output_file]
Intent launchIntent = getIntent();
Uri logFile = launchIntent.getData();
if (logFile != null) {
Log.i(TAG, "Log file " + logFile.getEncodedPath());
// ...
}
// [END ftl_game_output_file]
}
public void gameOutputFileDescriptor() throws FileNotFoundException {
// [START ftl_game_output_fd]
Intent launchIntent = getIntent();
Uri logFile = launchIntent.getData();
int fd = -1;
if (logFile != null) {
Log.i(TAG, "Log file " + logFile.getEncodedPath());
try {
fd = getContentResolver()
.openAssetFileDescriptor(logFile, "w")
.getParcelFileDescriptor()
.getFd();
} catch (FileNotFoundException e) {
e.printStackTrace();
fd = -1;
} catch (NullPointerException e) {
e.printStackTrace();
fd = -1;
}
}
// C++ code invoked here.
// native_function(fd);
// [END ftl_game_output_fd]
}
public void gameScenario() {
// [START ftl_game_scenario]
Intent launchIntent = getIntent();
int scenario = launchIntent.getIntExtra("scenario", 0);
// [END ftl_game_scenario]
}
public void takeScreenshot() {
// [START ftl_take_screenshot]
ScreenShotter.takeScreenshot("main_screen_2", this /* activity */);
// [END ftl_take_screenshot]
}
}