Skip to content

Commit

Permalink
#1 landscape issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hongbeomi committed Nov 26, 2020
1 parent 4525113 commit b0fdfdd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
16 changes: 16 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package github.hongbeomi.macgyver.camerax

import android.content.Context
import android.content.res.Configuration
import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.RectF
Expand All @@ -25,16 +26,33 @@ open class GraphicOverlay(context: Context?, attrs: AttributeSet?) :

fun calculateRect(height: Float, width: Float, boundingBoxT: Rect): RectF {

// why hight, width?
// because analyze image rotate value is 90
val scaleX = overlay.width.toFloat() / height
val scaleY = overlay.height.toFloat() / width
// for land scape
fun isLandScapeMode(): Boolean {
return overlay.context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
}

fun whenLandScapeModeWidth(): Float {
return when(isLandScapeMode()) {
true -> width
false -> height
}
}

fun whenLandScapeModeHeight(): Float {
return when(isLandScapeMode()) {
true -> height
false -> width
}
}

val scaleX = overlay.width.toFloat() / whenLandScapeModeWidth()
val scaleY = overlay.height.toFloat() / whenLandScapeModeHeight()
val scale = scaleX.coerceAtLeast(scaleY)
overlay.mScale = scale

// Calculate offset (we need to center the overlay on the target)
val offsetX = (overlay.width.toFloat() - ceil(height * scale)) / 2.0f
val offsetY = (overlay.height.toFloat() - ceil(width * scale)) / 2.0f
val offsetX = (overlay.width.toFloat() - ceil(whenLandScapeModeWidth() * scale)) / 2.0f
val offsetY = (overlay.height.toFloat() - ceil(whenLandScapeModeHeight() * scale)) / 2.0f

overlay.mOffsetX = offsetX
overlay.mOffsetY = offsetY
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
'cameraX' : '1.0.0-beta07',
]
dependencies {
classpath "com.android.tools.build:gradle:4.1.0-beta01"
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Aug 03 18:49:13 KST 2020
#Thu Nov 26 18:12:09 KST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-rc-1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

0 comments on commit b0fdfdd

Please sign in to comment.