55import android .app .AlertDialog ;
66import android .app .ProgressDialog ;
77import android .content .DialogInterface ;
8- import android .content .DialogInterface . OnCancelListener ;
8+ import android .content .Intent ;
99import android .content .pm .PackageManager ;
1010import android .content .pm .PackageManager .NameNotFoundException ;
11+ import android .net .Uri ;
1112import android .os .AsyncTask ;
1213import android .os .Build ;
1314import android .os .Bundle ;
1415import android .os .Environment ;
1516import android .support .annotation .NonNull ;
1617import android .support .v4 .app .ActivityCompat ;
17- import android .text .method .LinkMovementMethod ;
18- import android .text .util .Linkify ;
1918import android .util .Log ;
20- import android .widget .TextView ;
2119
2220import org .libsdl .app .SDLActivity ;
2321
@@ -29,9 +27,7 @@ public class sdlpluginActivity extends SDLActivity {
2927 private static final String TAG = "sdlpluginActivity" ;
3028 private static final int RC_PERMISSION_WRITE_EXTERNAL_STORAGE = 2 ;
3129
32- private static final String CCTOOLS_GOOGLE_URL = "https://play.google.com/store/apps/details?id=com.duy.ccppcompiler" ;
33-
34- private static final String CCTOOLS_URL = "http://cctools.info" ;
30+ private static final String CPP_NIDE_WIKI_URL = "https://github.com/tranleduy2000/c_cpp_compiler/wiki/" ;
3531
3632 private File mSdCardAppDir ;
3733
@@ -45,8 +41,8 @@ protected void onCreate(Bundle savedInstanceState) {
4541 initUI ();
4642 } else {
4743 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
48- requestPermissions ( new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE },
49- RC_PERMISSION_WRITE_EXTERNAL_STORAGE );
44+ String [] permission = {Manifest .permission .WRITE_EXTERNAL_STORAGE };
45+ requestPermissions ( permission , RC_PERMISSION_WRITE_EXTERNAL_STORAGE );
5046 } else {
5147 initUI ();
5248 }
@@ -73,60 +69,72 @@ private void initUI() {
7369 if (mSdCardAppDir .exists () && mSdCardAppDir .isDirectory ()) {
7470 File include = new File (mSdCardAppDir , "/SDL/include" );
7571 File lib = new File (mSdCardAppDir , "/SDL/lib" );
76- if (!include .exists () || !lib .exists () || true ) {
72+ if (!include .exists () || !lib .exists ()) {
7773 new InstallDevFilesTask ().execute ();
7874 } else {
79- aboutDialog ( 1 );
75+ showAboutDialog ( );
8076 }
8177 } else {
82- aboutDialog ( 0 );
78+ showAboutDialog ( );
8379 }
8480 }
8581 }
8682
87- private void aboutDialog ( int type ) {
83+ private void showAboutDialog ( ) {
8884 String versionName ;
8985 try {
9086 versionName = getPackageManager ().getPackageInfo (getPackageName (), 0 ).versionName ;
9187 } catch (NameNotFoundException e ) {
9288 versionName = "1.0" ;
9389 }
94- final TextView textView = new TextView (this );
95- textView .setAutoLinkMask (Linkify .WEB_URLS );
96- textView .setLinksClickable (true );
97- if (type == 0 ) {
98- String text = getString (R .string .about_dialog_text ) +
99- " " +
100- versionName +
101- "\n " +
102- getString (R .string .about_dialog_text1 ) +
103- "\n " + CCTOOLS_GOOGLE_URL + "\n " +
104- getString (R .string .about_dialog_text2 );
105- textView .setText (text );
106- } else {
107- String text = getString (R .string .about_dialog_text ) +
108- " " + versionName + "\n " +
109- getString (R .string .sdl_version ) + " " + Utils .getSDLVersion (Utils .Lib_SDL ) + "\n " +
110- getString (R .string .sdl_image_version ) + " " + Utils .getSDLVersion (Utils .Lib_SDL_image ) + "\n " +
111- getString (R .string .sdl_mixer_version ) + " " + Utils .getSDLVersion (Utils .Lib_SDL_mixer ) + "\n " +
112- getString (R .string .sdl_net_version ) + " " + Utils .getSDLVersion (Utils .Lib_SDL_net ) + "\n " +
113- getString (R .string .sdl_ttf_version ) + " " + Utils .getSDLVersion (Utils .Lib_SDL_ttf ) + "\n \n " +
114- getString (R .string .about_dialog_text3 ) + "\n " +
115- CCTOOLS_URL + "\n " ;
116- textView .setText (text
117- );
118- }
119- textView .setMovementMethod (LinkMovementMethod .getInstance ());
120- new AlertDialog .Builder (this )
90+ String message = getString (R .string .about_dialog_text ) +
91+ " " + versionName + "\n " +
92+ getString (R .string .sdl_version ) + " " + Utils .getSDLVersion (Utils .Lib_SDL ) + "\n " +
93+ getString (R .string .sdl_image_version ) + " " + Utils .getSDLVersion (Utils .Lib_SDL_image ) + "\n " +
94+ getString (R .string .sdl_mixer_version ) + " " + Utils .getSDLVersion (Utils .Lib_SDL_mixer ) + "\n " +
95+ getString (R .string .sdl_net_version ) + " " + Utils .getSDLVersion (Utils .Lib_SDL_net ) + "\n " +
96+ getString (R .string .sdl_ttf_version ) + " " + Utils .getSDLVersion (Utils .Lib_SDL_ttf ) + "\n \n " +
97+ getString (R .string .about_dialog_text3 ) + "\n " +
98+ CPP_NIDE_WIKI_URL + "\n " ;
99+
100+ AlertDialog .Builder builder = new AlertDialog .Builder (this )
121101 .setTitle (getString (R .string .about_dialog ))
122- .setView ( textView )
123- .setOnCancelListener ( new OnCancelListener () {
102+ .setMessage ( message )
103+ .setNegativeButton ( R . string . exit , new DialogInterface . OnClickListener () {
124104 @ Override
125- public void onCancel (DialogInterface dialog ) {
126- System .exit (RESULT_OK );
105+ public void onClick (DialogInterface dialog , int which ) {
106+ dialog .cancel ();
107+ finish ();
127108 }
128- })
129- .show ();
109+ });
110+ if (!isAppInstalled ("com.duy.c.cpp.compiler" )) {
111+ builder .setPositiveButton (R .string .install_cpp_nide , new DialogInterface .OnClickListener () {
112+ @ Override
113+ public void onClick (DialogInterface dialog , int which ) {
114+ dialog .cancel ();
115+ gotoPlayStore ("com.duy.c.cpp.compiler" );
116+ finish ();
117+ }
118+ });
119+ }
120+ builder .create ().show ();
121+ }
122+
123+ private void gotoPlayStore (String packageName ) {
124+ try {
125+ startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse ("market://details?id=" + packageName )));
126+ } catch (android .content .ActivityNotFoundException anfe ) {
127+ startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse ("https://play.google.com/store/apps/details?id=" + packageName )));
128+ }
129+ }
130+
131+ public boolean isAppInstalled (String packageName ) {
132+ try {
133+ getPackageManager ().getApplicationInfo (packageName , 0 );
134+ return true ;
135+ } catch (PackageManager .NameNotFoundException e ) {
136+ return false ;
137+ }
130138 }
131139
132140 @ Override
@@ -157,11 +165,13 @@ protected void onProgressUpdate(String... values) {
157165 protected Void doInBackground (Void ... params ) {
158166 try {
159167 File sdlDir = new File (mSdCardAppDir , "SDL" );
160- File libDir = new File (sdlDir , "/SDL/ lib" );
168+ File libDir = new File (sdlDir , "lib" );
161169 libDir .mkdirs ();
162- Utils .copyDirectory (new File (getCacheDir ().getParentFile ().getAbsolutePath () + "/lib" ), libDir );
170+ Utils .copyDirectory (new File (getCacheDir ().getParentFile ().getAbsolutePath (), "lib" ), libDir );
171+
163172 new File (libDir , "libmain.so" ).delete ();
164173 new File (libDir , "libccsdlplugin.so" ).delete ();
174+
165175 String arch = Build .CPU_ABI ;
166176 if (arch .startsWith ("mips" )) {
167177 arch = "mips" ;
@@ -191,7 +201,7 @@ protected Void doInBackground(Void... params) {
191201 protected void onPostExecute (Void result ) {
192202 super .onPostExecute (result );
193203 mProgressDialog .dismiss ();
194- aboutDialog ( 1 );
204+ showAboutDialog ( );
195205 }
196206 }
197207}
0 commit comments