NDK SurfaceView redraw got broken display on screen rotate - android

I am using SurfaceView with ndk+openGL, when press screen rotate button of the emulator,
i received SurfaceChanged event from SurfaceHolder.Callback, then i post a redraw message via Handler, and the Handler redraws the screen with new display metrics via JNI native code, but the display is broken, as the picture shows.
I sure that the native OpenGL drawing code already draws one frame, after press rotate button and before screen rotation finish, but don't know why the display is broken.
I'm not so familiar with android, could someone help me. thanks.
EDIT:
when i make some touch events to trigger new frames, the display got fixed.
so i'm thinking is there a rotate finish event, so i can force draw one frame to fix this issue.

Problem solved.
Override the surfaceRedrawNeeded method of SurfaceHolder.Callback2, it will be called after rotate finished.

Related

Is it possible to move the camera on a Google Map in Satellite mode?

In an Android app I'm trying to simulate a flyover of an area of land.
I can quite happily zoom into the start and animate the camera to the final point.
This works fine when it's a MAP_TYPE of normal.
Change it to a MAP_TYPE of SATELLITE it merely pauses for a while before displaying the final location.
Any way of getting the camera to animate from to start to end in Satellite view, I dont mind having to do some preload of images if necessary.
Cheers.
Well, yes you can.
What you need to do is let the looper finish drawing, then do your camera move.
So, a typical step by step animation would be a bit like this.
Move camera to position
When animation completes (onFinish)...
Start new thread, delay for a second or two, then on UI thread do camera
move.(onFinish of this animation, start new thread and do another camera
move. etc etc

Calling setRequestedOrientation without actually rotating the screen in Android

I am struggling with a quite rare problem.
Here it goes:
I have a SurfaceView and there is a JNI-side thread that handling the rendering operations on it (Let say Render-thread). For "some" reason I need to rotate my drawings by myself inside the render-thread. To achieve this, the render thread queries the rotation status from the android framework. And I can see the rotated screen whenever the device is rotated, but there is a problem: if I rotate the device, the screen rendered by Render-Thread is rotated, but Android UIs (such as notification bar, toast message, etc) are not rotated (Of course!). To resolve this problem, I use setRequestedOrientation function to tell the Android to rotate my Activity. Then I can also see the properly rotated Android UIs. At this moment, my real problem happens: The race between Render-Thread and Android's screen rotation stuff (I guess surface flinger?).
Apparently, if I call setRequestedOrientation function, Android framework rotates the screen by itself, while my Render-thread is also drawing the rotated screen. And this results in a glitch.
My question here is that:
Is there a way to tell Android framework not to rotate the SurfaceView while I'm still calling setRequestedOrientation?

Android: How do I make sure the screen has fully rotated?

I am writing an Android application that needs to rotate the screen as many times as possible in a certain period of time.
I can rotate the screen fine with setRequestedOrientation(int). The problem I am having is that if I try and rotate the screen in the last call to Activity, onWindowFocusChanged(boolean), the screen cannot keep up with the amount of times setRequestedOrientation is called.
My logcat is showing me that I am getting roughly 5-10 "Setting rotation to [0|1|2|3]" before I get one complete screen rotation.
Here's what I have tried:
Using view to request focus and using a OnRequestFocusChanged Listener
Rotating screen in a child thread to run runOnUiThread to add to main thread message queue
View.post
I know iv'e tried other stuff, but I forget, those are the most recent, and as you can tell I'm getting desperate.
So, is there a way to make sure that the Activity has fully rotated and is accepting user input? Maybe there is a way to check and see if the Activity is looping and waiting for input? Any help here would be absolutely great! Thanks guys.

How to force a call to onDrawFrame() on a GLSurfaceView?

I have a UI that haes a GLSurfaceView that shows a polygon.
The UI haves also two buttons ZoomIn and ZoomOut. When the user press these buttons, the zoomIn() and zoomOut() methods of myGLSurfaceView are called.
The problem is that i want that the method onDrawFrame get's called to get reflected the zoom in & out.
Why i want this? because the buttons have setClickable(true); why? because i need that if the user leaves the finger presing the button, the zoom get's applied continuosly until the user releases the buton.
Now it works but it works bad, i need to refresh the GLsurfaceview forcing onDrawFrame
Call gLSurfaceView.requestRender(). This will (from link):
Request that the renderer render a frame. This method is typically used when the render mode has been set to RENDERMODE_WHEN_DIRTY, so that frames are only rendered on demand. May be called from any thread. Must not be called before a renderer has been set.
solved using threads and press/release events of the finger

media player screen rotation issue

i have made a media player and have called setDataSource(), setDisplay() and prepare() methods in onSurfaceCreated() method. Everything works fine when the view is rendered for the first time, if i rotate the screen, display disappears and only audio is availaible.How would I get it working? I have used video view for displaying video. Please help me with this issue.
From your question I can see that you are using a surface view which will re initiate when you rotate your screen. so you must set your screen mode to either landscape or portrait based on your requirement.
Else you must figure out some other way other than using surface view.
When you rotate the screen, Activity gets destroyed and a new one is created with a different configuration. If something doesn't work, it means that you should test your application in the landscape mode.

Categories

Resources