RosImageView.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.view;
00018 
00019 import android.content.Context;
00020 import android.graphics.Bitmap;
00021 import android.util.AttributeSet;
00022 import android.widget.ImageView;
00023 import org.ros.android.MessageCallable;
00024 import org.ros.message.MessageListener;
00025 import org.ros.namespace.GraphName;
00026 import org.ros.node.ConnectedNode;
00027 import org.ros.node.Node;
00028 import org.ros.node.NodeMain;
00029 import org.ros.node.topic.Subscriber;
00030 
00037 public class RosImageView<T> extends ImageView implements NodeMain {
00038 
00039   private String topicName;
00040   private String messageType;
00041   private MessageCallable<Bitmap, T> callable;
00042 
00043   public RosImageView(Context context) {
00044     super(context);
00045   }
00046 
00047   public RosImageView(Context context, AttributeSet attrs) {
00048     super(context, attrs);
00049   }
00050 
00051   public RosImageView(Context context, AttributeSet attrs, int defStyle) {
00052     super(context, attrs, defStyle);
00053   }
00054 
00055   public void setTopicName(String topicName) {
00056     this.topicName = topicName;
00057   }
00058 
00059   public void setMessageType(String messageType) {
00060     this.messageType = messageType;
00061   }
00062 
00063   public void setMessageToBitmapCallable(MessageCallable<Bitmap, T> callable) {
00064     this.callable = callable;
00065   }
00066 
00067   @Override
00068   public GraphName getDefaultNodeName() {
00069     return GraphName.of("ros_image_view");
00070   }
00071 
00072   @Override
00073   public void onStart(ConnectedNode connectedNode) {
00074     Subscriber<T> subscriber = connectedNode.newSubscriber(topicName, messageType);
00075     subscriber.addMessageListener(new MessageListener<T>() {
00076       @Override
00077       public void onNewMessage(final T message) {
00078         post(new Runnable() {
00079           @Override
00080           public void run() {
00081             setImageBitmap(callable.call(message));
00082           }
00083         });
00084         postInvalidate();
00085       }
00086     });
00087   }
00088 
00089   @Override
00090   public void onShutdown(Node node) {
00091   }
00092 
00093   @Override
00094   public void onShutdownComplete(Node node) {
00095   }
00096 
00097   @Override
00098   public void onError(Node node, Throwable throwable) {
00099   }
00100 }


android_core
Author(s): Damon Kohler
autogenerated on Thu Jun 6 2019 21:20:07