MasterBrowser.java
Go to the documentation of this file.
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 package com.github.rosjava.android_extras.ros_master_browser;
00017 
00018 import java.io.IOException;
00019 import java.lang.Thread;
00020 import java.util.ArrayList;
00021 import java.util.List;
00022 import android.app.Activity;
00023 import android.app.ProgressDialog;
00024 import android.os.AsyncTask;
00025 import android.os.Bundle;
00026 import android.content.Context;
00027 import android.view.View;
00028 import android.view.ViewGroup;
00029 import android.view.LayoutInflater;
00030 import android.widget.ListView;
00031 import android.widget.ArrayAdapter;
00032 import android.widget.AdapterView;
00033 import android.widget.AdapterView.OnItemClickListener;
00034 import android.widget.Toast;
00035 import android.widget.TextView;
00036 import android.text.method.ScrollingMovementMethod;
00037 import com.github.rosjava.zeroconf_jmdns_suite.jmdns.DiscoveredService;
00038 import com.github.rosjava.zeroconf_jmdns_suite.jmdns.Zeroconf;
00039 import com.github.rosjava.zeroconf_jmdns_suite.jmdns.ZeroconfDiscoveryHandler;
00040 import com.github.rosjava.android_extras.ros_master_browser.R;
00041 import com.github.rosjava.android_extras.ros_master_browser.DiscoveryAdapter;
00042 import com.github.rosjava.android_extras.ros_master_browser.DiscoveryHandler;
00043 import com.github.rosjava.android_extras.ros_master_browser.DiscoverySetup;
00044 import com.github.rosjava.android_extras.ros_master_browser.Logger;
00045 
00046 // adb logcat System.out:I *:S
00047 // adb logcat zeroconf:I *:S
00048 
00063 public class MasterBrowser extends Activity {
00064         
00065         /********************
00066          * Variables
00067          *******************/
00068         private Zeroconf zeroconf;
00069         private Logger logger;
00070         private TextView tv;
00071         private ListView lv;
00072         private ArrayList<DiscoveredService> discovered_services;
00073     private DiscoveryAdapter discovery_adapter;
00074         private DiscoveryHandler discovery_handler;
00075         
00077     @Override
00078     public void onCreate(Bundle savedInstanceState)
00079     {
00080         super.onCreate(savedInstanceState);
00081         logger = new Logger();
00082         android.util.Log.i("zeroconf","*********** Zeroconf Create **************");
00083         discovered_services = new ArrayList<DiscoveredService>();
00084         setContentView(R.layout.main);
00085         lv = (ListView)findViewById(R.id.discovered_services_view);
00086         discovery_adapter = new DiscoveryAdapter(this, discovered_services);
00087         lv.setAdapter(discovery_adapter);
00088         tv = (TextView)findViewById(R.id.mytextview);
00089         tv.setMovementMethod(new ScrollingMovementMethod());
00090         tv.setText("");
00091 
00092                 zeroconf = new Zeroconf(logger);
00093                 discovery_handler = new DiscoveryHandler(tv, discovery_adapter, discovered_services);
00094                 zeroconf.setDefaultDiscoveryCallback(discovery_handler);
00095 
00096                 new DiscoverySetup(this).execute(zeroconf);
00097     }
00098     
00099     @Override
00100     public void onPause() {
00101         logger.println("*********** Zeroconf Pause **************");
00102                 super.onPause();
00103     }
00104 
00105     @Override
00106     public void onStop() {
00107         logger.println("*********** Zeroconf Stop **************");
00108                 super.onStop();
00109     }
00110     
00111     
00112     @Override
00113     public void onDestroy() {
00114         logger.println("*********** Zeroconf Destroy **************");
00115         zeroconf.removeListener("_ros-master._tcp","local");
00116             zeroconf.removeListener("_ros-master._udp","local");
00117             try {
00118                 zeroconf.shutdown();
00119         } catch (IOException e) {
00120                 e.printStackTrace();
00121         }
00122                 super.onDestroy();
00123     }
00124 }


android_extras
Author(s): Daniel Stonier
autogenerated on Thu Aug 27 2015 12:12:07