Search in sources :

Example 36 with WifiP2pDevice

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

the class WifiP2pSettings method handlePeersChanged.

private void handlePeersChanged() {
    mPeerCategoryController.removeAllChildren();
    mConnectedDevices = 0;
    if (DBG)
        Log.d(TAG, "List of available peers");
    for (WifiP2pDevice peer : mPeers.getDeviceList()) {
        if (DBG)
            Log.d(TAG, "-> " + peer);
        mPeerCategoryController.addChild(new WifiP2pPeer(getPrefContext(), peer));
        if (peer.status == WifiP2pDevice.CONNECTED)
            mConnectedDevices++;
    }
    if (DBG)
        Log.d(TAG, " mConnectedDevices " + mConnectedDevices);
}
Also used : WifiP2pDevice(android.net.wifi.p2p.WifiP2pDevice)

Example 37 with WifiP2pDevice

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

the class P2pThisDevicePreferenceControllerTest method updateDeviceName_emptyName_shouldUseIpAddress.

@Test
public void updateDeviceName_emptyName_shouldUseIpAddress() {
    WifiP2pDevice device = new WifiP2pDevice();
    device.deviceAddress = "address";
    mController.displayPreference(mPreferenceScreen);
    mController.updateDeviceName(device);
    assertThat(mPreference.getTitle()).isEqualTo(device.deviceAddress);
}
Also used : WifiP2pDevice(android.net.wifi.p2p.WifiP2pDevice) Test(org.junit.Test)

Example 38 with WifiP2pDevice

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

the class P2pThisDevicePreferenceControllerTest method updateDeviceName_hasName_shouldUseName.

@Test
public void updateDeviceName_hasName_shouldUseName() {
    WifiP2pDevice device = new WifiP2pDevice();
    device.deviceAddress = "address";
    device.deviceName = "name";
    mController.displayPreference(mPreferenceScreen);
    mController.updateDeviceName(device);
    assertThat(mPreference.getTitle()).isEqualTo(device.deviceName);
}
Also used : WifiP2pDevice(android.net.wifi.p2p.WifiP2pDevice) Test(org.junit.Test)

Example 39 with WifiP2pDevice

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

the class WifiP2pSettings method handlePeersChanged.

private void handlePeersChanged() {
    mPeerCategoryController.removeAllChildren();
    mConnectedDevices = 0;
    if (DBG)
        Log.d(TAG, "List of available peers");
    for (WifiP2pDevice peer : mPeers.getDeviceList()) {
        if (DBG)
            Log.d(TAG, "-> " + peer);
        mPeerCategoryController.addChild(new WifiP2pPeer(getPrefContext(), peer));
        if (peer.status == WifiP2pDevice.CONNECTED)
            mConnectedDevices++;
    }
    if (DBG)
        Log.d(TAG, " mConnectedDevices " + mConnectedDevices);
}
Also used : WifiP2pDevice(android.net.wifi.p2p.WifiP2pDevice)

Example 40 with WifiP2pDevice

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

the class WifiP2pSettings method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    final Activity activity = getActivity();
    mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    if (mWifiP2pManager != null) {
        mChannel = mWifiP2pManager.initialize(activity.getApplicationContext(), getActivity().getMainLooper(), null);
        if (mChannel == null) {
            // Failure to set up connection
            Log.e(TAG, "Failed to set up connection with wifi p2p service");
            mWifiP2pManager = null;
        }
    } else {
        Log.e(TAG, "mWifiP2pManager is null !");
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(SAVE_DIALOG_PEER)) {
        WifiP2pDevice device = savedInstanceState.getParcelable(SAVE_DIALOG_PEER);
        mSelectedWifiPeer = new WifiP2pPeer(getPrefContext(), device);
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(SAVE_DEVICE_NAME)) {
        mSavedDeviceName = savedInstanceState.getString(SAVE_DEVICE_NAME);
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(SAVE_SELECTED_GROUP)) {
        mSelectedGroupName = savedInstanceState.getString(SAVE_SELECTED_GROUP);
    }
    mRenameListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    String name = mDeviceNameText.getText().toString();
                    if (name != null) {
                        for (int i = 0; i < name.length(); i++) {
                            char cur = name.charAt(i);
                            if (!Character.isDigit(cur) && !Character.isLetter(cur) && cur != '-' && cur != '_' && cur != ' ') {
                                Toast.makeText(getActivity(), R.string.wifi_p2p_failed_rename_message, Toast.LENGTH_LONG).show();
                                return;
                            }
                        }
                    }
                    mWifiP2pManager.setDeviceName(mChannel, mDeviceNameText.getText().toString(), new WifiP2pManager.ActionListener() {

                        public void onSuccess() {
                            if (DBG)
                                Log.d(TAG, " device rename success");
                        }

                        public void onFailure(int reason) {
                            Toast.makeText(getActivity(), R.string.wifi_p2p_failed_rename_message, Toast.LENGTH_LONG).show();
                        }
                    });
                }
            }
        }
    };
    // disconnect dialog listener
    mDisconnectListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    mWifiP2pManager.removeGroup(mChannel, new WifiP2pManager.ActionListener() {

                        public void onSuccess() {
                            if (DBG)
                                Log.d(TAG, " remove group success");
                        }

                        public void onFailure(int reason) {
                            if (DBG)
                                Log.d(TAG, " remove group fail " + reason);
                        }
                    });
                }
            }
        }
    };
    // cancel connect dialog listener
    mCancelConnectListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    mWifiP2pManager.cancelConnect(mChannel, new WifiP2pManager.ActionListener() {

                        public void onSuccess() {
                            if (DBG)
                                Log.d(TAG, " cancel connect success");
                        }

                        public void onFailure(int reason) {
                            if (DBG)
                                Log.d(TAG, " cancel connect fail " + reason);
                        }
                    });
                }
            }
        }
    };
    // delete persistent group dialog listener
    mDeleteGroupListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    if (mSelectedGroup != null) {
                        if (DBG)
                            Log.d(TAG, " deleting group " + mSelectedGroup.getGroupName());
                        mWifiP2pManager.deletePersistentGroup(mChannel, mSelectedGroup.getNetworkId(), new WifiP2pManager.ActionListener() {

                            public void onSuccess() {
                                if (DBG)
                                    Log.d(TAG, " delete group success");
                            }

                            public void onFailure(int reason) {
                                if (DBG)
                                    Log.d(TAG, " delete group fail " + reason);
                            }
                        });
                        mSelectedGroup = null;
                    } else {
                        if (DBG)
                            Log.w(TAG, " No selected group to delete!");
                    }
                }
            } else if (which == DialogInterface.BUTTON_NEGATIVE) {
                if (DBG) {
                    Log.d(TAG, " forgetting selected group " + mSelectedGroup.getGroupName());
                }
                mSelectedGroup = null;
            }
        }
    };
    super.onActivityCreated(savedInstanceState);
}
Also used : WifiP2pDevice(android.net.wifi.p2p.WifiP2pDevice) DialogInterface(android.content.DialogInterface) Activity(android.app.Activity) OnClickListener(android.content.DialogInterface.OnClickListener)

Aggregations

WifiP2pDevice (android.net.wifi.p2p.WifiP2pDevice)95 Test (org.junit.Test)14 WifiDisplay (android.hardware.display.WifiDisplay)12 Activity (android.app.Activity)7 DialogInterface (android.content.DialogInterface)7 OnClickListener (android.content.DialogInterface.OnClickListener)7 WpsInfo (android.net.wifi.WpsInfo)6 WifiP2pConfig (android.net.wifi.p2p.WifiP2pConfig)6 ActionListener (android.net.wifi.p2p.WifiP2pManager.ActionListener)6 GroupInfoListener (android.net.wifi.p2p.WifiP2pManager.GroupInfoListener)6 PeerListListener (android.net.wifi.p2p.WifiP2pManager.PeerListListener)6 Surface (android.view.Surface)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DataInputStream (java.io.DataInputStream)6 IOException (java.io.IOException)6 Inet4Address (java.net.Inet4Address)6 ArrayList (java.util.ArrayList)6 RemoteDisplay (android.media.RemoteDisplay)3 StackTraceElement (java.lang.StackTraceElement)3 ListView (android.widget.ListView)1