Skip to content

Commit

Permalink
add menu item for high quality recording
Browse files Browse the repository at this point in the history
also remove # from filename
  • Loading branch information
ChristophHaag committed May 22, 2017
1 parent 522f153 commit 4a62684
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaRecorder;
import android.os.Environment;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;
Expand Down Expand Up @@ -77,6 +79,8 @@ public void onDestroy() {

public void startRecording() {

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

setFileNameAndPath();

mRecorder = new MediaRecorder();
Expand All @@ -85,6 +89,10 @@ public void startRecording() {
mRecorder.setOutputFile(mFilePath);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setAudioChannels(1);
if (preferences.getBoolean("high_quality", true)) {
mRecorder.setAudioSamplingRate(44100);
mRecorder.setAudioEncodingBitRate(192000);
}

try {
mRecorder.prepare();
Expand All @@ -107,7 +115,7 @@ public void setFileNameAndPath(){
count++;

mFileName = getString(R.string.default_file_name)
+ " #" + (mDatabase.getCount() + count) + ".mp4";
+ " " + (mDatabase.getCount() + count) + ".mp4";
mFilePath = Environment.getExternalStorageDirectory().getAbsolutePath();
mFilePath += "/SoundRecorder/" + mFileName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.danielkim.soundrecorder.activities;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
Expand All @@ -23,6 +25,8 @@ public class MainActivity extends ActionBarActivity{

private PagerSlidingTabStrip tabs;
private ViewPager pager;
public SharedPreferences sharedPref;
private Menu mOptionsMenu;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -39,12 +43,18 @@ protected void onCreate(Bundle savedInstanceState) {
if (toolbar != null) {
setSupportActionBar(toolbar);
}

sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
mOptionsMenu = menu;

MenuItem high_quality = mOptionsMenu.findItem(R.id.action_high_quality);
high_quality.setChecked(sharedPref.getBoolean("high_quality", true));
return true;
}

Expand All @@ -58,11 +68,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_licenses:
openLicenses();
return true;
case R.id.action_high_quality:
toggleQuality();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

public void toggleQuality() {
SharedPreferences.Editor editor = sharedPref.edit();
editor.putBoolean("high_quality", !sharedPref.getBoolean("high_quality", true));
editor.commit();

MenuItem high_quality = mOptionsMenu.findItem(R.id.action_high_quality);
high_quality.setChecked(sharedPref.getBoolean("high_quality", true));
}

public void openLicenses(){
LicensesFragment licensesFragment = new LicensesFragment();
licensesFragment.show(getSupportFragmentManager().beginTransaction(), "dialog_licenses");
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
tools:context=".MainActivity">
<!-- View Open Source Licenses -->
<item
android:id="@+id/action_licenses"
android:title="@string/action_licenses"
android:id="@+id/action_high_quality"
android:checkable="true"
android:checked="true"
android:enabled="true"
android:orderInCategory="100"
app:showAsAction="never" />
android:title="@string/action_high_quality" />
<item
android:id="@+id/action_licenses"
android:orderInCategory="101"
android:title="@string/action_licenses" />
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
<string name="default_file_name">Meine Aufzeichnung</string>
<string name="record_prompt">Berühre den Button, um die Aufzeichnung zu starten</string>
<string name="record_in_progress">Nehme auf</string>
<string name="action_high_quality">Hohe Qualität</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
<string name="record_in_progress">Recording</string>

<string name="send_to">Send to</string>
<string name="action_high_quality">High Quality</string>

</resources>

0 comments on commit 4a62684

Please sign in to comment.