Search in sources :

Example 6 with WifiP2pGroup

use of android.net.wifi.p2p.WifiP2pGroup in project android_packages_apps_Settings by omnirom.

the class WifiP2pSettingsTest method persistentController_withOneGroup_shouldBeAvailable.

@Test
public void persistentController_withOneGroup_shouldBeAvailable() {
    final String fakeGroupName = new String("fakeGroupName");
    doReturn(fakeGroupName).when(mWifiP2pGroup).getNetworkName();
    final List<WifiP2pGroup> groupList = new ArrayList<>();
    groupList.add(mWifiP2pGroup);
    final WifiP2pGroupList wifiP2pGroupList = mock(WifiP2pGroupList.class);
    doReturn(groupList).when(wifiP2pGroupList).getGroupList();
    final Bundle bundle = new Bundle();
    bundle.putString(WifiP2pSettings.SAVE_SELECTED_GROUP, fakeGroupName);
    mFragment.onActivityCreated(bundle);
    mFragment.onPersistentGroupInfoAvailable(wifiP2pGroupList);
    assertThat(mFragment.mPersistentCategoryController.isAvailable()).isTrue();
}
Also used : WifiP2pGroupList(android.net.wifi.p2p.WifiP2pGroupList) WifiP2pGroup(android.net.wifi.p2p.WifiP2pGroup) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with WifiP2pGroup

use of android.net.wifi.p2p.WifiP2pGroup in project android_packages_apps_Settings by DirtyUnicorns.

the class WifiP2pSettings method onPersistentGroupInfoAvailable.

@Override
public void onPersistentGroupInfoAvailable(WifiP2pGroupList groups) {
    mPersistentCategoryController.removeAllChildren();
    for (WifiP2pGroup group : groups.getGroupList()) {
        if (DBG)
            Log.d(TAG, " group " + group);
        WifiP2pPersistentGroup wppg = new WifiP2pPersistentGroup(getPrefContext(), group);
        mPersistentCategoryController.addChild(wppg);
        if (wppg.getGroupName().equals(mSelectedGroupName)) {
            if (DBG)
                Log.d(TAG, "Selecting group " + wppg.getGroupName());
            mSelectedGroup = wppg;
            mSelectedGroupName = null;
        }
    }
    if (mSelectedGroupName != null) {
        // Looks like there's a dialog pending getting user confirmation to delete the
        // selected group. When user hits OK on that dialog, we won't do anything; but we
        // shouldn't be in this situation in first place, because these groups are persistent
        // groups and they shouldn't just get deleted!
        Log.w(TAG, " Selected group " + mSelectedGroupName + " disappered on next query ");
    }
}
Also used : WifiP2pGroup(android.net.wifi.p2p.WifiP2pGroup)

Example 8 with WifiP2pGroup

use of android.net.wifi.p2p.WifiP2pGroup in project android_packages_apps_Settings by crdroidandroid.

the class WifiP2pSettings method onPersistentGroupInfoAvailable.

@Override
public void onPersistentGroupInfoAvailable(WifiP2pGroupList groups) {
    mPersistentCategoryController.removeAllChildren();
    for (WifiP2pGroup group : groups.getGroupList()) {
        if (DBG)
            Log.d(TAG, " group " + group);
        WifiP2pPersistentGroup wppg = new WifiP2pPersistentGroup(getPrefContext(), group);
        mPersistentCategoryController.addChild(wppg);
        if (wppg.getGroupName().equals(mSelectedGroupName)) {
            if (DBG)
                Log.d(TAG, "Selecting group " + wppg.getGroupName());
            mSelectedGroup = wppg;
            mSelectedGroupName = null;
        }
    }
    if (mSelectedGroupName != null) {
        // Looks like there's a dialog pending getting user confirmation to delete the
        // selected group. When user hits OK on that dialog, we won't do anything; but we
        // shouldn't be in this situation in first place, because these groups are persistent
        // groups and they shouldn't just get deleted!
        Log.w(TAG, " Selected group " + mSelectedGroupName + " disappered on next query ");
    }
}
Also used : WifiP2pGroup(android.net.wifi.p2p.WifiP2pGroup)

Example 9 with WifiP2pGroup

use of android.net.wifi.p2p.WifiP2pGroup in project physical-web by google.

the class WifiDirectConnect method connect.

public void connect(UrlDevice urlDevice, String title) {
    String progressTitle = mContext.getString(R.string.page_loading_title) + " " + title;
    mProgress = new ProgressDialog(mContext);
    mProgress.setCancelable(true);
    mProgress.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            Log.i(TAG, "Dialog box canceled");
            mDevice = null;
            mManager.cancelConnect(mChannel, new ActionListener() {

                @Override
                public void onSuccess() {
                    Log.d(TAG, "cancel connect call success");
                }

                @Override
                public void onFailure(int reason) {
                    Log.d(TAG, "cancel connect call fail " + reason);
                }
            });
        }
    });
    mProgress.setTitle(progressTitle);
    mProgress.setMessage(mContext.getString(R.string.page_loading_message));
    mProgress.show();
    mDevice = urlDevice;
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = Utils.getWifiAddress(mDevice);
    config.groupOwnerIntent = 0;
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    mContext.registerReceiver(mReceiver, intentFilter);
    mManager.requestGroupInfo(mChannel, new WifiP2pManager.GroupInfoListener() {

        public void onGroupInfoAvailable(final WifiP2pGroup group) {
            if (group != null) {
                Log.d(TAG, "group not null");
                if (group.getOwner().deviceAddress.equals(Utils.getWifiAddress(mDevice))) {
                    Log.i(TAG, "Already connected");
                    mManager.requestConnectionInfo(mChannel, new WifiP2pManager.ConnectionInfoListener() {

                        public void onConnectionInfoAvailable(final WifiP2pInfo info) {
                            if (mDevice != null && info.groupOwnerAddress != null) {
                                Intent intent = new Intent(Intent.ACTION_VIEW);
                                intent.setData(Uri.parse("http:/" + info.groupOwnerAddress + ":" + Integer.toString(Utils.getWifiPort(mDevice))));
                                mContext.startActivity(intent);
                            }
                        }
                    });
                } else {
                    mManager.removeGroup(mChannel, new ActionListener() {

                        @Override
                        public void onSuccess() {
                            Log.d(TAG, "remove call success");
                            connectHelper(true, config);
                        }

                        @Override
                        public void onFailure(int reason) {
                            Log.d(TAG, "remove call fail " + reason);
                        }
                    });
                }
            } else {
                Log.d(TAG, "group null");
                connectHelper(true, config);
            }
        }
    });
}
Also used : IntentFilter(android.content.IntentFilter) DialogInterface(android.content.DialogInterface) WifiP2pConfig(android.net.wifi.p2p.WifiP2pConfig) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) WifiP2pInfo(android.net.wifi.p2p.WifiP2pInfo) ActionListener(android.net.wifi.p2p.WifiP2pManager.ActionListener) WifiP2pGroup(android.net.wifi.p2p.WifiP2pGroup) WifiP2pManager(android.net.wifi.p2p.WifiP2pManager) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 10 with WifiP2pGroup

use of android.net.wifi.p2p.WifiP2pGroup in project platform_packages_apps_Settings by BlissRoms.

the class WifiP2pSettings method onPersistentGroupInfoAvailable.

@Override
public void onPersistentGroupInfoAvailable(WifiP2pGroupList groups) {
    mPersistentCategoryController.removeAllChildren();
    for (WifiP2pGroup group : groups.getGroupList()) {
        if (DBG)
            Log.d(TAG, " group " + group);
        WifiP2pPersistentGroup wppg = new WifiP2pPersistentGroup(getPrefContext(), group);
        mPersistentCategoryController.addChild(wppg);
        if (wppg.getGroupName().equals(mSelectedGroupName)) {
            if (DBG)
                Log.d(TAG, "Selecting group " + wppg.getGroupName());
            mSelectedGroup = wppg;
            mSelectedGroupName = null;
        }
    }
    if (mSelectedGroupName != null) {
        // Looks like there's a dialog pending getting user confirmation to delete the
        // selected group. When user hits OK on that dialog, we won't do anything; but we
        // shouldn't be in this situation in first place, because these groups are persistent
        // groups and they shouldn't just get deleted!
        Log.w(TAG, " Selected group " + mSelectedGroupName + " disappered on next query ");
    }
}
Also used : WifiP2pGroup(android.net.wifi.p2p.WifiP2pGroup)

Aggregations

WifiP2pGroup (android.net.wifi.p2p.WifiP2pGroup)12 Test (org.junit.Test)4 WifiP2pGroupList (android.net.wifi.p2p.WifiP2pGroupList)2 ArrayList (java.util.ArrayList)2 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 OnCancelListener (android.content.DialogInterface.OnCancelListener)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 WifiP2pConfig (android.net.wifi.p2p.WifiP2pConfig)1 WifiP2pInfo (android.net.wifi.p2p.WifiP2pInfo)1 WifiP2pManager (android.net.wifi.p2p.WifiP2pManager)1 ActionListener (android.net.wifi.p2p.WifiP2pManager.ActionListener)1 Bundle (android.os.Bundle)1