Skip to content

Commit e1f5100

Browse files
committed
Complete sdl plugin for CPP NIDE
1 parent d1b1950 commit e1f5100

File tree

9 files changed

+81
-53
lines changed

9 files changed

+81
-53
lines changed

sdlplugin/AndroidManifest.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
43
package="com.duy.ccppcompiler.sdlplugin"
54
android:installLocation="auto">
65

76
<uses-permission android:name="android.permission.INTERNET" />
87
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
9-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
108

119
<application
1210
android:allowBackup="false"
1311
android:fullBackupContent="false"
1412
android:icon="@mipmap/ic_launcher"
1513
android:label="@string/app_name"
16-
android:theme="@style/Theme.AppCompat.Light"
17-
tools:ignore="GoogleAppIndexingWarning">
14+
android:theme="@style/Theme.AppCompat.Light">
1815

1916
<activity
2017
android:name=".sdlpluginActivity"

sdlplugin/addincludes.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ find ./build/intermediates/ndkBuild/debug/obj/local/ -name "SDL_android_main.o"
2626
arch=`echo $f | cut -f8 -d'/'`
2727
echo "Arch=${arch}"
2828
cd `dirname $f`
29+
echo "PWD=`pwd`"
2930
rm -f ${TOPDIR}/assets/sdlmain-${arch}.zip
3031
zip -9 ${TOPDIR}/assets/sdlmain-${arch}.zip SDL_android_main.o
3132
cd $TOPDIR
@@ -34,3 +35,5 @@ cd ${TOPDIR}
3435

3536
rm -rf ${TOPDIR}/assets/examples.zip
3637
zip -r9 ${TOPDIR}/assets/examples.zip Examples
38+
39+
read

sdlplugin/assets/examples.zip

0 Bytes
Binary file not shown.

sdlplugin/assets/headers.zip

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

sdlplugin/assets/sdlmain-x86.zip

0 Bytes
Binary file not shown.

sdlplugin/build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,26 @@ android {
4141
jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk
4242
}
4343
}
44+
45+
46+
signingConfigs {
47+
release {
48+
def propFile = new File(rootProject.projectDir, "signing.properties")
49+
if (propFile.exists()) {
50+
Properties props = new Properties()
51+
props.load(new FileInputStream(propFile))
52+
storeFile new File(rootProject.projectDir, props["RELEASE_STORE_FILE"])
53+
storePassword props["RELEASE_STORE_PASSWORD"]
54+
keyAlias props["RELEASE_KEY_ALIAS"]
55+
keyPassword props["RELEASE_KEY_PASSWORD"]
56+
}
57+
}
58+
}
4459
buildTypes {
4560
release {
4661
minifyEnabled true
4762
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
63+
signingConfig signingConfigs.release
4864
}
4965
debug {
5066
minifyEnabled false

sdlplugin/src/main/java/com/duy/ccppcompiler/sdlplugin/sdlpluginActivity.java

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
import android.app.AlertDialog;
66
import android.app.ProgressDialog;
77
import android.content.DialogInterface;
8-
import android.content.DialogInterface.OnCancelListener;
8+
import android.content.Intent;
99
import android.content.pm.PackageManager;
1010
import android.content.pm.PackageManager.NameNotFoundException;
11+
import android.net.Uri;
1112
import android.os.AsyncTask;
1213
import android.os.Build;
1314
import android.os.Bundle;
1415
import android.os.Environment;
1516
import android.support.annotation.NonNull;
1617
import android.support.v4.app.ActivityCompat;
17-
import android.text.method.LinkMovementMethod;
18-
import android.text.util.Linkify;
1918
import android.util.Log;
20-
import android.widget.TextView;
2119

2220
import 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
}

sdlplugin/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
<string name="sdl_mixer_version">SDL2_mixer version</string>
1616
<string name="sdl_net_version">SDL2_net version</string>
1717
<string name="sdl_ttf_version">SDL2_ttf version</string>
18+
<string name="install_cpp_nide">Install CPP NIDE</string>
19+
<string name="exit">Exit</string>
1820
</resources>

0 commit comments

Comments
 (0)