Skip to content

Commit 2299766

Browse files
committed
Updating Teapot sample to GPGS 3.0 and CMake
Change-Id: I150d1c64aa39f15403002542eacb6da1acd73f42
1 parent a81e0c9 commit 2299766

39 files changed

Lines changed: 261 additions & 3929 deletions
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright (C) 2017 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
##
15+
16+
cmake_minimum_required(VERSION 3.4.1)
17+
18+
add_library(gpg_sdk STATIC IMPORTED)
19+
set_target_properties(gpg_sdk PROPERTIES IMPORTED_LOCATION
20+
${GPG_SDK_PATH}/lib/c++/${ANDROID_ABI}/libgpg.a)
21+
22+
# build native_app_glue as a static lib
23+
add_library(native_app_glue STATIC
24+
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
25+
26+
# build cpufeatures as a static lib
27+
add_library(cpufeatures STATIC
28+
${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
29+
30+
#include the native part of JUI Helper
31+
add_subdirectory (${JUI_HELPER_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libjuihelper")
32+
33+
#include the native part of NDKHelper
34+
add_subdirectory (${NDK_HELPER_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libndkhelper")
35+
36+
# Export ANativeActivity_onCreate(),
37+
# Refer to: https://github.com/android-ndk/ndk/issues/381.
38+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
39+
40+
add_library(teapot
41+
SHARED
42+
src/main/jni/NativeGameActivity.cpp
43+
src/main/jni/StateManager.cpp
44+
${TEAPOT_RENDERER_PATH}/TeapotRenderer.cpp
45+
)
46+
47+
target_include_directories(teapot PRIVATE
48+
${ANDROID_NDK}/sources/android/native_app_glue
49+
${ANDROID_NDK}/sources/android/cpufeatures
50+
${GPG_SDK_PATH}/include
51+
${juihelper_SOURCE_DIR}/src/main/cpp
52+
${ndkhelper_SOURCE_DIR}/src/main/cpp
53+
${TEAPOT_RENDERER_PATH}
54+
)
55+
56+
target_link_libraries( # Specifies the target library.
57+
teapot
58+
gpg_sdk
59+
native_app_glue
60+
cpufeatures
61+
juihelper
62+
ndkhelper
63+
log
64+
android
65+
EGL
66+
GLESv2
67+
z)
Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
11
apply plugin: 'com.android.application'
22

3-
// Depend on another project that downloads and unzips the C++ SDK.
4-
evaluationDependsOn(':Common/gpg-sdk')
5-
6-
// As the plugin has created the build tasks, add the gpg-sdk task to
7-
// the task dependencies so it gets done before compiling
8-
tasks.whenTaskAdded { task ->
9-
project(':Common/gpg-sdk').defaultTasks.each {
10-
t ->task.dependsOn project(':Common/gpg-sdk').tasks[t]
11-
12-
}
13-
}
14-
153
android {
16-
compileSdkVersion 23
17-
buildToolsVersion '23.0.2'
18-
defaultConfig {
4+
compileSdkVersion 26
5+
defaultConfig {
196
//
207
// REPLACE THE APPLICATION ID with your bundle ID
218
//
22-
applicationId "com.google.example.games.ReplaceMe"
23-
minSdkVersion 14
24-
targetSdkVersion 23
9+
applicationId "com.google.example.games.ReplaceMe"
10+
minSdkVersion 14
11+
targetSdkVersion 26
12+
13+
ndk.abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a'
14+
15+
externalNativeBuild {
16+
cmake {
17+
cppFlags "-std=c++11 -Wall -frtti"
18+
arguments "-DJUI_HELPER_PATH=${project(':Common:JuiHelper').projectDir}" ,
19+
"-DNDK_HELPER_PATH=${project(':Common:NDKHelper').projectDir}" ,
20+
"-DGPG_SDK_PATH=${project(':Common:gpg-sdk').projectDir}/gpg-cpp-sdk/android",
21+
"-DTEAPOT_RENDERER_PATH=${project(':Common').projectDir}/TeapotRenderer" ,
22+
"-DANDROID_STL=c++_static"
23+
}
2524

26-
ndk {
27-
abiFilters 'x86', 'armeabi-v7a'
25+
}
2826
}
29-
}
3027

31-
externalNativeBuild {
32-
ndkBuild {
33-
path 'src/main/jni/Android.mk'
34-
}
35-
}
36-
}
3728

29+
externalNativeBuild {
30+
cmake.path "CMakeLists.txt"
31+
}
32+
}
3833
dependencies {
39-
compile 'com.google.android.gms:play-services-games:10.0.0'
40-
compile 'com.google.android.gms:play-services-nearby:10.0.0'
41-
compile 'com.android.support:support-v4:23.1.1'
34+
implementation project(":Common:JuiHelper")
35+
implementation 'com.google.android.gms:play-services-games:11.6.2'
36+
implementation 'com.google.android.gms:play-services-nearby:11.6.2'
37+
implementation 'com.android.support:support-v4:26.1.0'
4238
}

‎samples-android/Teapot/src/main/AndroidManifest.xml‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
// Copyright (c) 2014 Google Inc.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//
17+
-->
118
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
219
package="com.google.example.nativegame"
320
android:versionCode="1"
@@ -23,7 +40,7 @@
2340
android:configChanges="orientation|keyboardHidden">
2441
<!-- Tell NativeActivity the name of or .so -->
2542
<meta-data android:name="android.app.lib_name"
26-
android:value="NativeGameActivity" />
43+
android:value="teapot" />
2744
<intent-filter>
2845
<action android:name="android.intent.action.MAIN" />
2946
<category android:name="android.intent.category.LAUNCHER" />

‎samples-android/Teapot/src/main/ant.properties‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎samples-android/Teapot/src/main/build.sh‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎samples-android/Teapot/src/main/java/com/google/example/nativegame/NativeGameActivity.java‎

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
package com.google.example.nativegame;
1818

19+
import android.annotation.TargetApi;
1920
import android.app.Activity;
2021
import android.app.NativeActivity;
2122
import android.content.Intent;
23+
import android.os.Build;
2224
import android.os.Bundle;
2325
import android.view.Gravity;
2426
import android.view.LayoutInflater;
@@ -29,6 +31,8 @@
2931
import android.widget.PopupWindow;
3032
import android.widget.TextView;
3133

34+
import java.util.Locale;
35+
3236
public class NativeGameActivity extends NativeActivity {
3337
@Override
3438
protected void onCreate(Bundle savedInstanceState) {
@@ -62,7 +66,8 @@ protected void onResume() {
6266
}
6367
else if(SDK_INT >= 14 && SDK_INT < 19)
6468
{
65-
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE);
69+
getWindow().getDecorView().setSystemUiVisibility(
70+
View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE);
6671
}
6772
else if(SDK_INT >= 19)
6873
{
@@ -72,6 +77,7 @@ else if(SDK_INT >= 19)
7277
}
7378
// Our popup window, you will call it from your C/C++ code later
7479

80+
@TargetApi(Build.VERSION_CODES.KITKAT)
7581
void setImmersiveSticky() {
7682
View decorView = getWindow().getDecorView();
7783
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
@@ -99,22 +105,27 @@ public void run() {
99105
LayoutInflater layoutInflater
100106
= (LayoutInflater)getBaseContext()
101107
.getSystemService(LAYOUT_INFLATER_SERVICE);
102-
View popupView = layoutInflater.inflate(R.layout.widgets, null);
103-
_popupWindow = new PopupWindow(
104-
popupView,
105-
LayoutParams.WRAP_CONTENT,
106-
LayoutParams.WRAP_CONTENT);
107-
108-
LinearLayout mainLayout = new LinearLayout(_activity);
109-
MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
110-
params.setMargins(0, 0, 0, 0);
111-
_activity.setContentView(mainLayout, params);
112-
113-
// Show our UI over NativeActivity window
114-
_popupWindow.showAtLocation(mainLayout, Gravity.TOP | Gravity.LEFT, 10, 10);
115-
_popupWindow.update();
116-
117-
_label = (TextView)popupView.findViewById(R.id.textViewFPS);
108+
if (layoutInflater != null) {
109+
View popupView = layoutInflater.inflate(R.layout.widgets, null);
110+
_popupWindow = new PopupWindow(
111+
popupView,
112+
LayoutParams.WRAP_CONTENT,
113+
LayoutParams.WRAP_CONTENT);
114+
115+
LinearLayout mainLayout = new LinearLayout(_activity);
116+
MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT,
117+
LayoutParams.WRAP_CONTENT);
118+
params.setMargins(0, 0, 0, 0);
119+
_activity.setContentView(mainLayout, params);
120+
121+
// Show our UI over NativeActivity window
122+
_popupWindow.showAtLocation(mainLayout, Gravity.TOP | Gravity.START, 10, 10);
123+
_popupWindow.update();
124+
125+
_label = popupView.findViewById(R.id.textViewFPS);
126+
} else {
127+
throw new IllegalStateException("Cannot get layout service!");
128+
}
118129

119130
}});
120131
}
@@ -128,7 +139,7 @@ public void updateFPS(final float fFPS)
128139
this.runOnUiThread(new Runnable() {
129140
@Override
130141
public void run() {
131-
_label.setText(String.format("%2.2f FPS", fFPS));
142+
_label.setText(String.format(Locale.getDefault(),"%2.2f FPS", fFPS));
132143

133144
}});
134145
}

‎samples-android/Teapot/src/main/java/com/google/example/nativegame/NativeGameApplication.java‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@
1717
package com.google.example.nativegame;
1818

1919
import android.app.Application;
20-
import android.content.pm.ApplicationInfo;
21-
import android.content.pm.PackageManager;
22-
import android.content.pm.PackageManager.NameNotFoundException;
2320
import android.util.Log;
24-
import android.widget.Toast;
2521

2622
public class NativeGameApplication extends Application {
2723
public void onCreate(){
24+
super.onCreate();
2825
Log.w("native-activity", "onCreate");
2926
}
3027
}

‎samples-android/Teapot/src/main/java/com/sample/helper/JUIAlertDialog.java‎

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)