Skip to content
This repository has been archived by the owner on May 2, 2021. It is now read-only.

Commit

Permalink
alert dialog & sound when WARN event is logged
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanson committed Mar 15, 2015
1 parent 2ec9b14 commit 43e5338
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.tomjanson.wifilocationlogger;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.location.Location;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
Expand Down Expand Up @@ -263,6 +268,7 @@ void stopLocationUpdates() {
log.trace("Stopped location updates");
} else {
log.warn("Attempted to stop location updates, but not connected");
onWarn();
}
}

Expand Down Expand Up @@ -365,6 +371,7 @@ public void onConnected(Bundle connectionHint) {
@Override
public void onConnectionFailed(ConnectionResult result) {
log.warn("GoogleApiClient connection failed: ConnectionResult.getErrorCode() = {}", result.getErrorCode());
onWarn();
}

@Override
Expand Down Expand Up @@ -404,4 +411,23 @@ public void removeFocusFromEditText(View view) {
public void triggerUpload(View view) {
Uploader.upload(this, "/sdcard/WifiLocationLogger/wifilog.csv");
}

private void onWarn() {
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
new AlertDialog.Builder(this)
.setTitle(getString(R.string.warning))
.setMessage(getString(R.string.warning_msg_logged))
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
<string name="upload_failed">Fehler: Upload fehlgeschlagen!</string>
<string name="upload_file_not_found">Fehler: Logdatei wurde nicht gefunden</string>
<string name="upload_successful">Upload erfolgreich</string>
<string name="warning">Achtung</string>
<string name="warning_msg_logged">Ein Ereignis der Kategorie „WARN“ oder höher wurde geloggt. Bitte sende das Debug-Log an den Entwickler. Die App verhält sich wahrscheinlich fehlerhaft.</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
<string name="upload_failed">Error: Upload failed!</string>
<string name="server">Server</string>
<string name="server_url">Server URL</string>
<string name="warning">Warning</string>
<string name="warning_msg_logged">An event of category “WARN” or higher was logged. Please send the debug log to the developer. It is likely that the app is misbehaving.</string>
</resources>

0 comments on commit 43e5338

Please sign in to comment.