MonitorApplication.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
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 org.ros.android.robot_monitor;
00018 
00019 import android.content.res.Resources;
00020 import android.graphics.drawable.Drawable;
00021 import android.os.Bundle;
00022 import android.widget.TableLayout;
00023 import android.widget.TextView;
00024 
00025 import org.ros.address.InetAddressFactory;
00026 import org.ros.android.MessageCallable;
00027 import org.ros.android.RosActivity;
00028 import org.ros.node.NodeConfiguration;
00029 import org.ros.node.NodeMainExecutor;
00030 
00031 import diagnostic_msgs.DiagnosticArray;
00032 
00034 import java.net.URI;
00035 
00041 public class MonitorApplication extends RosActivity
00042 {
00043         
00044   private DiagnosticArraySubscriber sub;
00045   private DiagnosticsArrayDisplay dad;
00046 
00047   public MonitorApplication()
00048   {
00049           super("ROS Robot Monitor", "ROS Robot Monitor");
00050   }
00051   
00052   @Override
00053   protected void onPause()
00054   {
00055           super.onPause();
00056   }
00057   
00058   protected void onCreate(Bundle savedInstanceState)
00059   {
00060           super.onCreate(savedInstanceState);
00061           
00062           setContentView(R.layout.main);
00063           this.dad = new DiagnosticsArrayDisplay(this);
00064           TableLayout tl = (TableLayout)findViewById(R.id.maintable);
00065           this.dad.setTableLayout(tl);
00066           TextView tv = (TextView)findViewById(R.id.global);
00067           this.dad.setTextView(tv);
00068           
00069           // TODO Investigate why these icons can be wrong.
00070           Resources res = getResources();
00071           Drawable error = res.getDrawable(R.drawable.error);
00072           Drawable warn = res.getDrawable(R.drawable.warn);
00073           Drawable ok = res.getDrawable(R.drawable.ok);
00074           Drawable stale = res.getDrawable(R.drawable.stale);
00075           this.dad.setDrawables(error, warn, ok, stale);
00076           this.dad.setColors(getResources().getColor(R.color.error), getResources().getColor(R.color.warn), getResources().getColor(R.color.ok), getResources().getColor(R.color.stale));
00077           
00078           this.sub = (DiagnosticArraySubscriber)getLastNonConfigurationInstance();
00079           if(this.sub != null){
00080                   if(this.sub.getLastMessage() != null){
00081                           this.dad.displayArray(this.sub.getLastMessage());
00082                   }
00083           } else {
00084                   this.sub = new DiagnosticArraySubscriber();
00085           }
00086           this.sub.setMessageCallable(new MessageCallable<DiagnosticArray, DiagnosticArray>(){
00087                   @Override
00088                   public DiagnosticArray call(DiagnosticArray message){
00089                           MonitorApplication.this.dad.displayArray(message);
00090                           return message;
00091                   }
00092           });
00093   }
00094   
00095   @Override
00096   protected void onResume()
00097   {
00098                 super.onResume();
00099   }
00100   
00101   @Override
00102   public Object onRetainNonConfigurationInstance(){
00103           this.sub.clearCallable();
00104           return this.sub;
00105   }
00106 
00107   @Override
00108   protected void init(NodeMainExecutor nodeMainExecutor)
00109   {
00110     boolean staticMaster = true;
00111     NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(InetAddressFactory.newNonLoopback().getHostAddress());
00112     if(staticMaster){
00113       nodeConfiguration.setMasterUri(URI.create("http://192.168.15.247:11311/"));
00114     } else {
00115       nodeConfiguration.setMasterUri(getMasterUri());
00116     }
00117     nodeConfiguration.setNodeName("android_robot_monitor");
00118     nodeMainExecutor.execute(this.sub, nodeConfiguration);
00119   }
00120 }


android_robot_monitor
Author(s): Chad Rockey
autogenerated on Sat Dec 28 2013 16:44:07