2015-07-26 01:30:00 +06:00
|
|
|
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;
|
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
|
|
|
|
{
|
|
|
|
static EditText name;
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle bundle)
|
|
|
|
{
|
|
|
|
super.onCreate(bundle);
|
|
|
|
setContentView(R.layout.activity_shortcut);
|
|
|
|
name=(EditText)findViewById(R.id.shortcut_name);
|
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();
|
|
|
|
intent.setAction("in.celest.xash3d.START");
|
2015-07-26 01:30:00 +06:00
|
|
|
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());
|
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);
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
};
|
2015-09-04 19:38:05 +07: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
|
|
|
|
icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
|
|
|
|
}
|
|
|
|
wrapIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
|
2015-07-26 01:30:00 +06:00
|
|
|
setResult(RESULT_OK, wrapIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|