00001 /* 00002 * Copyright (C) 2013 Yujin Robot. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 00005 * use this file except in compliance with the License. You may obtain a copy of 00006 * the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 00013 * License for the specific language governing permissions and limitations under 00014 * the License. 00015 */ 00016 00017 package com.github.rosjava.android_remocons.robot_remocon.zeroconf; 00018 00019 import java.io.IOException; 00020 import java.util.ArrayList; 00021 00022 import android.content.Context; 00023 import android.widget.ListView; 00024 00025 import com.github.rosjava.zeroconf_jmdns_suite.jmdns.DiscoveredService; 00026 import com.github.rosjava.zeroconf_jmdns_suite.jmdns.Zeroconf; 00027 00028 00029 00030 public class MasterSearcher { 00031 00032 private Zeroconf zeroconf; 00033 private ArrayList<DiscoveredService> discoveredMasters; 00034 private DiscoveryAdapter discoveryAdapter; 00035 private DiscoveryHandler discoveryHandler; 00036 private Logger logger; 00037 00038 public MasterSearcher(Context context,final ListView listView) { 00039 00040 discoveredMasters = new ArrayList<DiscoveredService>(); 00041 00042 discoveryAdapter = new DiscoveryAdapter(context,discoveredMasters); 00043 listView.setAdapter(discoveryAdapter); 00044 listView.setItemsCanFocus(false); 00045 listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 00046 00047 logger = new Logger(); 00048 zeroconf = new Zeroconf(logger); 00049 discoveryHandler = new DiscoveryHandler(discoveryAdapter,discoveredMasters); 00050 zeroconf.setDefaultDiscoveryCallback(discoveryHandler); 00051 00052 new DiscoverySetup(context).execute(zeroconf); 00053 } 00054 00055 public void shutdown() { 00056 try { 00057 zeroconf.shutdown(); 00058 } catch (IOException e) { 00059 e.printStackTrace(); 00060 } 00061 } 00062 00063 }