How to customize NativeActivity content presentation for a component created in Java

Is there a way to set the NativeActivity content for a component created in Java (e.g. FrameLayout, ImageView, etc.)? I need to use NativeActivity (to get touchpad input in Xperia Play), but I also need to be able to view components created in Java code.

I tried to override the onCreate command and call setContentView there, but although it does not cause any errors, it does nothing (apparently because the content view is already set by its own code). Is there some kind of window id or something that I can pass into my own code to tell it what a content view is, or can it be somehow configured in XML to set the NativeActivity content view to a component that can i change from java?

Let me know if you need more information.

+7
source share
1 answer

I will post an answer here for others with the same problem, as I eventually figured out a method that works.

In the onCreate () method, if you set any specific window flags (FEATURE_NO_TITLE, FLAG_FULLSCREEN, FLAG_KEEP_SCREEN_ON, etc.), then before you call super.onCreate () (or they will be ignored). Then, wherever you usually mark this:

setContentView( whatever ); 

Do this instead:

 getWindow().takeSurface( null ); getWindow().setContentView( whatever ); 

This is the main way to get content to be controlled by Java. Anywhere in your code where you work with content, use getWindow () instead of this.

Some other things to keep in mind are that the normal onKey and onTouch methods will not be called (they will have their own equivalents instead), so if you need to process input on the Java side, you will need to configure some JNI communication for sending information from native to Java. I believe that everything else is included in the official sample of the XPeria Play-style iPad example (additions to AndroidManifest.xml and something is wrong).

If you want to see my project for reference, it is open source and can be found at:

http://www.paulscode.com/forum/index.php?topic=75.msg1540#msg1540

Just click the “Source Code” link next to “XPEA Play Touch Touch Pad”. Perhaps this is not so useful for you, because it is a rather large project, and it may be difficult for you to find what you are looking for. If you have any problems, send a question to my forum or write me, and I will be happy to help.

+12
source

All Articles