1 package net.minetest.minetest;
3 import android.app.NativeActivity;
4 import android.content.Intent;
5 import android.os.Build;
6 import android.os.Bundle;
7 import android.view.View;
8 import android.view.WindowManager;
10 public class MtNativeActivity extends NativeActivity {
13 System.loadLibrary("c++_shared");
14 System.loadLibrary("openal");
15 System.loadLibrary("ogg");
16 System.loadLibrary("vorbis");
17 System.loadLibrary("iconv");
18 System.loadLibrary("minetest");
21 private int m_MessagReturnCode;
22 private String m_MessageReturnValue;
24 public static native void putMessageBoxResult(String text);
27 public void onCreate(Bundle savedInstanceState) {
28 super.onCreate(savedInstanceState);
29 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
30 m_MessagReturnCode = -1;
31 m_MessageReturnValue = "";
35 protected void onResume() {
40 public void makeFullScreen() {
41 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
42 this.getWindow().getDecorView().setSystemUiVisibility(
43 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
49 public void onWindowFocusChanged(boolean hasFocus) {
50 super.onWindowFocusChanged(hasFocus);
56 public void copyAssets() {
57 Intent intent = new Intent(this, MinetestAssetCopy.class);
58 startActivity(intent);
61 public void showDialog(String acceptButton, String hint, String current,
64 Intent intent = new Intent(this, MinetestTextEntry.class);
65 Bundle params = new Bundle();
66 params.putString("acceptButton", acceptButton);
67 params.putString("hint", hint);
68 params.putString("current", current);
69 params.putInt("editType", editType);
70 intent.putExtras(params);
71 startActivityForResult(intent, 101);
72 m_MessageReturnValue = "";
73 m_MessagReturnCode = -1;
76 /* ugly code to workaround putMessageBoxResult not beeing found */
77 public int getDialogState() {
78 return m_MessagReturnCode;
81 public String getDialogValue() {
82 m_MessagReturnCode = -1;
83 return m_MessageReturnValue;
86 public float getDensity() {
87 return getResources().getDisplayMetrics().density;
90 public int getDisplayWidth() {
91 return getResources().getDisplayMetrics().widthPixels;
94 public int getDisplayHeight() {
95 return getResources().getDisplayMetrics().heightPixels;
99 protected void onActivityResult(int requestCode, int resultCode,
101 if (requestCode == 101) {
102 if (resultCode == RESULT_OK) {
103 String text = data.getStringExtra("text");
104 m_MessagReturnCode = 0;
105 m_MessageReturnValue = text;
107 m_MessagReturnCode = 1;