mirror of
https://github.com/xdsopl/robot36.git
synced 2025-12-06 07:12:07 +01:00
catch decoder init errors and prepare to send email
This commit is contained in:
parent
57e5779468
commit
5286f176c1
|
|
@ -101,7 +101,7 @@ public class Decoder {
|
|||
}
|
||||
};
|
||||
|
||||
public Decoder(MainActivity activity, SpectrumView spectrum, SpectrumView spectrogram, ImageView image, VUMeterView meter) {
|
||||
public Decoder(MainActivity activity, SpectrumView spectrum, SpectrumView spectrogram, ImageView image, VUMeterView meter) throws Exception {
|
||||
this.image = image;
|
||||
this.spectrogram = spectrogram;
|
||||
this.spectrum = spectrum;
|
||||
|
|
@ -112,6 +112,8 @@ public class Decoder {
|
|||
spectrogramBuffer = new int[spectrogram.bitmap.getWidth() * spectrogram.bitmap.getHeight()];
|
||||
|
||||
int bufferSizeInBytes = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
|
||||
if (bufferSizeInBytes <= 0)
|
||||
throw new Exception("Unable to open audio with " + sampleRate + "Hz samplerate");
|
||||
int bufferSizeInSamples = bufferSizeInBytes / 2;
|
||||
int framesPerSecond = Math.max(1, sampleRate / bufferSizeInSamples);
|
||||
audioBuffer = new short[framesPerSecond * bufferSizeInSamples];
|
||||
|
|
|
|||
|
|
@ -18,11 +18,13 @@ limitations under the License.
|
|||
package xdsopl.robot36;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
|
|
@ -143,15 +145,51 @@ public class MainActivity extends Activity {
|
|||
menu.setGroupEnabled(R.id.group_decoder, false);
|
||||
}
|
||||
|
||||
private Intent createEmailIntent(final String subject, final String text) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType("text/email");
|
||||
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{ getString(R.string.email_address) });
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, text);
|
||||
return intent;
|
||||
}
|
||||
|
||||
private void showErrorMessage(final String title, final String shortText, final String longText) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(title);
|
||||
builder.setMessage(shortText);
|
||||
builder.setNeutralButton(getString(R.string.btn_ok), null);
|
||||
builder.setPositiveButton(getString(R.string.btn_send_email), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = createEmailIntent(getString(R.string.email_subject), longText);
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.chooser_title)));
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private String createMessage(Exception ex) {
|
||||
String message = ex.getMessage() + "\n";
|
||||
for (StackTraceElement el : ex.getStackTrace())
|
||||
message += "\n" + el.toString();
|
||||
return message;
|
||||
}
|
||||
|
||||
protected void startDecoder() {
|
||||
if (decoder != null)
|
||||
return;
|
||||
decoder = new Decoder(this,
|
||||
(SpectrumView)findViewById(R.id.spectrum),
|
||||
(SpectrumView)findViewById(R.id.spectrogram),
|
||||
(ImageView)findViewById(R.id.image),
|
||||
(VUMeterView)findViewById(R.id.meter)
|
||||
);
|
||||
try {
|
||||
decoder = new Decoder(this,
|
||||
(SpectrumView) findViewById(R.id.spectrum),
|
||||
(SpectrumView) findViewById(R.id.spectrogram),
|
||||
(ImageView) findViewById(R.id.image),
|
||||
(VUMeterView) findViewById(R.id.meter)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
showErrorMessage(getString(R.string.decoder_error), e.getMessage(), createMessage(e));
|
||||
return;
|
||||
}
|
||||
decoder.enable_analyzer(enableAnalyzer);
|
||||
showNotification();
|
||||
if (menu != null) {
|
||||
|
|
@ -191,6 +229,10 @@ public class MainActivity extends Activity {
|
|||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
this.menu = menu;
|
||||
if (decoder != null) {
|
||||
menu.findItem(R.id.action_toggle_decoder).setIcon(getResources().getDrawable(android.R.drawable.ic_media_pause));
|
||||
menu.setGroupEnabled(R.id.group_decoder, true);
|
||||
}
|
||||
share = (ShareActionProvider)menu.findItem(R.id.menu_item_share).getActionProvider();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,25 +2,26 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context=".MainActivity">
|
||||
<item
|
||||
android:id="@+id/menu_item_share"
|
||||
android:showAsAction="always"
|
||||
android:title="@string/action_share"
|
||||
android:actionProviderClass="android.widget.ShareActionProvider" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_save_image"
|
||||
android:title="@string/action_save_image"
|
||||
android:icon="@android:drawable/ic_menu_save"
|
||||
android:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_toggle_decoder"
|
||||
android:title="@string/action_toggle_decoder"
|
||||
android:icon="@android:drawable/ic_media_pause"
|
||||
android:icon="@android:drawable/ic_media_play"
|
||||
android:showAsAction="ifRoom" />
|
||||
|
||||
<group android:id="@+id/group_decoder">
|
||||
<group android:id="@+id/group_decoder" android:enabled="false">
|
||||
<item
|
||||
android:id="@+id/menu_item_share"
|
||||
android:showAsAction="always"
|
||||
android:title="@string/action_share"
|
||||
android:actionProviderClass="android.widget.ShareActionProvider" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_save_image"
|
||||
android:title="@string/action_save_image"
|
||||
android:icon="@android:drawable/ic_menu_save"
|
||||
android:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_clear_image"
|
||||
android:title="@string/action_clear_image"
|
||||
|
|
|
|||
|
|
@ -50,4 +50,8 @@
|
|||
<string name="martin_modes">Martin Modi</string>
|
||||
<string name="scottie_modes">Scottie Modi</string>
|
||||
<string name="wraase_modes">Wraase Modi</string>
|
||||
<string name="btn_ok">Ok</string>
|
||||
<string name="btn_send_email">Email senden</string>
|
||||
<string name="chooser_title">Fehlermeldung senden:</string>
|
||||
<string name="decoder_error">Dekodierer Fehler</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -50,4 +50,10 @@
|
|||
<string name="martin_modes">Martin Modes</string>
|
||||
<string name="scottie_modes">Scottie Modes</string>
|
||||
<string name="wraase_modes">Wraase Modes</string>
|
||||
<string name="btn_ok">OK</string>
|
||||
<string name="btn_send_email">Send Email</string>
|
||||
<string name="email_subject">[BUG] Robot36 - SSTV Image Decoder</string>
|
||||
<string name="chooser_title">Send Bug Report:</string>
|
||||
<string name="email_address">xdsopl@googlemail.com</string>
|
||||
<string name="decoder_error">Decoder error</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Reference in a new issue