[demo] bluetooth initial pairing support
authorLeandro Dorileo <leandro.maciel.dorileo@intel.com>
Tue, 13 Aug 2013 21:14:54 +0000 (18:14 -0300)
committerLeandro Dorileo <leandro.maciel.dorileo@intel.com>
Tue, 13 Aug 2013 21:55:20 +0000 (18:55 -0300)
demos/tizen/bluetooth.html
demos/tizen/js/main.js

index 2893862..7250de9 100644 (file)
           </li>
         </ul>
 
+      <div id="paired-device-group">
+        <h6>Paired Devices</h6>
+        <ul data-role="listview" id="paired-device-list">
+        </ul>
+      </div>
+
+      <div id="avalilable-device-group">
         <h6>Available Devices</h6>
-        <ul data-role="listview" id="device-group">
+        <ul data-role="listview" id="available-device-list">
         </ul>
       </div>
+      </div>
 
       <div data-role="footer" data-position="fixed">
         <div id="main-footer">
index f77f58d..6835143 100644 (file)
@@ -16,6 +16,7 @@ blueApp.init = function() {
 
     blueApp.cleanDeviceList();
 
+    $("#paired-device-group").hide();
     $("#visibility-toggle").click(blueApp.toggleVisibility);
 
     $("input[type=radio][name=visibility]").change(function() {
@@ -80,8 +81,8 @@ blueApp.adapterStatusToggle = function() {
  * Clean the device list.
  */
 blueApp.cleanDeviceList = function() {
-    $("#device-group").hide();
-    $("#device-group").html('');
+    $("#available-device-list").hide();
+    $("#available-device-list").html('');
 };
 
 /**
@@ -96,10 +97,7 @@ blueApp.scan = function() {
     });
 };
 
-/**
- * Efectively add new devices to devices list.
- */
-blueApp.addDevice = function(device) {
+blueApp.newDeviceEntry = function(device, list) {
     var deviceStyle;
     var deviceClass = device.deviceClass;
     var deviceItem = "<li><div id='device-icon' ";
@@ -124,11 +122,29 @@ blueApp.addDevice = function(device) {
     deviceItem += device.name;
     deviceItem += "</li>";
 
-    $("#device-group").show();
-    $("#device-group").append(
-        $(deviceItem).attr("class",
-                           "ui-li ui-li-static ui-btn-up-s ui-li-last").attr(
-                               "address", device.address));
+    $(list + "-group").show();
+    $(list + "-list").show();
+    $(list + "-list").append(
+      $(deviceItem).attr("class",
+                         "ui-li ui-li-static ui-btn-up-s ui-li-last").attr(
+                           "address", device.address));
+}
+
+/**
+ * Efectively add new devices to devices list.
+ */
+blueApp.addDevice = function(device) {
+    blueApp.newDeviceEntry(device, "#available-device");
+
+    $("#available-device-list li[address='"+device.address+"']").click(function() {
+      var device_entry = $(this);
+      blueApp.adapter.createBonding($(device_entry).attr("address"), function(device) {
+        $(device_entry).remove();
+        blueApp.newDeviceEntry(device, "#paired-device");
+      }, function(e) {
+        console.log("error on creating bonding.");
+      });
+    });
 };
 
 /**
@@ -140,7 +156,7 @@ blueApp.discoverDevicesCb = {
     },
     ondevicefound : blueApp.addDevice,
     ondevicedisappeared : function(address) {
-        $("#device-group li").each(function() {
+        $("#available-device-list li").each(function() {
             if ($(this).attr("address") == address)
                 $(this).remove();
         });