Integrating PlayN with standard Android components
Tags: Gaming
Over the weekend while a question came in on the PlayN google group asking how to integrate a PlayN with standard Android components. Below is a quick and dirty way to do it:
public class IntegratedViewActivity extends GameActivity {
@Override
public void main(){
platform().assets().setPathPrefix("com/html5gamebook/resources");
PlayN.run(new IntegratedView());
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout linearLayout = viewLayout();
linearLayout.setOrientation(LinearLayout.VERTICAL);
TextView txtView = new TextView(context());
txtView.setText("This is a text view.");
linearLayout.addView(txtView, 0);
Button btn = new Button(context());
btn.setText("Click Me");
linearLayout.addView(btn);
// resize game view
gameView().setLayoutParams(new LinearLayout.LayoutParams(600, 600));
}
}
Here is how that looks on a device: http://imgur.com/Gh4nv
Additionally, you could create a layout xml file and use the AndroidLayoutView (returned by GameActivity.viewLayout()) directly. If you don't care about the look and feel of the widgets or maybe wanted to make all code PlayN-centric, TriplePlay could work for you as well.
Cross-posted from Google+.