From c94265669b917a75a42f95354af3124368786a0b Mon Sep 17 00:00:00 2001 From: Skalaw Date: Sat, 25 Feb 2017 09:46:21 +0100 Subject: [PATCH] Derive from Adapter and only override what you need --- .../camerafragment/sample/MainActivity.java | 16 ++-- .../CameraFragmentControlsAdapter.java | 33 ++++++++ .../CameraFragmentResultAdapter.java | 18 +++++ .../listeners/CameraFragmentStateAdapter.java | 75 +++++++++++++++++++ .../CameraFragmentVideoRecordTextAdapter.java | 28 +++++++ 5 files changed, 162 insertions(+), 8 deletions(-) create mode 100644 camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentControlsAdapter.java create mode 100644 camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentResultAdapter.java create mode 100644 camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentStateAdapter.java create mode 100644 camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentVideoRecordTextAdapter.java diff --git a/app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java b/app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java index 83de9c4..e4c1ad6 100644 --- a/app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java +++ b/app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java @@ -16,10 +16,10 @@ import android.widget.Toast; import com.github.florent37.camerafragment.CameraFragment; import com.github.florent37.camerafragment.CameraFragmentApi; import com.github.florent37.camerafragment.configuration.Configuration; -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.listeners.CameraFragmentControlsAdapter; +import com.github.florent37.camerafragment.listeners.CameraFragmentResultAdapter; +import com.github.florent37.camerafragment.listeners.CameraFragmentStateAdapter; +import com.github.florent37.camerafragment.listeners.CameraFragmentVideoRecordTextAdapter; import com.github.florent37.camerafragment.widgets.CameraSettingsView; import com.github.florent37.camerafragment.widgets.CameraSwitchView; import com.github.florent37.camerafragment.widgets.FlashSwitchView; @@ -87,7 +87,7 @@ public class MainActivity extends AppCompatActivity { public void onRecordButtonClicked() { final CameraFragmentApi cameraFragment = getCameraFragment(); if (cameraFragment != null) { - cameraFragment.takePhotoOrCaptureVideo(new CameraFragmentResultListener() { + cameraFragment.takePhotoOrCaptureVideo(new CameraFragmentResultAdapter() { @Override public void onVideoRecorded(String filePath) { Toast.makeText(getBaseContext(), "onVideoRecorded " + filePath, Toast.LENGTH_SHORT).show(); @@ -176,7 +176,7 @@ public class MainActivity extends AppCompatActivity { // } //}); - cameraFragment.setStateListener(new CameraFragmentStateListener() { + cameraFragment.setStateListener(new CameraFragmentStateAdapter() { @Override public void onCurrentCameraBack() { @@ -255,7 +255,7 @@ public class MainActivity extends AppCompatActivity { } }); - cameraFragment.setControlsListener(new CameraFragmentControlsListener() { + cameraFragment.setControlsListener(new CameraFragmentControlsAdapter() { @Override public void lockControls() { cameraSwitchView.setEnabled(false); @@ -288,7 +288,7 @@ public class MainActivity extends AppCompatActivity { } }); - cameraFragment.setTextListener(new CameraFragmentVideoRecordTextListener() { + cameraFragment.setTextListener(new CameraFragmentVideoRecordTextAdapter() { @Override public void setRecordSizeText(long size, String text) { recordSizeText.setText(text); diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentControlsAdapter.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentControlsAdapter.java new file mode 100644 index 0000000..4e2f198 --- /dev/null +++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentControlsAdapter.java @@ -0,0 +1,33 @@ +package com.github.florent37.camerafragment.listeners; + +/** + * Convenience implementation of {@link CameraFragmentControlsListener}. Derive from this and only override what you need. + * @author Skala + */ + +public class CameraFragmentControlsAdapter implements CameraFragmentControlsListener { + @Override + public void lockControls() { + + } + + @Override + public void unLockControls() { + + } + + @Override + public void allowCameraSwitching(boolean allow) { + + } + + @Override + public void allowRecord(boolean allow) { + + } + + @Override + public void setMediaActionSwitchVisible(boolean visible) { + + } +} diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentResultAdapter.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentResultAdapter.java new file mode 100644 index 0000000..8515aaa --- /dev/null +++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentResultAdapter.java @@ -0,0 +1,18 @@ +package com.github.florent37.camerafragment.listeners; + +/** + * Convenience implementation of {@link CameraFragmentResultListener}. Derive from this and only override what you need. + * @author Skala + */ + +public class CameraFragmentResultAdapter implements CameraFragmentResultListener { + @Override + public void onVideoRecorded(String filePath) { + + } + + @Override + public void onPhotoTaken(byte[] bytes, String filePath) { + + } +} diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentStateAdapter.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentStateAdapter.java new file mode 100644 index 0000000..8a4b0f9 --- /dev/null +++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentStateAdapter.java @@ -0,0 +1,75 @@ +package com.github.florent37.camerafragment.listeners; + +import java.io.File; + +/** + * Convenience implementation of {@link CameraFragmentStateListener}. Derive from this and only override what you need. + * @author Skala + */ + +public class CameraFragmentStateAdapter implements CameraFragmentStateListener { + @Override + public void onCurrentCameraBack() { + + } + + @Override + public void onCurrentCameraFront() { + + } + + @Override + public void onFlashAuto() { + + } + + @Override + public void onFlashOn() { + + } + + @Override + public void onFlashOff() { + + } + + @Override + public void onCameraSetupForPhoto() { + + } + + @Override + public void onCameraSetupForVideo() { + + } + + @Override + public void onRecordStateVideoReadyForRecord() { + + } + + @Override + public void onRecordStateVideoInProgress() { + + } + + @Override + public void onRecordStatePhoto() { + + } + + @Override + public void shouldRotateControls(int degrees) { + + } + + @Override + public void onStartVideoRecord(File outputFile) { + + } + + @Override + public void onStopVideoRecord() { + + } +} diff --git a/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentVideoRecordTextAdapter.java b/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentVideoRecordTextAdapter.java new file mode 100644 index 0000000..09a68f1 --- /dev/null +++ b/camerafragment/src/main/java/com/github/florent37/camerafragment/listeners/CameraFragmentVideoRecordTextAdapter.java @@ -0,0 +1,28 @@ +package com.github.florent37.camerafragment.listeners; + +/** + * Convenience implementation of {@link CameraFragmentVideoRecordTextListener}. Derive from this and only override what you need. + * @author Skala + */ + +public class CameraFragmentVideoRecordTextAdapter implements CameraFragmentVideoRecordTextListener { + @Override + public void setRecordSizeText(long size, String text) { + + } + + @Override + public void setRecordSizeTextVisible(boolean visible) { + + } + + @Override + public void setRecordDurationText(String text) { + + } + + @Override + public void setRecordDurationTextVisible(boolean visible) { + + } +}