From 94740acadf826ef50b291a48bf705f642d4af45e Mon Sep 17 00:00:00 2001 From: a1batross Date: Sun, 16 Oct 2016 02:06:41 +0300 Subject: [PATCH] Open Google Play Store page of Xash3D(or GitHub Releases page if GP isn't available) when engine isn't installed on the device --- android/clean | 1 + android/res/values/strings.xml | 4 + .../xash3d/cs16client/LauncherActivity.java | 82 ++++++++++++++++++- 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/android/clean b/android/clean index e572fd3..ba0f9cb 100755 --- a/android/clean +++ b/android/clean @@ -1,4 +1,5 @@ #!/bin/bash echo " ------- CLEANING ------- " + rm -rf obj/ libs/armeabi-v7a libs/armeabi libs/x86 bin/ gen/ assets/ pak/ diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index fab6153..f5c79c2 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -22,5 +22,9 @@ Advanced Normal settings Advanced settings + No engine found + To continue, you must install Xash3D engine on your device + Install + Cancel diff --git a/android/src/in/celest/xash3d/cs16client/LauncherActivity.java b/android/src/in/celest/xash3d/cs16client/LauncherActivity.java index eaeae2a..0c818ef 100644 --- a/android/src/in/celest/xash3d/cs16client/LauncherActivity.java +++ b/android/src/in/celest/xash3d/cs16client/LauncherActivity.java @@ -34,6 +34,7 @@ import android.content.Intent; import android.content.ComponentName; import android.content.pm.PackageManager; import android.content.SharedPreferences; +import android.content.DialogInterface; import android.os.Bundle; import android.util.Log; import android.view.Menu; @@ -47,12 +48,15 @@ import android.widget.TextView; import android.widget.TabHost; import android.os.Environment; import android.os.Build; +import android.net.Uri; import java.io.FileOutputStream; import java.io.File; import java.io.InputStream; import java.lang.reflect.Method; import com.google.android.gms.ads.*; +import com.google.android.gms.common.GoogleApiAvailability; +import com.google.android.gms.common.ConnectionResult; import in.celest.xash3d.cs16client.R; @@ -61,8 +65,8 @@ public class LauncherActivity extends Activity { public final static int sdk = Integer.valueOf(Build.VERSION.SDK); public final static String TAG = "LauncherActivity"; + public static Context mContext; static SharedPreferences mPref; - static EditText mCmdArgs; static EditText mBaseDir; static ToggleButton mEnableZBot; @@ -92,6 +96,8 @@ public class LauncherActivity extends Activity { setContentView(R.layout.activity_launcher); + mContext = getApplicationContext(); + // get preferences mPref = getSharedPreferences("mod", 0); @@ -167,6 +173,11 @@ public class LauncherActivity extends Activity { gamedir = "czero"; // use when czero will be done } + // TODO: + // Check is installed engine is Google Play version + // Check myself for GP version + argv = argv + " -noch"; + Intent intent = new Intent(); intent.setAction("in.celest.xash3d.START"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -175,7 +186,72 @@ public class LauncherActivity extends Activity { intent.putExtra("gamedir", gamedir ); intent.putExtra("gamelibdir", getFilesDir().getAbsolutePath().replace("/files","/lib")); intent.putExtra("pakfile", getFilesDir().getAbsolutePath() + "/extras.pak" ); - startActivity(intent); + + PackageManager pm = getPackageManager(); + if( intent.resolveActivity( pm ) != null ) + { + startActivity( intent ); + } + else + { + showXashInstallDialog( ); + } + } + + public void showXashInstallDialog( ) + { + AlertDialog.Builder builder = new AlertDialog.Builder( this ); + + builder.setTitle( R.string.xash_not_installed_title ) + .setMessage( R.string.xash_not_installed_msg ) + .setPositiveButton( R.string.install_xash, + new DialogInterface.OnClickListener() + { + @Override + public void onClick( DialogInterface dialog, int which ) + { + GoogleApiAvailability api = GoogleApiAvailability.getInstance(); + int avail = api.isGooglePlayServicesAvailable( LauncherActivity.mContext ); + + if( avail == ConnectionResult.SUCCESS ) + { + // open GP + try + { + startActivity( + new Intent( Intent.ACTION_VIEW, + Uri.parse("market://details?id=in.celest.xash3d.hl") ) ); + } + catch( android.content.ActivityNotFoundException e ) + { + startActivity( + new Intent( Intent.ACTION_VIEW, + Uri.parse("https://play.google.com/store/apps/details?id=in.celest.xash3d.hl" ) ) ); + } + } + else + { + try + { + startActivity( + new Intent( Intent.ACTION_VIEW, + Uri.parse("https://github.com/FWGS/xash3d/releases/latest") ) ); + } + catch( Exception e ) + { } + } + } + } ) + .setNegativeButton( R.string.cancel, + new DialogInterface.OnClickListener() + { + @Override + public void onClick( DialogInterface dialog, int which ) + { + dialog.cancel(); + } + } ) + .show(); } public void onTitleClick(View view) @@ -193,9 +269,7 @@ public class LauncherActivity extends Activity { mDev = true; mEnableCZero.setVisibility(View.VISIBLE); - } - } @Override