Example usage for android.net.wifi.p2p WifiP2pDeviceList getDeviceList

List of usage examples for android.net.wifi.p2p WifiP2pDeviceList getDeviceList

Introduction

In this page you can find the example usage for android.net.wifi.p2p WifiP2pDeviceList getDeviceList.

Prototype

public Collection<WifiP2pDevice> getDeviceList() 

Source Link

Document

Get the list of devices

Usage

From source file:org.distantshoresmedia.wifiDirect.DeviceListFragment.java

@Override
public void onPeersAvailable(WifiP2pDeviceList peerList) {

    if (progressDialog != null && progressDialog.isShowing()) {
        progressDialog.dismiss();/*  www  .  j  a va  2s. co m*/
    }
    peers.clear();
    peers.addAll(peerList.getDeviceList());
    listAdapter.notifyDataSetChanged();
    if (peers.size() == 0) {
        Log.d(WiFiDirectActivity.TAG, "No devices found");
        return;
    }

}

From source file:com.github.peejweej.androidsideloading.fragments.DevicesListFragment.java

public void onPeersAvailable(WifiP2pDeviceList peerList) {

    if (progressDialog != null && progressDialog.isShowing()) {
        progressDialog.dismiss();//  w  w w.  ja v  a 2 s .co m
    }
    peers.clear();
    peers.addAll(peerList.getDeviceList());
    listAdapter.notifyDataSetChanged();
    if (peers.size() == 0) {
        Log.d(WiFiDirectActivity.TAG, "No devices found");
        return;
    }

}

From source file:com.alanddev.gmscall.fragment.DeviceListFragment.java

@Override
public void onPeersAvailable(WifiP2pDeviceList peerList) {
    if (progressDialog != null && progressDialog.isShowing()) {
        progressDialog.dismiss();//from  ww  w .j a v  a  2  s  .c o m
    }
    peers.clear();
    peers.addAll(peerList.getDeviceList());
    ((WiFiPeerListAdapter) getListAdapter()).notifyDataSetChanged();
    if (peers.size() == 0) {
        //Log.d(MainActivity.TAG, "No devices found");
        return;
    }
    //printList(peers);
}

From source file:com.example.swiftdatahop.Fragment_ShowPeers.java

@Override
public void onPeersAvailable(WifiP2pDeviceList peerList) {
    if (progressDialog != null && progressDialog.isShowing()) {
        progressDialog.dismiss();//from w  ww. jav  a2  s .c o  m
    }
    peers.clear();
    peers.addAll(peerList.getDeviceList());
    ((WiFiPeerListAdapter) getListAdapter()).notifyDataSetChanged();
    if (peers.size() == 0) {
        Log.d(TAG, "No devices found");
        return;
    }

}

From source file:com.example.android.wifidirect.DeviceListFragment.java

@Override
public void onPeersAvailable(WifiP2pDeviceList peerList) {
    if (mProgressWheel != null && mProgressWheel.isSpinning()) {
        mProgressWheel.setVisibility(View.GONE);
    }//w w w .  j a  v  a  2  s .  c  o m
    //??DeviceListFragmentView
    FileTransmitFragment fileTransmitfragment = (FileTransmitFragment) getActivity().getSupportFragmentManager()
            .findFragmentByTag("android:switcher:" + R.id.pager + ":0");
    fileTransmitfragment.ChangeFragmentHeight(200);
    peers.clear();
    peers.addAll(peerList.getDeviceList());
    //AdapterView?????ListView?
    ((WiFiPeerListAdapter) getListAdapter()).notifyDataSetChanged();
    if (peers.size() == 0) {
        Log.d(WiFiDirectActivity.TAG, "No devices found");
        return;
    }

}

From source file:edu.nust.distributed.downloader.ClientActivity.java

public void displayPeers(final WifiP2pDeviceList peers) {
    //Dialog to show errors/status
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setTitle("WiFi Direct File Transfer");

    //Get list view
    ListView peerView = (ListView) findViewById(R.id.peers_listview);

    //Make array list
    ArrayList<String> peersStringArrayList = new ArrayList<String>();

    //Fill array list with strings of peer names
    for (WifiP2pDevice wd : peers.getDeviceList()) {
        peersStringArrayList.add(wd.deviceName);
    }//from  ww w  . ja  va 2s  .  co  m

    //Set list view as clickable
    peerView.setClickable(true);

    //Make adapter to connect peer data to list view
    ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,
            peersStringArrayList.toArray());

    //Show peer data in listview
    peerView.setAdapter(arrayAdapter);

    peerView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View view, int arg2, long arg3) {

            //Get string from textview
            TextView tv = (TextView) view;

            WifiP2pDevice device = null;

            //Search all known peers for matching name
            for (WifiP2pDevice wd : peers.getDeviceList()) {
                if (wd.deviceName.equals(tv.getText()))
                    device = wd;
            }

            if (device != null) {
                //Connect to selected peer
                connectToPeer(device);

            } else {
                dialog.setMessage("Failed");
                dialog.show();

            }
        }
        // TODO Auto-generated method stub            
    });

}

From source file:com.example.ramesh.p2pfileshare.ClientActivity.java

public void displayPeers(final WifiP2pDeviceList peers) {
    //Dialog to show errors/status
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setTitle("WiFi Direct File Transfer");

    //Get list view
    //ListView peerView = (ListView) findViewById(R.id.peers_listview); //--version2

    //Make array list
    ArrayList<String> peersStringArrayList = new ArrayList<String>();

    //Fill array list with strings of peer names
    for (WifiP2pDevice wd : peers.getDeviceList()) {
        peersStringArrayList.add(wd.deviceName);
    }/*  w  w w  .j a v  a 2 s .c  om*/

    //Set list view as clickable
    //peerView.setClickable(true); --version2

    String[] peersList = new String[peersStringArrayList.size()];
    peersList = peersStringArrayList.toArray(peersList);

    Log.v("WIFIP2PNEW", "Total servers showing " + peersList.length);
    Bundle bundle = new Bundle();
    bundle.putStringArray("server_names", peersList);

    ServerListFragment serverListFragment = new ServerListFragment();
    serverListFragment.setArguments(bundle);

    FragmentManager fm = getSupportFragmentManager();

    ServerListFragment prevFrag = (ServerListFragment) fm.findFragmentById(R.id.myclientlayout);
    if (prevFrag != null) {
        fm.beginTransaction().remove(prevFrag).commit();
        Log.v("WIFIP2PNEW", "Prevs fargment found so removing");
    } else {
        Log.v("WIFIP2PNEW", "No Prevs fargment found so creating new one");
    }

    fm.beginTransaction().add(R.id.myclientlayout, serverListFragment, "myfragement").commit();
    //Make adapter to connect peer data to list view
    /*ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, peersStringArrayList.toArray()); //--version2
            
    //Show peer data in listview
    peerView.setAdapter(arrayAdapter);
               
            
    peerView.setOnItemClickListener(new OnItemClickListener() {
            
      public void onItemClick(AdapterView<?> arg0, View view, int arg2,long arg3) {
            
    //Get string from textview
    TextView tv = (TextView) view;
            
    WifiP2pDevice device = null;
            
    //Search all known peers for matching name
     for(WifiP2pDevice wd : peers.getDeviceList())
     {
        if(wd.deviceName.equals(tv.getText()))
           device = wd;                   
     }
            
    if(device != null)
    {
       //Connect to selected peer
       connectToPeer(device);
                              
    }
    else
    {
       dialog.setMessage("Failed");
       dialog.show();
                              
    }                     
      }         
    // TODO Auto-generated method stub            
      }); //--version2
    */
}

From source file:com.nest5.businessClient.Initialactivity.java

@Override
public void onPeersAvailable(WifiP2pDeviceList peerList) {
    if (!isConnecting) {
        List<WifiP2pDevice> peers = new ArrayList<WifiP2pDevice>();
        peers.clear();//from   ww w  .j  a  va  2s.  co  m
        peers.addAll(peerList.getDeviceList());
        // ((WiFiPeerListAdapter) deviceAdapter).notifyDataSetChanged();
        if (peers.size() == 0) {
            Log.d(Initialactivity.TAG, "No devices found");
            return;
        } else {
            android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
            WifiDirectDialog wifiDirectdialog = new WifiDirectDialog(peers);
            wifiDirectdialog.show(fm, "fragment_edit_name");
        }
    }

}