コード例 #1
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   if (mSelectedAccessPoint == null) {
     return super.onContextItemSelected(item);
   }
   switch (item.getItemId()) {
     case MENU_ID_CONNECT:
       {
         if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
           mWifiManager.connect(mSelectedAccessPoint.networkId, mConnectListener);
         } else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) {
           /** Bypass dialog for unsecured networks */
           mSelectedAccessPoint.generateOpenNetworkConfig();
           mWifiManager.connect(mSelectedAccessPoint.getConfig(), mConnectListener);
         } else {
           showDialog(mSelectedAccessPoint, true);
         }
         return true;
       }
     case MENU_ID_FORGET:
       {
         mWifiManager.forget(mSelectedAccessPoint.networkId, mForgetListener);
         return true;
       }
     case MENU_ID_MODIFY:
       {
         showDialog(mSelectedAccessPoint, true);
         return true;
       }
   }
   return super.onContextItemSelected(item);
 }
コード例 #2
0
 @Override
 public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
   if (preference instanceof AccessPoint) {
     mSelectedAccessPoint = (AccessPoint) preference;
     /** Bypass dialog for unsecured, unsaved networks */
     if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE
         && mSelectedAccessPoint.networkId == INVALID_NETWORK_ID
         && !mSelectedAccessPoint.isIBSS) {
       mSelectedAccessPoint.generateOpenNetworkConfig();
       mWifiManager.connect(mSelectedAccessPoint.getConfig(), mConnectListener);
     } else {
       showDialog(mSelectedAccessPoint, false);
     }
   } else {
     return super.onPreferenceTreeClick(screen, preference);
   }
   return true;
 }