Demo app fixes

pull/1/head
Mattia Iavarone 7 years ago
parent 7f39b1b5b7
commit 474d26e0c4
  1. 9
      README.md
  2. 9
      build.gradle
  3. 2
      demo/src/main/AndroidManifest.xml
  4. 48
      demo/src/main/java/com/flurgle/camerakit/demo/MainActivity.java
  5. 30
      demo/src/main/res/layout/activity_main.xml

@ -119,20 +119,23 @@ camera.captureImage();
TODO: test size and orientation stuff. TODO: test size and orientation stuff.
To capture video just call `CameraView.startRecordingVideo()` to start, and `CameraView.stopRecordingVideo()` to finish. Make sure you setup a `CameraListener` to handle the video callback. To capture video just call `CameraView.startRecordingVideo(file)` to start, and `CameraView.stopRecordingVideo()` to finish. Make sure you setup a `CameraListener` to handle the video callback.
```java ```java
camera.setCameraListener(new CameraListener() { camera.setCameraListener(new CameraListener() {
@Override @Override
public void onVideoTaken(File video) { public void onVideoTaken(File video) {
// The File parameter is an MP4 file. // The File is the same you passed before.
// Now it holds a MP4 video.
} }
}); });
camera.startRecordingVideo(); File file = ...; // Make sure you have permissions to write here.
camera.startRecordingVideo(file);
camera.postDelayed(new Runnable() { camera.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
// This will trigger onVideoTaken().
camera.stopRecordingVideo(); camera.stopRecordingVideo();
} }
}, 2500); }, 2500);

@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.3.0' classpath 'com.android.tools.build:gradle:2.3.2'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
@ -19,6 +19,13 @@ allprojects {
} }
} }
ext {
compileSdkVersion = 25
buildToolsVersion = "25.0.2"
minSdkVersion = 15
targetSdkVersion = 25
}
task clean(type: Delete) { task clean(type: Delete) {
delete rootProject.buildDir delete rootProject.buildDir
} }

@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.flurgle.camerakit.demo"> package="com.flurgle.camerakit.demo">
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application <application
android:allowBackup="false" android:allowBackup="false"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"

@ -66,6 +66,7 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
private int mCameraWidth; private int mCameraWidth;
private int mCameraHeight; private int mCameraHeight;
private boolean mCapturing;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -97,17 +98,26 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
@Override @Override
protected void onPause() { protected void onPause() {
camera.stop();
super.onPause(); super.onPause();
camera.stop();
}
@Override
protected void onDestroy() {
super.onDestroy();
camera.destroy();
} }
@OnClick(R.id.capturePhoto) @OnClick(R.id.capturePhoto)
void capturePhoto() { void capturePhoto() {
if (mCapturing) return;
mCapturing = true;
final long startTime = System.currentTimeMillis(); final long startTime = System.currentTimeMillis();
camera.setCameraListener(new CameraListener() { camera.setCameraListener(new CameraListener() {
@Override @Override
public void onPictureTaken(byte[] jpeg) { public void onPictureTaken(byte[] jpeg) {
super.onPictureTaken(jpeg); super.onPictureTaken(jpeg);
mCapturing = false;
long callbackTime = System.currentTimeMillis(); long callbackTime = System.currentTimeMillis();
Bitmap bitmap = BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length); Bitmap bitmap = BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length);
ResultHolder.dispose(); ResultHolder.dispose();
@ -126,30 +136,35 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
@OnClick(R.id.captureVideo) @OnClick(R.id.captureVideo)
void captureVideo() { void captureVideo() {
if (mCapturing) return;
mCapturing = true;
camera.setCameraListener(new CameraListener() { camera.setCameraListener(new CameraListener() {
@Override @Override
public void onVideoTaken(File video) { public void onVideoTaken(File video) {
super.onVideoTaken(video); super.onVideoTaken(video);
mCapturing = false;
} }
}); });
Toast.makeText(this, "Recording for 3 seconds...", Toast.LENGTH_LONG).show();
camera.startRecordingVideo(); camera.startCapturingVideo(null);
camera.postDelayed(new Runnable() { camera.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
camera.stopRecordingVideo(); camera.stopCapturingVideo();
} }
}, 3000); }, 3000);
} }
@OnClick(R.id.toggleCamera) @OnClick(R.id.toggleCamera)
void toggleCamera() { void toggleCamera() {
if (mCapturing) return;
switch (camera.toggleFacing()) { switch (camera.toggleFacing()) {
case CameraKit.Constants.FACING_BACK: case CameraKit.Constants.FACING_BACK:
Toast.makeText(this, "Switched to back camera!", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Switched to back camera!", Toast.LENGTH_SHORT).show();
break; break;
case CameraKit.Constants.FACING_FRONT: case CameraKit.Constants.FACING_FRONT:
Toast.makeText(this, "Switched to front camera!", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Switched to front camera!", Toast.LENGTH_SHORT).show();
break; break;
} }
@ -157,6 +172,7 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
@OnClick(R.id.toggleFlash) @OnClick(R.id.toggleFlash)
void toggleFlash() { void toggleFlash() {
if (mCapturing) return;
switch (camera.toggleFlash()) { switch (camera.toggleFlash()) {
case CameraKit.Constants.FLASH_ON: case CameraKit.Constants.FLASH_ON:
Toast.makeText(this, "Flash on!", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Flash on!", Toast.LENGTH_SHORT).show();
@ -175,29 +191,28 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
RadioGroup.OnCheckedChangeListener captureModeChangedListener = new RadioGroup.OnCheckedChangeListener() { RadioGroup.OnCheckedChangeListener captureModeChangedListener = new RadioGroup.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { public void onCheckedChanged(RadioGroup group, int checkedId) {
camera.setMethod( if (mCapturing) return;
camera.setSessionType(
checkedId == R.id.modeCaptureStandard ? checkedId == R.id.modeCaptureStandard ?
CameraKit.Constants.METHOD_STANDARD : CameraKit.Constants.SESSION_TYPE_PICTURE :
CameraKit.Constants.METHOD_STILL CameraKit.Constants.SESSION_TYPE_VIDEO
); );
Toast.makeText(MainActivity.this, "Session type set to" + (checkedId == R.id.modeCaptureStandard ? " picture!" : " video!"), Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "Picture capture set to" + (checkedId == R.id.modeCaptureStandard ? " quality!" : " speed!"), Toast.LENGTH_SHORT).show();
} }
}; };
RadioGroup.OnCheckedChangeListener cropModeChangedListener = new RadioGroup.OnCheckedChangeListener() { RadioGroup.OnCheckedChangeListener cropModeChangedListener = new RadioGroup.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { public void onCheckedChanged(RadioGroup group, int checkedId) {
camera.setCropOutput( if (mCapturing) return;
checkedId == R.id.modeCropVisible camera.setCropOutput(checkedId == R.id.modeCropVisible);
);
Toast.makeText(MainActivity.this, "Picture cropping is" + (checkedId == R.id.modeCropVisible ? " on!" : " off!"), Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "Picture cropping is" + (checkedId == R.id.modeCropVisible ? " on!" : " off!"), Toast.LENGTH_SHORT).show();
} }
}; };
@OnClick(R.id.widthUpdate) @OnClick(R.id.widthUpdate)
void widthUpdateClicked() { void widthUpdateClicked() {
if (mCapturing) return;
if (widthUpdate.getAlpha() >= 1) { if (widthUpdate.getAlpha() >= 1) {
updateCamera(true, false); updateCamera(true, false);
} }
@ -206,6 +221,7 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
RadioGroup.OnCheckedChangeListener widthModeChangedListener = new RadioGroup.OnCheckedChangeListener() { RadioGroup.OnCheckedChangeListener widthModeChangedListener = new RadioGroup.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { public void onCheckedChanged(RadioGroup group, int checkedId) {
if (mCapturing) return;
widthUpdate.setEnabled(checkedId == R.id.widthCustom); widthUpdate.setEnabled(checkedId == R.id.widthCustom);
widthUpdate.setAlpha(checkedId == R.id.widthCustom ? 1f : 0.3f); widthUpdate.setAlpha(checkedId == R.id.widthCustom ? 1f : 0.3f);
width.clearFocus(); width.clearFocus();
@ -218,6 +234,7 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
@OnClick(R.id.heightUpdate) @OnClick(R.id.heightUpdate)
void heightUpdateClicked() { void heightUpdateClicked() {
if (mCapturing) return;
if (heightUpdate.getAlpha() >= 1) { if (heightUpdate.getAlpha() >= 1) {
updateCamera(false, true); updateCamera(false, true);
} }
@ -226,6 +243,7 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
RadioGroup.OnCheckedChangeListener heightModeChangedListener = new RadioGroup.OnCheckedChangeListener() { RadioGroup.OnCheckedChangeListener heightModeChangedListener = new RadioGroup.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { public void onCheckedChanged(RadioGroup group, int checkedId) {
if (mCapturing) return;
heightUpdate.setEnabled(checkedId == R.id.heightCustom); heightUpdate.setEnabled(checkedId == R.id.heightCustom);
heightUpdate.setAlpha(checkedId == R.id.heightCustom ? 1f : 0.3f); heightUpdate.setAlpha(checkedId == R.id.heightCustom ? 1f : 0.3f);
height.clearFocus(); height.clearFocus();
@ -237,6 +255,7 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
}; };
private void updateCamera(boolean updateWidth, boolean updateHeight) { private void updateCamera(boolean updateWidth, boolean updateHeight) {
if (mCapturing) return;
ViewGroup.LayoutParams cameraLayoutParams = camera.getLayoutParams(); ViewGroup.LayoutParams cameraLayoutParams = camera.getLayoutParams();
int width = cameraLayoutParams.width; int width = cameraLayoutParams.width;
int height = cameraLayoutParams.height; int height = cameraLayoutParams.height;
@ -290,7 +309,6 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
cameraLayoutParams.width = width; cameraLayoutParams.width = width;
cameraLayoutParams.height = height; cameraLayoutParams.height = height;
camera.addOnLayoutChangeListener(this); camera.addOnLayoutChangeListener(this);
camera.setLayoutParams(cameraLayoutParams); camera.setLayoutParams(cameraLayoutParams);
@ -301,10 +319,8 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
mCameraWidth = right - left; mCameraWidth = right - left;
mCameraHeight = bottom - top; mCameraHeight = bottom - top;
width.setText(String.valueOf(mCameraWidth)); width.setText(String.valueOf(mCameraWidth));
height.setText(String.valueOf(mCameraHeight)); height.setText(String.valueOf(mCameraHeight));
camera.removeOnLayoutChangeListener(this); camera.removeOnLayoutChangeListener(this);
} }

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:id="@+id/activity_main"
android:layout_height="match_parent" android:layout_width="match_parent"
android:background="@android:color/white" android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants" android:background="@android:color/white"
android:focusable="true" android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"> android:focusable="true"
android:focusableInTouchMode="true">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -23,12 +24,12 @@
android:layout_height="400dp" android:layout_height="400dp"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:adjustViewBounds="true" android:adjustViewBounds="true"
app:ckCropOutput="false" app:cameraCropOutput="false"
app:ckFacing="back" app:cameraFacing="back"
app:ckFlash="off" app:cameraFlash="off"
app:ckFocus="tapWithMarker" app:cameraFocus="tapWithMarker"
app:ckJpegQuality="100" app:cameraJpegQuality="100"
app:ckMethod="standard" /> app:cameraSessionType="picture" />
</RelativeLayout> </RelativeLayout>
@ -62,8 +63,7 @@
android:layout_weight="1" android:layout_weight="1"
android:backgroundTint="@color/colorPrimary" android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_video" android:src="@drawable/ic_video"
android:tint="@android:color/white" android:tint="@android:color/white" />
android:visibility="gone" />
<ImageButton <ImageButton
android:id="@+id/toggleFlash" android:id="@+id/toggleFlash"

Loading…
Cancel
Save