Can't use photo callback without cameraFragmentResultListener #11

pull/17/head
florent champigny 8 years ago
parent a7dc19664f
commit 6a8db6fc69
  1. 85
      app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java
  2. 4
      camerafragment/src/main/java/com/github/florent37/camerafragment/internal/ui/BaseAnncaFragment.java

@ -1,7 +1,6 @@
package com.github.florent37.camerafragment.sample; package com.github.florent37.camerafragment.sample;
import android.Manifest; import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -12,21 +11,14 @@ import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.github.florent37.camerafragment.CameraFragment; import com.github.florent37.camerafragment.CameraFragment;
import com.github.florent37.camerafragment.CameraFragmentApi; import com.github.florent37.camerafragment.CameraFragmentApi;
import com.github.florent37.camerafragment.configuration.Configuration; import com.github.florent37.camerafragment.configuration.Configuration;
import com.github.florent37.camerafragment.PreviewActivity;
import com.github.florent37.camerafragment.listeners.CameraFragmentStateListener;
import com.github.florent37.camerafragment.listeners.CameraFragmentControlsListener; import com.github.florent37.camerafragment.listeners.CameraFragmentControlsListener;
import com.github.florent37.camerafragment.listeners.CameraFragmentResultListener; import com.github.florent37.camerafragment.listeners.CameraFragmentResultListener;
import com.github.florent37.camerafragment.listeners.CameraFragmentStateListener;
import com.github.florent37.camerafragment.listeners.CameraFragmentVideoRecordTextListener; import com.github.florent37.camerafragment.listeners.CameraFragmentVideoRecordTextListener;
import com.github.florent37.camerafragment.widgets.CameraSettingsView; import com.github.florent37.camerafragment.widgets.CameraSettingsView;
import com.github.florent37.camerafragment.widgets.CameraSwitchView; import com.github.florent37.camerafragment.widgets.CameraSwitchView;
@ -34,24 +26,39 @@ import com.github.florent37.camerafragment.widgets.FlashSwitchView;
import com.github.florent37.camerafragment.widgets.MediaActionSwitchView; import com.github.florent37.camerafragment.widgets.MediaActionSwitchView;
import com.github.florent37.camerafragment.widgets.RecordButton; import com.github.florent37.camerafragment.widgets.RecordButton;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
public static final String FRAGMENT_TAG = "camera";
private static final int REQUEST_CAMERA_PERMISSIONS = 931; private static final int REQUEST_CAMERA_PERMISSIONS = 931;
private static final int REQUEST_PREVIEW_CODE = 1001; private static final int REQUEST_PREVIEW_CODE = 1001;
@Bind(R.id.settings_view)
public static final String FRAGMENT_TAG = "camera"; CameraSettingsView settingsView;
@Bind(R.id.flash_switch_view)
@Bind(R.id.settings_view) CameraSettingsView settingsView; FlashSwitchView flashSwitchView;
@Bind(R.id.flash_switch_view) FlashSwitchView flashSwitchView; @Bind(R.id.front_back_camera_switcher)
@Bind(R.id.front_back_camera_switcher) CameraSwitchView cameraSwitchView; CameraSwitchView cameraSwitchView;
@Bind(R.id.record_button) RecordButton recordButton; @Bind(R.id.record_button)
@Bind(R.id.photo_video_camera_switcher) MediaActionSwitchView mediaActionSwitchView; RecordButton recordButton;
@Bind(R.id.photo_video_camera_switcher)
@Bind(R.id.record_duration_text) TextView recordDurationText; MediaActionSwitchView mediaActionSwitchView;
@Bind(R.id.record_size_mb_text) TextView recordSizeText;
@Bind(R.id.record_duration_text)
@Bind(R.id.cameraLayout) View cameraLayout; TextView recordDurationText;
@Bind(R.id.addCameraButton) View addCameraButton; @Bind(R.id.record_size_mb_text)
TextView recordSizeText;
@Bind(R.id.cameraLayout)
View cameraLayout;
@Bind(R.id.addCameraButton)
View addCameraButton;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -83,12 +90,12 @@ public class MainActivity extends AppCompatActivity {
cameraFragment.takePhotoOrCaptureVideo(new CameraFragmentResultListener() { cameraFragment.takePhotoOrCaptureVideo(new CameraFragmentResultListener() {
@Override @Override
public void onVideoRecorded(String filePath) { public void onVideoRecorded(String filePath) {
Toast.makeText(getBaseContext(), "onVideoRecorded " + filePath, Toast.LENGTH_SHORT).show();
} }
@Override @Override
public void onPhotoTaken(byte[] bytes, String filePath) { public void onPhotoTaken(byte[] bytes, String filePath) {
Toast.makeText(getBaseContext(), "onPhotoTaken " + filePath, Toast.LENGTH_SHORT).show();
} }
}); });
} }
@ -153,19 +160,19 @@ public class MainActivity extends AppCompatActivity {
.commit(); .commit();
if (cameraFragment != null) { if (cameraFragment != null) {
cameraFragment.setResultListener(new CameraFragmentResultListener() { //cameraFragment.setResultListener(new CameraFragmentResultListener() {
@Override // @Override
public void onVideoRecorded(String filePath) { // public void onVideoRecorded(String filePath) {
Intent intent = PreviewActivity.newIntentVideo(MainActivity.this, filePath); // Intent intent = PreviewActivity.newIntentVideo(MainActivity.this, filePath);
startActivityForResult(intent, REQUEST_PREVIEW_CODE); // startActivityForResult(intent, REQUEST_PREVIEW_CODE);
} // }
//
@Override // @Override
public void onPhotoTaken(byte[] bytes, String filePath) { // public void onPhotoTaken(byte[] bytes, String filePath) {
Intent intent = PreviewActivity.newIntentPhoto(MainActivity.this, filePath); // Intent intent = PreviewActivity.newIntentPhoto(MainActivity.this, filePath);
startActivityForResult(intent, REQUEST_PREVIEW_CODE); // startActivityForResult(intent, REQUEST_PREVIEW_CODE);
} // }
}); //});
cameraFragment.setStateListener(new CameraFragmentStateListener() { cameraFragment.setStateListener(new CameraFragmentStateListener() {

@ -197,14 +197,14 @@ public abstract class BaseAnncaFragment<CameraId> extends Fragment implements Ca
@Override @Override
public void onPhotoTaken(byte[] bytes, CameraFragmentResultListener callback) { public void onPhotoTaken(byte[] bytes, CameraFragmentResultListener callback) {
if (cameraFragmentResultListener != null) {
final String filePath = cameraController.getOutputFile().toString(); final String filePath = cameraController.getOutputFile().toString();
if (cameraFragmentResultListener != null) {
cameraFragmentResultListener.onPhotoTaken(bytes, filePath); cameraFragmentResultListener.onPhotoTaken(bytes, filePath);
}
if (callback != null) { if (callback != null) {
callback.onPhotoTaken(bytes, filePath); callback.onPhotoTaken(bytes, filePath);
} }
} }
}
@Override @Override
public void onVideoRecordStart(int width, int height) { public void onVideoRecordStart(int width, int height) {

Loading…
Cancel
Save