Skip to content

Commit

Permalink
Merge pull request #22 from furkanturkn/development
Browse files Browse the repository at this point in the history
[refactor] code cleaning + reformatting
  • Loading branch information
furkanturkn authored Oct 21, 2023
2 parents df0363e + ae5529f commit c8831cd
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 159 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ No need to waste time on CameraX and ML Kit app anymore. This library will speed
```sh
dependencies {
...
implementation 'com.github.furkanturkn:camerax-mlkit-pack:1.0.9'
implementation 'com.github.furkanturkn:camerax-mlkit-pack:1.1.0'
}
```
<p align="right">(<a href="#readme-top">back to top</a>)</p>
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ dependencies {
implementation "androidx.camera:camera-view:1.2.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1"

// implementation 'com.github.furkanturkn:camerax-mlkit-pack:1.0.8'
// implementation 'com.github.furkanturkn:camerax-mlkit-pack:1.1.0'
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
package com.furkan.cameraxmlkitpackexample

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

companion object {
const val REQUEST_CODE_PERMISSIONS = 10
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val btnQrReaderActivity: Button = findViewById(R.id.btnQrReaderActivity)
val btnQrReaderFragment: Button = findViewById(R.id.btnQrReaderFragment)
btnQrReaderActivity.setOnClickListener{

btnQrReaderActivity.setOnClickListener {
val qrReaderActivityIntent =
Intent(applicationContext, QrActivity::class.java)
startActivity(qrReaderActivityIntent)
}
btnQrReaderFragment.setOnClickListener{

btnQrReaderFragment.setOnClickListener {
val qrReaderFragment = QrDialogFragment()
qrReaderFragment.show(supportFragmentManager, "QR_FRAGMENT")
}


}
}
38 changes: 20 additions & 18 deletions app/src/main/java/com/furkan/cameraxmlkitpackexample/QrActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ import androidx.lifecycle.lifecycleScope
import com.furkan.camerax_mlkit_pack.CameraxManager
import com.furkan.camerax_mlkit_pack.core.ReaderType
import com.furkan.camerax_mlkit_pack.core.state.FlashStatus
import com.furkan.cameraxmlkitpackexample.MainActivity.Companion.REQUEST_CODE_PERMISSIONS
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class QrActivity : AppCompatActivity() {

private val REQUIRED_PERMISSIONS =
private val requiredPermissions =
mutableListOf(
Manifest.permission.CAMERA
).toTypedArray()

private val REQUEST_CODE_PERMISSIONS = 10

private var cameraxManager: CameraxManager? = null

private lateinit var previewView: PreviewView
private lateinit var focusRing: ImageView
private lateinit var btnFlash: Button
private lateinit var ivCapturePreview: ImageView
lateinit var btnCapturePhoto: Button
lateinit var btnChangeCameraType: Button
private lateinit var btnCapturePhoto: Button
private lateinit var btnChangeCameraType: Button
private lateinit var btnStartCamera: Button
private lateinit var btnStopCamera: Button
private lateinit var btnStartReading: Button
Expand Down Expand Up @@ -79,16 +79,6 @@ class QrActivity : AppCompatActivity() {

}

private fun checkCameraPermission() {
if (allPermissionsGranted()) {
initCameraManager()
} else {
ActivityCompat.requestPermissions(
this, REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS
)
}
}

private fun initViews() {
previewView = findViewById(R.id.previewView)
focusRing = findViewById(R.id.focusRing)
Expand All @@ -104,6 +94,7 @@ class QrActivity : AppCompatActivity() {
}

private fun initCameraManager() {

cameraxManager = CameraxManager.getInstance(
this,
null,
Expand Down Expand Up @@ -135,6 +126,7 @@ class QrActivity : AppCompatActivity() {
FlashStatus.ENABLED -> {
btnFlash.setBackgroundResource(R.drawable.baseline_flash_on_24)
}

FlashStatus.DISABLED -> {
btnFlash.setBackgroundResource(R.drawable.baseline_flash_off_24)
}
Expand All @@ -154,8 +146,18 @@ class QrActivity : AppCompatActivity() {
cameraxManager?.destroyReferences()
}

//[START] Permission Check
private fun allPermissionsGranted() = REQUIRED_PERMISSIONS.all {
//region Permission Check
private fun checkCameraPermission() {
if (allPermissionsGranted()) {
initCameraManager()
} else {
ActivityCompat.requestPermissions(
this, requiredPermissions, REQUEST_CODE_PERMISSIONS
)
}
}

private fun allPermissionsGranted() = requiredPermissions.all {
ContextCompat.checkSelfPermission(
baseContext, it
) == PackageManager.PERMISSION_GRANTED
Expand All @@ -179,5 +181,5 @@ class QrActivity : AppCompatActivity() {
}
}
}
//[END] Permission Check
//endregion Permission Check
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,40 @@ package com.furkan.cameraxmlkitpackexample
import android.Manifest
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.furkan.camerax_mlkit_pack.CameraxManager
import com.furkan.camerax_mlkit_pack.core.ReaderType
import com.furkan.camerax_mlkit_pack.core.state.FlashStatus
import kotlinx.android.synthetic.main.fragment_qr_dialog.*
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.*
import com.furkan.cameraxmlkitpackexample.MainActivity.Companion.REQUEST_CODE_PERMISSIONS
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.btnCapturePhotoFragment
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.btnChangeCameraTypeFragment
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.btnFlashFragment
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.btnStartCameraFragment
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.btnStartReadingFragment
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.btnStopCameraFragment
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.btnStopReadingFragment
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.focusRingFragment
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.ivCapturePreviewFragment
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.previewViewFragment
import kotlinx.android.synthetic.main.fragment_qr_dialog.view.tvReadResultFragment
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch


class QrDialogFragment : DialogFragment(R.layout.fragment_qr_dialog) {
private lateinit var rootView: View

private var cameraxManager: CameraxManager? = null

private val REQUIRED_PERMISSIONS =
mutableListOf(
Manifest.permission.CAMERA
).toTypedArray()
private val requiredPermissions = mutableListOf(
Manifest.permission.CAMERA
).toTypedArray()

private val REQUEST_CODE_PERMISSIONS = 10
private var cameraxManager: CameraxManager? = null

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
Expand Down Expand Up @@ -74,15 +78,8 @@ class QrDialogFragment : DialogFragment(R.layout.fragment_qr_dialog) {

return rootView
}
private fun checkCameraPermission() {
if (allPermissionsGranted()) {
initCameraManager(this)
} else {
requestPermissions(
REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS
)
}
}


private fun initCameraManager(qrDialogFragment: QrDialogFragment) {
cameraxManager = CameraxManager.getInstance(
requireContext(),
Expand Down Expand Up @@ -115,6 +112,7 @@ class QrDialogFragment : DialogFragment(R.layout.fragment_qr_dialog) {
FlashStatus.ENABLED -> {
rootView.btnFlashFragment.setBackgroundResource(R.drawable.baseline_flash_on_24)
}

FlashStatus.DISABLED -> {
rootView.btnFlashFragment.setBackgroundResource(R.drawable.baseline_flash_off_24)
}
Expand All @@ -128,34 +126,33 @@ class QrDialogFragment : DialogFragment(R.layout.fragment_qr_dialog) {
}
}
}
/*private fun checkCameraPermission() {

override fun onDestroy() {
super.onDestroy()
cameraxManager?.destroyReferences()
}

//region Permission Check
private fun checkCameraPermission() {
if (allPermissionsGranted()) {
initCameraManager(this)
} else {
ActivityCompat.requestPermissions(
this, REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS
requestPermissions(
requiredPermissions, REQUEST_CODE_PERMISSIONS
)
}
}*/

override fun onStart() {
super.onStart()
}

override fun onDestroy() {
super.onDestroy()
cameraxManager?.destroyReferences()
}
//[START] Permission Check
private fun allPermissionsGranted() = REQUIRED_PERMISSIONS.all {
private fun allPermissionsGranted() = requiredPermissions.all {
ContextCompat.checkSelfPermission(
requireContext(), it
) == PackageManager.PERMISSION_GRANTED
}

override fun onRequestPermissionsResult(
requestCode: Int, permissions: Array<String>, grantResults:
IntArray
requestCode: Int,
permissions: Array<String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == REQUEST_CODE_PERMISSIONS) {
Expand All @@ -164,13 +161,11 @@ class QrDialogFragment : DialogFragment(R.layout.fragment_qr_dialog) {

} else {
Toast.makeText(
requireContext(),
"Permissions not granted by the user.",
Toast.LENGTH_SHORT
requireContext(), "Permissions not granted by the user.", Toast.LENGTH_SHORT
).show()
}
}
}
//[END] Permission Check
//endregion Permission Check

}

This file was deleted.

2 changes: 1 addition & 1 deletion camerax-mlkit-pack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ afterEvaluate {

groupId = 'com.github.furkanturkn'
artifactId = 'camerax-mlkit-pack'
version = '1.0.9'
version = '1.1.0'
}
}
}
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions camerax-mlkit-pack/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.CAMERA" />
<application>
<meta-data
Expand Down
Loading

0 comments on commit c8831cd

Please sign in to comment.