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

Added a pause button #109

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.danielkim.soundrecorder.fragments;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.os.SystemClock;
Expand All @@ -9,7 +10,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -36,7 +36,7 @@ public class RecordFragment extends Fragment {

//Recording controls
private FloatingActionButton mRecordButton = null;
private Button mPauseButton = null;
private FloatingActionButton mPauseButton = null;

private TextView mRecordingPrompt;
private int mRecordPromptCount = 0;
Expand Down Expand Up @@ -91,11 +91,12 @@ public void onClick(View v) {
}
});

mPauseButton = (Button) recordView.findViewById(R.id.btnPause);
mPauseButton = (FloatingActionButton) recordView.findViewById(R.id.btnPause);
mPauseButton.setVisibility(View.GONE); //hide pause button before recording starts
mPauseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(),mPauseRecording + "",Toast.LENGTH_SHORT).show();
onPauseRecord(mPauseRecording);
mPauseRecording = !mPauseRecording;
}
Expand All @@ -113,7 +114,7 @@ private void onRecord(boolean start){
if (start) {
// start recording
mRecordButton.setImageResource(R.drawable.ic_media_stop);
//mPauseButton.setVisibility(View.VISIBLE);
mPauseButton.setVisibility(View.VISIBLE);
Toast.makeText(getActivity(),R.string.toast_recording_start,Toast.LENGTH_SHORT).show();
File folder = new File(Environment.getExternalStorageDirectory() + "/SoundRecorder");
if (!folder.exists()) {
Expand Down Expand Up @@ -144,14 +145,16 @@ public void onChronometerTick(Chronometer chronometer) {
getActivity().startService(intent);
//keep screen on while recording
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

mRecordingPrompt.setText(getString(R.string.record_in_progress) + ".");
mRecordPromptCount++;

} else {
//stop recording
mRecordButton.setImageResource(R.drawable.ic_mic_white_36dp);
//mPauseButton.setVisibility(View.GONE);

mPauseButton.setVisibility(View.GONE);
mPauseRecording = true;
onPauseRecord(!mPauseRecording);
mChronometer.stop();
mChronometer.setBase(SystemClock.elapsedRealtime());
timeWhenPaused = 0;
Expand All @@ -167,18 +170,24 @@ public void onChronometerTick(Chronometer chronometer) {
private void onPauseRecord(boolean pause) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TODO, if you've implemented this.

Copy link
Author

@vishistv vishistv Nov 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing my PR. I will make the changes. :). I used a device to test.

if (pause) {
//pause recording
mPauseButton.setCompoundDrawablesWithIntrinsicBounds
(R.drawable.ic_media_play ,0 ,0 ,0);
mPauseButton.setImageResource(R.drawable.ic_media_play);
mPauseButton.setColorNormal(Color.parseColor("#FFC107"));
mPauseButton.setColorRipple(Color.parseColor("#C0C0C0"));
mPauseButton.setColorPressed(Color.parseColor("#727272"));
mRecordingPrompt.setText((String)getString(R.string.resume_recording_button).toUpperCase());
timeWhenPaused = mChronometer.getBase() - SystemClock.elapsedRealtime();
mChronometer.stop();
} else {
//resume recording
mPauseButton.setCompoundDrawablesWithIntrinsicBounds
(R.drawable.ic_media_pause ,0 ,0 ,0);
mPauseButton.setImageResource(R.drawable.ic_media_pause);
mPauseButton.setColorNormal(Color.parseColor("#F44336"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you set fab:fab_colorNormal="@color/primary" in the layout and then override it here in the code?

mPauseButton.setColorRipple(Color.parseColor("#C0C0C0"));
vishistv marked this conversation as resolved.
Show resolved Hide resolved
mPauseButton.setColorPressed(Color.parseColor("#727272"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you set app:fab_colorPressed="@color/secondary_text" in the layout and then override it here in the code? If you do it in the layout file only, the code will be cleaner.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed!

mRecordingPrompt.setText((String)getString(R.string.pause_recording_button).toUpperCase());
mChronometer.setBase(SystemClock.elapsedRealtime() + timeWhenPaused);
mChronometer.start();
}
}
}


}
57 changes: 34 additions & 23 deletions app/src/main/res/layout/fragment_record.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xmlns:fab is the same as xmlns:app. Why do you need to redefine this namespace?

android:id="@+id/fragment_record"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<com.melnykov.fab.FloatingActionButton
android:id="@+id/btnRecord"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:fab_colorNormal="@color/primary"
android:layout_marginBottom="10dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_mic_white_36dp" />
android:gravity="center_horizontal"
android:orientation="horizontal">

<com.melnykov.fab.FloatingActionButton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know that com.melnykov.fab.FloatingActionButton view is DEPRECATED? This is stated in makovkastar/FloatingActionButton repository readme. The author also suggests to use the FloatingActionButton from the support library instead.

android:id="@+id/btnRecord"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/primary"
app:fab_colorPressed="@color/secondary_text"
app:fab_colorRipple="@color/ripple"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_mic_white_36dp" />

<com.melnykov.fab.FloatingActionButton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same for pause button. com.melnykov.fab.FloatingActionButton view is DEPRECATED.

android:id="@+id/btnPause"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/primary"
app:fab_colorPressed="@color/secondary_text"
app:fab_colorRipple="@color/ripple"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_media_pause"/>

</LinearLayout>



<Chronometer
android:layout_width="wrap_content"
Expand All @@ -40,21 +66,6 @@
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnPause"
android:drawableLeft="@drawable/ic_media_pause"
android:text="@string/pause_recording_button"
android:textAllCaps="true"
android:fontFamily="sans-serif-condensed"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -68,4 +79,4 @@
android:layout_centerHorizontal="true"
android:layout_marginBottom="60dp" />

</RelativeLayout>
</RelativeLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<color name="primary_text">#212121</color>
<color name="accent">#FFC107</color>
<color name="secondary_text">#727272</color>
<color name="ripple">#C0C0C0</color>
<color name="divider">#FFFFFF</color>
<color name="text">#FFFFFF</color>
<color name="white">#FFFFFF</color>
<color name="tab_strip">#B42929</color>
</resources>
</resources>