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;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
@ -12,21 +11,14 @@ import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
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.CameraFragmentApi;
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.CameraFragmentResultListener;
import com.github.florent37.camerafragment.listeners.CameraFragmentStateListener;
import com.github.florent37.camerafragment.listeners.CameraFragmentVideoRecordTextListener;
import com.github.florent37.camerafragment.widgets.CameraSettingsView;
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.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 static final String FRAGMENT_TAG = "camera";
private static final int REQUEST_CAMERA_PERMISSIONS = 931;
private static final int REQUEST_PREVIEW_CODE = 1001;
public static final String FRAGMENT_TAG = "camera";
@Bind(R.id.settings_view) CameraSettingsView settingsView;
@Bind(R.id.flash_switch_view) FlashSwitchView flashSwitchView;
@Bind(R.id.front_back_camera_switcher) CameraSwitchView cameraSwitchView;
@Bind(R.id.record_button) RecordButton recordButton;
@Bind(R.id.photo_video_camera_switcher) MediaActionSwitchView mediaActionSwitchView;
@Bind(R.id.record_duration_text) TextView recordDurationText;
@Bind(R.id.record_size_mb_text) TextView recordSizeText;
@Bind(R.id.cameraLayout) View cameraLayout;
@Bind(R.id.addCameraButton) View addCameraButton;
@Bind(R.id.settings_view)
CameraSettingsView settingsView;
@Bind(R.id.flash_switch_view)
FlashSwitchView flashSwitchView;
@Bind(R.id.front_back_camera_switcher)
CameraSwitchView cameraSwitchView;
@Bind(R.id.record_button)
RecordButton recordButton;
@Bind(R.id.photo_video_camera_switcher)
MediaActionSwitchView mediaActionSwitchView;
@Bind(R.id.record_duration_text)
TextView recordDurationText;
@Bind(R.id.record_size_mb_text)
TextView recordSizeText;
@Bind(R.id.cameraLayout)
View cameraLayout;
@Bind(R.id.addCameraButton)
View addCameraButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -83,12 +90,12 @@ public class MainActivity extends AppCompatActivity {
cameraFragment.takePhotoOrCaptureVideo(new CameraFragmentResultListener() {
@Override
public void onVideoRecorded(String filePath) {
Toast.makeText(getBaseContext(), "onVideoRecorded " + filePath, Toast.LENGTH_SHORT).show();
}
@Override
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();
if (cameraFragment != null) {
cameraFragment.setResultListener(new CameraFragmentResultListener() {
@Override
public void onVideoRecorded(String filePath) {
Intent intent = PreviewActivity.newIntentVideo(MainActivity.this, filePath);
startActivityForResult(intent, REQUEST_PREVIEW_CODE);
}
@Override
public void onPhotoTaken(byte[] bytes, String filePath) {
Intent intent = PreviewActivity.newIntentPhoto(MainActivity.this, filePath);
startActivityForResult(intent, REQUEST_PREVIEW_CODE);
}
});
//cameraFragment.setResultListener(new CameraFragmentResultListener() {
// @Override
// public void onVideoRecorded(String filePath) {
// Intent intent = PreviewActivity.newIntentVideo(MainActivity.this, filePath);
// startActivityForResult(intent, REQUEST_PREVIEW_CODE);
// }
//
// @Override
// public void onPhotoTaken(byte[] bytes, String filePath) {
// Intent intent = PreviewActivity.newIntentPhoto(MainActivity.this, filePath);
// startActivityForResult(intent, REQUEST_PREVIEW_CODE);
// }
//});
cameraFragment.setStateListener(new CameraFragmentStateListener() {

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

Loading…
Cancel
Save