From 62200fff4b4c0c2a77574ddf94a34f9fa9027816 Mon Sep 17 00:00:00 2001 From: Florent CHAMPIGNY Date: Mon, 16 Jan 2017 12:43:07 +0100 Subject: [PATCH] Added sample png --- README.md | 2 +- app/src/main/AndroidManifest.xml | 2 +- .../camerafragment/sample/MainActivity.java | 8 +- .../sample/MainActivityCustoms.java | 245 ++++++++++++++++++ ...ctivity_fragment.xml => activity_main.xml} | 0 .../main/res/layout/activity_main_customs.xml | 116 +++++++++ .../layout/{sample.xml => sample_widgets.xml} | 0 .../internal/ui/view/AspectFrameLayout.java | 2 - .../layout/camera_control_panel_layout.xml | 80 ------ media/sample.png | Bin 0 -> 607446 bytes media/sample1.png | Bin 0 -> 6240316 bytes media/sample2.png | Bin 0 -> 6067620 bytes 12 files changed, 366 insertions(+), 89 deletions(-) create mode 100644 app/src/main/java/com/github/florent37/camerafragment/sample/MainActivityCustoms.java rename app/src/main/res/layout/{activity_fragment.xml => activity_main.xml} (100%) create mode 100644 app/src/main/res/layout/activity_main_customs.xml rename app/src/main/res/layout/{sample.xml => sample_widgets.xml} (100%) delete mode 100644 camerafragment/src/main/res/layout/camera_control_panel_layout.xml create mode 100644 media/sample.png create mode 100644 media/sample1.png create mode 100644 media/sample2.png diff --git a/README.md b/README.md index e632c95..672b32b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # CameraFragment -[![gif](https://raw.githubusercontent.com/florent37/CameraFragment/master/media/cameraFragment.gif)](https://github.com/florent37/CameraFragment) +[![png](https://raw.githubusercontent.com/florent37/CameraFragment/master/media/sample.gif)](https://github.com/florent37/CameraFragment) ```java //you can configure the fragment by the configuration builder diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6ef4e12..be48fc7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,7 +21,7 @@ android:theme="@style/ThemeFullscreen" /> 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 dae6bcc..1b13ece 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 @@ -56,7 +56,7 @@ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_fragment); + setContentView(R.layout.activity_main); ButterKnife.bind(this); } @@ -264,7 +264,7 @@ public class MainActivity extends AppCompatActivity { @Override public void allowCameraSwitching(boolean allow) { - //cameraSwitchView.setVisibility(allow ? View.VISIBLE : View.GONE); + cameraSwitchView.setVisibility(allow ? View.VISIBLE : View.GONE); } @Override @@ -274,7 +274,7 @@ public class MainActivity extends AppCompatActivity { @Override public void setMediaActionSwitchVisible(boolean visible) { - //mediaActionSwitchView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); + mediaActionSwitchView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); } }); @@ -299,8 +299,6 @@ public class MainActivity extends AppCompatActivity { recordDurationText.setVisibility(visible ? View.VISIBLE : View.GONE); } }); - - } } diff --git a/app/src/main/java/com/github/florent37/camerafragment/sample/MainActivityCustoms.java b/app/src/main/java/com/github/florent37/camerafragment/sample/MainActivityCustoms.java new file mode 100644 index 0000000..8789a06 --- /dev/null +++ b/app/src/main/java/com/github/florent37/camerafragment/sample/MainActivityCustoms.java @@ -0,0 +1,245 @@ +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; +import android.support.annotation.NonNull; +import android.support.annotation.RequiresPermission; +import android.support.v4.app.ActivityCompat; +import android.support.v4.view.ViewCompat; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import com.github.florent37.camerafragment.CameraFragment; +import com.github.florent37.camerafragment.CameraFragmentApi; +import com.github.florent37.camerafragment.PreviewActivity; +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.widgets.CameraSettingsView; +import com.github.florent37.camerafragment.widgets.CameraSwitchView; +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 MainActivityCustoms extends AppCompatActivity { + + 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) Button settingsView; + @Bind(R.id.flash_switch_view) Button flashSwitchView; + @Bind(R.id.front_back_camera_switcher) Button cameraSwitchView; + @Bind(R.id.record_button) Button recordButton; + @Bind(R.id.photo_video_camera_switcher) Button mediaActionSwitchView; + + @Bind(R.id.cameraLayout) View cameraLayout; + @Bind(R.id.addCameraButton) View addCameraButton; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main_customs); + ButterKnife.bind(this); + } + + @OnClick(R.id.flash_switch_view) + public void onFlashSwitcClicked(){ + final CameraFragmentApi cameraFragment = getCameraFragment(); + if (cameraFragment != null) { + cameraFragment.toggleFlashMode(); + } + } + + @OnClick(R.id.front_back_camera_switcher) + public void onSwitchCameraClicked(){ + final CameraFragmentApi cameraFragment = getCameraFragment(); + if (cameraFragment != null) { + cameraFragment.switchCameraType(); + } + } + + @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) { + + } + + @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.photo_video_camera_switcher) + public void onMediaActionSwitchClicked(){ + final CameraFragmentApi cameraFragment = getCameraFragment(); + if (cameraFragment != null) { + cameraFragment.switchActionPhotoVideo(); + } + } + + @OnClick(R.id.addCameraButton) + public void onAddCameraClicked(){ + if (Build.VERSION.SDK_INT > 15) { + final String[] permissions = { + Manifest.permission.CAMERA, + Manifest.permission.RECORD_AUDIO, + Manifest.permission.WRITE_EXTERNAL_STORAGE, + Manifest.permission.READ_EXTERNAL_STORAGE}; + + final List permissionsToRequest = new ArrayList<>(); + for (String permission : permissions) { + if (ActivityCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) { + permissionsToRequest.add(permission); + } + } + if (!permissionsToRequest.isEmpty()) { + ActivityCompat.requestPermissions(this, permissionsToRequest.toArray(new String[permissionsToRequest.size()]), REQUEST_CAMERA_PERMISSIONS); + } else addCamera(); + } else { + addCamera(); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (grantResults.length != 0) { + addCamera(); + } + } + + @RequiresPermission(Manifest.permission.CAMERA) + public void addCamera() { + addCameraButton.setVisibility(View.GONE); + cameraLayout.setVisibility(View.VISIBLE); + + final CameraFragment cameraFragment = CameraFragment.newInstance(new Configuration.Builder().build()); + getSupportFragmentManager().beginTransaction() + .replace(R.id.content, cameraFragment, FRAGMENT_TAG) + .commit(); + + if (cameraFragment != null) { + cameraFragment.setResultListener(new CameraFragmentResultListener() { + @Override + public void onVideoRecorded(String filePath) { + Intent intent = PreviewActivity.newIntentVideo(MainActivityCustoms.this, filePath); + startActivityForResult(intent, REQUEST_PREVIEW_CODE); + } + + @Override + public void onPhotoTaken(byte[] bytes, String filePath) { + Intent intent = PreviewActivity.newIntentPhoto(MainActivityCustoms.this, filePath); + startActivityForResult(intent, REQUEST_PREVIEW_CODE); + } + }); + + cameraFragment.setStateListener(new CameraFragmentStateListener() { + + @Override + public void onCurrentCameraBack() { + cameraSwitchView.setText("back"); + } + + @Override + public void onCurrentCameraFront() { + cameraSwitchView.setText("front"); + } + + @Override + public void onFlashAuto() { + flashSwitchView.setText("auto"); + } + + @Override + public void onFlashOn() { + flashSwitchView.setText("on"); + } + + @Override + public void onFlashOff() { + flashSwitchView.setText("off"); + } + + @Override + public void onCameraSetupForPhoto() { + mediaActionSwitchView.setText("photo"); + flashSwitchView.setVisibility(View.VISIBLE); + } + + @Override + public void onCameraSetupForVideo() { + mediaActionSwitchView.setText("video"); + flashSwitchView.setVisibility(View.GONE); + } + + @Override + public void shouldRotateControls(int degrees) { + ViewCompat.setRotation(cameraSwitchView, degrees); + ViewCompat.setRotation(mediaActionSwitchView, degrees); + ViewCompat.setRotation(flashSwitchView, degrees); + } + + @Override + public void onRecordStateVideoReadyForRecord() { + recordButton.setText("take video"); + } + + @Override + public void onRecordStateVideoInProgress() { + recordButton.setText("stop"); + } + + @Override + public void onRecordStatePhoto() { + recordButton.setText("take photo"); + } + + @Override + public void onStopVideoRecord() { + settingsView.setVisibility(View.VISIBLE); + } + + @Override + public void onStartVideoRecord(File outputFile) { + } + }); + + } + } + + 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_main.xml similarity index 100% rename from app/src/main/res/layout/activity_fragment.xml rename to app/src/main/res/layout/activity_main.xml diff --git a/app/src/main/res/layout/activity_main_customs.xml b/app/src/main/res/layout/activity_main_customs.xml new file mode 100644 index 0000000..ab891c8 --- /dev/null +++ b/app/src/main/res/layout/activity_main_customs.xml @@ -0,0 +1,116 @@ + + + + + +