mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-06-27 09:02:59 +02:00
add a button for toggling front/rear camera
This commit is contained in:
@ -3,8 +3,8 @@ package com.simplemobiletools.camera;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
@ -16,9 +16,10 @@ import butterknife.OnClick;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
@Bind(R.id.viewHolder) RelativeLayout viewHolder;
|
||||
@Bind(R.id.toggle_camera) View toggleCameraBtn;
|
||||
|
||||
private static final String TAG = Preview.class.getSimpleName();
|
||||
private Preview preview;
|
||||
private int currCamera;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -28,12 +29,17 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
currCamera = Camera.CameraInfo.CAMERA_FACING_BACK;
|
||||
preview = new Preview(this, (SurfaceView) findViewById(R.id.surfaceView));
|
||||
preview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
viewHolder.addView(preview);
|
||||
}
|
||||
|
||||
@OnClick(R.id.toggle_camera)
|
||||
public void toggleCamera() {
|
||||
|
||||
}
|
||||
|
||||
@OnClick(R.id.shutter)
|
||||
public void takePicture() {
|
||||
preview.takePicture();
|
||||
@ -43,12 +49,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
try {
|
||||
Camera camera = Camera.open(0);
|
||||
preview.setCamera(camera);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "onResume IOException " + e.getMessage());
|
||||
final int cnt = Camera.getNumberOfCameras();
|
||||
if (cnt == 1) {
|
||||
toggleCameraBtn.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
Camera camera = Camera.open(currCamera);
|
||||
preview.setCamera(camera);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user