2019-11-28 23:06:56 +03:00
|
|
|
package su.xash.engine;
|
2015-07-26 01:30:00 +06:00
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.view.View;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2015-09-04 20:55:37 +07:00
|
|
|
import android.widget.Toast;
|
2019-11-28 23:06:56 +03:00
|
|
|
import su.xash.engine.R;
|
2015-07-26 01:30:00 +06:00
|
|
|
import android.widget.EditText;
|
2016-05-06 08:58:01 +00:00
|
|
|
import android.widget.Button;
|
2015-09-03 03:52:21 +07:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FilenameFilter;
|
2015-07-26 01:30:00 +06:00
|
|
|
|
|
|
|
import android.os.*;
|
|
|
|
|
|
|
|
public class ShortcutActivity extends Activity
|
|
|
|
{
|
2015-12-20 16:39:56 +06:00
|
|
|
static EditText name, gamedir, pkgname, argv;
|
2015-12-30 00:58:35 +06:00
|
|
|
String [] env = null;
|
2016-05-06 08:58:01 +00:00
|
|
|
public static final int sdk = Integer.valueOf(Build.VERSION.SDK);
|
2015-07-26 01:30:00 +06:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle bundle)
|
|
|
|
{
|
|
|
|
super.onCreate(bundle);
|
2016-05-01 12:53:36 +00:00
|
|
|
//material dialog
|
2016-05-06 08:58:01 +00:00
|
|
|
if ( sdk >= 21 )
|
2016-05-01 12:53:36 +00:00
|
|
|
super.setTheme( 0x01030225 );
|
2016-09-13 22:26:39 +03:00
|
|
|
else super.setTheme( 0x0103000b );
|
2015-07-26 01:30:00 +06:00
|
|
|
setContentView(R.layout.activity_shortcut);
|
2015-12-20 16:39:56 +06:00
|
|
|
Intent intent=getIntent();
|
|
|
|
name = (EditText)findViewById(R.id.shortcut_name);
|
|
|
|
pkgname = (EditText)findViewById(R.id.shortcut_pkgname);
|
|
|
|
gamedir = (EditText)findViewById(R.id.shortcut_gamedir);
|
|
|
|
argv = (EditText)findViewById(R.id.shortcut_cmdArgs);
|
2016-05-06 08:58:01 +00:00
|
|
|
((Button)findViewById( R.id.shortcut_buttonOk )).setOnClickListener(new View.OnClickListener(){
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
saveShortcut(v);
|
|
|
|
}
|
|
|
|
});
|
2015-12-20 16:39:56 +06:00
|
|
|
String argvs = intent.getStringExtra("argv");
|
|
|
|
if( argvs != null )
|
|
|
|
argv.setText(argvs);
|
|
|
|
String pkgnames = intent.getStringExtra("pkgname");
|
|
|
|
if( pkgnames != null )
|
2015-12-20 18:52:09 +06:00
|
|
|
pkgname.setText(pkgnames);
|
2015-12-20 16:39:56 +06:00
|
|
|
String gamedirs = intent.getStringExtra("gamedir");
|
|
|
|
if( gamedirs != null )
|
2015-12-20 18:52:09 +06:00
|
|
|
gamedir.setText(gamedirs);
|
2015-12-20 16:39:56 +06:00
|
|
|
String names = intent.getStringExtra("name");
|
|
|
|
if( names != null )
|
2015-12-20 18:52:09 +06:00
|
|
|
name.setText(names);
|
2015-12-30 00:58:35 +06:00
|
|
|
env = intent.getStringArrayExtra("env");
|
2016-05-06 08:58:01 +00:00
|
|
|
|
2015-09-03 03:52:21 +07:00
|
|
|
//name.setText("Name");
|
2015-07-26 01:30:00 +06:00
|
|
|
}
|
|
|
|
public void saveShortcut(View view)
|
|
|
|
{
|
2015-08-15 04:38:05 +07:00
|
|
|
Intent intent = new Intent();
|
2019-11-28 23:06:56 +03:00
|
|
|
intent.setAction("su.xash.engine.START");
|
2015-07-26 01:30:00 +06:00
|
|
|
if(argv.length() != 0) intent.putExtra("argv",argv.getText().toString());
|
2015-12-20 16:39:56 +06:00
|
|
|
if(pkgname.length() != 0)
|
|
|
|
{
|
|
|
|
intent.putExtra("gamelibdir", "/data/data/"+pkgname.getText().toString().replace("!","in.celest.xash3d.")+"/lib/");
|
|
|
|
intent.putExtra("pakfile", "/data/data/"+pkgname.getText().toString().replace("!","in.celest.xash3d.")+"/files/extras.pak");
|
|
|
|
}
|
2015-07-26 01:30:00 +06:00
|
|
|
if(gamedir.length() != 0) intent.putExtra("gamedir",gamedir.getText().toString());
|
2015-12-30 00:58:35 +06:00
|
|
|
if(env != null)
|
|
|
|
intent.putExtra("env", env);
|
2015-07-26 01:30:00 +06:00
|
|
|
Intent wrapIntent = new Intent();
|
|
|
|
wrapIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
|
|
|
|
wrapIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name.getText().toString());
|
2016-05-06 08:58:01 +00:00
|
|
|
|
2015-09-04 19:38:05 +07:00
|
|
|
Bitmap icon = null;
|
2015-09-03 03:52:21 +07:00
|
|
|
// Try find icon
|
2015-09-04 19:38:05 +07:00
|
|
|
int size = (int) getResources().getDimension(android.R.dimen.app_icon_size);
|
2015-11-08 01:09:57 +06:00
|
|
|
String gamedirstring = getSharedPreferences("engine", 0).getString("basedir","/sdcard/xash/")+"/"+(gamedir.length()!=0?gamedir.getText().toString():"valve");
|
2015-09-03 03:52:21 +07:00
|
|
|
try
|
2015-09-04 19:38:05 +07:00
|
|
|
{
|
|
|
|
icon = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(gamedirstring+"/icon.png"), size, size, false);
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
if(icon == null) try
|
2015-09-04 21:06:00 +07:00
|
|
|
{
|
|
|
|
icon = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(gamedirstring+"/game.ico"), size, size, false);
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
if(icon == null) try
|
2015-09-03 03:52:21 +07:00
|
|
|
{
|
|
|
|
FilenameFilter icoFilter = new FilenameFilter() {
|
|
|
|
public boolean accept(File dir, String name) {
|
|
|
|
if(name.endsWith(".ico") || name.endsWith(".ICO")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2016-05-06 08:58:01 +00:00
|
|
|
|
2015-09-03 03:52:21 +07:00
|
|
|
File gamedirfile = new File(gamedirstring);
|
|
|
|
String files[] = gamedirfile.list(icoFilter);
|
|
|
|
icon = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(gamedirstring+"/"+files[0]), size, size, false);
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
// Android may not support ico loading, so fallback if something going wrong
|
2020-07-07 07:26:25 +07:00
|
|
|
icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
|
2015-09-03 03:52:21 +07:00
|
|
|
}
|
|
|
|
wrapIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
|
2015-09-04 20:55:37 +07:00
|
|
|
if(getIntent().getAction() == "android.intent.action.CREATE_SHORTCUT" ) // Called from launcher
|
|
|
|
{
|
|
|
|
setResult(RESULT_OK, wrapIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else try
|
|
|
|
{
|
|
|
|
wrapIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
|
|
|
|
getApplicationContext().sendBroadcast(wrapIntent);
|
|
|
|
Toast.makeText(getApplicationContext(), "Shortcut created!", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
Toast.makeText(getApplicationContext(), "Problem creating shortcut: " + e.toString() +
|
|
|
|
"\nTry create it manually from laucnher", Toast.LENGTH_LONG).show();
|
|
|
|
}
|
2015-07-26 01:30:00 +06:00
|
|
|
}
|
|
|
|
}
|