Skip to content

Commit a7bcc8f

Browse files
authored
Merge pull request #16 from triniwiz/feat/3.0.0-alpha17
feat(): 3.0.0 alpha17
2 parents da25e2f + 48df22e commit a7bcc8f

File tree

5 files changed

+47
-24
lines changed

5 files changed

+47
-24
lines changed

fancycamera/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ group = 'com.github.triniwiz.fancycamera'
88
ext {
99
PUBLISH_GROUP_ID = 'com.github.triniwiz'
1010
PUBLISH_ARTIFACT_ID = 'fancycamera'
11-
PUBLISH_VERSION = '3.0.0-alpha16'
11+
PUBLISH_VERSION = '3.0.0-alpha17'
1212
}
1313

1414
android {

fancycamera/publish.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'maven-publish'
22
apply plugin: 'com.jfrog.bintray'
33

44
group 'com.github.triniwiz.fancycamera'
5-
version '3.0.0-alpha15'
5+
version '3.0.0-alpha17'
66

77

88
afterEvaluate {
@@ -16,7 +16,7 @@ afterEvaluate {
1616
// You can then customize attributes of the publication as shown below.
1717
groupId = 'com.github.triniwiz'
1818
artifactId = 'fancycamera'
19-
version = '3.0.0-alpha16'
19+
version = '3.0.0-alpha17'
2020
}
2121
}
2222
}

fancycamera/src/main/java/com/github/triniwiz/fancycamera/Camera2.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,15 @@ class Camera2 @JvmOverloads constructor(
432432

433433
@SuppressLint("RestrictedApi", "UnsafeExperimentalUsageError")
434434
override fun orientationUpdated() {
435-
435+
val rotation = when (currentOrientation) {
436+
270 -> Surface.ROTATION_270
437+
180 -> Surface.ROTATION_180
438+
90 -> Surface.ROTATION_90
439+
else -> Surface.ROTATION_0
440+
}
441+
imageCapture?.targetRotation = rotation
442+
videoCapture?.setTargetRotation(rotation)
443+
imageAnalysis?.targetRotation = rotation
436444
}
437445

438446
private fun getDeviceRotation(): Int {
@@ -507,6 +515,9 @@ class Camera2 @JvmOverloads constructor(
507515
private fun setUpAnalysis() {
508516
val builder = androidx.camera.core.ImageAnalysis.Builder()
509517
.apply {
518+
if(getDeviceRotation() > -1){
519+
setTargetRotation(getDeviceRotation())
520+
}
510521
setBackpressureStrategy(STRATEGY_KEEP_ONLY_LATEST)
511522
}
512523
val extender = Camera2Interop.Extender(builder)
@@ -574,6 +585,9 @@ class Camera2 @JvmOverloads constructor(
574585
}
575586

576587
val builder = ImageCapture.Builder().apply {
588+
if(getDeviceRotation() > -1){
589+
setTargetRotation(getDeviceRotation())
590+
}
577591
if (pictureSize == "0x0") {
578592
setTargetAspectRatio(
579593
when (displayRatio) {
@@ -683,6 +697,9 @@ class Camera2 @JvmOverloads constructor(
683697
val profile = getCamcorderProfile(quality)
684698
val builder = VideoCapture.Builder()
685699
.apply {
700+
if(getDeviceRotation() > -1){
701+
setTargetRotation(getDeviceRotation())
702+
}
686703
setTargetResolution(android.util.Size(profile.videoFrameWidth, profile.videoFrameHeight))
687704
setMaxResolution(android.util.Size(profile.videoFrameWidth, profile.videoFrameHeight))
688705

@@ -1033,7 +1050,6 @@ class Camera2 @JvmOverloads constructor(
10331050
// Registering image's required rotation, provided by Androidx ImageAnalysis
10341051
var imageTargetRotation = image.imageInfo.rotationDegrees
10351052
matrix.postRotate(imageTargetRotation.toFloat())
1036-
Log.d("Camera2", "takePhoto: imageTargetRotation=$imageTargetRotation")
10371053

10381054
// Flipping over the image in case it is the front camera
10391055
if (position == CameraPosition.FRONT)
@@ -1052,7 +1068,6 @@ class Camera2 @JvmOverloads constructor(
10521068
originalWidth = originalHeight;
10531069
}
10541070
}
1055-
Log.d("Camera2", "takePhoto: originalWidth=$originalWidth, originalHeight=$originalHeight")
10561071
val rotated = Bitmap.createBitmap(bm, offsetWidth, offsetHeight, originalWidth, originalHeight, matrix, false)
10571072
outputStream = FileOutputStream(file!!, false)
10581073
var override: Bitmap? = null

fancycamera/src/main/java/com/github/triniwiz/fancycamera/CameraBase.kt

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.triniwiz.fancycamera
33
import android.Manifest
44
import android.app.Activity
55
import android.content.Context
6+
import android.content.pm.ActivityInfo
67
import android.content.pm.PackageManager
78
import android.media.CamcorderProfile
89
import android.media.MediaRecorder
@@ -220,9 +221,9 @@ abstract class CameraBase @JvmOverloads constructor(
220221
}
221222

222223
/** Device orientation in degrees 0-359 */
223-
internal var currentOrientation: Int = OrientationEventListener.ORIENTATION_UNKNOWN
224+
var currentOrientation: Int = OrientationEventListener.ORIENTATION_UNKNOWN
224225

225-
internal abstract fun orientationUpdated();
226+
abstract fun orientationUpdated();
226227

227228
internal val VIDEO_RECORDER_PERMISSIONS_REQUEST = 868
228229
internal val VIDEO_RECORDER_PERMISSIONS = arrayOf(Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA)
@@ -244,17 +245,18 @@ abstract class CameraBase @JvmOverloads constructor(
244245

245246
private val orientationEventListener = object : OrientationEventListener(context) {
246247
override fun onOrientationChanged(orientation: Int) {
247-
// Based on: https://developer.android.com/reference/androidx/camera/core/ImageAnalysis#setTargetRotation(int)
248-
val newOrientation = when (orientation) {
249-
in 0..20, in 340..359 -> 0
250-
in 70..110 -> 90
251-
in 250..290 -> 270
252-
in 160..200 -> 180
253-
else -> currentOrientation
254-
}
255-
if (newOrientation != currentOrientation) {
256-
Log.d("CameraBase", "Event: onOrientationChanged($orientation) -> currentOrientation = $currentOrientation to $newOrientation");
257-
currentOrientation = newOrientation
248+
if(rotation == CameraOrientation.UNKNOWN){
249+
val newOrientation = when (orientation) {
250+
in 45 until 135 -> 270
251+
in 135 until 225 -> 180
252+
in 225 until 315 -> 90
253+
else -> 0
254+
}
255+
256+
if (newOrientation != currentOrientation) {
257+
currentOrientation = newOrientation
258+
orientationUpdated()
259+
}
258260
}
259261
}
260262
}
@@ -263,6 +265,12 @@ abstract class CameraBase @JvmOverloads constructor(
263265
orientationEventListener.enable()
264266
}
265267

268+
@Synchronized
269+
@Throws(Throwable::class)
270+
protected fun finalize() {
271+
orientationEventListener.disable()
272+
}
273+
266274

267275
private var timerLock: Any = Any()
268276

fancycamera/src/main/java/com/github/triniwiz/fancycamera/CameraOrientation.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.github.triniwiz.fancycamera
22

33
enum class CameraOrientation constructor(val value: Int) {
4-
UNKNOWN(0),
5-
PORTRAIT(1),
6-
PORTRAIT_UPSIDE_DOWN(2),
7-
LANDSCAPE_LEFT(3),
8-
LANDSCAPE_RIGHT(4);
4+
UNKNOWN(1000),
5+
PORTRAIT(1001),
6+
PORTRAIT_UPSIDE_DOWN(1002),
7+
LANDSCAPE_LEFT(1003),
8+
LANDSCAPE_RIGHT(1004);
99

1010
companion object {
1111
fun from(value: Int): CameraOrientation = values().first { it.value == value }

0 commit comments

Comments
 (0)