Exemple #1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.NearbyConnection, container, false);

            AvalibleDeviceslistview = (ExpandableListView)view.FindViewById(Resource.Id.Nearby_Devices1);
            AvalibleDeviceslistview.SetAdapter(MainActivity.Adapter);
            switchScan  = view.FindViewById <Switch>(Resource.Id.switchScan);
            switchBroad = view.FindViewById <Switch>(Resource.Id.switchBroadcast);
            M_SERVICE   = (MainActivity)Activity;
            RegisterForContextMenu(AvalibleDeviceslistview);


            switchScan.CheckedChange += delegate(object sender, CompoundButton.CheckedChangeEventArgs e)
            {
                if (e.IsChecked)
                {
                    Toast.MakeText((Activity), " Starting Scanning ", ToastLength.Short).Show();
                    ScanOption.Builder discBuilder = new ScanOption.Builder();
                    Policy             policy      = Policy.PolicyStar;
                    discBuilder.SetPolicy(policy);
                    MainActivity.mDiscoveryEngine.StartScan(MainActivity.MyServiceID, new ScanCallBack((MainActivity)Activity), discBuilder.Build()).AddOnSuccessListener(new TaskListener(Activity.ApplicationContext, "StartScanning")).AddOnFailureListener(new TaskListener(Activity.ApplicationContext, "StartScanning"));
                    Log.Debug(MainActivity.TAG, "ScanOption.Builder : Policy :" + policy.ToString());
                }
                else
                {
                    Toast.MakeText(Activity.ApplicationContext, " Stopping Scanning ", ToastLength.Short).Show();
                    MainActivity.mDiscoveryEngine.StopScan();
                }
            };

            switchBroad.CheckedChange += delegate(object sender, CompoundButton.CheckedChangeEventArgs e)
            {
                if (e.IsChecked)
                {
                    Toast.MakeText((Activity), " Starting Broadcasting ", ToastLength.Short).Show();
                    BroadcastOption.Builder advBuilder = new BroadcastOption.Builder();
                    Policy policy = Policy.PolicyStar;
                    advBuilder.SetPolicy(policy);
                    MainActivity.mDiscoveryEngine.StartBroadcasting(MainActivity.MyEndPoint, MainActivity.MyServiceID, new ConnCallBack((MainActivity)Activity), advBuilder.Build()).AddOnSuccessListener(new TaskListener(Activity.ApplicationContext, "StartBroadcasting")).AddOnFailureListener(new TaskListener(Activity.ApplicationContext, "StartBroadcasting"));
                    Log.Debug(MainActivity.TAG, "BroadcastOption.Builder : Policy :" + policy.ToString());
                }
                else
                {
                    Toast.MakeText(Activity.ApplicationContext, " Stopping Broadcasting ", ToastLength.Short).Show();
                    MainActivity.mDiscoveryEngine.StopBroadcasting();
                }
            };

            AvalibleDeviceslistview.GroupClick += delegate(object sender, ExpandableListView.GroupClickEventArgs e)
            {
                if (!MainActivity.AvaliableDevicesList.ElementAt(e.GroupPosition).Status)
                {
                    MainActivity.InitiateConnection(MainActivity.AvaliableDevicesList.ElementAt(e.GroupPosition));
                }
                else if (AvalibleDeviceslistview.IsGroupExpanded(e.GroupPosition))
                {
                    AvalibleDeviceslistview.CollapseGroup(e.GroupPosition);
                }
                else
                {
                    AvalibleDeviceslistview.ExpandGroup(e.GroupPosition);
                }
            };

            return(view);
        }