Skip to content

Commit

Permalink
minor changes to demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
Adebayo Osipitan authored and Adebayo Osipitan committed May 20, 2021
1 parent d07c9ea commit 4fba9c7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 38 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion 29
defaultConfig {
applicationId "inc.osips.bleproject"
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,29 @@ public RemoteControllerPresenter(final ControllerViewInterface viewInterface, St
DeviceConnectionFactory factory = DeviceConnectionFactory.withContext(viewInterface.getControlContext());

try {
builder = factory.establishConnectionWithDeviceOf(type, device);
} catch (IoTCommException e) {
Log.e(TAG, "RemoteControllerPresenter: ",e );
e.printStackTrace();
}

if (device instanceof BluetoothDevice && type.equalsIgnoreCase(Constants.BLE)){
Log.i("Connection type", builder.getDeviceType());
this.deviceName = ((BluetoothDevice) device).getName();
//viewInterface.getUUIDFromPopUp();
intent = new Intent(activity, BleGattService.class);
deviceConnector = builder.build();
if (!ServiceUtil.isAnyRemoteConnectionServiceRunningAPI16(viewInterface.getControlContext()))
bindBleService();
}else if (device instanceof WifiP2pDevice && type.equalsIgnoreCase(Constants.P2P)) {
Log.i("Connection", builder.getDeviceType());
if (builder !=null){
builder = factory.getDeviceConnectionBuilder(type, device);
if (device instanceof BluetoothDevice && type.equalsIgnoreCase(Constants.BLE)){
Log.i("Connection type", builder.getDeviceType());
this.deviceName = ((BluetoothDevice) device).getName();
//viewInterface.getUUIDFromPopUp();
intent = new Intent(activity, BleGattService.class);
deviceConnector = builder.build();

intent = new Intent(activity, P2pDataTransferService.class);
if(!ServiceUtil.isAnyRemoteConnectionServiceRunningAPI16(viewInterface.getControlContext()))
if (!ServiceUtil.isAnyRemoteConnectionServiceRunningAPI16(viewInterface.getControlContext()))
bindBleService();
}else if (device instanceof WifiP2pDevice && type.equalsIgnoreCase(Constants.P2P)) {
Log.i("Connection", builder.getDeviceType());
if (builder !=null){
deviceConnector = builder.build();

intent = new Intent(activity, P2pDataTransferService.class);
if(!ServiceUtil.isAnyRemoteConnectionServiceRunningAPI16(viewInterface.getControlContext()))
bindBleService();
}
this.deviceName = ((WifiP2pDevice) device).deviceName;
}
this.deviceName = ((WifiP2pDevice) device).deviceName;
} catch (IoTCommException e) {
Log.e(TAG, "RemoteControllerPresenter: ",e );
e.printStackTrace();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package inc.osips.iot_wireless_communication.wireless_comms_module.remote_comms;

import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.net.wifi.p2p.WifiP2pDevice;
import android.os.Parcelable;
import android.text.TextUtils;

Expand Down Expand Up @@ -30,7 +32,7 @@ public synchronized static DeviceConnectionFactory withContext(@NonNull Context
}
return factory_instance;
}
public Builder establishConnectionWithDeviceOf(@NonNull String connectionType, @NonNull Parcelable device) throws IoTCommException {
public Builder getDeviceConnectionBuilder(@NonNull String connectionType, @NonNull Parcelable device) throws IoTCommException {

if(TextUtils.isEmpty(connectionType))return null;

Expand All @@ -57,7 +59,13 @@ private Builder(Context activity, Parcelable device) {

abstract public WirelessDeviceConnector build();
abstract public DeviceConnectionFactory.Builder setDeviceUniqueID(String UUID_IP);
abstract public String getDeviceType();
public String getDeviceType() throws IoTCommException{
if(device instanceof BluetoothDevice){
return Constants.BLE;
}else if (device instanceof WifiP2pDevice) return Constants.P2P;

else throw new IoTCommException("This Parcelable object is not recognised", "Error!");
}
abstract public Builder setConnectionTimeOut(int timeOut);
abstract public Builder setMaxTransmissionUnit(int size);
}
Expand All @@ -83,12 +91,6 @@ public Builder setDeviceUniqueID(@Nullable String ip) {
return this;
}

@Override
public String getDeviceType() {
return Constants.P2P;
}


@Override
public Builder setConnectionTimeOut(int timeOut) {
this.timeOut = timeOut;
Expand Down Expand Up @@ -120,12 +122,6 @@ public Builder setDeviceUniqueID(@Nullable String UUID) {
return this;
}

@Override
public String getDeviceType() {
return Constants.BLE;
}


@Override
public Builder setConnectionTimeOut(int timeOut) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class P2pConnection implements WirelessDeviceConnector {
public P2pConnection(@NonNull Context context, @NonNull final Parcelable p2pDevice, int time_out) {
this.p2pDevice = (WifiP2pDevice) p2pDevice;
this.context = context;

if (time_out>1000)
this.TIME_OUT = time_out;
initializeServerSocket();
Expand Down

0 comments on commit 4fba9c7

Please sign in to comment.