示例#1
0
        public WifiDirectManager()
        {
            _WifiP2pActonListener  = new Receiver(this);
            _DiscoverPeersListener = new WifiP2pActionListener(this);

            _DroidWifiP2pManager = (WifiP2pManager)Application.Context.GetSystemService(Context.WifiP2pService);
            _Channel             = _DroidWifiP2pManager.Initialize(Application.Context, Application.Context.MainLooper, null);

            /*
             * IntentFilter startFilter = new IntentFilter(BluetoothAdapter.ActionDiscoveryStarted);
             * IntentFilter foundFilter = new IntentFilter(BluetoothDevice.ActionFound);
             * IntentFilter finshFilter = new IntentFilter(BluetoothAdapter.ActionDiscoveryFinished);
             *
             * Application.Context.RegisterReceiver(_DiscoveryStartedReceiver, startFilter);
             * Application.Context.RegisterReceiver(_DevicesFoundReceiver, foundFilter);
             * Application.Context.RegisterReceiver(_DiscoveryFinishedReceiver, finshFilter);
             */

            IntentFilter connectionChangedFilter = new IntentFilter(WifiP2pManager.WifiP2pConnectionChangedAction);
            IntentFilter peersChangedFilter      = new IntentFilter(WifiP2pManager.WifiP2pPeersChangedAction);
            IntentFilter stateChangedFilter      = new IntentFilter(WifiP2pManager.WifiP2pStateChangedAction);
            IntentFilter thisDeviceChangedFilter = new IntentFilter(WifiP2pManager.WifiP2pThisDeviceChangedAction);

            Application.Context.RegisterReceiver(_WifiP2pActonListener, stateChangedFilter);
            Application.Context.RegisterReceiver(_WifiP2pActonListener, connectionChangedFilter);
            Application.Context.RegisterReceiver(_WifiP2pActonListener, peersChangedFilter);

            //Application.Context.RegisterReceiver()
        }
示例#2
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="manager">WifiP2pManager system service</param>
 /// <param name="channel">Wifi p2p channel</param>
 /// <param name="activity">activity associated with the receiver</param>
 public WiFiDirectBroadcastReceiver(WifiP2pManager manager, WifiP2pManager.Channel channel,
                                    MainActivity activity)
 {
     _manager  = manager;
     _channel  = channel;
     _activity = activity;
 }
示例#3
0
 /// <summary>
 /// Default constructor.
 /// Specify the timeOut in milli seconds.
 /// </summary>
 /// <param name="activity">The context.</param>
 /// <param name="manager">The wifi P2P manager.</param>
 /// <param name="channel">The channel used for wifi P2P communications.</param>
 /// <param name="timeOutSeconds">How long the task should keep discovering peers. Use a zero or a negative value for indefinite time.</param>
 /// <remarks>For indefinite times, the method <see cref="WifiP2pManager.StopPeerDiscovery(WifiP2pManager.Channel, WifiP2pManager.IActionListener)"/> must be called manually.</remarks>
 public DiscoverAsyncTask(Activity activity, WifiP2pManager manager, WifiP2pManager.Channel channel, float timeOutSeconds)
 {
     m_Activity       = activity ?? throw new ArgumentNullException(nameof(activity));
     m_WifiP2pManager = manager ?? throw new ArgumentNullException(nameof(manager));
     m_WifiP2pChannel = channel ?? throw new ArgumentNullException(nameof(channel));
     m_TimeOutSeconds = timeOutSeconds;
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            _intentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction);
            _intentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction);
            _intentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction);
            _intentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction);

            _manager = (WifiP2pManager)GetSystemService(WifiP2pService);
            _channel = _manager.Initialize(this, MainLooper, null);
        }
示例#5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            _manager = (WifiP2pManager)GetSystemService(Activity.WifiP2pService);
            _channel = _manager.Initialize(this, MainLooper, null);

            // Set up the intent filter for the broadcast receiver
            _intentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction);
            _intentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction);
            _intentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction);
            _intentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction);

            // Get our button from the layout resource,
            // and attach an event to it
            buttons["upper-left"]    = FindViewById <Button>(Resource.Id.button1);
            buttons["upper-center"]  = FindViewById <Button>(Resource.Id.button2);
            buttons["upper-right"]   = FindViewById <Button>(Resource.Id.button3);
            buttons["middle-left"]   = FindViewById <Button>(Resource.Id.button4);
            buttons["middle-center"] = FindViewById <Button>(Resource.Id.button5);
            buttons["middle-right"]  = FindViewById <Button>(Resource.Id.button6);
            buttons["lower-left"]    = FindViewById <Button>(Resource.Id.button7);
            buttons["lower-center"]  = FindViewById <Button>(Resource.Id.button8);
            buttons["lower-right"]   = FindViewById <Button>(Resource.Id.button9);

            messageView      = FindViewById <TextView> (Resource.Id.textView1);
            messageView.Text = "Welcome to Android Tic-Tac-Toe!";

            MatchUIToBoard();
            messageView.Text = string.Format("It's {0}'s turn",
                                             game.PlayersTurn);

            foreach (var k in buttons.Keys)
            {
                buttons [k].Tag = k;
                Log.Info("BCTTT", string.Format("button[{0}].Tag = {1}", k, buttons[k].Tag));
                buttons [k].Click += ButtonClick;
            }
        }
示例#6
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            mLvPeers            = FindViewById <ListView>(Resource.Id.lvPeers);
            mLvPeers.ItemClick += OnListViewItemClick;

            mBtShowPeers        = FindViewById <Button>(Resource.Id.btShowPeers);
            mBtShowPeers.Click += OnListAllPeers;

            mManager  = (WifiP2pManager)GetSystemService(WifiP2pService);
            mChannel  = mManager.Initialize(this, MainLooper, null);
            mReceiver = new WifiDirectBroadcastReceiver(mManager, mChannel, this);

            mIntentFilter = new IntentFilter();
            mIntentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction);
            mIntentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction);
            mIntentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction);
            mIntentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction);

            mPeers = new List <WifiP2pDevice>();
        }
示例#7
0
 public WifiDirectBroadcastReceiver(WifiP2pManager p2pManager, WifiP2pManager.Channel p2pChannel, MainActivity mainActivity)
 {
     this.mManager      = p2pManager;
     this.mChannel      = p2pChannel;
     this.mMainActivity = mainActivity;
 }