Autoupdater: add a checkbox for checking beta versions also
This commit is contained in:
parent
1195c1b96b
commit
106b193511
4 changed files with 128 additions and 67 deletions
|
@ -87,6 +87,15 @@
|
|||
android:background="#444444"
|
||||
android:orientation="vertical"
|
||||
android:weightSum="1">
|
||||
<TextView
|
||||
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/volume"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
<ToggleButton
|
||||
android:id="@+id/useVolume"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -98,6 +107,16 @@
|
|||
android:text="nothing"
|
||||
android:textOff="@string/no_volume"
|
||||
android:textOn="@string/use_volume" />
|
||||
<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" />
|
||||
<Button
|
||||
android:id="@+id/button_select"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -109,6 +128,16 @@
|
|||
android:layout_marginRight="10dp"
|
||||
android:onClick="selectFolder"
|
||||
android:text="@string/select_folder" />
|
||||
<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" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
|
@ -163,7 +192,6 @@
|
|||
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"
|
||||
|
@ -180,19 +208,18 @@
|
|||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="3dp" />
|
||||
<Button
|
||||
android:id="@+id/button_shortcut"
|
||||
android:layout_width="match_parent"
|
||||
<TextView
|
||||
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="10dp"
|
||||
android:onClick="createShortcut"
|
||||
android:text="@string/create_shortcut_button" />
|
||||
android:layout_marginTop="3dp"
|
||||
android:text="Pixel Format"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
<Spinner
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="math_parent"
|
||||
android:id="@+id/pixelSpinner"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
|
@ -218,6 +245,15 @@
|
|||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/update_button" />
|
||||
<CheckBox
|
||||
android:id="@+id/check_betas"
|
||||
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_to_beta" />
|
||||
<TextView
|
||||
android:id="@+id/textView7"
|
||||
android:layout_marginBottom="10dp"
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
<string name="folder">Выбрать текущий каталог</string>
|
||||
|
||||
<string name="update_button">Проверять обновления при запуске</string>
|
||||
<string name="update_button">Обновлять до нестабильной версии, если доступно</string>
|
||||
<string name="update_message">%s доступен! Скачай его сейчас!</string>
|
||||
<string name="update">Обновить</string>
|
||||
<string name="cancel">Отмена</string>
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
<string name="folder">Set current folder</string>
|
||||
|
||||
<string name="update_button">Check updates on start</string>
|
||||
<string name="update_button">Update to unstable version if available</string>
|
||||
<string name="update_message">%s is available! Download it now!</string>
|
||||
<string name="update">Update</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
|
|
|
@ -56,14 +56,13 @@ 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 ToggleButton resizeWorkaround;
|
||||
static CheckBox checkUpdates;
|
||||
static EditText resPath;
|
||||
public final static String UPDATE_LINK = "https://api.github.com/repos/SDLash3D/xash3d-android-project/releases"; // releases/latest doesn't return prerelease and drafts
|
||||
static EditText cmdArgs, resPath;
|
||||
static ToggleButton useVolume, resizeWorkaround;
|
||||
static CheckBox checkUpdates, updateToBeta;
|
||||
static SharedPreferences mPref;
|
||||
static Spinner pixelSpinner;
|
||||
static TextView tvResPath;
|
||||
|
||||
String getDefaultPath()
|
||||
{
|
||||
|
@ -98,35 +97,47 @@ public class LauncherActivity extends Activity {
|
|||
tabSpec.setContent(R.id.tab2);
|
||||
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 );
|
||||
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);
|
||||
updateToBeta = (CheckBox)findViewById(R.id.check_betas);
|
||||
pixelSpinner = (Spinner) findViewById(R.id.pixelSpinner);
|
||||
resizeWorkaround = (ToggleButton) findViewById( R.id.enableResizeWorkaround );
|
||||
|
||||
tvResPath = (TextView) findViewById( R.id.textView_path );
|
||||
|
||||
final String[] list = {
|
||||
"RGBA8888",
|
||||
"RGBA888",
|
||||
"RGB565",
|
||||
"RGBA5551",
|
||||
"RGBA4444",
|
||||
"RGB332"
|
||||
"32 bit (RGBA8888)",
|
||||
"24 bit (RGB888)",
|
||||
"16 bit (RGB565)",
|
||||
"15 bit (RGBA5551)",
|
||||
"12 bit (RGBA4444)",
|
||||
"8 bit (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()));
|
||||
updateToBeta.setChecked(mPref.getBoolean("check_betas", false);
|
||||
updatePath(mPref.getString("basedir", getDefaultPath()));
|
||||
cmdArgs.setText(mPref.getString("argv","-dev 3 -log"));
|
||||
pixelSpinner.setSelection(mPref.getInt("pixelformat", 0));
|
||||
resizeWorkaround.setChecked(mPref.getBoolean("enableResizeWorkaround",true));
|
||||
resizeWorkaround.setChecked(mPref.getBoolean("enableResizeWorkaround", true));
|
||||
|
||||
resPath.setOnFocusChangeListener( new View.OnFocusChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus)
|
||||
{
|
||||
updatePath( resPath.getText().toString() );
|
||||
}
|
||||
} );
|
||||
|
||||
if(mPref.getBoolean("check_updates", true))
|
||||
{
|
||||
new CheckUpdate(true).execute(UPDATE_LINK);
|
||||
new CheckUpdate(true, updateToBeta.getBoolean()).execute(UPDATE_LINK);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,13 +196,6 @@ public class LauncherActivity extends Activity {
|
|||
if( resPath == null )
|
||||
return;
|
||||
updatePath(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)
|
||||
|
@ -237,13 +241,16 @@ public class LauncherActivity extends Activity {
|
|||
InputStream is = null;
|
||||
ByteArrayOutputStream os = null;
|
||||
boolean mSilent;
|
||||
boolean mBeta;
|
||||
|
||||
public CheckUpdate( boolean silent )
|
||||
public CheckUpdate( boolean silent, boolean beta )
|
||||
{
|
||||
mSilent = silent;
|
||||
mBeta = beta;
|
||||
}
|
||||
|
||||
protected String doInBackground(String... urls) {
|
||||
protected String doInBackground(String... urls)
|
||||
{
|
||||
try
|
||||
{
|
||||
URL url = new URL(urls[0]);
|
||||
|
@ -268,6 +275,7 @@ public class LauncherActivity extends Activity {
|
|||
|
||||
protected void onPostExecute(String result)
|
||||
{
|
||||
JSONArray releases = null;
|
||||
try
|
||||
{
|
||||
if (is != null)
|
||||
|
@ -280,12 +288,12 @@ public class LauncherActivity extends Activity {
|
|||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONObject obj = new JSONObject(os.toString());
|
||||
|
||||
try
|
||||
{
|
||||
if (os != null)
|
||||
{
|
||||
releases = new JSONArray(os.toString());
|
||||
os.close();
|
||||
os = null;
|
||||
}
|
||||
|
@ -293,36 +301,51 @@ public class LauncherActivity extends Activity {
|
|||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
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));
|
||||
|
||||
// this is an update
|
||||
if( getString(R.string.version_string).compareTo(version) < 0 )
|
||||
|
||||
if( releases == null )
|
||||
return;
|
||||
|
||||
for( JSONObject obj: releases )
|
||||
{
|
||||
String dialog_message = String.format(getString(R.string.update_message), 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();
|
||||
final String version, url, name;
|
||||
final bool beta = obj.getBoolean("prerelease");
|
||||
|
||||
if( beta && !mBeta )
|
||||
continue;
|
||||
|
||||
version = obj.getString("tag_name");
|
||||
url = obj.getString("html_url");
|
||||
name = obj.getString("name");
|
||||
Log.d("Xash", "Found: " + version +
|
||||
", I: " + getString(R.string.version_string));
|
||||
|
||||
// this is an update
|
||||
if( getString(R.string.version_string).compareTo(version) < 0 )
|
||||
{
|
||||
String dialog_message String.format(getString(R.string.update_message), 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 id) {} } );
|
||||
builder.create().show();
|
||||
}
|
||||
else if( !mSilent )
|
||||
{
|
||||
Toast.makeText(getBaseContext(), R.string.no_updates, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
// No need to check other releases, so we will stop here.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue