项目作者: dinkar1708-zz

项目描述 :
Take picture using android camera on android latest devices. Kotlin is used in separate module with detailed comment.
高级语言: Java
项目地址: git://github.com/dinkar1708-zz/Taking-Photo-Camera-Android.git


Taking-Photo-Camera-Android

Taking picture using intent
Take picture using android camera on android latest devices.
Using glide library to display image
Hanlding run time permissions

Camerakotlin module -

Code explanation-

  1. /**
  2. * : and () - invokes constructor invocation referes to extends
  3. */
  4. class CameraIntentActivity : AppCompatActivity() {
  1. //NOTE no need to define the class level variable and findviewbyid for initialization
  2. // image view
  3. // private var imageView: ImageView? = null
  1. /**
  2. * fun is used for defining the function
  3. * ? refers - savedInstanceState can be null
  4. * savedInstanceState ->this is the variable name: Bundle -> is the data type it could be any thing like Int, Double etc.
  5. */
  6. override fun onCreate(savedInstanceState: Bundle?) {
  1. //NOTE NO NEED TO DO THIS
  2. // imageView = findViewById(R.id.imageView)

//NOTE - i can directly refer the id of XML file imageView
imageView.setOnClickListener {
//checking for write permission
if (ContextCompat.checkSelfPermission(this@CameraIntentActivity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

/**

  1. * after taking picture using camera this method is invoked in activity
  2. *
  3. * @param requestCode
  4. * @param resultCode
  5. * @param data
  6. */
  7. public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
  8. super.onActivityResult(requestCode, resultCode, data)

// Log.i(TAG, “onActivityResult requestCode$requestCode resultCode $resultCode data $data”)
// NOTE - above log statement can be printed as below print statement
/** println works as system.out as defined in sdk

  1. * @kotlin.internal.InlineOnly
  2. public inline fun println(message: Any?) {
  3. System.out.println(message)
  4. }
  5. */
  6. println("onActivityResult requestCode$requestCode resultCode $resultCode data $data");

//note
/**

  1. * https://kotlinlang.org/docs/reference/object-declarations.html
  2. * Companion Objects
  3. An object declaration inside a class can be marked with the companion keyword:
  4. class MyClass {
  5. companion object Factory {
  6. fun create(): MyClass = MyClass()
  7. }
  8. }
  9. Members of the companion object can be called by using simply the class name as the qualifier:
  10. */
  11. companion object {
  12. private val TAG = CameraIntentActivity::class.java.simpleName
  13. private val MY_PERMISSIONS_REQUEST_OPEN_CAMERA = 10
  14. private val REQ_RESULT_CODE_CAMERA = 2
  15. }

```