lets remove PreviewListener interface, call activity functions directly

This commit is contained in:
tibbi 2018-05-30 17:27:30 +02:00
parent dfcb72b7f6
commit 292e2f6ad0
2 changed files with 12 additions and 25 deletions

View File

@ -23,14 +23,13 @@ import com.simplemobiletools.camera.interfaces.MyCamera
import com.simplemobiletools.camera.interfaces.MyPreview import com.simplemobiletools.camera.interfaces.MyPreview
import com.simplemobiletools.camera.views.FocusCircleView import com.simplemobiletools.camera.views.FocusCircleView
import com.simplemobiletools.camera.views.PreviewCameraOne import com.simplemobiletools.camera.views.PreviewCameraOne
import com.simplemobiletools.camera.views.PreviewCameraOne.PreviewListener
import com.simplemobiletools.camera.views.PreviewCameraTwo import com.simplemobiletools.camera.views.PreviewCameraTwo
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.Release import com.simplemobiletools.commons.models.Release
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSavedListener { class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener {
private val FADE_DELAY = 5000L private val FADE_DELAY = 5000L
lateinit var mTimerHandler: Handler lateinit var mTimerHandler: Handler
@ -194,7 +193,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
(btn_holder.layoutParams as RelativeLayout.LayoutParams).setMargins(0, 0, 0, (navBarHeight + resources.getDimension(R.dimen.activity_margin)).toInt()) (btn_holder.layoutParams as RelativeLayout.LayoutParams).setMargins(0, 0, 0, (navBarHeight + resources.getDimension(R.dimen.activity_margin)).toInt())
mPreview = if (isLollipopPlus()) PreviewCameraTwo(this, camera_texture_view) else PreviewCameraOne(this, camera_surface_view, this) mPreview = if (isLollipopPlus()) PreviewCameraTwo(this, camera_texture_view) else PreviewCameraOne(this, camera_surface_view)
view_holder.addView(mPreview as ViewGroup) view_holder.addView(mPreview as ViewGroup)
val imageDrawable = if (config.lastUsedCamera == mCameraImpl.getBackCameraId()) R.drawable.ic_camera_front else R.drawable.ic_camera_rear val imageDrawable = if (config.lastUsedCamera == mCameraImpl.getBackCameraId()) R.drawable.ic_camera_front else R.drawable.ic_camera_rear
@ -511,7 +510,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
return mIsCameraAvailable return mIsCameraAvailable
} }
override fun setFlashAvailable(available: Boolean) { fun setFlashAvailable(available: Boolean) {
if (available) { if (available) {
toggle_flash.beVisible() toggle_flash.beVisible()
} else { } else {
@ -520,11 +519,11 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
} }
} }
override fun setIsCameraAvailable(available: Boolean) { fun setIsCameraAvailable(available: Boolean) {
mIsCameraAvailable = available mIsCameraAvailable = available
} }
override fun videoSaved(uri: Uri) { fun videoSaved(uri: Uri) {
setupPreviewImage(mIsInPhotoMode) setupPreviewImage(mIsInPhotoMode)
if (mIsVideoCaptureIntent) { if (mIsVideoCaptureIntent) {
Intent().apply { Intent().apply {
@ -536,7 +535,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
} }
} }
override fun drawFocusCircle(x: Float, y: Float) = mFocusCircleView.drawFocusCircle(x, y) fun drawFocusCircle(x: Float, y: Float) = mFocusCircleView.drawFocusCircle(x, y)
override fun mediaSaved(path: String) { override fun mediaSaved(path: String) {
rescanPaths(arrayListOf(path)) { rescanPaths(arrayListOf(path)) {

View File

@ -36,7 +36,6 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
private lateinit var mSurfaceHolder: SurfaceHolder private lateinit var mSurfaceHolder: SurfaceHolder
private lateinit var mSurfaceView: SurfaceView private lateinit var mSurfaceView: SurfaceView
private lateinit var mCallback: PreviewListener
private lateinit var mScreenSize: Point private lateinit var mScreenSize: Point
private lateinit var mConfig: Config private lateinit var mConfig: Config
private var mSupportedPreviewSizes: List<Camera.Size>? = null private var mSupportedPreviewSizes: List<Camera.Size>? = null
@ -75,9 +74,8 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
constructor(context: Context) : super(context) constructor(context: Context) : super(context)
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
constructor(activity: MainActivity, surfaceView: SurfaceView, previewListener: PreviewListener) : super(activity) { constructor(activity: MainActivity, surfaceView: SurfaceView) : super(activity) {
mActivity = activity mActivity = activity
mCallback = previewListener
mSurfaceView = surfaceView mSurfaceView = surfaceView
mSurfaceHolder = mSurfaceView.holder mSurfaceHolder = mSurfaceView.holder
mSurfaceHolder.addCallback(this) mSurfaceHolder.addCallback(this)
@ -128,10 +126,10 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
val newCamera: Camera val newCamera: Camera
try { try {
newCamera = Camera.open(mCurrCameraId) newCamera = Camera.open(mCurrCameraId)
mCallback.setIsCameraAvailable(true) mActivity!!.setIsCameraAvailable(true)
} catch (e: Exception) { } catch (e: Exception) {
mActivity!!.showErrorToast(e) mActivity!!.showErrorToast(e)
mCallback.setIsCameraAvailable(false) mActivity!!.setIsCameraAvailable(false)
return false return false
} }
@ -188,7 +186,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
} }
} }
mCallback.setFlashAvailable(hasFlash(mCamera)) mActivity!!.setFlashAvailable(hasFlash(mCamera))
return true return true
} }
@ -432,7 +430,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
mParameters!!.focusAreas = focusAreas mParameters!!.focusAreas = focusAreas
if (showFocusRect) { if (showFocusRect) {
mCallback.drawFocusCircle(mLastClickX, mLastClickY) mActivity!!.drawFocusCircle(mLastClickX, mLastClickY)
} }
} }
@ -829,7 +827,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
toggleShutterSound(true) toggleShutterSound(true)
mRecorder!!.stop() mRecorder!!.stop()
mActivity!!.rescanPaths(arrayListOf(mCurrVideoPath)) { mActivity!!.rescanPaths(arrayListOf(mCurrVideoPath)) {
mCallback.videoSaved(Uri.fromFile(File(mCurrVideoPath))) mActivity!!.videoSaved(Uri.fromFile(File(mCurrVideoPath)))
toggleShutterSound(false) toggleShutterSound(false)
} }
} catch (e: RuntimeException) { } catch (e: RuntimeException) {
@ -908,14 +906,4 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
Camera.getCameraInfo(cameraId, info) Camera.getCameraInfo(cameraId, info)
return info return info
} }
interface PreviewListener {
fun setFlashAvailable(available: Boolean)
fun setIsCameraAvailable(available: Boolean)
fun videoSaved(uri: Uri)
fun drawFocusCircle(x: Float, y: Float)
}
} }