/
ADPFSampleActivity.java
87 lines (76 loc) · 3.32 KB
/
ADPFSampleActivity.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
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.example.games;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import com.google.androidgamesdk.GameActivity;
// A minimal extension of GameActivity. For this sample, it is used to invoke
// a workaround for loading the runtime shared library on old Android versions.
public class ADPFSampleActivity extends GameActivity {
// Load our native library:
static {
// Load the STL first to workaround issues on old Android versions:
// "if your app targets a version of Android earlier than
// Android 4.3 (Android API level 18),
// and you use libc++_shared.so, you must load the shared library before any other
// library that depends on it."
// See https://developer.android.com/ndk/guides/cpp-support#shared_runtimes
System.loadLibrary("c++_shared");
// Load the game library:
System.loadLibrary("game");
}
private void hideSystemUI() {
// This will put the game behind any cutouts and waterfalls on devices which have
// them, so the corresponding insets will be non-zero.
if (VERSION.SDK_INT >= VERSION_CODES.P) {
getWindow().getAttributes().layoutInDisplayCutoutMode
= LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
}
// From API 30 onwards, this is the recommended way to hide the system UI, rather than
// using View.setSystemUiVisibility.
View decorView = getWindow().getDecorView();
WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(getWindow(),
decorView);
controller.hide(WindowInsetsCompat.Type.systemBars());
controller.hide(WindowInsetsCompat.Type.displayCutout());
controller.setSystemBarsBehavior(
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// When true, the app will fit inside any system UI windows.
// When false, we render behind any system UI windows.
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
hideSystemUI();
super.onCreate(savedInstanceState);
}
// onResume() the activity, register the thermal status listener.
@Override
protected void onResume() {
super.onResume();
}
// onPause(), removing the thermal state change listener.
@Override
protected void onPause() {
super.onPause();
}
}