From 1c219d40f00d8df004f02d6aae2e550a5c8d02fc Mon Sep 17 00:00:00 2001 From: Florent CHAMPIGNY Date: Mon, 16 Jan 2017 10:55:09 +0100 Subject: [PATCH] Added CameraApi --- README.md | 4 +- .../camerafragment/sample/MainActivity.java | 106 +++++++-------- app/src/main/res/layout/activity_fragment.xml | 8 -- .../camerafragment/CameraFragmentApi.java | 32 +++++ .../internal/controller/CameraController.java | 5 +- .../controller/impl/Camera1Controller.java | 20 +-- .../controller/impl/Camera2Controller.java | 20 +-- .../internal/controller/view/CameraView.java | 6 +- .../internal/manager/CameraManager.java | 5 +- .../internal/manager/impl/Camera1Manager.java | 114 ++++++++-------- .../internal/manager/impl/Camera2Manager.java | 89 ++++++------- .../manager/listener/CameraPhotoListener.java | 4 +- .../manager/listener/CameraVideoListener.java | 3 +- .../internal/ui/BaseAnncaFragment.java | 124 +++++++++--------- .../widgets/CameraSwitchView.java | 19 --- .../widgets/FlashSwitchView.java | 19 --- 16 files changed, 268 insertions(+), 310 deletions(-) create mode 100644 camerafragment/src/main/java/com/github/florent37/camerafragment/CameraFragmentApi.java diff --git a/README.md b/README.md index db59d50..165ce20 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ getSupportFragmentManager().beginTransaction() You can directly take a photo / video with ```java -cameraFragment.takePhotoOrCaptureVideo(); +cameraFragment.takePhotoOrCaptureVideo(callback); ``` [![gif](https://raw.githubusercontent.com/florent37/CameraFragment/master/media/take_photo.gif)](https://github.com/florent37/CameraFragment) @@ -39,7 +39,7 @@ cameraFragment.switchCameraType(); Camera action ( `PHOTO` / `VIDEO` ) can be modified with ```java -cameraFragment.switchAction(); +cameraFragment.switchActionPhotoVideo(); ``` [![gif](https://raw.githubusercontent.com/florent37/CameraFragment/master/media/switch_action.gif)](https://github.com/florent37/CameraFragment) 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 4cfb750..96adc0b 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 @@ -21,6 +21,7 @@ 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; @@ -57,74 +58,56 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fragment); ButterKnife.bind(this); + } - recordButton.setVisibility(View.GONE); - settingsView.setVisibility(View.GONE); - flashSwitchView.setVisibility(View.GONE); - cameraSwitchView.setVisibility(View.GONE); - mediaActionSwitchView.setVisibility(View.GONE); - - setupViewListeners(); + @OnClick(R.id.flash_switch_view) + public void onFlashSwitcClicked(){ + final CameraFragmentApi cameraFragment = getCameraFragment(); + if (cameraFragment != null) { + cameraFragment.toggleFlashMode(); + } } - @OnClick(R.id.take_photo) - public void takePhotoClicked(){ - final CameraFragment cameraFragment = getCameraFragment(); + @OnClick(R.id.front_back_camera_switcher) + public void onSwitchCameraClicked(){ + final CameraFragmentApi cameraFragment = getCameraFragment(); if (cameraFragment != null) { - cameraFragment.takePhotoOrCaptureVideo(); + cameraFragment.switchCameraType(); } } - private void setupViewListeners() { - flashSwitchView.setFlashSwitchListener(new FlashSwitchView.FlashModeSwitchListener() { - @Override - public void toggleFlashMode() { - final CameraFragment cameraFragment = getCameraFragment(); - if (cameraFragment != null) { - cameraFragment.toggleFlashMode(); - } - } - }); - - cameraSwitchView.setOnCameraTypeChangeListener(new CameraSwitchView.OnCameraTypeChangeListener() { - @Override - public void switchCameraType() { - final CameraFragment cameraFragment = getCameraFragment(); - if (cameraFragment != null) { - cameraFragment.switchCameraType(); - } - } - }); - - recordButton.setRecordButtonListener(new RecordButton.RecordButtonListener() { - @Override - public void onRecordButtonClicked() { - final CameraFragment cameraFragment = getCameraFragment(); - if (cameraFragment != null) { - cameraFragment.takePhotoOrCaptureVideo(); - } - } - }); - - mediaActionSwitchView.setOnMediaActionStateChangeListener(new MediaActionSwitchView.OnMediaActionStateChangeListener() { - @Override - public void switchAction() { - final CameraFragment cameraFragment = getCameraFragment(); - if (cameraFragment != null) { - cameraFragment.switchAction(); + @OnClick(R.id.record_button) + public void onRecordButtonClicked(){ + final CameraFragmentApi cameraFragment = getCameraFragment(); + if (cameraFragment != null) { + cameraFragment.takePhotoOrCaptureVideo(new CameraFragmentResultListener() { + @Override + public void onVideoRecorded(String filePath) { + } - } - }); - - settingsView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - final CameraFragment cameraFragment = getCameraFragment(); - if (cameraFragment != null) { - cameraFragment.openSettingDialog(); + + @Override + public void onPhotoTaken(byte[] bytes, String filePath) { + } - } - }); + }); + } + } + + @OnClick(R.id.settings_view) + public void onSettingsClicked(){ + final CameraFragmentApi cameraFragment = getCameraFragment(); + if (cameraFragment != null) { + cameraFragment.openSettingDialog(); + } + } + + @OnClick(R.id.settings_view) + public void onMediaActionSwitchClicked(){ + final CameraFragmentApi cameraFragment = getCameraFragment(); + if (cameraFragment != null) { + cameraFragment.switchActionPhotoVideo(); + } } @OnClick(R.id.addCameraButton) @@ -169,7 +152,6 @@ public class MainActivity extends AppCompatActivity { .commit(); if (cameraFragment != null) { - cameraFragment.setResultListener(new CameraFragmentResultListener() { @Override public void onVideoRecorded(String filePath) { @@ -327,7 +309,7 @@ public class MainActivity extends AppCompatActivity { mediaActionSwitchView.displayActionWillSwitchVideo(); } - private CameraFragment getCameraFragment() { - return (CameraFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG); + private CameraFragmentApi getCameraFragment() { + return (CameraFragmentApi) getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG); } } diff --git a/app/src/main/res/layout/activity_fragment.xml b/app/src/main/res/layout/activity_fragment.xml index 7b73767..fc650d7 100644 --- a/app/src/main/res/layout/activity_fragment.xml +++ b/app/src/main/res/layout/activity_fragment.xml @@ -73,18 +73,10 @@ android:id="@+id/record_button" android:layout_width="75dp" android:layout_height="75dp" - android:visibility="gone" android:layout_centerInParent="true" android:layout_marginLeft="50dp" android:layout_marginRight="50dp" /> -