Constants refactor, readme changes

pull/1/head
Mattia Iavarone 7 years ago
parent df77e95967
commit f644bfdfef
  1. BIN
      .repo/camerakit-android-header.png
  2. BIN
      .repo/demo1.png
  3. BIN
      .repo/demo2.png
  4. BIN
      .repo/demo3.png
  5. BIN
      .repo/demo4.png
  6. BIN
      .repo/google-play-badge.png
  7. BIN
      .repo/permissions.gif
  8. BIN
      .repo/sizing.gif
  9. 377
      README.md
  10. 2
      camerakit/src/main/AndroidManifest.xml
  11. 8
      camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java
  12. 17
      camerakit/src/main/java/com/flurgle/camerakit/CameraKit.java
  13. 25
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java
  14. 28
      camerakit/src/main/res/values/attrs.xml
  15. 6
      camerakit/src/main/types/com/flurgle/camerakit/Method.java

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 MiB

@ -1,7 +1,9 @@
*A fork of [Dylan McIntyre's CameraKit-Android library](https://github.com/gogopop/CameraKit-Android), originally a fork of [Google's CameraView library](https://github.com/google/cameraview)* *A fork of [Dylan McIntyre's CameraKit-Android library](https://github.com/gogopop/CameraKit-Android), originally a fork of [Google's CameraView library](https://github.com/google/cameraview).*
CameraKit is an easy to use utility to work with the Android Camera APIs. Everything at the moment is work in progress. # CameraKit
CameraKit is an easy to use utility to work with the Android Camera APIs. Everything at the moment is work in progress, but it works well for pictures at least.
## Table of Contents ## Table of Contents
@ -10,43 +12,38 @@ CameraKit is an easy to use utility to work with the Android Camera APIs. Everyt
- [Usage](#usage) - [Usage](#usage)
- [Capturing Images](#capturing-images) - [Capturing Images](#capturing-images)
- [Capturing Video](#capturing-video) - [Capturing Video](#capturing-video)
- [Other camera events](#other-camera-events)
- [Extra Attributes](#extra-attributes) - [Extra Attributes](#extra-attributes)
- [`ckFacing`](#ckfacing) - [cameraFacing](#camerafacing)
- [`ckFlash`](#ckflash) - [cameraFlash](#cameraflash)
- [`ckFocus`](#ckfocus) - [cameraFocus](#camerafocus)
- [`ckMethod`](#ckmethod) - [cameraCaptureMethod](#cameracapturemethod)
- [`ckZoom`](#ckzoom) - [cameraZoom](#camerazoom)
- [`ckCropOutput`](#ckcropoutput) - [cameraCropOutput](#cameracropoutput)
- [`ckJpegQuality`](#ckjpegquality) - [cameraJpegQuality](#camerajpegquality)
- [Automatic Permissions Behavior](#automatic-permissions-behavior) - [Permissions Behavior](#permissions-behavior)
- [Dynamic Sizing Behavior](#dynamic-sizing-behavior) - [Dynamic Sizing Behavior](#dynamic-sizing-behavior)
- [`adjustViewBounds`](#adjustviewbounds) - [Center Crop](#center-crop)
- [Events](#events) - [Center Inside](#center-inside)
- [Credits](#credits)
- [License](#license) # Features
## Features - Image and video capture seamlessly working with the same preview session. (TODO: remove this, use different sessions)
- System permission handling
- Image and video capture seamlessly working with the same preview session. - Dynamic sizing behavior
- Automatic system permission handling. - Create a `CameraView` of any size (not just presets!)...
- Automatic preview scaling. - Or let it adapt to the sensor preview size
- Create a `CameraView` of any size (not just presets!). - Automatic output cropping to match your `CameraView` bounds
- Automatic output cropping to match your `CameraView` bounds. - Multiple capture methods
- Multiple capture methods. - `CAPTURE_METHOD_STANDARD`: an image captured normally using the camera APIs.
- `METHOD_STANDARD`: an image captured normally using the camera APIs. - `CAPTURE_METHOD_FRAME`: a freeze frame of the `CameraView` preview (similar to SnapChat and Instagram) for devices with slower cameras
- `METHOD_STILL`: a freeze frame of the `CameraView` preview (similar to SnapChat and Instagram) for devices with slower cameras. - Built-in tap to focus
- **Coming soon:** `METHOD_SPEED`: automatic capture method determination based on measured speed. - TODO: Built-in pinch to zoom
- Built-in continuous focus.
- Built-in tap to focus.
- **Coming soon:** Built-in pinch to zoom.
## Setup ## Setup
Add __CameraKit__ to the dependencies block in your `app` level `build.gradle`: For now, clone the repo and add it to your project.
TODO: publish to bintray.
```groovy
compile 'com.flurgle:camerakit:0.9.17'
```
## Usage ## Usage
@ -60,7 +57,7 @@ To use CameraKit, simply add a `CameraView` to your layout:
android:adjustViewBounds="true" /> android:adjustViewBounds="true" />
``` ```
Make sure you override `onResume` and `onPause` in your activity, and make calls respectively to `CameraView.start()` and `CameraView.stop()`. Make sure you override `onResume`, `onPause` and `onDestroy` in your activity, and call `CameraView.start()`, `stop()` and `destroy()`.
```java ```java
@Override @Override
@ -71,8 +68,14 @@ protected void onResume() {
@Override @Override
protected void onPause() { protected void onPause() {
cameraView.stop();
super.onPause(); super.onPause();
cameraView.stop();
}
@Override
protected void onDestroy() {
super.onDestroy();
cameraView.destroy();
} }
``` ```
@ -84,9 +87,7 @@ To capture an image just call `CameraView.captureImage()`. Make sure you setup a
camera.setCameraListener(new CameraListener() { camera.setCameraListener(new CameraListener() {
@Override @Override
public void onPictureTaken(byte[] picture) { public void onPictureTaken(byte[] picture) {
super.onPictureTaken(picture); // Create a bitmap or a file...
// Create a bitmap
Bitmap result = BitmapFactory.decodeByteArray(picture, 0, picture.length); Bitmap result = BitmapFactory.decodeByteArray(picture, 0, picture.length);
} }
}); });
@ -96,13 +97,14 @@ camera.captureImage();
### Capturing Video ### Capturing Video
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()` 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) {
super.onVideoTaken(video);
// The File parameter is an MP4 file. // The File parameter is an MP4 file.
} }
}); });
@ -116,296 +118,185 @@ camera.postDelayed(new Runnable() {
}, 2500); }, 2500);
``` ```
### Other camera events
Make sure you can react to different camera events by setting up a `CameraListener` instance.
```java
camera.setCameraListener(new CameraListener() {
@Override
public void onCameraOpened() {}
@Override
public void onCameraClosed() {}
@Override
public void onPictureTaken(byte[] picture) {}
@Override
public void onVideoTaken(File video) {}
});
```
## Extra Attributes ## Extra Attributes
```xml ```xml
<com.flurgle.camerakit.CameraView xmlns:camerakit="http://schemas.android.com/apk/res-auto" <com.flurgle.camerakit.CameraView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/camera" android:id="@+id/camera"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
camerakit:ckFacing="back" app:cameraFacing="back"
camerakit:ckFlash="off" app:cameraFlash="off"
camerakit:ckFocus="continuous" app:cameraFocus="continuous"
camerakit:ckMethod="standard" app:cameraCaptureMethod="standard"
camerakit:ckZoom="pinch" app:cameraZoom="pinch"
camerakit:ckPermissions="strict" app:cameraPermissionPolicy="strict"
camerakit:ckCropOutput="true" app:cameraCropOutput="true"
camerakit:ckJpegQuality="100" app:cameraJpegQuality="100"
camerakit:ckVideoQuality="480p" app:cameraVideoQuality="480p"
android:adjustViewBounds="true" /> android:adjustViewBounds="true" />
``` ```
|Attribute|Values|Default Value| |XML Attribute|Method|Values|Default Value|
|---------|------|-------------| |-------------|------|------|-------------|
|[`ckFacing`](#ckfacing)|[`back`](#back) [`front`](#front)|`back`| |[`cameraFacing`](#camerafacing)|`setFacing()`|`back` `front`|`back`|
|[`ckFlash`](#ckflash)|[`off`](#off) [`on`](#on) [`auto`](#auto)|`off`| |[`cameraFlash`](#cameraflash)|`setFlash()`|`off` `on` `auto` `torch`|`off`|
|[`ckFocus`](#ckfocus)|[`off`](#off-1) [`continuous`](#continuous) [`tap`](#tap)|`continuous`| |[`cameraFocus`](#camerafocus)|`setFocus()`|`off` `continuous` `tap` `tapWithMarker`|`continuous`|
|[`ckMethod`](#ckmethod)|[`standard`](#standard) [`still`](#still) [`speed`](#speed)|`standard`| |[`cameraCaptureMethod`](#cameracapturemethod)|`setCaptureMethod()`|`standard` `frame`|`standard`|
|[`ckZoom`](#ckzoom)|[`off`](#off-2) [`pinch`](#pinch)|`off`| |[`cameraZoom`](#camerazoom)|`setZoom()`|`off` `pinch`|`off`|
|[`ckPermissions`](#ckpermissions)|[`strict`](#strict) [`lazy`](#lazy) [`picture`](#picture`)|`strict`| |[`cameraPermissionPolicy`](#camerapermissionpolicy)|`setPermissionPolicy()`|`picture` `video`|`picture`|
|[`ckCropOutput`](#ckcropoutput)|[`true`](#true) [`false`](#false)|`false`| |[`cameraCropOutput`](#cameracropoutput)|`setCropOutput()`|`true` `false`|`false`|
|[`ckJpegQuality`](#ckjpegquality)|[`0 <= n <= 100`](#ckjpegquality)|`100`| |[`cameraJpegQuality`](#camerajpegquality)|`setJpegQuality()`|`0 <= n <= 100`|`100`|
|[`ckVideoQuality`](#ckvideoquality)|[`max480p`](#max480p) [`max720p`](#max720p) [`max1080p`](#max1080p) [`max2160p`](#max2160p) [`highest`](#highest) [`lowest`](#lowest)|`max480p`| |[`cameraVideoQuality`](#cameravideoquality)|`setVideoQuality()`|`max480p` `max720p` `max1080p` `max2160p` `highest` `lowest`|`max480p`|
- - -
### `ckFacing` ### cameraFacing
[`back`](#back) [`front`](#front)
#### `back` Which camera to use, either back facing or front facing.
```java ```java
cameraView.setFacing(CameraKit.Constants.FACING_BACK); cameraView.setFacing(CameraKit.Constants.FACING_BACK);
```
#### `front`
```java
cameraView.setFacing(CameraKit.Constants.FACING_FRONT); cameraView.setFacing(CameraKit.Constants.FACING_FRONT);
``` ```
- - - ### cameraFlash
### `ckFlash` Flash mode, either off, on, auto or *torch*.
[`off`](#off) [`on`](#on) [`auto`](#auto) [`torch`](#torch)
#### `off`
```java ```java
cameraView.setFlash(CameraKit.Constants.FLASH_OFF); cameraView.setFlash(CameraKit.Constants.FLASH_OFF);
```
#### `on`
```java
cameraView.setFlash(CameraKit.Constants.FLASH_ON); cameraView.setFlash(CameraKit.Constants.FLASH_ON);
```
#### `auto`
```java
cameraView.setFlash(CameraKit.Constants.FLASH_AUTO); cameraView.setFlash(CameraKit.Constants.FLASH_AUTO);
```
#### `torch`
```java
cameraView.setFlash(CameraKit.Constants.FLASH_TORCH); cameraView.setFlash(CameraKit.Constants.FLASH_TORCH);
``` ```
- - - ### cameraFocus
### `ckFocus`
[`off`](#off-1) [`continuous`](#continuous) [`tap`](#tap)
#### `off` Focus behavior. Can be off, continuous (camera continuously tries to adapt its focus), tap (focus is driven by the user tap) and tapWithMarker (a marker is drawn on screen to indicate focusing).
```java ```java
cameraView.setFocus(CameraKit.Constants.FOCUS_OFF); cameraView.setFocus(CameraKit.Constants.FOCUS_OFF);
```
#### `continuous`
```java
cameraView.setFocus(CameraKit.Constants.FOCUS_CONTINUOUS); cameraView.setFocus(CameraKit.Constants.FOCUS_CONTINUOUS);
```
#### `tap`
```java
cameraView.setFocus(CameraKit.Constants.FOCUS_TAP); cameraView.setFocus(CameraKit.Constants.FOCUS_TAP);
cameraView.setFocus(CameraKit.Constants.FOCUS_TAP_WITH_MARKER);
``` ```
- - - ### cameraCaptureMethod
### `ckMethod`
[`standard`](#standard) [`still`](#still) [`speed`](#speed)
#### `standard` How to capture pictures, either standard or frame. The frame option lets you capture and save a preview frame, which can be better with slower camera sensors, though the captured image can be blurry or noisy.
```java ```java
cameraView.setMethod(CameraKit.Constants.METHOD_STANDARD); cameraView.setMethod(CameraKit.Constants.CAPTURE_METHOD_STANDARD);
cameraView.setMethod(CameraKit.Constants.CAPTURE_METHOD_FRAME);
``` ```
When you use `METHOD_STANDARD` (`camerakit:ckMethod="standard"`), images will be captured using the normal camera API capture method using the shutter. ### cameraZoom
#### `still`
```java
cameraView.setMethod(CameraKit.Constants.METHOD_STILL);
```
When you use `METHOD_STILL` (`camerakit:ckMethod="still"`), images will be captured by grabbing a single frame from the preview. This behavior is the same as SnapChat and Instagram. This method has a higher rate of motion blur but can be a better experience for users with slower cameras.
#### `speed`
**Coming soon** TODO: work in progress. Right now 'off' is the onlly option.
```java
cameraView.setMethod(CameraKit.Constants.METHOD_SPEED);
```
When you use `METHOD_SPEED` (`camerakit:ckMethod="speed"`), images will be captured using both `METHOD_STANDARD` and `METHOD_SPEED`. After 6 image captures the camera will set itself to `METHOD_STANDARD` or `METHOD_STILL` permanently based on whichever is faster.
- - -
### `ckZoom`
[`off`](#off-2) [`pinch`](#pinch)
#### `off`
```java ```java
cameraView.setZoom(CameraKit.Constants.ZOOM_OFF); cameraView.setZoom(CameraKit.Constants.ZOOM_OFF);
```
#### `pinch`
```java
cameraView.setZoom(CameraKit.Constants.ZOOM_PINCH); cameraView.setZoom(CameraKit.Constants.ZOOM_PINCH);
``` ```
- - - ### cameraPermissionPolicy
### `ckPermissions` Either picture or video. This tells the library which permissions should be asked before starting the camera session. In the case of 'picture', we require the camera permissions. In the case of 'video', the record audio permission is asked as well.
[`strict`](#strict) [`lazy`](#lazy) [`picture`](#picture`)
#### `strict` Please note that, if needed, the latter should be added to your manifest file or the app will crash.
```java
cameraView.setPermissions(CameraKit.Constants.PERMISSIONS_STRICT);
```
#### `lazy`
```java
cameraView.setPermissions(CameraKit.Constants.PERMISSIONS_LAZY);
```
#### `picture`
```java ```java
cameraView.setPermissions(CameraKit.Constants.PERMISSIONS_PICTURE); cameraView.setPermissions(CameraKit.Constants.PERMISSIONS_PICTURE);
cameraView.setPermissions(CameraKit.Constants.PERMISSIONS_VIDEO);
``` ```
- - - ### cameraCropOutput
### `ckCropOutput`
[`true`](#true) [`false`](#false)
#### `true`
```java
cameraView.setCropOutput(true);
```
#### `false`
```java Wheter the output file should be cropped to fit the aspect ratio of the preview surface.
cameraView.setCropOutput(false); This can guarantee consistency between what the user sees and the final output, if you fixed the camera view dimensions.
```
- - - ### cameraJpegQuality
### `ckJpegQuality` Sets the JPEG quality of pictures.
```java ```java
cameraView.setJpegQuality(100); cameraView.setJpegQuality(100);
cameraView.setJpegQuality(50);
``` ```
- - - ### cameraVideoQuality
### `ckVideoQuality`
[`max480p`](#max480p) [`max720p`](#max720p) [`max1080p`](#max1080p) [`max2160p`](#max2160p) [`lowest`](#lowest) [`highest`](#highest) [`qvga`](#qvga)
#### `max480p` Sets the desired video quality.
```java ```java
cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_480P); cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_480P);
```
#### `max720p`
```java
cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_720P); cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_720P);
```
#### `max1080p`
```java
cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_1080P); cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_1080P);
```
#### `max2160p`
```java
cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_2160P); cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_2160P);
```
#### `lowest`
```java
cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_LOWEST); cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_LOWEST);
```
#### `highest`
```java
cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_HIGHEST); cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_HIGHEST);
```
#### `qvga`
```java
cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_QVGA); cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_QVGA);
``` ```
- - - ## Permissions behavior
## Automatic Permissions Behavior
You can handle permissions yourself in whatever way you want, but if you make a call to `CameraView.start()` without the `android.permission.CAMERA` permission, an exception would normally be thrown and your app would crash. `CameraView` needs two permissions:
With CameraKit, we will automatically prompt for the `android.permission.CAMERA` permission if it's not available. If you want to handle it yourself, just make sure you don't call `CameraView.start()` until you acquire the permissions. - `android.permission.CAMERA` : required
- `android.permission.RECORD_AUDIO` : required for capturing videos
![Permissions behavior gif](.repo/permissions.gif) You can handle permissions yourself and then call `CameraView.start()` once they are acquired. If they are not, `CameraView` will request permissions to the user based on the `permissionPolicy` that was set. In that case, you can restart the camera if you have a successful response from `onRequestPermissionResults()`.
## Dynamic Sizing Behavior ## Manifest file
You can setup the `CameraView` dimensions however you want. When your dimensions don't match the aspect ratio of the internal preview surface, the surface will be cropped minimally to fill the view. The behavior is the same as the `android:scaleType="centerCrop"` on an `ImageView`. The library manifest file is not strict and only asks for camera permissions. This means that:
![Dynamic sizing gif](.repo/sizing.gif) - If you wish to record videos, you should also add `android.permission.RECORD_AUDIO` to required permissions
### `adjustViewBounds` ```xml
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
```
You can use a mix of a fixed dimension (a set value or `match_parent`) as well as `wrap_content`. When you do this make sure you set `android:adjustViewBounds="true"` on the `CameraView`. - If you want your app to be installed only on devices that have a camera, you should add:
When you do this the dimension set to `wrap_content` will automatically align with the true aspect ratio of the preview surface. In this case the whole preview will be visible with no cropping. ```xml
<uses-feature
android:name="android.hardware.camera"
android:required="true"/>
```
## Events If you don't request this feature, you can use `CameraKit.hasCameras()` to detect if current device has cameras, and then start the camera view.
Make sure you can react to different camera events by setting up a `CameraListener` instance. ## Dynamic Sizing Behavior
```java
camera.setCameraListener(new CameraListener() {
@Override ### Center crop
public void onCameraOpened() {
super.onCameraOpened();
}
@Override You can setup the `CameraView` dimensions as you wish. Default behavior is that if your dimensions don't match the aspect ratio of the internal preview surface, the surface will be cropped to fill the view, just like `android:scaleType="centerCrop"` on an `ImageView`.
public void onCameraClosed() {
super.onCameraClosed();
}
@Override ### Center inside
public void onPictureTaken(byte[] picture) {
super.onPictureTaken(picture);
}
@Override If `android:adjustViewBounds` is set to true the library will try to adapt the view dimension to the chosen preview size. How? All dimensions set to `wrap_content` are streched out to ensure the view holds the whole preview. If both dimensions are `wrap_content`, this is exactly like `android:scaleType="centerInside"` on an `ImageView`.
public void onVideoTaken(File video) {
super.onVideoTaken(video);
}
});
```

@ -9,7 +9,7 @@
<uses-feature <uses-feature
android:name="android.hardware.camera" android:name="android.hardware.camera"
android:required="true"/> android:required="false"/>
<uses-feature <uses-feature
android:name="android.hardware.camera.autofocus" android:name="android.hardware.camera.autofocus"
android:required="false"/> android:required="false"/>

@ -22,8 +22,8 @@ import static com.flurgle.camerakit.CameraKit.Constants.FLASH_OFF;
import static com.flurgle.camerakit.CameraKit.Constants.FOCUS_CONTINUOUS; import static com.flurgle.camerakit.CameraKit.Constants.FOCUS_CONTINUOUS;
import static com.flurgle.camerakit.CameraKit.Constants.FOCUS_OFF; import static com.flurgle.camerakit.CameraKit.Constants.FOCUS_OFF;
import static com.flurgle.camerakit.CameraKit.Constants.FOCUS_TAP; import static com.flurgle.camerakit.CameraKit.Constants.FOCUS_TAP;
import static com.flurgle.camerakit.CameraKit.Constants.METHOD_STANDARD; import static com.flurgle.camerakit.CameraKit.Constants.CAPTURE_METHOD_STANDARD;
import static com.flurgle.camerakit.CameraKit.Constants.METHOD_STILL; import static com.flurgle.camerakit.CameraKit.Constants.CAPTURE_METHOD_FRAME;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
class Camera1 extends CameraImpl { class Camera1 extends CameraImpl {
@ -226,7 +226,7 @@ class Camera1 extends CameraImpl {
@Override @Override
void captureImage() { void captureImage() {
switch (mMethod) { switch (mMethod) {
case METHOD_STANDARD: case CAPTURE_METHOD_STANDARD:
// Null check required for camera here as is briefly null when View is detached // Null check required for camera here as is briefly null when View is detached
if (!capturingImage && mCamera != null) { if (!capturingImage && mCamera != null) {
// Set boolean to wait for image callback // Set boolean to wait for image callback
@ -250,7 +250,7 @@ class Camera1 extends CameraImpl {
} }
break; break;
case METHOD_STILL: case CAPTURE_METHOD_FRAME:
// TODO: will calculateCaptureRotation work here? It's the only usage. Test... // TODO: will calculateCaptureRotation work here? It's the only usage. Test...
mCamera.setOneShotPreviewCallback(new Camera.PreviewCallback() { mCamera.setOneShotPreviewCallback(new Camera.PreviewCallback() {
@Override @Override

@ -1,9 +1,17 @@
package com.flurgle.camerakit; package com.flurgle.camerakit;
import android.content.res.Resources; import android.content.Context;
import android.content.pm.PackageManager;
public class CameraKit { public class CameraKit {
public static boolean hasCameras(Context context) {
PackageManager manager = context.getPackageManager();
// There's also FEATURE_CAMERA_EXTERNAL , should we support it?
return manager.hasSystemFeature(PackageManager.FEATURE_CAMERA)
|| manager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
}
public static class Constants { public static class Constants {
public static final int PERMISSION_REQUEST_CODE = 16; public static final int PERMISSION_REQUEST_CODE = 16;
@ -24,9 +32,8 @@ public class CameraKit {
public static final int ZOOM_OFF = 0; public static final int ZOOM_OFF = 0;
public static final int ZOOM_PINCH = 1; public static final int ZOOM_PINCH = 1;
public static final int METHOD_STANDARD = 0; public static final int CAPTURE_METHOD_STANDARD = 0;
public static final int METHOD_STILL = 1; public static final int CAPTURE_METHOD_FRAME = 1;
public static final int METHOD_SPEED = 2;
/** /**
@ -60,7 +67,7 @@ public class CameraKit {
static final int DEFAULT_FLASH = Constants.FLASH_OFF; static final int DEFAULT_FLASH = Constants.FLASH_OFF;
static final int DEFAULT_FOCUS = Constants.FOCUS_CONTINUOUS; static final int DEFAULT_FOCUS = Constants.FOCUS_CONTINUOUS;
static final int DEFAULT_ZOOM = Constants.ZOOM_OFF; static final int DEFAULT_ZOOM = Constants.ZOOM_OFF;
static final int DEFAULT_METHOD = Constants.METHOD_STANDARD; static final int DEFAULT_METHOD = Constants.CAPTURE_METHOD_STANDARD;
static final int DEFAULT_PERMISSIONS = Constants.PERMISSIONS_PICTURE; static final int DEFAULT_PERMISSIONS = Constants.PERMISSIONS_PICTURE;
static final int DEFAULT_VIDEO_QUALITY = Constants.VIDEO_QUALITY_480P; static final int DEFAULT_VIDEO_QUALITY = Constants.VIDEO_QUALITY_480P;

@ -11,10 +11,8 @@ import android.content.ContextWrapper;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.YuvImage; import android.graphics.YuvImage;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -41,7 +39,6 @@ import static com.flurgle.camerakit.CameraKit.Constants.FLASH_AUTO;
import static com.flurgle.camerakit.CameraKit.Constants.FLASH_OFF; import static com.flurgle.camerakit.CameraKit.Constants.FLASH_OFF;
import static com.flurgle.camerakit.CameraKit.Constants.FLASH_ON; import static com.flurgle.camerakit.CameraKit.Constants.FLASH_ON;
import static com.flurgle.camerakit.CameraKit.Constants.FLASH_TORCH; import static com.flurgle.camerakit.CameraKit.Constants.FLASH_TORCH;
import static com.flurgle.camerakit.CameraKit.Constants.METHOD_STANDARD;
import static com.flurgle.camerakit.CameraKit.Constants.PERMISSIONS_PICTURE; import static com.flurgle.camerakit.CameraKit.Constants.PERMISSIONS_PICTURE;
import static com.flurgle.camerakit.CameraKit.Constants.PERMISSIONS_VIDEO; import static com.flurgle.camerakit.CameraKit.Constants.PERMISSIONS_VIDEO;
@ -112,15 +109,15 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
if (attrs != null) { if (attrs != null) {
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0);
try { try {
mFacing = a.getInteger(R.styleable.CameraView_ckFacing, CameraKit.Defaults.DEFAULT_FACING); mFacing = a.getInteger(R.styleable.CameraView_cameraFacing, CameraKit.Defaults.DEFAULT_FACING);
mFlash = a.getInteger(R.styleable.CameraView_ckFlash, CameraKit.Defaults.DEFAULT_FLASH); mFlash = a.getInteger(R.styleable.CameraView_cameraFlash, CameraKit.Defaults.DEFAULT_FLASH);
mFocus = a.getInteger(R.styleable.CameraView_ckFocus, CameraKit.Defaults.DEFAULT_FOCUS); mFocus = a.getInteger(R.styleable.CameraView_cameraFocus, CameraKit.Defaults.DEFAULT_FOCUS);
mMethod = a.getInteger(R.styleable.CameraView_ckMethod, CameraKit.Defaults.DEFAULT_METHOD); mMethod = a.getInteger(R.styleable.CameraView_cameraCaptureMethod, CameraKit.Defaults.DEFAULT_METHOD);
mZoom = a.getInteger(R.styleable.CameraView_ckZoom, CameraKit.Defaults.DEFAULT_ZOOM); mZoom = a.getInteger(R.styleable.CameraView_cameraZoom, CameraKit.Defaults.DEFAULT_ZOOM);
mPermissions = a.getInteger(R.styleable.CameraView_ckPermissions, CameraKit.Defaults.DEFAULT_PERMISSIONS); mPermissions = a.getInteger(R.styleable.CameraView_cameraPermissionPolicy, CameraKit.Defaults.DEFAULT_PERMISSIONS);
mVideoQuality = a.getInteger(R.styleable.CameraView_ckVideoQuality, CameraKit.Defaults.DEFAULT_VIDEO_QUALITY); mVideoQuality = a.getInteger(R.styleable.CameraView_cameraVideoQuality, CameraKit.Defaults.DEFAULT_VIDEO_QUALITY);
mJpegQuality = a.getInteger(R.styleable.CameraView_ckJpegQuality, CameraKit.Defaults.DEFAULT_JPEG_QUALITY); mJpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, CameraKit.Defaults.DEFAULT_JPEG_QUALITY);
mCropOutput = a.getBoolean(R.styleable.CameraView_ckCropOutput, CameraKit.Defaults.DEFAULT_CROP_OUTPUT); mCropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, CameraKit.Defaults.DEFAULT_CROP_OUTPUT);
mAdjustViewBounds = a.getBoolean(R.styleable.CameraView_android_adjustViewBounds, CameraKit.Defaults.DEFAULT_ADJUST_VIEW_BOUNDS); mAdjustViewBounds = a.getBoolean(R.styleable.CameraView_android_adjustViewBounds, CameraKit.Defaults.DEFAULT_ADJUST_VIEW_BOUNDS);
} finally { } finally {
a.recycle(); a.recycle();
@ -136,7 +133,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
setFacing(mFacing); setFacing(mFacing);
setFlash(mFlash); setFlash(mFlash);
setFocus(mFocus); setFocus(mFocus);
setMethod(mMethod); setCaptureMethod(mMethod);
setZoom(mZoom); setZoom(mZoom);
setPermissionPolicy(mPermissions); setPermissionPolicy(mPermissions);
setVideoQuality(mVideoQuality); setVideoQuality(mVideoQuality);
@ -394,7 +391,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
mCameraImpl.setFocus(mFocus); mCameraImpl.setFocus(mFocus);
} }
public void setMethod(@Method int method) { public void setCaptureMethod(@Method int method) {
this.mMethod = method; this.mMethod = method;
mCameraImpl.setMethod(mMethod); mCameraImpl.setMethod(mMethod);
} }

@ -3,26 +3,26 @@
<declare-styleable name="CameraView"> <declare-styleable name="CameraView">
<attr name="ckFacing" format="enum"> <attr name="cameraFacing" format="enum">
<enum name="back" value="0" /> <enum name="back" value="0" />
<enum name="front" value="1" /> <enum name="front" value="1" />
</attr> </attr>
<attr name="ckFlash" format="enum"> <attr name="cameraFlash" format="enum">
<enum name="off" value="0" /> <enum name="off" value="0" />
<enum name="on" value="1" /> <enum name="on" value="1" />
<enum name="auto" value="2" /> <enum name="auto" value="2" />
<enum name="torch" value="3" /> <enum name="torch" value="3" />
</attr> </attr>
<attr name="ckFocus" format="enum"> <attr name="cameraFocus" format="enum">
<enum name="off" value="0" /> <enum name="off" value="0" />
<enum name="continuous" value="1" /> <enum name="continuous" value="1" />
<enum name="tap" value="2" /> <enum name="tap" value="2" />
<enum name="tapWithMarker" value="3" /> <enum name="tapWithMarker" value="3" />
</attr> </attr>
<attr name="ckZoom" format="enum"> <attr name="cameraZoom" format="enum">
<enum name="off" value="0" /> <enum name="off" value="0" />
<!-- TODO: Set to unique value when feature added --> <!-- TODO: Set to unique value when feature added -->
@ -30,23 +30,19 @@
</attr> </attr>
<attr name="ckMethod" format="enum"> <attr name="cameraCaptureMethod" format="enum">
<enum name="standard" value="0" /> <enum name="standard" value="0" />
<enum name="still" value="1" /> <enum name="frame" value="1" />
<!-- TODO: Set to unique value when feature added -->
<enum name="speed" value="0" />
</attr> </attr>
<attr name="ckPermissions" format="enum"> <attr name="cameraPermissionPolicy" format="enum">
<enum name="strict" value="0" /> <enum name="video" value="0" />
<enum name="lazy" value="1" /> <enum name="picture" value="1" />
<enum name="picture" value="2" />
</attr> </attr>
<attr name="ckJpegQuality" format="integer" /> <attr name="cameraJpegQuality" format="integer" />
<attr name="ckVideoQuality" format="enum"> <attr name="cameraVideoQuality" format="enum">
<enum name="max480p" value="0" /> <enum name="max480p" value="0" />
<enum name="max720p" value="1" /> <enum name="max720p" value="1" />
<enum name="max1080p" value="2" /> <enum name="max1080p" value="2" />
@ -56,7 +52,7 @@
<enum name="qvga" value="6" /> <enum name="qvga" value="6" />
</attr> </attr>
<attr name="ckCropOutput" format="boolean" /> <attr name="cameraCropOutput" format="boolean" />
<attr name="android:adjustViewBounds" /> <attr name="android:adjustViewBounds" />

@ -5,10 +5,10 @@ import android.support.annotation.IntDef;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import static com.flurgle.camerakit.CameraKit.Constants.METHOD_STANDARD; import static com.flurgle.camerakit.CameraKit.Constants.CAPTURE_METHOD_STANDARD;
import static com.flurgle.camerakit.CameraKit.Constants.METHOD_STILL; import static com.flurgle.camerakit.CameraKit.Constants.CAPTURE_METHOD_FRAME;
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({METHOD_STANDARD, METHOD_STILL}) @IntDef({CAPTURE_METHOD_STANDARD, CAPTURE_METHOD_FRAME})
public @interface Method { public @interface Method {
} }

Loading…
Cancel
Save