Access to the Surface Holder Please :)

Monkey Targets Forums/Android/Access to the Surface Holder Please :)

therevills(Posted 2011) [#1]
Could we get access to the Surface Holder?

This would allow us to alter the screen resolution (a bit like a virtual resolution, but without the overhead).

http://developer.android.com/reference/android/view/SurfaceHolder.html

All what is needed is this:

	public static class MonkeyView extends GLSurfaceView{
		private SurfaceHolder surfaceHolder;
	
		public MonkeyView( Context context ){
			super( context );
			setUpSurfaceHolder();
		}
		
		public MonkeyView( Context context,AttributeSet attrs ){
			super( context,attrs );
			setUpSurfaceHolder();
		}
		
		private void setUpSurfaceHolder()
		{
			surfaceHolder = getHolder();
			surfaceHolder.addCallback(this);
			surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
		}
		
		public SurfaceHolder getSurfaceHolder() {
			return surfaceHolder;
		}


Once that is done I can do this:

	static void setGraphics(int w, int h)
	{
		MonkeyGame.view.getSurfaceHolder().setFixedSize(w, h);
	}


Also could you add Samah's stack trace thing:
http://www.monkeycoder.co.nz/Community/posts.php?topic=1135#9929

Thanks!


therevills(Posted 2011) [#2]
Bump.... plus Samah's log thingy...


marksibly(Posted 2011) [#3]
Hi,

Not sure why this SurfaceHolder stuff needs to be 'in' Mojo - can't you just use getHolder() externally?


AdamRedwoods(Posted 2011) [#4]
My thought is there should be a place for target-specific commands, that can be added by the community, as desired. Then Mojo can be kept "pure".

import android.SurfaceHolder


therevills(Posted 2011) [#5]
SurfaceHolder stuff needs to be 'in' Mojo


Because it needs to be set up first before you can use it?

Ill have to test it to see if MonkeyGame.view.getHolder().setFixedSize(w, h) works... I thought the callback stuff was needed.


therevills(Posted 2011) [#6]
Hmmmm I cant get it to work now even using the code in post #1 (in v43 & v44) I keep getting the following error:
08-17 20:19:41.084: ERROR/AndroidRuntime(445): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()


It was working :(