Add autoupdate checker

This commit is contained in:
a1batross 2016-05-20 23:46:35 +03:00
parent e5c3122ba7
commit 9b2c616baa
3 changed files with 497 additions and 418 deletions

View file

@ -1,296 +1,265 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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">
<TextView
android:id="@+id/textView_tittle"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginBottom="1dp"
android:layout_marginLeft="5dp"
android:background="#555555"
android:layout_marginRight="5dp"
android:layout_marginTop="20dp"
android:text="@string/launcher_name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="25sp"
android:drawableLeft="@drawable/ic_launcher"
android:drawablePadding="10dp"
android:singleLine="true"
android:gravity="center_vertical" />
<TabHost
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.20"
android:paddingBottom="10dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#555555"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:showDividers="middle"></TabWidget>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView2" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="25dp"
android:background="#333333"
android:orientation="vertical"
android:text="@string/text_tab1"
android:weightSum="0.6">
<TextView
android:id="@+id/textView_path1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="10dp"
android:background="#444444"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="@string/text_res_tittle2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp"
android:gravity="center_vertical|center_horizontal" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#444444"
android:orientation="vertical"
android:weightSum="1">
<ToggleButton
android:id="@+id/useVolume"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="nothing"
android:textOff="@string/no_volume"
android:textOn="@string/use_volume" />
<!--<CheckBox-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_width="match_parent"-->
<!--android:textAppearance="?android:attr/textAppearanceMedium"-->
<!--android:text="@string/use_volume"-->
<!--android:id="@+id/useVolume"/>-->
<!--<CheckBox-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_width="match_parent"-->
<!--android:textAppearance="?android:attr/textAppearanceMedium"-->
<!--android:text="@string/tracking"-->
<!--android:id="@+id/Tracking"/>-->
<Button
android:id="@+id/button_select"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:onClick="selectFolder"
android:text="@string/select_folder" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#333333"
android:orientation="vertical"
android:text="@string/text_tab2">
<TextView
android:id="@+id/textView_path2"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="10dp"
android:background="#444444"
android:layout_marginRight="10dp"
android:layout_marginTop="13dp"
android:text="@string/text_res_tittle3"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp"
android:gravity="center_vertical|center_horizontal" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#444444"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="@+id/textView_args"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:text="@string/cmd_args_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/cmdArgs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp" />
<TextView
android:id="@+id/textView_path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:text="@string/text_res_path"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/cmdPath"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp" />
<Button
android:id="@+id/button_shortcut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:onClick="createShortcut"
android:text="@string/create_shortcut_button" />
<Spinner
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:id="@+id/pixelSpinner"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/textView7"
android:layout_marginBottom="10dp"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:clickable="false" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</ScrollView>
</LinearLayout>
</TabHost>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#444444"
android:layout_marginBottom="-20dp"
android:paddingTop="5dp"
android:layout_gravity="bottom"
android:orientation="horizontal">
<Button
android:id="@+id/button_about"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:onClick="aboutXash"
android:text="@string/about_button" />
<Button
android:id="@+id/button_launch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="6"
android:layout_marginLeft="0dp"
android:layout_weight="0.87"
android:onClick="startXash"
android:text="@string/launch_button" />
</LinearLayout>
</LinearLayout>
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">
<TextView
android:id="@+id/textView_tittle"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginBottom="1dp"
android:layout_marginLeft="5dp"
android:background="#555555"
android:layout_marginRight="5dp"
android:layout_marginTop="20dp"
android:text="@string/launcher_name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="25sp"
android:drawableLeft="@drawable/ic_launcher"
android:drawablePadding="10dp"
android:singleLine="true"
android:gravity="center_vertical" />
<TabHost
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.20"
android:paddingBottom="10dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#555555"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:showDividers="middle" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView2">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="25dp"
android:background="#333333"
android:orientation="vertical"
android:text="@string/text_tab1"
android:weightSum="0.6">
<TextView
android:id="@+id/textView_path1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="10dp"
android:background="#444444"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="@string/text_res_tittle2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp"
android:gravity="center_vertical|center_horizontal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#444444"
android:orientation="vertical"
android:weightSum="1">
<ToggleButton
android:id="@+id/useVolume"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="nothing"
android:textOff="@string/no_volume"
android:textOn="@string/use_volume" />
<!--
<CheckBox
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/use_volume"
android:id="@+id/useVolume"/>
-->
<!--
<CheckBox
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/tracking"
android:id="@+id/Tracking"/>
-->
<Button
android:id="@+id/button_select"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:onClick="selectFolder"
android:text="@string/select_folder" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#333333"
android:orientation="vertical"
android:text="@string/text_tab2">
<TextView
android:id="@+id/textView_path2"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="10dp"
android:background="#444444"
android:layout_marginRight="10dp"
android:layout_marginTop="13dp"
android:text="@string/text_res_tittle3"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp"
android:gravity="center_vertical|center_horizontal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#444444"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="@+id/textView_args"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:text="@string/cmd_args_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/cmdArgs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp" />
<TextView
android:id="@+id/textView_path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:text="@string/text_res_path"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/cmdPath"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp" />
<Button
android:id="@+id/button_shortcut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:onClick="createShortcut"
android:text="@string/create_shortcut_button" />
<Spinner
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:id="@+id/pixelSpinner"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
<CheckBox
android:id="@+id/check_updates"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="@string/update_button" />
<TextView
android:id="@+id/textView7"
android:layout_marginBottom="10dp"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:clickable="false" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</ScrollView>
</LinearLayout>
</TabHost>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#444444"
android:layout_marginBottom="-20dp"
android:paddingTop="5dp"
android:layout_gravity="bottom"
android:orientation="horizontal">
<Button
android:id="@+id/button_about"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:onClick="aboutXash"
android:text="@string/about_button" />
<Button
android:id="@+id/button_launch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="6"
android:layout_marginLeft="0dp"
android:layout_weight="0.87"
android:onClick="startXash"
android:text="@string/launch_button" />
</LinearLayout>
</LinearLayout>

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Xash3D</string>
<string name="launcher_name">Xash3D</string>
<string name="launcher_name_test">Xash3D (test)</string>
<string name="version_string" translatable="false">v0.17.1</string>
<string name="launch_button">Launch Xash3D!</string>
<string name="cmd_args_text">Command line arguments(experts only)</string>
@ -16,26 +16,29 @@
<string name="pkgname">Mod package name (experts only)</string>
<string name="shortcut_name">Shortcut name</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="about_main">Xash3D Android</string>
<string name="about_copyright">SDLash3D is not affiliated with Valve or any of their partners. All copyrights reserved to their respective owners.</string>
<string name="version_string" translatable="false">v0.17.1</string>
<string name="about_authors">Port to Android by SDLash3D team: \n
&#8226; a1batross\n
&#8226; mittorn \n
&#8226; nicknekit.\n
<!-- Seems Android skips any line breaks and tabs here. -->
<string name="about_authors">
Port to Android by SDLash3D team: \n
&#8226; a1batross\n
&#8226; mittorn \n
&#8226; nicknekit.\n
Special thanks to:\n
&#8226; Uncle Mike for Xash3D engine\n
&#8226; Valve for Half-Life\n
&#8226; libSDL2 developers.\n</string>
<string name="about_links">Follow us in:
&#8226; <a href="https://vk.com/xashdroid">VK</a>
&#8226; <a href="http://moddb.com/game/xash3d-android">ModDB</a>
&#8226; <a href="https://github.com/SDLash3D">GitHub</a></string>
<string name="about_button">About Xash3D Android</string>
Special thanks to:\n
&#8226; Uncle Mike for Xash3D engine\n
&#8226; Valve for Half-Life\n
&#8226; libSDL2 developers.\n
</string>
<string name="about_links">
Follow us in: \n
&#8226; <a href="https://vk.com/xashdroid">VK</a>\n
&#8226; <a href="http://moddb.com/game/xash3d-android">ModDB</a>\n
&#8226; <a href="https://github.com/SDLash3D">GitHub</a>
</string>
<string name="about_button">About</string>
<string name="create_shortcut_button">Create mod shortcut</string>
<string name="select_folder">(select)</string>
<string name="select_folder">Select game data location</string>
<string name="text_tab1">Normal</string>
<string name="text_tab2">Advanced</string>
@ -44,4 +47,11 @@ Special thanks to:\n
<string name="use_volume">Gamepad support off!</string>
<string name="no_volume">Gamepad support active!</string>
<string name="folder">Set current folder</string>
<string name="update_button">Check updates on start</string>
<string name="update_message">%s is available!</string>
<string name="update">Update</string>
<string name="cancel">Cancel</string>
<string name="no_updates">No updates was found</string>
<string name="checking_updates">Working...</string>
</resources>

View file

@ -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<String> adapter = new ArrayAdapter<String>(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<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, list);
//ArrayAdapter<CharSequence> 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<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)
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<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);
}
@ -212,4 +220,96 @@ try{
return super.onOptionsItemSelected(item);
}
private class RetrieveJSON extends AsyncTask<String, Void, String> {
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();
}
}
}
}