MainActivity.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.my_android_package;
00018 
00019 import android.os.Bundle;
00020 import org.ros.android.MessageCallable;
00021 import org.ros.android.RosActivity;
00022 import org.ros.android.view.RosTextView;
00023 import org.ros.node.NodeConfiguration;
00024 import org.ros.node.NodeMainExecutor;
00025 import org.ros.rosjava_tutorial_pubsub.Talker;
00026 
00030 public class MainActivity extends RosActivity {
00031 
00032   private RosTextView<std_msgs.String> rosTextView;
00033   private Talker talker;
00034 
00035   public MainActivity() {
00036     // The RosActivity constructor configures the notification title and ticker
00037     // messages.
00038     super("Pubsub Tutorial", "Pubsub Tutorial");
00039   }
00040 
00041   @SuppressWarnings("unchecked")
00042   @Override
00043   public void onCreate(Bundle savedInstanceState) {
00044     super.onCreate(savedInstanceState);
00045     setContentView(R.layout.main);
00046     rosTextView = (RosTextView<std_msgs.String>) findViewById(R.id.text);
00047     rosTextView.setTopicName("chatter");
00048     rosTextView.setMessageType(std_msgs.String._TYPE);
00049     rosTextView.setMessageToStringCallable(new MessageCallable<String, std_msgs.String>() {
00050       @Override
00051       public String call(std_msgs.String message) {
00052         return message.getData();
00053       }
00054     });
00055   }
00056 
00057   @Override
00058   protected void init(NodeMainExecutor nodeMainExecutor) {
00059     talker = new Talker();
00060     NodeConfiguration nodeConfiguration = NodeConfiguration.newPrivate();
00061     // At this point, the user has already been prompted to either enter the URI
00062     // of a master to use or to start a master locally.
00063     nodeConfiguration.setMasterUri(getMasterUri());
00064     nodeMainExecutor.execute(talker, nodeConfiguration);
00065     // The RosTextView is also a NodeMain that must be executed in order to
00066     // start displaying incoming messages.
00067     nodeMainExecutor.execute(rosTextView, nodeConfiguration);
00068   }
00069 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


my_android_package
Author(s): Damon Kohler
autogenerated on Sat Mar 23 2013 19:33:57