Added sample png

pull/17/head
Florent CHAMPIGNY 8 years ago
parent cd69904e59
commit 62200fff4b
  1. 2
      README.md
  2. 2
      app/src/main/AndroidManifest.xml
  3. 8
      app/src/main/java/com/github/florent37/camerafragment/sample/MainActivity.java
  4. 245
      app/src/main/java/com/github/florent37/camerafragment/sample/MainActivityCustoms.java
  5. 0
      app/src/main/res/layout/activity_main.xml
  6. 116
      app/src/main/res/layout/activity_main_customs.xml
  7. 0
      app/src/main/res/layout/sample_widgets.xml
  8. 2
      camerafragment/src/main/java/com/github/florent37/camerafragment/internal/ui/view/AspectFrameLayout.java
  9. 80
      camerafragment/src/main/res/layout/camera_control_panel_layout.xml
  10. BIN
      media/sample.png
  11. BIN
      media/sample1.png
  12. BIN
      media/sample2.png

@ -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

@ -21,7 +21,7 @@
android:theme="@style/ThemeFullscreen" />
<activity
android:name="com.github.florent37.camerafragment.sample.MainActivity"
android:name="com.github.florent37.camerafragment.sample.MainActivityCustoms"
android:screenOrientation="portrait"
android:theme="@style/ThemeFullscreen" >
<intent-filter>

@ -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);
}
});
}
}

@ -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<String> 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);
}
}

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/addCameraButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Add camera"
tools:visibility="gone" />
<!--android:background="#82000000"-->
<RelativeLayout
android:id="@+id/cameraLayout"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="bottom"
android:background="@android:color/transparent">
<Button
android:id="@+id/record_button"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:text="take photo" />
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="capture type"
android:textColor="@android:color/white" />
<Button
android:id="@+id/photo_video_camera_switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:gravity="center"
android:text="photo" />
</LinearLayout>
<Button
android:id="@+id/settings_view"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="settings" />
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="flash"
android:textColor="@android:color/white" />
<Button
android:id="@+id/flash_switch_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="auto" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="camera"
android:textColor="@android:color/white" />
<Button
android:id="@+id/front_back_camera_switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="front" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>

@ -9,8 +9,6 @@ import android.widget.FrameLayout;
*/
public class AspectFrameLayout extends FrameLayout {
private static final String TAG = "AspectFrameLayout";
private double targetAspectRatio = -1.0; // initially use default window size
public AspectFrameLayout(Context context) {

@ -1,80 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:paddingTop="10dp">
<com.github.florent37.camerafragment.widgets.FlashSwitchView
android:id="@+id/flash_switch_view"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true" />
<com.github.florent37.camerafragment.widgets.CameraSwitchView
android:id="@+id/front_back_camera_switcher"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:visibility="gone" />
</RelativeLayout>
<!--android:background="#82000000"-->
<RelativeLayout
android:id="@+id/record_panel"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:background="@android:color/transparent">
<com.github.florent37.camerafragment.widgets.RecordButton
android:id="@+id/record_button"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" />
<com.github.florent37.camerafragment.widgets.MediaActionSwitchView
android:id="@+id/photo_video_camera_switcher"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="40dp"
android:checked="false"
android:gravity="center" />
<TextView
android:id="@+id/record_duration_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/record_button"
android:textColor="@android:color/white"
android:textSize="14dp"
android:visibility="invisible" />
<TextView
android:id="@+id/record_size_mb_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/record_button"
android:textColor="@android:color/white"
android:textSize="14dp"
android:visibility="invisible" />
</RelativeLayout>
</merge>

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 MiB

Loading…
Cancel
Save