fill in the values at resolution pickers

This commit is contained in:
tibbi 2017-03-20 23:23:30 +01:00
parent cee0ada35f
commit ba173944f7
1 changed files with 30 additions and 7 deletions

View File

@ -3,21 +3,19 @@ package com.simplemobiletools.camera.dialogs
import android.hardware.Camera import android.hardware.Camera
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.view.LayoutInflater import android.view.LayoutInflater
import com.simplemobiletools.camera.Preview.Companion.config
import com.simplemobiletools.camera.R import com.simplemobiletools.camera.R
import com.simplemobiletools.camera.activities.SimpleActivity import com.simplemobiletools.camera.activities.SimpleActivity
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.models.RadioItem
import kotlinx.android.synthetic.main.dialog_change_resolution.view.* import kotlinx.android.synthetic.main.dialog_change_resolution.view.*
class ChangeResolutionDialog(val activity: SimpleActivity, val isBackCamera: Boolean, val camera: Camera, val callback: () -> Unit) { class ChangeResolutionDialog(val activity: SimpleActivity, val isBackCamera: Boolean, val camera: Camera, val callback: () -> Unit) {
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 {
change_resolution_photo_holder.setOnClickListener { change_resolution_photo_holder.setOnClickListener { showPhotoResolutionPicker() }
change_resolution_video_holder.setOnClickListener { showVideoResolutionPicker() }
}
change_resolution_video_holder.setOnClickListener {
}
} }
AlertDialog.Builder(activity) AlertDialog.Builder(activity)
@ -26,4 +24,29 @@ class ChangeResolutionDialog(val activity: SimpleActivity, val isBackCamera: Boo
activity.setupDialogStuff(view, this, if (isBackCamera) R.string.back_camera else R.string.front_camera) activity.setupDialogStuff(view, this, if (isBackCamera) R.string.back_camera else R.string.front_camera)
} }
} }
private fun showPhotoResolutionPicker() {
val resolutions = camera.parameters.supportedPictureSizes.sortedByDescending { it.width * it.height }
val items = ArrayList<RadioItem>(resolutions.size)
resolutions.forEachIndexed { index, size ->
items.add(RadioItem(index, "${size.width} x ${size.height}"))
}
RadioGroupDialog(activity, items, if (isBackCamera) config.backPhotoResIndex else config.frontPhotoResIndex) {
if (isBackCamera) config.backPhotoResIndex else config.frontPhotoResIndex = it as Int
}
}
private fun showVideoResolutionPicker() {
val sizes = camera.parameters.supportedVideoSizes ?: camera.parameters.supportedPreviewSizes
val resolutions = sizes.sortedByDescending { it.width * it.height }
val items = ArrayList<RadioItem>(resolutions.size)
resolutions.forEachIndexed { index, size ->
items.add(RadioItem(index, "${size.width} x ${size.height}"))
}
RadioGroupDialog(activity, items, if (isBackCamera) config.backVideoResIndex else config.frontVideoResIndex) {
if (isBackCamera) config.backVideoResIndex else config.frontVideoResIndex = it as Int
}
}
} }