/** * Remove all peers. * * <p>This is called on {@link AperiBroadcastReceiver} receiving at state change event of {@link * WifiP2pManager#WIFI_P2P_STATE_CHANGED_ACTION WIFI_P2P_STATE_CHANGED_ACTION}. * * @see DeviceListFragment#clearPeers() */ protected void clearPeers() { DeviceListFragment fragmentList = (DeviceListFragment) getFragment(TabsPagerAdaptor.LIST_FRAG); if (fragmentList != null) { fragmentList.clearPeers(); Log.i(TAG, "Peer list reset"); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.atn_direct_enable: if (mManager != null && mChannel != null) { // Since this is the system wireless settings activity, it's // not going to send us a result. We will be notified by // WiFiDeviceBroadcastReceiver instead. startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); } else { Log.e(TAG, "mChannel or manager is null"); } return true; case R.id.atn_direct_discover: if (!mIsWifiP2pEnabled) { Toast.makeText(AperiMainActivity.this, R.string.p2p_off_warning, Toast.LENGTH_SHORT) .show(); return true; } final DeviceListFragment list = (DeviceListFragment) getFragment(TabsPagerAdaptor.LIST_FRAG); list.onInitiateDiscovery(); mManager.discoverPeers( mChannel, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Toast.makeText(AperiMainActivity.this, "Discovery Initiated", Toast.LENGTH_SHORT) .show(); } @Override public void onFailure(int reasonCode) { String reason = reasonCode == WifiP2pManager.P2P_UNSUPPORTED ? "P2P not supported" : (reasonCode == WifiP2pManager.ERROR ? "Error" : (reasonCode == WifiP2pManager.BUSY) ? "System Busy, try again later" : "Unknown :'("); Toast.makeText( AperiMainActivity.this, "Discovery Failed : " + reason, Toast.LENGTH_SHORT) .show(); } }); return true; case R.id.macip_refresh: updateMap(); return true; default: return super.onOptionsItemSelected(item); } }
@Override public void cancelDisconnect() { /* * A cancel abort request by user. Disconnect i.e. removeGroup if * already connected. Else, request WifiP2pManager to abort the ongoing * request */ if (mManager != null) { final DeviceListFragment fragment = (DeviceListFragment) getFragment(TabsPagerAdaptor.LIST_FRAG); if (fragment.getDevice() == null || fragment.getDevice().status == WifiP2pDevice.CONNECTED) { disconnect(); } else if (fragment.getDevice().status == WifiP2pDevice.AVAILABLE || fragment.getDevice().status == WifiP2pDevice.INVITED) { mManager.cancelConnect( mChannel, new ActionListener() { @Override public void onSuccess() { Toast.makeText(AperiMainActivity.this, "Aborting connection", Toast.LENGTH_SHORT) .show(); } @Override public void onFailure(int reasonCode) { Toast.makeText( AperiMainActivity.this, "Connect abort request failed. Reason Code: " + reasonCode, Toast.LENGTH_SHORT) .show(); } }); } } }
public void onGetDevicesClick(View view) { DeviceListFragment fragment = (DeviceListFragment) getSupportFragmentManager().findFragmentById(R.id.item_list); fragment.getDevices(); }