diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..23a89bb --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d5d35ec --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..4c73b90 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,38 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 29 + + defaultConfig { + applicationId "com.example.recordnclick" + minSdkVersion 29 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# 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 \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/recordnclick/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/recordnclick/ExampleInstrumentedTest.java new file mode 100644 index 0000000..1761192 --- /dev/null +++ b/app/src/androidTest/java/com/example/recordnclick/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.recordnclick; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.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.getInstrumentation().getTargetContext(); + assertEquals("com.example.recordnclick", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..439c3eb --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/recordnclick/MainActivity.java b/app/src/main/java/com/example/recordnclick/MainActivity.java new file mode 100644 index 0000000..1da0580 --- /dev/null +++ b/app/src/main/java/com/example/recordnclick/MainActivity.java @@ -0,0 +1,170 @@ +package com.example.recordnclick; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; + +import android.Manifest; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.media.MediaPlayer; +import android.media.MediaRecorder; +import android.os.Bundle; +import android.os.Environment; +import android.provider.MediaStore; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; + +import java.io.File; +import java.io.IOException; + +public class MainActivity extends AppCompatActivity { + + private Button play, stop, record; + private MediaRecorder myAudioRecorder; + + public static String filename= "recorded.3pg"; + String outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator+ filename; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + play = (Button) findViewById(R.id.play); + stop = (Button) findViewById(R.id.stop); + record = (Button) findViewById(R.id.record); + + stop.setEnabled(false); + play.setEnabled(false); + + //myAudioRecorder = new MediaRecorder(); + //myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + //myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); + //myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB); + //myAudioRecorder.setOutputFile(outputFile); + Log.d("myTag",outputFile ); + + if(ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.RECORD_AUDIO)!= PackageManager.PERMISSION_GRANTED) + { + ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.RECORD_AUDIO},0); + } + else + { + + Log.d("myTag",outputFile ); + } + + + if(ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) + { + ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},0); + } + else + { + + Log.d("myTag",outputFile ); + } + + if(ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) + { + ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},0); + } + else + { + + Log.d("myTag",outputFile ); + } + + + if(ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.MODIFY_AUDIO_SETTINGS)!= PackageManager.PERMISSION_GRANTED) + { + ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.MODIFY_AUDIO_SETTINGS},0); + } + else + { + + Log.d("myTag",outputFile ); + } + + //MODIFY_AUDIO_SETTINGS + + //MODIFY_AUDIO_SETTINGS + //READ_EXTERNAL_STORAGE + + + myAudioRecorder = new MediaRecorder(); + myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); + myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB); + myAudioRecorder.setAudioSamplingRate(16000); + myAudioRecorder.setOutputFile(outputFile); + + + + + record.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + myAudioRecorder.prepare(); + myAudioRecorder.start(); + Toast.makeText(getApplicationContext(), "Recording started", Toast.LENGTH_LONG).show(); + } catch (IllegalStateException ise) { + // make something ... + } catch (IOException ioe) { + // make something + } + record.setEnabled(false); + stop.setEnabled(true); + + } + }); + + stop.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + try { + myAudioRecorder.stop(); + myAudioRecorder.release(); + + + } catch(RuntimeException stopException) { + // handle cleanup here + Toast.makeText(getApplicationContext(), "Not successful", Toast.LENGTH_LONG).show(); + } + + myAudioRecorder = null; + record.setEnabled(true); + stop.setEnabled(false); + play.setEnabled(true); + Toast.makeText(getApplicationContext(), "Audio Recorder successfully", Toast.LENGTH_LONG).show(); + + + } + }); + + play.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MediaPlayer mediaPlayer = new MediaPlayer(); + try { + mediaPlayer.setDataSource(outputFile); + mediaPlayer.prepare(); + mediaPlayer.start(); + Toast.makeText(getApplicationContext(), "Playing Audio", Toast.LENGTH_LONG).show(); + } catch (Exception e) { + // make something + + System.out.println(e); + } + } + }); + + + + + + + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..1db4f94 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,43 @@ + + + + +