Skip to content

Commit ccd77bb

Browse files
committed
ASAP Service creates engines based on creation intent - allows app developer to set up new asap apps by using a constructor instead of creating a folder under root asap folder
1 parent 6bf0bca commit ccd77bb

File tree

8 files changed

+43
-15
lines changed

8 files changed

+43
-15
lines changed

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ https://developer.android.com/studio/projects/android-library
33
*/
44

55
// choose one line either for an app or a lib
6-
apply plugin: 'com.android.application'
7-
//apply plugin: 'com.android.library'
6+
//apply plugin: 'com.android.application'
7+
apply plugin: 'com.android.library'
88

99
android {
1010
compileSdkVersion 28
1111
defaultConfig {
1212
// we produce a library by commenting out that line:
13-
applicationId "net.sharksystem.asap.example"
13+
// applicationId "net.sharksystem.asap.example"
1414
minSdkVersion 23
1515
targetSdkVersion 28
1616
versionCode 1

app/libs/ASAP_Engine_0.5.0.jar

6.01 KB
Binary file not shown.

app/src/main/java/net/sharksystem/asap/android/ASAP.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ public class ASAP {
2525
public static final String ONLINE_EXCHANGE = "ASAP_ONLINE_EXCHANGE";
2626
public static final boolean ONLINE_EXCHANGE_DEFAULT = true;
2727
public static final String MAX_EXECUTION_TIME = "ASAP_MAX_EXECUTION_TIME";
28+
public static final String SUPPORTED_FORMATS = "ASAP_SUPPORTED_FORMATS";
2829
}

app/src/main/java/net/sharksystem/asap/android/ASAPServiceCreationIntent.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88
import net.sharksystem.asap.MultiASAPEngineFS;
99
import net.sharksystem.asap.android.service.ASAPService;
1010

11-
public class ASAPServiceCreationIntent extends Intent {
11+
import java.util.ArrayList;
12+
import java.util.Collection;
1213

14+
public class ASAPServiceCreationIntent extends Intent {
1315
private final CharSequence owner;
1416
private final CharSequence rootFolder;
1517
private final boolean onlineExchange;
1618
private final long maxExecutionTime;
19+
private ArrayList<CharSequence> supportFormatsList;
1720

1821
public ASAPServiceCreationIntent(Activity activity, CharSequence owner, CharSequence rootFolder,
19-
boolean onlineExchange)
22+
boolean onlineExchange,
23+
Collection<CharSequence> supportedFormats)
2024
throws ASAPException {
2125

22-
this(activity, owner, rootFolder, onlineExchange,
26+
this(activity, owner, rootFolder, onlineExchange, supportedFormats,
2327
MultiASAPEngineFS.DEFAULT_MAX_PROCESSING_TIME);
2428
}
2529

2630
public ASAPServiceCreationIntent(Activity activity, CharSequence owner, CharSequence rootFolder,
27-
boolean onlineExchange, long maxExecutionTime)
31+
boolean onlineExchange, Collection<CharSequence> supportedFormats, long maxExecutionTime)
2832
throws ASAPException {
2933

3034
super(activity, ASAPService.class);
@@ -37,10 +41,18 @@ public ASAPServiceCreationIntent(Activity activity, CharSequence owner, CharSequ
3741
this.putExtra(ASAP.ONLINE_EXCHANGE, onlineExchange);
3842
this.putExtra(ASAP.MAX_EXECUTION_TIME, maxExecutionTime);
3943

44+
ArrayList<CharSequence> supportFormatsList = new ArrayList<>();
45+
for(CharSequence supportedFormat : supportedFormats) {
46+
supportFormatsList.add(supportedFormat);
47+
}
48+
this.putCharSequenceArrayListExtra(ASAP.SUPPORTED_FORMATS, supportFormatsList);
49+
50+
4051
this.owner = owner;
4152
this.rootFolder = rootFolder;
4253
this.onlineExchange = onlineExchange;
4354
this.maxExecutionTime = maxExecutionTime;
55+
this.supportFormatsList = supportFormatsList;
4456
}
4557

4658
public ASAPServiceCreationIntent(Intent intent) {
@@ -53,7 +65,7 @@ public ASAPServiceCreationIntent(Intent intent) {
5365
ASAP.ONLINE_EXCHANGE_DEFAULT);
5466
this.maxExecutionTime = intent.getLongExtra(ASAP.MAX_EXECUTION_TIME,
5567
MultiASAPEngineFS.DEFAULT_MAX_PROCESSING_TIME);
56-
68+
this.supportFormatsList = intent.getCharSequenceArrayListExtra(ASAP.SUPPORTED_FORMATS);
5769
}
5870

5971
public CharSequence getOwner() {
@@ -72,6 +84,10 @@ public long getMaxExecutionTime() {
7284
return this.maxExecutionTime;
7385
}
7486

87+
public ArrayList getSupportedFormats() {
88+
return this.supportFormatsList;
89+
}
90+
7591
public String toString() {
7692
StringBuilder sb = new StringBuilder();
7793

@@ -83,8 +99,9 @@ public String toString() {
8399
sb.append(this.onlineExchange);
84100
sb.append(" | maxExecutionTime: ");
85101
sb.append(this.maxExecutionTime);
102+
sb.append(" | supportedFormats: ");
103+
sb.append(this.supportFormatsList);
86104

87105
return sb.toString();
88106
}
89-
90107
}

app/src/main/java/net/sharksystem/asap/android/apps/ASAPApplication.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ protected ASAPApplication() {
7676
ASAP.ONLINE_EXCHANGE_DEFAULT);
7777
}
7878

79-
protected ASAPApplication(Collection<CharSequence> supportedFormats,
79+
private ASAPApplication(Collection<CharSequence> supportedFormats,
8080
CharSequence asapOwner,
8181
CharSequence rootFolder,
8282
boolean onlineExchange) {
83+
8384
this.supportedFormats = supportedFormats;
8485
this.asapOwner = asapOwner;
8586
this.rootFolder = rootFolder;
@@ -115,7 +116,7 @@ private void initialize() {
115116

116117
try {
117118
Intent asapServiceCreationIntent = new ASAPServiceCreationIntent(activity,
118-
this.asapOwner, this.rootFolder, this.onlineExchange);
119+
this.asapOwner, this.rootFolder, this.onlineExchange, this.supportedFormats);
119120

120121
Log.d(this.getLogStart(), "start service with intent: "
121122
+ asapServiceCreationIntent.toString());

app/src/main/java/net/sharksystem/asap/android/service/ASAPMessageHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import java.util.ArrayList;
1919
import java.util.List;
2020

21+
/**
22+
* Class handles messages on service side.
23+
*/
2124
class ASAPMessageHandler extends Handler {
2225
private static final String LOGSTART = "ASAPMessageHandler";
2326
private ASAPService asapService;

app/src/main/java/net/sharksystem/asap/android/service/ASAPService.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.File;
3030
import java.io.IOException;
3131
import java.util.ArrayList;
32+
import java.util.Collection;
3233
import java.util.List;
3334

3435
/**
@@ -49,6 +50,7 @@ public class ASAPService extends Service implements ASAPChunkReceivedListener,
4950
private CharSequence rootFolder;
5051
private boolean onlineExchange;
5152
private long maxExecutionTime;
53+
private ArrayList<CharSequence> supportedFormats;
5254

5355
String getASAPRootFolderName() {
5456
return this.asapEngineRootFolderName;
@@ -77,12 +79,15 @@ public MultiASAPEngineFS getMultiASAPEngine() {
7779
File rootFolder = new File(this.asapEngineRootFolderName);
7880
try {
7981
if (!rootFolder.exists()) {
80-
Log.d(LOGSTART,"createFolder");
82+
Log.d(LOGSTART,"root folder does not exist - create");
8183
rootFolder.mkdirs();
82-
Log.d(LOGSTART,"createdFolder");
84+
Log.d(LOGSTART,"done creating root folder");
8385
}
86+
8487
this.asapMultiEngine = MultiASAPEngineFS_Impl.createMultiEngine(
85-
this.owner, this.asapEngineRootFolderName, this.maxExecutionTime, this);
88+
this.owner, this.asapEngineRootFolderName,
89+
this.maxExecutionTime, this.supportedFormats, this);
90+
8691
Log.d(LOGSTART,"engine created");
8792

8893
this.asapMultiEngine.addOnlinePeersChangedListener(this);
@@ -135,6 +140,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
135140
this.rootFolder = asapServiceCreationIntent.getRootFolder();
136141
this.onlineExchange = asapServiceCreationIntent.isOnlineExchange();
137142
this.maxExecutionTime = asapServiceCreationIntent.getMaxExecutionTime();
143+
this.supportedFormats = asapServiceCreationIntent.getSupportedFormats();
138144
}
139145

140146
// get root directory

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.5.2'
10+
classpath 'com.android.tools.build:gradle:3.5.3'
1111

1212

1313
// NOTE: Do not place your application dependencies here; they belong

0 commit comments

Comments
 (0)