Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 package com.github.rosjava.android_extras.ros_master_browser;
00017
00018 import java.util.ArrayList;
00019 import android.content.Context;
00020 import android.view.LayoutInflater;
00021 import android.view.View;
00022 import android.view.ViewGroup;
00023 import android.widget.ArrayAdapter;
00024 import android.widget.ImageView;
00025 import android.widget.TextView;
00026
00027 import com.github.rosjava.android_extras.ros_master_browser.R;
00028 import com.github.rosjava.zeroconf_jmdns_suite.jmdns.DiscoveredService;
00029
00030 import java.net.Inet4Address;
00031 import java.net.Inet6Address;
00032
00033 public class DiscoveryAdapter extends ArrayAdapter<DiscoveredService> {
00034
00035 private final Context context;
00036 private ArrayList<DiscoveredService> discovered_services;
00037
00038 public DiscoveryAdapter(Context context, ArrayList<DiscoveredService> discovered_services) {
00039 super(context, R.layout.row_layout,discovered_services);
00040 this.context = context;
00041 this.discovered_services = discovered_services;
00042 }
00043
00044 @Override
00045 public View getView(int position, View convertView, ViewGroup parent) {
00046 View v = convertView;
00047 if (v == null) {
00048 LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
00049 v = vi.inflate(R.layout.row_layout, null);
00050 }
00051 DiscoveredService discovered_service = discovered_services.get(position);
00052 if (discovered_service != null) {
00053 TextView tt = (TextView) v.findViewById(R.id.service_name);
00054 TextView bt = (TextView) v.findViewById(R.id.service_detail);
00055 if (tt != null) {
00056 tt.setText(discovered_service.name);
00057 }
00058 if( bt != null ) {
00059 String result = "";
00060 for ( String address : discovered_service.ipv4_addresses ) {
00061 if ( result.equals("") ) {
00062 result += address + ":" + discovered_service.port;
00063 } else {
00064 result += "\n" + address + ":" + discovered_service.port;
00065 }
00066 }
00067 for ( String address : discovered_service.ipv6_addresses ) {
00068 if ( result.equals("") ) {
00069 result += address + ":" + discovered_service.port;
00070 } else {
00071 result += "\n" + address + ":" + discovered_service.port;
00072 }
00073 }
00074 bt.setText(result);
00075 }
00076 ImageView im = (ImageView) v.findViewById(R.id.icon);
00077 if ( im != null ) {
00078 if ( discovered_service.type.equals("_ros-master._tcp" ) ||
00079 discovered_service.type.equals("_ros-master._udp" ) ) {
00080 im.setImageDrawable(context.getResources().getDrawable(R.drawable.turtle));
00081 } else {
00082
00083 im.setImageDrawable(context.getResources().getDrawable(R.drawable.conductor));
00084 }
00085 }
00086 }
00087 return v;
00088 }
00089 }