Example #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()
        }
        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);
        }
        /// <summary>
        /// <see cref="Activity.OnCreate(Bundle)"/>
        /// </summary>
        override protected void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            WifiP2pManager             = (WifiP2pManager)GetSystemService(WifiP2pService);
            WifiP2pChannel             = WifiP2pManager.Initialize(this, MainLooper, null);
            m_WifiP2pBroadcastReceiver = new WifiP2pBroadcastReceiver(WifiP2pManager, WifiP2pChannel, this);

            m_WifiP2pIntentFilter = new IntentFilter();
            m_WifiP2pIntentFilter.AddAction(WifiP2pManager.WifiP2pStateChangedAction);
            m_WifiP2pIntentFilter.AddAction(WifiP2pManager.WifiP2pPeersChangedAction);
            m_WifiP2pIntentFilter.AddAction(WifiP2pManager.WifiP2pConnectionChangedAction);
            m_WifiP2pIntentFilter.AddAction(WifiP2pManager.WifiP2pThisDeviceChangedAction);
        }
 public void OnChannelDisconnected()
 {
     // we will try once more
     if (_manager != null && !_retryChannel)
     {
         Toast.MakeText(this, "Channel lost. Trying again", ToastLength.Long).Show();
         ResetData();
         _retryChannel = true;
         _manager.Initialize(this, MainLooper, this);
     }
     else
     {
         Toast.MakeText(this, "Severe! Channel is probably lost permanently. Try Disable/Re-Enable P2P.",
                        ToastLength.Long).Show();
     }
 }
Example #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;
            }
        }
Example #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>();
        }