Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in-app camera #6763

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
51b905f
Add VideoCamera button for attachment
p1gp1g Jul 28, 2022
59546b0
Add internal Camera : take photo
p1gp1g Jul 30, 2022
8fcc9c2
Add internal Camera : record video
p1gp1g Aug 2, 2022
59e0c1e
Create tempfile in the fragment
p1gp1g Aug 2, 2022
6b4fef9
Change capture mode in camera view
p1gp1g Aug 5, 2022
764ef53
Change camera in camera view
p1gp1g Aug 5, 2022
a215fe2
Restore capture mode in camera view
p1gp1g Aug 5, 2022
e916709
Add gesture to zoom in camera view
p1gp1g Aug 5, 2022
f56a8fe
Remove intent action for camera activity
p1gp1g Aug 5, 2022
90e922b
Set the built-in camera as a lab preference
p1gp1g Aug 7, 2022
d534a7d
Control flash in camera view
p1gp1g Aug 7, 2022
9945231
Lint
p1gp1g Aug 7, 2022
0e3a8a1
Add progress indicator when taking a photo
p1gp1g Aug 7, 2022
8236a32
Add changelog detail
p1gp1g Aug 7, 2022
4856fc6
Add support for orientation
p1gp1g Aug 27, 2022
ec1e5e2
Camera: Follow the MVI pattern
p1gp1g Aug 29, 2022
3776305
Camera: Add UI tests
p1gp1g Aug 29, 2022
9bca9bd
Do not use "VectorCamera" for names
p1gp1g Aug 29, 2022
bbdfa6e
Fix dependencies.gradle for androidx.camera
p1gp1g Aug 29, 2022
08ae120
Enable orientationEventListener onStart
p1gp1g Sep 5, 2022
db5e582
Lint
p1gp1g Sep 5, 2022
d88371d
Add chronometer to camera view
p1gp1g Sep 5, 2022
ccf0c88
Use new UX for the camera
p1gp1g Sep 5, 2022
916cc2e
Import drawable and fix colors
p1gp1g Sep 5, 2022
772e97b
Fix UI test for the video camera
p1gp1g Sep 6, 2022
8cad95d
Better style/UX
p1gp1g Sep 6, 2022
23fa3c9
Use OnImageCapturedCallback to improve latency
p1gp1g Sep 6, 2022
d5039dc
Fix UI tests for the camera
p1gp1g Sep 6, 2022
d43b144
Add Camera Action description
p1gp1g Sep 6, 2022
64f3b2e
Fix chronometer visibility
p1gp1g Sep 12, 2022
4eac12d
Change text size and chrono margin
p1gp1g Sep 12, 2022
8114f5b
Use recording and done states
p1gp1g Sep 17, 2022
a28fb0d
Revert "Add VideoCamera button for attachment"
p1gp1g Sep 17, 2022
a5d87e6
Use common icon to flip camera
p1gp1g Sep 18, 2022
ae2a920
Fix image rotation
p1gp1g Oct 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change capture mode in camera view
p1gp1g committed Aug 27, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 6b4fef9b53a0ae7f35a345a25d52e144f0c77716
Original file line number Diff line number Diff line change
@@ -67,7 +67,6 @@ class AttachmentsCameraFragment :
private lateinit var storageDir : File

private var imageCapture: ImageCapture? = null

private var videoCapture: VideoCapture<Recorder>? = null
private var recording: Recording? = null

@@ -99,12 +98,12 @@ class AttachmentsCameraFragment :
requestPermissionLauncher.launch(REQUIRED_PERMISSIONS)
}

views.attachmentsCameraImageAction.debouncedClicks {
takePhoto()
views.attachmentsCameraCaptureAction.debouncedClicks {
capture()
}

views.attachmentsCameraVideoAction.debouncedClicks {
captureVideo()
views.attachmentsCameraChangeAction.debouncedClicks {
changeCaptureMode()
}

cameraExecutor = Executors.newSingleThreadExecutor()
@@ -116,6 +115,43 @@ class AttachmentsCameraFragment :
} == PackageManager.PERMISSION_GRANTED
}

private fun changeCaptureMode() {
when (captureMode) {
MediaType.IMAGE -> {
captureMode = MediaType.VIDEO
views.attachmentsCameraCaptureAction.setImageDrawable(
context?.getDrawable(R.drawable.ic_video)
)
views.attachmentsCameraChangeAction.apply {
setImageDrawable(
context?.getDrawable(R.drawable.ic_camera_plain)
)
contentDescription = getString(R.string.attachment_camera_photo)
}
}
MediaType.VIDEO -> {
captureMode = MediaType.IMAGE
views.attachmentsCameraCaptureAction.setImageDrawable(
context?.getDrawable(R.drawable.ic_camera_plain)
)
views.attachmentsCameraChangeAction.apply {
setImageDrawable(
context?.getDrawable(R.drawable.ic_video)
)
contentDescription = getString(R.string.attachment_camera_video)
}
}
}
}

private fun capture() {
when (captureMode) {
MediaType.IMAGE -> takePhoto()
MediaType.VIDEO -> captureVideo()
}

}

private fun takePhoto() {
Timber.d("Taking a photo")
context?.let { context ->
@@ -161,7 +197,8 @@ class AttachmentsCameraFragment :
context?.let { context ->
val videoCapture = this.videoCapture ?: return

views.attachmentsCameraImageAction.isEnabled = false
views.attachmentsCameraChangeAction.isEnabled = false
views.attachmentsCameraFlip.isEnabled = false

val curRecording = recording
if (curRecording != null) {
@@ -190,7 +227,7 @@ class AttachmentsCameraFragment :
.start(ContextCompat.getMainExecutor(context)) { recordEvent ->
when(recordEvent) {
is VideoRecordEvent.Start -> {
views.attachmentsCameraVideoAction.setImageDrawable(
views.attachmentsCameraCaptureAction.setImageDrawable(
context.getDrawable(R.drawable.ic_video_off)
)
}
@@ -303,6 +340,7 @@ class AttachmentsCameraFragment :
}

companion object {
private var captureMode = MediaType.IMAGE
private val REQUIRED_PERMISSIONS =
mutableListOf (
Manifest.permission.CAMERA,
34 changes: 26 additions & 8 deletions vector/src/main/res/layout/fragment_attachments_camera.xml
Original file line number Diff line number Diff line change
@@ -11,35 +11,53 @@
android:layout_height="match_parent" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/attachmentsCameraImageAction"
android:id="@+id/attachmentsCameraChangeAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:contentDescription="@string/attachment_camera_photo"
android:contentDescription="@string/attachment_camera_video"
android:elevation="2dp"
android:src="@drawable/ic_camera_plain"
android:scaleX="0.7"
android:scaleY="0.7"
android:src="@drawable/ic_video"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/vertical_leftline"
app:layout_constraintStart_toStartOf="@+id/vertical_leftline" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/attachmentsCameraVideoAction"
android:id="@+id/attachmentsCameraCaptureAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:elevation="2dp"
android:src="@drawable/ic_video"
android:scaleX="1.3"
android:scaleY="1.3"
android:src="@drawable/ic_camera_plain"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@id/vertical_centerline"
app:layout_constraintEnd_toStartOf="@id/vertical_centerline"
android:contentDescription="@string/attachment_camera_capture" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/attachmentsCameraFlip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:elevation="2dp"
android:scaleX="0.7"
android:scaleY="0.7"
android:src="@drawable/ic_video_flip"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@id/vertical_rightline"
app:layout_constraintEnd_toStartOf="@id/vertical_rightline"
android:contentDescription="@string/attachment_camera_video" />
android:contentDescription="@string/attachment_camera_flip" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/vertical_leftline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent=".25" />
app:layout_constraintGuide_percent=".2" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/vertical_centerline"
@@ -53,6 +71,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent=".75" />
app:layout_constraintGuide_percent=".8" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 2 additions & 0 deletions vector/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -3199,6 +3199,8 @@
<string name="tooltip_attachment_video">Open camera for a video</string>
<string name="attachment_camera_photo">Take a photo</string>
<string name="attachment_camera_video">Take a video</string>
<string name="attachment_camera_capture">Capture</string>
<string name="attachment_camera_flip">Change camera</string>

<plurals name="room_removed_messages">
<item quantity="one">%d message removed</item>