protected internal override void onCreate(Bundle savedInstanceState) { base.onCreate(savedInstanceState); mType = Intent.getIntExtra("deviceType", SmcDevice.TYPE_IMAGEVIEWER); ContentView = R.layout.device_select; TextView noDevicesTextView = (TextView)findViewById(R.id.no_devices); noDevicesTextView.Visibility = View.GONE; if (FrameworkInstalled) { noDevicesTextView.Text = [email protected]_picker_no_devices; } else { noDevicesTextView.Text = [email protected]_picker_framework_not_installed; findViewById(R.id.refresh_button).Visibility = View.GONE; } ListView.EmptyView = noDevicesTextView; ListAdapter = new DevicesAdapter(this); findViewById(R.id.cancel_button).OnClickListener = this; findViewById(R.id.refresh_button).OnClickListener = this; SmcDeviceFinder df = new SmcDeviceFinder(this); df.StatusListener = this; df.start(); }
protected void WireupExternalHandlers() { this.deviceDiscoveredHandler = (object sender, BluetoothLEManager.DeviceDiscoveredEventArgs e) => { Console.WriteLine("Discovered device: " + e.Device.Name); // reload the list view //TODO: why doens't NotifyDataSetChanged work? is it because i'm replacing the reference? this.RunOnUiThread(() => { this._listAdapter = new DevicesAdapter(this, BluetoothLEManager.Current.DiscoveredDevices); this._listView.Adapter = this._listAdapter; }); }; BluetoothLEManager.Current.DeviceDiscovered += this.deviceDiscoveredHandler; this.deviceConnectedHandler = (object sender, BluetoothLEManager.DeviceConnectionEventArgs e) => { this.RunOnUiThread(() => { this._progress.Hide(); }); // now that we're connected, save it App.Current.State.SelectedDevice = e.Device; // launch the details screen this.StartActivity(typeof(DeviceDetails.DeviceDetailsScreen)); }; BluetoothLEManager.Current.DeviceConnected += this.deviceConnectedHandler; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // load our layout SetContentView(Resource.Layout.ScannerHome); // find our controls this._listView = FindViewById <ListView> (Resource.Id.DevicesTable); this._scanButton = FindViewById <ScanButton> (Resource.Id.ScanButton); // create our list adapter this._listAdapter = new DevicesAdapter(this, BluetoothLEManager.Current.DiscoveredDevices); this._listView.Adapter = this._listAdapter; }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // load our layout SetContentView (Resource.Layout.ScannerHome); // find our controls this._listView = FindViewById<ListView> (Resource.Id.DevicesTable); this._scanButton = FindViewById<ScanButton> (Resource.Id.ScanButton); // create our list adapter this._listAdapter = new DevicesAdapter(this, BluetoothLEManager.Current.DiscoveredDevices); this._listView.Adapter = this._listAdapter; }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // load our layout SetContentView (Resource.Layout.ScannerHome); // find our controls this._listView = FindViewById<ListView> (Resource.Id.DevicesListView); this._scanButton = FindViewById<ScanButton> (Resource.Id.ScanButton); // create our list adapter this._listAdapter = new DevicesAdapter(this, App.Current.BleAdapter.DiscoveredDevices); this._listView.Adapter = this._listAdapter; this.WireupLocalHandlers (); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // load our layout SetContentView(Resource.Layout.ScannerHome); // find our controls this._listView = FindViewById <ListView> (Resource.Id.DevicesListView); this._scanButton = FindViewById <ScanButton> (Resource.Id.ScanButton); // create our list adapter this._listAdapter = new DevicesAdapter(this, App.Current.BleAdapter.DiscoveredDevices); this._listView.Adapter = this._listAdapter; this.WireupLocalHandlers(); }
protected void WireupExternalHandlers () { this.deviceDiscoveredHandler = (object sender, BluetoothLEManager.DeviceDiscoveredEventArgs e) => { Console.WriteLine ("Discovered device: " + e.Device.Name); // reload the list view //TODO: why doens't NotifyDataSetChanged work? is it because i'm replacing the reference? this.RunOnUiThread( () => { this._listAdapter = new DevicesAdapter(this, BluetoothLEManager.Current.DiscoveredDevices); this._listView.Adapter = this._listAdapter; }); }; BluetoothLEManager.Current.DeviceDiscovered += this.deviceDiscoveredHandler; this.deviceConnectedHandler = (object sender, BluetoothLEManager.DeviceConnectionEventArgs e) => { this.RunOnUiThread( () => { this._progress.Hide(); }); // now that we're connected, save it App.Current.State.SelectedDevice = e.Device; // launch the details screen this.StartActivity (typeof(DeviceDetails.DeviceDetailsScreen)); }; BluetoothLEManager.Current.DeviceConnected += this.deviceConnectedHandler; }
public LruCacheAnonymousInnerClassHelper(DevicesAdapter outerInstance) : base(1024 * 1024) { this.outerInstance = outerInstance; }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var view = inflater.Inflate(Resource.Layout.profile_fragment, container, false); grid = view.FindViewById <GridView>(Resource.Id.profile_devices); _adapter = new DevicesAdapter(Activity, ChadderUI.Source.db.LocalUser.Devices); grid.Adapter = _adapter; grid.ItemClick += grid_ItemClick; SetupMenu(); _btnPicture = view.FindViewById <ImageButton>(Resource.Id.profile_picture); _btnPicture.Click += (sender, e) => { ChadderImagePicker.MultiSourcePick(this); }; var btnName = view.FindViewById <Button>(Resource.Id.profile_name_btn); _tvName = view.FindViewById <TextView>(Resource.Id.profile_name_label); btnName.Click += async(object sender, EventArgs e) => await ChadderUI.ChangeName(); var btnEmail = view.FindViewById <Button>(Resource.Id.profile_email_btn); _tvEmail = view.FindViewById <TextView>(Resource.Id.profile_email_label); btnEmail.Click += async(object sender, EventArgs e) => await ChadderUI.ChangeEmail(); var btnPhone = view.FindViewById <Button>(Resource.Id.profile_phone_btn); _tvPhone = view.FindViewById <TextView>(Resource.Id.profile_phone_label); btnPhone.Click += async(object sender, EventArgs e) => await ChadderUI.ChangePhone(); var btnShareName = view.FindViewById <Button>(Resource.Id.profile_sharename_btn); _tvShareName = view.FindViewById <TextView>(Resource.Id.profile_sharename_label); btnShareName.Click += async(object sender, EventArgs e) => await ChadderUI.ChangeShareName(); var btnFacebook = view.FindViewById <Button>(Resource.Id.profile_facebook_btn); btnFacebook.Click += (object sender, EventArgs e) => //++RegisterEndFragment.ShareFacebook(Activity, uiHelper); RegisterEndFragment.ShareFacebook(Activity); var btnDevicePassword = view.FindViewById <Button>(Resource.Id.profile_device_pwd_btn); btnDevicePassword.Click += async(object sender, EventArgs e) => await ChadderUI.ChangeDevicePassword(); var btnAccPassword = view.FindViewById <Button>(Resource.Id.profile_account_pwd_btn); btnAccPassword.Click += async(object sender, EventArgs e) => await ChadderUI.ChangeAccountPassword(); var btnLogout = view.FindViewById <Button>(Resource.Id.profile_logout_btn); btnLogout.Click += async(object sender, EventArgs e) => { await ChadderUI.Logout(); ChadderApp.UIHelper.Source_OnNotAuthorized(); }; view.FindViewById <Button>(Resource.Id.profile_scan_btn) .Click += (object sender, EventArgs e) => MainActivity.ScanFingerprint(Activity as MainActivity); _btnFingerprint = view.FindViewById <Button>(Resource.Id.profile_fingerprint_btn); _btnFingerprint.Click += async(object sender, EventArgs e) => { var layout = new RelativeLayout(Activity); var image = new ImageView(Activity); image.Focusable = true; image.FocusableInTouchMode = true; image.SetScaleType(ImageView.ScaleType.FitCenter); image.SetBackgroundResource(Android.Resource.Color.White); layout.AddView(image, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MatchParent, RelativeLayout.LayoutParams.MatchParent)); var bottomText = new TextView(Activity); var param = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent); param.SetMargins(20, 20, 20, 20); param.AddRule(LayoutRules.CenterHorizontal); param.AddRule(LayoutRules.AlignParentBottom); layout.AddView(bottomText, param); bottomText.Text = GetString(Resource.String.ProfileFingerprintBottomMessage); InputDialog.ShowProgressDialog(Activity); var writer = new ZXing.BarcodeWriter { Format = ZXing.BarcodeFormat.QR_CODE }; var qr = writer.Write(await ChadderUI.GetFingerprint()); image.SetImageBitmap(qr); InputDialog.DismissProgressDialog(); var wnd = new PopupWindow(layout, RelativeLayout.LayoutParams.MatchParent, RelativeLayout.LayoutParams.MatchParent); wnd.ShowAtLocation(View, GravityFlags.Center, 0, 0); image.Touch += (object s, Android.Views.View.TouchEventArgs e2) => { wnd.Dismiss(); }; }; view.FindViewById <Button>(Resource.Id.Erase_All_Msgs_btn) .Click += async(object sender, EventArgs e) => await ChadderUI.DeleteAllMessages(); view.FindViewById <Button>(Resource.Id.profile_contactbook_btn) //++.Click += async (s, e) => await ChadderUI.ToggleUploadContactBook(); .Click += (s, e) => { }; _tvContactBook = view.FindViewById <TextView>(Resource.Id.profile_contactbook_label); return(view); }
//经过测试 , 即使不使用StartLeScan()方法 //在DeviceFound的广播里面也能搜到Le和Classic的设备 ; //所以这里注释掉这个callback ; //private BLEScanCallBack bleScanCallback = null; protected override void OnCreate(Bundle savedInstanceState) { RequestWindowFeature(WindowFeatures.NoTitle); base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); //初始化View控件 deviceList = FindViewById <GridView>(Resource.Id.device_list); refreshBluedevice = FindViewById <Button>(Resource.Id.ble_refresh); startBLEConnection = FindViewById <Button>(Resource.Id.ble_connect); getServices = FindViewById <Button>(Resource.Id.ble_getservices); searchedDevices = new List <BluetoothDevice>(); adapter = new DevicesAdapter(this, searchedDevices); deviceList.Adapter = adapter; deviceList.OnItemClickListener = this; startBLEConnection.SetOnClickListener(this); getServices.SetOnClickListener(this); refreshBluedevice.SetOnClickListener(this); startBLEConnection.Enabled = false; //---------------------------------------------------------------------- //-----------------------下面是开启业务逻辑的部分------------------------ //---------------------------------------------------------------------- BluetoothManager bm = (BluetoothManager)GetSystemService(Context.BluetoothService); //BluetoothAdapter bt = BluetoothAdapter.DefaultAdapter; btAdapter = bm.Adapter; bondedDevices = new List <BluetoothDevice>(btAdapter.BondedDevices); foreach (BluetoothDevice device in bondedDevices) { searchedDevices.Add(device); adapter.NotifyDataSetChanged(); } if (!btAdapter.IsEnabled) { btAdapter.Enable(); } //开启BR/EDR的蓝牙扫描(基于SPP协议的蓝牙设备发现) ; btAdapter.StartDiscovery(); Log.Error("dana.ye->xamarin->bt", "开始扫描周围的BR/EDR蓝牙设备"); //开启BLE的蓝牙扫描(基于BLE协议的蓝牙设备发现) //StartLeScan 是一个过时的方法 , 但是确实需要用到它 /* * bleScanCallback = new BLEScanCallBack(this); * try * { #pragma warning disable CS0618 // 类型或成员已过时 * btAdapter.StartLeScan(bleScanCallback); #pragma warning restore CS0618 // 类型或成员已过时 * Log.Error("dana.ye->xamarin->bt", "开始扫描周围的BLE蓝牙设备"); * } * catch (Exception e) * { * Log.Error("dana.ye->xamarin->bt", "stopLeScan时出错 : " + e.Message); * } * */ //20秒后关闭扫描 , 这里的语法和java有些不同 , 主要是因为C#不支持匿名内部对象的原因导致的 //这样也有好处 , 就是对象方便管理 , 但是在写某些简单逻辑的时候就比较麻烦了 action = () => { //关闭BR/EDR的蓝牙扫描(基于SPP协议的蓝牙设备发现) ; btAdapter.CancelDiscovery(); //关闭BLE设备的扫描 /* * try * { * pragma warning disable CS0618 // 类型或成员已过时 * btAdapter.StopLeScan(bleScanCallback); #pragma warning restore CS0618 // 类型或成员已过时 * } * catch (Exception e) { * Log.Error("dana.ye->xamarin->bt", "stopLeScan时出错 : " + e.Message); * } * */ Log.Error("dana.ye->xamarin->bt", "自动停止扫描周围的蓝牙设备"); }; handler.PostDelayed(action, 10000); //到这里 , 定时关闭的任务就开启完成了 , 就等待10s后关闭扫描了 ; }