Skip to content

Commit

Permalink
camera2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Kopylov committed Mar 7, 2020
1 parent f07ca94 commit 7ff919b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,40 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.fragment_capture_photo.*
import java.io.ByteArrayOutputStream


class CapturePhotoFragment : Fragment() {
lateinit var Camera: ImageView
lateinit var Button: Button
lateinit var intent:Intent

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
private lateinit var camera: ImageView
private lateinit var btnCapturePhoto: Button
private lateinit var intent:Intent
private lateinit var textClass:TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startActivityForResult(
intent,
CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {

// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_capture_photo, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {


Button = btnCapturePhoto
Camera = imgViewCamera

Button.setOnClickListener {
btnCapturePhoto = btn_capture_photo
camera = img_view_camera
textClass = text_view_class
btnCapturePhoto.setOnClickListener {
startActivityForResult(
intent,
CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
Expand All @@ -63,7 +68,11 @@ class CapturePhotoFragment : Fragment() {
byteArray, 0,
byteArray.size
)
Camera.setImageBitmap(bitmap)
camera.setImageBitmap(bitmap)
textClass.text = "Loading..."
// do classification
textClass.text = "Class"
btnCapturePhoto.visibility=View.VISIBLE
}
}
}
Expand Down
29 changes: 22 additions & 7 deletions app/src/main/res/layout/fragment_capture_photo.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout2"
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".CapturePhotoFragment">

<TextView
android:id="@+id/text_view_class"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center" />

<Space
android:layout_width="match_parent"
android:layout_height="30dp" />

<ImageView
android:id="@+id/imgViewCamera"
android:id="@+id/img_view_camera"
android:layout_width="match_parent"
android:layout_height="394dp"
android:src="@android:drawable/ic_menu_camera" />
android:layout_height="450dp" />

<Space
android:layout_width="match_parent"
android:layout_height="30dp" />

<Button
android:id="@+id/btnCapturePhoto"
android:id="@+id/btn_capture_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
android:layout_height="80dp"
android:text="Take Photo"
android:visibility="invisible" />

</LinearLayout>

0 comments on commit 7ff919b

Please sign in to comment.