private void OnDialogDeviceScanResult(PairedDevice pd)
        {
            var sd = new StoredDevice
            {
                scanDevice = pd.scanDevice,
                conFlag    = 2,
                id         = pd.id
            };
            var conInd = deviceHelper.liDevices.Count;

            deviceHelper.liDevices.Add(sd);
            deviceHelper.Save();


            AddDrawerItem(
                smDrawerDevices,
                smDrawerDevices.Size(),
                sd.scanDevice.Model,
                Resource.Drawable.av_receiver_100_black,
                true,
                0,
                Resource.Layout.layout_home_drawer_item_action, pd.id.ToString());

            ConnectWithDevice(conInd);
        }
Exemplo n.º 2
0
        public int AddItem(PairedDevice sd, bool store)
        {
            if (sd.conFlag > 0)
            {
                int i = 0;
                foreach (PairedDevice device in GetAllItems().ToList())
                {
                    if (device.conFlag > 0)
                    {
                        device.conFlag = 0;
                        UpdateItem(i, device, !store);
                    }
                    i++;
                }
            }
            var pIns = liMain.Count;

            liMain.Add(sd);
            NotifyItemInserted(pIns);
            if (store)
            {
                deviceHelper.liDevices.Add(sd.ToStoredDevice());
                deviceHelper.Save();
            }
            return(pIns);
        }
Exemplo n.º 3
0
 public void UpdateItem(int i, PairedDevice sd, bool store)
 {
     try
     {
         if (sd.conFlag > 0)
         {
             int c = 0;
             foreach (PairedDevice device in GetAllItems().ToList())
             {
                 if (i != c && device.conFlag > 0)
                 {
                     device.conFlag = 0;
                     UpdateItem(c, device, false);
                 }
                 c++;
             }
         }
         if (sd.status != DEVICE_STAT_NONE)
         {
             if (i != lastItemExp && lastItemExp >= 0)
             {
                 var a = liMain[lastItemExp];
                 a.status            = DEVICE_STAT_NONE;
                 liMain[lastItemExp] = a;
                 NotifyItemChanged(lastItemExp);
             }
             lastItemExp = i;
         }
         liMain[i] = sd;
         if (store)
         {
             deviceHelper.liDevices[i] = sd.ToStoredDevice();
             deviceHelper.Save();
         }
         NotifyItemChanged(i);
     }
     catch (Exception e)
     {
         Toast.MakeText(Application.Context, $"Error: {e.Message}", ToastLength.Short).Show();
     }
 }
Exemplo n.º 4
0
        public bool ConnectToDevice(PairedDevice device, out string errorMessage)
        {
            ConnectionStatus = BluetoothConnectionStatus.None;
            errorMessage     = "";

            // try and get the device by name
            CurrentBluetoothDevice = FindDevice(device.Address);
            if (CurrentBluetoothDevice == null)
            {
                errorMessage = "Could not locate device: " + device.Name;
                return(false);
            }

            BluetoothSocket = CurrentBluetoothDevice.CreateRfcommSocketToServiceRecord(Java.Util.UUID.FromString("00001101-0000-1000-8000-00805F9B34FB"));

            // cancel discovery because it slows down the connection and may cause it to fail altogether
            BluetoothAdapter.CancelDiscovery();

            try
            {
                ConnectionStatus = BluetoothConnectionStatus.Connecting;
                BluetoothSocket.Connect();
            }
            catch (Java.IO.IOException connectException)
            {
                errorMessage = "Connection Failed:" + connectException.Message;
                return(false);
            }
            catch (Exception connectException)
            {
                errorMessage = "Connection Failed:" + connectException.Message;
                return(false);
            }
            ConnectionStatus = BluetoothConnectionStatus.Connected;

            StartListeningForDataFromBluetoothDevice();
            ConnectionStatus = BluetoothConnectionStatus.ConnectedAndListening;

            return(true);
        }
Exemplo n.º 5
0
 private void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
 {
     _selectedDevice         = (PairedDevice)e.SelectedItem;
     connectButton.IsEnabled = true;
     connectButton.Text      = "Connect to Device";
 }