Skip to content

Commit

Permalink
full reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
wuan committed Nov 17, 2015
1 parent 8cd8e69 commit dd8fabd
Show file tree
Hide file tree
Showing 123 changed files with 1,382 additions and 1,566 deletions.
47 changes: 24 additions & 23 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.blitzortung.android.app">
package="org.blitzortung.android.app">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:hardwareAccelerated="true"
android:allowBackup="true"
android:installLocation="auto">
<uses-library android:name="com.google.android.maps"/>
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:installLocation="auto"
android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />

<activity
android:name=".Main"
android:label="@string/app_name">
android:name=".Main"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".AppService"/>
<service android:name=".AppService" />
<activity
android:name=".Preferences"
android:label="@string/preferences"/>
android:name=".Preferences"
android:label="@string/preferences" />
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="false">
android:name=".BootReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT"/>

<category android:name="android.intent.category.DEFAULT" />
<category android:name="org.blitzortung.android.app" />
</intent-filter>
</receiver>
Expand Down
72 changes: 30 additions & 42 deletions app/src/main/java/org/blitzortung/android/alert/AlertHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.location.Location;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
Expand All @@ -14,23 +13,23 @@

import com.annimon.stream.function.Consumer;

import org.blitzortung.android.alert.event.AlertResultEvent;
import org.blitzortung.android.alert.data.AlertSector;
import org.blitzortung.android.alert.data.AlertStatus;
import org.blitzortung.android.alert.event.AlertCancelEvent;
import org.blitzortung.android.alert.event.AlertEvent;
import org.blitzortung.android.alert.event.AlertResultEvent;
import org.blitzortung.android.alert.factory.AlertObjectFactory;
import org.blitzortung.android.alert.handler.AlertStatusHandler;
import org.blitzortung.android.alert.data.AlertSector;
import org.blitzortung.android.alert.data.AlertStatus;
import org.blitzortung.android.app.Main;
import org.blitzortung.android.app.R;
import org.blitzortung.android.app.controller.NotificationHandler;
import org.blitzortung.android.app.view.PreferenceKey;
import org.blitzortung.android.data.beans.Strike;
import org.blitzortung.android.data.provider.result.ClearDataEvent;
import org.blitzortung.android.data.provider.result.DataEvent;
import org.blitzortung.android.data.provider.result.ResultEvent;
import org.blitzortung.android.location.LocationEvent;
import org.blitzortung.android.location.LocationHandler;
import org.blitzortung.android.app.controller.NotificationHandler;
import org.blitzortung.android.app.view.PreferenceKey;
import org.blitzortung.android.util.MeasurementSystem;

import java.util.Collection;
Expand All @@ -40,34 +39,45 @@ public class AlertHandler implements OnSharedPreferenceChangeListener {
public static final AlertCancelEvent ALERT_CANCEL_EVENT = new AlertCancelEvent();
private final Vibrator vibrator;
private final NotificationHandler notificationHandler;
private final AlertParameters alertParameters;
private final AlertStatus alertStatus;
private final AlertStatusHandler alertStatusHandler;
private final LocationHandler locationHandler;
protected Consumer<AlertEvent> alertEventConsumer;
private Context context;
private Collection<? extends Strike> lastStrikes;
private int vibrationSignalDuration;
private Uri alarmSoundNotificationSignal;

private final AlertParameters alertParameters;

private Location location;

private boolean alertEnabled;

private boolean alarmValid;

protected Consumer<AlertEvent> alertEventConsumer;

private final AlertStatus alertStatus;

private final AlertStatusHandler alertStatusHandler;

private final LocationHandler locationHandler;

private float notificationDistanceLimit;

private long notificationLastTimestamp;

private float signalingDistanceLimit;

private long signalingLastTimestamp;
private final Consumer<LocationEvent> locationEventConsumer = new Consumer<LocationEvent>() {
@Override
public void accept(LocationEvent event) {
Log.v(Main.LOG_TAG, "AlertHandler received location " + location);
location = event.getLocation();
checkStrikes(lastStrikes);
}
};
private final Consumer<DataEvent> dataEventConsumer = event -> {
if (event instanceof ResultEvent) {
ResultEvent resultEvent = (ResultEvent) event;
if (!resultEvent.hasFailed() && resultEvent.containsRealtimeData()) {
checkStrikes(resultEvent.getStrikes());
} else {
invalidateAlert();
}
} else if (event instanceof ClearDataEvent) {
invalidateAlert();
}
};

public AlertHandler(LocationHandler locationHandler, SharedPreferences preferences, Context context, Vibrator vibrator, NotificationHandler notificationHandler, AlertObjectFactory alertObjectFactory, AlertParameters alertParameters) {
this.locationHandler = locationHandler;
Expand Down Expand Up @@ -135,32 +145,10 @@ private void updateLocationHandler() {
}
}

private final Consumer<LocationEvent> locationEventConsumer = new Consumer<LocationEvent>() {
@Override
public void accept(LocationEvent event) {
Log.v(Main.LOG_TAG, "AlertHandler received location " + location);
location = event.getLocation();
checkStrikes(lastStrikes);
}
};

public Consumer<LocationEvent> getLocationEventConsumer() {
return locationEventConsumer;
}

private final Consumer<DataEvent> dataEventConsumer = event -> {
if (event instanceof ResultEvent) {
ResultEvent resultEvent = (ResultEvent) event;
if (!resultEvent.hasFailed() && resultEvent.containsRealtimeData()) {
checkStrikes(resultEvent.getStrikes());
} else {
invalidateAlert();
}
} else if (event instanceof ClearDataEvent) {
invalidateAlert();
}
};

public Consumer<DataEvent> getDataEventConsumer() {
return dataEventConsumer;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package org.blitzortung.android.alert;

import android.content.Context;

import org.blitzortung.android.app.R;
import org.blitzortung.android.util.MeasurementSystem;

public class AlertParameters {
private static String[] SECTOR_LABELS;

private static final float[] RANGE_STEPS = {10, 25, 50, 100, 250, 500};

private static final long alarmInterval = 10 * 60 * 1000;

private static String[] SECTOR_LABELS;
private MeasurementSystem measurementSystem;

public void updateSectorLabels(Context context) {
SECTOR_LABELS = context.getResources().getStringArray(R.array.direction_names);
}
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/org/blitzortung/android/alert/AlertResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
import org.blitzortung.android.alert.data.AlertSector;

public class AlertResult {
private final AlertSector sector;

private final AlertSector sector;

private final String distanceUnitName;

public AlertResult(AlertSector sector, String distanceUnitName) {
this.sector = sector;
this.sector = sector;
this.distanceUnitName = distanceUnitName;
}

public float getClosestStrikeDistance() {
return sector.getClosestStrikeDistance();
}
public float getClosestStrikeDistance() {
return sector.getClosestStrikeDistance();
}

public String getDistanceUnitName() {
return distanceUnitName;
Expand All @@ -24,7 +24,7 @@ public String getDistanceUnitName() {
public String getBearingName() {
return sector.getLabel();
}

@Override
public String toString() {
return String.format("%s %.1f %s", getBearingName(), getClosestStrikeDistance(), getDistanceUnitName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
public class AlertSectorRange {

private final float rangeMinimum;

private final float rangeMaximum;

private int strikeCount;

private long latestStrikeTimestamp;

public AlertSectorRange(float rangeMinimum, float rangeMaximum) {
this.rangeMinimum = rangeMinimum;
this.rangeMaximum = rangeMaximum;
}

public void clearResults()
{

public void clearResults() {
strikeCount = 0;
latestStrikeTimestamp = 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.blitzortung.android.alert.factory;

import org.blitzortung.android.alert.AlertParameters;
import org.blitzortung.android.alert.handler.AlertSectorHandler;
import org.blitzortung.android.alert.handler.AlertStatusHandler;
import org.blitzortung.android.alert.data.AlertSector;
import org.blitzortung.android.alert.data.AlertSectorRange;
import org.blitzortung.android.alert.data.AlertStatus;
import org.blitzortung.android.alert.handler.AlertSectorHandler;
import org.blitzortung.android.alert.handler.AlertStatusHandler;

public class AlertObjectFactory {

public AlertObjectFactory() {
}

public AlertStatus createAlarmStatus(AlertParameters alertParameters) {
return new AlertStatus(this, alertParameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.location.Location;

import com.annimon.stream.Optional;
import com.annimon.stream.Stream;

import org.blitzortung.android.alert.AlertParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.location.Location;
import android.util.Log;

import org.blitzortung.android.alert.AlertParameters;
import org.blitzortung.android.alert.AlertResult;
import org.blitzortung.android.alert.data.AlertSector;
Expand Down Expand Up @@ -46,14 +47,14 @@ public AlertStatus checkStrikes(AlertStatus alertStatus, Collection<? extends St

public long getLatestTimstampWithin(float distanceLimit, AlertStatus alertStatus) {
long latestTimestamp = 0;

for (AlertSector sector : alertStatus.getSectors()) {
latestTimestamp = Math.max(latestTimestamp, alertSectorHandler.getLatestTimestampWithin(distanceLimit, sector));
}

return latestTimestamp;
}

public AlertSector getSectorWithClosestStrike(AlertStatus alertStatus) {
float minDistance = Float.POSITIVE_INFINITY;

Expand Down
Loading

0 comments on commit dd8fabd

Please sign in to comment.