To another View and back?

Started by EgonOlsen, July 22, 2010, 08:01:51 PM

Previous topic - Next topic

EgonOlsen

Has anybody an idea how to replace the GLSurfaceView with another View and make it render again after the other View is done?

What i'm trying to do, is to open another View (defined in a layout.xml file) when pressing OK (on the phone). This actually works fine. When i press OK, i set the content view to the new view, the GLSurfaceView obviously stops doing rendering and i can use the GUI in the new View. After pressing a button, i want to return to the GLSurfaceView and continue rendering. It tried this by doing another setContentView(...), this time with the GLSurfaceView. This works to a degree. The GUI View goes away, the GLSurfaceView thread requests and gets the gl surface again (judging from the logs) and...nothing happens. The onDrawFrame()-method never gets called again!? Even if i enqueue something to be executed in the gl thread, this never happens.

I tried several other things like playing around with setVisibility(...) and stuff, but to no avail. I couldn't find any example in the sources and wasn't lucky on the net either.

Any ideas?

EgonOlsen

I did some further debugging and obviously, setContentView() isn't the way to go. When doing this, the render thread gets stopped and never starts again. I can avoid this by overriding one method in GLSurfaceView, but then, the surface gets created again after returning to the render thread, which also isn't what i want. There has to be some other solution...

EgonOlsen

#2
Got it. This is my main.xml


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.opengl.GLSurfaceView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/surface_view" android:visibility="visible" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:id="@+id/mylayout"
android:visibility="invisible" android:background="#000000">

<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Options menu"
android:textStyle="bold"></TextView>

<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/backdrop"
android:text="Render backdrop"></CheckBox>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/glows"
android:text="Render glow effects"></CheckBox>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/particles"
android:text="Render particles"></CheckBox>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/limiter"
android:text="Eco mode (fast devices only)"></CheckBox>
<Button android:id="@+id/Button01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Continue playing"></Button>
</LinearLayout>
</FrameLayout>


In the onCreate()-method of the Activity, i'm now doing this:


setContentView(R.layout.main);
mGLView = (GLSurfaceView) this.findViewById(R.id.surface_view);
....


instead of the former:


mGLView = new GLSurfaceView(getApplication());
...
setContentView(mGLView);


When pressing the OK button, i'm doing this:


final View v2=this.findViewById(R.id.mylayout);
mGLView.setVisibility(View.INVISIBLE);
v2.setVisibility(View.VISIBLE);


...and when i'm done in the GUI View, i'm doing this in reverse...

My main fault before was, that i expected the View to be available via findViewById() in any case, but i always got "null", which was why i couldn't activate my GUI view...simply because i couldn't access it. The trick is to set the whole layout defined in the main.xml as content view. If you don't do this, you can't access neither the GLSurfaceView nor the GUI View.

raft

so, you wont use a GL based gui in your game i suppose ? instead switch to an Android gui ?

EgonOlsen

Not for the actual game menu, but the options menu is easier to do in an Android gui.

raft

is there a spesific reason you do it this way ? for example spawning a sub activity can be an alternative

EgonOlsen

Quote from: raft on August 17, 2010, 04:26:32 PM
is there a spesific reason you do it this way ? for example spawning a sub activity can be an alternative
I've read about that option, but i somehow found it obscure to create another activity just to show some gui stuff.