1
1
package net .alhazmy13 .mediarecorderdialog ;
2
2
3
- import android .Manifest ;
4
3
import android .app .Activity ;
5
4
import android .app .Dialog ;
6
5
import android .content .Context ;
24
23
import com .truizlop .fabreveallayout .FABRevealLayout ;
25
24
import com .truizlop .fabreveallayout .OnRevealChangeListener ;
26
25
27
- import net .alhazmy13 .gota .Gota ;
28
- import net .alhazmy13 .gota .GotaResponse ;
29
26
import net .alhazmy13 .library .R ;
30
27
31
28
import java .io .IOException ;
@@ -41,7 +38,7 @@ class SoundDialog extends Dialog implements View.OnClickListener,SeekBar.OnSeekB
41
38
private FABRevealLayout fab ;
42
39
private RippleBackground rippleBackground ;
43
40
private ImageView stopRecording ,save ,play ,stopPlaing ;
44
- private LinearLayout recrodLayout ,playLayout ;
41
+ private LinearLayout recordLayout ,playLayout ;
45
42
private TextView timer ,title ,msg ;
46
43
private Handler handler = new Handler ();
47
44
private AudioManager audioManager ;
@@ -65,8 +62,8 @@ protected void onCreate(Bundle savedInstanceState) {
65
62
setListeners ();
66
63
recorder = new MediaRecorder ();
67
64
recorder .setAudioSource (MediaRecorder .AudioSource .MIC );
68
- recorder .setOutputFormat (GenralAtteribute .outPutFormat );
69
- recorder .setAudioEncoder (GenralAtteribute .audioEncoder );
65
+ recorder .setOutputFormat (GenralAtteribute .outPutFormat . getValue () );
66
+ recorder .setAudioEncoder (GenralAtteribute .audioEncoder . getValue () );
70
67
path ="/sdcard/Music/" +System .currentTimeMillis ()+".3gp" ;
71
68
recorder .setOutputFile (path );
72
69
this .setOnDismissListener (this );
@@ -90,7 +87,7 @@ private void initViews(){
90
87
stopRecording = (ImageView ) findViewById (R .id .stopRecording );
91
88
stopPlaing = (ImageView ) findViewById (R .id .stop );
92
89
rippleBackground =(RippleBackground )findViewById (R .id .content );
93
- recrodLayout = (LinearLayout ) findViewById (R .id .recordingLayout );
90
+ recordLayout = (LinearLayout ) findViewById (R .id .recordingLayout );
94
91
playLayout = (LinearLayout ) findViewById (R .id .playLayout );
95
92
timer = (TextView ) findViewById (R .id .timer );
96
93
msg = (TextView ) findViewById (R .id .msg );
@@ -108,22 +105,7 @@ private void initViews(){
108
105
@ Override
109
106
public void onClick (View view ) {
110
107
if (view == stopRecording ){
111
- updateViews ();
112
- rippleBackground .stopRippleAnimation ();
113
- YoYo .with (Techniques .FadeIn )
114
- .duration (700 )
115
- .playOn (playLayout );
116
- recorder .stop ();
117
- mp =MediaPlayer .create (activity , Uri .parse (path ));
118
- mp .setOnCompletionListener (new MediaPlayer .OnCompletionListener () {
119
- @ Override
120
- public void onCompletion (MediaPlayer mediaPlayer ) {
121
- handler .removeCallbacks (runnable );
122
- runnable =new MyCountDownTimer (SoundDialog .this ,handler );
123
- play .setImageDrawable (activity .getResources ().getDrawable (R .drawable .ic_play_arrow_black_24dp ));
124
- play .setTag (R .drawable .ic_play_arrow_black_24dp );
125
- }
126
- });
108
+ stopRecording ();
127
109
}else if (view == play ){
128
110
if ((Integer )play .getTag () == R .drawable .ic_play_arrow_black_24dp ) {
129
111
play .setImageDrawable (activity .getResources ().getDrawable (R .drawable .ic_pause_black_18dp ));
@@ -150,7 +132,7 @@ public void onCompletion(MediaPlayer mediaPlayer) {
150
132
}
151
133
152
134
private void updateViews () {
153
- recrodLayout .setVisibility (View .GONE );
135
+ recordLayout .setVisibility (View .GONE );
154
136
playLayout .setVisibility (View .VISIBLE );
155
137
timer .setVisibility (View .VISIBLE );
156
138
rippleBackground .setVisibility (View .GONE );
@@ -176,6 +158,28 @@ public void updateTimer(String value) {
176
158
timer .setText (value );
177
159
}
178
160
161
+ @ Override
162
+ public void stopRecording () {
163
+ updateViews ();
164
+ recorder .stop ();
165
+ handler .removeCallbacks (runnable );
166
+ runnable =new MyCountDownTimer (SoundDialog .this ,handler );
167
+ rippleBackground .stopRippleAnimation ();
168
+ YoYo .with (Techniques .FadeIn )
169
+ .duration (700 )
170
+ .playOn (playLayout );
171
+ mp =MediaPlayer .create (activity , Uri .parse (path ));
172
+ mp .setOnCompletionListener (new MediaPlayer .OnCompletionListener () {
173
+ @ Override
174
+ public void onCompletion (MediaPlayer mediaPlayer ) {
175
+ handler .removeCallbacks (runnable );
176
+ runnable =new MyCountDownTimer (SoundDialog .this ,handler );
177
+ play .setImageDrawable (activity .getResources ().getDrawable (R .drawable .ic_play_arrow_black_24dp ));
178
+ play .setTag (R .drawable .ic_play_arrow_black_24dp );
179
+ }
180
+ });
181
+ }
182
+
179
183
@ Override
180
184
public void onMainViewAppeared (FABRevealLayout fabRevealLayout , View mainView ) {
181
185
@@ -191,6 +195,8 @@ public void onSecondaryViewAppeared(FABRevealLayout fabRevealLayout, View second
191
195
e .printStackTrace ();
192
196
}
193
197
recorder .start ();
198
+ handler .postDelayed (runnable , 1000 );
199
+
194
200
}
195
201
196
202
0 commit comments