Skip to content

Commit

Permalink
Gradle: Fix build script, Examples: Added Kotlin example
Browse files Browse the repository at this point in the history
  • Loading branch information
pavly-gerges committed May 5, 2022
1 parent d07a6fb commit e20f678
Show file tree
Hide file tree
Showing 39 changed files with 566 additions and 58 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.6.20'
repositories {
google()
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -18,6 +21,7 @@ allprojects {
google()
jcenter()
mavenCentral()
mavenLocal()
}
}

Expand Down
5 changes: 2 additions & 3 deletions helloandroidharness/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ plugins {
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 31

defaultConfig {
applicationId "com.jme3.helloandroidharness"
minSdkVersion 22
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "1.0"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.jme3.helloandroidharness;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.Menu;

import androidx.annotation.Nullable;

import com.jme3.app.AndroidHarness;

import java.util.Objects;
Expand All @@ -24,4 +31,10 @@ public MainActivity() {
/*get the jme class dir*/
appClass = Objects.requireNonNull(MyGame.class.getName());
}

@Override
protected void onDestroy() {
super.onDestroy();
System.err.println("OnDestroy invoked");
}
}
9 changes: 4 additions & 5 deletions helloandroidui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ plugins {
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 31

defaultConfig {
applicationId "com.jme3.helloandroidui"
minSdkVersion 22
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "1.0"

Expand All @@ -32,12 +31,12 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

/*add the JMonkeyEngine Dependencies*/
implementation "org.jmonkeyengine:jme3-core:3.5.1-stable"
implementation "org.jmonkeyengine:jme3-effects:3.5.1-stable"
implementation "org.jmonkeyengine:jme3-android-native:3.5.1-stable"
implementation "org.jmonkeyengine:jme3-android-native:3.4.0-SNAPSHOT"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.jme3.app.LegacyApplication;
import com.jme3.app.jmeSurfaceView.JmeSurfaceView;
import com.jme3.app.jmeSurfaceView.OnExceptionThrown;
import com.jme3.app.jmeSurfaceView.OnRendererCompleted;
import com.jme3.system.AppSettings;

import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;

import com.jme3.app.LegacyApplication;
import com.jme3.system.AppSettings;
import com.jme3.view.surfaceview.JmeSurfaceView;
import com.jme3.view.surfaceview.OnExceptionThrown;
import com.jme3.view.surfaceview.OnRendererCompleted;

import static android.widget.Toast.LENGTH_LONG;

/**
Expand All @@ -34,6 +34,7 @@
*/
public final class MainActivity extends AppCompatActivity implements OnRendererCompleted, OnExceptionThrown {

private static boolean isRenderingCompleted;
private JmeSurfaceView jmeSurfaceView;
private CardView splashScreen;

Expand All @@ -45,17 +46,24 @@ protected void onCreate(Bundle savedInstanceState) {

/*define the android view with it's id from xml*/
jmeSurfaceView = findViewById(R.id.jmeSurfaceView);
jmeSurfaceView.setDestructionPolicy(JmeSurfaceView.DestructionPolicy.KEEP_WHEN_FINISH);

/*display a splash screen*/
splashScreen = new CardView(MainActivity.this);
splashScreen.setLayoutParams(new RelativeLayout.LayoutParams(jmeSurfaceView.getLayoutParams().width, jmeSurfaceView.getLayoutParams().height));
splashScreen.setBackground(ContextCompat.getDrawable(this, R.drawable.power2));
jmeSurfaceView.addView(splashScreen);
if (!isRenderingCompleted) {
splashScreen = new CardView(MainActivity.this);
splashScreen.setLayoutParams(new RelativeLayout.LayoutParams(jmeSurfaceView.getLayoutParams().width, jmeSurfaceView.getLayoutParams().height));
splashScreen.setBackground(ContextCompat.getDrawable(this, R.drawable.power2));
jmeSurfaceView.addView(splashScreen);
} else {
findViewById(R.id.webView).setVisibility(View.VISIBLE);
findViewById(R.id.image).setVisibility(View.VISIBLE);
}

/*set the jme game*/
jmeSurfaceView.setLegacyApplication(new MyGame());
jmeSurfaceView.setOnExceptionThrown(this);
jmeSurfaceView.setOnRendererCompleted(this);
/*start the game, with delay for the splashScreen*/
jmeSurfaceView.startRenderer(300);
jmeSurfaceView.startRenderer(500);

/*Handle other UI-Components parts*/
final WebView webView = findViewById(R.id.webView);
Expand Down Expand Up @@ -98,6 +106,7 @@ public void onRenderCompletion(LegacyApplication application, AppSettings appSet
/*dismiss the splash screen at the send of the animation*/
jmeSurfaceView.removeView(splashScreen);
}).start();
isRenderingCompleted = true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* To use it inside Android :
* <ol>
* <li>Create an instance of it inside the #{@link MainActivity}</li>
* <li>Set that instance using #{@link com.jme3.app.jmeSurfaceView.JmeSurfaceView#setLegacyApplication(LegacyApplication)}</li>
* <li>Start the game using #{@link com.jme3.app.jmeSurfaceView.JmeSurfaceView#startRenderer(int)}</li>
* <li>Set that instance using #{@link com.jme3.view.surfaceview.JmeSurfaceView#setLegacyApplication(LegacyApplication)}</li>
* <li>Start the game using #{@link com.jme3.view.surfaceview.JmeSurfaceView#startRenderer(int)}</li>
* </ol>
*
* @author pavl_g
*/

public final class MyGame extends SimpleApplication {
@Override
public void simpleInitApp() {
Expand Down
2 changes: 1 addition & 1 deletion helloandroidui/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.jme3.app.jmeSurfaceView.JmeSurfaceView
<com.jme3.view.surfaceview.JmeSurfaceView
android:id="@+id/jmeSurfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
9 changes: 4 additions & 5 deletions hellofragmentharness/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ plugins {
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 31

defaultConfig {
applicationId "com.jme3.hellofragmentharness"
minSdkVersion 22
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "1.0"

Expand All @@ -32,12 +31,12 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

/*add the JMonkeyEngine Dependencies*/
implementation "org.jmonkeyengine:jme3-core:3.5.1-stable"
implementation "org.jmonkeyengine:jme3-effects:3.5.1-stable"
implementation "org.jmonkeyengine:jme3-android-native:3.5.1-stable"
implementation "org.jmonkeyengine:jme3-android-native:3.4.0-SNAPSHOT"
}
13 changes: 7 additions & 6 deletions hellojmesurfaceview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ plugins {
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 31

defaultConfig {
applicationId "com.jme3.hellojmesurfaceview"
minSdkVersion 22
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -37,7 +36,9 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

/*add the JMonkeyEngine Dependencies*/
implementation "org.jmonkeyengine:jme3-core:3.5.1-stable"
implementation "org.jmonkeyengine:jme3-effects:3.5.1-stable"
implementation "org.jmonkeyengine:jme3-android-native:3.5.1-stable"
implementation "org.jmonkeyengine:jme3-core:3.4.0-SNAPSHOT"
//noinspection GradleDependency
implementation "org.jmonkeyengine:jme3-effects:3.4.0-SNAPSHOT"
//noinspection GradleDependency
implementation "org.jmonkeyengine:jme3-android-native:3.4.0-SNAPSHOT"
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package com.jme3.hellojmesurfaceview;
package com.jme3.hellojmesurfaceview;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.content.pm.ActivityInfo;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.TouchDelegate;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

import com.jme3.app.LegacyApplication;
import com.jme3.app.jmeSurfaceView.JmeSurfaceView;
import com.jme3.app.jmeSurfaceView.OnExceptionThrown;
import com.jme3.app.jmeSurfaceView.OnRendererCompleted;
import com.jme3.system.AppSettings;
import com.jme3.app.LegacyApplication;
import com.jme3.system.AppSettings;
import com.jme3.view.surfaceview.JmeSurfaceView;
import com.jme3.view.surfaceview.OnExceptionThrown;
import com.jme3.view.surfaceview.OnRendererCompleted;

import androidx.appcompat.app.AppCompatActivity;

/**
/**
* <b>NB: Please Open this example <u>root module</u> using Android Studio; because android build scripts are different from java builds.</b>
* <br/>
* An Android Example that demonstrates : How to use a simple game#{@link MyGame}
* on #{@link com.jme3.app.jmeSurfaceView.JmeSurfaceView} inside an #{@link androidx.appcompat.app.AppCompatActivity}.
* on #{@link com.jme3.view.surfaceview.JmeSurfaceView} inside an #{@link androidx.appcompat.app.AppCompatActivity}.
* <br>
* <b>Note : use #{@link AppCompatActivity#setRequestedOrientation(int)} and #{@link ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE} for LandScape mode or specify that under the <activity> activity tag xml.</b>
*
Expand All @@ -31,15 +29,15 @@ public final class MainActivity extends AppCompatActivity implements OnRendererC
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
/*define the android view with it's id from xml*/
final JmeSurfaceView jmeSurfaceView = findViewById(R.id.jmeSurfaceView);
jmeSurfaceView.setDestructionPolicy(JmeSurfaceView.DestructionPolicy.KEEP_WHEN_FINISH);
/*set the jme game*/
jmeSurfaceView.setLegacyApplication(new MyGame());
jmeSurfaceView.setOnExceptionThrown(this);
jmeSurfaceView.setOnRendererCompleted(this);
/*start the game*/
jmeSurfaceView.startRenderer(0);
jmeSurfaceView.startRenderer(500);
}

/**
Expand All @@ -51,7 +49,6 @@ protected void onCreate(Bundle savedInstanceState) {
public void onExceptionThrown(Throwable e) {
Toast.makeText(MainActivity.this, "User's Delay Finished w/ exception : " + e.getMessage(), Toast.LENGTH_SHORT).show();
}

/**
* Fired when the user delay in ms is up #{@link JmeSurfaceView#startRenderer(int)}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.jme3.app.LegacyApplication;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetKey;
import com.jme3.input.CameraInput;
import com.jme3.input.ChaseCamera;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
Expand All @@ -14,13 +16,14 @@
* To use it inside Android :
* <ol>
* <li>Create an instance of it inside the #{@link MainActivity}</li>
* <li>Set that instance using #{@link com.jme3.app.jmeSurfaceView.JmeSurfaceView#setLegacyApplication(LegacyApplication)}</li>
* <li>Start the game using #{@link com.jme3.app.jmeSurfaceView.JmeSurfaceView#startRenderer(int)}</li>
* <li>Set that instance using #{@link com.jme3.view.surfaceview.JmeSurfaceView#setLegacyApplication(LegacyApplication)}</li>
* <li>Start the game using #{@link com.jme3.view.surfaceview.JmeSurfaceView#startRenderer(int)}</li>
* </ol>
*
* @author pavl_g
*/
public final class MyGame extends SimpleApplication {

@Override
public void simpleInitApp() {
final Sphere mySphere = new Sphere(10, 50, 50);
Expand Down
2 changes: 1 addition & 1 deletion hellojmesurfaceview/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.jme3.app.jmeSurfaceView.JmeSurfaceView
<com.jme3.view.surfaceview.JmeSurfaceView
android:id="@+id/jmeSurfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
1 change: 1 addition & 0 deletions hellokotlin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading

0 comments on commit e20f678

Please sign in to comment.