Skip to content

Commit

Permalink
Set autofocus when launching video preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Grzegorz Kapusta authored and Grzegorz Kapusta committed Aug 16, 2017
1 parent 0b9c98a commit 746d80b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ android {
applicationId "pl.pola_app"
minSdkVersion 16
targetSdkVersion 25
versionCode 22
versionName "1.5"
versionCode 23
versionName "1.5.1"
}

signingConfigs {
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/pl/pola_app/helpers/OldCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class OldCamera extends CameraCompat {

private static final int DEFAULT_MIN_PIC_SIZE = 1000;
Camera camera;
boolean saveToTakePicture = false;
boolean safeToTakePicture = false;
boolean isPreviewing = false;

private final int maxPictureSize;
Expand All @@ -29,6 +29,7 @@ public class OldCamera extends CameraCompat {
@Override
public void open(){
camera = Camera.open();
camera.cancelAutoFocus();
final Camera.Parameters parameters = camera.getParameters();
final List<Camera.Size> supportedPictureSizes = parameters.getSupportedPictureSizes();
Camera.Size size = supportedPictureSizes.get(0);
Expand All @@ -39,8 +40,9 @@ public void open(){
size = cameraSize;
}
}
parameters.setSceneMode(Camera.Parameters.SCENE_MODE_PORTRAIT);

parameters.setPictureSize(size.width, size.height);
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
camera.setParameters(parameters);
camera.setDisplayOrientation(90);
}
Expand All @@ -51,8 +53,9 @@ public void openPreview(SurfaceHolder surface) {
try {
camera.setPreviewDisplay(surface);
camera.startPreview();
camera.autoFocus(null);
isPreviewing = true;
saveToTakePicture = true;
safeToTakePicture = true;
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -63,17 +66,17 @@ public void closePreview() {
camera.stopPreview();
camera.release();
isPreviewing = false;
saveToTakePicture = false;
safeToTakePicture = false;
}

@Override
public void takePicture(OnPhotoTakenSuccessListener onPhotoTakenSuccessListener) {
if (!saveToTakePicture) {
if (!safeToTakePicture) {
Log.e("TAG", "Skipped photo");
return;
}
camera.takePicture(null, null, (data, camera) -> {
saveToTakePicture = true;
safeToTakePicture = true;
final Camera.Parameters parameters = camera.getParameters();
final Camera.Size pictureSize = parameters.getPictureSize();
final Bitmap bitmap = FileUtils.rotateImageAndScale(BitmapFactory.decodeByteArray(data, 0, data.length), 90, maxPictureSize);
Expand All @@ -87,6 +90,6 @@ public void takePicture(OnPhotoTakenSuccessListener onPhotoTakenSuccessListener)
);
camera.startPreview();
});
saveToTakePicture = false;
safeToTakePicture = false;
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/pl/pola_app/helpers/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.res.Resources;
import android.os.Build;
import android.support.compat.BuildConfig;
import android.text.TextUtils;

public class Utils {
Expand All @@ -28,7 +29,7 @@ public static String getDeviceName() {
if (Build.MODEL.startsWith(Build.MANUFACTURER)) {
return upperFirstLetter(Build.MODEL);
}
return "Android: " + upperFirstLetter(Build.MANUFACTURER) + " " + Build.MODEL;
return "Android: " + upperFirstLetter(Build.MANUFACTURER) + " " + Build.MODEL + " (" + BuildConfig.VERSION_NAME + ")";
}

private static String upperFirstLetter(String strToUpper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void onDestroy() {
view = null;
}

public void sandFilesToServer(List<TakenPicInfo> list) {
public void sendFilesToServer(List<TakenPicInfo> list) {
final PhotoPicturesReport photoPicturesReport = PhotoPicturesReport.builder()
.setDeviceName(Utils.getDeviceName())
.setFilesCount(list.size())
Expand Down Expand Up @@ -146,7 +146,7 @@ public void onTakePicture(Bitmap bitmap, long time, int originalWidth, int origi
fileNames.add(new TakenPicInfo(picturePath, originalWidth, originalHeight, width, height));
Log.d(TAG, "File " + picturePath + " is saved o thread " + Thread.currentThread().getName());
if (time == 1) {
sandFilesToServer(fileNames);
sendFilesToServer(fileNames);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void onTeachPolaButtonClick() {

@Override
public void onTeachPolaAction(SearchResult searchResult) {
mainPresenter.onTechPolaClick(searchResult);
mainPresenter.onTeachPolaClick(searchResult);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void reportButtonClicked(ReportButtonClickedEvent event) {
viewBinder.launchReportActivity(productId);
}

public void onTechPolaClick(SearchResult searchResult) {
public void onTeachPolaClick(SearchResult searchResult) {
viewBinder.displayVideoActivity(searchResult, sessionId.get());
}

Expand Down

0 comments on commit 746d80b

Please sign in to comment.