mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-07 21:10:46 +08:00
Add shortcut activity and library mods support
This commit is contained in:
@@ -22,7 +22,6 @@ public class LauncherActivity extends Activity {
|
||||
static EditText cmdArgs;
|
||||
static CheckBox useControls;
|
||||
static EditText resPath;
|
||||
static CheckBox showIcon;
|
||||
static SharedPreferences mPref;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -38,41 +37,17 @@ public class LauncherActivity extends Activity {
|
||||
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.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
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);
|
||||
|
||||
42
src/in/celest/xash3d/ShortcutActivity.java
Normal file
42
src/in/celest/xash3d/ShortcutActivity.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package in.celest.xash3d;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.View;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import in.celest.xash3d.hl.R;
|
||||
import android.widget.EditText;
|
||||
|
||||
import android.os.*;
|
||||
|
||||
public class ShortcutActivity extends Activity
|
||||
{
|
||||
static EditText name;
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle)
|
||||
{
|
||||
super.onCreate(bundle);
|
||||
setContentView(R.layout.activity_shortcut);
|
||||
name=(EditText)findViewById(R.id.shortcut_name);
|
||||
name.setText("Name");
|
||||
}
|
||||
public void saveShortcut(View view)
|
||||
{
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW,null);
|
||||
intent.setType("xash3d.android/game");
|
||||
EditText argv = (EditText)findViewById(R.id.shortcut_cmdArgs);
|
||||
if(argv.length() != 0) intent.putExtra("argv",argv.getText().toString());
|
||||
EditText gamedir = (EditText)findViewById(R.id.shortcut_gamedir);
|
||||
if(gamedir.length() != 0) intent.putExtra("gamedir",gamedir.getText().toString());
|
||||
Intent wrapIntent = new Intent();
|
||||
wrapIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
|
||||
wrapIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name.getText().toString());
|
||||
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
|
||||
/// TODO: Load icon from path+gamedir+"game.ico"
|
||||
int size = (int) getResources().getDimension(android.R.dimen.app_icon_size);
|
||||
wrapIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, Bitmap.createScaledBitmap(icon, size, size, false));
|
||||
setResult(RESULT_OK, wrapIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -125,6 +125,9 @@ public class SDLActivity extends Activity {
|
||||
* @return arguments for the native application.
|
||||
*/
|
||||
protected String[] getArguments() {
|
||||
String argv=getIntent().getStringExtra("argv");
|
||||
if(argv != null)
|
||||
return argv.split(" ");
|
||||
return mPref.getString("argv","-dev 3 -log -console").split(" ");
|
||||
}
|
||||
|
||||
@@ -203,11 +206,20 @@ public class SDLActivity extends Activity {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
setenv("XASH3D_BASEDIR", mPref.getString("basedir","/sdcard/xash/"), true);
|
||||
Intent intent=getIntent();
|
||||
String gamelibdir = intent.getStringExtra("gamelibdir");
|
||||
if(gamelibdir == null)
|
||||
gamelibdir = getFilesDir().getParentFile().getPath() + "/lib";
|
||||
String gamedir = intent.getStringExtra("gamedir");
|
||||
if(gamedir == null)
|
||||
gamedir = "valve";
|
||||
String basedir = intent.getStringExtra("basedir");
|
||||
if(basedir == null)
|
||||
basedir = mPref.getString("basedir","/sdcard/xash/");
|
||||
setenv("XASH3D_BASEDIR", basedir, true);
|
||||
setenv("XASH3D_ENGLIBDIR", getFilesDir().getParentFile().getPath() + "/lib", true);
|
||||
setenv("XASH3D_GAMELIBDIR", getFilesDir().getParentFile().getPath() + "/lib", true);
|
||||
setenv("XASH3D_GAMEDIR", "valve", true);
|
||||
setenv("XASH3D_GAMELIBDIR", gamelibdir, true);
|
||||
setenv("XASH3D_GAMEDIR", gamedir, true);
|
||||
|
||||
// Set up the surface
|
||||
mSurface = new SDLSurface(getApplication());
|
||||
|
||||
Reference in New Issue
Block a user