create a helper function for getting the proper camera impl
This commit is contained in:
parent
3e6aab0cb5
commit
2cdae95de8
|
@ -16,10 +16,9 @@ import com.bumptech.glide.request.RequestOptions
|
||||||
import com.simplemobiletools.camera.BuildConfig
|
import com.simplemobiletools.camera.BuildConfig
|
||||||
import com.simplemobiletools.camera.R
|
import com.simplemobiletools.camera.R
|
||||||
import com.simplemobiletools.camera.extensions.config
|
import com.simplemobiletools.camera.extensions.config
|
||||||
|
import com.simplemobiletools.camera.extensions.getMyCamera
|
||||||
import com.simplemobiletools.camera.extensions.navBarHeight
|
import com.simplemobiletools.camera.extensions.navBarHeight
|
||||||
import com.simplemobiletools.camera.helpers.*
|
import com.simplemobiletools.camera.helpers.*
|
||||||
import com.simplemobiletools.camera.implementations.MyCameraOneImpl
|
|
||||||
import com.simplemobiletools.camera.implementations.MyCameraTwoImpl
|
|
||||||
import com.simplemobiletools.camera.interfaces.MyCamera
|
import com.simplemobiletools.camera.interfaces.MyCamera
|
||||||
import com.simplemobiletools.camera.views.FocusCircleView
|
import com.simplemobiletools.camera.views.FocusCircleView
|
||||||
import com.simplemobiletools.camera.views.PreviewCameraOne
|
import com.simplemobiletools.camera.views.PreviewCameraOne
|
||||||
|
@ -121,7 +120,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||||
mCurrVideoRecTimer = 0
|
mCurrVideoRecTimer = 0
|
||||||
mCurrCameraId = 0
|
mCurrCameraId = 0
|
||||||
mLastHandledOrientation = 0
|
mLastHandledOrientation = 0
|
||||||
mCameraImpl = if (isLollipopPlus()) MyCameraTwoImpl(applicationContext) else MyCameraOneImpl(applicationContext)
|
mCameraImpl = getMyCamera()
|
||||||
|
|
||||||
if (config.alwaysOpenBackCamera) {
|
if (config.alwaysOpenBackCamera) {
|
||||||
config.lastUsedCamera = mCameraImpl.getBackCameraId()
|
config.lastUsedCamera = mCameraImpl.getBackCameraId()
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.simplemobiletools.camera.R
|
||||||
import com.simplemobiletools.camera.activities.SimpleActivity
|
import com.simplemobiletools.camera.activities.SimpleActivity
|
||||||
import com.simplemobiletools.camera.extensions.config
|
import com.simplemobiletools.camera.extensions.config
|
||||||
import com.simplemobiletools.camera.extensions.getAspectRatio
|
import com.simplemobiletools.camera.extensions.getAspectRatio
|
||||||
|
import com.simplemobiletools.camera.extensions.getMyCamera
|
||||||
import com.simplemobiletools.camera.helpers.Config
|
import com.simplemobiletools.camera.helpers.Config
|
||||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
|
@ -16,7 +17,7 @@ import kotlinx.android.synthetic.main.dialog_change_resolution.view.*
|
||||||
|
|
||||||
class ChangeResolutionDialog(val activity: SimpleActivity, val config: Config, val camera: Camera, val callback: () -> Unit) {
|
class ChangeResolutionDialog(val activity: SimpleActivity, val config: Config, val camera: Camera, val callback: () -> Unit) {
|
||||||
var dialog: AlertDialog
|
var dialog: AlertDialog
|
||||||
private val isBackCamera = activity.config.lastUsedCamera == Camera.CameraInfo.CAMERA_FACING_BACK
|
private val isBackCamera = activity.config.lastUsedCamera == activity.getMyCamera().getBackCameraId()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_resolution, null).apply {
|
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_resolution, null).apply {
|
||||||
|
|
|
@ -9,7 +9,7 @@ fun Activity.getPreviewRotation(cameraId: Int): Int {
|
||||||
val degrees = getDeviceRotationDegrees()
|
val degrees = getDeviceRotationDegrees()
|
||||||
|
|
||||||
var result: Int
|
var result: Int
|
||||||
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
if (info.facing == getMyCamera().getFrontCameraId()) {
|
||||||
result = (info.orientation + degrees) % 360
|
result = (info.orientation + degrees) % 360
|
||||||
result = 360 - result
|
result = 360 - result
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,6 +4,11 @@ import android.content.Context
|
||||||
import android.graphics.Point
|
import android.graphics.Point
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import com.simplemobiletools.camera.helpers.Config
|
import com.simplemobiletools.camera.helpers.Config
|
||||||
|
import com.simplemobiletools.camera.helpers.ORIENT_LANDSCAPE_LEFT
|
||||||
|
import com.simplemobiletools.camera.helpers.ORIENT_LANDSCAPE_RIGHT
|
||||||
|
import com.simplemobiletools.camera.implementations.MyCameraOneImpl
|
||||||
|
import com.simplemobiletools.camera.implementations.MyCameraTwoImpl
|
||||||
|
import com.simplemobiletools.commons.helpers.isLollipopPlus
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -44,3 +49,12 @@ val Context.realScreenSize: Point
|
||||||
}
|
}
|
||||||
|
|
||||||
val Context.navBarHeight: Int get() = realScreenSize.y - usableScreenSize.y
|
val Context.navBarHeight: Int get() = realScreenSize.y - usableScreenSize.y
|
||||||
|
|
||||||
|
fun Context.getMyCamera() = if (isLollipopPlus()) MyCameraTwoImpl(applicationContext) else MyCameraOneImpl(applicationContext)
|
||||||
|
|
||||||
|
fun Context.compensateDeviceRotation(orientation: Int, currCameraId: Int) = when {
|
||||||
|
orientation == ORIENT_LANDSCAPE_LEFT -> 270
|
||||||
|
orientation == ORIENT_LANDSCAPE_RIGHT -> 90
|
||||||
|
currCameraId == getMyCamera().getFrontCameraId() -> 180
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package com.simplemobiletools.camera.extensions
|
|
||||||
|
|
||||||
import android.hardware.Camera
|
|
||||||
import com.simplemobiletools.camera.helpers.ORIENT_LANDSCAPE_LEFT
|
|
||||||
import com.simplemobiletools.camera.helpers.ORIENT_LANDSCAPE_RIGHT
|
|
||||||
|
|
||||||
fun Int.compensateDeviceRotation(currCameraId: Int) = when {
|
|
||||||
this == ORIENT_LANDSCAPE_LEFT -> 270
|
|
||||||
this == ORIENT_LANDSCAPE_RIGHT -> 90
|
|
||||||
currCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT -> 180
|
|
||||||
else -> 0
|
|
||||||
}
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.simplemobiletools.camera.helpers
|
package com.simplemobiletools.camera.helpers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.hardware.Camera
|
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
|
import com.simplemobiletools.camera.extensions.getMyCamera
|
||||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
set(flipPhotos) = prefs.edit().putBoolean(FLIP_PHOTOS, flipPhotos).apply()
|
set(flipPhotos) = prefs.edit().putBoolean(FLIP_PHOTOS, flipPhotos).apply()
|
||||||
|
|
||||||
var lastUsedCamera: Int
|
var lastUsedCamera: Int
|
||||||
get() = prefs.getInt(LAST_USED_CAMERA, Camera.CameraInfo.CAMERA_FACING_BACK)
|
get() = prefs.getInt(LAST_USED_CAMERA, context.getMyCamera().getBackCameraId())
|
||||||
set(cameraId) = prefs.edit().putInt(LAST_USED_CAMERA, cameraId).apply()
|
set(cameraId) = prefs.edit().putInt(LAST_USED_CAMERA, cameraId).apply()
|
||||||
|
|
||||||
var flashlightState: Int
|
var flashlightState: Int
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
package com.simplemobiletools.camera.helpers
|
package com.simplemobiletools.camera.helpers
|
||||||
|
|
||||||
val ORIENT_PORTRAIT = 0
|
const val ORIENT_PORTRAIT = 0
|
||||||
val ORIENT_LANDSCAPE_LEFT = 1
|
const val ORIENT_LANDSCAPE_LEFT = 1
|
||||||
val ORIENT_LANDSCAPE_RIGHT = 2
|
const val ORIENT_LANDSCAPE_RIGHT = 2
|
||||||
|
|
||||||
// shared preferences
|
// shared preferences
|
||||||
val SAVE_PHOTOS = "save_photos"
|
const val SAVE_PHOTOS = "save_photos"
|
||||||
val SHOW_PREVIEW = "show_preview"
|
const val SHOW_PREVIEW = "show_preview"
|
||||||
val SOUND = "sound"
|
const val SOUND = "sound"
|
||||||
val FOCUS_BEFORE_CAPTURE = "focus_before_capture"
|
const val FOCUS_BEFORE_CAPTURE = "focus_before_capture"
|
||||||
val VOLUME_BUTTONS_AS_SHUTTER = "volume_buttons_as_shutter"
|
const val VOLUME_BUTTONS_AS_SHUTTER = "volume_buttons_as_shutter"
|
||||||
val TURN_FLASH_OFF_AT_STARTUP = "turn_flash_off_at_startup"
|
const val TURN_FLASH_OFF_AT_STARTUP = "turn_flash_off_at_startup"
|
||||||
val FLIP_PHOTOS = "flip_photos"
|
const val FLIP_PHOTOS = "flip_photos"
|
||||||
val LAST_USED_CAMERA = "last_used_camera"
|
const val LAST_USED_CAMERA = "last_used_camera"
|
||||||
val FLASHLIGHT_STATE = "flashlight_state"
|
const val FLASHLIGHT_STATE = "flashlight_state"
|
||||||
val BACK_PHOTO_RESOLUTION_INDEX = "back_photo_resolution_index"
|
const val BACK_PHOTO_RESOLUTION_INDEX = "back_photo_resolution_index"
|
||||||
val BACK_VIDEO_RESOLUTION_INDEX = "back_video_resolution_index"
|
const val BACK_VIDEO_RESOLUTION_INDEX = "back_video_resolution_index"
|
||||||
val FRONT_PHOTO_RESOLUTION_INDEX = "front_photo_resolution_index"
|
const val FRONT_PHOTO_RESOLUTION_INDEX = "front_photo_resolution_index"
|
||||||
val FRONT_VIDEO_RESOLUTION_INDEX = "front_video_resolution_index"
|
const val FRONT_VIDEO_RESOLUTION_INDEX = "front_video_resolution_index"
|
||||||
val PHOTO_PREVIEW_HINT_SHOWN = "photo_preview_hint_shown"
|
const val PHOTO_PREVIEW_HINT_SHOWN = "photo_preview_hint_shown"
|
||||||
val KEEP_SETTINGS_VISIBLE = "keep_settings_visible"
|
const val KEEP_SETTINGS_VISIBLE = "keep_settings_visible"
|
||||||
val ALWAYS_OPEN_BACK_CAMERA = "always_open_back_camera"
|
const val ALWAYS_OPEN_BACK_CAMERA = "always_open_back_camera"
|
||||||
val SAVE_PHOTO_METADATA = "save_photo_metadata"
|
const val SAVE_PHOTO_METADATA = "save_photo_metadata"
|
||||||
val PHOTO_QUALITY = "photo_quality"
|
const val PHOTO_QUALITY = "photo_quality"
|
||||||
|
|
||||||
val FLASH_OFF = 0
|
const val FLASH_OFF = 0
|
||||||
val FLASH_ON = 1
|
const val FLASH_ON = 1
|
||||||
val FLASH_AUTO = 2
|
const val FLASH_AUTO = 2
|
||||||
|
|
|
@ -3,17 +3,13 @@ package com.simplemobiletools.camera.helpers
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.Matrix
|
import android.graphics.Matrix
|
||||||
import android.hardware.Camera
|
|
||||||
import android.media.ExifInterface
|
import android.media.ExifInterface
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import com.simplemobiletools.camera.R
|
import com.simplemobiletools.camera.R
|
||||||
import com.simplemobiletools.camera.activities.MainActivity
|
import com.simplemobiletools.camera.activities.MainActivity
|
||||||
import com.simplemobiletools.camera.extensions.compensateDeviceRotation
|
import com.simplemobiletools.camera.extensions.*
|
||||||
import com.simplemobiletools.camera.extensions.config
|
|
||||||
import com.simplemobiletools.camera.extensions.getOutputMediaFile
|
|
||||||
import com.simplemobiletools.camera.extensions.getPreviewRotation
|
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.isNougatPlus
|
import com.simplemobiletools.commons.helpers.isNougatPlus
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -72,7 +68,7 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
|
||||||
var image = BitmapFactory.decodeByteArray(data, 0, data.size)
|
var image = BitmapFactory.decodeByteArray(data, 0, data.size)
|
||||||
val exif = ExifInterface(photoFile.toString())
|
val exif = ExifInterface(photoFile.toString())
|
||||||
|
|
||||||
val deviceRot = deviceOrientation.compensateDeviceRotation(currCameraId)
|
val deviceRot = activity.compensateDeviceRotation(deviceOrientation, currCameraId)
|
||||||
val previewRot = activity.getPreviewRotation(currCameraId)
|
val previewRot = activity.getPreviewRotation(currCameraId)
|
||||||
val orient = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
|
val orient = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
|
||||||
val imageRot = orient.degreesFromOrientation()
|
val imageRot = orient.degreesFromOrientation()
|
||||||
|
@ -82,7 +78,7 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
|
||||||
image = rotate(image, totalRotation)
|
image = rotate(image, totalRotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT && !activity.config.flipPhotos) {
|
if (currCameraId == activity.getMyCamera().getFrontCameraId() && !activity.config.flipPhotos) {
|
||||||
val matrix = Matrix()
|
val matrix = Matrix()
|
||||||
if (path.startsWith(activity.internalStoragePath)) {
|
if (path.startsWith(activity.internalStoragePath)) {
|
||||||
matrix.preScale(1f, -1f)
|
matrix.preScale(1f, -1f)
|
||||||
|
|
|
@ -735,7 +735,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MediaScannerConnecti
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getVideoRotation(): Int {
|
private fun getVideoRotation(): Int {
|
||||||
val deviceRot = mActivity!!.mLastHandledOrientation.compensateDeviceRotation(mCurrCameraId)
|
val deviceRot = mActivity!!.compensateDeviceRotation(mActivity!!.mLastHandledOrientation, mCurrCameraId)
|
||||||
val previewRot = mActivity!!.getPreviewRotation(mCurrCameraId)
|
val previewRot = mActivity!!.getPreviewRotation(mCurrCameraId)
|
||||||
return (deviceRot + previewRot) % 360
|
return (deviceRot + previewRot) % 360
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue