diff --git a/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java b/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java
index 6cb27f7..3dc8d8b 100644
--- a/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java
+++ b/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java
@@ -517,6 +517,7 @@ public class MainActivity extends AppCompatActivity implements AbsListView.OnScr
@Override
protected void onResume() {
super.onResume();
+ Log.d(TAG, "onResume");
if (permitted(PERMISSIONS))
load();
@@ -525,6 +526,8 @@ public class MainActivity extends AppCompatActivity implements AbsListView.OnScr
checkPending();
+ updateHeader();
+
final int selected = getLastRecording();
list.setSelection(selected);
if (selected != -1) {
@@ -659,4 +662,34 @@ public class MainActivity extends AppCompatActivity implements AbsListView.OnScr
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
+
+ void updateHeader() {
+ File f = storage.getTempRecording();
+ long free = storage.getFree(f);
+
+ long sec = storage.average(free);
+
+ String str = "";
+
+ long diff = sec;
+ int diffSeconds = (int) (diff / 1000 % 60);
+ int diffMinutes = (int) (diff / (60 * 1000) % 60);
+ int diffHours = (int) (diff / (60 * 60 * 1000) % 24);
+ int diffDays = (int) (diff / (24 * 60 * 60 * 1000));
+
+ if (diffDays > 0) {
+ str = getResources().getQuantityString(R.plurals.days, diffDays, diffDays);
+ } else if (diffHours > 0) {
+ str = getResources().getQuantityString(R.plurals.hours, diffHours, diffHours);
+ } else if (diffMinutes > 0) {
+ str = getResources().getQuantityString(R.plurals.minutes, diffMinutes, diffMinutes);
+ } else if (diffSeconds > 0) {
+ str = getResources().getQuantityString(R.plurals.seconds, diffSeconds, diffSeconds);
+ }
+
+ String ss = String.format("free %s ~ %s left", MainApplication.formatSize(free), str);
+
+ TextView text = (TextView) findViewById(R.id.space_left);
+ text.setText(ss);
+ }
}
diff --git a/app/src/main/java/com/github/axet/audiorecorder/app/MainApplication.java b/app/src/main/java/com/github/axet/audiorecorder/app/MainApplication.java
index a3e38c5..d129889 100644
--- a/app/src/main/java/com/github/axet/audiorecorder/app/MainApplication.java
+++ b/app/src/main/java/com/github/axet/audiorecorder/app/MainApplication.java
@@ -26,7 +26,10 @@ public class MainApplication extends Application {
}
public static String formatSize(long s) {
- if (s > 0.1 * 1024 * 1024) {
+ if (s > 0.1 * 1024 * 1024 * 1024) {
+ float f = s / 1024f / 1024f / 1024f;
+ return String.format("%.1f GB", f);
+ } else if (s > 0.1 * 1024 * 1024) {
float f = s / 1024f / 1024f;
return String.format("%.1f MB", f);
} else {
diff --git a/app/src/main/java/com/github/axet/audiorecorder/app/Storage.java b/app/src/main/java/com/github/axet/audiorecorder/app/Storage.java
index 6773f33..6d51de6 100644
--- a/app/src/main/java/com/github/axet/audiorecorder/app/Storage.java
+++ b/app/src/main/java/com/github/axet/audiorecorder/app/Storage.java
@@ -5,11 +5,18 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
+import android.media.AudioFormat;
+import android.os.Build;
+import android.os.StatFs;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
+import android.util.Log;
import android.widget.Toast;
import com.github.axet.audiorecorder.R;
+import com.github.axet.audiorecorder.activities.RecordingActivity;
+import com.github.axet.audiorecorder.encoders.FormatM4A;
+import com.github.axet.audiorecorder.encoders.FormatWAV;
import java.io.File;
import java.io.FileInputStream;
@@ -185,8 +192,68 @@ public class Storage {
return list;
}
+ // get average recording miliseconds based on compression format
+ public long average(long free) {
+ final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
+ int rate = Integer.parseInt(shared.getString(MainApplication.PREFERENCE_RATE, ""));
+ String ext = shared.getString(MainApplication.PREFERENCE_ENCODING, "");
+
+ if (ext.equals("m4a")) {
+ long y1 = 365723; // one minute sample 16000Hz
+ long x1 = 16000; // at 16000
+ long y2 = 493743; // one minute sample
+ long x2 = 44000; // at 44000
+ long x = rate;
+ long y = (x - x1) * (y2 - y1) / (x2 - x1) + y1;
+
+ int m = RawSamples.CHANNEL_CONFIG == AudioFormat.CHANNEL_IN_MONO ? 1 : 2;
+ long perSec = (y / 60) * m;
+ return free / perSec * 1000;
+ }
+
+ // default raw
+ int m = RawSamples.CHANNEL_CONFIG == AudioFormat.CHANNEL_IN_MONO ? 1 : 2;
+ int c = RawSamples.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1;
+ long perSec = (c * m * rate);
+ return free / perSec * 1000;
+ }
+
+ public long getFree(File f) {
+ while (!f.exists())
+ f = f.getParentFile();
+
+ StatFs fsi = new StatFs(f.getPath());
+ if (Build.VERSION.SDK_INT < 18)
+ return fsi.getBlockSize() * fsi.getAvailableBlocks();
+ else
+ return fsi.getBlockSizeLong() * fsi.getAvailableBlocksLong();
+ }
+
public File getTempRecording() {
- return new File(context.getApplicationInfo().dataDir, TMP_REC);
+ File internal = new File(context.getApplicationInfo().dataDir, TMP_REC);
+
+ // Starting in KITKAT, no permissions are required to read or write to the returned path;
+ // it's always accessible to the calling app
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+ if (!permitted(PERMISSIONS))
+ return internal;
+ }
+
+ File external = new File(context.getExternalCacheDir(), TMP_REC);
+
+ if (internal.exists())
+ return internal;
+
+ if (external.exists())
+ return external;
+
+ long freeI = getFree(internal);
+ long freeE = getFree(external);
+
+ if (freeI > freeE)
+ return internal;
+ else
+ return external;
}
public FileOutputStream open(File f) {
diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml
index 0144341..2b94ac4 100644
--- a/app/src/main/res/layout/content_main.xml
+++ b/app/src/main/res/layout/content_main.xml
@@ -1,17 +1,25 @@
-
+
+
-
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 2aa6034..b15321d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -33,4 +33,25 @@
Audio Recorder
Settings
+
+
+ - %d day
+ - %d days
+
+
+
+ - %d hour
+ - %d hours
+
+
+
+ - %d minute
+ - %d minutes
+
+
+
+ - %d second
+ - %d seconds
+
+