mirror of
https://github.com/FWGS/xash3d-fwgs
synced 2024-11-27 12:29:53 +01:00
Improvements in launcher and shortcuts
This commit is contained in:
parent
0e3e1d8af9
commit
f8a0acd776
@ -38,12 +38,17 @@
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/text_res_path"
|
||||
android:id="@+id/textView_path" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/cmdPath" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/select_folder"
|
||||
android:id="@+id/button_select"
|
||||
android:onClick="selectFolder" />
|
||||
<CheckBox
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -18,7 +18,7 @@
|
||||
android:id="@+id/shortcut_buttonOk"
|
||||
android:layout_alignParentRight="true"
|
||||
android:onClick="saveShortcut"
|
||||
android:layout_below="@+id/shortcut_gamedir"/>
|
||||
android:layout_below="@+id/shortcut_pkgname"/>
|
||||
|
||||
<EditText
|
||||
android:layout_height="wrap_content"
|
||||
@ -68,5 +68,22 @@
|
||||
android:layout_below="@+id/shortcut_cmdArgs"
|
||||
android:layout_alignParentRight="true"/>
|
||||
|
||||
|
||||
<EditText
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/shortcut_pkgname"
|
||||
android:layout_below="@+id/shortcut_pkgname_text"
|
||||
android:layout_alignParentRight="true"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/pkgname"
|
||||
android:id="@+id/shortcut_pkgname_text"
|
||||
android:layout_below="@+id/shortcut_gamedir"
|
||||
android:layout_alignParentRight="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
<string name="text_shortcut">Ярлык Xash3D</string>
|
||||
<string name="shortcut_button_save">Сохранить ярлык</string>
|
||||
<string name="gamedir">Каталог мода</string>
|
||||
<string name="pkgname">Пакет мода (только для экспертов)</string>
|
||||
<string name="shortcut_name">Название ярлыка</string>
|
||||
<string name="about_authors">Порт на Android осуществлен командой SDLash3D:\n
|
||||
• a1batross\n
|
||||
|
@ -22,6 +22,7 @@
|
||||
<string name="text_shortcut_test">Xash3D_test shortcut</string>
|
||||
<string name="shortcut_button_save">Save shortcut</string>
|
||||
<string name="gamedir">Mod directory</string>
|
||||
<string name="pkgname">Mod package name (experts only)</string>
|
||||
<string name="shortcut_name">Shortcut name</string>
|
||||
|
||||
<!-- TODO: Remove or change this placeholder text -->
|
||||
@ -40,4 +41,5 @@ Special thanks to:\n
|
||||
• libSDL2 developers.\n</string>
|
||||
<string name="about_button">About Xash3D Android</string>
|
||||
<string name="create_shortcut_button">Create mod shortcut</string>
|
||||
<string name="select_folder">(select)</string>
|
||||
</resources>
|
||||
|
@ -3,6 +3,7 @@ package in.celest.xash3d;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.os.Build;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@ -10,11 +11,18 @@ import android.content.Intent;
|
||||
import android.widget.EditText;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Button;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.io.File;
|
||||
|
||||
import in.celest.xash3d.hl.R;
|
||||
import com.beloko.touchcontrols.TouchControlsSettings;
|
||||
@ -27,10 +35,20 @@ public class LauncherActivity extends Activity {
|
||||
static CheckBox useVolume;
|
||||
static EditText resPath;
|
||||
static SharedPreferences mPref;
|
||||
String getDefaultPath()
|
||||
{
|
||||
File dir = Environment.getExternalStorageDirectory();
|
||||
if( dir != null && dir.exists() )
|
||||
return dir.getPath() + "/xash";
|
||||
return "/sdcard/xash";
|
||||
}
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_launcher);
|
||||
Button selectFolder = ( Button ) findViewById( R.id.button_select );
|
||||
if ( Build.VERSION.SDK_INT < 21 )
|
||||
selectFolder.setVisibility( View.GONE );
|
||||
mSettings=new TouchControlsSettings();
|
||||
mSettings.setup(this, null);
|
||||
mSettings.loadSettings(this);
|
||||
@ -42,8 +60,8 @@ public class LauncherActivity extends Activity {
|
||||
useVolume = ( CheckBox ) findViewById( R.id.useVolume );
|
||||
useVolume.setChecked(mPref.getBoolean("usevolume",true));
|
||||
resPath = ( EditText ) findViewById( R.id.cmdPath );
|
||||
resPath.setText(mPref.getString("basedir","/sdcard/xash/"));
|
||||
}
|
||||
resPath.setText(mPref.getString("basedir", getDefaultPath()));
|
||||
}
|
||||
|
||||
public void startXash(View view)
|
||||
{
|
||||
@ -79,7 +97,33 @@ public class LauncherActivity extends Activity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void selectFolder(View view)
|
||||
{
|
||||
Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT_TREE");
|
||||
startActivityForResult(intent, 42);
|
||||
resPath.setEnabled(false);
|
||||
}
|
||||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
try{
|
||||
final List<String> paths = resultData.getData().getPathSegments();
|
||||
String[] parts = paths.get(1).split(":");
|
||||
String storagepath = Environment.getExternalStorageDirectory().getPath() + "/";
|
||||
String path = storagepath + parts[1];
|
||||
if( path != null)
|
||||
resPath.setText( path );
|
||||
resPath.setEnabled(true);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
resPath.setEnabled(true);
|
||||
}
|
||||
|
||||
public void createShortcut(View view)
|
||||
{
|
||||
Intent intent = new Intent(this, ShortcutActivity.class);
|
||||
|
@ -31,14 +31,17 @@ public class ShortcutActivity extends Activity
|
||||
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);
|
||||
EditText pkgname = (EditText)findViewById(R.id.shortcut_pkgname);
|
||||
if(pkgname.length() != 0) intent.putExtra("gamelibdir", "/data/data/"+pkgname.getText().toString().replace("!","in.celest.xash3d.")+"/lib/");
|
||||
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 = null;
|
||||
// Try find icon
|
||||
int size = (int) getResources().getDimension(android.R.dimen.app_icon_size);
|
||||
String gamedirstring = getSharedPreferences("engine", 0).getString("basedir","/sdcard/xash/")+(gamedir.length()!=0?gamedir.getText().toString():"valve");
|
||||
String gamedirstring = getSharedPreferences("engine", 0).getString("basedir","/sdcard/xash/")+"/"+(gamedir.length()!=0?gamedir.getText().toString():"valve");
|
||||
try
|
||||
{
|
||||
icon = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(gamedirstring+"/icon.png"), size, size, false);
|
||||
|
Loading…
Reference in New Issue
Block a user