diff --git a/res/layout/activity_launcher.xml b/res/layout/activity_launcher.xml
index fa08ecca..51796d7c 100644
--- a/res/layout/activity_launcher.xml
+++ b/res/layout/activity_launcher.xml
@@ -1,296 +1,265 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ xmlns:tools="http://schemas.android.com/tools"
+ android:id="@+id/layout_shortcut"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:background="#252525"
+ android:weightSum="1"
+ tools:context="in.celest.xash3d.LauncherActivity">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 19b742ab..1283762e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1,9 +1,9 @@
-
Xash3D
Xash3D
Xash3D (test)
+ v0.17.1
Launch Xash3D!
Command line arguments(experts only)
@@ -16,26 +16,29 @@
Mod package name (experts only)
Shortcut name
-
Xash3D Android
SDLash3D is not affiliated with Valve or any of their partners. All copyrights reserved to their respective owners.
- v0.17.1
- Port to Android by SDLash3D team: \n
-• a1batross\n
-• mittorn \n
-• nicknekit.\n
+
+
+ Port to Android by SDLash3D team: \n
+ • a1batross\n
+ • mittorn \n
+ • nicknekit.\n
-Special thanks to:\n
-• Uncle Mike for Xash3D engine\n
-• Valve for Half-Life\n
-• libSDL2 developers.\n
-Follow us in:
- • VK
- • ModDB
- • GitHub
- About Xash3D Android
+ Special thanks to:\n
+ • Uncle Mike for Xash3D engine\n
+ • Valve for Half-Life\n
+ • libSDL2 developers.\n
+
+
+ Follow us in: \n
+ • VK\n
+ • ModDB\n
+ • GitHub
+
+ About
Create mod shortcut
- (select)
+ Select game data location
Normal
Advanced
@@ -44,4 +47,11 @@ Special thanks to:\n
Gamepad support off!
Gamepad support active!
Set current folder
+
+ Check updates on start
+ %s is available!
+ Update
+ Cancel
+ No updates was found
+ Working...
diff --git a/src/in/celest/xash3d/LauncherActivity.java b/src/in/celest/xash3d/LauncherActivity.java
index 5c0e1036..4c9471e5 100644
--- a/src/in/celest/xash3d/LauncherActivity.java
+++ b/src/in/celest/xash3d/LauncherActivity.java
@@ -2,44 +2,67 @@ package in.celest.xash3d;
import android.app.Activity;
import android.app.Dialog;
+import android.app.AlertDialog;
+
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Build;
+import android.os.Environment;
+
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.content.Intent;
import android.view.Window;
-import android.widget.EditText;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-import android.widget.Button;
-import android.widget.Spinner;
-import android.widget.ArrayAdapter;
+import android.content.Intent;
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 android.widget.EditText;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.Button;
+import android.widget.Spinner;
+import android.widget.ArrayAdapter;
import android.widget.TabHost;
import android.widget.ToggleButton;
+import android.widget.Toast;
+
+import android.net.Uri;
+
+import android.util.Log;
+
+import java.lang.reflect.Method;
+
+import java.util.List;
+
+import java.io.File;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.FileOutputStream;
+
+import java.net.URLConnection;
+import java.net.URL;
+
+import org.json.*;
import in.celest.xash3d.hl.R;
public class LauncherActivity extends Activity {
// public final static String ARGV = "in.celest.xash3d.MESSAGE";
public final static int sdk = Integer.valueOf(Build.VERSION.SDK);
+ public final static String UPDATE_LINK = "https://api.github.com/repos/SDLash3D/xash3d-android-project/releases/latest";
static EditText cmdArgs;
static ToggleButton useVolume;
+ static CheckBox checkUpdates;
static EditText resPath;
static SharedPreferences mPref;
static Spinner pixelSpinner;
+
String getDefaultPath()
{
File dir = Environment.getExternalStorageDirectory();
@@ -47,104 +70,87 @@ public class LauncherActivity extends Activity {
return dir.getPath() + "/xash";
return "/sdcard/xash";
}
+
@Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- //super.setTheme( 0x01030005 );
- if ( sdk >= 21 )
+ protected void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ this.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ //super.setTheme( 0x01030005 );
+ if ( sdk >= 21 )
super.setTheme( 0x01030224 );
- setContentView(R.layout.activity_launcher);
+ setContentView(R.layout.activity_launcher);
- TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
+ TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
+ tabHost.setup();
+
+ TabHost.TabSpec tabSpec;
+ tabSpec = tabHost.newTabSpec("tabtag1");
+ tabSpec.setIndicator(getString(R.string.text_tab1));
+ tabSpec.setContent(R.id.tab1);
+ tabHost.addTab(tabSpec);
- tabHost.setup();
+ tabSpec = tabHost.newTabSpec("tabtag2");
+ tabSpec.setIndicator(getString(R.string.text_tab2));
+ tabSpec.setContent(R.id.tab2);
+ tabHost.addTab(tabSpec);
- TabHost.TabSpec tabSpec;
- tabSpec = tabHost.newTabSpec("tabtag1");
- tabSpec.setIndicator(getString(R.string.text_tab1));
- tabSpec.setContent(R.id.tab1);
- tabHost.addTab(tabSpec);
+ mPref = getSharedPreferences("engine", 0);
+ cmdArgs = (EditText)findViewById(R.id.cmdArgs);
+ useVolume = ( ToggleButton ) findViewById( R.id.useVolume );
+ resPath = ( EditText ) findViewById( R.id.cmdPath );
+ checkUpdates = (CheckBox)findViewById(R.id.check_updates);
+ pixelSpinner = (Spinner) findViewById(R.id.pixelSpinner);
- tabSpec = tabHost.newTabSpec("tabtag2");
- tabSpec.setIndicator(getString(R.string.text_tab2));
- tabSpec.setContent(R.id.tab2);
- tabHost.addTab(tabSpec);
+ final String[] list = {
+ "RGBA8888",
+ "RGBA888",
+ "RGB565",
+ "RGBA5551",
+ "RGBA4444",
+ "RGB332"
+ };
+ ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, list);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
+ pixelSpinner.setAdapter(adapter);
+ useVolume.setChecked(mPref.getBoolean("usevolume",true));
+ checkUpdates.setChecked(mPref.getBoolean("check_updates",true));
+ resPath.setText(mPref.getString("basedir", getDefaultPath()));
+ cmdArgs.setText(mPref.getString("argv","-dev 3 -log"));
+ pixelSpinner.setSelection(mPref.getInt("pixelformat", 0));
+
+ if(mPref.getBoolean("check_updates", true))
+ {
+ new RetrieveJSON(true).execute(UPDATE_LINK);
+ }
- final String[] list = {
- "RGBA8888",
- "RGBA888",
- "RGB565",
- "RGBA5551",
- "RGBA4444",
- "RGB332"
- };
- pixelSpinner = (Spinner) findViewById(R.id.pixelSpinner);
- ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, list);
- //ArrayAdapter adapter = ArrayAdapter.createFromResource(this, list, android.R.layout.simple_spinner_item);
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
- pixelSpinner.setAdapter(adapter);
- Button selectFolderButton = ( Button ) findViewById( R.id.button_select );
- selectFolderButton.setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- selectFolder(v);
- }
- });
- ((Button)findViewById( R.id.button_launch )).setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- startXash(v);
- }
- });
- ((Button)findViewById( R.id.button_shortcut )).setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- createShortcut(v);
- }
- });
- ((Button)findViewById( R.id.button_about )).setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- aboutXash(v);
- }
- });
-// if ( Build.VERSION.SDK_INT < 21 )
-// selectFolder.setVisibility( View.GONE );
- mPref = getSharedPreferences("engine", 0);
- cmdArgs = (EditText)findViewById(R.id.cmdArgs);
- cmdArgs.setText(mPref.getString("argv","-dev 3 -log"));
- useVolume = ( ToggleButton ) findViewById( R.id.useVolume );
- useVolume.setChecked(mPref.getBoolean("usevolume",true));
- resPath = ( EditText ) findViewById( R.id.cmdPath );
- resPath.setText(mPref.getString("basedir", getDefaultPath()));
- pixelSpinner.setSelection(mPref.getInt("pixelformat", 0));
}
public void startXash(View view)
{
- Intent intent = new Intent(this, XashActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ Intent intent = new Intent(this, XashActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- SharedPreferences.Editor editor = mPref.edit();
- editor.putString("argv", cmdArgs.getText().toString());
- editor.putBoolean("usevolume",useVolume.isChecked());
- editor.putString("basedir", resPath.getText().toString());
- editor.putInt("pixelformat", pixelSpinner.getSelectedItemPosition());
- editor.commit();
- startActivity(intent);
+ SharedPreferences.Editor editor = mPref.edit();
+ editor.putString("argv", cmdArgs.getText().toString());
+ editor.putBoolean("usevolume",useVolume.isChecked());
+ editor.putString("basedir", resPath.getText().toString());
+ editor.putInt("pixelformat", pixelSpinner.getSelectedItemPosition());
+ editor.putBoolean("check_updates", checkUpdates.isChecked());
+ editor.commit();
+ startActivity(intent);
}
public void aboutXash(View view)
{
final Activity a = this;
- this.runOnUiThread(new Runnable() {
+ this.runOnUiThread(new Runnable()
+ {
public void run()
{
final Dialog dialog = new Dialog(a);
dialog.setContentView(R.layout.about);
dialog.setCancelable(true);
-
dialog.show();
}
});
@@ -154,30 +160,32 @@ public class LauncherActivity extends Activity {
{
Intent intent = new Intent(this, in.celest.xash3d.FPicker.class);
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- // Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT_TREE");
+ //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{
-
- resPath = ( EditText ) findViewById( R.id.cmdPath );
- resPath.setText( resultData.getStringExtra("GetPath"));
-
-// final List 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)
+ public void onActivityResult(int requestCode, int resultCode, Intent resultData)
+ {
+ if (resultCode == RESULT_OK)
{
- e.printStackTrace();
- }
+ try
+ {
+ resPath = ( EditText ) findViewById( R.id.cmdPath );
+ resPath.setText( resultData.getStringExtra("GetPath"));
+
+// final List 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);
}
@@ -212,4 +220,96 @@ try{
return super.onOptionsItemSelected(item);
}
+
+ private class RetrieveJSON extends AsyncTask {
+ InputStream is = null;
+ ByteArrayOutputStream os = null;
+ boolean mSilent;
+
+ public RetrieveJSON( boolean silent )
+ {
+ mSilent = silent;
+ }
+
+ protected String doInBackground(String... urls) {
+ try
+ {
+ URL url = new URL(urls[0]);
+ is = url.openConnection().getInputStream();
+ os = new ByteArrayOutputStream();
+
+ byte[] buffer = new byte[8196];
+ int len;
+
+ while ((len = is.read(buffer)) > 0)
+ {
+ os.write(buffer, 0, len);
+ }
+ return os.toString();
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ protected void onPostExecute(String result)
+ {
+ try
+ {
+ if (is != null)
+ {
+ is.close();
+ is = null;
+ }
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ JSONObject obj = new JSONObject(os.toString());
+
+ try
+ {
+ if (os != null) {
+ os.close();
+ os = null;
+ }
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ final String version = obj.getString("tag_name");
+ final String url = obj.getString("html_url");
+ final String name = obj.getString("name");
+
+ Log.d("Xash", "Found: " + version +
+ ", I: " + getString(R.string.version_string));
+
+ if( !getString(R.string.version_string).equals(version) )
+ {
+ String dialog_message = getString(R.string.update_message).format(name);
+ AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext());
+ builder.setMessage(dialog_message)
+ .setPositiveButton(R.string.update, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int id) {
+ final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url));
+ startActivity(intent);
+ }
+ })
+ .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
+ {
+ public void onClick(DialogInterface dialog, int which){}
+ });
+ builder.create().show();
+ }
+ else if( !mSilent )
+ {
+ Toast.makeText(getBaseContext(), R.string.no_updates, Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
}