private void BlueToothServiceDeviceAdded(IBlueToothService service, BluetoothDevice obj) { if (!Devices.Any(d => d.MacAddress == obj.MacAddress)) { Devices.Add(obj); } }
public ListViewAllOrder() { InitializeComponent(); init(); _blueToothService = DependencyService.Get <IBlueToothService>(); BindDeviceList(); }
public ListWaitingQueue() { InitializeComponent(); init(); _blueToothService = DependencyService.Get <IBlueToothService>(); BindDeviceList(); }
public EstimationGoldViewModel() { _messageService = DependencyService.Get <IMessageService>(); _navigationService = DependencyService.Get <INavigationService>(); _blueToothService = DependencyService.Get <IBlueToothService>(); BindDeviceList(); InitEstimateUI(); }
public MainPageViewModel(INavigationService navigationService, IBlueToothService btService) : base(navigationService) { RefreshBlueTooothDevicesCommand = new DelegateCommand(RefreshBlueToothExecuted, RefreshBlueToothCanExecute); _blueToothService = btService; MessagingCenter.Subscribe <IBlueToothService, BluetoothDevice>(this, MessageTypes.DeviceFound.ToString(), BlueToothServiceDeviceAdded); MessagingCenter.Subscribe <IBlueToothService>(this, MessageTypes.ScanFinished.ToString(), (service) => ToggleRunningState()); //_blueToothService.DeviceAdded += BlueToothServiceDeviceAdded; //_blueToothService.ScanFinished += () => ToggleRunningState(); }
public override void OnReceive(Context context, Intent intent) { IBlueToothService service = (IBlueToothService)App.Current.Container.Resolve(typeof(IBlueToothService)); string action = intent.Action; if (action == BluetoothDevice.ActionFound) { BluetoothDevice newDevice = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice); service.AddDevice(new Models.BluetoothDevice(newDevice.Name, newDevice.Address)); } if (action == BluetoothAdapter.ActionDiscoveryFinished) { service.RaiseScanFinishedEvent(); } }
public TicketsViewModel() { this.IsEnableAct = true; this.IsEnableVal = true; this.AlertaTicket = false; this.IsVisible = true; this.IsVisibleOrigen = false; this.IsVisibleOrigenPick = true; this.IsVisibleAlert = true; this.TickPer = true; this.TickEnco = false; this.NoPersonas = 1; this.ValTicket = val * NoPersonas; this.apiService = new ApiService(); this.IntermediosModel = new IntermediosDataBase(); this.UbicacionesModel = new UbicacionesDataBase(); this.LoadIntermedios(); blueToothService = DependencyService.Get <IBlueToothService>(); this.OrigenPickSgte = null; this.Posicion = 1; this.BindDeviceList(); }
public MyDevice(IBlueToothService device) { this.device = device; device.ValueChangedHandler = handler; }
public BlueToothDevicePrinting() { _blueToothService = DependencyService.Get <IBlueToothService>(); }
public PrintPageViewModel() { _blueToothService = DependencyService.Get <IBlueToothService>(); BindDeviceList(); }
public PrintSettingPageViewModel(INavigationService navigationService, IDialogService dialogService ) : base(navigationService, dialogService) { _blueToothService = DependencyService.Get <IBlueToothService>(); Title = "蓝牙打印机"; this.PrintData = null; this.EnableBluetooth = Settings.EnableBluetooth; this.WhenAnyValue(x => x.PrintStyleSelected).Subscribe(x => { Settings.PrintStyleSelected = x; }) .DisposeWith(this.DeactivateWith); //启用蓝牙 this.WhenAnyValue(x => x.EnableBluetooth) .Subscribe(async x => { try { if (x) { this.Drives.Clear(); Settings.EnableBluetooth = true; var micAccessGranted = await _blueToothService.GetPermissionsAsync(); if (!micAccessGranted) { this.EnableBluetooth = false; this.Alert("请打先启用手机蓝牙功能"); return; } Device.BeginInvokeOnMainThread(async() => { using (var dig = UserDialogs.Instance.Loading("扫描中...")) { long timeOutTime = 8000; long curRunTime = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; long tempTime = curRunTime; while (this.Drives.Count == 0 && (curRunTime - tempTime) <= timeOutTime) { curRunTime = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; var results = _blueToothService.PairedDevices(); if (results != null && results.Any()) { this.DrivesHeight = results.Count() * 40.7; this.Drives = new ObservableRangeCollection <Printer>(results); } await Task.Delay(1000); } } if (this.Drives.Count == 0) { _dialogService.LongAlert("没有扫描蓝牙到设备!"); this.EnableBluetooth = false; Settings.EnableBluetooth = false; } }); } else { Settings.EnableBluetooth = false; this.EnableBluetooth = false; this.Drives.Clear(); } } catch (NullReferenceException) { this.EnableBluetooth = false; Settings.EnableBluetooth = false; _dialogService.LongAlert("没有找到蓝牙设备!"); } }) .DisposeWith(this.DeactivateWith); //适配 this.AdaptationCmd = ReactiveCommand.CreateFromTask <Printer>(async(item) => { if (!item.Status && Drives != null && Drives.Where(s => s.Status).Count() > 0) { _dialogService.LongAlert("请先断开当前适配"); return; } using (var dig = UserDialogs.Instance.Loading("请稍等...")) { try { await Task.Delay(500); await Task.Run(() => { Device.BeginInvokeOnMainThread(async() => { if (!item.Status) { var connected = await _blueToothService.ConnectDevice(item); if (connected) { item.Status = true; } } else { _blueToothService.PrintStop(); App.BtAddress = ""; item.Status = false; } }); }); } catch (Exception) { _dialogService.LongAlert("适配不到设备,请确保打印机开启"); } } }); //打印测试 this.PrintCommand = ReactiveCommand.Create(() => { try { if (!string.IsNullOrEmpty(App.BtAddress)) { _blueToothService.Print(this.PrintData, Settings.PrintStyleSelected, this.RepeatPrintNum); } else { _dialogService.LongAlert("请选择匹配设备!"); } } catch (Exception ex) { _dialogService.LongAlert(ex.Message); } }); }