DiagnosticsStatusDisplay.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Chad Rockey
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Android Robot Monitor nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 package org.ros.android.robot_monitor;
00031 
00032 /*import org.ros.message.MessageListener;
00033 import org.ros.message.diagnostic_msgs.DiagnosticArray;
00034 import org.ros.message.diagnostic_msgs.DiagnosticStatus;
00035 
00036 import android.app.Activity;
00037 import android.content.Intent;
00038 import android.content.res.Configuration;
00039 import android.content.res.Resources;
00040 import android.os.AsyncTask;
00041 import android.os.Bundle;
00042 import android.view.ViewGroup.LayoutParams;
00043 import android.widget.TableLayout;
00044 import android.widget.TextView;*/
00045 
00050 /*public class DiagnosticsStatusDisplay extends Activity {
00051         private final DiagnosticsStatusDisplay dsd;
00052         private MessageListener<DiagnosticArray> ml;
00053         private String name;
00054         private boolean saveNode;
00055 
00056   public DiagnosticsStatusDisplay() {
00057           dsd = this;
00058   }
00059 
00060   @Override
00061   protected void onCreate(Bundle savedInstanceState) {
00062     super.onCreate(savedInstanceState);
00063     setContentView(R.layout.details);
00064     Intent intent = getIntent();
00065     TextView tname = (TextView)findViewById(R.id.name);
00066     name = intent.getStringExtra("name");
00067     tname.setText(name);
00068     TextView thard = (TextView)findViewById(R.id.hardware_id);
00069     thard.setText(intent.getStringExtra("hardware_id"));
00070     TextView tmess = (TextView)findViewById(R.id.message);
00071     tmess.setText(intent.getStringExtra("message"));
00072     TableLayout tl = (TableLayout)findViewById(R.id.keys);
00073     String[] keys = intent.getStringArrayExtra("keys");
00074     String[] values = intent.getStringArrayExtra("values");
00075     for(int i = 0; i < keys.length; i++){
00076         TextView tv = new TextView(this);
00077         String keystring = keys[i] + ": " + values[i];
00078         tv.setText(keystring);
00079         tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
00080         tl.addView(tv);
00081     }
00082         TextView tv = (TextView)findViewById(R.id.global);
00083         byte level = intent.getByteExtra("level", (byte) 3);
00084         Resources res = getResources();
00085         if(level == 3){ // STALE is not part of the message definitions
00086                 tv.setBackgroundColor(res.getColor(R.color.stale));
00087         } else if(level == DiagnosticStatus.ERROR){
00088                 tv.setBackgroundColor(res.getColor(R.color.error));
00089         } else if(level == DiagnosticStatus.WARN){
00090                 tv.setBackgroundColor(res.getColor(R.color.warn));
00091         } else { // Is OK!
00092                 tv.setBackgroundColor(res.getColor(R.color.ok));
00093         }
00094   }
00095 
00096   @Override
00097   protected void onResume() {
00098     super.onResume();
00099     saveNode = false;
00100         DisplayClass dc = new DisplayClass();
00101     dc.execute();
00102   }
00103 
00104   @Override
00105   protected void onPause() {
00106     super.onPause();
00107     if(!saveNode){
00108             MonitorApplication ma = (MonitorApplication)getApplicationContext();
00109             ma.clear();
00110                 ma.getNodeMainExecutor().shutdownNodeMain(ma);
00111     }
00112   }
00113   
00114   @Override
00115   public void onBackPressed() {
00116           saveNode = true;
00117             MonitorApplication ma = (MonitorApplication)getApplicationContext();
00118             ma.getSubscriber().removeMessageListener(ml);
00119             super.onBackPressed();
00120   }
00121   
00122   @Override
00123   public void onConfigurationChanged(Configuration newConfig) {
00124     super.onConfigurationChanged(newConfig);
00125     setContentView(R.layout.details);
00126   }
00127   
00128         private class DisplayClass extends AsyncTask<String, DiagnosticArray, String> {
00129                 
00130                 @Override
00131                 protected void onPreExecute(){
00132                         
00133                 }
00134         
00135                 @Override
00136                 protected String doInBackground(String... params) {
00137                         MonitorApplication ma = (MonitorApplication)getApplicationContext();
00138                         while(ma.getSubscriber() == null && !isCancelled()){
00139                                 try {
00140                                         Thread.sleep(100);
00141                                 } catch (InterruptedException e) {
00142                                         // TODO Auto-generated catch block
00143                                         e.printStackTrace();
00144                                 }
00145                         }
00146                         ml = new MessageListener<DiagnosticArray>() {
00147                         @Override
00148                         public void onNewMessage(DiagnosticArray message) {
00149                                 publishProgress(message);
00150                         }
00151                         };
00152                         ma.getSubscriber().addMessageListener(ml);
00153                   return null;
00154                 }
00155                 
00156                 @Override
00157                 protected void onProgressUpdate(DiagnosticArray... vals){
00158                         displayArray(vals[0]);
00159                 }
00160                 
00161                 @Override
00162                 protected void onPostExecute(String msg){
00163                         
00164                 }
00165                 
00166                 public void displayArray(DiagnosticArray msg){
00167                         // Find our current status
00168                         for(final DiagnosticStatus ds : msg.status){
00169                                 if(ds.name.equals(name)){
00170                                         // TODO Figure out what marks a diagnostic group
00171                                         if(ds.values.size() == -1 && ds.hardware_id.length() == 0){// Aggregated Diagnostic
00172                                         } else { // Final level diagnostic
00173                                             TextView tname = (TextView)findViewById(R.id.name);
00174                                             if(tname != null){
00175                                                     tname.setText(ds.name);
00176                                                     TextView thard = (TextView)findViewById(R.id.hardware_id);
00177                                                     thard.setText(ds.hardware_id);
00178                                                     TextView tmess = (TextView)findViewById(R.id.message);
00179                                                     tmess.setText(ds.message);
00180                                                     TableLayout tl = (TableLayout)findViewById(R.id.keys);
00181                                                     tl.removeAllViews();
00182                                                     for(int i = 0; i < ds.values.size(); i++){
00183                                                         TextView tv = new TextView(dsd);
00184                                                         String keystring = ds.values.get(i).key + ": " + ds.values.get(i).value;
00185                                                         tv.setText(keystring);
00186                                                         tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
00187                                                         tl.addView(tv);
00188                                                     }
00189                                             }
00190                                         }
00191                                         TextView tv = (TextView)findViewById(R.id.global);
00192                                         byte level = ds.level;
00193                                         Resources res = getResources();
00194                                         if(level == 3){ // STALE is not part of the message definitions
00195                                                 tv.setBackgroundColor(res.getColor(R.color.stale));
00196                                         } else if(level == DiagnosticStatus.ERROR){
00197                                                 tv.setBackgroundColor(res.getColor(R.color.error));
00198                                         } else if(level == DiagnosticStatus.WARN){
00199                                                 tv.setBackgroundColor(res.getColor(R.color.warn));
00200                                         } else { // Is OK!
00201                                                 tv.setBackgroundColor(res.getColor(R.color.ok));
00202                                         }
00203                                 }
00204                         }
00205                 }
00206         }
00207 
00208 }*/


android_robot_monitor
Author(s): Chad Rockey
autogenerated on Sun Oct 5 2014 22:09:23