cleanups
This commit is contained in:
parent
fb08385f82
commit
d0fee25ba7
4 changed files with 89 additions and 98 deletions
|
|
@ -4,7 +4,7 @@ import com.android.build.OutputFile
|
|||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion '28.0.2'
|
||||
buildToolsVersion '28.0.3'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.github.axet.audiorecorder"
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import com.github.axet.audiolibrary.encoders.Encoder;
|
|||
import com.github.axet.audiolibrary.encoders.EncoderInfo;
|
||||
import com.github.axet.audiolibrary.encoders.Factory;
|
||||
import com.github.axet.audiolibrary.encoders.FileEncoder;
|
||||
import com.github.axet.audiolibrary.encoders.FormatWAV;
|
||||
import com.github.axet.audiolibrary.encoders.OnFlyEncoding;
|
||||
import com.github.axet.audiolibrary.filters.AmplifierFilter;
|
||||
import com.github.axet.audiolibrary.filters.SkipSilenceFilter;
|
||||
|
|
@ -190,6 +191,83 @@ public class RecordingActivity extends AppCompatThemeActivity {
|
|||
}
|
||||
}
|
||||
|
||||
public void Post(final Throwable e) {
|
||||
Log.d(TAG, "error", e);
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Error(toMessage(e));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String toMessage(Throwable e) {
|
||||
String msg = e.getMessage();
|
||||
if (msg == null || msg.isEmpty()) {
|
||||
Throwable t;
|
||||
if (encoder == null) {
|
||||
t = e;
|
||||
} else {
|
||||
t = encoder.getException();
|
||||
if (t == null)
|
||||
t = e;
|
||||
}
|
||||
while (t.getCause() != null)
|
||||
t = t.getCause();
|
||||
msg = t.getMessage();
|
||||
if (msg == null || msg.isEmpty())
|
||||
msg = t.getClass().getSimpleName();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void Error(Throwable e) {
|
||||
Log.d(TAG, "error", e);
|
||||
Error(toMessage(e));
|
||||
}
|
||||
|
||||
public void Error(String msg) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Error");
|
||||
builder.setMessage(msg);
|
||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
final File in = storage.getTempRecording();
|
||||
if (in.length() > 0) {
|
||||
builder.setNeutralButton(R.string.save_as_wav, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final OpenFileDialog d = new OpenFileDialog(RecordingActivity.this, OpenFileDialog.DIALOG_TYPE.FOLDER_DIALOG);
|
||||
d.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
OnFlyEncoding fly = new OnFlyEncoding(storage, storage.getNewFile(d.getCurrentPath(), FormatWAV.EXT), getInfo());
|
||||
FileEncoder encoder = new FileEncoder(RecordingActivity.this, in, fly);
|
||||
encoding(encoder, fly, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
d.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
builder.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAppTheme() {
|
||||
return AudioApplication.getTheme(this, R.style.RecThemeLight, R.style.RecThemeDark);
|
||||
|
|
@ -1040,103 +1118,17 @@ public class RecordingActivity extends AppCompatThemeActivity {
|
|||
});
|
||||
}
|
||||
|
||||
void Post(final Throwable e) {
|
||||
Log.d(TAG, "error", e);
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Error(toMessage(e));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String toMessage(Throwable e) {
|
||||
String msg = e.getMessage();
|
||||
if (msg == null || msg.isEmpty()) {
|
||||
Throwable t;
|
||||
if (encoder == null) {
|
||||
t = e;
|
||||
} else {
|
||||
t = encoder.getException();
|
||||
if (t == null)
|
||||
t = e;
|
||||
}
|
||||
while (t.getCause() != null)
|
||||
t = t.getCause();
|
||||
msg = t.getMessage();
|
||||
if (msg == null || msg.isEmpty())
|
||||
msg = t.getClass().getSimpleName();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
void Error(Throwable e) {
|
||||
Log.d(TAG, "error", e);
|
||||
Error(toMessage(e));
|
||||
}
|
||||
|
||||
void Error(String msg) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Error");
|
||||
builder.setMessage(msg);
|
||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
final File in = storage.getTempRecording();
|
||||
if (in.length() > 0) {
|
||||
builder.setNeutralButton(R.string.save_as_wav, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final OpenFileDialog d = new OpenFileDialog(RecordingActivity.this, OpenFileDialog.DIALOG_TYPE.FOLDER_DIALOG);
|
||||
d.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
OnFlyEncoding fly = new OnFlyEncoding(storage, storage.getNewFile(d.getCurrentPath(), "wav"), getInfo());
|
||||
FileEncoder encoder = new FileEncoder(RecordingActivity.this, in, fly);
|
||||
encoding(encoder, fly, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
d.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
builder.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
MainActivity.startActivity(this);
|
||||
}
|
||||
|
||||
static PlaybackStateCompat buildState(boolean recording) {
|
||||
PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder()
|
||||
.setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE |
|
||||
PlaybackStateCompat.ACTION_STOP)
|
||||
.setState(recording ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED, 0, 1);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
void headset(boolean b, final boolean recording) {
|
||||
if (b) {
|
||||
if (msc == null) {
|
||||
Log.d(TAG, "headset mediabutton on");
|
||||
ComponentName tr = new ComponentName(this, RecordingReceiver.class);
|
||||
msc = new MediaSessionCompat(this, TAG, tr, null);
|
||||
msc = new MediaSessionCompat(this, TAG, new ComponentName(this, RecordingReceiver.class), null);
|
||||
msc.setCallback(new MediaSessionCompat.Callback() {
|
||||
@Override
|
||||
public void onPlay() {
|
||||
|
|
@ -1155,9 +1147,13 @@ public class RecordingActivity extends AppCompatThemeActivity {
|
|||
});
|
||||
msc.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMANDS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
|
||||
msc.setActive(true);
|
||||
msc.setPlaybackState(buildState(true)); // bug, when after device boot we have to set playing state to 'playing' to make mediabutton work
|
||||
msc.setPlaybackState(new PlaybackStateCompat.Builder().setState(PlaybackStateCompat.STATE_PLAYING, 0, 1).build()); // bug, when after device reboots we have to set playing state to 'playing' to make mediabutton work
|
||||
}
|
||||
msc.setPlaybackState(buildState(recording));
|
||||
PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder()
|
||||
.setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE |
|
||||
PlaybackStateCompat.ACTION_STOP)
|
||||
.setState(recording ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED, 0, 1);
|
||||
msc.setPlaybackState(builder.build());
|
||||
} else {
|
||||
if (msc != null) {
|
||||
Log.d(TAG, "headset mediabutton off");
|
||||
|
|
|
|||
|
|
@ -105,11 +105,6 @@ public class RecordingService extends Service {
|
|||
public RecordingService() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
|
@ -193,7 +188,6 @@ public class RecordingService extends Service {
|
|||
long sec = Storage.average(this, free);
|
||||
text = AudioApplication.formatFree(this, free, sec);
|
||||
builder.setViewVisibility(R.id.notification_record, View.VISIBLE);
|
||||
builder.setOnClickPendingIntent(R.id.notification_record, re);
|
||||
builder.setViewVisibility(R.id.notification_pause, View.GONE);
|
||||
} else {
|
||||
if (recording)
|
||||
|
|
@ -211,8 +205,9 @@ public class RecordingService extends Service {
|
|||
}
|
||||
|
||||
builder.setOnClickPendingIntent(R.id.notification_pause, pe);
|
||||
builder.setOnClickPendingIntent(R.id.notification_record, re);
|
||||
builder.setImageViewResource(R.id.notification_pause, !recording ? R.drawable.ic_play_arrow_black_24dp : R.drawable.ic_pause_black_24dp);
|
||||
RemoteViewsCompat.setContentDescription(builder.compact, R.id.notification_pause, getString(!recording ? R.string.record_button : R.string.pause_button));
|
||||
builder.setContentDescription(R.id.notification_pause, getString(!recording ? R.string.record_button : R.string.pause_button));
|
||||
|
||||
builder.setTheme(AudioApplication.getTheme(this, R.style.RecThemeLight, R.style.RecThemeDark))
|
||||
.setChannel(AudioApplication.from(this).channelStatus)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ buildscript {
|
|||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.2.0'
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue