Skip to content

Commit

Permalink
Updating Teapot sample to GPGS 3.0 and CMake
Browse files Browse the repository at this point in the history
Change-Id: I150d1c64aa39f15403002542eacb6da1acd73f42
  • Loading branch information
claywilkinson committed Jan 3, 2018
1 parent a81e0c9 commit 2299766
Show file tree
Hide file tree
Showing 39 changed files with 261 additions and 3,929 deletions.
67 changes: 67 additions & 0 deletions samples-android/Teapot/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (C) 2017 Google Inc.
#
# 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
#
# http://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.
##

cmake_minimum_required(VERSION 3.4.1)

add_library(gpg_sdk STATIC IMPORTED)
set_target_properties(gpg_sdk PROPERTIES IMPORTED_LOCATION
${GPG_SDK_PATH}/lib/c++/${ANDROID_ABI}/libgpg.a)

# build native_app_glue as a static lib
add_library(native_app_glue STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

# build cpufeatures as a static lib
add_library(cpufeatures STATIC
${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)

#include the native part of JUI Helper
add_subdirectory (${JUI_HELPER_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libjuihelper")

#include the native part of NDKHelper
add_subdirectory (${NDK_HELPER_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libndkhelper")

# Export ANativeActivity_onCreate(),
# Refer to: https://github.com/android-ndk/ndk/issues/381.
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")

add_library(teapot
SHARED
src/main/jni/NativeGameActivity.cpp
src/main/jni/StateManager.cpp
${TEAPOT_RENDERER_PATH}/TeapotRenderer.cpp
)

target_include_directories(teapot PRIVATE
${ANDROID_NDK}/sources/android/native_app_glue
${ANDROID_NDK}/sources/android/cpufeatures
${GPG_SDK_PATH}/include
${juihelper_SOURCE_DIR}/src/main/cpp
${ndkhelper_SOURCE_DIR}/src/main/cpp
${TEAPOT_RENDERER_PATH}
)

target_link_libraries( # Specifies the target library.
teapot
gpg_sdk
native_app_glue
cpufeatures
juihelper
ndkhelper
log
android
EGL
GLESv2
z)
56 changes: 26 additions & 30 deletions samples-android/Teapot/build.gradle
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
apply plugin: 'com.android.application'

// Depend on another project that downloads and unzips the C++ SDK.
evaluationDependsOn(':Common/gpg-sdk')

// As the plugin has created the build tasks, add the gpg-sdk task to
// the task dependencies so it gets done before compiling
tasks.whenTaskAdded { task ->
project(':Common/gpg-sdk').defaultTasks.each {
t ->task.dependsOn project(':Common/gpg-sdk').tasks[t]

}
}

android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
compileSdkVersion 26
defaultConfig {
//
// REPLACE THE APPLICATION ID with your bundle ID
//
applicationId "com.google.example.games.ReplaceMe"
minSdkVersion 14
targetSdkVersion 23
applicationId "com.google.example.games.ReplaceMe"
minSdkVersion 14
targetSdkVersion 26

ndk.abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a'

externalNativeBuild {
cmake {
cppFlags "-std=c++11 -Wall -frtti"
arguments "-DJUI_HELPER_PATH=${project(':Common:JuiHelper').projectDir}" ,
"-DNDK_HELPER_PATH=${project(':Common:NDKHelper').projectDir}" ,
"-DGPG_SDK_PATH=${project(':Common:gpg-sdk').projectDir}/gpg-cpp-sdk/android",
"-DTEAPOT_RENDERER_PATH=${project(':Common').projectDir}/TeapotRenderer" ,
"-DANDROID_STL=c++_static"
}

ndk {
abiFilters 'x86', 'armeabi-v7a'
}
}
}

externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
}

externalNativeBuild {
cmake.path "CMakeLists.txt"
}
}
dependencies {
compile 'com.google.android.gms:play-services-games:10.0.0'
compile 'com.google.android.gms:play-services-nearby:10.0.0'
compile 'com.android.support:support-v4:23.1.1'
implementation project(":Common:JuiHelper")
implementation 'com.google.android.gms:play-services-games:11.6.2'
implementation 'com.google.android.gms:play-services-nearby:11.6.2'
implementation 'com.android.support:support-v4:26.1.0'
}
19 changes: 18 additions & 1 deletion samples-android/Teapot/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
// Copyright (c) 2014 Google Inc.
//
// 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
//
// http://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.
//
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.example.nativegame"
android:versionCode="1"
Expand All @@ -23,7 +40,7 @@
android:configChanges="orientation|keyboardHidden">
<!-- Tell NativeActivity the name of or .so -->
<meta-data android:name="android.app.lib_name"
android:value="NativeGameActivity" />
android:value="teapot" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
1 change: 0 additions & 1 deletion samples-android/Teapot/src/main/ant.properties

This file was deleted.

7 changes: 0 additions & 7 deletions samples-android/Teapot/src/main/build.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package com.google.example.nativegame;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.NativeActivity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
Expand All @@ -29,6 +31,8 @@
import android.widget.PopupWindow;
import android.widget.TextView;

import java.util.Locale;

public class NativeGameActivity extends NativeActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -62,7 +66,8 @@ protected void onResume() {
}
else if(SDK_INT >= 14 && SDK_INT < 19)
{
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
else if(SDK_INT >= 19)
{
Expand All @@ -72,6 +77,7 @@ else if(SDK_INT >= 19)
}
// Our popup window, you will call it from your C/C++ code later

@TargetApi(Build.VERSION_CODES.KITKAT)
void setImmersiveSticky() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
Expand Down Expand Up @@ -99,22 +105,27 @@ public void run() {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.widgets, null);
_popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);

LinearLayout mainLayout = new LinearLayout(_activity);
MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 0);
_activity.setContentView(mainLayout, params);

// Show our UI over NativeActivity window
_popupWindow.showAtLocation(mainLayout, Gravity.TOP | Gravity.LEFT, 10, 10);
_popupWindow.update();

_label = (TextView)popupView.findViewById(R.id.textViewFPS);
if (layoutInflater != null) {
View popupView = layoutInflater.inflate(R.layout.widgets, null);
_popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);

LinearLayout mainLayout = new LinearLayout(_activity);
MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 0);
_activity.setContentView(mainLayout, params);

// Show our UI over NativeActivity window
_popupWindow.showAtLocation(mainLayout, Gravity.TOP | Gravity.START, 10, 10);
_popupWindow.update();

_label = popupView.findViewById(R.id.textViewFPS);
} else {
throw new IllegalStateException("Cannot get layout service!");
}

}});
}
Expand All @@ -128,7 +139,7 @@ public void updateFPS(final float fFPS)
this.runOnUiThread(new Runnable() {
@Override
public void run() {
_label.setText(String.format("%2.2f FPS", fFPS));
_label.setText(String.format(Locale.getDefault(),"%2.2f FPS", fFPS));

}});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
package com.google.example.nativegame;

import android.app.Application;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
import android.widget.Toast;

public class NativeGameApplication extends Application {
public void onCreate(){
super.onCreate();
Log.w("native-activity", "onCreate");
}
}

This file was deleted.

Loading

0 comments on commit 2299766

Please sign in to comment.