Add shortcut activity and library mods support
This commit is contained in:
parent
fa72090ea1
commit
b20e90ea24
8 changed files with 158 additions and 40 deletions
|
@ -26,12 +26,18 @@
|
|||
android:label="@string/launcher_name"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
>
|
||||
<intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name=".LauncherActivity"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="in.celest.xash3d.ShortcutActivity" android:label="@string/text_shortcut" android:theme="@android:style/Theme.Dialog">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.CREATE_SHORTCUT" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="org.libsdl.app.SDLActivity"
|
||||
android:screenOrientation="sensorLandscape"
|
||||
android:configChanges="orientation|screenSize"
|
||||
|
@ -39,10 +45,16 @@
|
|||
android:label="@string/app_name"
|
||||
android:taskAffinity="org.libsdl.app.SDLActivity"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name=".SDLActivity"/>
|
||||
<!--<intent-filter>
|
||||
As user can add now empty shortcut, disable this
|
||||
<action android:name="org.libsdl.app.SDLActivity"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>-->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="xash3d.android/game"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="in.celest.xash3d.XashActivity"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
tools:context="in.celest.xash3d.LauncherActivity"
|
||||
android:id="@+id/layout">
|
||||
android:id="@+id/layout_shortcut">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -70,14 +70,14 @@
|
|||
android:text="@string/text_res_path"
|
||||
android:id="@+id/textView_path"
|
||||
android:layout_below="@+id/useControls"/>
|
||||
|
||||
<!--
|
||||
<CheckBox
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_below="@+id/cmdPath"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/text_show_icon"
|
||||
android:id="@+id/showIcon"/>
|
||||
android:id="@+id/showIcon"/>-->
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
73
res/layout/activity_shortcut.xml
Normal file
73
res/layout/activity_shortcut.xml
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
tools:context="in.celest.xash3d.ShortcutActivity"
|
||||
android:id="@+id/layout_shortcut">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/shortcut_button_save"
|
||||
android:id="@+id/shortcut_buttonOk"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:onClick="saveShortcut"/>
|
||||
|
||||
<EditText
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:id="@+id/shortcut_name"
|
||||
android:layout_below="@+id/shortcut_name_text"
|
||||
android:layout_alignParentRight="true"/>
|
||||
<TextView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/shortcut_name_text"
|
||||
android:layout_alignRight="@+id/shortcut_name"
|
||||
android:layout_alignParentTop="true"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="Shortcut name"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/shortcut_cmdArgs"
|
||||
android:layout_below="@+id/shortcut_textView_args"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignRight="@+id/shortcut_textView_args"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/cmd_args_text"
|
||||
android:id="@+id/shortcut_textView_args"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@+id/shortcut_name"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/shortcut_gamedir"
|
||||
android:layout_below="@+id/shortcut_gamedir_text"
|
||||
android:layout_alignParentLeft="true"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/gamedir"
|
||||
android:id="@+id/shortcut_gamedir_text"
|
||||
android:layout_below="@+id/shortcut_cmdArgs"
|
||||
android:layout_alignParentRight="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
@ -6,5 +6,7 @@
|
|||
<string name="use_controls">Включить экранное управление</string>
|
||||
<string name="text_res_path">Путь к ресурсам игры</string>
|
||||
<string name="touch_set">Настройки управления</string>
|
||||
<string name="text_show_icon">Отображать значёк Half-Life</string>
|
||||
<string name="text_shortcut">Ярлык Xash3D</string>
|
||||
<string name="shortcut_button_save">Сохранить ярлык</string>
|
||||
<string name="gamedir">Каталог мода</string>
|
||||
</resources>
|
||||
|
|
|
@ -21,5 +21,7 @@
|
|||
<string name="text_res_path">Path to game resources</string>
|
||||
<string name="hello_world">Hello world!</string>
|
||||
<string name="touch_set">Controls settings</string>
|
||||
<string name="text_show_icon">Show Half-Life icon</string>
|
||||
<string name="text_shortcut">Xash3D shortcut</string>
|
||||
<string name="shortcut_button_save">Save shortcut</string>
|
||||
<string name="gamedir">Mod directory</string>
|
||||
</resources>
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Reference in a new issue