From 03105e096da4eaa3e9590e09030f0d3add8885e1 Mon Sep 17 00:00:00 2001 From: mittorn Date: Sat, 12 May 2018 02:56:17 +0700 Subject: [PATCH] Code clean, improve resolution selection --- jni/src/NanoGL/nanogl | 2 +- jni/src/Xash3D/xash3d | 2 +- jni/src/hlsdk-xash3d | 2 +- src/in/celest/xash3d/LauncherActivity.java | 233 +++------------------ src/su/xash/fwgslib/CheckUpdate.java | 142 +++++++++++++ 5 files changed, 172 insertions(+), 209 deletions(-) create mode 100644 src/su/xash/fwgslib/CheckUpdate.java diff --git a/jni/src/NanoGL/nanogl b/jni/src/NanoGL/nanogl index 5bdf537d..7895c4fa 160000 --- a/jni/src/NanoGL/nanogl +++ b/jni/src/NanoGL/nanogl @@ -1 +1 @@ -Subproject commit 5bdf537d06bac340e861338af9c3fea99d3724cf +Subproject commit 7895c4fac080f1805668d6b3583ca3a0f7faa6d6 diff --git a/jni/src/Xash3D/xash3d b/jni/src/Xash3D/xash3d index f9f501eb..44cfcf8a 160000 --- a/jni/src/Xash3D/xash3d +++ b/jni/src/Xash3D/xash3d @@ -1 +1 @@ -Subproject commit f9f501eb0914645a4f68623f48dd92ad5d91de15 +Subproject commit 44cfcf8a62735c2d5312a1bcc1c4c633dddba1ed diff --git a/jni/src/hlsdk-xash3d b/jni/src/hlsdk-xash3d index d17387c6..2aab84f6 160000 --- a/jni/src/hlsdk-xash3d +++ b/jni/src/hlsdk-xash3d @@ -1 +1 @@ -Subproject commit d17387c61ffe0a81b2ae6c6737bc7f08d7040ab3 +Subproject commit 2aab84f6432b78246d146348a5a4a29a6ad5decc diff --git a/src/in/celest/xash3d/LauncherActivity.java b/src/in/celest/xash3d/LauncherActivity.java index 6bc92f1e..5467309f 100644 --- a/src/in/celest/xash3d/LauncherActivity.java +++ b/src/in/celest/xash3d/LauncherActivity.java @@ -183,7 +183,7 @@ public class LauncherActivity extends Activity resHeight.setText(String.valueOf(mPref.getInt("resolution_height", mEngineHeight ))); resScale.setText(String.valueOf(mPref.getFloat("resolution_scale", 2.0f))); - resWidth.addTextChangedListener( resTextChangeWatcher ); + resWidth.addTextChangedListener( resWidthTextChangeWatcher ); resHeight.addTextChangedListener( resTextChangeWatcher ); resScale.addTextChangedListener( resTextChangeWatcher ); @@ -256,7 +256,7 @@ public class LauncherActivity extends Activity // disable autoupdater for Google Play if( !XashConfig.GP_VERSION && mPref.getBoolean("check_updates", true)) { - new CheckUpdate(true, false).execute(UPDATE_LINK); + new CheckUpdate(getBaseContext(),true, false).execute(UPDATE_LINK); } FWGSLib.changeButtonsStyle((ViewGroup)tabHost.getParent()); hideResolutionSettings( !resolution.isChecked() ); @@ -295,7 +295,7 @@ public class LauncherActivity extends Activity rodirSettings.setVisibility( hide ? View.GONE : View.VISIBLE ); } - TextWatcher resTextChangeWatcher = new TextWatcher() + TextWatcher resWidthTextChangeWatcher = new TextWatcher() { @Override public void afterTextChanged(Editable s){} @@ -303,6 +303,23 @@ public class LauncherActivity extends Activity @Override public void beforeTextChanged(CharSequence s, int start, int count, int after){} + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) + { + int h = (int)((float)mEngineHeight / mEngineWidth * getCustomEngineWidth()); + resHeight.setText(String.valueOf(h)); + updateResolutionResult(); + } + }; + + TextWatcher resTextChangeWatcher = new TextWatcher() + { + @Override + public void afterTextChanged(Editable s){} + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after){} + @Override public void onTextChanged(CharSequence s, int start, int before, int count) { @@ -317,6 +334,13 @@ public class LauncherActivity extends Activity { w = getCustomEngineWidth(); h = getCustomEngineHeight(); + + // some fool-proof + if( Math.abs((float)w/(float)h - 4.0/3.0) < 0.001 ) + { + w = (int)((float)mEngineWidth / mEngineHeight * h+0.5); + resWidth.setText(String.valueOf(w)); + } } else { @@ -416,83 +440,6 @@ public class LauncherActivity extends Activity int m_iFirstRunCounter = 0; public void showFirstRun() { - /*if( m_iFirstRunCounter < 0 ) - m_iFirstRunCounter = 0; - - final int titleres = getResources().getIdentifier("page_title" + String.valueOf(m_iFirstRunCounter), "string", getPackageName()); - final int contentres = getResources().getIdentifier("page_content" + String.valueOf(m_iFirstRunCounter), "string", getPackageName()); - final Activity a = this; - if( titleres == 0 || contentres == 0 ) - return; - this.runOnUiThread(new Runnable() - { - public void run() - { - final TextView content = new TextView(LauncherActivity.this); - content.setMovementMethod(LinkMovementMethod.getInstance()); - AlertDialog.Builder builder = new AlertDialog.Builder(a) - .setTitle(titleres) - .setView(content); - DialogInterface.OnClickListener nextClick = new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface d, int p1) - { - m_iFirstRunCounter++; - showFirstRun(); - } - }; - DialogInterface.OnClickListener prevClick = new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface d, int p1) - { - m_iFirstRunCounter--; - showFirstRun(); - } - }; - - if( sdk >= 21 ) - { - builder.setPositiveButton(R.string.next, nextClick); - if( m_iFirstRunCounter > 0 ) - { - builder.setNegativeButton(R.string.prev, prevClick); - } - builder.setNeutralButton(R.string.skip, null); - } - else - { - builder.setNegativeButton(R.string.next, nextClick); - if( m_iFirstRunCounter > 0 ) - { - builder.setNeutralButton(R.string.prev, prevClick); - } - builder.setPositiveButton(R.string.skip, null); - } - builder.setCancelable(false); - final AlertDialog dialog = builder.create(); - dialog.show(); - content.setText(Html.fromHtml(getResources().getText(contentres).toString(), - new Html.ImageGetter() - { - @Override - public Drawable getDrawable(String source) - { - int dourceId = getApplicationContext().getResources().getIdentifier(source, "drawable", getPackageName()); - Drawable drawable = getApplicationContext().getResources().getDrawable(dourceId); - final int visibleWidth = dialog.getWindow().getDecorView().getWidth(); - final int picWidth = drawable.getIntrinsicWidth(); - final int picHeight = drawable.getIntrinsicHeight(); - - final int calcWidth = visibleWidth < picWidth ? visibleWidth : picWidth; - // final int calcHeight = (int)((float)picHeight * ((float)calcWidth / (float)picWidth)); - final int calcHeight = (int)((float)picHeight); - - drawable.setBounds( 0, 0, calcWidth, calcHeight); - return drawable; - } - }, null)); - } - });*/ startActivity(new Intent(this, in.celest.xash3d.XashTutorialActivity.class)); } @@ -588,130 +535,4 @@ public class LauncherActivity extends Activity return super.onOptionsItemSelected(item); } - - private class CheckUpdate extends AsyncTask { - InputStream is = null; - ByteArrayOutputStream os = null; - boolean mSilent; - boolean mBeta; - - public CheckUpdate( boolean silent, boolean beta ) - { - mSilent = silent; - mBeta = beta; - } - - 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); - } - os.flush(); - - return os.toString(); - } - catch(Exception e) - { - e.printStackTrace(); - return null; - } - } - - protected void onPostExecute(String result) - { - JSONArray releases = null; - try - { - if (is != null) - { - is.close(); - is = null; - } - } - catch(Exception e) - { - e.printStackTrace(); - } - - try - { - if (os != null) - { - releases = new JSONArray(os.toString()); - os.close(); - os = null; - } - } - catch(Exception e) - { - e.printStackTrace(); - return; - } - - if( releases == null ) - return; - - for( int i = 0; i < releases.length(); i++ ) - { - final JSONObject obj; - try - { - obj = releases.getJSONObject(i); - - final String version, url, name; - final boolean 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; - } - catch(Exception e) - { - e.printStackTrace(); - continue; - } - } - } - } } diff --git a/src/su/xash/fwgslib/CheckUpdate.java b/src/su/xash/fwgslib/CheckUpdate.java new file mode 100644 index 00000000..3b2f8586 --- /dev/null +++ b/src/su/xash/fwgslib/CheckUpdate.java @@ -0,0 +1,142 @@ +package su.xash.fwgslib; + + +import android.app.*; +import android.content.*; +import android.net.*; +import android.os.*; +import android.util.*; +import android.widget.*; +import in.celest.xash3d.hl.*; +import java.io.*; +import java.net.*; +import org.json.*; + + +public class CheckUpdate extends AsyncTask { + InputStream is = null; + ByteArrayOutputStream os = null; + boolean mSilent; + boolean mBeta; + Context mContext; + + public CheckUpdate( Context context, boolean silent, boolean beta ) + { + mSilent = silent; + mBeta = beta; + mContext = context; + } + + 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); + } + os.flush(); + + return os.toString(); + } + catch(Exception e) + { + e.printStackTrace(); + return null; + } + } + + protected void onPostExecute(String result) + { + JSONArray releases = null; + try + { + if (is != null) + { + is.close(); + is = null; + } + } + catch(Exception e) + { + e.printStackTrace(); + } + + try + { + if (os != null) + { + releases = new JSONArray(os.toString()); + os.close(); + os = null; + } + } + catch(Exception e) + { + e.printStackTrace(); + return; + } + + if( releases == null ) + return; + + for( int i = 0; i < releases.length(); i++ ) + { + final JSONObject obj; + try + { + obj = releases.getJSONObject(i); + + final String version, url, name; + final boolean 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: " + mContext.getString(R.string.version_string)); + + // this is an update + if( mContext.getString(R.string.version_string).compareTo(version) < 0 ) + { + String dialog_message = String.format(mContext.getString(R.string.update_message), name); + AlertDialog.Builder builder = new AlertDialog.Builder(mContext); + 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)); + mContext.startActivity(intent); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() + { public void onClick(DialogInterface dialog, int id) {} } ); + builder.create().show(); + } + else if( !mSilent ) + { + Toast.makeText(mContext, R.string.no_updates, Toast.LENGTH_SHORT).show(); + } + + // No need to check other releases, so we will stop here. + break; + } + catch(Exception e) + { + e.printStackTrace(); + continue; + } + } + } +}