removing some no longer needed stuff

This commit is contained in:
tibbi 2022-10-06 19:31:50 +02:00
parent 8f80fcc83f
commit a2828b69c4
17 changed files with 10 additions and 1392 deletions

View File

@ -5,6 +5,7 @@ import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.Bitmap
import android.hardware.SensorManager
import android.hardware.camera2.CameraCharacteristics
import android.net.Uri
import android.os.Bundle
import android.os.Handler
@ -31,7 +32,6 @@ import com.simplemobiletools.camera.extensions.toFlashModeId
import com.simplemobiletools.camera.helpers.*
import com.simplemobiletools.camera.implementations.CameraXInitializer
import com.simplemobiletools.camera.implementations.CameraXPreviewListener
import com.simplemobiletools.camera.implementations.MyCameraImpl
import com.simplemobiletools.camera.interfaces.MyPreview
import com.simplemobiletools.camera.models.ResolutionOption
import com.simplemobiletools.camera.views.FocusCircleView
@ -55,7 +55,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
private lateinit var flashModeScene: Scene
private lateinit var mOrientationEventListener: OrientationEventListener
private lateinit var mFocusCircleView: FocusCircleView
private lateinit var mCameraImpl: MyCameraImpl
private var mPreview: MyPreview? = null
private var mediaSizeToggleGroup: MaterialButtonToggleGroup? = null
private var mPreviewUri: Uri? = null
@ -181,8 +180,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
mIsHardwareShutterHandled = false
mCurrVideoRecTimer = 0
mLastHandledOrientation = 0
mCameraImpl = MyCameraImpl(applicationContext)
config.lastUsedCamera = mCameraImpl.getBackCameraId().toString()
config.lastUsedCamera = CameraCharacteristics.LENS_FACING_BACK.toString()
}
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
@ -330,8 +328,12 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
checkImageCaptureIntent()
mPreview?.setIsImageCaptureIntent(isImageCaptureIntent())
val imageDrawable =
if (config.lastUsedCamera == mCameraImpl.getBackCameraId().toString()) R.drawable.ic_camera_front_vector else R.drawable.ic_camera_rear_vector
val imageDrawable = if (config.lastUsedCamera == CameraCharacteristics.LENS_FACING_BACK.toString()) {
R.drawable.ic_camera_front_vector
} else {
R.drawable.ic_camera_rear_vector
}
toggle_camera.setImageResource(imageDrawable)
mFocusCircleView = FocusCircleView(applicationContext)

View File

@ -1,95 +0,0 @@
package com.simplemobiletools.camera.dialogs
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.camera.R
import com.simplemobiletools.camera.activities.SimpleActivity
import com.simplemobiletools.camera.extensions.config
import com.simplemobiletools.camera.models.MySize
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.models.RadioItem
import kotlinx.android.synthetic.main.dialog_change_resolution.view.change_resolution_photo
import kotlinx.android.synthetic.main.dialog_change_resolution.view.change_resolution_photo_holder
import kotlinx.android.synthetic.main.dialog_change_resolution.view.change_resolution_video
import kotlinx.android.synthetic.main.dialog_change_resolution.view.change_resolution_video_holder
class ChangeResolutionDialog(
val activity: SimpleActivity, val isFrontCamera: Boolean, val photoResolutions: ArrayList<MySize>,
val videoResolutions: ArrayList<MySize>, val openVideoResolutions: Boolean, val callback: () -> Unit
) {
private var dialog: AlertDialog? = null
private val config = activity.config
init {
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_resolution, null).apply {
setupPhotoResolutionPicker(this)
setupVideoResolutionPicker(this)
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.setOnDismissListener { callback() }
.apply {
val titleId = if (isFrontCamera) R.string.front_camera else R.string.back_camera
activity.setupDialogStuff(view, this, titleId) { alertDialog ->
dialog = alertDialog
if (openVideoResolutions) {
view.change_resolution_video_holder.performClick()
}
}
}
}
private fun setupPhotoResolutionPicker(view: View) {
val items = getFormattedResolutions(photoResolutions)
var selectionIndex = if (isFrontCamera) config.frontPhotoResIndex else config.backPhotoResIndex
selectionIndex = Math.max(selectionIndex, 0)
view.change_resolution_photo_holder.setOnClickListener {
RadioGroupDialog(activity, items, selectionIndex) {
selectionIndex = it as Int
view.change_resolution_photo.text = items[selectionIndex].title
if (isFrontCamera) {
config.frontPhotoResIndex = it
} else {
config.backPhotoResIndex = it
}
dialog?.dismiss()
}
}
view.change_resolution_photo.text = items.getOrNull(selectionIndex)?.title
}
private fun setupVideoResolutionPicker(view: View) {
val items = getFormattedResolutions(videoResolutions)
var selectionIndex = if (isFrontCamera) config.frontVideoResIndex else config.backVideoResIndex
view.change_resolution_video_holder.setOnClickListener {
RadioGroupDialog(activity, items, selectionIndex) {
selectionIndex = it as Int
view.change_resolution_video.text = items[selectionIndex].title
if (isFrontCamera) {
config.frontVideoResIndex = it
} else {
config.backVideoResIndex = it
}
dialog?.dismiss()
}
}
view.change_resolution_video.text = items.getOrNull(selectionIndex)?.title
}
private fun getFormattedResolutions(resolutions: List<MySize>): ArrayList<RadioItem> {
val items = ArrayList<RadioItem>(resolutions.size)
val sorted = resolutions.sortedByDescending { it.width * it.height }
sorted.forEachIndexed { index, size ->
val megapixels = String.format("%.1f", (size.width * size.height.toFloat()) / 1000000)
val aspectRatio = size.getAspectRatio(activity)
items.add(RadioItem(index, "${size.width} x ${size.height} ($megapixels MP, $aspectRatio)"))
}
return items
}
}

View File

@ -1,103 +0,0 @@
package com.simplemobiletools.camera.dialogs
import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.camera.R
import com.simplemobiletools.camera.extensions.config
import com.simplemobiletools.camera.models.MySize
import com.simplemobiletools.camera.models.VideoQuality
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.models.RadioItem
import kotlinx.android.synthetic.main.dialog_change_resolution.view.change_resolution_photo
import kotlinx.android.synthetic.main.dialog_change_resolution.view.change_resolution_photo_holder
import kotlinx.android.synthetic.main.dialog_change_resolution.view.change_resolution_video
import kotlinx.android.synthetic.main.dialog_change_resolution.view.change_resolution_video_holder
class ChangeResolutionDialogX(
private val activity: Activity,
private val isFrontCamera: Boolean,
private val photoResolutions: List<MySize> = listOf(),
private val videoResolutions: List<VideoQuality>,
private val callback: () -> Unit,
) {
private var dialog: AlertDialog? = null
private val config = activity.config
init {
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_resolution, null).apply {
setupPhotoResolutionPicker(this)
setupVideoResolutionPicker(this)
}
activity.getAlertDialogBuilder()
.setPositiveButton(R.string.ok, null)
.apply {
val titleId = if (isFrontCamera) R.string.front_camera else R.string.back_camera
activity.setupDialogStuff(view, this, titleId) { alertDialog ->
dialog = alertDialog
}
}
}
private fun setupPhotoResolutionPicker(view: View) {
val items = photoResolutions.mapIndexed { index, resolution ->
val megapixels = resolution.megaPixels
val aspectRatio = resolution.getAspectRatio(activity)
if (resolution.isFullScreen) {
//TODO: Extract to string resource
RadioItem(index, "Full")
} else {
RadioItem(index, "${resolution.width} x ${resolution.height} ($megapixels MP, $aspectRatio)")
}
}
var selectionIndex = if (isFrontCamera) config.frontPhotoResIndex else config.backPhotoResIndex
selectionIndex = selectionIndex.coerceAtLeast(0)
view.change_resolution_photo_holder.setOnClickListener {
RadioGroupDialog(activity, ArrayList(items), selectionIndex) {
selectionIndex = it as Int
view.change_resolution_photo.text = items[selectionIndex].title
if (isFrontCamera) {
config.frontPhotoResIndex = it
} else {
config.backPhotoResIndex = it
}
dialog?.dismiss()
callback.invoke()
}
}
view.change_resolution_photo.text = items.getOrNull(selectionIndex)?.title
}
private fun setupVideoResolutionPicker(view: View) {
val items = videoResolutions.mapIndexed { index, videoQuality ->
val megapixels = videoQuality.megaPixels
val aspectRatio = videoQuality.getAspectRatio(activity)
RadioItem(index, "${videoQuality.width} x ${videoQuality.height} ($megapixels MP, $aspectRatio)")
}
var selectionIndex = if (isFrontCamera) config.frontVideoResIndex else config.backVideoResIndex
selectionIndex = selectionIndex.coerceAtLeast(0)
view.change_resolution_video_holder.setOnClickListener {
RadioGroupDialog(activity, ArrayList(items), selectionIndex) {
selectionIndex = it as Int
val selectedItem = items[selectionIndex]
view.change_resolution_video.text = selectedItem.title
if (isFrontCamera) {
config.frontVideoResIndex = selectionIndex
} else {
config.backVideoResIndex = selectionIndex
}
dialog?.dismiss()
callback.invoke()
}
}
val selectedItem = items.getOrNull(selectionIndex)
view.change_resolution_video.text = selectedItem?.title
}
}

View File

@ -34,15 +34,6 @@ fun Int.toFlashModeId(): Int {
}
}
fun Int.idToAppFlashMode(): Int {
return when (this) {
R.id.flash_on -> FLASH_ON
R.id.flash_off -> FLASH_OFF
R.id.flash_auto -> FLASH_AUTO
else -> throw IllegalArgumentException("Unknown mode: $this")
}
}
fun Int.toCameraSelector(): CameraSelector {
return if (this == CameraSelector.LENS_FACING_FRONT) {
CameraSelector.DEFAULT_FRONT_CAMERA

View File

@ -1,6 +1,5 @@
package com.simplemobiletools.camera.extensions
import androidx.camera.core.AspectRatio
import androidx.camera.video.Quality
import com.simplemobiletools.camera.models.VideoQuality
@ -22,11 +21,3 @@ fun VideoQuality.toCameraXQuality(): Quality {
VideoQuality.SD -> Quality.SD
}
}
fun Quality.getAspectRatio(): Int {
return when(this) {
Quality.UHD, Quality.FHD, Quality.HD -> AspectRatio.RATIO_16_9
Quality.SD -> AspectRatio.RATIO_4_3
else -> throw IllegalArgumentException("Unsupported quality: $this")
}
}

View File

@ -17,7 +17,6 @@ const val BACK_PHOTO_RESOLUTION_INDEX = "back_photo_resolution_index_2"
const val BACK_VIDEO_RESOLUTION_INDEX = "back_video_resolution_index_2"
const val FRONT_PHOTO_RESOLUTION_INDEX = "front_photo_resolution_index_2"
const val FRONT_VIDEO_RESOLUTION_INDEX = "front_video_resolution_index_2"
const val KEEP_SETTINGS_VISIBLE = "keep_settings_visible"
const val SAVE_PHOTO_METADATA = "save_photo_metadata"
const val PHOTO_QUALITY = "photo_quality"
@ -25,17 +24,6 @@ const val FLASH_OFF = 0
const val FLASH_ON = 1
const val FLASH_AUTO = 2
// camera states
const val STATE_INIT = 0
const val STATE_PREVIEW = 1
const val STATE_PICTURE_TAKEN = 2
const val STATE_WAITING_LOCK = 3
const val STATE_WAITING_PRECAPTURE = 4
const val STATE_WAITING_NON_PRECAPTURE = 5
const val STATE_STARTING_RECORDING = 6
const val STATE_STOPING_RECORDING = 7
const val STATE_RECORDING = 8
fun compensateDeviceRotation(orientation: Int) = when (orientation) {
ORIENT_LANDSCAPE_LEFT -> 270
ORIENT_LANDSCAPE_RIGHT -> 90

View File

@ -1,8 +1,6 @@
package com.simplemobiletools.camera.helpers
class MediaSizeStore(
private val config: Config,
) {
class MediaSizeStore(private val config: Config) {
fun storeSize(isPhotoCapture: Boolean, isFrontCamera: Boolean, currentIndex: Int) {
if (isPhotoCapture) {

View File

@ -3,7 +3,7 @@ package com.simplemobiletools.camera.helpers
import com.google.android.material.tabs.TabLayout
interface TabSelectedListener : TabLayout.OnTabSelectedListener {
override fun onTabReselected(tab: TabLayout.Tab?){}
override fun onTabReselected(tab: TabLayout.Tab?) {}
override fun onTabUnselected(tab: TabLayout.Tab?) {}
}

View File

@ -14,7 +14,6 @@ import com.simplemobiletools.commons.extensions.showErrorToast
class VideoQualityManager(
private val activity: AppCompatActivity,
) {
companion object {
private val QUALITIES = listOf(Quality.UHD, Quality.FHD, Quality.HD, Quality.SD)
private val CAMERA_SELECTORS = arrayOf(CameraSelector.DEFAULT_BACK_CAMERA, CameraSelector.DEFAULT_FRONT_CAMERA)

View File

@ -23,7 +23,6 @@ import androidx.lifecycle.LifecycleOwner
import androidx.window.layout.WindowMetricsCalculator
import com.bumptech.glide.load.ImageHeaderParser.UNKNOWN_ORIENTATION
import com.simplemobiletools.camera.R
import com.simplemobiletools.camera.dialogs.ChangeResolutionDialogX
import com.simplemobiletools.camera.extensions.*
import com.simplemobiletools.camera.helpers.*
import com.simplemobiletools.camera.interfaces.MyPreview
@ -326,21 +325,6 @@ class CameraXPreview(
orientationEventListener.disable()
}
override fun showChangeResolutionDialog() {
val oldQuality = videoQualityManager.getUserSelectedQuality(cameraSelector)
ChangeResolutionDialogX(
activity,
isFrontCameraInUse(),
imageQualityManager.getSupportedResolutions(cameraSelector),
videoQualityManager.getSupportedQualities(cameraSelector),
) {
if (oldQuality != videoQualityManager.getUserSelectedQuality(cameraSelector)) {
currentRecording?.stop()
}
startCamera()
}
}
override fun showChangeResolution() {
val selectedResolution = if (isPhotoCapture) {
imageQualityManager.getUserSelectedResolution(cameraSelector).toResolutionOption()

View File

@ -1,20 +0,0 @@
package com.simplemobiletools.camera.implementations
import android.content.Context
import android.hardware.camera2.CameraCharacteristics
import android.hardware.camera2.CameraManager
class MyCameraImpl(val context: Context) {
fun getFrontCameraId() = CameraCharacteristics.LENS_FACING_FRONT
fun getBackCameraId() = CameraCharacteristics.LENS_FACING_BACK
fun getCountOfCameras(): Int? {
return try {
val manager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
manager.cameraIdList.size
} catch (e: Exception) {
null
}
}
}

View File

@ -4,20 +4,12 @@ import android.net.Uri
interface MyPreview {
fun onResumed() = Unit
fun onPaused() = Unit
fun setTargetUri(uri: Uri) = Unit
fun setIsImageCaptureIntent(isImageCaptureIntent: Boolean) = Unit
fun setFlashlightState(state: Int) = Unit
fun getCameraState(): Int = 0
fun showChangeResolutionDialog()
fun toggleFrontBackCamera()
fun toggleFlashlight() = Unit

View File

@ -1,5 +0,0 @@
package com.simplemobiletools.camera.models
import android.graphics.Rect
data class FocusArea(val rect: Rect, val weight: Int)

View File

@ -1,7 +1,6 @@
package com.simplemobiletools.camera.models
import android.content.Context
import android.util.Size
import androidx.annotation.DrawableRes
import androidx.annotation.IdRes
import com.simplemobiletools.camera.R
@ -84,6 +83,4 @@ data class MySize(val width: Int, val height: Int, val isFullScreen: Boolean = f
fun toResolutionOption(): ResolutionOption {
return ResolutionOption(buttonViewId = getButtonId(), imageDrawableResId = getImageResId())
}
fun toSize() = Size(width, height)
}

View File

@ -1,38 +0,0 @@
package com.simplemobiletools.camera.views
import android.content.Context
import android.util.AttributeSet
import android.view.TextureView
// taken from the official Camera2 sample at https://github.com/googlesamples/android-Camera2Basic
class AutoFitTextureView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : TextureView(context, attrs, defStyle) {
private var mRatioWidth = 0
private var mRatioHeight = 0
fun setAspectRatio(width: Int, height: Int) {
if (width < 0 || height < 0) {
throw IllegalArgumentException("Size cannot be negative.")
}
mRatioWidth = width
mRatioHeight = height
requestLayout()
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
val width = MeasureSpec.getSize(widthMeasureSpec)
val height = MeasureSpec.getSize(heightMeasureSpec)
if (mRatioWidth == 0 || mRatioHeight == 0) {
setMeasuredDimension(width, height)
} else {
if (width < height * mRatioWidth / mRatioHeight) {
setMeasuredDimension(width, width * mRatioHeight / mRatioWidth)
} else {
setMeasuredDimension(height * mRatioWidth / mRatioHeight, height)
}
}
}
}

View File

@ -1,59 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/change_resolution_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/activity_margin">
<RelativeLayout
android:id="@+id/change_resolution_photo_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/change_resolution_photo_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/change_resolution_photo"
android:text="@string/photo" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/change_resolution_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@null"
android:clickable="false" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/change_resolution_video_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/small_margin"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/change_resolution_video_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/change_resolution_video"
android:text="@string/video" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/change_resolution_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@null"
android:clickable="false" />
</RelativeLayout>
</LinearLayout>