Skip to content

Commit

Permalink
updated sample
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsguy committed Feb 9, 2019
1 parent a25d758 commit 5c3b21d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 52 deletions.
26 changes: 12 additions & 14 deletions Camera/Fotoapparat/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
apply plugin: 'com.android.application'

repositories {
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
}

dependencies {
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.githang:com-phillipcalvin-iconbutton:1.0.1@aar'
implementation 'com.android.support:support-compat:26.1.0'
implementation 'io.fotoapparat.fotoapparat:library:1.3.0'
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.githang:com-phillipcalvin-iconbutton:1.0.1@aar'
implementation 'com.android.support:support-compat:28.0.0'
implementation 'io.fotoapparat:fotoapparat:2.5.0'
}

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'

compileSdkVersion 28

defaultConfig {
minSdkVersion 15
targetSdkVersion 26
targetSdkVersion 28
applicationId 'com.commonsware.android.camera.fotoapparat'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,24 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import com.github.clans.fab.FloatingActionButton;
import io.fotoapparat.Fotoapparat;
import io.fotoapparat.parameter.ScaleType;
import io.fotoapparat.photo.BitmapPhoto;
import io.fotoapparat.result.PendingResult;
import io.fotoapparat.result.PhotoResult;
import io.fotoapparat.selector.FlashSelectorsKt;
import io.fotoapparat.selector.FocusModeSelectorsKt;
import io.fotoapparat.selector.LensPositionSelectorsKt;
import io.fotoapparat.selector.ResolutionSelectorsKt;
import io.fotoapparat.selector.SelectorsKt;
import io.fotoapparat.view.CameraView;
import static io.fotoapparat.parameter.selector.FlashSelectors.autoFlash;
import static io.fotoapparat.parameter.selector.FlashSelectors.autoRedEye;
import static io.fotoapparat.parameter.selector.FocusModeSelectors.autoFocus;
import static io.fotoapparat.parameter.selector.FocusModeSelectors.continuousFocus;
import static io.fotoapparat.parameter.selector.FocusModeSelectors.fixed;
import static io.fotoapparat.parameter.selector.LensPositionSelectors.back;
import static io.fotoapparat.parameter.selector.Selectors.firstAvailable;
import static io.fotoapparat.parameter.selector.SizeSelectors.biggestSize;
import kotlin.Unit;

public class CameraActivity extends Activity {
private CameraView camera;
private FloatingActionButton fab;
private Fotoapparat fotoapparat;

public static void takePhoto(Activity requester, int requestCode) {
Intent i=new Intent(requester, CameraActivity.class);
Intent i = new Intent(requester, CameraActivity.class);

requester.startActivityForResult(i, requestCode);
}
Expand All @@ -51,24 +45,22 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);

camera=findViewById(R.id.camera);
fab=findViewById(R.id.fab);
CameraView camera = findViewById(R.id.camera);

fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
takePhoto();
}
});
fab = findViewById(R.id.fab);
fab.setOnClickListener(view -> takePhoto());

fotoapparat=Fotoapparat
fotoapparat = Fotoapparat
.with(this)
.into(camera)
.previewScaleType(ScaleType.CENTER_CROP)
.photoSize(biggestSize())
.lensPosition(back())
.focusMode(firstAvailable(continuousFocus(), autoFocus(), fixed()))
.flash(firstAvailable(autoRedEye(), autoFlash()))
.previewScaleType(ScaleType.CenterCrop)
.photoResolution(ResolutionSelectorsKt.highestResolution())
.lensPosition(LensPositionSelectorsKt.back())
.focusMode(SelectorsKt.firstAvailable(
FocusModeSelectorsKt.continuousFocusPicture(),
FocusModeSelectorsKt.autoFocus(), FocusModeSelectorsKt.fixed()))
.flash(SelectorsKt.firstAvailable(FlashSelectorsKt.autoRedEye(),
FlashSelectorsKt.autoFlash()))
.build();
}

Expand All @@ -87,16 +79,15 @@ protected void onStop() {
private void takePhoto() {
fab.setEnabled(false);

PhotoResult result=fotoapparat.takePicture();
PhotoResult result = fotoapparat.takePicture();

result.toBitmap().whenAvailable(bitmapPhoto -> {
// TODO: do something with picture

result.toBitmap().whenAvailable(new PendingResult.Callback<BitmapPhoto>() {
@Override
public void onResult(BitmapPhoto bitmapPhoto) {
// TODO: do something with picture
setResult(RESULT_OK);
finish();

setResult(RESULT_OK);
finish();
}
return Unit.INSTANCE;
});
}
}
3 changes: 1 addition & 2 deletions Camera/Fotoapparat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.3.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -17,6 +17,5 @@ allprojects {
repositories {
jcenter()
google()
maven { url 'https://jitpack.io' }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

0 comments on commit 5c3b21d

Please sign in to comment.