Use shared prefs and setenv

This commit is contained in:
mittorn 2015-07-24 06:56:03 +06:00
parent 56670e9015
commit fa72090ea1
5 changed files with 117 additions and 48 deletions

View file

@ -5,7 +5,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.celest.xash3d.hl"
android:versionCode="0"
android:versionName="0.14.1"
android:versionName="0.15pre"
android:installLocation="auto">
<!-- Create a Java class extending SDLActivity and place it in a
@ -23,9 +23,11 @@
android:hardwareAccelerated="true">
<activity android:name="in.celest.xash3d.LauncherActivity"
android:label="@string/app_name"
android:label="@string/launcher_name"
android:windowSoftInputMode="adjustResize"
>
<intent-filter>
<action android:name=".LauncherActivity"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
@ -33,19 +35,27 @@
<activity android:name="org.libsdl.app.SDLActivity"
android:screenOrientation="sensorLandscape"
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 android:name="in.celest.xash3d.XashActivity"
<activity android:name="in.celest.xash3d.XashActivity"
android:screenOrientation="landscape"
android:label="@string/app_name">
</activity>
</application>
<!-- Android 2.3.3 -->
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" />
<!-- Android 2.3 -->
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="9" />
<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" />
<!-- OpenGL ES 1.1 -->
<uses-feature android:glEsVersion="0x00010000" />
<!-- Allow writing to external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

View file

@ -201,7 +201,8 @@ public class TouchControlsSettings {
public static void sendToQuake()
{
if(quakeIf == null) return;
int other = 0;
other += showWeaponCycle?0x1:0;
other += mouseMode?0x2:0;

View file

@ -7,30 +7,81 @@ import android.view.MenuItem;
import android.view.View;
import android.content.Intent;
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 com.beloko.touchcontrols.TouchControlsSettings;
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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)
{
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);
String sArgv = cmdArgs.getText().toString();
intent.putExtra(ARGV, sArgv);
SharedPreferences.Editor editor = mPref.edit();
editor.putString("argv", cmdArgs.getText().toString());
editor.putBoolean("controls",useControls.isChecked());
editor.putString("basedir", resPath.getText().toString());
editor.putBoolean("show_icon", showIcon.isChecked());
editor.commit();
editor.apply();
startActivity(intent);
}
public void controlsSettings(View view)
{
mSettings.loadSettings(this);
mSettings.showSettings();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {

View file

@ -54,7 +54,7 @@ public class XashActivity extends Activity {
// So we can call stuff from static callbacks
mSingleton = this;
Intent intent = getIntent();
mArgv = intent.getStringExtra(in.celest.xash3d.LauncherActivity.ARGV);
// mArgv = intent.getStringExtra(in.celest.xash3d.LauncherActivity.ARGV);
// Set up the surface
mSurface = new EngineSurface(getApplication());
setContentView(mSurface);

View file

@ -58,6 +58,7 @@ import com.beloko.games.hl.NativeLib;
import com.beloko.touchcontrols.ControlInterpreter;
import com.beloko.touchcontrols.Settings;
import com.beloko.touchcontrols.TouchControlsSettings;
import android.content.*;
/**
SDL Activity
@ -66,7 +67,7 @@ public class SDLActivity extends Activity {
private static final String TAG = "SDL";
// Keep track of the paused state
public static boolean mIsPaused, mIsSurfaceReady, mHasFocus;
public static boolean mIsPaused, mIsSurfaceReady, mHasFocus, mUseControls;
public static boolean mExitCalledFromJava;
/** If shared libraries (e.g. SDL or the native application) could not be loaded. */
@ -89,9 +90,11 @@ public class SDLActivity extends Activity {
// Audio
protected static AudioTrack mAudioTrack;
//Touch control interp
// Touch control interp
public static ControlInterpreter controlInterp;
// Preferences
public static SharedPreferences mPref;
/**
* 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.
@ -122,14 +125,7 @@ public class SDLActivity extends Activity {
* @return arguments for the native application.
*/
protected String[] getArguments() {
Intent intent = getIntent();
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(" ");
return mPref.getString("argv","-dev 3 -log -console").split(" ");
}
public static void initialize() {
@ -169,7 +165,8 @@ public class SDLActivity extends Activity {
SDLActivity.initialize();
// So we can call stuff from static callbacks
mSingleton = this;
mPref = this.getSharedPreferences("engine", 0);
mUseControls = mPref.getBoolean("controls", false);
// Load shared libraries
String errorMsgBrokenLib = "";
try {
@ -205,6 +202,12 @@ public class SDLActivity extends Activity {
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
mSurface = new SDLSurface(getApplication());
@ -467,7 +470,8 @@ public class SDLActivity extends Activity {
int naxes, int nhats, int nballs);
public static native int nativeRemoveJoystick(int device_id);
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.
*/
@ -965,21 +969,23 @@ class SDLMain implements Runnable {
@Override
public void run() {
// 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();
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 = 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.sendToQuake();
Settings.copyPNGAssets(SDLActivity.mSingleton,SDLActivity.mSingleton.getFilesDir().toString() + "/",null);
TouchControlsSettings.setup(SDLActivity.mSingleton, engine);
TouchControlsSettings.loadSettings(SDLActivity.mSingleton);
TouchControlsSettings.sendToQuake();
Settings.copyPNGAssets(SDLActivity.mSingleton,SDLActivity.mSingleton.getFilesDir().toString() + "/",null);
}
SDLActivity.nativeInit(SDLActivity.mSingleton.getArguments());
//Log.v("SDL", "SDL thread terminated");
}
@ -1189,12 +1195,14 @@ View.OnKeyListener, View.OnTouchListener, SensorEventListener {
@Override
public boolean onTouch(View v, MotionEvent event) {
SDLActivity.controlInterp.onTouchEvent(event);
return true;
if(SDLActivity.mUseControls)
{
SDLActivity.controlInterp.onTouchEvent(event);
return true;
}
/* Ref: http://developer.android.com/training/gestures/multi.html */
/*
final int touchDevId = event.getDeviceId();
final int pointerCount = event.getPointerCount();
int action = event.getActionMasked();
@ -1262,7 +1270,6 @@ View.OnKeyListener, View.OnTouchListener, SensorEventListener {
}
return true;
*/
}
// Sensor events