Splash Screen for Android

Here you go.



[java]

This patch file was generated by NetBeans IDE

Following Index: paths are relative to: D:UserspotterecDocumentsjMonkeyProjects_NightlyjME3srcandroidcomjme3app

This patch can be applied using context Tools: Patch action on respective folder.

It uses platform neutral UTF-8 encoding and n newlines.

Above lines and this line are ignored by the patching process.

Index: AndroidHarness.java

— AndroidHarness.java Base (BASE)

+++ AndroidHarness.java Locally Modified (Based On LOCAL)

@@ -7,8 +7,12 @@

import android.opengl.GLSurfaceView;

import android.os.Bundle;

import android.view.Display;

+import android.view.View;

+import android.view.ViewGroup.LayoutParams;

import android.view.Window;

import android.view.WindowManager;

+import android.widget.FrameLayout;

+import android.widget.ImageView;

import android.widget.TextView;

import com.jme3.input.android.AndroidInput;

import com.jme3.input.controls.TouchListener;

@@ -86,6 +90,13 @@

protected boolean screenShowTitle = true;



/**

  • * Splash Screen picture Resource ID.  If a Splash Screen is desired, set<br />
    
  • * splashPicID to the value of the Resource ID (i.e. R.drawable.picname).<br />
    
  • * If splashPicID = 0, then no splash screen will be displayed.<br />
    
  • */<br />
    
  • protected int splashPicID = 0;

    +
  • /**
  • Set the screen orientation, default is SENSOR
  • ActivityInfo.SCREEN_ORIENTATION_* constants
  • package android.content.pm.ActivityInfo

    @@ -102,6 +113,8 @@

    protected OGLESContext ctx;

    protected GLSurfaceView view = null;

    protected boolean isGLThreadPaused = true;
  • private ImageView splashImageView = null;
  • private FrameLayout frameLayout = null;

    final private String ESCAPE_EVENT = "TouchEscape";



    static {

    @@ -167,7 +180,6 @@

    app.start();

    ctx = (OGLESContext) app.getContext();

    view = ctx.createView(input, eglConfigType, eglConfigVerboseLogging);
  •        setContentView(view);<br />
    

// Set the screen reolution
WindowManager wind = this.getWindowManager();
@@ -176,6 +188,9 @@

AppSettings s = ctx.getSettings();
logger.log(Level.INFO, "Settings: Width {0} Height {1}", new Object[]{s.getWidth(), s.getHeight()});
+
+ layoutDisplay();
+
} catch (Exception ex) {
handleError("Class " + appClass + " init failed", ex);
setContentView(new TextView(this));
@@ -310,4 +325,49 @@
}

}
+
+ public void layoutDisplay() {
+ logger.log(Level.INFO, "Splash Screen Picture Resource ID: {0}", splashPicID);
+ if (splashPicID != 0) {
+ LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
+
+ frameLayout = new FrameLayout(this);
+ frameLayout.setLayoutParams(lp);
+
+ splashImageView = new ImageView(this);
+ splashImageView.setImageResource(splashPicID);
+ splashImageView.setLayoutParams(lp);
+
+ frameLayout.addView(view);
+ frameLayout.addView(splashImageView, lp);
+
+ setContentView(frameLayout);
+ logger.log(Level.INFO, "Splash Screen Created");
+ } else {
+ logger.log(Level.INFO, "Splash Screen Skipped.");
+ setContentView(view);
}
+
+ }
+
+ public void removeSplashScreen() {
+ logger.log(Level.INFO, "Splash Screen Picture Resource ID: {0}", splashPicID);
+ if (splashPicID != 0) {
+ if (frameLayout != null) {
+ if (splashImageView != null) {
+ this.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ splashImageView.setVisibility(View.INVISIBLE);
+ frameLayout.removeView(splashImageView);
+ }
+ });
+ } else {
+ logger.log(Level.INFO, "splashImageView is null");
+ }
+ } else {
+ logger.log(Level.INFO, "frameLayout is null");
+ }
+ }
+ }
+}

[/java]

[java]
# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: D:UserspotterecDocumentsjMonkeyProjects_NightlyjME3srcandroidcomjme3systemandroid
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and n newlines.
# Above lines and this line are ignored by the patching process.
Index: OGLESContext.java
--- OGLESContext.java Base (BASE)
+++ OGLESContext.java Locally Modified (Based On LOCAL)
@@ -83,6 +83,7 @@
protected boolean autoFlush = true;

protected AndroidInput view;
+ private boolean firstDrawFrame = true;

private long milliStart;
private long milliDelta;
@@ -408,9 +409,17 @@
milliStart = System.currentTimeMillis();


-
listener.update();

+ // call to AndroidHarness to remove the splash screen, if present.
+ // call after listener.update() to make sure no gap between
+ // splash screen going away and app display being shown.
+ if (firstDrawFrame) {
+ final Context ctx = this.view.getContext();
+ if (ctx instanceof AndroidHarness) {
+ ((AndroidHarness)ctx).removeSplashScreen();
+ }
+ }

if (autoFlush)
{
@@ -431,7 +440,7 @@

}

-
+ firstDrawFrame = false;
}

@Override

[/java]
1 Like

BTW, I didn’t test this with a 9-patch type png file. Right now the image is scaled to be either full width or full height without modifying the aspect ratio of the picture. I think with a 9-patch image file it will scale to full screen both ways without affecting the original image (depending on the 9-patch scaling regions of course).



Also, I didn’t put in the ability to set the background color. I didn’t think that was necessary. Let me know what you think.

So. 9-patch files are not stretching right now. I think allowing users to use 9-patch files so that the splash screen stretches to full screen would be a nice addition to this. I think I need to change the splash image view in order to support 9-patch files (set background image instead of setImageResource). I’d like to add that support in as well. I think I can make it so if the user selects a normal image file, the image is scaled while maintaining the aspect ratio to fill either the height or width and if they select a 9-patch file, the image fills the screen completely.

Here’s an updated patch file that includes automatically switching the splash screen view to handle standard drawables and 9-patch drawables based on the resource id supplied by the user. Let me know if you try this out.



[java]

This patch file was generated by NetBeans IDE

Following Index: paths are relative to: D:UserspotterecDocumentsjMonkeyProjects_NightlyjME3srcandroidcomjme3app

This patch can be applied using context Tools: Patch action on respective folder.

It uses platform neutral UTF-8 encoding and n newlines.

Above lines and this line are ignored by the patching process.

Index: AndroidHarness.java

— AndroidHarness.java Base (BASE)

+++ AndroidHarness.java Locally Modified (Based On LOCAL)

@@ -4,11 +4,18 @@

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.content.pm.ActivityInfo;

+import android.graphics.drawable.Drawable;

+import android.graphics.drawable.NinePatchDrawable;

import android.opengl.GLSurfaceView;

import android.os.Bundle;

import android.view.Display;

+import android.view.Gravity;

+import android.view.View;

+import android.view.ViewGroup.LayoutParams;

import android.view.Window;

import android.view.WindowManager;

+import android.widget.FrameLayout;

+import android.widget.ImageView;

import android.widget.TextView;

import com.jme3.input.android.AndroidInput;

import com.jme3.input.controls.TouchListener;

@@ -86,6 +93,13 @@

protected boolean screenShowTitle = true;



/**

  • * Splash Screen picture Resource ID.  If a Splash Screen is desired, set<br />
    
  • * splashPicID to the value of the Resource ID (i.e. R.drawable.picname).<br />
    
  • * If splashPicID = 0, then no splash screen will be displayed.<br />
    
  • */<br />
    
  • protected int splashPicID = 0;

    +
  • /**
  • Set the screen orientation, default is SENSOR
  • ActivityInfo.SCREEN_ORIENTATION_* constants
  • package android.content.pm.ActivityInfo

    @@ -102,6 +116,9 @@

    protected OGLESContext ctx;

    protected GLSurfaceView view = null;

    protected boolean isGLThreadPaused = true;
  • private ImageView splashImageView = null;
  • private View splashView = null;
  • private FrameLayout frameLayout = null;

    final private String ESCAPE_EVENT = "TouchEscape";



    static {

    @@ -167,7 +184,6 @@

    app.start();

    ctx = (OGLESContext) app.getContext();

    view = ctx.createView(input, eglConfigType, eglConfigVerboseLogging);
  •        setContentView(view);<br />
    

// Set the screen reolution
WindowManager wind = this.getWindowManager();
@@ -176,6 +192,9 @@

AppSettings s = ctx.getSettings();
logger.log(Level.INFO, "Settings: Width {0} Height {1}", new Object[]{s.getWidth(), s.getHeight()});
+
+ layoutDisplay();
+
} catch (Exception ex) {
handleError("Class " + appClass + " init failed", ex);
setContentView(new TextView(this));
@@ -310,4 +329,57 @@
}

}
+
+ public void layoutDisplay() {
+ logger.log(Level.INFO, "Splash Screen Picture Resource ID: {0}", splashPicID);
+ if (splashPicID != 0) {
+ FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
+ LayoutParams.FILL_PARENT,
+ LayoutParams.FILL_PARENT,
+ Gravity.CENTER
+ );
+
+ frameLayout = new FrameLayout(this);
+
+ splashImageView = new ImageView(this);
+
+ Drawable drawable = this.getResources().getDrawable(splashPicID);
+ if (drawable instanceof NinePatchDrawable) {
+ splashImageView.setBackgroundDrawable(drawable);
+ } else {
+ splashImageView.setImageResource(splashPicID);
}
+
+ frameLayout.addView(view);
+ frameLayout.addView(splashImageView, lp);
+
+ setContentView(frameLayout);
+ logger.log(Level.INFO, "Splash Screen Created");
+ } else {
+ logger.log(Level.INFO, "Splash Screen Skipped.");
+ setContentView(view);
+ }
+
+ }
+
+ public void removeSplashScreen() {
+ logger.log(Level.INFO, "Splash Screen Picture Resource ID: {0}", splashPicID);
+ if (splashPicID != 0) {
+ if (frameLayout != null) {
+ if (splashImageView != null) {
+ this.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ splashImageView.setVisibility(View.INVISIBLE);
+ frameLayout.removeView(splashImageView);
+ }
+ });
+ } else {
+ logger.log(Level.INFO, "splashImageView is null");
+ }
+ } else {
+ logger.log(Level.INFO, "frameLayout is null");
+ }
+ }
+ }
+}

[/java]
1 Like

Thanks i’ll test that tonight.

This is working very well.

I’ll add it to android core.



Thanks!

Great. Thanks.

Looks like there is a stable update coming. Did we miss the chance to put in the splash screen support in this update?

Yes you did but thats nothing to worry about, we can push more updates soon, the issue with this update taking so long was that there were a lot of half-done changes throughout the engine that wouldn’t allow merging or releasing.

Btw, can we add the splash handling to the SDK? Like extend the build script so it copies the right files like the desktop distribution does. I think theres already a variable in the AppSettings for that no?

@iwgeric said:
Looks like there is a stable update coming. Did we miss the chance to put in the splash screen support in this update?

Sorry my bad, i've been quite busy lately, and things are starting to stack up :p

@normen said:
Btw, can we add the splash handling to the SDK? Like extend the build script so it copies the right files like the desktop distribution does. I think theres already a variable in the AppSettings for that no?

yes would be nice, the splash screen needs to be in android resources, we could plug this with the appSetting splash screen.

committed in last SVN

2 Likes

What is the status with this?
I have not found anything newer since this thread about this topic.

Are the changes inside JME3 and now really working?
Is there a working example somewhere, where one don’t need to copy things from this different posts and guess what changes else need to be done?

I have linked a splash image under properties, guessing that in JME3 working splash for android is already inside and that is ment to enable it.
Sadly nothing happens, no splash comes up.
Any info would be nice.

It’s been in the engine for awhile.

Copy the image you want to use as a splash screen to /mobile/res/drawable (you will need to create the drawable directory).

Then add the following line to the constructor of MainActivity.java
splashPicID = R.drawable.filename_without_extension;

That’s it.

1 Like

Thank you iwgeric, but it don’t works:

.../MainActivity.java:34: error: cannot find symbol splashPicID = R.drawable.brickwall; symbol: variable drawable location: class R

On R. it gives me only class, attr, layout, string. No drawable, even if I have restarted jme.

Is there any tutorial about that, or is it only an undocumented function?

Is your version uptodate / on nightlies?

No, but when I have understood iwgeric correctly, that should work since the beginning of the year and I have DL a stable JME3 a month ago.

Also it says “Welcome to the jMonkeyEngine SDK
You are running the latest version of the SDK (jMonkeyEngine SDK 3.0)”.

Do I need to DL nighties? It warns me “it breaks all”. 8-O

Does the splash on android work for you?

clean and build the project, and it should appear

Hmm, no. Did not help a bit. :S

I just tried it and it worked fine.

Make sure you are including the right “R” file. Also check the generated source packages in the android project, and it should have “drawable” in the R.java of your package