Implement icon loading

This commit is contained in:
mittorn 2015-09-03 03:52:21 +07:00
parent bf0a8bf50a
commit 1b894336fc
2 changed files with 28 additions and 6 deletions

View file

@ -35,7 +35,7 @@ public class LauncherActivity extends Activity {
mSettings.loadSettings(this);
mPref = getSharedPreferences("engine", 0);
cmdArgs = (EditText)findViewById(R.id.cmdArgs);
cmdArgs.setText(mPref.getString("argv","-dev 3 -console -log"));
cmdArgs.setText(mPref.getString("argv","-dev 3 -log"));
useControls = ( CheckBox ) findViewById( R.id.useControls );
useControls.setChecked(mPref.getBoolean("controls",true));
resPath = ( EditText ) findViewById( R.id.cmdPath );

View file

@ -7,6 +7,8 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import in.celest.xash3d.hl.R;
import android.widget.EditText;
import java.io.File;
import java.io.FilenameFilter;
import android.os.*;
@ -19,7 +21,7 @@ public class ShortcutActivity extends Activity
super.onCreate(bundle);
setContentView(R.layout.activity_shortcut);
name=(EditText)findViewById(R.id.shortcut_name);
name.setText("Name");
//name.setText("Name");
}
public void saveShortcut(View view)
{
@ -32,10 +34,30 @@ public class ShortcutActivity extends Activity
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));
Bitmap icon;
// Try find icon
try
{
FilenameFilter icoFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
if(name.endsWith(".ico") || name.endsWith(".ICO")) {
return true;
}
return false;
}
};
String gamedirstring = getSharedPreferences("engine", 0).getString("basedir","/sdcard/xash/")+(gamedir.length()!=0?gamedir.getText().toString():"valve");
File gamedirfile = new File(gamedirstring);
String files[] = gamedirfile.list(icoFilter);
int size = (int) getResources().getDimension(android.R.dimen.app_icon_size);
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);
setResult(RESULT_OK, wrapIntent);
finish();
}