Skip to content

Commit

Permalink
feat: single-mode audio recorder
Browse files Browse the repository at this point in the history
When the audio recorder is on the reviewer
we want a single mode which includes playback
without pausing

This removes the 'save' button and associated state

record -> stop -> playback -> cancel

====

icons were added for:
* play
* stop

The record button was made slightly smaller to be consistent with this icon set

Issue 16185
  • Loading branch information
david-allison committed Apr 27, 2024
1 parent 0a62992 commit 8a72fe5
Show file tree
Hide file tree
Showing 9 changed files with 467 additions and 44 deletions.
8 changes: 7 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import com.ichi2.audio.AudioRecordingController.Companion.isAudioRecordingSaved
import com.ichi2.audio.AudioRecordingController.Companion.isRecording
import com.ichi2.audio.AudioRecordingController.Companion.setEditorStatus
import com.ichi2.audio.AudioRecordingController.Companion.tempAudioPath
import com.ichi2.audio.AudioRecordingController.RecordingState
import com.ichi2.libanki.*
import com.ichi2.libanki.Collection
import com.ichi2.libanki.sched.Counts
Expand Down Expand Up @@ -598,7 +599,12 @@ open class Reviewer :
if (!isAudioUIInitialized) {
try {
audioRecordingController = AudioRecordingController()
audioRecordingController?.createUI(this, micToolBarLayer)
audioRecordingController?.createUI(
this,
micToolBarLayer,
initialState = RecordingState.ImmediatePlayback.CLEARED,
R.layout.activity_audio_recording_reviewer
)
} catch (e: Exception) {
Timber.w(e, "unable to add the audio recorder to toolbar")
CrashReportService.sendExceptionReport(e, "Unable to create recorder tool bar")
Expand Down
218 changes: 176 additions & 42 deletions AnkiDroid/src/main/java/com/ichi2/audio/AudioRecordingController.kt

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions AnkiDroid/src/main/res/drawable/bg_rounded_drop_shadow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2024 David Allison <davidallisongithub@gmail.com>
~
~ This program is free software; you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by the Free Software
~ Foundation; either version 3 of the License, or (at your option) any later
~ version.
~
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY
~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
~ PARTICULAR PURPOSE. See the GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License along with
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->

<!--
Drop shadow - Android tips & tricks - anonymous contributor
https://stackoverflow.com/a/24095309/
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#CABBBBBB"/>
<corners android:radius="16dp" />
</shape>
</item>

<item
android:left="0dp"
android:right="1dp"
android:top="0dp"
android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="?android:attr/colorBackground"/>
<corners android:radius="16dp" />
<stroke android:color="#CABBBBBB" android:width="1dp" />
</shape>
</item>
</layer-list>
5 changes: 5 additions & 0 deletions AnkiDroid/src/main/res/drawable/ic_play.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M8,5v14l11,-7z"/>

</vector>
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/drawable/ic_record.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,12m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0"/>
<path android:fillColor="@android:color/white" android:pathData="M12,12m-7,0a7,7 0,1 1,14 0a7,7 0,1 1,-14 0"/>
</vector>
10 changes: 10 additions & 0 deletions AnkiDroid/src/main/res/drawable/ic_skip_next.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#000000">
<path
android:fillColor="@android:color/white"
android:pathData="M6,18l8.5,-6L6,6v12zM16,6v12h2V6h-2z"/>
</vector>
5 changes: 5 additions & 0 deletions AnkiDroid/src/main/res/drawable/ic_stop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M8,6h8c1.1,0 2,0.9 2,2v8c0,1.1 -0.9,2 -2,2H8c-1.1,0 -2,-0.9 -2,-2V8c0,-1.1 0.9,-2 2,-2z"/>

</vector>
222 changes: 222 additions & 0 deletions AnkiDroid/src/main/res/layout/activity_audio_recording_reviewer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2023 Ashish Yadav <mailtoashish693@gmail.com>
~ Copyright (c) 2024 David Allison <davidallisongithub@gmail.com>
~
~ This program is free software; you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by the Free Software
~ Foundation; either version 3 of the License, or (at your option) any later
~ version.
~
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY
~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
~ PARTICULAR PURPOSE. See the GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License along with
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout android:id="@+id/audioView"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:keepScreenOn="true"
tools:context="com.ichi2.audio.AudioRecordingController">

<RelativeLayout
android:id="@+id/record_buttons_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginTop="12dp"
android:layout_marginBottom="8dp"
android:layout_marginHorizontal="16dp"
android:background="@drawable/bg_rounded_drop_shadow"
android:orientation="horizontal">

<com.ichi2.audio.AudioWaveform
android:id="@+id/audio_waveform_view"
android:layout_height="40dp"
android:layout_width="match_parent"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/action_start_recording"
android:layout_centerVertical="true"
android:layout_marginStart="14dp"
android:paddingVertical="6dp"
android:background="?android:attr/colorBackground"
app:display_vertical_line="false" />

<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/audio_progress_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="12dp"
android:layout_marginStart="14dp"
android:layout_centerVertical="true"
android:foregroundGravity="center"

android:layout_toStartOf="@+id/action_start_recording"

android:progress="0"

app:indicatorColor="@color/material_blue_500"
app:trackColor="@color/material_light_blue_100"
android:visibility="gone"
/>

<!-- TODO: Icons are centered manually on the next two buttons-->
<com.google.android.material.button.MaterialButton
android:id="@+id/action_start_recording"
style="@style/Widget.Material3.Button.IconButton.Filled"

android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/action_cancel_recording"

android:layout_marginStart="2dp"
android:clickable="true"
android:focusable="true"

android:insetBottom="6dp"
android:insetLeft="6dp"
android:insetRight="6dp"
android:insetTop="6dp"

android:paddingStart="10dp"

app:backgroundTint="@color/material_grey_100"
app:icon="@drawable/ic_record"
app:iconGravity="textStart"
app:iconSize="24dp"
app:iconTint="@color/flag_red"
app:strokeColor="@color/flag_red"
app:strokeWidth="2dp" />

<com.google.android.material.button.MaterialButton
android:id="@+id/action_cancel_recording"
style="@style/Widget.Material3.Button.IconButton.Filled"
android:layout_width="48dp"
android:layout_height="48dp"

android:layout_alignParentEnd="true"

android:insetBottom="0dp"
android:insetLeft="0dp"
android:insetRight="0dp"
android:insetTop="0dp"

android:paddingStart="11dp"

app:backgroundTint="@color/transparent"
app:icon="@drawable/ic_clear_white"
app:iconTint="?attr/editTextColor"
app:iconSize="24dp"
/>

</RelativeLayout>

<LinearLayout
android:visibility="gone"
android:id="@+id/play_buttons_layout"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/audio_file_imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="2dp"
android:minHeight="300px"
android:paddingVertical="6dp"
android:src="@drawable/round_audio_file_24"
android:tint="@color/material_blue_500" />

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="8dp"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible">
<com.google.android.material.button.MaterialButton
android:id="@+id/action_rewind"
style="@style/Widget.Material3.Button.IconButton.Filled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="6dp"
android:clickable="true"
android:focusable="true"
android:enabled="false"
app:backgroundTint="@color/material_blue_500"
app:icon="@drawable/baseline_replay_5_24"
app:iconPadding="0dp"
app:iconSize="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/action_play_recording"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.button.MaterialButton
android:id="@+id/action_play_recording"
style="@style/Widget.Material3.Button.IconButton.Filled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:clickable="true"
android:focusable="true"
android:padding="10dp"
app:backgroundTint="@color/material_grey_100"
app:icon="@drawable/round_play_arrow_24"
app:iconPadding="0dp"
app:iconSize="50dp"
app:iconTint="@color/flag_red"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:strokeColor="@color/flag_red"
app:strokeWidth="4dp" />

<com.google.android.material.button.MaterialButton
android:id="@+id/action_forward"
style="@style/Widget.Material3.Button.IconButton.Filled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="6dp"
android:clickable="true"
android:focusable="true"
android:enabled="false"
app:backgroundTint="@color/material_blue_500"
app:icon="@drawable/baseline_forward_5_24"
app:iconPadding="0dp"
app:iconSize="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/action_play_recording"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.button.MaterialButton
android:id="@+id/action_discard_recording"
style="@style/Widget.Material3.Button.IconButton.Filled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="6dp"
app:backgroundTint="@color/material_blue_500"
app:icon="@drawable/ic_delete"
app:iconPadding="0dp"
app:iconSize="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/action_forward"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:dividerThickness="2dp" />
</LinearLayout>
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,6 @@
<!-- Audio Recorder Colors -->
<color name="audio_recorder_red">#FF4747</color>
<color name="audio_recorder_green">#6FF06F</color>
<color name="audio_recorder_grey">#444444</color>
</resources>

0 comments on commit 8a72fe5

Please sign in to comment.