Skip to content

Commit 23b5395

Browse files
committed
Fix Bugs
1 parent 68fed46 commit 23b5395

File tree

16 files changed

+107
-93
lines changed

16 files changed

+107
-93
lines changed

.idea/vcs.xml

-6
This file was deleted.

README.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
![](https://img.shields.io/badge/Platform-Android-brightgreen.svg)
66
![](https://img.shields.io/badge/Android-CustomView-blue.svg)
77
![](https://img.shields.io/crates/l/rustc-serialize.svg)
8-
![](https://img.shields.io/badge/version-0.1.1_beta-blue.svg)
8+
![](https://img.shields.io/badge/version-0.1.2_beta-blue.svg)
99

1010
------
1111
Android has a built in microphone through which you can capture audio and store it , or play it in your phone. There are many ways to do that but with this dialog you can do all thats with only one dialog.
@@ -23,7 +23,7 @@ You can report any issue on issues page. **Note: If you speak Arabic, you can su
2323
<dependency>
2424
<groupId>net.alhazmy13.MediaRecorderDialog</groupId>
2525
<artifactId>libary</artifactId>
26-
<version>0.1.1-beta</version>
26+
<version>0.1.2-beta</version>
2727
</dependency>
2828
```
2929

@@ -32,7 +32,7 @@ You can report any issue on issues page. **Note: If you speak Arabic, you can su
3232
```gradle
3333
3434
dependencies {
35-
compile 'net.alhazmy13.MediaRecorderDialog:libary:0.1.1-beta'
35+
compile 'net.alhazmy13.MediaRecorderDialog:libary:0.1.2-beta'
3636
}
3737
```
3838

@@ -81,10 +81,6 @@ In order to receive the path of file, you will need to implement the `OnSaveButt
8181
```java
8282
.setMessage("Press the button")
8383
```
84-
* `setTitle` You can change the title of Dialog
85-
```java
86-
.setTitle("Recording,,,")
87-
```
8884
* `setOutputFormat` You can change the Output format by passing the format from `MediaRecorderDialog.OutputFormat`
8985
```java
9086
.setOutputFormat(MediaRecorderDialog.OutputFormat.MPEG_4)
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,47 @@
11
package net.alhazmy13.mediarecorderdialog_example;
22

3+
import android.graphics.Bitmap;
34
import android.support.v7.app.AppCompatActivity;
45
import android.os.Bundle;
56
import android.view.View;
67
import android.widget.Button;
8+
import android.widget.TextView;
79
import android.widget.Toast;
810

911
import net.alhazmy13.mediarecorderdialog.MediaRecorderDialog;
1012
import net.alhazmy13.mediarecorderdialog.OnSaveButtonClickListener;
1113

14+
import java.util.concurrent.TimeUnit;
15+
1216
public class MainActivity extends AppCompatActivity {
1317

1418
@Override
1519
protected void onCreate(Bundle savedInstanceState) {
1620
super.onCreate(savedInstanceState);
1721
setContentView(R.layout.activity_main);
18-
((Button) findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {
22+
23+
((Button)findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {
1924
@Override
2025
public void onClick(View view) {
21-
22-
23-
2426
new MediaRecorderDialog.Builder(MainActivity.this)
2527
.setOutputFormat(MediaRecorderDialog.OutputFormat.MPEG_4)
2628
.setAudioEncoder(MediaRecorderDialog.AudioEncoder.AAC)
29+
.setMaxLength(MediaRecorderDialog.TimeUnit.SECONDS,1)
2730
.setTitle("Recording,,,")
2831
.setMessage("Press the button")
2932
.setOnSaveButtonClickListener(new OnSaveButtonClickListener() {
3033
@Override
3134
public void onSucceed(String path) {
32-
Toast.makeText(MainActivity.this,path,Toast.LENGTH_SHORT).show();
35+
// Toast.makeText(MainActivity.this,path,Toast.LENGTH_SHORT).show();
3336
}
34-
3537
@Override
3638
public void onFailure() {
37-
//Toast.makeText(MainActivity.this,"onFailure",Toast.LENGTH_SHORT).show();
38-
39+
//Toast.makeText(MainActivity.this,"Failure",Toast.LENGTH_SHORT).show();
3940
}
4041
})
4142
.show();
42-
43-
44-
4543
}
4644
});
4745

48-
4946
}
5047
}

app/src/main/res/layout/activity_main.xml

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
android:text="Record"
1717
android:layout_centerVertical="true"
1818
android:layout_centerHorizontal="true" />
19+
1920
</RelativeLayout>

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
8+
classpath 'com.android.tools.build:gradle:2.0.0-alpha5'
99
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
1010
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
1111
// NOTE: Do not place your application dependencies here; they belong
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Oct 21 11:34:03 PDT 2015
1+
#Fri Jan 22 21:57:35 AST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

libary/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ dependencies {
4949
compile 'com.skyfishjy.ripplebackground:library:1.0.1'
5050
compile 'com.nineoldandroids:library:2.4.0'
5151
compile 'com.daimajia.androidanimations:library:1.1.3@aar'
52-
compile 'net.alhazmy13.Gota:libary:1.0.0-beta'
52+
compile 'net.alhazmy13.Gota:libary:1.0.2-beta'
53+
compile 'com.android.support:appcompat-v7:23.1.1'
5354

5455

5556
}

libary/src/main/AndroidManifest.xml

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
package="net.alhazmy13.library">
33
<uses-permission android:name="android.permission.RECORD_AUDIO" />
44
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
5-
<application
6-
android:supportsRtl="true">
7-
8-
</application>
5+
<application/>
96

107
</manifest>

libary/src/main/java/net/alhazmy13/mediarecorderdialog/GenralAtteribute.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class GenralAtteribute {
99
protected static Context context;
1010
protected static String title="";
1111
protected static String message="";
12-
protected static int outPutFormat;
13-
protected static int audioEncoder;
12+
protected static MediaRecorderDialog.OutputFormat outPutFormat;
13+
protected static MediaRecorderDialog.AudioEncoder audioEncoder;
1414
protected static OnSaveButtonClickListener onSaveButtonClickListener;
15+
public static int length = -1;
1516
}

libary/src/main/java/net/alhazmy13/mediarecorderdialog/MediaRecorderDialog.java

+46-27
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public MediaRecorderDialog.Builder setMessage(String msg) {
3131
return this;
3232
}
3333
public MediaRecorderDialog.Builder show(){
34+
// new SoundDialog(GenralAtteribute.context).show();
3435
new Gota(GenralAtteribute.context).checkPermission(new String[]{Manifest.permission.RECORD_AUDIO
3536
,Manifest.permission.WRITE_EXTERNAL_STORAGE}, new Gota.OnRequestPermissionsBack() {
3637
@Override
@@ -42,12 +43,12 @@ public void onRequestBack(GotaResponse goaResponse) {
4243
return this;
4344
}
4445

45-
public MediaRecorderDialog.Builder setOutputFormat(int outputFormat){
46+
public MediaRecorderDialog.Builder setOutputFormat(OutputFormat outputFormat){
4647
GenralAtteribute.outPutFormat=outputFormat;
4748
return this;
4849
}
4950

50-
public MediaRecorderDialog.Builder setAudioEncoder(int audioEncoder){
51+
public MediaRecorderDialog.Builder setAudioEncoder(AudioEncoder audioEncoder){
5152
GenralAtteribute.audioEncoder=audioEncoder;
5253
return this;
5354
}
@@ -57,36 +58,54 @@ public MediaRecorderDialog.Builder setOnSaveButtonClickListener(OnSaveButtonClic
5758
return this;
5859
}
5960

61+
public MediaRecorderDialog.Builder setMaxLength(TimeUnit timeUnit,int length){
62+
GenralAtteribute.length = length*timeUnit.getValue() ;
63+
return this;
64+
}
65+
66+
}
67+
68+
public enum OutputFormat {
69+
AAC_ADTS(6),AMR_NB(3),AMR_WB(4),DEFAULT(0),MPEG_4(2);
70+
private final int value;
71+
72+
OutputFormat(int value){
73+
74+
this.value = value;
75+
}
76+
public int getValue(){
77+
return value;
78+
}
79+
6080
}
6181

62-
public final class OutputFormat {
63-
public static final int AAC_ADTS = 6;
64-
public static final int AMR_NB = 3;
65-
public static final int AMR_WB = 4;
66-
public static final int DEFAULT = 0;
67-
public static final int MPEG_4 = 2;
68-
/** @deprecated */
69-
@Deprecated
70-
public static final int RAW_AMR = 3;
71-
public static final int THREE_GPP = 1;
72-
public static final int WEBM = 9;
73-
74-
OutputFormat() {
75-
throw new RuntimeException("Stub!");
82+
public enum AudioEncoder {
83+
AAC (3),AAC_ELD(5),AMR_NB(1),AMR_WB(2),DEFAULT(0),HE_AAC(4),VORBIS(6);
84+
85+
private final int value;
86+
87+
AudioEncoder(int value){
88+
89+
this.value = value;
90+
}
91+
92+
public int getValue() {
93+
return value;
7694
}
7795
}
7896

79-
public final class AudioEncoder {
80-
public static final int AAC = 3;
81-
public static final int AAC_ELD = 5;
82-
public static final int AMR_NB = 1;
83-
public static final int AMR_WB = 2;
84-
public static final int DEFAULT = 0;
85-
public static final int HE_AAC = 4;
86-
public static final int VORBIS = 6;
87-
88-
AudioEncoder() {
89-
throw new RuntimeException("Stub!");
97+
public enum TimeUnit {
98+
MINUTES(60),SECONDS(1);
99+
100+
private final int value;
101+
102+
TimeUnit(int value){
103+
104+
this.value = value;
105+
}
106+
107+
public int getValue() {
108+
return value;
90109
}
91110
}
92111

libary/src/main/java/net/alhazmy13/mediarecorderdialog/MyCountDownTimer.java

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public void run() {
2020
min++;
2121
sec = 0;
2222
}
23+
if(GenralAtteribute.length != -1){
24+
if(GenralAtteribute.length < sec +(min*60))
25+
mView.stopRecording();
26+
}
2327
mView.updateTimer(String.format("%02d", min) + ":" + String.format("%02d", sec));
2428
handler.postDelayed(this, 1000);
2529
}

libary/src/main/java/net/alhazmy13/mediarecorderdialog/SoundDialog.java

+30-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.alhazmy13.mediarecorderdialog;
22

3-
import android.Manifest;
43
import android.app.Activity;
54
import android.app.Dialog;
65
import android.content.Context;
@@ -24,8 +23,6 @@
2423
import com.truizlop.fabreveallayout.FABRevealLayout;
2524
import com.truizlop.fabreveallayout.OnRevealChangeListener;
2625

27-
import net.alhazmy13.gota.Gota;
28-
import net.alhazmy13.gota.GotaResponse;
2926
import net.alhazmy13.library.R;
3027

3128
import java.io.IOException;
@@ -41,7 +38,7 @@ class SoundDialog extends Dialog implements View.OnClickListener,SeekBar.OnSeekB
4138
private FABRevealLayout fab;
4239
private RippleBackground rippleBackground;
4340
private ImageView stopRecording,save,play,stopPlaing;
44-
private LinearLayout recrodLayout,playLayout;
41+
private LinearLayout recordLayout,playLayout;
4542
private TextView timer,title,msg;
4643
private Handler handler = new Handler();
4744
private AudioManager audioManager;
@@ -65,8 +62,8 @@ protected void onCreate(Bundle savedInstanceState) {
6562
setListeners();
6663
recorder = new MediaRecorder();
6764
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());
7067
path="/sdcard/Music/"+System.currentTimeMillis()+".3gp";
7168
recorder.setOutputFile(path);
7269
this.setOnDismissListener(this);
@@ -90,7 +87,7 @@ private void initViews(){
9087
stopRecording = (ImageView) findViewById(R.id.stopRecording);
9188
stopPlaing = (ImageView) findViewById(R.id.stop);
9289
rippleBackground=(RippleBackground)findViewById(R.id.content);
93-
recrodLayout = (LinearLayout) findViewById(R.id.recordingLayout);
90+
recordLayout = (LinearLayout) findViewById(R.id.recordingLayout);
9491
playLayout = (LinearLayout) findViewById(R.id.playLayout);
9592
timer = (TextView) findViewById(R.id.timer);
9693
msg= (TextView) findViewById(R.id.msg);
@@ -108,22 +105,7 @@ private void initViews(){
108105
@Override
109106
public void onClick(View view) {
110107
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();
127109
}else if(view == play){
128110
if((Integer)play.getTag() == R.drawable.ic_play_arrow_black_24dp) {
129111
play.setImageDrawable(activity.getResources().getDrawable(R.drawable.ic_pause_black_18dp));
@@ -150,7 +132,7 @@ public void onCompletion(MediaPlayer mediaPlayer) {
150132
}
151133

152134
private void updateViews() {
153-
recrodLayout.setVisibility(View.GONE);
135+
recordLayout.setVisibility(View.GONE);
154136
playLayout.setVisibility(View.VISIBLE);
155137
timer.setVisibility(View.VISIBLE);
156138
rippleBackground.setVisibility(View.GONE);
@@ -176,6 +158,28 @@ public void updateTimer(String value) {
176158
timer.setText(value);
177159
}
178160

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+
179183
@Override
180184
public void onMainViewAppeared(FABRevealLayout fabRevealLayout, View mainView) {
181185

@@ -191,6 +195,8 @@ public void onSecondaryViewAppeared(FABRevealLayout fabRevealLayout, View second
191195
e.printStackTrace();
192196
}
193197
recorder.start();
198+
handler.postDelayed(runnable, 1000);
199+
194200
}
195201

196202

libary/src/main/java/net/alhazmy13/mediarecorderdialog/SoundDialogView.java

+2
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
interface SoundDialogView {
77

88
void updateTimer(String value);
9+
10+
void stopRecording();
911
}

0 commit comments

Comments
 (0)