2020-04-15 16:27:40 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2014-2020 MoNTE48, Maksim Gamarnik <MoNTE48@mail.ua>
|
|
|
|
Copyright (C) 2014-2020 ubulem, Bektur Mambetov <berkut87@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2015-03-14 18:52:31 +01:00
|
|
|
package net.minetest.minetest;
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
import android.app.NativeActivity;
|
|
|
|
import android.content.Intent;
|
2018-12-03 00:39:35 +01:00
|
|
|
import android.os.Build;
|
2014-04-21 14:10:59 +02:00
|
|
|
import android.os.Bundle;
|
2018-12-03 00:39:35 +01:00
|
|
|
import android.view.View;
|
2014-04-21 14:10:59 +02:00
|
|
|
import android.view.WindowManager;
|
|
|
|
|
2020-04-15 16:27:40 +02:00
|
|
|
public class GameActivity extends NativeActivity {
|
2018-12-03 00:39:35 +01:00
|
|
|
static {
|
2018-12-22 19:02:00 +01:00
|
|
|
System.loadLibrary("c++_shared");
|
2020-04-15 16:27:40 +02:00
|
|
|
System.loadLibrary("Minetest");
|
2018-12-03 00:39:35 +01:00
|
|
|
}
|
|
|
|
|
2020-04-15 16:27:40 +02:00
|
|
|
private int messageReturnCode;
|
|
|
|
private String messageReturnValue;
|
2018-12-03 00:39:35 +01:00
|
|
|
|
|
|
|
public static native void putMessageBoxResult(String text);
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2018-01-04 21:18:18 +01:00
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
2020-04-15 16:27:40 +02:00
|
|
|
messageReturnCode = -1;
|
|
|
|
messageReturnValue = "";
|
2018-12-03 00:39:35 +01:00
|
|
|
}
|
2015-10-24 20:44:07 +02:00
|
|
|
|
2019-11-07 00:39:39 +01:00
|
|
|
private void makeFullScreen() {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19)
|
2018-12-03 00:39:35 +01:00
|
|
|
this.getWindow().getDecorView().setSystemUiVisibility(
|
2020-04-15 16:27:40 +02:00
|
|
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
|
|
|
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
|
|
|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-03 00:39:35 +01:00
|
|
|
public void onWindowFocusChanged(boolean hasFocus) {
|
|
|
|
super.onWindowFocusChanged(hasFocus);
|
2019-11-07 00:39:39 +01:00
|
|
|
if (hasFocus)
|
2018-12-03 00:39:35 +01:00
|
|
|
makeFullScreen();
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
2015-10-24 20:44:07 +02:00
|
|
|
|
2020-04-15 16:27:40 +02:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
makeFullScreen();
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
2015-10-24 20:44:07 +02:00
|
|
|
|
2020-04-15 16:27:40 +02:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
// Ignore the back press so Minetest can handle it
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
if (requestCode == 101) {
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
String text = data.getStringExtra("text");
|
|
|
|
messageReturnCode = 0;
|
|
|
|
messageReturnValue = text;
|
|
|
|
} else
|
|
|
|
messageReturnCode = 1;
|
|
|
|
}
|
|
|
|
}
|
2015-10-24 20:44:07 +02:00
|
|
|
|
2020-04-15 16:27:40 +02:00
|
|
|
public void showDialog(String acceptButton, String hint, String current, int editType) {
|
|
|
|
Intent intent = new Intent(this, InputDialogActivity.class);
|
2014-04-21 14:10:59 +02:00
|
|
|
Bundle params = new Bundle();
|
|
|
|
params.putString("acceptButton", acceptButton);
|
|
|
|
params.putString("hint", hint);
|
|
|
|
params.putString("current", current);
|
|
|
|
params.putInt("editType", editType);
|
|
|
|
intent.putExtras(params);
|
|
|
|
startActivityForResult(intent, 101);
|
2020-04-15 16:27:40 +02:00
|
|
|
messageReturnValue = "";
|
|
|
|
messageReturnCode = -1;
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
2015-10-24 20:44:07 +02:00
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
public int getDialogState() {
|
2020-04-15 16:27:40 +02:00
|
|
|
return messageReturnCode;
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
2015-10-24 20:44:07 +02:00
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
public String getDialogValue() {
|
2020-04-15 16:27:40 +02:00
|
|
|
messageReturnCode = -1;
|
|
|
|
return messageReturnValue;
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
2015-10-24 20:44:07 +02:00
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
public float getDensity() {
|
|
|
|
return getResources().getDisplayMetrics().density;
|
|
|
|
}
|
2015-10-24 20:44:07 +02:00
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
public int getDisplayHeight() {
|
|
|
|
return getResources().getDisplayMetrics().heightPixels;
|
|
|
|
}
|
2015-10-24 20:44:07 +02:00
|
|
|
|
2020-04-15 16:27:40 +02:00
|
|
|
public int getDisplayWidth() {
|
|
|
|
return getResources().getDisplayMetrics().widthPixels;
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
}
|