Skip to content

Commit

Permalink
feat(java): basic ble service in java
Browse files Browse the repository at this point in the history
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
  • Loading branch information
sfroment committed Nov 9, 2018
1 parent b100434 commit fad6275
Show file tree
Hide file tree
Showing 18 changed files with 432 additions and 6 deletions.
1 change: 1 addition & 0 deletions client/react-native/android/app/build.gradle
Expand Up @@ -145,6 +145,7 @@ dependencies {
compile project(':react-native-network-info')
compile project(':react-native-image-picker')
implementation fileTree(dir: "libs", include: ["*.jar", "core.aar"])
implementation project(":ble")
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
}
Expand Down
@@ -1,12 +1,10 @@
package chat.berty.core;

import android.util.Log;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactMethod;

import chat.berty.ble.Manager;
import core.Core;

public class CoreModule extends ReactContextBaseJavaModule {
Expand Down
Expand Up @@ -12,8 +12,10 @@
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.lang.System;
import java.util.List;

import chat.berty.ble.Manager;
import chat.berty.core.CorePackage;

public class MainApplication extends Application implements ReactApplication {
Expand Down Expand Up @@ -50,5 +52,7 @@ public ReactNativeHost getReactNativeHost() {
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);

Manager.getInstance().setmContext(this.getApplicationContext());
}
}
6 changes: 6 additions & 0 deletions client/react-native/android/ble/.classpath
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
1 change: 1 addition & 0 deletions client/react-native/android/ble/.gitignore
@@ -0,0 +1 @@
/build
23 changes: 23 additions & 0 deletions client/react-native/android/ble/.project
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ble</name>
<comment>Project ble created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,2 @@
connection.project.dir=..
eclipse.preferences.version=1
47 changes: 47 additions & 0 deletions client/react-native/android/ble/build.gradle
@@ -0,0 +1,47 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion = 27

buildToolsVersion = "27.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

task deleteJar(type: Delete) {
delete 'libs/jars/ble.jar'
}

task createJar(type: Copy) {
from('build/intermediates/packaged-classes/release/')
into('libs/jars/')
include('classes.jar')
rename('classes.jar', 'ble.jar')
}

createJar.dependsOn(deleteJar, build)
Binary file added client/react-native/android/ble/libs/jars/ble.jar
Binary file not shown.
21 changes: 21 additions & 0 deletions client/react-native/android/ble/proguard-rules.pro
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
@@ -0,0 +1,26 @@
package chat.berty.ble;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {

public void useAppContext() {
// Context of the app under test.
// Context appContext = InstrumentationRegistry.getTargetContext();

// assertEquals("chat.berty.ble.manager", appContext.getPackageName());
}
}
7 changes: 7 additions & 0 deletions client/react-native/android/ble/src/main/AndroidManifest.xml
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="chat.berty.ble" >
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>

0 comments on commit fad6275

Please sign in to comment.