Skip to content

Commit

Permalink
feat(java): export calling getCurrentActivity to display ble ask
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 fad6275 commit aa918ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
@@ -1,5 +1,7 @@
package chat.berty.core;

import android.app.Activity;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.Promise;
Expand All @@ -12,10 +14,18 @@ public class CoreModule extends ReactContextBaseJavaModule {
private String filesDir = "";
private ReactApplicationContext reactContext;

public CoreModule(ReactApplicationContext reactContext) {
public CoreModule(final ReactApplicationContext reactContext) {
super(reactContext);
this.filesDir = reactContext.getFilesDir().getAbsolutePath();
this.reactContext = reactContext;

Object o = new Manager.ActivityGetter() {
public Activity getCurrentActivity() {
return reactContext.getCurrentActivity();
}
};

Manager.getInstance().setmReactContext(o);
}

public String getName() {
Expand Down
@@ -1,6 +1,7 @@
package chat.berty.ble;

import android.app.Activity;
import android.arch.core.util.Function;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
Expand Down Expand Up @@ -33,6 +34,8 @@ public class Manager {

private Context mContext;

private ActivityGetter mReactContext;

final static int BLUETOOTH_ENABLE_REQUEST = 1;

protected UUID SERVICE_UUID = UUID.fromString("A06C6AB8-886F-4D56-82FC-2CF8610D6664");
Expand Down Expand Up @@ -66,6 +69,10 @@ public class Manager {
protected BluetoothGattCharacteristic isRdyCharacteristic;
protected BluetoothGattCharacteristic closerCharacteristic;

public interface ActivityGetter {
Activity getCurrentActivity();
}

private Manager() {
super();
Log.e(TAG, "BLEManager init");
Expand All @@ -76,6 +83,11 @@ public void setmContext(Context ctx) {
mContext = ctx;
}

public void setmReactContext(Object rCtx) {
Log.e(TAG, "BLEManager ReactContext set");
mReactContext = (ActivityGetter)rCtx;
}

public static Manager getInstance() {
if (instance == null) {
synchronized (Manager.class) {
Expand Down Expand Up @@ -205,16 +217,12 @@ public void onStartFailure(int errorCode) {
public String realTest() {
Log.e(TAG, "THIS IS REAL SHIT GUY");
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// if (!mBluetoothAdapter.isEnabled()) {
if (!mBluetoothAdapter.isEnabled()) {
Log.e(TAG, "NEED TO ENABLE");
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
if (mContext instanceof Activity) {
((Activity)mContext).startActivityForResult(enableBtIntent, BLUETOOTH_ENABLE_REQUEST);
} else {
Log.e(TAG, "mContext should be an instanceof Activity.");
}
// ((Activity)mContext).startActivityForResult(enableBtIntent, BLUETOOTH_ENABLE_REQUEST);
// }
mReactContext.getCurrentActivity().startActivityForResult(enableBtIntent, BLUETOOTH_ENABLE_REQUEST);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
Log.e(TAG, "THIS IS REAL SHIT GUY2");
initGattServerCallBack();
Expand Down

0 comments on commit aa918ed

Please sign in to comment.