check pending on lock

This commit is contained in:
Alexey Kuznetsov 2017-06-20 12:54:59 +03:00
commit 7e050716a0
4 changed files with 26 additions and 8 deletions

View file

@ -7,7 +7,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name=".app.MainApplication"

View file

@ -75,7 +75,7 @@ public class RecordingActivity extends AppCompatActivity {
// pitch size in samples. how many samples count need to update view. 4410 for 100ms update.
int samplesUpdate;
// output target file 2016-01-01 01.01.01.wav
File targetFile;
File targetFile = null;
// how many samples passed for current recording
long samplesTime;
// current cut position in samples from begining of file
@ -167,8 +167,19 @@ public class RecordingActivity extends AppCompatActivity {
edit(false, false);
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
try {
targetFile = storage.getNewFile();
if (storage.recordingPending()) {
String file = shared.getString(MainApplication.PREFERENCE_TARGET, null);
if (file != null)
targetFile = new File(file);
}
if (targetFile == null)
targetFile = storage.getNewFile();
SharedPreferences.Editor editor = shared.edit();
editor.putString(MainApplication.PREFERENCE_TARGET, targetFile.toString());
editor.commit();
} catch (RuntimeException e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
finish();
@ -177,7 +188,6 @@ public class RecordingActivity extends AppCompatActivity {
title.setText(targetFile.getName());
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
if (shared.getBoolean(MainApplication.PREFERENCE_CALL, false)) {
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
@ -569,6 +579,10 @@ public class RecordingActivity extends AppCompatActivity {
encoder.close();
encoder = null;
}
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = shared.edit();
editor.remove(MainApplication.PREFERENCE_TARGET);
}
void startRecording() {

View file

@ -7,6 +7,7 @@ import com.github.axet.audiorecorder.R;
public class MainApplication extends com.github.axet.audiolibrary.app.MainApplication {
public static final String PREFERENCE_CONTROLS = "controls";
public static final String PREFERENCE_TARGET = "target";
@Override
public void onCreate() {

View file

@ -56,7 +56,10 @@ public class RecordingService extends Service {
public static void startIfEnabledPending(Context context) {
Storage s = new Storage(context);
if (s.recordingPending()) {
RecordingActivity.startActivity(context, true);
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
String f = shared.getString(MainApplication.PREFERENCE_TARGET, "");
File file = new File(f);
startService(context, file.getName(), false, false);
return;
}
startIfEnabled(context);
@ -111,10 +114,10 @@ public class RecordingService extends Service {
} else if (a.equals(RECORD_BUTTON)) {
RecordingActivity.startActivity(this, false);
} else if (a.equals(SHOW_ACTIVITY)) {
if (!intent.getBooleanExtra("recording", false))
if (intent.getStringExtra("targetFile") == null)
MainActivity.startActivity(this);
else
RecordingActivity.startActivity(this, false);
RecordingActivity.startActivity(this, !intent.getBooleanExtra("recording", false));
}
}
@ -149,7 +152,7 @@ public class RecordingService extends Service {
boolean encoding = intent.getBooleanExtra("encoding", false);
PendingIntent main = PendingIntent.getService(this, 0,
new Intent(this, RecordingService.class).setAction(SHOW_ACTIVITY).putExtra("recording", targetFile != null),
new Intent(this, RecordingService.class).setAction(SHOW_ACTIVITY).putExtra("targetFile", targetFile).putExtra("recording", recording),
PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pe = PendingIntent.getService(this, 0,