show duration in notification title

This commit is contained in:
Alexey Kuznetsov 2018-10-24 17:55:39 +03:00
commit 9e206ab93c
4 changed files with 24 additions and 14 deletions

View file

@ -1,5 +1,6 @@
package com.github.axet.audiorecorder.activities;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -129,6 +130,11 @@ public class MainActivity extends AppCompatThemeActivity {
getMenuInflater().inflate(R.menu.menu_main, menu);
KeyguardManager myKM = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
if (myKM.inKeyguardRestrictedInputMode()) {
menu.findItem(R.id.action_settings).setVisible(false);
}
MenuItem item = menu.findItem(R.id.action_show_folder);
Intent intent = StorageProvider.getProvider().openFolderIntent(storage.getStoragePath());
item.setIntent(intent);

View file

@ -102,6 +102,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
TextView title;
TextView time;
String duration;
TextView state;
ImageButton pause;
View done;
@ -113,7 +114,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
ScreenReceiver screen;
Handler handler = new Handler();
ShortBuffer dbBuffer = null;
ShortBuffer dbBuffer = null; // PinchView samples buffer
MediaSessionCompat msc;
@ -490,7 +491,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
boolean recording = thread != null;
RecordingService.startService(this, Storage.getDocumentName(targetUri), recording, encoder != null);
RecordingService.startService(this, Storage.getDocumentName(targetUri), recording, encoder != null, duration);
if (recording) {
pitch.record();
@ -516,7 +517,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
stopRecording();
RecordingService.startService(this, Storage.getDocumentName(targetUri), thread != null, encoder != null);
RecordingService.startService(this, Storage.getDocumentName(targetUri), thread != null, encoder != null, duration);
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
@ -873,8 +874,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
recorder.startRecording();
int samplesTimeCount = 0;
// how many samples we need to update 'samples'. time clock. every 1000ms.
int samplesTimeUpdate = 1000 * sampleRate / 1000;
final int samplesTimeUpdate = 1000 * sampleRate / 1000; // how many samples we need to update 'samples'. time clock. every 1000ms.
short[] buffer = null;
@ -887,9 +887,8 @@ public class RecordingActivity extends AppCompatThemeActivity {
}
int readSize = recorder.read(buffer, 0, buffer.length);
if (readSize < 0) {
if (readSize < 0)
return;
}
long end = System.currentTimeMillis();
long diff = (end - start) * sampleRate / 1000;
@ -981,7 +980,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
}, "RecordingThread");
thread.start();
RecordingService.startService(this, Storage.getDocumentName(targetUri), thread != null, encoder != null);
RecordingService.startService(this, Storage.getDocumentName(targetUri), thread != null, encoder != null, duration);
}
// calcuale buffer length dynamically, this way we can reduce thread cycles when activity in background
@ -1012,7 +1011,9 @@ public class RecordingActivity extends AppCompatThemeActivity {
void updateSamples(long samplesTime) {
long ms = samplesTime / sampleRate * 1000;
time.setText(AudioApplication.formatDuration(this, ms));
duration = AudioApplication.formatDuration(this, ms);
time.setText(duration);
RecordingService.startService(this, Storage.getDocumentName(targetUri), thread != null, encoder != null, duration);
}
@Override
@ -1083,7 +1084,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
}
void encoding(final FileEncoder encoder, final OnFlyEncoding fly, final Runnable last) {
RecordingService.startService(this, Storage.getDocumentName(fly.targetUri), thread != null, encoder != null);
RecordingService.startService(this, Storage.getDocumentName(fly.targetUri), thread != null, encoder != null, duration);
final ProgressDialog d = new ProgressDialog(this);
d.setTitle(R.string.encoding_title);

View file

@ -65,13 +65,13 @@ public class RecordingService extends Service {
d = Storage.getDocumentName(u);
} else if (f.startsWith(ContentResolver.SCHEME_FILE)) {
Uri u = Uri.parse(f);
File file = new File(u.getPath());
File file = Storage.getFile(u);
d = file.getName();
} else {
File file = new File(f);
d = file.getName();
}
startService(context, d, false, false);
startService(context, d, false, false, null);
return;
}
startIfEnabled(context);
@ -81,11 +81,12 @@ public class RecordingService extends Service {
context.startService(new Intent(context, RecordingService.class));
}
public static void startService(Context context, String targetFile, boolean recording, boolean encoding) {
public static void startService(Context context, String targetFile, boolean recording, boolean encoding, String duration) {
context.startService(new Intent(context, RecordingService.class)
.putExtra("targetFile", targetFile)
.putExtra("recording", recording)
.putExtra("encoding", encoding)
.putExtra("duration", duration)
);
}
@ -164,6 +165,7 @@ public class RecordingService extends Service {
String targetFile = intent.getStringExtra("targetFile");
boolean recording = intent.getBooleanExtra("recording", false);
boolean encoding = intent.getBooleanExtra("encoding", false);
String duration = intent.getStringExtra("duration");
PendingIntent main = PendingIntent.getService(this, 0,
new Intent(this, RecordingService.class).setAction(SHOW_ACTIVITY).putExtra("targetFile", targetFile).putExtra("recording", recording),
@ -194,6 +196,8 @@ public class RecordingService extends Service {
title = getString(R.string.recording_title);
else
title = getString(R.string.pause_title);
if (duration != null)
title += " (" + duration + ")";
text = ".../" + targetFile;
builder.setViewVisibility(R.id.notification_record, View.GONE);
builder.setViewVisibility(R.id.notification_pause, View.VISIBLE);

View file

@ -32,5 +32,4 @@
android:background="?attr/colorAccent"
android:src="@drawable/ic_mic_24dp"
android:contentDescription="@string/record_button" />
</android.support.design.widget.CoordinatorLayout>