Skip to content

Commit

Permalink
Merge branch 'v1.0.1'
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle/wrapper/gradle-wrapper.properties
#	iot_wireless_communication/build.gradle
  • Loading branch information
bayosip committed Aug 5, 2021
2 parents d426f7c + 776d876 commit a038fe6
Show file tree
Hide file tree
Showing 40 changed files with 888 additions and 575 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file modified .idea/modules.xml
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 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 29
compileSdkVersion 30
defaultConfig {
applicationId "inc.osips.bleproject"
minSdkVersion 21
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -16,25 +16,31 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding = true
dataBinding = true
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.palette:palette:1.0.0'
implementation 'com.github.markushi:circlebutton:1.1'
implementation 'cat.ereza:customactivityoncrash:2.2.0'
implementation 'com.github.skydoves:colorpickerview:2.1.5'
implementation 'com.karumi:dexter:5.0.0'
testImplementation 'junit:junit:4.12'
//implementation 'com.github.bayosip:BluConnector:Tag'
implementation project(path: ':iot_wireless_communication')

//added Libraries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface ControlFragmentListener extends AppActivity {
void speechInputCall();
void stopListening();
void startListening();
void setSelectedServiceUUID (String uuid);
void setSelectedServiceUUID ( String uuid, int flag);
void getDeviceAddressFromPopUp();
Activity getFragmentactivity();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public interface OnDiscoveredDevicesClickListener {

void selectDeviceToConnectTo(Devices device);
void selectDevicesToConnectTo(Devices device);
Context getListenerContext();

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
import android.util.Log;
import android.widget.EditText;

import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import inc.osips.bleproject.interfaces.ControllerViewInterface;
import inc.osips.iot_wireless_communication.wireless_comms_module.interfaces.WirelessDeviceConnector;
import inc.osips.iot_wireless_communication.wireless_comms_module.remote_comms.DeviceConnectionFactory;
import inc.osips.iot_wireless_communication.wireless_comms_module.remote_comms.Devices;
import inc.osips.iot_wireless_communication.wireless_comms_module.remote_comms.ble_comms.services.BleGattService;
import inc.osips.iot_wireless_communication.wireless_comms_module.remote_comms.p2p_comms.service.P2pDataTransferService;
import inc.osips.bleproject.utilities.Constants;
Expand All @@ -35,24 +40,33 @@ public class RemoteControllerPresenter extends VoiceControlPresenter {
private String deviceName;
private DeviceConnectionFactory.Builder builder;
private Intent intent;
private List<String> listOfRemoteServices = new ArrayList<>();
private boolean isServiceSelected = false;
private String deviceAddr =null;
private final List<String> listOfRemoteServices = new ArrayList<>();
private Map<Integer, Boolean> serviceMap = new HashMap<>();
private String type ="";
private int count = 1;
private final List<Parcelable> listDevice= new ArrayList<>();

public List<String> getListOfRemoteServices() {
return listOfRemoteServices;
}

public RemoteControllerPresenter(final ControllerViewInterface viewInterface, String type,
Parcelable device) {
List<Parcelable> devices) {
super(viewInterface);
this.type = type;
activity = viewInterface.getControlContext();
this.listDevice.clear();
listDevice.addAll(devices);
DeviceConnectionFactory factory = DeviceConnectionFactory.withContext(viewInterface.getControlContext());

Parcelable device = devices.get(0);
try {
builder = factory.getDeviceConnectionBuilder(type, device);
if (device instanceof BluetoothDevice && type.equalsIgnoreCase(Constants.BLE)){
Log.i("Connection type", builder.getDeviceType());
//this.deviceAddr = ((BluetoothDevice) device).getAddress();
this.deviceName = ((BluetoothDevice) device).getName();
serviceMap.put(count, false);
//viewInterface.getUUIDFromPopUp();
intent = new Intent(activity, BleGattService.class);
deviceConnector = builder.build();
Expand All @@ -75,6 +89,16 @@ public RemoteControllerPresenter(final ControllerViewInterface viewInterface, St
}
}

private void connectToAnotherDevice(Parcelable device){
if (device instanceof BluetoothDevice && type.equalsIgnoreCase(Constants.BLE)){
try {
deviceConnector.connectAnotherDeviceSimultaneously(device, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}

public void setEditTextIfStringAvailable(EditText txt, String str){
if(!TextUtils.isEmpty(str)){
txt.setText(str);
Expand All @@ -89,8 +113,15 @@ public void setBaseUuidOfBLEDeviceAndConnect(String uuid){
if (deviceConnector !=null){//"6e400001-b5a3-f393-e0a9-e50e24dcca9e"
String str = uuid.toLowerCase();
if (!TextUtils.isEmpty(str)) {
isServiceSelected = true;
deviceConnector.selectServiceUsingUUID(str);
serviceMap.put(count, true);
int index = count-1;
BluetoothDevice device = (BluetoothDevice)listDevice.get(index);
deviceConnector.selectServiceUsingUUID(device.getAddress(), str);
if (type.equalsIgnoreCase(Constants.BLE) && count< listDevice.size()){
connectToAnotherDevice(listDevice.get(count));
count++;
serviceMap.put(count, false);
}
}else {
GeneralUtil.message("Please Select A Valid BaseUUID");
}
Expand All @@ -106,7 +137,15 @@ private void bindBleService(){
}

public String getDeviceName() {
return deviceName;
StringBuilder names = new StringBuilder();
if (type.equalsIgnoreCase(Constants.BLE)){
for (Parcelable p: listDevice){
BluetoothDevice device = (BluetoothDevice)p;
names.append(device.getName());
names.append(", ");
}
}else return deviceName;
return names.toString();
}

public void unbindBleService(){
Expand Down Expand Up @@ -146,7 +185,7 @@ public void onReceive(Context context, Intent intent) {
break;
case Constants.ACTION_BLE_SERVICES_DISCOVERED:
Log.w("BLE", "services discovered");
if (!isServiceSelected) {
if (!serviceMap.get(count)) {
listOfRemoteServices.clear();
listOfRemoteServices.addAll(intent.getStringArrayListExtra(Constants.SERVICE_UUID));
viewInterface.getUUIDFromPopUp(listOfRemoteServices);
Expand All @@ -162,16 +201,18 @@ public void onReceive(Context context, Intent intent) {
GeneralUtil.message(intent.getStringExtra(P2pDataTransferService.EXTRA_DATA));
break;
case WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION:
int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
switch (state){
case WifiP2pManager.WIFI_P2P_STATE_ENABLED:
GeneralUtil.message("Wifi is Ok");
break;
case WifiP2pManager.WIFI_P2P_STATE_DISABLED:
GeneralUtil.message("Wifi has been turned off, " +
"Please turn on to use this feature");
GeneralUtil.transitionActivity(activity, Home.class);
break;
if(type.equalsIgnoreCase(Constants.P2P)) {
int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
switch (state) {
case WifiP2pManager.WIFI_P2P_STATE_ENABLED:
GeneralUtil.message("Wifi is Ok");
break;
case WifiP2pManager.WIFI_P2P_STATE_DISABLED:
GeneralUtil.message("Wifi has been turned off, " +
"Please turn on to use this feature");
GeneralUtil.transitionActivity(activity, Home.class);
break;
}
}
break;
case WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION:
Expand Down Expand Up @@ -211,7 +252,13 @@ private IntentFilter commsUpdateIntentFilter() {
return intentFilter;
}

public void sendInstructionsToDevice(String instruct) {
deviceConnector.sendInstructionsToRemoteDevice(instruct);
private void sendInstructionsToDevice(String instruct) {
deviceConnector.sendInstructionsToRemoteDevice(deviceAddr,null, instruct);
}

public void setDeviceAddressAndSendInstructions(String uuidAddr, String instructions) {
if (!TextUtils.isEmpty(uuidAddr))
this.deviceAddr = uuidAddr;
sendInstructionsToDevice(instructions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public void unregisterBroadCastReceiver(Activity activity) {
activity.unregisterReceiver(commsReceiver);
}



private final BroadcastReceiver commsReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.net.InetAddress;
Expand Down Expand Up @@ -166,7 +167,7 @@ public static void expand(final View v) {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1
? ViewGroup.LayoutParams.WRAP_CONTENT
? LinearLayout.LayoutParams.WRAP_CONTENT
: (int)(targetHeight * interpolatedTime);
v.requestLayout();
}
Expand Down
Loading

0 comments on commit a038fe6

Please sign in to comment.