From fa72090ea1c53cbce7bd0be9bc64eba7ba6d5843 Mon Sep 17 00:00:00 2001 From: mittorn Date: Fri, 24 Jul 2015 06:56:03 +0600 Subject: [PATCH] Use shared prefs and setenv --- AndroidManifest.xml | 26 ++++--- .../touchcontrols/TouchControlsSettings.java | 3 +- src/in/celest/xash3d/LauncherActivity.java | 69 ++++++++++++++++--- src/in/celest/xash3d/XashActivity.java | 2 +- src/org/libsdl/app/SDLActivity.java | 65 +++++++++-------- 5 files changed, 117 insertions(+), 48 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 68c336cd..bf1800bc 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -5,7 +5,7 @@ - + + - - + + diff --git a/src/com/beloko/touchcontrols/TouchControlsSettings.java b/src/com/beloko/touchcontrols/TouchControlsSettings.java index c68c977e..8101cb56 100644 --- a/src/com/beloko/touchcontrols/TouchControlsSettings.java +++ b/src/com/beloko/touchcontrols/TouchControlsSettings.java @@ -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; diff --git a/src/in/celest/xash3d/LauncherActivity.java b/src/in/celest/xash3d/LauncherActivity.java index e5827d62..6f064e88 100644 --- a/src/in/celest/xash3d/LauncherActivity.java +++ b/src/in/celest/xash3d/LauncherActivity.java @@ -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) { diff --git a/src/in/celest/xash3d/XashActivity.java b/src/in/celest/xash3d/XashActivity.java index d78833b0..6993c057 100644 --- a/src/in/celest/xash3d/XashActivity.java +++ b/src/in/celest/xash3d/XashActivity.java @@ -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); diff --git a/src/org/libsdl/app/SDLActivity.java b/src/org/libsdl/app/SDLActivity.java index c13b4abb..bbfe4bdd 100644 --- a/src/org/libsdl/app/SDLActivity.java +++ b/src/org/libsdl/app/SDLActivity.java @@ -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