-
-
Save deepak140596/eddec5b0752435a4cda10ea905ce4920 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity(), LifecycleOwner { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
... | |
} | |
// Add this after onCreate | |
private lateinit var viewFinder: TextureView | |
private fun startCamera() { | |
// TODO: Implement CameraX operations | |
} | |
private fun updateTransform() { | |
// TODO: Implement camera viewfinder transformations | |
} | |
/** | |
* Process result from permission request dialog box, has the request | |
* been granted? If yes, start Camera. Otherwise display a toast | |
*/ | |
override fun onRequestPermissionsResult( | |
requestCode: Int, permissions: Array<String>, grantResults: IntArray) { | |
if (requestCode == REQUEST_CODE_PERMISSIONS) { | |
if (allPermissionsGranted()) { | |
viewFinder.post { startCamera() } | |
} else { | |
Toast.makeText(this, | |
"Permissions not granted by the user.", | |
Toast.LENGTH_SHORT).show() | |
finish() | |
} | |
} | |
} | |
/** | |
* Check if all permission specified in the manifest have been granted | |
*/ | |
private fun allPermissionsGranted() = REQUIRED_PERMISSIONS.all { | |
ContextCompat.checkSelfPermission( | |
baseContext, it) == PackageManager.PERMISSION_GRANTED | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment