Skip to content

Commit 23d327d

Browse files
committed
This is not backward compatible and start of 0.4. line. Did some major refactoring. Code duplicates (compared to ASAPJava) are removed. ASAPPeer interface from ASAPJava can now be used in activities. Initialization became easier. This code isn't yet tested enough. A later commit will be basis for a new release.
1 parent 2318d81 commit 23d327d

17 files changed

+426
-472
lines changed

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ 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 {
10-
compileSdkVersion 28
10+
compileSdkVersion 29
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
15-
targetSdkVersion 28
15+
targetSdkVersion 29
1616
versionCode 1
1717
versionName "1.0"
1818
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<activity android:name="net.sharksystem.asap.android.example.ASAPInitialExampleActivity">
1515
<intent-filter>
1616
<action android:name="android.intent.action.MAIN" />
17-
1817
<category android:name="android.intent.category.LAUNCHER" />
1918
</intent-filter>
2019
</activity>
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package net.sharksystem.asap.android;
22

3-
import java.util.UUID;
4-
53
/**
64
* Be sure to have the ASAPEngine in one of your library directories!
75
*/
86
public class ASAPAndroid {
9-
public static final String UNKNOWN_USER = "anon";
10-
117
public static final String USER = "user";
128
public static final String FOLDER = "folder";
139
public static final String RECIPIENT = "recipient";
@@ -16,8 +12,7 @@ public class ASAPAndroid {
1612

1713
public static final int PORT_NUMBER = 7777;
1814

19-
public static final String ONLINE_EXCHANGE = "ASAP_ONLINE_EXCHANGE";
20-
public static final boolean ONLINE_EXCHANGE_DEFAULT = true;
21-
public static final String MAX_EXECUTION_TIME = "ASAP_MAX_EXECUTION_TIME";
22-
public static final String SUPPORTED_FORMATS = "ASAP_SUPPORTED_FORMATS";
15+
public static final String ONLINE_EXCHANGE_PARAMETER_NAME = "ASAP_ONLINE_EXCHANGE";
16+
public static final String MAX_EXECUTION_TIME_PARAMETER_NAME = "ASAP_MAX_EXECUTION_TIME";
17+
public static final String SUPPORTED_FORMATS_PARAMETER_NAME = "ASAP_SUPPORTED_FORMATS";
2318
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import net.sharksystem.asap.ASAPException;
88
import net.sharksystem.asap.ASAPPeer;
9+
import net.sharksystem.asap.ASAPPeerService;
910
import net.sharksystem.asap.android.service.ASAPService;
1011

1112
import java.util.ArrayList;
@@ -24,7 +25,7 @@ public ASAPServiceCreationIntent(Activity activity, CharSequence owner, CharSequ
2425
throws ASAPException {
2526

2627
this(activity, owner, rootFolder, onlineExchange, supportedFormats,
27-
ASAPPeer.DEFAULT_MAX_PROCESSING_TIME);
28+
ASAPPeerService.DEFAULT_MAX_PROCESSING_TIME);
2829
}
2930

3031
public ASAPServiceCreationIntent(Activity activity, CharSequence owner, CharSequence rootFolder,
@@ -43,15 +44,15 @@ public ASAPServiceCreationIntent(Activity activity, CharSequence owner, CharSequ
4344

4445
this.putExtra(ASAPAndroid.USER, owner);
4546
this.putExtra(ASAPAndroid.FOLDER, rootFolder);
46-
this.putExtra(ASAPAndroid.ONLINE_EXCHANGE, onlineExchange);
47-
this.putExtra(ASAPAndroid.MAX_EXECUTION_TIME, maxExecutionTime);
47+
this.putExtra(ASAPAndroid.ONLINE_EXCHANGE_PARAMETER_NAME, onlineExchange);
48+
this.putExtra(ASAPAndroid.MAX_EXECUTION_TIME_PARAMETER_NAME, maxExecutionTime);
4849

4950
if(supportedFormats != null) {
5051
this.supportFormatsList = new ArrayList<>();
5152
for (CharSequence supportedFormat : supportedFormats) {
5253
supportFormatsList.add(supportedFormat);
5354
}
54-
this.putCharSequenceArrayListExtra(ASAPAndroid.SUPPORTED_FORMATS, supportFormatsList);
55+
this.putCharSequenceArrayListExtra(ASAPAndroid.SUPPORTED_FORMATS_PARAMETER_NAME, supportFormatsList);
5556
} else {
5657
Log.d(this.getLogStart(), "no format set - FAILURE?");
5758
}
@@ -63,11 +64,11 @@ public ASAPServiceCreationIntent(Intent intent) {
6364
// just parse extras
6465
this.owner = intent.getStringExtra(ASAPAndroid.USER);
6566
this.rootFolder = intent.getStringExtra(ASAPAndroid.FOLDER);
66-
this.onlineExchange = intent.getBooleanExtra(ASAPAndroid.ONLINE_EXCHANGE,
67-
ASAPAndroid.ONLINE_EXCHANGE_DEFAULT);
68-
this.maxExecutionTime = intent.getLongExtra(ASAPAndroid.MAX_EXECUTION_TIME,
69-
ASAPPeer.DEFAULT_MAX_PROCESSING_TIME);
70-
this.supportFormatsList = intent.getCharSequenceArrayListExtra(ASAPAndroid.SUPPORTED_FORMATS);
67+
this.onlineExchange = intent.getBooleanExtra(ASAPAndroid.ONLINE_EXCHANGE_PARAMETER_NAME,
68+
ASAPPeer.ONLINE_EXCHANGE_DEFAULT);
69+
this.maxExecutionTime = intent.getLongExtra(ASAPAndroid.MAX_EXECUTION_TIME_PARAMETER_NAME,
70+
ASAPPeerService.DEFAULT_MAX_PROCESSING_TIME);
71+
this.supportFormatsList = intent.getCharSequenceArrayListExtra(ASAPAndroid.SUPPORTED_FORMATS_PARAMETER_NAME);
7172
}
7273

7374
public CharSequence getOwner() {

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

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.widget.Toast;
1818

1919
import net.sharksystem.asap.ASAPException;
20+
import net.sharksystem.asap.ASAPPeer;
2021
import net.sharksystem.asap.android.ASAPAndroid;
2122
import net.sharksystem.asap.android.ASAPServiceMessage;
2223
import net.sharksystem.asap.android.ASAPServiceMethods;
@@ -40,19 +41,30 @@ public class ASAPActivity extends AppCompatActivity implements
4041
private Messenger mService;
4142
private boolean mBound;
4243

43-
private ASAPApplication asapApplication;
44+
private ASAPAndroidPeer asapAndroidPeer;
4445

4546
/**
4647
* Create a new activity object. Make sure your application object is fully
4748
* instantiated
48-
* @param asapApplication
49+
* @param asapAndroidPeer
4950
*/
50-
public ASAPActivity(ASAPApplication asapApplication) {
51-
this.asapApplication = asapApplication;
51+
ASAPActivity(ASAPAndroidPeer asapAndroidPeer) {
52+
this.asapAndroidPeer = asapAndroidPeer;
5253
}
5354

54-
protected ASAPApplication getASAPApplication() {
55-
return this.asapApplication;
55+
/**
56+
* @throws ASAPComponentNotYetInitializedException if ASAPAndroidPeer was not initialized
57+
*/
58+
public ASAPActivity() {
59+
this(ASAPAndroidPeer.getASAPAndroidPeer());
60+
}
61+
62+
protected ASAPAndroidPeer getASAPAndroidPeer() {
63+
return this.asapAndroidPeer;
64+
}
65+
66+
protected ASAPPeer getASAPPeer() {
67+
return this.asapAndroidPeer;
5668
}
5769

5870
/**
@@ -87,7 +99,6 @@ public final void createClosedASAPChannel(CharSequence appName, CharSequence uri
8799
*/
88100
public final void sendASAPMessage(CharSequence appName, CharSequence uri,
89101
byte[] message, boolean persistent) throws ASAPException {
90-
91102
Log.d(this.getLogStart(), "ask service to send: "
92103
+ "format: " + appName
93104
+ "| uri: " + uri
@@ -311,7 +322,7 @@ private void startASAPEngineBroadcasts() {
311322
}
312323

313324
private void stopASAPEngineBroadcasts() {
314-
if(this.getASAPApplication().getNumberASAPActivities() == 1) {
325+
if(this.getASAPAndroidPeer().getNumberASAPActivities() == 1) {
315326
Log.d(this.getLogStart(), "send message to service: stop ASAP Engine Broadcasts");
316327
this.sendMessage2Service(ASAPServiceMethods.STOP_BROADCASTS);
317328
} else {
@@ -370,13 +381,13 @@ private void setupASAPChunkReceivedBroadcastReceiver() {
370381
filter.addAction(ASAPAndroid.ASAP_CHUNK_RECEIVED_ACTION);
371382

372383
// register
373-
this.registerReceiver(this.asapApplication, filter);
384+
this.registerReceiver(this.asapAndroidPeer, filter);
374385
}
375386

376387
private void shutdownASAPChunkReceivedBroadcastReceiver() {
377388
Log.d(this.getLogStart(), "shutdown asap received bc receiver");
378389
try {
379-
this.unregisterReceiver(this.asapApplication);
390+
this.unregisterReceiver(this.asapAndroidPeer);
380391
}
381392
catch(RuntimeException re) {
382393
Log.d(this.getLogStart(), "problems when unregister asap received bcr - ignore"
@@ -402,14 +413,14 @@ private void shutdownASAPChunkReceivedBroadcastReceiver() {
402413
protected void onCreate(Bundle savedInstanceState) {
403414
super.onCreate(savedInstanceState);
404415
Log.d(this.getLogStart(), "onCreate");
405-
this.asapApplication.activityCreated(this);
416+
this.asapAndroidPeer.activityCreated(this);
406417
}
407418

408419
protected void onStart() {
409420
// Bind to the service
410421
super.onStart();
411422
Log.d(this.getLogStart(), "onStart");
412-
this.asapApplication.setActivity(this);
423+
this.asapAndroidPeer.setActivity(this);
413424
this.setupASAPServiceNotificationBroadcastReceiver();
414425
this.setupASAPChunkReceivedBroadcastReceiver();
415426
this.bindServices();
@@ -420,7 +431,7 @@ protected void onStart() {
420431
protected void onResume() {
421432
super.onResume();
422433
Log.d(this.getLogStart(), "onResume");
423-
this.asapApplication.setActivity(this);
434+
this.asapAndroidPeer.setActivity(this);
424435
this.startASAPEngineBroadcasts();
425436
}
426437

@@ -448,7 +459,7 @@ protected void onDestroy() {
448459
Log.d(this.getLogStart(), "onDestroy");
449460
this.shutdownASAPServiceNotificationBroadcastReceiver();
450461
this.unbindServices();
451-
this.asapApplication.activityDestroyed(this);
462+
this.asapAndroidPeer.activityDestroyed(this);
452463

453464
// forget stored messages
454465
this.messageStorage = null;
@@ -523,7 +534,7 @@ public void onServiceDisconnected(ComponentName className) {
523534
@Override
524535
@CallSuper
525536
public void asapNotifyBTDiscoverableStarted() {
526-
this.asapApplication.setBTDiscoverable(true);
537+
this.asapAndroidPeer.notifyBTDiscoverable(true);
527538
}
528539

529540
/**
@@ -537,7 +548,7 @@ public void asapNotifyBTDiscoverableStarted() {
537548
@Override
538549
@CallSuper
539550
public void asapNotifyBTDiscoverableStopped() {
540-
this.asapApplication.setBTDiscoverable(false);
551+
this.asapAndroidPeer.notifyBTDiscoverable(false);
541552
}
542553

543554
/**
@@ -551,7 +562,7 @@ public void asapNotifyBTDiscoverableStopped() {
551562
@Override
552563
@CallSuper
553564
public void asapNotifyBTEnvironmentStarted() {
554-
this.asapApplication.setBTEnvironmentRunning(true);
565+
this.asapAndroidPeer.notifyBTEnvironmentRunning(true);
555566
}
556567

557568
/**
@@ -565,7 +576,7 @@ public void asapNotifyBTEnvironmentStarted() {
565576
@Override
566577
@CallSuper
567578
public void asapNotifyBTEnvironmentStopped() {
568-
this.asapApplication.setBTEnvironmentRunning(false);
579+
this.asapAndroidPeer.notifyBTEnvironmentRunning(false);
569580
}
570581

571582
/**
@@ -581,7 +592,7 @@ public void asapNotifyBTEnvironmentStopped() {
581592
@Override
582593
@CallSuper
583594
public void asapNotifyOnlinePeersChanged(Set<CharSequence> peerList) {
584-
this.asapApplication.setOnlinePeersList(peerList);
595+
this.asapAndroidPeer.notifyOnlinePeersChanged(peerList);
585596
}
586597

587598
/**
@@ -595,7 +606,7 @@ public void asapNotifyOnlinePeersChanged(Set<CharSequence> peerList) {
595606
@Override
596607
@CallSuper
597608
public void asapNotifyBTDiscoveryStarted() {
598-
this.asapApplication.setBTDiscovery(true);
609+
this.asapAndroidPeer.notifyBTDiscovery(true);
599610
}
600611

601612
/**
@@ -609,7 +620,7 @@ public void asapNotifyBTDiscoveryStarted() {
609620
@Override
610621
@CallSuper
611622
public void asapNotifyBTDiscoveryStopped() {
612-
this.asapApplication.setBTDiscovery(false);
623+
this.asapAndroidPeer.notifyBTDiscovery(false);
613624
}
614625

615626
////////////////////////////////////////////////////////////////////////////////
@@ -620,20 +631,20 @@ public void asapNotifyBTDiscoveryStopped() {
620631
* @return true if bluetooth environment is one.
621632
*/
622633
public boolean isBluetoothEnvironmentOn() {
623-
return this.asapApplication.getBTEnvironmentRunning();
634+
return this.asapAndroidPeer.getBTEnvironmentRunning();
624635
}
625636

626637
/**
627638
* @return true if this device is discoverable now.
628639
*/
629640
public boolean isBluetoothDiscoverable() {
630-
return this.asapApplication.getBTDiscoverable();
641+
return this.asapAndroidPeer.getBTDiscoverable();
631642
}
632643

633644
/**
634645
* @return true if this device looking for other Bluetooth devices.
635646
*/
636647
public boolean isBluetoothDiscovery() {
637-
return this.asapApplication.getBTDiscovery();
648+
return this.asapAndroidPeer.getBTDiscovery();
638649
}
639650
}

0 commit comments

Comments
 (0)