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

@ -8,7 +8,6 @@
android:background="#252525" android:background="#252525"
android:weightSum="1" android:weightSum="1"
tools:context="in.celest.xash3d.LauncherActivity"> tools:context="in.celest.xash3d.LauncherActivity">
<TextView <TextView
android:id="@+id/textView_tittle" android:id="@+id/textView_tittle"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -25,7 +24,6 @@
android:drawablePadding="10dp" android:drawablePadding="10dp"
android:singleLine="true" android:singleLine="true"
android:gravity="center_vertical" /> android:gravity="center_vertical" />
<TabHost <TabHost
android:id="@+id/tabhost" android:id="@+id/tabhost"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -35,29 +33,24 @@
android:paddingLeft="3dp" android:paddingLeft="3dp"
android:paddingRight="3dp" android:paddingRight="3dp"
android:paddingTop="8dp"> android:paddingTop="8dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#555555" android:background="#555555"
android:orientation="vertical"> android:orientation="vertical">
<TabWidget <TabWidget
android:id="@android:id/tabs" android:id="@android:id/tabs"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:showDividers="middle"></TabWidget> android:showDividers="middle" />
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/scrollView2" > android:id="@+id/scrollView2">
<FrameLayout <FrameLayout
android:id="@android:id/tabcontent" android:id="@android:id/tabcontent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
>
<LinearLayout <LinearLayout
android:id="@+id/tab1" android:id="@+id/tab1"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -70,7 +63,6 @@
android:orientation="vertical" android:orientation="vertical"
android:text="@string/text_tab1" android:text="@string/text_tab1"
android:weightSum="0.6"> android:weightSum="0.6">
<TextView <TextView
android:id="@+id/textView_path1" android:id="@+id/textView_path1"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -84,9 +76,7 @@
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" android:textSize="20sp"
android:gravity="center_vertical|center_horizontal" /> android:gravity="center_vertical|center_horizontal" />
<LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
@ -96,8 +86,6 @@
android:background="#444444" android:background="#444444"
android:orientation="vertical" android:orientation="vertical"
android:weightSum="1"> android:weightSum="1">
<ToggleButton <ToggleButton
android:id="@+id/useVolume" android:id="@+id/useVolume"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -109,23 +97,23 @@
android:text="nothing" android:text="nothing"
android:textOff="@string/no_volume" android:textOff="@string/no_volume"
android:textOn="@string/use_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"--> <CheckBox
<!--android:layout_width="match_parent"--> android:layout_height="wrap_content"
<!--android:textAppearance="?android:attr/textAppearanceMedium"--> android:layout_width="match_parent"
<!--android:text="@string/use_volume"--> android:textAppearance="?android:attr/textAppearanceMedium"
<!--android:id="@+id/useVolume"/>--> android:text="@string/tracking"
android:id="@+id/Tracking"/>
<!--<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 <Button
android:id="@+id/button_select" android:id="@+id/button_select"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -137,14 +125,8 @@
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:onClick="selectFolder" android:onClick="selectFolder"
android:text="@string/select_folder" /> android:text="@string/select_folder" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/tab2" android:id="@+id/tab2"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -155,7 +137,6 @@
android:background="#333333" android:background="#333333"
android:orientation="vertical" android:orientation="vertical"
android:text="@string/text_tab2"> android:text="@string/text_tab2">
<TextView <TextView
android:id="@+id/textView_path2" android:id="@+id/textView_path2"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -169,9 +150,7 @@
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" android:textSize="20sp"
android:gravity="center_vertical|center_horizontal" /> android:gravity="center_vertical|center_horizontal" />
<LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
@ -181,7 +160,6 @@
android:background="#444444" android:background="#444444"
android:orientation="vertical" android:orientation="vertical"
android:weightSum="1"> android:weightSum="1">
<TextView <TextView
android:id="@+id/textView_args" android:id="@+id/textView_args"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -192,7 +170,6 @@
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:text="@string/cmd_args_text" android:text="@string/cmd_args_text"
android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText <EditText
android:id="@+id/cmdArgs" android:id="@+id/cmdArgs"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -201,7 +178,6 @@
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:layout_marginTop="3dp" /> android:layout_marginTop="3dp" />
<TextView <TextView
android:id="@+id/textView_path" android:id="@+id/textView_path"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -212,7 +188,6 @@
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:text="@string/text_res_path" android:text="@string/text_res_path"
android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText <EditText
android:id="@+id/cmdPath" android:id="@+id/cmdPath"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -221,8 +196,6 @@
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:layout_marginTop="3dp" /> android:layout_marginTop="3dp" />
<Button <Button
android:id="@+id/button_shortcut" android:id="@+id/button_shortcut"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -240,8 +213,16 @@
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:layout_marginTop="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 <TextView
android:id="@+id/textView7" android:id="@+id/textView7"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
@ -252,15 +233,10 @@
android:clickable="false" /> android:clickable="false" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>
</ScrollView> </ScrollView>
</LinearLayout> </LinearLayout>
</TabHost> </TabHost>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="50dp"
@ -269,16 +245,13 @@
android:paddingTop="5dp" android:paddingTop="5dp"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:orientation="horizontal"> android:orientation="horizontal">
<Button <Button
android:id="@+id/button_about" android:id="@+id/button_about"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="left" android:layout_gravity="left"
android:onClick="aboutXash" android:onClick="aboutXash"
android:text="@string/about_button" /> android:text="@string/about_button" />
<Button <Button
android:id="@+id/button_launch" android:id="@+id/button_launch"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -288,9 +261,5 @@
android:layout_weight="0.87" android:layout_weight="0.87"
android:onClick="startXash" android:onClick="startXash"
android:text="@string/launch_button" /> android:text="@string/launch_button" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">Xash3D</string> <string name="app_name">Xash3D</string>
<string name="launcher_name">Xash3D</string> <string name="launcher_name">Xash3D</string>
<string name="launcher_name_test">Xash3D (test)</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="launch_button">Launch Xash3D!</string>
<string name="cmd_args_text">Command line arguments(experts only)</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="pkgname">Mod package name (experts only)</string>
<string name="shortcut_name">Shortcut name</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_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="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> <!-- Seems Android skips any line breaks and tabs here. -->
<string name="about_authors">Port to Android by SDLash3D team: \n <string name="about_authors">
&#8226; a1batross\n Port to Android by SDLash3D team: \n
&#8226; mittorn \n &#8226; a1batross\n
&#8226; nicknekit.\n &#8226; mittorn \n
&#8226; nicknekit.\n
Special thanks to:\n Special thanks to:\n
&#8226; Uncle Mike for Xash3D engine\n &#8226; Uncle Mike for Xash3D engine\n
&#8226; Valve for Half-Life\n &#8226; Valve for Half-Life\n
&#8226; libSDL2 developers.\n</string> &#8226; libSDL2 developers.\n
<string name="about_links">Follow us in: </string>
&#8226; <a href="https://vk.com/xashdroid">VK</a> <string name="about_links">
&#8226; <a href="http://moddb.com/game/xash3d-android">ModDB</a> Follow us in: \n
&#8226; <a href="https://github.com/SDLash3D">GitHub</a></string> &#8226; <a href="https://vk.com/xashdroid">VK</a>\n
<string name="about_button">About Xash3D Android</string> &#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="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_tab1">Normal</string>
<string name="text_tab2">Advanced</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="use_volume">Gamepad support off!</string>
<string name="no_volume">Gamepad support active!</string> <string name="no_volume">Gamepad support active!</string>
<string name="folder">Set current folder</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> </resources>

View file

@ -2,44 +2,67 @@ package in.celest.xash3d;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.app.AlertDialog;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Build; import android.os.Build;
import android.os.Environment;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.content.Intent;
import android.view.Window; 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.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener; import android.content.DialogInterface.OnDismissListener;
import android.net.Uri;
import android.os.Environment; import android.widget.EditText;
import java.lang.reflect.Method; import android.widget.CheckBox;
import java.util.List; import android.widget.CompoundButton;
import java.io.File; import android.widget.Button;
import android.widget.Spinner;
import android.widget.ArrayAdapter;
import android.widget.TabHost; import android.widget.TabHost;
import android.widget.ToggleButton; 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; import in.celest.xash3d.hl.R;
public class LauncherActivity extends Activity { public class LauncherActivity extends Activity {
// public final static String ARGV = "in.celest.xash3d.MESSAGE"; // public final static String ARGV = "in.celest.xash3d.MESSAGE";
public final static int sdk = Integer.valueOf(Build.VERSION.SDK); 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 EditText cmdArgs;
static ToggleButton useVolume; static ToggleButton useVolume;
static CheckBox checkUpdates;
static EditText resPath; static EditText resPath;
static SharedPreferences mPref; static SharedPreferences mPref;
static Spinner pixelSpinner; static Spinner pixelSpinner;
String getDefaultPath() String getDefaultPath()
{ {
File dir = Environment.getExternalStorageDirectory(); File dir = Environment.getExternalStorageDirectory();
@ -47,8 +70,10 @@ public class LauncherActivity extends Activity {
return dir.getPath() + "/xash"; return dir.getPath() + "/xash";
return "/sdcard/xash"; return "/sdcard/xash";
} }
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//super.setTheme( 0x01030005 ); //super.setTheme( 0x01030005 );
@ -57,7 +82,6 @@ public class LauncherActivity extends Activity {
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.setup();
TabHost.TabSpec tabSpec; TabHost.TabSpec tabSpec;
@ -71,6 +95,13 @@ public class LauncherActivity extends Activity {
tabSpec.setContent(R.id.tab2); tabSpec.setContent(R.id.tab2);
tabHost.addTab(tabSpec); 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);
final String[] list = { final String[] list = {
"RGBA8888", "RGBA8888",
"RGBA888", "RGBA888",
@ -79,46 +110,20 @@ public class LauncherActivity extends Activity {
"RGBA4444", "RGBA4444",
"RGB332" "RGB332"
}; };
pixelSpinner = (Spinner) findViewById(R.id.pixelSpinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, list); 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); adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
pixelSpinner.setAdapter(adapter); 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)); useVolume.setChecked(mPref.getBoolean("usevolume",true));
resPath = ( EditText ) findViewById( R.id.cmdPath ); checkUpdates.setChecked(mPref.getBoolean("check_updates",true));
resPath.setText(mPref.getString("basedir", getDefaultPath())); resPath.setText(mPref.getString("basedir", getDefaultPath()));
cmdArgs.setText(mPref.getString("argv","-dev 3 -log"));
pixelSpinner.setSelection(mPref.getInt("pixelformat", 0)); pixelSpinner.setSelection(mPref.getInt("pixelformat", 0));
if(mPref.getBoolean("check_updates", true))
{
new RetrieveJSON(true).execute(UPDATE_LINK);
}
} }
public void startXash(View view) public void startXash(View view)
@ -131,6 +136,7 @@ public class LauncherActivity extends Activity {
editor.putBoolean("usevolume",useVolume.isChecked()); editor.putBoolean("usevolume",useVolume.isChecked());
editor.putString("basedir", resPath.getText().toString()); editor.putString("basedir", resPath.getText().toString());
editor.putInt("pixelformat", pixelSpinner.getSelectedItemPosition()); editor.putInt("pixelformat", pixelSpinner.getSelectedItemPosition());
editor.putBoolean("check_updates", checkUpdates.isChecked());
editor.commit(); editor.commit();
startActivity(intent); startActivity(intent);
} }
@ -138,13 +144,13 @@ public class LauncherActivity extends Activity {
public void aboutXash(View view) public void aboutXash(View view)
{ {
final Activity a = this; final Activity a = this;
this.runOnUiThread(new Runnable() { this.runOnUiThread(new Runnable()
{
public void run() public void run()
{ {
final Dialog dialog = new Dialog(a); final Dialog dialog = new Dialog(a);
dialog.setContentView(R.layout.about); dialog.setContentView(R.layout.about);
dialog.setCancelable(true); dialog.setCancelable(true);
dialog.show(); dialog.show();
} }
}); });
@ -154,15 +160,17 @@ public class LauncherActivity extends Activity {
{ {
Intent intent = new Intent(this, in.celest.xash3d.FPicker.class); Intent intent = new Intent(this, in.celest.xash3d.FPicker.class);
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //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); startActivityForResult(intent, 42);
resPath.setEnabled(false); resPath.setEnabled(false);
} }
public void onActivityResult(int requestCode, int resultCode, Intent resultData) { public void onActivityResult(int requestCode, int resultCode, Intent resultData)
if (resultCode == RESULT_OK) { {
try{ if (resultCode == RESULT_OK)
{
try
{
resPath = ( EditText ) findViewById( R.id.cmdPath ); resPath = ( EditText ) findViewById( R.id.cmdPath );
resPath.setText( resultData.getStringExtra("GetPath")); resPath.setText( resultData.getStringExtra("GetPath"));
@ -212,4 +220,96 @@ try{
return super.onOptionsItemSelected(item); 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();
}
}
}
} }