DiscoveryAdapter.java
Go to the documentation of this file.
00001 package ros.zeroconf.android.jmdns.master_browser;
00002 
00003 import java.util.ArrayList;
00004 import android.content.Context;
00005 import android.view.LayoutInflater;
00006 import android.view.View;
00007 import android.view.ViewGroup;
00008 import android.widget.ArrayAdapter;
00009 import android.widget.ImageView;
00010 import android.widget.TextView;
00011 import org.ros.message.zeroconf_comms.DiscoveredService;
00012 
00013 public class DiscoveryAdapter extends ArrayAdapter<DiscoveredService> {
00014 
00015         private final Context context;
00016         private ArrayList<DiscoveredService> discovered_services;
00017 
00018     public DiscoveryAdapter(Context context, ArrayList<DiscoveredService> discovered_services) {
00019         super(context, R.layout.row_layout,discovered_services); // pass the list to the super
00020         this.context = context;
00021         this.discovered_services = discovered_services;  // keep a pointer locally so we can play with it
00022     }
00023 
00024     @Override
00025     public View getView(int position, View convertView, ViewGroup parent) {
00026         View v = convertView;
00027         if (v == null) {
00028             LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
00029             v = vi.inflate(R.layout.row_layout, null);
00030         }
00031         DiscoveredService discovered_service = discovered_services.get(position);
00032         if (discovered_service != null) {
00033                 TextView tt = (TextView) v.findViewById(R.id.service_name);
00034                 TextView bt = (TextView) v.findViewById(R.id.service_detail);
00035                 if (tt != null) {
00036                     tt.setText(discovered_service.name);                            
00037                 }
00038                 if( bt != null ) {
00039                         String result = "";
00040                         for ( String address : discovered_service.ipv4_addresses ) {
00041                                 if ( result.equals("") ) {
00042                                         result += address + ":" + discovered_service.port;
00043                                 } else { 
00044                                         result += "\n" + address + ":" + discovered_service.port;
00045                                 }
00046                         }
00047                         for ( String address : discovered_service.ipv6_addresses ) {
00048                                 if ( result.equals("") ) {
00049                                         result += address + ":" + discovered_service.port;
00050                                 } else { 
00051                                         result += "\n" + address + ":" + discovered_service.port;
00052                                 }
00053                         }
00054                     bt.setText(result);
00055                 }
00056                 ImageView im = (ImageView) v.findViewById(R.id.icon);
00057                 if ( im != null ) {
00058                         if ( discovered_service.type.equals("_ros-master._tcp" ) ||
00059                                  discovered_service.type.equals("_ros-master._udp" ) ) {
00060                         im.setImageDrawable(context.getResources().getDrawable(R.drawable.turtle));
00061                         } else if ( 
00062                                  discovered_service.type.equals("_app-manager._tcp" ) ||
00063                                  discovered_service.type.equals("_app-manager._udp" ) ) {
00064                         im.setImageDrawable(context.getResources().getDrawable(R.drawable.app_manager));
00065                         } else {
00066                         im.setImageDrawable(context.getResources().getDrawable(R.drawable.conductor));
00067                         }
00068                 }
00069         }
00070         return v;
00071     }
00072 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations


zeroconf_android_master_browser
Author(s): Daniel Stonier
autogenerated on Fri Apr 26 2013 20:45:18