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:background="#444444"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:weightSum="1">
|
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
|
<ToggleButton
|
||||||
android:id="@+id/useVolume"
|
android:id="@+id/useVolume"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -98,6 +107,16 @@
|
||||||
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" />
|
||||||
|
<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
|
<Button
|
||||||
android:id="@+id/button_select"
|
android:id="@+id/button_select"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -109,6 +128,16 @@
|
||||||
android:layout_marginRight="10dp"
|
android:layout_marginRight="10dp"
|
||||||
android:onClick="selectFolder"
|
android:onClick="selectFolder"
|
||||||
android:text="@string/select_folder" />
|
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>
|
</LinearLayout>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -163,7 +192,6 @@
|
||||||
android:layout_marginRight="10dp"
|
android:layout_marginRight="10dp"
|
||||||
android:layout_marginTop="3dp" />
|
android:layout_marginTop="3dp" />
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView_path"
|
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
|
@ -180,19 +208,18 @@
|
||||||
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
|
<TextView
|
||||||
android:id="@+id/button_shortcut"
|
android:layout_width="fill_parent"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
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="3dp"
|
||||||
android:onClick="createShortcut"
|
android:text="Pixel Format"
|
||||||
android:text="@string/create_shortcut_button" />
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
<Spinner
|
<Spinner
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="math_parent"
|
||||||
android:id="@+id/pixelSpinner"
|
android:id="@+id/pixelSpinner"
|
||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:layout_marginLeft="10dp"
|
android:layout_marginLeft="10dp"
|
||||||
|
@ -218,6 +245,15 @@
|
||||||
android:layout_marginRight="10dp"
|
android:layout_marginRight="10dp"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:text="@string/update_button" />
|
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
|
<TextView
|
||||||
android:id="@+id/textView7"
|
android:id="@+id/textView7"
|
||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
<string name="folder">Выбрать текущий каталог</string>
|
<string name="folder">Выбрать текущий каталог</string>
|
||||||
|
|
||||||
<string name="update_button">Проверять обновления при запуске</string>
|
<string name="update_button">Проверять обновления при запуске</string>
|
||||||
|
<string name="update_button">Обновлять до нестабильной версии, если доступно</string>
|
||||||
<string name="update_message">%s доступен! Скачай его сейчас!</string>
|
<string name="update_message">%s доступен! Скачай его сейчас!</string>
|
||||||
<string name="update">Обновить</string>
|
<string name="update">Обновить</string>
|
||||||
<string name="cancel">Отмена</string>
|
<string name="cancel">Отмена</string>
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
<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_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_message">%s is available! Download it now!</string>
|
||||||
<string name="update">Update</string>
|
<string name="update">Update</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
|
|
|
@ -56,14 +56,13 @@ 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";
|
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;
|
static EditText cmdArgs, resPath;
|
||||||
static ToggleButton useVolume;
|
static ToggleButton useVolume, resizeWorkaround;
|
||||||
static ToggleButton resizeWorkaround;
|
static CheckBox checkUpdates, updateToBeta;
|
||||||
static CheckBox checkUpdates;
|
|
||||||
static EditText resPath;
|
|
||||||
static SharedPreferences mPref;
|
static SharedPreferences mPref;
|
||||||
static Spinner pixelSpinner;
|
static Spinner pixelSpinner;
|
||||||
|
static TextView tvResPath;
|
||||||
|
|
||||||
String getDefaultPath()
|
String getDefaultPath()
|
||||||
{
|
{
|
||||||
|
@ -98,35 +97,47 @@ 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);
|
mPref = getSharedPreferences("engine", 0);
|
||||||
cmdArgs = (EditText)findViewById(R.id.cmdArgs);
|
cmdArgs = (EditText)findViewById(R.id.cmdArgs);
|
||||||
useVolume = (ToggleButton) findViewById( R.id.useVolume );
|
useVolume = (ToggleButton) findViewById( R.id.useVolume );
|
||||||
resPath = (EditText) findViewById( R.id.cmdPath );
|
resPath = (EditText) findViewById( R.id.cmdPath );
|
||||||
checkUpdates = (CheckBox)findViewById(R.id.check_updates);
|
checkUpdates = (CheckBox)findViewById(R.id.check_updates);
|
||||||
|
updateToBeta = (CheckBox)findViewById(R.id.check_betas);
|
||||||
pixelSpinner = (Spinner) findViewById(R.id.pixelSpinner);
|
pixelSpinner = (Spinner) findViewById(R.id.pixelSpinner);
|
||||||
resizeWorkaround = (ToggleButton) findViewById( R.id.enableResizeWorkaround );
|
resizeWorkaround = (ToggleButton) findViewById( R.id.enableResizeWorkaround );
|
||||||
|
tvResPath = (TextView) findViewById( R.id.textView_path );
|
||||||
|
|
||||||
final String[] list = {
|
final String[] list = {
|
||||||
"RGBA8888",
|
"32 bit (RGBA8888)",
|
||||||
"RGBA888",
|
"24 bit (RGB888)",
|
||||||
"RGB565",
|
"16 bit (RGB565)",
|
||||||
"RGBA5551",
|
"15 bit (RGBA5551)",
|
||||||
"RGBA4444",
|
"12 bit (RGBA4444)",
|
||||||
"RGB332"
|
"8 bit (RGB332)"
|
||||||
};
|
};
|
||||||
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);
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
|
||||||
pixelSpinner.setAdapter(adapter);
|
pixelSpinner.setAdapter(adapter);
|
||||||
useVolume.setChecked(mPref.getBoolean("usevolume",true));
|
useVolume.setChecked(mPref.getBoolean("usevolume",true));
|
||||||
checkUpdates.setChecked(mPref.getBoolean("check_updates",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"));
|
cmdArgs.setText(mPref.getString("argv","-dev 3 -log"));
|
||||||
pixelSpinner.setSelection(mPref.getInt("pixelformat", 0));
|
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))
|
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 )
|
if( resPath == null )
|
||||||
return;
|
return;
|
||||||
updatePath(resultData.getStringExtra("GetPath"));
|
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);
|
resPath.setEnabled(true);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
|
@ -237,13 +241,16 @@ public class LauncherActivity extends Activity {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
ByteArrayOutputStream os = null;
|
ByteArrayOutputStream os = null;
|
||||||
boolean mSilent;
|
boolean mSilent;
|
||||||
|
boolean mBeta;
|
||||||
|
|
||||||
public CheckUpdate( boolean silent )
|
public CheckUpdate( boolean silent, boolean beta )
|
||||||
{
|
{
|
||||||
mSilent = silent;
|
mSilent = silent;
|
||||||
|
mBeta = beta;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String doInBackground(String... urls) {
|
protected String doInBackground(String... urls)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
URL url = new URL(urls[0]);
|
URL url = new URL(urls[0]);
|
||||||
|
@ -268,6 +275,7 @@ public class LauncherActivity extends Activity {
|
||||||
|
|
||||||
protected void onPostExecute(String result)
|
protected void onPostExecute(String result)
|
||||||
{
|
{
|
||||||
|
JSONArray releases = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (is != null)
|
if (is != null)
|
||||||
|
@ -280,12 +288,12 @@ public class LauncherActivity extends Activity {
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
JSONObject obj = new JSONObject(os.toString());
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (os != null)
|
if (os != null)
|
||||||
{
|
{
|
||||||
|
releases = new JSONArray(os.toString());
|
||||||
os.close();
|
os.close();
|
||||||
os = null;
|
os = null;
|
||||||
}
|
}
|
||||||
|
@ -293,36 +301,51 @@ public class LauncherActivity extends Activity {
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
final String version = obj.getString("tag_name");
|
|
||||||
final String url = obj.getString("html_url");
|
if( releases == null )
|
||||||
final String name = obj.getString("name");
|
return;
|
||||||
|
|
||||||
Log.d("Xash", "Found: " + version +
|
for( JSONObject obj: releases )
|
||||||
", 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);
|
final String version, url, name;
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext());
|
final bool beta = obj.getBoolean("prerelease");
|
||||||
builder.setMessage(dialog_message)
|
|
||||||
.setPositiveButton(R.string.update, new DialogInterface.OnClickListener()
|
if( beta && !mBeta )
|
||||||
{
|
continue;
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url));
|
version = obj.getString("tag_name");
|
||||||
startActivity(intent);
|
url = obj.getString("html_url");
|
||||||
}
|
name = obj.getString("name");
|
||||||
})
|
Log.d("Xash", "Found: " + version +
|
||||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
|
", I: " + getString(R.string.version_string));
|
||||||
{
|
|
||||||
public void onClick(DialogInterface dialog, int which){}
|
// this is an update
|
||||||
});
|
if( getString(R.string.version_string).compareTo(version) < 0 )
|
||||||
builder.create().show();
|
{
|
||||||
}
|
String dialog_message String.format(getString(R.string.update_message), name);
|
||||||
else if( !mSilent )
|
AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext());
|
||||||
{
|
builder.setMessage(dialog_message)
|
||||||
Toast.makeText(getBaseContext(), R.string.no_updates, Toast.LENGTH_SHORT).show();
|
.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