-
Notifications
You must be signed in to change notification settings - Fork 806
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
base: master
Are you sure you want to change the base?
Added a pause button #109
Changes from 3 commits
c4990fa
8a9cc10
e9a1917
98ad27c
082480b
7b8c19e
6c9c04b
37ce59f
30e4788
d018283
3347f54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
} | ||
|
@@ -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()) { | ||
|
@@ -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; | ||
|
@@ -167,18 +170,24 @@ public void onChronometerTick(Chronometer chronometer) { | |
private void onPauseRecord(boolean pause) { | ||
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")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you set |
||
mPauseButton.setColorRipple(Color.parseColor("#C0C0C0")); | ||
vishistv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mPauseButton.setColorPressed(Color.parseColor("#727272")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you set There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know that |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same for pause button. |
||
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" | ||
|
@@ -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" | ||
|
@@ -68,4 +79,4 @@ | |
android:layout_centerHorizontal="true" | ||
android:layout_marginBottom="60dp" /> | ||
|
||
</RelativeLayout> | ||
</RelativeLayout> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.