From 85a0ce4ab232f9e64c00293f2133229dd2673153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E4=B8=BD=E5=A8=87?= <1195920470@qq.com> Date: Tue, 8 Jan 2019 15:18:33 +0800 Subject: [PATCH] second commit --- FunctionRealize/Record/.gitignore | 11 -- .../Record/.idea/codeStyles/Project.xml | 29 --- FunctionRealize/Record/.idea/gradle.xml | 18 -- FunctionRealize/Record/.idea/misc.xml | 38 ---- .../Record/.idea/runConfigurations.xml | 12 -- FunctionRealize/Record/RecordActivity.java | 114 ++++++++++++ FunctionRealize/Record/app/.gitignore | 1 - FunctionRealize/Record/app/build.gradle | 29 --- FunctionRealize/Record/app/proguard-rules.pro | 21 --- .../com/record/ExampleInstrumentedTest.java | 26 --- .../Record/app/src/main/AndroidManifest.xml | 25 --- .../main/java/com/record/MainActivity.java | 27 --- .../java/com/record/MyButtonListener.java | 16 -- .../drawable-v24/ic_launcher_foreground.xml | 34 ---- .../res/drawable/ic_launcher_background.xml | 74 -------- .../app/src/main/res/layout/activity_main.xml | 72 -------- .../app/src/main/res/layout/content_main.xml | 21 --- .../app/src/main/res/menu/menu_main.xml | 9 - .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 - .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 - .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 2963 -> 0 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 4905 -> 0 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 2060 -> 0 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 2783 -> 0 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 4490 -> 0 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 6895 -> 0 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 6387 -> 0 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 10413 -> 0 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 9128 -> 0 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 15132 -> 0 bytes .../Record/app/src/main/res/values/colors.xml | 6 - .../Record/app/src/main/res/values/dimens.xml | 3 - .../app/src/main/res/values/strings.xml | 4 - .../Record/app/src/main/res/values/styles.xml | 17 -- .../test/java/com/record/ExampleUnitTest.java | 17 -- FunctionRealize/Record/build.gradle | 27 --- FunctionRealize/Record/gradle.properties | 19 -- .../Record/gradle/wrapper/gradle-wrapper.jar | Bin 54329 -> 0 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 - FunctionRealize/Record/gradlew | 172 ------------------ FunctionRealize/Record/gradlew.bat | 84 --------- FunctionRealize/Record/settings.gradle | 1 - 42 files changed, 114 insertions(+), 828 deletions(-) delete mode 100644 FunctionRealize/Record/.gitignore delete mode 100644 FunctionRealize/Record/.idea/codeStyles/Project.xml delete mode 100644 FunctionRealize/Record/.idea/gradle.xml delete mode 100644 FunctionRealize/Record/.idea/misc.xml delete mode 100644 FunctionRealize/Record/.idea/runConfigurations.xml create mode 100644 FunctionRealize/Record/RecordActivity.java delete mode 100644 FunctionRealize/Record/app/.gitignore delete mode 100644 FunctionRealize/Record/app/build.gradle delete mode 100644 FunctionRealize/Record/app/proguard-rules.pro delete mode 100644 FunctionRealize/Record/app/src/androidTest/java/com/record/ExampleInstrumentedTest.java delete mode 100644 FunctionRealize/Record/app/src/main/AndroidManifest.xml delete mode 100644 FunctionRealize/Record/app/src/main/java/com/record/MainActivity.java delete mode 100644 FunctionRealize/Record/app/src/main/java/com/record/MyButtonListener.java delete mode 100644 FunctionRealize/Record/app/src/main/res/drawable-v24/ic_launcher_foreground.xml delete mode 100644 FunctionRealize/Record/app/src/main/res/drawable/ic_launcher_background.xml delete mode 100644 FunctionRealize/Record/app/src/main/res/layout/activity_main.xml delete mode 100644 FunctionRealize/Record/app/src/main/res/layout/content_main.xml delete mode 100644 FunctionRealize/Record/app/src/main/res/menu/menu_main.xml delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-hdpi/ic_launcher.png delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-hdpi/ic_launcher_round.png delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-mdpi/ic_launcher.png delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-mdpi/ic_launcher_round.png delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-xhdpi/ic_launcher.png delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-xxhdpi/ic_launcher.png delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png delete mode 100644 FunctionRealize/Record/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png delete mode 100644 FunctionRealize/Record/app/src/main/res/values/colors.xml delete mode 100644 FunctionRealize/Record/app/src/main/res/values/dimens.xml delete mode 100644 FunctionRealize/Record/app/src/main/res/values/strings.xml delete mode 100644 FunctionRealize/Record/app/src/main/res/values/styles.xml delete mode 100644 FunctionRealize/Record/app/src/test/java/com/record/ExampleUnitTest.java delete mode 100644 FunctionRealize/Record/build.gradle delete mode 100644 FunctionRealize/Record/gradle.properties delete mode 100644 FunctionRealize/Record/gradle/wrapper/gradle-wrapper.jar delete mode 100644 FunctionRealize/Record/gradle/wrapper/gradle-wrapper.properties delete mode 100644 FunctionRealize/Record/gradlew delete mode 100644 FunctionRealize/Record/gradlew.bat delete mode 100644 FunctionRealize/Record/settings.gradle diff --git a/FunctionRealize/Record/.gitignore b/FunctionRealize/Record/.gitignore deleted file mode 100644 index fd45b12..0000000 --- a/FunctionRealize/Record/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -*.iml -.gradle -/local.properties -/.idea/caches/build_file_checksums.ser -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -.DS_Store -/build -/captures -.externalNativeBuild diff --git a/FunctionRealize/Record/.idea/codeStyles/Project.xml b/FunctionRealize/Record/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626..0000000 --- a/FunctionRealize/Record/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/FunctionRealize/Record/.idea/gradle.xml b/FunctionRealize/Record/.idea/gradle.xml deleted file mode 100644 index 7ac24c7..0000000 --- a/FunctionRealize/Record/.idea/gradle.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/FunctionRealize/Record/.idea/misc.xml b/FunctionRealize/Record/.idea/misc.xml deleted file mode 100644 index b0c7b20..0000000 --- a/FunctionRealize/Record/.idea/misc.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/FunctionRealize/Record/.idea/runConfigurations.xml b/FunctionRealize/Record/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/FunctionRealize/Record/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/FunctionRealize/Record/RecordActivity.java b/FunctionRealize/Record/RecordActivity.java new file mode 100644 index 0000000..da17df6 --- /dev/null +++ b/FunctionRealize/Record/RecordActivity.java @@ -0,0 +1,114 @@ +package com.record; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.media.MediaRecorder; +import android.os.Environment; +import android.view.Window; +import android.widget.Button; +import android.widget.Toast; +import java.io.File; +import java.io.IOException; + +@SuppressLint("Registered") +public class RecordActivity extends Activity implements View.OnClickListener { + + Button startRecording, stopRecording, pauseRecording;//开始录音、停止录音、释放资源 + MediaRecorder recorder; + File audioFile; //录音保存的文件 + boolean isRecoding = false;// true 表示正在录音 + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); + setContentView(R.layout.activity_main); + init(); + initListener(); + } + + //初始化 + public void init() { + stopRecording = (Button) this.findViewById(R.id.btn_stop); + startRecording = (Button) this.findViewById(R.id.btn_play); + pauseRecording = (Button) this.findViewById(R.id.btn_pause); + if (!path.exists()) { + path.mkdirs(); + } + } + //初始化麦克风 + private void InitMedia(){ + recorder = new MediaRecorder(); + recorder.setAudioSource(MediaRecorder.AudioSource.MIC);//设置播放源 麦克风 + recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); //设置输入格式 3gp + recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); //设置编码AMR + } + //设置监听器 + public void initListener() { + startRecording.setOnClickListener(this); + stopRecording.setOnClickListener(this); + pauseRecording.setOnClickListener(this); + } + + //此处还应该对手机进行下判断,判断下手机里面有没有内存卡 + //保存在SD卡下MediaRecorderTest文件夹中 + File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MediaRecorderTest"); + + //录音 + public void recod() { + InitMedia(); + int i = (int) (Math.random() * 10000); + String a = Integer.toString(i); + String b = "Voice"; + String FileName = b + a; + try { + audioFile = new File(path, FileName + ".aac"); + //audioFile=new File(path,"ycc.aac"); + if (audioFile.exists()) { + audioFile.delete(); + } + audioFile.createNewFile();//创建文件 + + } catch (Exception e) { + throw new RuntimeException("Couldn't create recording audio file", e); + } + + recorder.setOutputFile(audioFile.getAbsolutePath()); //设置输出文件 + + try { + recorder.prepare(); + } catch (IllegalStateException e) { + throw new RuntimeException("IllegalStateException on MediaRecorder.prepare", e); + } catch (IOException e) { + throw new RuntimeException("IOException on MediaRecorder.prepare", e); + } + isRecoding = true; + recorder.start(); + } + + + public void onClick(View v) { + //开始录音 + while (true){ + if (v == startRecording) { + Toast.makeText(RecordActivity.this, "开始录音", Toast.LENGTH_SHORT).show(); + recod(); + break; + } + + if (v == pauseRecording) { + + } + //停止录音 + if (v == stopRecording) { + if (isRecoding) { + Toast.makeText(RecordActivity.this, "录音结束,文件已存至/MediaRecorderTest", Toast.LENGTH_SHORT).show(); + recorder.stop();//调用stop之后recorder会被清空,再次录音要再次初始化recorder + break; + } + } + } + } +} \ No newline at end of file diff --git a/FunctionRealize/Record/app/.gitignore b/FunctionRealize/Record/app/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/FunctionRealize/Record/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/FunctionRealize/Record/app/build.gradle b/FunctionRealize/Record/app/build.gradle deleted file mode 100644 index f736938..0000000 --- a/FunctionRealize/Record/app/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 28 - defaultConfig { - applicationId "com.record" - minSdkVersion 20 - targetSdkVersion 28 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - implementation 'com.android.support:design:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' -} diff --git a/FunctionRealize/Record/app/proguard-rules.pro b/FunctionRealize/Record/app/proguard-rules.pro deleted file mode 100644 index f1b4245..0000000 --- a/FunctionRealize/Record/app/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/FunctionRealize/Record/app/src/androidTest/java/com/record/ExampleInstrumentedTest.java b/FunctionRealize/Record/app/src/androidTest/java/com/record/ExampleInstrumentedTest.java deleted file mode 100644 index 7f787aa..0000000 --- a/FunctionRealize/Record/app/src/androidTest/java/com/record/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.record; - -import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("com.record", appContext.getPackageName()); - } -} diff --git a/FunctionRealize/Record/app/src/main/AndroidManifest.xml b/FunctionRealize/Record/app/src/main/AndroidManifest.xml deleted file mode 100644 index 13f15fe..0000000 --- a/FunctionRealize/Record/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/FunctionRealize/Record/app/src/main/java/com/record/MainActivity.java b/FunctionRealize/Record/app/src/main/java/com/record/MainActivity.java deleted file mode 100644 index 83803d5..0000000 --- a/FunctionRealize/Record/app/src/main/java/com/record/MainActivity.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.record; - -import android.annotation.TargetApi; -import android.os.Build; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.support.annotation.RequiresApi; -import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.View; -import android.media.MediaPlayer; -import android.media.MediaRecorder; -import android.os.Environment; -import android.util.Log; -import android.view.MotionEvent; -import android.view.Window; -import android.widget.Button; -import android.widget.Toast; -import android.widget.ListView; -import java.io.File; -import java.util.concurrent.ExecutorService; - -public class MainActivity extends AppCompatActivity { -} \ No newline at end of file diff --git a/FunctionRealize/Record/app/src/main/java/com/record/MyButtonListener.java b/FunctionRealize/Record/app/src/main/java/com/record/MyButtonListener.java deleted file mode 100644 index ee1bc6a..0000000 --- a/FunctionRealize/Record/app/src/main/java/com/record/MyButtonListener.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.record; - -import android.view.MotionEvent; -import android.view.View; - class MyButtonListener implements View.OnLongClickListener,View.OnTouchListener{ - @Override - public boolean onTouch(View v, MotionEvent event) { - return false; - } - - @Override - public boolean onLongClick(View v) { - return true; - } - } - diff --git a/FunctionRealize/Record/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/FunctionRealize/Record/app/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index c7bd21d..0000000 --- a/FunctionRealize/Record/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - diff --git a/FunctionRealize/Record/app/src/main/res/drawable/ic_launcher_background.xml b/FunctionRealize/Record/app/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index 2408e30..0000000 --- a/FunctionRealize/Record/app/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/FunctionRealize/Record/app/src/main/res/layout/activity_main.xml b/FunctionRealize/Record/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 12f116e..0000000 --- a/FunctionRealize/Record/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - -