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 private void makeFullScreen() {
41 if (Build.VERSION.SDK_INT >= 19)
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);
47 public void onWindowFocusChanged(boolean hasFocus) {
48 super.onWindowFocusChanged(hasFocus);
53 public void copyAssets() {
54 Intent intent = new Intent(this, MinetestAssetCopy.class);
55 startActivity(intent);
58 public void showDialog(String acceptButton, String hint, String current,
61 Intent intent = new Intent(this, MinetestTextEntry.class);
62 Bundle params = new Bundle();
63 params.putString("acceptButton", acceptButton);
64 params.putString("hint", hint);
65 params.putString("current", current);
66 params.putInt("editType", editType);
67 intent.putExtras(params);
68 startActivityForResult(intent, 101);
69 m_MessageReturnValue = "";
70 m_MessagReturnCode = -1;
73 /* ugly code to workaround putMessageBoxResult not beeing found */
74 public int getDialogState() {
75 return m_MessagReturnCode;
78 public String getDialogValue() {
79 m_MessagReturnCode = -1;
80 return m_MessageReturnValue;
83 public float getDensity() {
84 return getResources().getDisplayMetrics().density;
87 public int getDisplayWidth() {
88 return getResources().getDisplayMetrics().widthPixels;
91 public int getDisplayHeight() {
92 return getResources().getDisplayMetrics().heightPixels;
96 protected void onActivityResult(int requestCode, int resultCode,
98 if (requestCode == 101) {
99 if (resultCode == RESULT_OK) {
100 String text = data.getStringExtra("text");
101 m_MessagReturnCode = 0;
102 m_MessageReturnValue = text;
104 m_MessagReturnCode = 1;