Skip to content

Commit 7ea68fd

Browse files
committed
created example app
1 parent 812ea02 commit 7ea68fd

40 files changed

+3129
-29
lines changed

.idea/compiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BluetoothCommunicatorLibrary/src/main/AndroidManifest.xml

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2+
<!--
3+
* Copyright 2016 Luca Martino.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copyFile of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*-->
17+
118
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
219
package="com.bluetooth.communicatorlibrary">
320

BluetoothCommunicatorLibrary/src/main/java/com/bluetooth/communicatorlibrary/BluetoothCommunicator.java

+4
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,10 @@ public int setName(String name) {
715715
}
716716
}
717717

718+
public String getUniqueName() {
719+
return uniqueName;
720+
}
721+
718722
public ArrayList<Peer> getConnectedPeersList() {
719723
ArrayList<Peer> connectedPeers = new ArrayList<>();
720724
if (connectionServer != null && connectionClient != null) {

app/build.gradle

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
apply plugin: 'com.android.application'
22

3+
ext {
4+
supportLibraryVersion = '1.0.0'
5+
}
6+
37
android {
4-
compileSdkVersion 30
5-
buildToolsVersion "30.0.1"
8+
compileSdkVersion 28
9+
buildToolsVersion "28.0.3"
610

711
defaultConfig {
812
applicationId "com.bluetooth.communicator"
913
minSdkVersion 23
10-
targetSdkVersion 30
14+
targetSdkVersion 28
1115
versionCode 1
1216
versionName "1.0"
1317

@@ -26,6 +30,13 @@ dependencies {
2630
implementation fileTree(dir: "libs", include: ["*.jar"])
2731
implementation 'androidx.appcompat:appcompat:1.2.0'
2832
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
33+
// Support libraries
34+
implementation "com.google.android.material:material:1.0.0"
35+
implementation "androidx.cardview:cardview:1.0.0"
36+
implementation "androidx.recyclerview:recyclerview:1.0.0"
37+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
38+
implementation project(path: ':BluetoothCommunicatorLibrary')
39+
// Tests
2940
testImplementation 'junit:junit:4.12'
3041
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
3142
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

app/src/main/AndroidManifest.xml

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
* Copyright 2016 Luca Martino.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copyFile of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*-->
17+
18+
219
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
320
package="com.bluetooth.communicator">
421

22+
<uses-permission android:name="android.permission.BLUETOOTH" />
23+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
24+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
25+
526
<application
27+
android:name="com.bluetooth.communicator.Global"
628
android:allowBackup="true"
729
android:icon="@mipmap/ic_launcher"
830
android:label="@string/app_name"
931
android:roundIcon="@mipmap/ic_launcher_round"
1032
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
12-
<activity android:name=".MainActivity">
33+
android:largeHeap="true"
34+
android:theme="@style/Theme.Speech">
35+
<activity android:name=".MainActivity"
36+
android:configChanges="orientation|screenSize">
37+
1338
<intent-filter>
1439
<action android:name="android.intent.action.MAIN" />
15-
1640
<category android:name="android.intent.category.LAUNCHER" />
1741
</intent-filter>
1842
</activity>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2016 Luca Martino.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copyFile of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bluetooth.communicator;
18+
19+
import android.app.Application;
20+
import android.bluetooth.BluetoothAdapter;
21+
import android.os.Handler;
22+
import android.os.Looper;
23+
24+
import com.bluetooth.communicatorlibrary.BluetoothCommunicator;
25+
import com.bluetooth.communicatorlibrary.tools.BluetoothTools;
26+
27+
import java.util.ArrayList;
28+
import java.util.Random;
29+
30+
public class Global extends Application {
31+
private BluetoothCommunicator bluetoothCommunicator;
32+
33+
@Override
34+
public void onCreate() {
35+
super.onCreate();
36+
String name = android.os.Build.MODEL;
37+
//compatibily check for supported characters
38+
ArrayList<Character> supportedCharacters = BluetoothTools.getSupportedUTFCharacters(this);
39+
boolean equals = true;
40+
for (int i = 0; i < name.length() && equals; i++) {
41+
if (!supportedCharacters.contains(Character.valueOf(name.charAt(i)))) {
42+
equals = false;
43+
}
44+
}
45+
if (!equals || name.length() > 18) {
46+
name = "User " + new Random().nextInt(21);
47+
}
48+
49+
bluetoothCommunicator = new BluetoothCommunicator(this, name, BluetoothCommunicator.STRATEGY_P2P_WITH_RECONNECTION);
50+
}
51+
52+
53+
public BluetoothCommunicator getBluetoothCommunicator() {
54+
return bluetoothCommunicator;
55+
}
56+
}

0 commit comments

Comments
 (0)