Skip to content

Commit

Permalink
Merge pull request #160 from Fotoapparat/v2
Browse files Browse the repository at this point in the history
🎄 V2 🎄
  • Loading branch information
Diolor authored Dec 31, 2017
2 parents 1d6d2d0 + 3f6ecbd commit 2c80a90
Show file tree
Hide file tree
Showing 411 changed files with 8,598 additions and 18,072 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ android:
components:
- tools
- platform-tools
- build-tools-25.0.2
- android-25
- tools
- build-tools-27.0.3
- android-27
- extra-android-m2repository

before_install:
- yes | sdkmanager "platforms;android-27"

script:
- ./gradlew build test
157 changes: 82 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ What it provides:
- Simple yet powerful parameters customization.
- Standalone custom `CameraView` which can be integrated into any `Activity`.
- Fixes and workarounds for device-specific problems.
- Both Kotlin and Java friendly configurations.
- Last, but not least, non 0% test coverage.


Taking picture becomes as simple as:

```java
Fotoapparat fotoapparat = Fotoapparat
.with(context)
.into(cameraView)
.build();

fotoapparat.start();
```kotlin
val fotoapparat = Fotoapparat(
context = this,
view = cameraView
)
fotoapparat.start()

fotoapparat
.takePicture()
.saveToFile(someFile);
.saveToFile(someFile)
```

## How it works
Expand All @@ -45,109 +46,115 @@ Add `CameraView` to your layout

### Step Two

Configure `Fotoapparat` instance

```java
Fotoapparat
.with(context)
.into(cameraView) // view which will draw the camera preview
.previewScaleType(ScaleType.CENTER_CROP) // we want the preview to fill the view
.photoSize(biggestSize()) // we want to have the biggest photo possible
.lensPosition(back()) // we want back camera
.focusMode(firstAvailable( // (optional) use the first focus mode which is supported by device
continuousFocus(),
autoFocus(), // in case if continuous focus is not available on device, auto focus will be used
fixed() // if even auto focus is not available - fixed focus mode will be used
))
.flash(firstAvailable( // (optional) similar to how it is done for focus mode, this time for flash
autoRedEye(),
autoFlash(),
torch()
))
.frameProcessor(myFrameProcessor) // (optional) receives each frame from preview stream
.logger(loggers( // (optional) we want to log camera events in 2 places at once
logcat(), // ... in logcat
fileLogger(this) // ... and to file
))
.build();
```
Configure `Fotoapparat` instance.

```kotlin
Fotoapparat(
context = this,
view = cameraView, // view which will draw the camera preview
scaleType = ScaleType.CenterCrop, // (optional) we want the preview to fill the view
lensPosition = back(), // (optional) we want back camera
cameraConfiguration = configuration, // (optional) define an advanced configuration
logger = loggers( // (optional) we want to log camera events in 2 places at once
logcat(), // ... in logcat
fileLogger(this) // ... and to file
),
cameraErrorCallback = { error -> } // (optional) log fatal errors
)
```
Check the [wiki for the `configuration` options e.g. change iso](https://github.com/Fotoapparat/Fotoapparat/wiki/Configuration-Kotlin)

Are you using Java only? See our [wiki for the java-friendly configuration](https://github.com/Fotoapparat/Fotoapparat/wiki/Configuration-Java).


### Step Three

Call `start()` and `stop()`. No rocket science here.

```java
@Override
protected void onStart() {
super.onStart();
fotoapparat.start();
```kotlin
override fun onStart() {
super.onStart()
fotoapparat.start()
}

@Override
protected void onStop() {
super.onStop();
fotoapparat.stop();

override fun onStop() {
super.onStop()
fotoapparat.stop()
}
```

### Take picture

Finally we are ready to take picture. You have various options.

```java
PhotoResult photoResult = fotoapparat.takePicture();
```kotlin
val photoResult = fotoapparat.takePicture()

// Asynchronously saves photo to file
photoResult.saveToFile(someFile);
photoResult.saveToFile(someFile)

// Asynchronously converts photo to bitmap and returns result on main thread
photoResult
.toBitmap()
.whenAvailable(new PendingResult.Callback<BitmapPhoto>() {
@Override
public void onResult(BitmapPhoto result) {
ImageView imageView = (ImageView) findViewById(R.id.result);

imageView.setImageBitmap(result.bitmap);
imageView.setRotation(-result.rotationDegrees);
}
});
.whenAvailable { bitmapPhoto ->
val imageView = (ImageView) findViewById(R.id.result)

imageView.setImageBitmap(bitmapPhoto.bitmap)
imageView.setRotation(-bitmapPhoto.rotationDegrees)
}

// Of course you can also get a photo in a blocking way. Do not do it on main thread though.
BitmapPhoto result = photoResult.toBitmap().await();
val result = photoResult.toBitmap().await()

// Convert asynchronous events to RxJava 1.x/2.x types. See /fotoapparat-adapters/ module
// Convert asynchronous events to RxJava 1.x/2.x types.
// See /fotoapparat-adapters/ module
photoResult
.toBitmap()
.adapt(SingleAdapter.<BitmapPhoto>toSingle())
.subscribe(bitmapPhoto -> {
.toSingle()
.subscribe { bitmapPhoto ->

});
}
```

## Update parameters

It is also possible to update some parameters after `Fotoapparat` was already started.

```java
fotoapparat.updateParameters(
UpdateRequest.builder()
.flash(
isTurnedOn
? torch()
: off()
)
.build()
```kotlin
fotoapparat.updateConfiguration(
UpdateConfiguration(
flashMode = if (isChecked) torch() else off()
// ...
// all the parameters available in CameraConfiguration
)
)
```

Or alternatively you may provide updates on an existing full configuration.

```kotlin
val configuration = CameraConfiguration(
// A full configuration
// ...
)

fotoapparat.updateConfiguration(
configuration.copy(
flashMode = if (isChecked) torch() else off()
// all the parameters available in CameraConfiguration
)
)
```

## Switch cameras

In order to switch between multiple instances of Fotoapparat, for example an instance using the device's front camera and another using the back, `FotoapparatSwitcher` can be used:
In order to switch between cameras, `Fotoapparat.switchTo()` can be used with the new desired `lensPosition` and its `cameraConfiguration`.

```java
FotoapparatSwitcher fotoapparatSwitcher = FotoapparatSwitcher.withDefault(fotoapparatFront);
fotoapparatSwitcher.switchTo(fotoapparatBack);
```kotlin
fotoapparat.switchTo(
lensPosition = front(),
cameraConfiguration = newConfigurationForFrontCamera
)
```

## Set up
Expand All @@ -159,7 +166,7 @@ repositories {
maven { url 'https://jitpack.io' }
}
compile 'io.fotoapparat.fotoapparat:library:1.5.0'
compile 'io.fotoapparat.fotoapparat:library:2.0.0'
```

Camera permission will be automatically added to your `AndroidManifest.xml`. Do not forget to request this permission on Marshmallow and higher.
Expand Down
34 changes: 32 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext {
versions = [
gradle : '4.4.1',
kotlin : '1.2.10',
code : 1,
name : '1.0.0',
sdk : [
minimum: 16,
target : 27
],
android: [
buildTools: '27.0.3',
support : '27.0.2'
],
rx : [
rxJava1: '1.2.9',
rxJava2: '2.0.8'
],
test : [
junit : '4.12',
mockito: '2.13.0'
],
util : [
commons: '2.5'
]
]
}
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:${project.androidBuildToolsVersion}"
classpath "com.android.tools.build:gradle:3.1.0-alpha06"
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
}
}

allprojects {
repositories {
google()
jcenter()
}
}
Expand All @@ -21,5 +51,5 @@ task clean(type: Delete) {
}

task wrapper(type: Wrapper) {
gradleVersion = project.gradleVersion
gradleVersion = versions.gradle
}
21 changes: 21 additions & 0 deletions fotoapparat-adapters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ The child modules contained herein are additional adapters for other popular exe

To use, supply an instance of your desired adapter when performing a task of a PendingResult.

Kotlin:
```java
fotoapparat.takePicture()
.toBitmap()
.toObservable()
.subscribe { bitmapPhoto ->
// Do something with the photo
}
```


Java:
```java
fotoapparat.takePicture()
.toBitmap()
Expand All @@ -16,3 +28,12 @@ fotoapparat.takePicture()
}
});
```



Supported types:

* `Observable<T>` : RxJava 1/2
* `Flowable<T>` : RxJava 2
* `Single<T>` : RxJava 1/2
* `Completable` : RxJava 1/2
18 changes: 11 additions & 7 deletions fotoapparat-adapters/rxjava/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'kotlin-android'

group = 'io.fotoapparat'

android {
buildToolsVersion project.buildToolsVersion
compileSdkVersion Integer.parseInt(project.compileSdkVersion)
buildToolsVersion versions.android.buildTools
compileSdkVersion versions.sdk.target

defaultConfig {
minSdkVersion Integer.parseInt(project.minSdkVersion)
targetSdkVersion Integer.parseInt(project.targetSdkVersion)
minSdkVersion versions.sdk.minimum
targetSdkVersion versions.sdk.target

archivesBaseName = 'adapter-rxjava'
}
}

dependencies {
compile project(':fotoapparat')
provided "io.reactivex:rxjava:${project.rxjava1Version}"
compileOnly project(':fotoapparat')
compileOnly "io.reactivex:rxjava:${versions.rx.rxJava1}"

testCompile "junit:junit:${project.junitVersion}"
implementation "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}"

testImplementation "io.reactivex:rxjava:${versions.rx.rxJava1}"
testImplementation "junit:junit:${versions.test.junit}"
}

This file was deleted.

Loading

0 comments on commit 2c80a90

Please sign in to comment.