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.common_tools.zeroconf; 00018 00019 import android.content.Context; 00020 import android.widget.ListView; 00021 00022 import com.github.rosjava.zeroconf_jmdns_suite.jmdns.DiscoveredService; 00023 import com.github.rosjava.zeroconf_jmdns_suite.jmdns.Zeroconf; 00024 00025 import java.io.IOException; 00026 import java.util.ArrayList; 00027 00028 00029 public class MasterSearcher { 00030 00031 private Zeroconf zeroconf; 00032 private ArrayList<DiscoveredService> discoveredMasters; 00033 private DiscoveryAdapter discoveryAdapter; 00034 private DiscoveryHandler discoveryHandler; 00035 private Logger logger; 00036 00037 public MasterSearcher(Context context, final ListView listView, 00038 String targetServiceName, int targetServiceDrawable, int otherServicesDrawable) { 00039 00040 discoveredMasters = new ArrayList<DiscoveredService>(); 00041 00042 discoveryAdapter = new DiscoveryAdapter(context, discoveredMasters, 00043 targetServiceName, targetServiceDrawable, otherServicesDrawable); 00044 listView.setAdapter(discoveryAdapter); 00045 listView.setItemsCanFocus(false); 00046 listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 00047 00048 logger = new Logger(); 00049 zeroconf = new Zeroconf(logger); 00050 discoveryHandler = new DiscoveryHandler(discoveryAdapter, discoveredMasters); 00051 zeroconf.setDefaultDiscoveryCallback(discoveryHandler); 00052 00053 new DiscoverySetup(context).execute(zeroconf); 00054 } 00055 00056 public void shutdown() { 00057 try { 00058 zeroconf.shutdown(); 00059 } catch (IOException e) { 00060 e.printStackTrace(); 00061 } 00062 } 00063 00064 }