From 97b768fa85f3164f436fcb2e3038d0bda86d2634 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Mon, 7 Aug 2017 22:29:44 +0200 Subject: [PATCH] Refactor packages, removed appcompat dependency --- camerakit/build.gradle | 9 ++++----- .../com/flurgle/camerakit/AspectRatio.java | 8 ++++---- .../com/flurgle/camerakit/Camera1.java | 0 .../com/flurgle/camerakit/Camera2.java | 5 +++++ .../flurgle/camerakit/CameraController.java | 0 .../com/flurgle/camerakit/CameraOptions.java | 0 .../com/flurgle/camerakit/CameraView.java | 20 +++++++++++++------ .../flurgle/camerakit/ExtraProperties.java | 0 .../com/flurgle/camerakit/Mapper.java | 10 +++++----- .../com/flurgle/camerakit/Size.java | 0 .../com/flurgle/camerakit/Facing.java | 0 .../com/flurgle/camerakit/Flash.java | 0 .../com/flurgle/camerakit/Focus.java | 0 .../com/flurgle/camerakit/Grid.java | 0 .../com/flurgle/camerakit/Method.java | 0 .../com/flurgle/camerakit/Permissions.java | 0 .../com/flurgle/camerakit/SessionType.java | 0 .../com/flurgle/camerakit/VideoQuality.java | 0 .../com/flurgle/camerakit/WhiteBalance.java | 0 .../com/flurgle/camerakit/ZoomMode.java | 0 .../com/flurgle/camerakit/CameraUtils.java | 0 .../com/flurgle/camerakit/ExifUtils.java | 0 .../flurgle/camerakit/FocusMarkerLayout.java | 0 .../flurgle/camerakit/GridLinesLayout.java | 0 .../flurgle/camerakit/PinchToZoomLayout.java | 0 .../com/flurgle/camerakit/Preview.java | 0 .../flurgle/camerakit/SurfaceViewPreview.java | 0 .../flurgle/camerakit/TextureViewPreview.java | 0 28 files changed, 32 insertions(+), 20 deletions(-) rename camerakit/src/main/{utils => java}/com/flurgle/camerakit/AspectRatio.java (91%) rename camerakit/src/main/{api16 => java}/com/flurgle/camerakit/Camera1.java (100%) rename camerakit/src/main/{api21 => java}/com/flurgle/camerakit/Camera2.java (98%) rename camerakit/src/main/{base => java}/com/flurgle/camerakit/CameraController.java (100%) rename camerakit/src/main/{base => java}/com/flurgle/camerakit/CameraOptions.java (100%) rename camerakit/src/main/{base => java}/com/flurgle/camerakit/ExtraProperties.java (100%) rename camerakit/src/main/{api16 => java}/com/flurgle/camerakit/Mapper.java (91%) rename camerakit/src/main/{utils => java}/com/flurgle/camerakit/Size.java (100%) rename camerakit/src/main/{types => options}/com/flurgle/camerakit/Facing.java (100%) rename camerakit/src/main/{types => options}/com/flurgle/camerakit/Flash.java (100%) rename camerakit/src/main/{types => options}/com/flurgle/camerakit/Focus.java (100%) rename camerakit/src/main/{types => options}/com/flurgle/camerakit/Grid.java (100%) rename camerakit/src/main/{types => options}/com/flurgle/camerakit/Method.java (100%) rename camerakit/src/main/{types => options}/com/flurgle/camerakit/Permissions.java (100%) rename camerakit/src/main/{types => options}/com/flurgle/camerakit/SessionType.java (100%) rename camerakit/src/main/{types => options}/com/flurgle/camerakit/VideoQuality.java (100%) rename camerakit/src/main/{types => options}/com/flurgle/camerakit/WhiteBalance.java (100%) rename camerakit/src/main/{types => options}/com/flurgle/camerakit/ZoomMode.java (100%) rename camerakit/src/main/{java => utils}/com/flurgle/camerakit/CameraUtils.java (100%) rename camerakit/src/main/{java => utils}/com/flurgle/camerakit/ExifUtils.java (100%) rename camerakit/src/main/{java => views}/com/flurgle/camerakit/FocusMarkerLayout.java (100%) rename camerakit/src/main/{java => views}/com/flurgle/camerakit/GridLinesLayout.java (100%) rename camerakit/src/main/{java => views}/com/flurgle/camerakit/PinchToZoomLayout.java (100%) rename camerakit/src/main/{base => views}/com/flurgle/camerakit/Preview.java (100%) rename camerakit/src/main/{base => views}/com/flurgle/camerakit/SurfaceViewPreview.java (100%) rename camerakit/src/main/{base => views}/com/flurgle/camerakit/TextureViewPreview.java (100%) diff --git a/camerakit/build.gradle b/camerakit/build.gradle index ffeec354..7df79691 100644 --- a/camerakit/build.gradle +++ b/camerakit/build.gradle @@ -16,18 +16,17 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + sourceSets { - main.java.srcDirs += 'src/main/base' - main.java.srcDirs += 'src/main/api16' - main.java.srcDirs += 'src/main/api21' - main.java.srcDirs += 'src/main/types' + main.java.srcDirs += 'src/main/options' + main.java.srcDirs += 'src/main/views' main.java.srcDirs += 'src/main/utils' } } dependencies { - compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:exifinterface:25.3.1' + compile 'com.android.support:support-annotations:25.3.1' compile 'android.arch.lifecycle:runtime:1.0.0-alpha1' compile 'android.arch.lifecycle:extensions:1.0.0-alpha1' annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-alpha1' diff --git a/camerakit/src/main/utils/com/flurgle/camerakit/AspectRatio.java b/camerakit/src/main/java/com/flurgle/camerakit/AspectRatio.java similarity index 91% rename from camerakit/src/main/utils/com/flurgle/camerakit/AspectRatio.java rename to camerakit/src/main/java/com/flurgle/camerakit/AspectRatio.java index 2f153510..21883458 100644 --- a/camerakit/src/main/utils/com/flurgle/camerakit/AspectRatio.java +++ b/camerakit/src/main/java/com/flurgle/camerakit/AspectRatio.java @@ -3,11 +3,11 @@ package com.flurgle.camerakit; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; -import android.support.v4.util.SparseArrayCompat; +import android.util.SparseArray; public class AspectRatio implements Comparable, Parcelable { - private final static SparseArrayCompat> sCache = new SparseArrayCompat<>(16); + private final static SparseArray> sCache = new SparseArray<>(16); private final int mX; private final int mY; @@ -79,10 +79,10 @@ public class AspectRatio implements Comparable, Parcelable { int gcd = gcd(x, y); x /= gcd; y /= gcd; - SparseArrayCompat arrayX = sCache.get(x); + SparseArray arrayX = sCache.get(x); if (arrayX == null) { AspectRatio ratio = new AspectRatio(x, y); - arrayX = new SparseArrayCompat<>(); + arrayX = new SparseArray<>(); arrayX.put(y, ratio); sCache.put(x, arrayX); return ratio; diff --git a/camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java b/camerakit/src/main/java/com/flurgle/camerakit/Camera1.java similarity index 100% rename from camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java rename to camerakit/src/main/java/com/flurgle/camerakit/Camera1.java diff --git a/camerakit/src/main/api21/com/flurgle/camerakit/Camera2.java b/camerakit/src/main/java/com/flurgle/camerakit/Camera2.java similarity index 98% rename from camerakit/src/main/api21/com/flurgle/camerakit/Camera2.java rename to camerakit/src/main/java/com/flurgle/camerakit/Camera2.java index 498493d4..7000cd25 100644 --- a/camerakit/src/main/api21/com/flurgle/camerakit/Camera2.java +++ b/camerakit/src/main/java/com/flurgle/camerakit/Camera2.java @@ -35,6 +35,11 @@ class Camera2 extends CameraController { private final HashMap mExtraPropertiesMap = new HashMap<>(); + @Override + boolean setExposureCorrection(float EVvalue) { + return false; + } + @Override boolean setZoom(float zoom) { return false; diff --git a/camerakit/src/main/base/com/flurgle/camerakit/CameraController.java b/camerakit/src/main/java/com/flurgle/camerakit/CameraController.java similarity index 100% rename from camerakit/src/main/base/com/flurgle/camerakit/CameraController.java rename to camerakit/src/main/java/com/flurgle/camerakit/CameraController.java diff --git a/camerakit/src/main/base/com/flurgle/camerakit/CameraOptions.java b/camerakit/src/main/java/com/flurgle/camerakit/CameraOptions.java similarity index 100% rename from camerakit/src/main/base/com/flurgle/camerakit/CameraOptions.java rename to camerakit/src/main/java/com/flurgle/camerakit/CameraOptions.java diff --git a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java index 156d58d4..035a3ed0 100644 --- a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java +++ b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java @@ -1,6 +1,7 @@ package com.flurgle.camerakit; import android.Manifest; +import android.annotation.TargetApi; import android.app.Activity; import android.arch.lifecycle.Lifecycle; import android.arch.lifecycle.LifecycleObserver; @@ -14,13 +15,12 @@ import android.content.res.TypedArray; import android.graphics.PointF; import android.graphics.Rect; import android.graphics.YuvImage; +import android.os.Build; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; @@ -418,8 +418,15 @@ public class CameraView extends FrameLayout implements LifecycleObserver { */ private boolean checkPermissions(@SessionType int sessionType) { checkPermissionsManifestOrThrow(sessionType); - int cameraCheck = ContextCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA); - int audioCheck = ContextCompat.checkSelfPermission(getContext(), Manifest.permission.RECORD_AUDIO); + boolean api23 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; + int cameraCheck, audioCheck; + if (!api23) { + cameraCheck = PackageManager.PERMISSION_GRANTED; + audioCheck = PackageManager.PERMISSION_GRANTED; + } else { + cameraCheck = getContext().checkSelfPermission(Manifest.permission.CAMERA); + audioCheck = getContext().checkSelfPermission(Manifest.permission.RECORD_AUDIO); + } switch (sessionType) { case SESSION_TYPE_VIDEO: if (cameraCheck != PackageManager.PERMISSION_GRANTED || audioCheck != PackageManager.PERMISSION_GRANTED) { @@ -1069,6 +1076,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver { } + // If we end up here, we're in M. + @TargetApi(Build.VERSION_CODES.M) private void requestPermissions(boolean requestCamera, boolean requestAudio) { Activity activity = null; Context context = getContext(); @@ -1083,8 +1092,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { if (requestCamera) permissions.add(Manifest.permission.CAMERA); if (requestAudio) permissions.add(Manifest.permission.RECORD_AUDIO); if (activity != null) { - ActivityCompat.requestPermissions(activity, - permissions.toArray(new String[permissions.size()]), + activity.requestPermissions(permissions.toArray(new String[permissions.size()]), CameraConstants.PERMISSION_REQUEST_CODE); } } diff --git a/camerakit/src/main/base/com/flurgle/camerakit/ExtraProperties.java b/camerakit/src/main/java/com/flurgle/camerakit/ExtraProperties.java similarity index 100% rename from camerakit/src/main/base/com/flurgle/camerakit/ExtraProperties.java rename to camerakit/src/main/java/com/flurgle/camerakit/ExtraProperties.java diff --git a/camerakit/src/main/api16/com/flurgle/camerakit/Mapper.java b/camerakit/src/main/java/com/flurgle/camerakit/Mapper.java similarity index 91% rename from camerakit/src/main/api16/com/flurgle/camerakit/Mapper.java rename to camerakit/src/main/java/com/flurgle/camerakit/Mapper.java index 796ce72b..b8ac3b76 100644 --- a/camerakit/src/main/api16/com/flurgle/camerakit/Mapper.java +++ b/camerakit/src/main/java/com/flurgle/camerakit/Mapper.java @@ -1,7 +1,7 @@ package com.flurgle.camerakit; import android.hardware.Camera; -import android.support.v4.util.SparseArrayCompat; +import android.util.SparseArray; abstract class Mapper { @@ -15,10 +15,10 @@ abstract class Mapper { @Focus abstract int unmapFocus(T cameraConstant); static class Mapper1 extends Mapper { - private static final SparseArrayCompat FLASH = new SparseArrayCompat<>(); - private static final SparseArrayCompat WB = new SparseArrayCompat<>(); - private static final SparseArrayCompat FACING = new SparseArrayCompat<>(); - private static final SparseArrayCompat FOCUS = new SparseArrayCompat<>(); + private static final SparseArray FLASH = new SparseArray<>(); + private static final SparseArray WB = new SparseArray<>(); + private static final SparseArray FACING = new SparseArray<>(); + private static final SparseArray FOCUS = new SparseArray<>(); static { FLASH.put(CameraConstants.FLASH_OFF, Camera.Parameters.FLASH_MODE_OFF); diff --git a/camerakit/src/main/utils/com/flurgle/camerakit/Size.java b/camerakit/src/main/java/com/flurgle/camerakit/Size.java similarity index 100% rename from camerakit/src/main/utils/com/flurgle/camerakit/Size.java rename to camerakit/src/main/java/com/flurgle/camerakit/Size.java diff --git a/camerakit/src/main/types/com/flurgle/camerakit/Facing.java b/camerakit/src/main/options/com/flurgle/camerakit/Facing.java similarity index 100% rename from camerakit/src/main/types/com/flurgle/camerakit/Facing.java rename to camerakit/src/main/options/com/flurgle/camerakit/Facing.java diff --git a/camerakit/src/main/types/com/flurgle/camerakit/Flash.java b/camerakit/src/main/options/com/flurgle/camerakit/Flash.java similarity index 100% rename from camerakit/src/main/types/com/flurgle/camerakit/Flash.java rename to camerakit/src/main/options/com/flurgle/camerakit/Flash.java diff --git a/camerakit/src/main/types/com/flurgle/camerakit/Focus.java b/camerakit/src/main/options/com/flurgle/camerakit/Focus.java similarity index 100% rename from camerakit/src/main/types/com/flurgle/camerakit/Focus.java rename to camerakit/src/main/options/com/flurgle/camerakit/Focus.java diff --git a/camerakit/src/main/types/com/flurgle/camerakit/Grid.java b/camerakit/src/main/options/com/flurgle/camerakit/Grid.java similarity index 100% rename from camerakit/src/main/types/com/flurgle/camerakit/Grid.java rename to camerakit/src/main/options/com/flurgle/camerakit/Grid.java diff --git a/camerakit/src/main/types/com/flurgle/camerakit/Method.java b/camerakit/src/main/options/com/flurgle/camerakit/Method.java similarity index 100% rename from camerakit/src/main/types/com/flurgle/camerakit/Method.java rename to camerakit/src/main/options/com/flurgle/camerakit/Method.java diff --git a/camerakit/src/main/types/com/flurgle/camerakit/Permissions.java b/camerakit/src/main/options/com/flurgle/camerakit/Permissions.java similarity index 100% rename from camerakit/src/main/types/com/flurgle/camerakit/Permissions.java rename to camerakit/src/main/options/com/flurgle/camerakit/Permissions.java diff --git a/camerakit/src/main/types/com/flurgle/camerakit/SessionType.java b/camerakit/src/main/options/com/flurgle/camerakit/SessionType.java similarity index 100% rename from camerakit/src/main/types/com/flurgle/camerakit/SessionType.java rename to camerakit/src/main/options/com/flurgle/camerakit/SessionType.java diff --git a/camerakit/src/main/types/com/flurgle/camerakit/VideoQuality.java b/camerakit/src/main/options/com/flurgle/camerakit/VideoQuality.java similarity index 100% rename from camerakit/src/main/types/com/flurgle/camerakit/VideoQuality.java rename to camerakit/src/main/options/com/flurgle/camerakit/VideoQuality.java diff --git a/camerakit/src/main/types/com/flurgle/camerakit/WhiteBalance.java b/camerakit/src/main/options/com/flurgle/camerakit/WhiteBalance.java similarity index 100% rename from camerakit/src/main/types/com/flurgle/camerakit/WhiteBalance.java rename to camerakit/src/main/options/com/flurgle/camerakit/WhiteBalance.java diff --git a/camerakit/src/main/types/com/flurgle/camerakit/ZoomMode.java b/camerakit/src/main/options/com/flurgle/camerakit/ZoomMode.java similarity index 100% rename from camerakit/src/main/types/com/flurgle/camerakit/ZoomMode.java rename to camerakit/src/main/options/com/flurgle/camerakit/ZoomMode.java diff --git a/camerakit/src/main/java/com/flurgle/camerakit/CameraUtils.java b/camerakit/src/main/utils/com/flurgle/camerakit/CameraUtils.java similarity index 100% rename from camerakit/src/main/java/com/flurgle/camerakit/CameraUtils.java rename to camerakit/src/main/utils/com/flurgle/camerakit/CameraUtils.java diff --git a/camerakit/src/main/java/com/flurgle/camerakit/ExifUtils.java b/camerakit/src/main/utils/com/flurgle/camerakit/ExifUtils.java similarity index 100% rename from camerakit/src/main/java/com/flurgle/camerakit/ExifUtils.java rename to camerakit/src/main/utils/com/flurgle/camerakit/ExifUtils.java diff --git a/camerakit/src/main/java/com/flurgle/camerakit/FocusMarkerLayout.java b/camerakit/src/main/views/com/flurgle/camerakit/FocusMarkerLayout.java similarity index 100% rename from camerakit/src/main/java/com/flurgle/camerakit/FocusMarkerLayout.java rename to camerakit/src/main/views/com/flurgle/camerakit/FocusMarkerLayout.java diff --git a/camerakit/src/main/java/com/flurgle/camerakit/GridLinesLayout.java b/camerakit/src/main/views/com/flurgle/camerakit/GridLinesLayout.java similarity index 100% rename from camerakit/src/main/java/com/flurgle/camerakit/GridLinesLayout.java rename to camerakit/src/main/views/com/flurgle/camerakit/GridLinesLayout.java diff --git a/camerakit/src/main/java/com/flurgle/camerakit/PinchToZoomLayout.java b/camerakit/src/main/views/com/flurgle/camerakit/PinchToZoomLayout.java similarity index 100% rename from camerakit/src/main/java/com/flurgle/camerakit/PinchToZoomLayout.java rename to camerakit/src/main/views/com/flurgle/camerakit/PinchToZoomLayout.java diff --git a/camerakit/src/main/base/com/flurgle/camerakit/Preview.java b/camerakit/src/main/views/com/flurgle/camerakit/Preview.java similarity index 100% rename from camerakit/src/main/base/com/flurgle/camerakit/Preview.java rename to camerakit/src/main/views/com/flurgle/camerakit/Preview.java diff --git a/camerakit/src/main/base/com/flurgle/camerakit/SurfaceViewPreview.java b/camerakit/src/main/views/com/flurgle/camerakit/SurfaceViewPreview.java similarity index 100% rename from camerakit/src/main/base/com/flurgle/camerakit/SurfaceViewPreview.java rename to camerakit/src/main/views/com/flurgle/camerakit/SurfaceViewPreview.java diff --git a/camerakit/src/main/base/com/flurgle/camerakit/TextureViewPreview.java b/camerakit/src/main/views/com/flurgle/camerakit/TextureViewPreview.java similarity index 100% rename from camerakit/src/main/base/com/flurgle/camerakit/TextureViewPreview.java rename to camerakit/src/main/views/com/flurgle/camerakit/TextureViewPreview.java