Skip to content

Commit 77c8124

Browse files
committed
Run sdl activity menu
1 parent 8a03151 commit 77c8124

File tree

20 files changed

+240
-257
lines changed

20 files changed

+240
-257
lines changed

app/src/main/java/com/duy/ccppcompiler/compiler/compilers/GCCCompiler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
import com.duy.ccppcompiler.compiler.ICompileSetting;
2323
import com.duy.ccppcompiler.compiler.shell.CommandBuilder;
2424
import com.duy.ccppcompiler.compiler.shell.CommandResult;
25-
import com.duy.ccppcompiler.compiler.shell.CompileResult;
26-
import com.duy.ccppcompiler.compiler.shell.NativeActivityCompileResult;
25+
import com.duy.ccppcompiler.compiler.result.CompileResult;
26+
import com.duy.ccppcompiler.compiler.result.NativeActivityCompileResult;
27+
import com.duy.ccppcompiler.compiler.result.SDLCompileResult;
2728
import com.duy.ccppcompiler.packagemanager.Environment;
2829
import com.duy.common.DLog;
2930

@@ -58,6 +59,8 @@ public CompileResult compile(File[] sourceFiles) {
5859
CompileResult result;
5960
if (mBuildNativeActivity) {
6061
result = new NativeActivityCompileResult(shellResult);
62+
} else if (mBuildSDL) {
63+
result = new SDLCompileResult(shellResult);
6164
} else {
6265
result = new CompileResult(shellResult);
6366
}
@@ -96,7 +99,7 @@ protected String buildArgs(File[] sourceFiles) {
9699
return args.build();
97100
}
98101

99-
private ArrayList<String> buildSDLActivityFlags(File[] sourceFiles) {
102+
protected ArrayList<String> buildSDLActivityFlags(File[] sourceFiles) {
100103
File source = sourceFiles[0];
101104
String nameNoExt = source.getName().substring(0, source.getName().lastIndexOf("."));
102105

@@ -113,9 +116,6 @@ private ArrayList<String> buildSDLActivityFlags(File[] sourceFiles) {
113116
.addFlags("-shared")
114117
.addFlags(new File(Environment.getSdCardHomeDir(), "SDL/lib/SDL_android_main.o").getAbsolutePath())
115118
.addFlags("-I" + new File(Environment.getSdCardHomeDir(), "SDL/lib").getAbsolutePath())
116-
.addFlags("-lSDL2")
117-
.addFlags("-llog")
118-
.addFlags("-lm")
119119
.addFlags("-o", mOutFile.getAbsolutePath());
120120

121121
return flags.toList();

app/src/main/java/com/duy/ccppcompiler/compiler/compilers/GPlusPlusCompiler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import com.duy.ccppcompiler.compiler.ICompileSetting;
2222
import com.duy.ccppcompiler.compiler.shell.CommandBuilder;
23-
import com.duy.ccppcompiler.compiler.shell.CompileResult;
23+
import com.duy.ccppcompiler.compiler.result.CompileResult;
2424

2525
import java.io.File;
2626

@@ -52,11 +52,11 @@ protected String buildArgs(File[] sourceFiles) {
5252
args.addFlags(sourceFile.getAbsolutePath());
5353
}
5454
if (mBuildNativeActivity) {
55-
args.addFlags(super.buildNativeActivityFlags(sourceFiles));
55+
args.addFlags(buildNativeActivityFlags(sourceFiles));
5656
} else if (mBuildSDL) {
57-
args.addFlags(super.buildNativeActivityFlags(sourceFiles));
57+
args.addFlags(buildSDLActivityFlags(sourceFiles));
5858
} else {
59-
args.addFlags(super.buildExecutableFlags(sourceFiles));
59+
args.addFlags(buildExecutableFlags(sourceFiles));
6060
}
6161

6262
if (mSetting != null) {

app/src/main/java/com/duy/ccppcompiler/compiler/manager/CompileManager.java

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717

1818
package com.duy.ccppcompiler.compiler.manager;
1919

20+
import android.app.NativeActivity;
2021
import android.content.Intent;
2122

23+
import com.duy.ccppcompiler.compiler.result.CompileResult;
24+
import com.duy.ccppcompiler.compiler.result.NativeActivityCompileResult;
25+
import com.duy.ccppcompiler.compiler.result.SDLCompileResult;
2226
import com.duy.ccppcompiler.compiler.shell.CommandResult;
23-
import com.duy.ccppcompiler.compiler.shell.CompileResult;
2427
import com.duy.ccppcompiler.console.TermActivity;
2528
import com.duy.ccppcompiler.packagemanager.Environment;
2629
import com.duy.editor.CodeEditorActivity;
30+
import com.jecelyin.common.utils.UIUtils;
2731
import com.pdaxrom.cctools.BuildConstants;
2832
import com.pdaxrom.utils.Utils;
2933

@@ -47,26 +51,60 @@ public CompileManager(CodeEditorActivity activity) {
4751
@Override
4852
public void onCompileSuccess(CommandResult result) {
4953
super.onCompileSuccess(result);
54+
if (!(result instanceof CompileResult)) {
55+
return;
56+
}
5057

51-
if (result instanceof CompileResult) {
58+
if (result instanceof SDLCompileResult) {
5259
File binaryFile = ((CompileResult) result).getBinaryFile();
53-
if (binaryFile == null){
60+
if (binaryFile == null) {
5461
return;
5562
}
63+
64+
Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage("com.duy.c.cpp.compiler.sdlplugin");
65+
if (intent != null) {
66+
intent.putExtra("sdlmain", binaryFile.getAbsolutePath());
67+
getActivity().startActivity(intent);//null pointer check in case package name was not found
68+
} else {
69+
UIUtils.alert(getActivity(), "Can not run SDL application");
70+
}
71+
return;
72+
}
73+
74+
if (result instanceof NativeActivityCompileResult) {
5675
File internalBinary;
5776
try {
58-
internalBinary = copyToTmpExeDirAndSetExecutable(binaryFile);
77+
NativeActivityCompileResult compileResult = (NativeActivityCompileResult) result;
78+
internalBinary = copyToTmpExeDirAndSetExecutable(compileResult.getBinaryFile());
5979
} catch (IOException e) {
6080
handleInternalException(e);
61-
e.printStackTrace();
6281
return;
6382
}
6483

65-
Intent intent = new Intent(getActivity(), TermActivity.class);
66-
intent.putExtra(BuildConstants.EXTRA_FILE_NAME, internalBinary.getAbsolutePath());
67-
intent.putExtra(BuildConstants.EXTRA_WORK_DIR, internalBinary.getParent());
84+
//now run binary file
85+
Intent intent = new Intent(getActivity(), NativeActivity.class);
86+
//from jni: main.cpp
87+
intent.putExtra("nativeApp", internalBinary.getAbsolutePath());
6888
getActivity().startActivity(intent);
89+
return;
6990
}
91+
92+
File binaryFile = ((CompileResult) result).getBinaryFile();
93+
if (binaryFile == null) {
94+
return;
95+
}
96+
File internalBinary;
97+
try {
98+
internalBinary = copyToTmpExeDirAndSetExecutable(binaryFile);
99+
} catch (IOException e) {
100+
handleInternalException(e);
101+
return;
102+
}
103+
104+
Intent intent = new Intent(getActivity(), TermActivity.class);
105+
intent.putExtra(BuildConstants.EXTRA_FILE_NAME, internalBinary.getAbsolutePath());
106+
intent.putExtra(BuildConstants.EXTRA_WORK_DIR, internalBinary.getParent());
107+
getActivity().startActivity(intent);
70108
}
71109

72110
protected File copyToTmpExeDirAndSetExecutable(File binFile) throws IOException {

app/src/main/java/com/duy/ccppcompiler/compiler/manager/CompileManagerImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.duy.ccppcompiler.compiler.manager;
1919

2020
import android.app.ProgressDialog;
21+
import android.support.annotation.CallSuper;
2122
import android.support.annotation.MainThread;
2223
import android.support.annotation.NonNull;
2324
import android.support.annotation.Nullable;
@@ -98,6 +99,7 @@ public void onCompileFailed(CommandResult compileResult) {
9899
if (DLog.DEBUG) DLog.w(TAG, "onCompileFailed: \n" + compileResult.getMessage());
99100
}
100101

102+
@CallSuper
101103
@Override
102104
public void onCompileSuccess(CommandResult commandResult) {
103105
if (DLog.DEBUG) DLog.d(TAG, "onCompileSuccess() commandResult = [" + commandResult + "]");

app/src/main/java/com/duy/ccppcompiler/compiler/manager/NativeActivityCompileManager.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

app/src/main/java/com/duy/ccppcompiler/compiler/manager/SDLCompileManager.java

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) 2018 Duy Tran Le
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.duy.ccppcompiler.compiler.result;
19+
20+
import android.support.annotation.Nullable;
21+
22+
import com.duy.ccppcompiler.compiler.shell.CommandResult;
23+
24+
import java.io.File;
25+
26+
/**
27+
* Created by Duy on 18-May-18.
28+
*/
29+
30+
public class CompileResult extends CommandResult {
31+
@Nullable
32+
private File binaryFile;
33+
34+
public CompileResult(CommandResult commandResult) {
35+
super(commandResult);
36+
}
37+
38+
@Nullable
39+
public File getBinaryFile() {
40+
return binaryFile;
41+
}
42+
43+
public void setBinaryFile(@Nullable File binaryFile) {
44+
this.binaryFile = binaryFile;
45+
}
46+
47+
@Override
48+
public String toString() {
49+
return "CompileResult{" +
50+
"binaryFile=" + binaryFile +
51+
"} " + super.toString();
52+
}
53+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2018 Duy Tran Le
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.duy.ccppcompiler.compiler.result;
19+
20+
import android.support.annotation.Nullable;
21+
22+
import com.duy.ccppcompiler.compiler.shell.CommandResult;
23+
24+
import java.io.File;
25+
26+
/**
27+
* Compile result when build native activity
28+
*/
29+
public class NativeActivityCompileResult extends CompileResult {
30+
@Nullable
31+
private File binaryFile;
32+
33+
public NativeActivityCompileResult(CommandResult commandResult) {
34+
super(commandResult);
35+
}
36+
37+
@Nullable
38+
public File getBinaryFile() {
39+
return binaryFile;
40+
}
41+
42+
public void setBinaryFile(@Nullable File binaryFile) {
43+
this.binaryFile = binaryFile;
44+
}
45+
46+
@Override
47+
public String toString() {
48+
return "CompileResult{" +
49+
"binaryFile=" + binaryFile +
50+
"} " + super.toString();
51+
}
52+
}

0 commit comments

Comments
 (0)