Skip to content

Commit

Permalink
Testing Device Data Callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra Osorio authored and Alexandra Osorio committed Mar 5, 2016
1 parent 762e904 commit ff2f644
Show file tree
Hide file tree
Showing 744 changed files with 4,284 additions and 2,164 deletions.
2 changes: 2 additions & 0 deletions .idea/encodings.xml

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

332 changes: 229 additions & 103 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
#Thu Feb 25 19:52:25 EST 2016
#Sat Mar 05 11:28:56 EST 2016
Binary file not shown.
Binary file modified platforms/android/.gradle/2.2.1/taskArtifacts/fileHashes.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified platforms/android/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin
Binary file not shown.
3 changes: 3 additions & 0 deletions platforms/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
</activity>
</application>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="19" />
</manifest>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<merger version="3"><dataSet config="main"><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\assets"/></dataSet><dataSet config="debug"><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\src\debug\assets"/></dataSet></merger>
<merger version="3"><dataSet config="main"><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\assets"/></dataSet><dataSet config="debug"><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\src\debug\assets"/></dataSet></merger>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<merger version="3"><dataSet config="main"><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\src\main\jniLibs"/></dataSet><dataSet config="debug"><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\src\debug\jniLibs"/></dataSet></merger>
<merger version="3"><dataSet config="main"><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\src\main\jniLibs"/></dataSet><dataSet config="debug"><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\src\debug\jniLibs"/></dataSet></merger>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<merger version="3"><dataSet config="main$Generated" generated="true"><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\res"/><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\build\generated\res\rs\debug"/><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\build\generated\res\resValues\debug"/></dataSet><dataSet config="debug$Generated" generated="true"><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\src\debug\res"/></dataSet><dataSet config="main" generated-set="main$Generated"><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\res"/><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\build\generated\res\rs\debug"/><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\build\generated\res\resValues\debug"/></dataSet><dataSet config="debug" generated-set="debug$Generated"><source path="C:\Users\Alexandra\Documents\Android\Ionic\open-barbell-master\open-barbell-master\platforms\android\CordovaLib\src\debug\res"/></dataSet><mergedItems/></merger>
<merger version="3"><dataSet config="main$Generated" generated="true"><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\res"/><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\build\generated\res\rs\debug"/><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\build\generated\res\resValues\debug"/></dataSet><dataSet config="debug$Generated" generated="true"><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\src\debug\res"/></dataSet><dataSet config="main" generated-set="main$Generated"><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\res"/><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\build\generated\res\rs\debug"/><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\build\generated\res\resValues\debug"/></dataSet><dataSet config="debug" generated-set="debug$Generated"><source path="C:\Users\Alexandra\Documents\Android\Ionic\OBB\platforms\android\CordovaLib\src\debug\res"/></dataSet><mergedItems/></merger>
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,20 @@ public void onCordovaInit(PluginManager pluginManager) {
// If there was no Activity result, we still need to send out the resume event if the
// Activity was destroyed by the OS
activityWasDestroyed = false;

CoreAndroid appPlugin = (CoreAndroid) pluginManager.getPlugin(CoreAndroid.PLUGIN_NAME);
if(appPlugin != null) {
JSONObject obj = new JSONObject();
try {
obj.put("action", "resume");
} catch (JSONException e) {
LOG.e(TAG, "Failed to create event message", e);
if(pluginManager != null)
{
CoreAndroid appPlugin = (CoreAndroid) pluginManager.getPlugin(CoreAndroid.PLUGIN_NAME);
if(appPlugin != null) {
JSONObject obj = new JSONObject();
try {
obj.put("action", "resume");
} catch (JSONException e) {
LOG.e(TAG, "Failed to create event message", e);
}
appPlugin.sendResumeEvent(new PluginResult(PluginResult.Status.OK, obj));
}
appPlugin.sendResumeEvent(new PluginResult(PluginResult.Status.OK, obj));
}

}
}

Expand Down Expand Up @@ -169,8 +172,10 @@ public void onSaveInstanceState(Bundle outState) {
String serviceName = activityResultCallback.getServiceName();
outState.putString("callbackService", serviceName);
}
if(pluginManager != null){
outState.putBundle("plugin", pluginManager.onSaveInstanceState());
}

outState.putBundle("plugin", pluginManager.onSaveInstanceState());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Licensed to the Apache Software Foundation (ASF) under one
* are not expected to implement it.
*/
public interface CordovaWebView {
public static final String CORDOVA_VERSION = "5.1.0";
public static final String CORDOVA_VERSION = "5.1.1";

void init(CordovaInterface cordova, List<PluginEntry> pluginEntries, CordovaPreferences preferences);

Expand Down
35 changes: 33 additions & 2 deletions platforms/android/android.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,40 @@
{
"xml": "<feature name=\"BluetoothSerial\"><param name=\"android-package\" value=\"com.megster.cordova.BluetoothSerial\" /></feature>",
"count": 1
},
{
"xml": "<feature name=\"RFduino\"><param name=\"android-package\" value=\"com.megster.cordova.rfduino.RFduinoPlugin\" /></feature>",
"count": 1
}
]
}
},
"AndroidManifest.xml": {
"parents": {
"/manifest": []
"/manifest": [
{
"xml": "<uses-permission android:name=\"android.permission.BLUETOOTH\" />",
"count": 2
},
{
"xml": "<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\" />",
"count": 2
},
{
"xml": "<uses-sdk android:minSdkVersion=\"18\" android:targetSdkVersion=\"19\" />",
"count": 1
}
]
}
}
}
},
"installed_plugins": {
"cordova-plugin-bluetooth-serial": {
"PACKAGE_NAME": "com.ionicframework.testtabs509143"
},
"cordova-plugin-rfduino": {
"PACKAGE_NAME": "com.ionicframework.testtabs509143"
}
},
"dependent_plugins": {},
Expand All @@ -35,6 +55,17 @@
"clobbers": [
"window.bluetoothSerial"
]
},
{
"file": "plugins/cordova-plugin-rfduino/www/rfduino.js",
"id": "cordova-plugin-rfduino.rfduino",
"clobbers": [
"rfduino"
]
}
]
],
"plugin_metadata": {
"cordova-plugin-bluetooth-serial": "0.4.5",
"cordova-plugin-rfduino": "0.1.4"
}
}
14 changes: 7 additions & 7 deletions platforms/android/assets/www/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
// 'openbarbell' is the name of this angular module (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'required' modules
angular.module('openbarbell', [
'ngMaterial',
'ionic',
'appConfig',
'appRoutes',
'ngMaterial',
'ionic',
'appConfig',
'appRoutes',
'shell',
'workout',
'history',
'settings',
/* Services */
'bluetooth-service', 'settings-service'
'bluetooth-service', 'rfduino-service', 'settings-service'
]);

//.run(function($ionicPlatform) {
// $ionicPlatform.ready(function() {
// // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// // for form inputs)
//
//
// // This is where we could setup initial plug-in settings
// if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
// cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
Expand All @@ -29,4 +29,4 @@ angular.module('openbarbell', [
// StatusBar.styleDefault();
// }
// });
//});
//});
104 changes: 12 additions & 92 deletions platforms/android/assets/www/app/services/bluetooth.service.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
(function(angular){
angular.module('bluetooth-service', [])
.service('bluetoothService', bluetoothService);

bluetoothService.$inject = ['$q', '$timeout', '$window', 'settingsService'];
function bluetoothService($q, $timeout, $window, settingsService) {
var connectedDevice = {};

/*******************************
* DEPRECATED *
* Could possible be used for: *
*--------ANDROID ONLY---------*
* function @isEnabled *
* function @enable *
*******************************/

bluetoothService.$inject = ['$q', '$window'];
function bluetoothService($q, $window) {
var enabled = false;

var service = {
getConnectedDevice : getConnectedDevice,
isEnabled : isEnabled,
isConnected : isConnected,
enable : enable,
scanDevices : scanDevices,
connect : function(device) {
return connect(device);
}
enable : enable
};

return service;
Expand Down Expand Up @@ -47,27 +48,6 @@
return deferred.promise;
}

function isConnected() {
var deferred = $q.defer();

if ($window.bluetoothSerial && enabled) {
bluetoothSerial.isConnected(function() {
deferred.resolve("Device is connected.");
},
function() {
deferred.reject("Device is not connected.");
});
}
else if (!enabled) {
deferred.reject("Bluetooth is not enabled!");
}
else {
deferred.reject("BluetoothSerial plug-in not loaded.");
}

return deferred.promise;
}

function enable() {
var deferred = $q.defer();

Expand All @@ -89,65 +69,5 @@

return deferred.promise;
}

function scanDevices() {
var deferred = $q.defer();

if ($window.bluetoothSerial && enabled) {
bluetoothSerial.discoverUnpaired(function(devices) {
deferred.resolve(devices);
},
function() {
deferred.reject("Could not find any devices.");
});
}
else if (!enabled) {
deferred.reject("Bluetooth is not enabled!");
}
else {
deferred.reject("BluetoothSerial plug-in not loaded.");
}

return deferred.promise;
}

function connect(device) {
var deferred = $q.defer();

if ($window.bluetoothSerial && enabled) {
bluetoothSerial.connect(device.address, function() {
deferred.resolve("Connected to " + device.name + "!");
connectedDevice = device;
connected = true;

/* Store MAC Address of connected device */
settingsService.setSetting("mac_address", device.address);

//bluetoothSerial.subscribe('\n', onReceive, onSubscribeFail);
},
function(error) {
deferred.resolve("Failed to connected to " + device.name + "!");
connectedDevice = {};
connected = false;
});
}
else if (!enabled) {
deferred.reject("Bluetooth is not enabled!");
}
else {
deferred.reject("BluetoothSerial plug-in not loaded.");
}

return deferred.promise;
}

function onReceive(data) {
//TODO: Do something with the data
}

//TODO: Test subscribing with the device, otherwise may need read/timeouts
function onSubscribeFail() {
console.log("Failed to subscribe.");
}
};
})(angular);
Loading

0 comments on commit ff2f644

Please sign in to comment.