Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 package org.ros.android.view;
00031
00032 import android.content.Context;
00033 import android.content.res.Resources;
00034 import android.graphics.drawable.Drawable;
00035 import android.util.AttributeSet;
00036 import android.widget.Button;
00037 import android.widget.TableLayout;
00038 import diagnostic_msgs.DiagnosticArray;
00039 import diagnostic_msgs.DiagnosticStatus;
00040 import org.ros.android.android_10.R;
00041 import org.ros.message.MessageListener;
00042 import org.ros.namespace.GraphName;
00043 import org.ros.node.ConnectedNode;
00044 import org.ros.node.Node;
00045 import org.ros.node.NodeMain;
00046 import org.ros.node.topic.Subscriber;
00047
00048 import java.util.List;
00049
00054 public class DiagnosticsArrayView extends TableLayout implements NodeMain {
00055
00060 private static final int STALE = 3;
00061 private static final String DIAGNOSTICS_AGGREGATOR_TOPIC = "/diagnostics_agg";
00062
00063 private Drawable errorDrawable;
00064 private Drawable warningDrawable;
00065 private Drawable okDrawable;
00066 private Drawable staleDrawable;
00067
00068 public DiagnosticsArrayView(Context context) {
00069 super(context);
00070 init();
00071 }
00072
00073 public DiagnosticsArrayView(Context context, AttributeSet attrs) {
00074 super(context, attrs);
00075 init();
00076 }
00077
00078 private void init() {
00079 Resources resources = getResources();
00080 errorDrawable = resources.getDrawable(R.drawable.error);
00081 warningDrawable = resources.getDrawable(R.drawable.warn);
00082 okDrawable = resources.getDrawable(R.drawable.ok);
00083 staleDrawable = resources.getDrawable(R.drawable.stale);
00084 }
00085
00086 @Override
00087 public GraphName getDefaultNodeName() {
00088 return GraphName.of("android_10/diagnostics_array_view");
00089 }
00090
00091 @Override
00092 public void onStart(ConnectedNode connectedNode) {
00093 Subscriber<DiagnosticArray> subscriber =
00094 connectedNode.newSubscriber(DIAGNOSTICS_AGGREGATOR_TOPIC,
00095 diagnostic_msgs.DiagnosticArray._TYPE);
00096 subscriber.addMessageListener(new MessageListener<DiagnosticArray>() {
00097 @Override
00098 public void onNewMessage(final DiagnosticArray message) {
00099 final List<DiagnosticStatus> diagnosticStatusMessages = message.getStatus();
00100 post(new Runnable() {
00101 @Override
00102 public void run() {
00103 removeAllViews();
00104 for (final DiagnosticStatus diagnosticStatusMessage : diagnosticStatusMessages) {
00105 Button button = new Button(getContext());
00106 button.setText(diagnosticStatusMessage.getName());
00107 if (diagnosticStatusMessage.getLevel() == STALE) {
00108 button.setCompoundDrawablesWithIntrinsicBounds(staleDrawable, null, null, null);
00109 } else if (diagnosticStatusMessage.getLevel() == DiagnosticStatus.ERROR) {
00110 button.setCompoundDrawablesWithIntrinsicBounds(errorDrawable, null, null, null);
00111 } else if (diagnosticStatusMessage.getLevel() == DiagnosticStatus.WARN) {
00112 button.setCompoundDrawablesWithIntrinsicBounds(warningDrawable, null, null, null);
00113 } else {
00114 button.setCompoundDrawablesWithIntrinsicBounds(okDrawable, null, null, null);
00115 }
00116 addView(button);
00117 }
00118 }
00119 });
00120 postInvalidate();
00121 }
00122 });
00123 }
00124
00125 @Override
00126 public void onError(Node node, Throwable throwable) {
00127 }
00128
00129 @Override
00130 public void onShutdown(Node node) {
00131 }
00132
00133 @Override
00134 public void onShutdownComplete(Node node) {
00135 }
00136 }