Skip to main content
deleted 110 characters in body
Source Link
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69

Then I have my splashscreen class which uses a simple view (as I only want a basic screen with the ability to add simple animation if I want to later) - This could also be a surfaceView or another GLSurfaceView but I wanted to keep things as simple as possible.

Then I have my splashscreen class which uses a simple view (as I only want a basic screen with the ability to add simple animation if I want to later) - This could also be a surfaceView or another GLSurfaceView but I wanted to keep things as simple as possible.

Then I have my splashscreen class which uses a simple view (as I only want a basic screen with the ability to add simple animation if I want to later).

Source Link
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69

Thank you very much for the answer below, however, I worked out a way to do this. It works, so I am going to post here in case it helps someone else.

In Activity class - in onCreate, get object to Splashscreen class and pass in width and height

    DisplayMetrics display= new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(display);
    width = display.widthPixels;
    height = display.heightPixels;

    Splashscreen splash = new SplashScreen(this.getApplicationContext(), width, height);

In 'MyGLSurfaceView' class constructor (which is an inner class of my Activity class) , I have the following:

public MyGLSurfaceView(Context context) {
        super(context);
      
            //Create dialogue which will be displayed over the GLSurfaceView while resources load
            Dialog loading_dialog = new Dialog(context,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
            //Set it
            loading_dialog.setContentView(splash);
            //Show it
            loading_dialog.show();
         
            //You would have already setContentView to your GLRenderer earlier in
            //onCreate, this just goes over the top of it
            
            //Get object to renderer class and pass in dialogue through constructor
            renderer = new MyGLRenderer(this, loading_dialog);

Then I have my splashscreen class which uses a simple view (as I only want a basic screen with the ability to add simple animation if I want to later) - This could also be a surfaceView or another GLSurfaceView but I wanted to keep things as simple as possible.

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View;

public class SplashScreen extends View{

Bitmap loader;
Bitmap loaderScaled;
int width;
int height;

@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    //Show Scaled bitmap.
    canvas.drawBitmap(loaderScaled, x, y, null); //you can define x and y
}

public SplashScreen(Context context, int width, int height) {
    super(context);
    // TODO Auto-generated constructor stub

    this.width = width;
    this.height = height;

    //Initial Bitmap
    loader = BitmapFactory.decodeResource(getResources(), R.drawable.loading);
            //Create scaled bitmap
    loaderScaled = Bitmap.createScaledBitmap(loader, (int) (width*.25), (int) (height*.13), true);
    //And recycle the original bitmap as we no longer need it
    loader.recycle();

}



}

Then all you need to do is load your resources (I load mine in onSurfaceCreated). At the very end of onSurfaceChanged, just put the following to dismiss the loading screen and reveal you Open GL Renderer....

loading_dialog.dismiss();

It works, I've tested it on a couple of devices, There are a couple of small problemsso I'm going to improve it but the basics are there for a very simple splash screen. I hope it helps others who are looking for a simple solution.

PS I know instead of creating a Splashscreen class, I could simply use an XML layout, but I don't like working with XML, I find doing everything in code much more flexible.