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.android_tutorial_camera;
00018 
00019 import android.hardware.Camera;
00020 import android.os.Bundle;
00021 import android.view.MotionEvent;
00022 import android.view.Window;
00023 import android.view.WindowManager;
00024 import android.widget.Toast;
00025 import org.ros.address.InetAddressFactory;
00026 import org.ros.android.RosActivity;
00027 import org.ros.android.view.camera.RosCameraPreviewView;
00028 import org.ros.node.NodeConfiguration;
00029 import org.ros.node.NodeMainExecutor;
00030 
00035 public class MainActivity extends RosActivity {
00036 
00037   private int cameraId;
00038   private RosCameraPreviewView rosCameraPreviewView;
00039 
00040   public MainActivity() {
00041     super("CameraTutorial", "CameraTutorial");
00042   }
00043 
00044   @Override
00045   protected void onCreate(Bundle savedInstanceState) {
00046     super.onCreate(savedInstanceState);
00047     requestWindowFeature(Window.FEATURE_NO_TITLE);
00048     getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
00049     setContentView(R.layout.main);
00050     rosCameraPreviewView = (RosCameraPreviewView) findViewById(R.id.ros_camera_preview_view);
00051   }
00052 
00053   @Override
00054   public boolean onTouchEvent(MotionEvent event) {
00055     if (event.getAction() == MotionEvent.ACTION_UP) {
00056       int numberOfCameras = Camera.getNumberOfCameras();
00057       final Toast toast;
00058       if (numberOfCameras > 1) {
00059         cameraId = (cameraId + 1) % numberOfCameras;
00060         rosCameraPreviewView.releaseCamera();
00061         rosCameraPreviewView.setCamera(Camera.open(cameraId));
00062         toast = Toast.makeText(this, "Switching cameras.", Toast.LENGTH_SHORT);
00063       } else {
00064         toast = Toast.makeText(this, "No alternative cameras to switch to.", Toast.LENGTH_SHORT);
00065       }
00066       runOnUiThread(new Runnable() {
00067         @Override
00068         public void run() {
00069           toast.show();
00070         }
00071       });
00072     }
00073     return true;
00074   }
00075 
00076   @Override
00077   protected void init(NodeMainExecutor nodeMainExecutor) {
00078     cameraId = 0;
00079     rosCameraPreviewView.setCamera(Camera.open(cameraId));
00080     NodeConfiguration nodeConfiguration =
00081         NodeConfiguration.newPublic(InetAddressFactory.newNonLoopback().getHostAddress());
00082     nodeConfiguration.setMasterUri(getMasterUri());
00083     nodeMainExecutor.execute(rosCameraPreviewView, nodeConfiguration);
00084   }
00085 }


android_core
Author(s): Damon Kohler
autogenerated on Thu Aug 27 2015 12:11:33