Use shared prefs and setenv
This commit is contained in:
parent
56670e9015
commit
fa72090ea1
5 changed files with 117 additions and 48 deletions
|
@ -5,7 +5,7 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="in.celest.xash3d.hl"
|
package="in.celest.xash3d.hl"
|
||||||
android:versionCode="0"
|
android:versionCode="0"
|
||||||
android:versionName="0.14.1"
|
android:versionName="0.15pre"
|
||||||
android:installLocation="auto">
|
android:installLocation="auto">
|
||||||
|
|
||||||
<!-- Create a Java class extending SDLActivity and place it in a
|
<!-- Create a Java class extending SDLActivity and place it in a
|
||||||
|
@ -23,9 +23,11 @@
|
||||||
|
|
||||||
android:hardwareAccelerated="true">
|
android:hardwareAccelerated="true">
|
||||||
<activity android:name="in.celest.xash3d.LauncherActivity"
|
<activity android:name="in.celest.xash3d.LauncherActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/launcher_name"
|
||||||
|
android:windowSoftInputMode="adjustResize"
|
||||||
>
|
>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
<action android:name=".LauncherActivity"/>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
@ -33,19 +35,27 @@
|
||||||
<activity android:name="org.libsdl.app.SDLActivity"
|
<activity android:name="org.libsdl.app.SDLActivity"
|
||||||
android:screenOrientation="sensorLandscape"
|
android:screenOrientation="sensorLandscape"
|
||||||
android:configChanges="orientation|screenSize"
|
android:configChanges="orientation|screenSize"
|
||||||
>
|
android:windowSoftInputMode="adjustResize"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:taskAffinity="org.libsdl.app.SDLActivity"
|
||||||
|
>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name=".SDLActivity"/>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name="in.celest.xash3d.XashActivity"
|
<activity android:name="in.celest.xash3d.XashActivity"
|
||||||
android:screenOrientation="landscape"
|
android:screenOrientation="landscape"
|
||||||
android:label="@string/app_name">
|
android:label="@string/app_name">
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<!-- Android 2.3.3 -->
|
<!-- Android 2.3 -->
|
||||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" />
|
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="9" />
|
||||||
|
|
||||||
<!-- OpenGL ES 2.0 -->
|
<!-- OpenGL ES 1.1 -->
|
||||||
<uses-feature android:glEsVersion="0x00020000" />
|
<uses-feature android:glEsVersion="0x00010000" />
|
||||||
|
|
||||||
<!-- Allow writing to external storage -->
|
<!-- Allow writing to external storage -->
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
|
|
@ -201,7 +201,8 @@ public class TouchControlsSettings {
|
||||||
|
|
||||||
public static void sendToQuake()
|
public static void sendToQuake()
|
||||||
{
|
{
|
||||||
|
if(quakeIf == null) return;
|
||||||
|
|
||||||
int other = 0;
|
int other = 0;
|
||||||
other += showWeaponCycle?0x1:0;
|
other += showWeaponCycle?0x1:0;
|
||||||
other += mouseMode?0x2:0;
|
other += mouseMode?0x2:0;
|
||||||
|
|
|
@ -7,30 +7,81 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
import in.celest.xash3d.hl.R;
|
import in.celest.xash3d.hl.R;
|
||||||
|
import com.beloko.touchcontrols.TouchControlsSettings;
|
||||||
|
|
||||||
public class LauncherActivity extends Activity {
|
public class LauncherActivity extends Activity {
|
||||||
|
// public final static String ARGV = "in.celest.xash3d.MESSAGE";
|
||||||
public final static String ARGV = "in.celest.xash3d.MESSAGE";
|
static TouchControlsSettings mSettings;
|
||||||
|
static EditText cmdArgs;
|
||||||
|
static CheckBox useControls;
|
||||||
|
static EditText resPath;
|
||||||
|
static CheckBox showIcon;
|
||||||
|
static SharedPreferences mPref;
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_launcher);
|
setContentView(R.layout.activity_launcher);
|
||||||
|
mSettings=new TouchControlsSettings();
|
||||||
|
mSettings.setup(this, null);
|
||||||
|
mSettings.loadSettings(this);
|
||||||
|
mPref = getSharedPreferences("engine", 0);
|
||||||
|
cmdArgs = (EditText)findViewById(R.id.cmdArgs);
|
||||||
|
cmdArgs.setText(mPref.getString("argv","-dev 3 -console -log"));
|
||||||
|
useControls = ( CheckBox ) findViewById( R.id.useControls );
|
||||||
|
useControls.setChecked(mPref.getBoolean("controls",true));
|
||||||
|
resPath = ( EditText ) findViewById( R.id.cmdPath );
|
||||||
|
resPath.setText(mPref.getString("basedir","/sdcard/xash/"));
|
||||||
|
showIcon = ( CheckBox ) findViewById( R.id.showIcon );
|
||||||
|
showIcon.setChecked(mPref.getBoolean("show_icon",true));
|
||||||
|
// it is broken, so disable it now
|
||||||
|
showIcon.setEnabled(false);
|
||||||
|
showIcon.setActivated(false);
|
||||||
|
/*showIcon.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||||
|
{
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||||
|
{
|
||||||
|
ComponentName componentName = new ComponentName("in.celest.xash3d.hl","org.libsdl.app.SDLActivity");
|
||||||
|
PackageManager p = getPackageManager();
|
||||||
|
if ( isChecked )
|
||||||
|
{
|
||||||
|
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startXash(View view)
|
public void startXash(View view)
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(this, org.libsdl.app.SDLActivity.class);
|
Intent intent = new Intent(this, org.libsdl.app.SDLActivity.class);
|
||||||
//Intent intent = new Intent(this, in.celest.xash3d.XashActivity.class);
|
|
||||||
EditText cmdArgs = (EditText)findViewById(R.id.cmdArgs);
|
SharedPreferences.Editor editor = mPref.edit();
|
||||||
String sArgv = cmdArgs.getText().toString();
|
editor.putString("argv", cmdArgs.getText().toString());
|
||||||
|
editor.putBoolean("controls",useControls.isChecked());
|
||||||
intent.putExtra(ARGV, sArgv);
|
editor.putString("basedir", resPath.getText().toString());
|
||||||
|
editor.putBoolean("show_icon", showIcon.isChecked());
|
||||||
|
editor.commit();
|
||||||
|
editor.apply();
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
public void controlsSettings(View view)
|
||||||
|
{
|
||||||
|
mSettings.loadSettings(this);
|
||||||
|
mSettings.showSettings();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class XashActivity extends Activity {
|
||||||
// So we can call stuff from static callbacks
|
// So we can call stuff from static callbacks
|
||||||
mSingleton = this;
|
mSingleton = this;
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
mArgv = intent.getStringExtra(in.celest.xash3d.LauncherActivity.ARGV);
|
// mArgv = intent.getStringExtra(in.celest.xash3d.LauncherActivity.ARGV);
|
||||||
// Set up the surface
|
// Set up the surface
|
||||||
mSurface = new EngineSurface(getApplication());
|
mSurface = new EngineSurface(getApplication());
|
||||||
setContentView(mSurface);
|
setContentView(mSurface);
|
||||||
|
|
|
@ -58,6 +58,7 @@ import com.beloko.games.hl.NativeLib;
|
||||||
import com.beloko.touchcontrols.ControlInterpreter;
|
import com.beloko.touchcontrols.ControlInterpreter;
|
||||||
import com.beloko.touchcontrols.Settings;
|
import com.beloko.touchcontrols.Settings;
|
||||||
import com.beloko.touchcontrols.TouchControlsSettings;
|
import com.beloko.touchcontrols.TouchControlsSettings;
|
||||||
|
import android.content.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
SDL Activity
|
SDL Activity
|
||||||
|
@ -66,7 +67,7 @@ public class SDLActivity extends Activity {
|
||||||
private static final String TAG = "SDL";
|
private static final String TAG = "SDL";
|
||||||
|
|
||||||
// Keep track of the paused state
|
// Keep track of the paused state
|
||||||
public static boolean mIsPaused, mIsSurfaceReady, mHasFocus;
|
public static boolean mIsPaused, mIsSurfaceReady, mHasFocus, mUseControls;
|
||||||
public static boolean mExitCalledFromJava;
|
public static boolean mExitCalledFromJava;
|
||||||
|
|
||||||
/** If shared libraries (e.g. SDL or the native application) could not be loaded. */
|
/** If shared libraries (e.g. SDL or the native application) could not be loaded. */
|
||||||
|
@ -89,9 +90,11 @@ public class SDLActivity extends Activity {
|
||||||
// Audio
|
// Audio
|
||||||
protected static AudioTrack mAudioTrack;
|
protected static AudioTrack mAudioTrack;
|
||||||
|
|
||||||
//Touch control interp
|
// Touch control interp
|
||||||
public static ControlInterpreter controlInterp;
|
public static ControlInterpreter controlInterp;
|
||||||
|
|
||||||
|
// Preferences
|
||||||
|
public static SharedPreferences mPref;
|
||||||
/**
|
/**
|
||||||
* This method is called by SDL before loading the native shared libraries.
|
* This method is called by SDL before loading the native shared libraries.
|
||||||
* It can be overridden to provide names of shared libraries to be loaded.
|
* It can be overridden to provide names of shared libraries to be loaded.
|
||||||
|
@ -122,14 +125,7 @@ public class SDLActivity extends Activity {
|
||||||
* @return arguments for the native application.
|
* @return arguments for the native application.
|
||||||
*/
|
*/
|
||||||
protected String[] getArguments() {
|
protected String[] getArguments() {
|
||||||
Intent intent = getIntent();
|
return mPref.getString("argv","-dev 3 -log -console").split(" ");
|
||||||
String sArgv = intent.getStringExtra(in.celest.xash3d.LauncherActivity.ARGV);
|
|
||||||
|
|
||||||
Log.v("ArgvDebug", "Got args: " + sArgv);
|
|
||||||
|
|
||||||
if(sArgv == null || sArgv.isEmpty())
|
|
||||||
return "-dev 3 -log -console".split(" ");
|
|
||||||
else return sArgv.split(" ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
|
@ -169,7 +165,8 @@ public class SDLActivity extends Activity {
|
||||||
SDLActivity.initialize();
|
SDLActivity.initialize();
|
||||||
// So we can call stuff from static callbacks
|
// So we can call stuff from static callbacks
|
||||||
mSingleton = this;
|
mSingleton = this;
|
||||||
|
mPref = this.getSharedPreferences("engine", 0);
|
||||||
|
mUseControls = mPref.getBoolean("controls", false);
|
||||||
// Load shared libraries
|
// Load shared libraries
|
||||||
String errorMsgBrokenLib = "";
|
String errorMsgBrokenLib = "";
|
||||||
try {
|
try {
|
||||||
|
@ -205,6 +202,12 @@ public class SDLActivity extends Activity {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setenv("XASH3D_BASEDIR", mPref.getString("basedir","/sdcard/xash/"), true);
|
||||||
|
setenv("XASH3D_ENGLIBDIR", getFilesDir().getParentFile().getPath() + "/lib", true);
|
||||||
|
setenv("XASH3D_GAMELIBDIR", getFilesDir().getParentFile().getPath() + "/lib", true);
|
||||||
|
setenv("XASH3D_GAMEDIR", "valve", true);
|
||||||
|
|
||||||
// Set up the surface
|
// Set up the surface
|
||||||
mSurface = new SDLSurface(getApplication());
|
mSurface = new SDLSurface(getApplication());
|
||||||
|
@ -467,7 +470,8 @@ public class SDLActivity extends Activity {
|
||||||
int naxes, int nhats, int nballs);
|
int naxes, int nhats, int nballs);
|
||||||
public static native int nativeRemoveJoystick(int device_id);
|
public static native int nativeRemoveJoystick(int device_id);
|
||||||
public static native String nativeGetHint(String name);
|
public static native String nativeGetHint(String name);
|
||||||
|
public static native int setenv(String key, String value, boolean overwrite);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called by SDL using JNI.
|
* This method is called by SDL using JNI.
|
||||||
*/
|
*/
|
||||||
|
@ -965,21 +969,23 @@ class SDLMain implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Runs SDL_main()
|
// Runs SDL_main()
|
||||||
|
if(SDLActivity.mUseControls)
|
||||||
|
{
|
||||||
|
NativeLib engine = new NativeLib();
|
||||||
|
engine.initTouchControls_if(SDLActivity.mSingleton.getFilesDir().toString() + "/",
|
||||||
|
(int)SDLSurface.mWidth, (int)SDLSurface.mHeight);
|
||||||
|
|
||||||
NativeLib engine = new NativeLib();
|
SDLActivity.controlInterp = new ControlInterpreter(engine,Settings.IDGame.Doom,Settings.gamePadControlsFile,Settings.gamePadEnabled);
|
||||||
engine.initTouchControls_if(SDLActivity.mSingleton.getFilesDir().toString() + "/",
|
|
||||||
(int)SDLSurface.mWidth, (int)SDLSurface.mHeight);
|
|
||||||
|
|
||||||
SDLActivity.controlInterp = new ControlInterpreter(engine,Settings.IDGame.Doom,Settings.gamePadControlsFile,Settings.gamePadEnabled);
|
SDLActivity.controlInterp.setScreenSize((int)SDLSurface.mWidth, (int)SDLSurface.mHeight);
|
||||||
|
|
||||||
SDLActivity.controlInterp.setScreenSize((int)SDLSurface.mWidth, (int)SDLSurface.mHeight);
|
TouchControlsSettings.setup(SDLActivity.mSingleton, engine);
|
||||||
|
TouchControlsSettings.loadSettings(SDLActivity.mSingleton);
|
||||||
TouchControlsSettings.setup(SDLActivity.mSingleton, engine);
|
TouchControlsSettings.sendToQuake();
|
||||||
TouchControlsSettings.loadSettings(SDLActivity.mSingleton);
|
|
||||||
TouchControlsSettings.sendToQuake();
|
|
||||||
|
|
||||||
Settings.copyPNGAssets(SDLActivity.mSingleton,SDLActivity.mSingleton.getFilesDir().toString() + "/",null);
|
|
||||||
|
|
||||||
|
Settings.copyPNGAssets(SDLActivity.mSingleton,SDLActivity.mSingleton.getFilesDir().toString() + "/",null);
|
||||||
|
|
||||||
|
}
|
||||||
SDLActivity.nativeInit(SDLActivity.mSingleton.getArguments());
|
SDLActivity.nativeInit(SDLActivity.mSingleton.getArguments());
|
||||||
//Log.v("SDL", "SDL thread terminated");
|
//Log.v("SDL", "SDL thread terminated");
|
||||||
}
|
}
|
||||||
|
@ -1189,12 +1195,14 @@ View.OnKeyListener, View.OnTouchListener, SensorEventListener {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
|
||||||
|
if(SDLActivity.mUseControls)
|
||||||
SDLActivity.controlInterp.onTouchEvent(event);
|
{
|
||||||
return true;
|
SDLActivity.controlInterp.onTouchEvent(event);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Ref: http://developer.android.com/training/gestures/multi.html */
|
/* Ref: http://developer.android.com/training/gestures/multi.html */
|
||||||
/*
|
|
||||||
final int touchDevId = event.getDeviceId();
|
final int touchDevId = event.getDeviceId();
|
||||||
final int pointerCount = event.getPointerCount();
|
final int pointerCount = event.getPointerCount();
|
||||||
int action = event.getActionMasked();
|
int action = event.getActionMasked();
|
||||||
|
@ -1262,7 +1270,6 @@ View.OnKeyListener, View.OnTouchListener, SensorEventListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sensor events
|
// Sensor events
|
||||||
|
|
Loading…
Add table
Reference in a new issue