diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8fb2d4aa..f514475d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,41 +1,42 @@ + package="org.blitzortung.android.app"> - - - - - + + + + + - + android:allowBackup="true" + android:hardwareAccelerated="true" + android:icon="@drawable/icon" + android:installLocation="auto" + android:label="@string/app_name"> + + android:name=".Main" + android:label="@string/app_name"> - - + + - + + android:name=".Preferences" + android:label="@string/preferences" /> + android:name=".BootReceiver" + android:enabled="true" + android:exported="false"> - + + diff --git a/app/src/main/java/org/blitzortung/android/alert/AlertHandler.java b/app/src/main/java/org/blitzortung/android/alert/AlertHandler.java index 635f1d1a..42ad7aaa 100644 --- a/app/src/main/java/org/blitzortung/android/alert/AlertHandler.java +++ b/app/src/main/java/org/blitzortung/android/alert/AlertHandler.java @@ -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; @@ -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; @@ -40,27 +39,18 @@ 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 alertEventConsumer; private Context context; private Collection lastStrikes; private int vibrationSignalDuration; private Uri alarmSoundNotificationSignal; - - private final AlertParameters alertParameters; - private Location location; - private boolean alertEnabled; - private boolean alarmValid; - - protected Consumer alertEventConsumer; - - private final AlertStatus alertStatus; - - private final AlertStatusHandler alertStatusHandler; - - private final LocationHandler locationHandler; - private float notificationDistanceLimit; private long notificationLastTimestamp; @@ -68,6 +58,26 @@ public class AlertHandler implements OnSharedPreferenceChangeListener { private float signalingDistanceLimit; private long signalingLastTimestamp; + private final Consumer locationEventConsumer = new Consumer() { + @Override + public void accept(LocationEvent event) { + Log.v(Main.LOG_TAG, "AlertHandler received location " + location); + location = event.getLocation(); + checkStrikes(lastStrikes); + } + }; + private final Consumer 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; @@ -135,32 +145,10 @@ private void updateLocationHandler() { } } - private final Consumer locationEventConsumer = new Consumer() { - @Override - public void accept(LocationEvent event) { - Log.v(Main.LOG_TAG, "AlertHandler received location " + location); - location = event.getLocation(); - checkStrikes(lastStrikes); - } - }; - public Consumer getLocationEventConsumer() { return locationEventConsumer; } - private final Consumer 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 getDataEventConsumer() { return dataEventConsumer; } diff --git a/app/src/main/java/org/blitzortung/android/alert/AlertParameters.java b/app/src/main/java/org/blitzortung/android/alert/AlertParameters.java index 3f5e424b..b8b6eff4 100644 --- a/app/src/main/java/org/blitzortung/android/alert/AlertParameters.java +++ b/app/src/main/java/org/blitzortung/android/alert/AlertParameters.java @@ -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); } diff --git a/app/src/main/java/org/blitzortung/android/alert/AlertResult.java b/app/src/main/java/org/blitzortung/android/alert/AlertResult.java index 22908b27..6f33fcea 100644 --- a/app/src/main/java/org/blitzortung/android/alert/AlertResult.java +++ b/app/src/main/java/org/blitzortung/android/alert/AlertResult.java @@ -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; @@ -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()); diff --git a/app/src/main/java/org/blitzortung/android/alert/data/AlertSectorRange.java b/app/src/main/java/org/blitzortung/android/alert/data/AlertSectorRange.java index 8e9de1cc..688c5d20 100644 --- a/app/src/main/java/org/blitzortung/android/alert/data/AlertSectorRange.java +++ b/app/src/main/java/org/blitzortung/android/alert/data/AlertSectorRange.java @@ -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; } diff --git a/app/src/main/java/org/blitzortung/android/alert/factory/AlertObjectFactory.java b/app/src/main/java/org/blitzortung/android/alert/factory/AlertObjectFactory.java index 9845a3f1..75bc9d87 100644 --- a/app/src/main/java/org/blitzortung/android/alert/factory/AlertObjectFactory.java +++ b/app/src/main/java/org/blitzortung/android/alert/factory/AlertObjectFactory.java @@ -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); } diff --git a/app/src/main/java/org/blitzortung/android/alert/handler/AlertSectorHandler.java b/app/src/main/java/org/blitzortung/android/alert/handler/AlertSectorHandler.java index 095d7099..49c8a4bd 100644 --- a/app/src/main/java/org/blitzortung/android/alert/handler/AlertSectorHandler.java +++ b/app/src/main/java/org/blitzortung/android/alert/handler/AlertSectorHandler.java @@ -2,7 +2,6 @@ import android.location.Location; -import com.annimon.stream.Optional; import com.annimon.stream.Stream; import org.blitzortung.android.alert.AlertParameters; diff --git a/app/src/main/java/org/blitzortung/android/alert/handler/AlertStatusHandler.java b/app/src/main/java/org/blitzortung/android/alert/handler/AlertStatusHandler.java index 0459b0fe..624416ab 100644 --- a/app/src/main/java/org/blitzortung/android/alert/handler/AlertStatusHandler.java +++ b/app/src/main/java/org/blitzortung/android/alert/handler/AlertStatusHandler.java @@ -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; @@ -46,14 +47,14 @@ public AlertStatus checkStrikes(AlertStatus alertStatus, Collection alertConsumerContainer = new ConsumerContainer() { + @Override + public void addedFirstConsumer() { + Log.d(Main.LOG_TAG, "added first alert consumer"); + } + @Override + public void removedLastConsumer() { + Log.d(Main.LOG_TAG, "removed last alert consumer"); + } + }; + private final Consumer alertEventConsumer = new Consumer() { + @Override + public void accept(AlertEvent event) { + alertConsumerContainer.storeAndBroadcast(event); + } + }; private int period; - private int backgroundPeriod; - - private final Period updatePeriod; - private Parameters lastParameters; - private boolean updateParticipants; - private boolean enabled; - private DataHandler dataHandler; private AlertHandler alertHandler; private boolean alertEnabled; private LocationHandler locationHandler; - - private final IBinder binder = new DataServiceBinder(); - private AlarmManager alarmManager; - private PendingIntent pendingIntent; - - private PowerManager.WakeLock wakeLock; - ConsumerContainer dataConsumerContainer = new ConsumerContainer() { @Override public void addedFirstConsumer() { @@ -84,16 +88,27 @@ public void removedLastConsumer() { configureServiceMode(); } }; - - ConsumerContainer alertConsumerContainer = new ConsumerContainer() { + private PowerManager.WakeLock wakeLock; + private final Consumer dataEventConsumer = new Consumer() { @Override - public void addedFirstConsumer() { - Log.d(Main.LOG_TAG, "added first alert consumer"); - } + public void accept(DataEvent event) { + if (!dataConsumerContainer.isEmpty()) { + dataConsumerContainer.storeAndBroadcast(event); + } - @Override - public void removedLastConsumer() { - Log.d(Main.LOG_TAG, "removed last alert consumer"); + if (alertEnabled) { + alertHandler.getDataEventConsumer().accept(event); + } + + if (event instanceof ClearDataEvent) { + restart(); + } else if (event instanceof ResultEvent) { + ResultEvent resultEvent = (ResultEvent) event; + lastParameters = resultEvent.getParameters(); + configureServiceMode(); + } + + releaseWakeLock(); } }; @@ -135,40 +150,14 @@ public DataHandler getDataHandler() { return dataHandler; } + public void setDataHandler(DataHandler dataHandler) { + this.dataHandler = dataHandler; + } + public AlertHandler getAlertHandler() { return alertHandler; } - private final Consumer dataEventConsumer = new Consumer() { - @Override - public void accept(DataEvent event) { - if (!dataConsumerContainer.isEmpty()) { - dataConsumerContainer.storeAndBroadcast(event); - } - - if (alertEnabled) { - alertHandler.getDataEventConsumer().accept(event); - } - - if (event instanceof ClearDataEvent) { - restart(); - } else if (event instanceof ResultEvent) { - ResultEvent resultEvent = (ResultEvent) event; - lastParameters = resultEvent.getParameters(); - configureServiceMode(); - } - - releaseWakeLock(); - } - }; - - private final Consumer alertEventConsumer = new Consumer() { - @Override - public void accept(AlertEvent event) { - alertConsumerContainer.storeAndBroadcast(event); - } - }; - public void addDataConsumer(Consumer dataConsumer) { dataConsumerContainer.addConsumer(dataConsumer); } @@ -201,13 +190,6 @@ public void updateLocationHandler(SharedPreferences preferences) { locationHandler.update(preferences); } - public class DataServiceBinder extends Binder { - AppService getService() { - Log.d(Main.LOG_TAG, "DataServiceBinder.getService() " + AppService.this); - return AppService.this; - } - } - @Override public void onCreate() { Log.i(Main.LOG_TAG, "AppService.onCreate()"); @@ -334,10 +316,6 @@ public boolean isEnabled() { return enabled; } - public void setDataHandler(DataHandler dataHandler) { - this.dataHandler = dataHandler; - } - @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String keyString) { onSharedPreferenceChanged(sharedPreferences, PreferenceKey.fromString(keyString)); @@ -439,4 +417,11 @@ private PackageInfo getPackageInfo() { throw new IllegalStateException(e); } } + + public class DataServiceBinder extends Binder { + AppService getService() { + Log.d(Main.LOG_TAG, "DataServiceBinder.getService() " + AppService.this); + return AppService.this; + } + } } diff --git a/app/src/main/java/org/blitzortung/android/app/BootReceiver.java b/app/src/main/java/org/blitzortung/android/app/BootReceiver.java index 818ce3d2..dd524325 100644 --- a/app/src/main/java/org/blitzortung/android/app/BootReceiver.java +++ b/app/src/main/java/org/blitzortung/android/app/BootReceiver.java @@ -4,7 +4,7 @@ import android.content.Context; import android.content.Intent; -public class BootReceiver extends BroadcastReceiver{ +public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent bootIntent = new Intent(context, AppService.class); diff --git a/app/src/main/java/org/blitzortung/android/app/Main.java b/app/src/main/java/org/blitzortung/android/app/Main.java index 10cfc23a..cbe3b216 100644 --- a/app/src/main/java/org/blitzortung/android/app/Main.java +++ b/app/src/main/java/org/blitzortung/android/app/Main.java @@ -77,21 +77,13 @@ public class Main extends OwnMapActivity implements OnSharedPreferenceChangeList public static final String LOG_TAG = "BO_ANDROID"; public static final int REQUEST_GPS = 1; - + private final Set androidIdsForExtendedFunctionality = new HashSet<>(Arrays.asList("e72d101ce1bcdee3", "6d1b9a3da993af2d")); protected StatusComponent statusComponent; - - private FadeOverlay fadeOverlay; - protected StrikesOverlay strikesOverlay; - + private FadeOverlay fadeOverlay; private ParticipantsOverlay participantsOverlay; - private OwnLocationOverlay ownLocationOverlay; - private boolean clearData; - - private final Set androidIdsForExtendedFunctionality = new HashSet<>(Arrays.asList("e72d101ce1bcdee3", "6d1b9a3da993af2d")); - private ButtonColumnHandler buttonColumnHandler; private HistoryController historyController; @@ -103,6 +95,74 @@ public class Main extends OwnMapActivity implements OnSharedPreferenceChangeList private Optional currentResult; private HistogramView histogramView; private VersionComponent versionComponent; + private Consumer dataEventConsumer = new Consumer() { + @Override + public void accept(DataEvent event) { + if (event instanceof RequestStartedEvent) { + buttonColumnHandler.lockButtonColumn(); + statusComponent.startProgress(); + } else if (event instanceof ResultEvent) { + ResultEvent result = (ResultEvent) event; + + if (result.hasFailed()) { + statusComponent.indicateError(true); + } else { + statusComponent.indicateError(false); + + if (result.getParameters().getIntervalDuration() != appService.getDataHandler().getIntervalDuration()) { + reloadData(); + } + + currentResult = Optional.of(result); + + Log.d(Main.LOG_TAG, "Main.onDataUpdate() " + result); + + Parameters resultParameters = result.getParameters(); + + clearDataIfRequested(); + + if (result.containsStrikes()) { + strikesOverlay.setParameters(resultParameters); + strikesOverlay.setRasterParameters(result.getRasterParameters()); + strikesOverlay.setReferenceTime(result.getReferenceTime()); + + if (result.isIncrementalData()) { + strikesOverlay.expireStrikes(); + } else { + strikesOverlay.clear(); + } + strikesOverlay.addStrikes(result.getStrikes()); + + alertView.setColorHandler(strikesOverlay.getColorHandler(), strikesOverlay.getParameters().getIntervalDuration()); + + strikesOverlay.refresh(); + legendView.requestLayout(); + } + + if (!result.containsRealtimeData()) { + setHistoricStatusString(); + } + + if (participantsOverlay != null && result.containsParticipants()) { + participantsOverlay.setParticipants(result.getStations()); + participantsOverlay.refresh(); + } + } + + statusComponent.stopProgress(); + + buttonColumnHandler.unlockButtonColumn(); + + getMapView().invalidate(); + legendView.invalidate(); + } else if (event instanceof ClearDataEvent) { + clearData(); + } else if (event instanceof StatusEvent) { + StatusEvent statusEvent = (StatusEvent) event; + setStatusString(statusEvent.getStatus()); + } + } + }; @Override public void onCreate(Bundle savedInstanceState) { @@ -414,75 +474,6 @@ protected boolean isRouteDisplayed() { return false; } - private Consumer dataEventConsumer = new Consumer() { - @Override - public void accept(DataEvent event) { - if (event instanceof RequestStartedEvent) { - buttonColumnHandler.lockButtonColumn(); - statusComponent.startProgress(); - } else if (event instanceof ResultEvent) { - ResultEvent result = (ResultEvent) event; - - if (result.hasFailed()) { - statusComponent.indicateError(true); - } else { - statusComponent.indicateError(false); - - if (result.getParameters().getIntervalDuration() != appService.getDataHandler().getIntervalDuration()) { - reloadData(); - } - - currentResult = Optional.of(result); - - Log.d(Main.LOG_TAG, "Main.onDataUpdate() " + result); - - Parameters resultParameters = result.getParameters(); - - clearDataIfRequested(); - - if (result.containsStrikes()) { - strikesOverlay.setParameters(resultParameters); - strikesOverlay.setRasterParameters(result.getRasterParameters()); - strikesOverlay.setReferenceTime(result.getReferenceTime()); - - if (result.isIncrementalData()) { - strikesOverlay.expireStrikes(); - } else { - strikesOverlay.clear(); - } - strikesOverlay.addStrikes(result.getStrikes()); - - alertView.setColorHandler(strikesOverlay.getColorHandler(), strikesOverlay.getParameters().getIntervalDuration()); - - strikesOverlay.refresh(); - legendView.requestLayout(); - } - - if (!result.containsRealtimeData()) { - setHistoricStatusString(); - } - - if (participantsOverlay != null && result.containsParticipants()) { - participantsOverlay.setParticipants(result.getStations()); - participantsOverlay.refresh(); - } - } - - statusComponent.stopProgress(); - - buttonColumnHandler.unlockButtonColumn(); - - getMapView().invalidate(); - legendView.invalidate(); - } else if (event instanceof ClearDataEvent) { - clearData(); - } else if (event instanceof StatusEvent) { - StatusEvent statusEvent = (StatusEvent) event; - setStatusString(statusEvent.getStatus()); - } - } - }; - public Consumer getDataEventConsumer() { return dataEventConsumer; } diff --git a/app/src/main/java/org/blitzortung/android/app/Preferences.java b/app/src/main/java/org/blitzortung/android/app/Preferences.java index 507bf486..e44a399a 100644 --- a/app/src/main/java/org/blitzortung/android/app/Preferences.java +++ b/app/src/main/java/org/blitzortung/android/app/Preferences.java @@ -5,9 +5,10 @@ import android.os.Bundle; import android.preference.PreferenceActivity; import android.preference.PreferenceManager; -import org.blitzortung.android.location.LocationHandler; + import org.blitzortung.android.app.view.PreferenceKey; import org.blitzortung.android.data.provider.DataProviderType; +import org.blitzortung.android.location.LocationHandler; public class Preferences extends PreferenceActivity implements OnSharedPreferenceChangeListener { diff --git a/app/src/main/java/org/blitzortung/android/app/WidgetProvider.java b/app/src/main/java/org/blitzortung/android/app/WidgetProvider.java index 75450b68..bf06e7e2 100644 --- a/app/src/main/java/org/blitzortung/android/app/WidgetProvider.java +++ b/app/src/main/java/org/blitzortung/android/app/WidgetProvider.java @@ -5,6 +5,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.widget.RemoteViews; + import org.blitzortung.android.app.view.AlertView; public class WidgetProvider extends AppWidgetProvider { @@ -12,8 +13,7 @@ public class WidgetProvider extends AppWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = appWidgetIds.length; - for (int i=0; i alertEventConsumer = new Consumer() { - @Override - public void accept(AlertEvent event) { - if (event instanceof AlertResultEvent) { - AlertResultEvent alertResultEvent = (AlertResultEvent) event; - - alertStatus = alertResultEvent.getAlertStatus(); - } else { - alertStatus = null; - } - invalidate(); - } - }; - public Consumer getAlertEventConsumer() { return alertEventConsumer; } - private Consumer locationEventConsumer = locationEvent -> { - final Location location = locationEvent.getLocation(); - final int visibility = location != null ? View.VISIBLE : View.INVISIBLE; - setVisibility(visibility); - invalidate(); - }; - public Consumer getLocationEventConsumer() { return locationEventConsumer; } diff --git a/app/src/main/java/org/blitzortung/android/app/view/HistogramView.java b/app/src/main/java/org/blitzortung/android/app/view/HistogramView.java index 4682ea2f..51c71e7a 100644 --- a/app/src/main/java/org/blitzortung/android/app/view/HistogramView.java +++ b/app/src/main/java/org/blitzortung/android/app/view/HistogramView.java @@ -18,22 +18,22 @@ public class HistogramView extends View { - private float width; - private float height; - final private float padding; final private float textSize; - final private Paint backgroundPaint; final private Paint foregroundPaint; final private Paint textPaint; - - private StrikesOverlay strikesOverlay; - - private int[] histogram; - private final int defaultForegroundColor; private final RectF backgroundRect; + private float width; + private float height; + private StrikesOverlay strikesOverlay; + private int[] histogram; + private final Consumer dataEventConsumer = event -> { + if (event instanceof ResultEvent) { + updateHistogram((ResultEvent) event); + } + }; @SuppressWarnings("unused") public HistogramView(Context context, AttributeSet attrs) { @@ -126,12 +126,6 @@ public void setStrikesOverlay(StrikesOverlay strikesOverlay) { this.strikesOverlay = strikesOverlay; } - private final Consumer dataEventConsumer = event -> { - if (event instanceof ResultEvent) { - updateHistogram((ResultEvent) event); - } - }; - public Consumer getDataConsumer() { return dataEventConsumer; } diff --git a/app/src/main/java/org/blitzortung/android/app/view/LegendView.java b/app/src/main/java/org/blitzortung/android/app/view/LegendView.java index d3b12e77..cdcd5fbe 100644 --- a/app/src/main/java/org/blitzortung/android/app/view/LegendView.java +++ b/app/src/main/java/org/blitzortung/android/app/view/LegendView.java @@ -8,11 +8,8 @@ import android.util.AttributeSet; import android.view.View; -import com.annimon.stream.Optional; - import org.blitzortung.android.app.R; import org.blitzortung.android.app.helper.ViewHelper; -import org.blitzortung.android.data.Parameters; import org.blitzortung.android.data.beans.RasterParameters; import org.blitzortung.android.map.overlay.StrikesOverlay; import org.blitzortung.android.map.overlay.color.ColorHandler; @@ -22,24 +19,20 @@ public class LegendView extends View { public static final float REGION_HEIGHT = 1.1f; public static final float RASTER_HEIGHT = 0.8f; public static final float COUNT_THRESHOLD_HEIGHT = 0.8f; - private float width; - private float height; - final private float padding; final private float colorFieldSize; - private float textWidth; - final private Paint textPaint; final private Paint rasterTextPaint; final private Paint regionTextPaint; final private Paint countThresholdTextPaint; final private Paint backgroundPaint; final private Paint foregroundPaint; - - private StrikesOverlay strikesOverlay; - private final RectF backgroundRect; private final RectF legendColorRect; + private float width; + private float height; + private float textWidth; + private StrikesOverlay strikesOverlay; @SuppressWarnings("unused") public LegendView(Context context, AttributeSet attrs) { diff --git a/app/src/main/java/org/blitzortung/android/app/view/PreferenceKey.java b/app/src/main/java/org/blitzortung/android/app/view/PreferenceKey.java index 0c40a0b7..ab9ce23d 100644 --- a/app/src/main/java/org/blitzortung/android/app/view/PreferenceKey.java +++ b/app/src/main/java/org/blitzortung/android/app/view/PreferenceKey.java @@ -29,20 +29,9 @@ public enum PreferenceKey { LOCATION_MODE("location_mode"), LOCATION_LONGITUDE("location_longitude"), LOCATION_LATITUDE("location_latitude"); - - private final String key; - - PreferenceKey(String key) { - this.key = key; - } - - @Override - public String toString() - { - return key; - } private static Map stringToValueMap = new HashMap(); + static { for (PreferenceKey key : PreferenceKey.values()) { String keyString = key.toString(); @@ -53,7 +42,18 @@ public String toString() } } + private final String key; + + PreferenceKey(String key) { + this.key = key; + } + public static PreferenceKey fromString(String string) { return stringToValueMap.get(string); } + + @Override + public String toString() { + return key; + } } diff --git a/app/src/main/java/org/blitzortung/android/app/view/components/StatusComponent.java b/app/src/main/java/org/blitzortung/android/app/view/components/StatusComponent.java index 0962628f..956a4954 100644 --- a/app/src/main/java/org/blitzortung/android/app/view/components/StatusComponent.java +++ b/app/src/main/java/org/blitzortung/android/app/view/components/StatusComponent.java @@ -8,24 +8,29 @@ import com.annimon.stream.function.Consumer; -import org.blitzortung.android.alert.AlertLabelHandler; -import org.blitzortung.android.alert.event.AlertResultEvent; import org.blitzortung.android.alert.AlertLabel; +import org.blitzortung.android.alert.AlertLabelHandler; import org.blitzortung.android.alert.event.AlertEvent; +import org.blitzortung.android.alert.event.AlertResultEvent; import org.blitzortung.android.app.R; public class StatusComponent implements AlertLabel { + private final AlertLabelHandler alertLabelHandler; + private final Consumer alertEventConsumer = new Consumer() { + @Override + public void accept(AlertEvent event) { + alertLabelHandler.apply( + event instanceof AlertResultEvent + ? ((AlertResultEvent) event).getAlertResult() + : null); + } + }; private TextView status; - private TextView warning; - private ProgressBar progressBar; - private ImageView errorIndicator; - private final AlertLabelHandler alertLabelHandler; - public StatusComponent(Activity activity) { status = (TextView) activity.findViewById(R.id.status); @@ -68,16 +73,6 @@ public void setAlarmText(String alarmText) { warning.setText(alarmText); } - private final Consumer alertEventConsumer = new Consumer() { - @Override - public void accept(AlertEvent event) { - alertLabelHandler.apply( - event instanceof AlertResultEvent - ? ((AlertResultEvent) event).getAlertResult() - : null); - } - }; - public Consumer getAlertEventConsumer() { return alertEventConsumer; } diff --git a/app/src/main/java/org/blitzortung/android/data/Coordsys.java b/app/src/main/java/org/blitzortung/android/data/Coordsys.java index 8f8fc025..5efc36fa 100644 --- a/app/src/main/java/org/blitzortung/android/data/Coordsys.java +++ b/app/src/main/java/org/blitzortung/android/data/Coordsys.java @@ -4,8 +4,8 @@ public class Coordsys { - public static GeoPoint toMapCoords(float longitude, float latitude) { - return new GeoPoint((int) (latitude * 1e6), (int) (longitude * 1e6)); - } + public static GeoPoint toMapCoords(float longitude, float latitude) { + return new GeoPoint((int) (latitude * 1e6), (int) (longitude * 1e6)); + } } diff --git a/app/src/main/java/org/blitzortung/android/data/DataHandler.java b/app/src/main/java/org/blitzortung/android/data/DataHandler.java index 5896c4d2..c439ad61 100644 --- a/app/src/main/java/org/blitzortung/android/data/DataHandler.java +++ b/app/src/main/java/org/blitzortung/android/data/DataHandler.java @@ -30,37 +30,27 @@ public class DataHandler implements OnSharedPreferenceChangeListener { - private final Lock lock = new ReentrantLock(); + public static final RequestStartedEvent REQUEST_STARTED_EVENT = new RequestStartedEvent(); + public static final ClearDataEvent CLEAR_DATA_EVENT = new ClearDataEvent(); + public static final Set DEFAULT_DATA_CHANNELS = new HashSet<>(); + + static { + DEFAULT_DATA_CHANNELS.add(DataChannel.STRIKES); + } + private final Lock lock = new ReentrantLock(); private final PackageInfo pInfo; private DataProvider dataProvider; - private String username; private String password; - private Parameters parameters = Parameters.DEFAULT; - private ParametersController parametersController; - private Consumer dataEventConsumer; - private int preferencesRasterBaselength; - private int preferencesRegion; - private DataProviderFactory dataProviderFactory; - - public static final RequestStartedEvent REQUEST_STARTED_EVENT = new RequestStartedEvent(); - public static final ClearDataEvent CLEAR_DATA_EVENT = new ClearDataEvent(); - private PowerManager.WakeLock wakeLock; - public static final Set DEFAULT_DATA_CHANNELS = new HashSet<>(); - - static { - DEFAULT_DATA_CHANNELS.add(DataChannel.STRIKES); - } - public DataHandler(PowerManager.WakeLock wakeLock, SharedPreferences sharedPreferences, PackageInfo pInfo) { this(wakeLock, sharedPreferences, pInfo, new DataProviderFactory()); } @@ -85,89 +75,6 @@ public DataHandler(PowerManager.WakeLock wakeLock, SharedPreferences sharedPrefe updateProviderSpecifics(); } - private class FetchDataTask extends AsyncTask> { - - protected void onProgressUpdate(Integer... progress) { - } - - protected void onPostExecute(Optional result) { - if (result.isPresent()) { - final ResultEvent payload = result.get(); - sendEvent(payload); - } - } - - @Override - protected Optional doInBackground(TaskParameters... taskParametersArray) { - val taskParameters = taskParametersArray[0]; - val parameters = taskParameters.getParameters(); - - if (lock.tryLock()) { - try { - val result = ResultEvent.builder(); - - dataProvider.setUp(); - dataProvider.setCredentials(username, password); - - if (parameters.isRaster()) { - dataProvider.getStrikesGrid(parameters, result); - } else { - dataProvider.getStrikes(parameters, result); - } - - result.parameters(parameters) - .referenceTime(System.currentTimeMillis()); - - if (taskParameters.isUpdateParticipants()) { - result.stations(dataProvider.getStations(parameters.getRegion())); - } - - dataProvider.shutDown(); - - return Optional.of(result.build()); - } catch (RuntimeException e) { - e.printStackTrace(); - return Optional.of(ResultEvent.builder().fail(true).build()); - } finally { - lock.unlock(); - } - } - return Optional.empty(); - } - } - - private class FetchBackgroundDataTask extends FetchDataTask { - - private PowerManager.WakeLock wakeLock; - - public FetchBackgroundDataTask(PowerManager.WakeLock wakeLock) { - super(); - this.wakeLock = wakeLock; - } - - @Override - protected void onPostExecute(Optional result) { - super.onPostExecute(result); - if (wakeLock.isHeld()) { - try { - wakeLock.release(); - Log.v(Main.LOG_TAG, "FetchBackgroundDataTask released wakelock " + wakeLock); - } catch (RuntimeException e) { - Log.e(Main.LOG_TAG, "FetchBackgroundDataTask release wakelock failed ", e); - } - } else { - Log.e(Main.LOG_TAG, "FetchBackgroundDataTask release wakelock not held "); - } - } - - @Override - protected Optional doInBackground(TaskParameters... params) { - wakeLock.acquire(); - Log.v(Main.LOG_TAG, "FetchBackgroundDataTask aquire wakelock " + wakeLock); - return super.doInBackground(params); - } - } - public void updateDatainBackground() { new FetchBackgroundDataTask(wakeLock).execute(TaskParameters.builder().parameters(parameters).updateParticipants(false).build()); } @@ -340,4 +247,87 @@ public Parameters getParameters() { return parameters; } + private class FetchDataTask extends AsyncTask> { + + protected void onProgressUpdate(Integer... progress) { + } + + protected void onPostExecute(Optional result) { + if (result.isPresent()) { + final ResultEvent payload = result.get(); + sendEvent(payload); + } + } + + @Override + protected Optional doInBackground(TaskParameters... taskParametersArray) { + val taskParameters = taskParametersArray[0]; + val parameters = taskParameters.getParameters(); + + if (lock.tryLock()) { + try { + val result = ResultEvent.builder(); + + dataProvider.setUp(); + dataProvider.setCredentials(username, password); + + if (parameters.isRaster()) { + dataProvider.getStrikesGrid(parameters, result); + } else { + dataProvider.getStrikes(parameters, result); + } + + result.parameters(parameters) + .referenceTime(System.currentTimeMillis()); + + if (taskParameters.isUpdateParticipants()) { + result.stations(dataProvider.getStations(parameters.getRegion())); + } + + dataProvider.shutDown(); + + return Optional.of(result.build()); + } catch (RuntimeException e) { + e.printStackTrace(); + return Optional.of(ResultEvent.builder().fail(true).build()); + } finally { + lock.unlock(); + } + } + return Optional.empty(); + } + } + + private class FetchBackgroundDataTask extends FetchDataTask { + + private PowerManager.WakeLock wakeLock; + + public FetchBackgroundDataTask(PowerManager.WakeLock wakeLock) { + super(); + this.wakeLock = wakeLock; + } + + @Override + protected void onPostExecute(Optional result) { + super.onPostExecute(result); + if (wakeLock.isHeld()) { + try { + wakeLock.release(); + Log.v(Main.LOG_TAG, "FetchBackgroundDataTask released wakelock " + wakeLock); + } catch (RuntimeException e) { + Log.e(Main.LOG_TAG, "FetchBackgroundDataTask release wakelock failed ", e); + } + } else { + Log.e(Main.LOG_TAG, "FetchBackgroundDataTask release wakelock not held "); + } + } + + @Override + protected Optional doInBackground(TaskParameters... params) { + wakeLock.acquire(); + Log.v(Main.LOG_TAG, "FetchBackgroundDataTask aquire wakelock " + wakeLock); + return super.doInBackground(params); + } + } + } diff --git a/app/src/main/java/org/blitzortung/android/data/beans/DefaultStrike.java b/app/src/main/java/org/blitzortung/android/data/beans/DefaultStrike.java index 2c08d9a3..68a2e34f 100644 --- a/app/src/main/java/org/blitzortung/android/data/beans/DefaultStrike.java +++ b/app/src/main/java/org/blitzortung/android/data/beans/DefaultStrike.java @@ -7,7 +7,7 @@ import lombok.Value; @Value -@EqualsAndHashCode(callSuper=true) +@EqualsAndHashCode(callSuper = true) public class DefaultStrike extends StrikeAbstract implements Serializable { private static final long serialVersionUID = 4201042078597105622L; diff --git a/app/src/main/java/org/blitzortung/android/data/beans/RasterElement.java b/app/src/main/java/org/blitzortung/android/data/beans/RasterElement.java index cf42f4dd..70da3141 100644 --- a/app/src/main/java/org/blitzortung/android/data/beans/RasterElement.java +++ b/app/src/main/java/org/blitzortung/android/data/beans/RasterElement.java @@ -7,7 +7,7 @@ import lombok.Value; @Value -@EqualsAndHashCode(callSuper=true) +@EqualsAndHashCode(callSuper = true) public class RasterElement extends StrikeAbstract implements Serializable { private static final long serialVersionUID = 6765788323616893614L; diff --git a/app/src/main/java/org/blitzortung/android/data/beans/Station.java b/app/src/main/java/org/blitzortung/android/data/beans/Station.java index 984855ab..b975d920 100644 --- a/app/src/main/java/org/blitzortung/android/data/beans/Station.java +++ b/app/src/main/java/org/blitzortung/android/data/beans/Station.java @@ -9,18 +9,10 @@ @EqualsAndHashCode public class Station { - public enum State { - ON, DELAYED, OFF - } - public static final long OFFLINE_SINCE_NOT_SET = -1; - private final String name; - private final float longitude; - private final float latitude; - private final long offlineSince; public State getState() { @@ -40,4 +32,8 @@ public State getState() { } } } + + public enum State { + ON, DELAYED, OFF + } } diff --git a/app/src/main/java/org/blitzortung/android/data/provider/DataBuilder.java b/app/src/main/java/org/blitzortung/android/data/provider/DataBuilder.java index 51dcd41c..b2844968 100644 --- a/app/src/main/java/org/blitzortung/android/data/provider/DataBuilder.java +++ b/app/src/main/java/org/blitzortung/android/data/provider/DataBuilder.java @@ -69,7 +69,7 @@ public Station createStation(JSONArray jsonArray) { if (jsonArray.length() >= 6) { String offlineSinceString = jsonArray.getString(5); - stationBuilder.offlineSince( offlineSinceString.length() > 0 + stationBuilder.offlineSince(offlineSinceString.length() > 0 ? TimeFormat.parseTimeWithMilliseconds(offlineSinceString) : Station.OFFLINE_SINCE_NOT_SET); } else { diff --git a/app/src/main/java/org/blitzortung/android/data/provider/DataProvider.java b/app/src/main/java/org/blitzortung/android/data/provider/DataProvider.java index 5cbbfe27..faaebbc9 100644 --- a/app/src/main/java/org/blitzortung/android/data/provider/DataProvider.java +++ b/app/src/main/java/org/blitzortung/android/data/provider/DataProvider.java @@ -3,9 +3,7 @@ import android.content.pm.PackageInfo; import org.blitzortung.android.data.Parameters; -import org.blitzortung.android.data.beans.RasterParameters; import org.blitzortung.android.data.beans.Station; -import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.provider.result.ResultEvent; import java.util.List; diff --git a/app/src/main/java/org/blitzortung/android/data/provider/DataProviderFactory.java b/app/src/main/java/org/blitzortung/android/data/provider/DataProviderFactory.java index 66c396cf..8eab8b3b 100644 --- a/app/src/main/java/org/blitzortung/android/data/provider/DataProviderFactory.java +++ b/app/src/main/java/org/blitzortung/android/data/provider/DataProviderFactory.java @@ -1,11 +1,11 @@ package org.blitzortung.android.data.provider; -import org.blitzortung.android.data.provider.standard.JsonRpcDataProvider; import org.blitzortung.android.data.provider.blitzortung.BlitzortungHttpDataProvider; +import org.blitzortung.android.data.provider.standard.JsonRpcDataProvider; public class DataProviderFactory { public DataProvider getDataProviderForType(DataProviderType providerType) { - switch(providerType) { + switch (providerType) { case RPC: return new JsonRpcDataProvider(); diff --git a/app/src/main/java/org/blitzortung/android/data/provider/DataProviderType.java b/app/src/main/java/org/blitzortung/android/data/provider/DataProviderType.java index 7cc5fb29..48228185 100644 --- a/app/src/main/java/org/blitzortung/android/data/provider/DataProviderType.java +++ b/app/src/main/java/org/blitzortung/android/data/provider/DataProviderType.java @@ -1,5 +1,5 @@ package org.blitzortung.android.data.provider; public enum DataProviderType { - HTTP, RPC + HTTP, RPC } \ No newline at end of file diff --git a/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/BlitzortungHttpDataProvider.java b/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/BlitzortungHttpDataProvider.java index 35a985c2..1672cb93 100644 --- a/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/BlitzortungHttpDataProvider.java +++ b/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/BlitzortungHttpDataProvider.java @@ -1,11 +1,11 @@ package org.blitzortung.android.data.provider.blitzortung; import android.util.Log; + import org.blitzortung.android.app.Main; import org.blitzortung.android.data.Parameters; -import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.beans.Station; -import org.blitzortung.android.data.beans.RasterParameters; +import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.provider.DataProvider; import org.blitzortung.android.data.provider.DataProviderType; import org.blitzortung.android.data.provider.result.ResultEvent; @@ -18,7 +18,11 @@ import java.net.PasswordAuthentication; import java.net.URL; import java.net.URLConnection; -import java.util.*; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.TimeZone; import java.util.zip.GZIPInputStream; public class BlitzortungHttpDataProvider extends DataProvider { @@ -27,16 +31,6 @@ public class BlitzortungHttpDataProvider extends DataProvider { private MapBuilder strikeMapBuilder; private MapBuilder stationMapBuilder; - - public enum Type {STRIKES, STATIONS} - - private class MyAuthenticator extends Authenticator { - - public PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password.toCharArray()); - } - } - private long latestTime = 0; public BlitzortungHttpDataProvider() { @@ -211,4 +205,13 @@ public boolean isCapableOfHistoricalData() { return false; } + public enum Type {STRIKES, STATIONS} + + private class MyAuthenticator extends Authenticator { + + public PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password.toCharArray()); + } + } + } diff --git a/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/IntervalTimer.java b/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/IntervalTimer.java index 9552b303..c618567e 100644 --- a/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/IntervalTimer.java +++ b/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/IntervalTimer.java @@ -6,24 +6,20 @@ public class IntervalTimer { private long currentTime; private long endTime; - public IntervalTimer(long intervalLength) - { + public IntervalTimer(long intervalLength) { this.intervalLength = intervalLength; } - public long roundTime(long time) - { + public long roundTime(long time) { return time / intervalLength * intervalLength; } - public void startInterval(long startTime) - { + public void startInterval(long startTime) { currentTime = roundTime(startTime); endTime = roundTime(System.currentTimeMillis()); } - public boolean hasNext() - { + public boolean hasNext() { return currentTime <= endTime; } diff --git a/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/MapBuilder.java b/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/MapBuilder.java index d9cbe310..63597894 100644 --- a/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/MapBuilder.java +++ b/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/MapBuilder.java @@ -1,6 +1,7 @@ package org.blitzortung.android.data.provider.blitzortung; import android.text.Html; + import org.blitzortung.android.data.provider.blitzortung.generic.Consumer; import org.blitzortung.android.data.provider.blitzortung.generic.LineSplitter; diff --git a/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactory.java b/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactory.java index c7e039f8..7968ed00 100644 --- a/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactory.java +++ b/app/src/main/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactory.java @@ -1,8 +1,8 @@ package org.blitzortung.android.data.provider.blitzortung; import org.blitzortung.android.data.beans.DefaultStrike; -import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.beans.Station; +import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.provider.blitzortung.generic.Consumer; import org.blitzortung.android.data.provider.blitzortung.generic.LineSplitter; import org.blitzortung.android.util.TimeFormat; diff --git a/app/src/main/java/org/blitzortung/android/data/provider/result/RequestStartedEvent.java b/app/src/main/java/org/blitzortung/android/data/provider/result/RequestStartedEvent.java index 1fe2f89b..205be24f 100644 --- a/app/src/main/java/org/blitzortung/android/data/provider/result/RequestStartedEvent.java +++ b/app/src/main/java/org/blitzortung/android/data/provider/result/RequestStartedEvent.java @@ -1,4 +1,4 @@ package org.blitzortung.android.data.provider.result; -public class RequestStartedEvent implements DataEvent { +public class RequestStartedEvent implements DataEvent { } diff --git a/app/src/main/java/org/blitzortung/android/data/provider/result/ResultEvent.java b/app/src/main/java/org/blitzortung/android/data/provider/result/ResultEvent.java index 37c13ab3..fe8c0141 100644 --- a/app/src/main/java/org/blitzortung/android/data/provider/result/ResultEvent.java +++ b/app/src/main/java/org/blitzortung/android/data/provider/result/ResultEvent.java @@ -5,12 +5,10 @@ import org.blitzortung.android.data.beans.Station; import org.blitzortung.android.data.beans.StrikeAbstract; -import java.util.ArrayList; import java.util.List; import lombok.Builder; import lombok.EqualsAndHashCode; -import lombok.ToString; import lombok.Value; @Value diff --git a/app/src/main/java/org/blitzortung/android/data/provider/standard/JsonRpcDataProvider.java b/app/src/main/java/org/blitzortung/android/data/provider/standard/JsonRpcDataProvider.java index 5d35dc97..f2f36694 100644 --- a/app/src/main/java/org/blitzortung/android/data/provider/standard/JsonRpcDataProvider.java +++ b/app/src/main/java/org/blitzortung/android/data/provider/standard/JsonRpcDataProvider.java @@ -25,29 +25,27 @@ public class JsonRpcDataProvider extends DataProvider { private static final SimpleDateFormat DATE_TIME_FORMATTER = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); + static private final String[] SERVERS = new String[]{"http://bo-service.tryb.de:7080/", "http://bo-service.tryb.de/"}; + static private int CURRENT_SERVER = 0; static { TimeZone tz = TimeZone.getTimeZone("UTC"); DATE_TIME_FORMATTER.setTimeZone(tz); } - static private final String[] SERVERS = new String[]{"http://bo-service.tryb.de:7080/", "http://bo-service.tryb.de/"}; - - static private int CURRENT_SERVER = 0; - - + private final DataBuilder dataBuilder; private JsonRpcClient client; - private int nextId = 0; - private boolean incrementalResult; - private final DataBuilder dataBuilder; - public JsonRpcDataProvider() { dataBuilder = new DataBuilder(); } + private static String getServer() { + return SERVERS[CURRENT_SERVER]; + } + @Override public void getStrikes(Parameters parameters, ResultEvent.ResultEventBuilder result) { final int intervalDuration = parameters.getIntervalDuration(); @@ -140,7 +138,6 @@ public void shutDown() { client = null; } - @Override public void reset() { nextId = 0; @@ -198,10 +195,6 @@ private void addStrikesHistogram(JSONObject response, ResultEvent.ResultEventBui } } - private static String getServer() { - return SERVERS[CURRENT_SERVER]; - } - private void skipServer() { CURRENT_SERVER = (CURRENT_SERVER + 1) % SERVERS.length; } diff --git a/app/src/main/java/org/blitzortung/android/dialogs/AlertDialog.java b/app/src/main/java/org/blitzortung/android/dialogs/AlertDialog.java index b0d9846b..7a8160ba 100644 --- a/app/src/main/java/org/blitzortung/android/dialogs/AlertDialog.java +++ b/app/src/main/java/org/blitzortung/android/dialogs/AlertDialog.java @@ -12,9 +12,9 @@ public class AlertDialog extends android.app.AlertDialog { private final ColorHandler colorHandler; - private AlertView alertView; private final AppService service; int intervalDuration; + private AlertView alertView; public AlertDialog(Context context, AppService service, ColorHandler colorHandler) { super(context); diff --git a/app/src/main/java/org/blitzortung/android/dialogs/AlertDialogColorHandler.java b/app/src/main/java/org/blitzortung/android/dialogs/AlertDialogColorHandler.java index afc2acf3..73917749 100644 --- a/app/src/main/java/org/blitzortung/android/dialogs/AlertDialogColorHandler.java +++ b/app/src/main/java/org/blitzortung/android/dialogs/AlertDialogColorHandler.java @@ -1,16 +1,17 @@ package org.blitzortung.android.dialogs; import android.content.SharedPreferences; + import org.blitzortung.android.map.overlay.color.ColorTarget; import org.blitzortung.android.map.overlay.color.StrikeColorHandler; public class AlertDialogColorHandler extends StrikeColorHandler { public AlertDialogColorHandler(SharedPreferences preferences) { - super(preferences); - } + super(preferences); + } - public int getTextColor(ColorTarget target) { + public int getTextColor(ColorTarget target) { switch (target) { default: case SATELLITE: diff --git a/app/src/main/java/org/blitzortung/android/jsonrpc/HttpServiceClient.java b/app/src/main/java/org/blitzortung/android/jsonrpc/HttpServiceClient.java index c391c0fd..b18ba3b7 100644 --- a/app/src/main/java/org/blitzortung/android/jsonrpc/HttpServiceClient.java +++ b/app/src/main/java/org/blitzortung/android/jsonrpc/HttpServiceClient.java @@ -11,13 +11,10 @@ public class HttpServiceClient { - private int socketTimeout = 0; - - private int connectionTimeout = 0; - private final URL url; - private final String userAgentString; + private int socketTimeout = 0; + private int connectionTimeout = 0; HttpServiceClient(String uriString, String agentSuffix) { try { diff --git a/app/src/main/java/org/blitzortung/android/jsonrpc/JsonRpcClient.java b/app/src/main/java/org/blitzortung/android/jsonrpc/JsonRpcClient.java index 8167ff9b..64063634 100644 --- a/app/src/main/java/org/blitzortung/android/jsonrpc/JsonRpcClient.java +++ b/app/src/main/java/org/blitzortung/android/jsonrpc/JsonRpcClient.java @@ -10,6 +10,10 @@ public class JsonRpcClient extends HttpServiceClient { private int lastNumberOfTransferredBytes; + public JsonRpcClient(String uri, String agentSuffix) { + super(uri, agentSuffix); + } + // VisibleForTesting protected JSONArray buildParameters(Object[] parameters) { JSONArray parameterArray = new JSONArray(); @@ -33,10 +37,6 @@ protected String buildRequest(String methodName, Object[] parameters) { return requestObject.toString(); } - public JsonRpcClient(String uri, String agentSuffix) { - super(uri, agentSuffix); - } - public JSONObject call(String methodName, Object... parameters) { String response = doRequest(buildRequest(methodName, parameters)); diff --git a/app/src/main/java/org/blitzortung/android/jsonrpc/JsonRpcException.java b/app/src/main/java/org/blitzortung/android/jsonrpc/JsonRpcException.java index 3c01a351..cec17574 100644 --- a/app/src/main/java/org/blitzortung/android/jsonrpc/JsonRpcException.java +++ b/app/src/main/java/org/blitzortung/android/jsonrpc/JsonRpcException.java @@ -3,13 +3,13 @@ public class JsonRpcException extends RuntimeException { - private static final long serialVersionUID = -8108432807261988215L; + private static final long serialVersionUID = -8108432807261988215L; - public JsonRpcException(String msg, Exception e) { - super(msg, e); - } + public JsonRpcException(String msg, Exception e) { + super(msg, e); + } - public JsonRpcException(String msg) { - super(msg); - } + public JsonRpcException(String msg) { + super(msg); + } } diff --git a/app/src/main/java/org/blitzortung/android/location/LocationEvent.java b/app/src/main/java/org/blitzortung/android/location/LocationEvent.java index ed102822..c9b80dee 100644 --- a/app/src/main/java/org/blitzortung/android/location/LocationEvent.java +++ b/app/src/main/java/org/blitzortung/android/location/LocationEvent.java @@ -1,6 +1,7 @@ package org.blitzortung.android.location; import android.location.Location; + import org.blitzortung.android.protocol.Event; import lombok.Value; diff --git a/app/src/main/java/org/blitzortung/android/location/LocationHandler.java b/app/src/main/java/org/blitzortung/android/location/LocationHandler.java index 5e4d0cc5..0b0b3169 100644 --- a/app/src/main/java/org/blitzortung/android/location/LocationHandler.java +++ b/app/src/main/java/org/blitzortung/android/location/LocationHandler.java @@ -26,41 +26,10 @@ public class LocationHandler implements SharedPreferences.OnSharedPreferenceChangeListener, android.location.LocationListener, GpsStatus.Listener { private final Context context; + private final LocationManager locationManager; + private final Location location; private boolean backgroundMode = true; - - public enum Provider { - NETWORK(LocationManager.NETWORK_PROVIDER), - GPS(LocationManager.GPS_PROVIDER), - PASSIVE(LocationManager.PASSIVE_PROVIDER), - MANUAL("manual"); - - private String type; - - Provider(String type) { - this.type = type; - } - - public String getType() { - return type; - } - - private static Map stringToValueMap = new HashMap(); - - static { - for (Provider key : Provider.values()) { - String keyString = key.getType(); - if (stringToValueMap.containsKey(keyString)) { - throw new IllegalStateException(String.format("key value '%s' already defined", keyString)); - } - stringToValueMap.put(keyString, key); - } - } - - public static Provider fromString(String string) { - return stringToValueMap.get(string); - } - } - + private Provider provider; private ConsumerContainer consumerContainer = new ConsumerContainer() { @Override public void addedFirstConsumer() { @@ -75,12 +44,6 @@ public void removedLastConsumer() { } }; - private final LocationManager locationManager; - - private Provider provider; - - private final Location location; - public LocationHandler(Context context, SharedPreferences sharedPreferences) { this.context = context; locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); @@ -283,4 +246,37 @@ public void update(SharedPreferences preferences) { onSharedPreferenceChanged(preferences, PreferenceKey.LOCATION_MODE); } + public enum Provider { + NETWORK(LocationManager.NETWORK_PROVIDER), + GPS(LocationManager.GPS_PROVIDER), + PASSIVE(LocationManager.PASSIVE_PROVIDER), + MANUAL("manual"); + + private static Map stringToValueMap = new HashMap(); + + static { + for (Provider key : Provider.values()) { + String keyString = key.getType(); + if (stringToValueMap.containsKey(keyString)) { + throw new IllegalStateException(String.format("key value '%s' already defined", keyString)); + } + stringToValueMap.put(keyString, key); + } + } + + private String type; + + Provider(String type) { + this.type = type; + } + + public static Provider fromString(String string) { + return stringToValueMap.get(string); + } + + public String getType() { + return type; + } + } + } diff --git a/app/src/main/java/org/blitzortung/android/map/OwnMapActivity.java b/app/src/main/java/org/blitzortung/android/map/OwnMapActivity.java index 79ebb8e4..b9eb6ad9 100644 --- a/app/src/main/java/org/blitzortung/android/map/OwnMapActivity.java +++ b/app/src/main/java/org/blitzortung/android/map/OwnMapActivity.java @@ -1,8 +1,10 @@ package org.blitzortung.android.map; import android.util.Log; + import com.google.android.maps.MapActivity; import com.google.android.maps.Overlay; + import org.blitzortung.android.app.Main; import org.blitzortung.android.map.overlay.LayerOverlay; @@ -12,18 +14,17 @@ public abstract class OwnMapActivity extends MapActivity { + List overlays = new ArrayList<>(); private OwnMapView mapView; - List overlays = new ArrayList<>(); + public OwnMapView getMapView() { + return mapView; + } public void setMapView(OwnMapView mapView) { this.mapView = mapView; } - public OwnMapView getMapView() { - return mapView; - } - public void addOverlay(Overlay overlay) { overlays.add(overlay); } diff --git a/app/src/main/java/org/blitzortung/android/map/OwnMapView.java b/app/src/main/java/org/blitzortung/android/map/OwnMapView.java index 3724e79e..702b7ba6 100644 --- a/app/src/main/java/org/blitzortung/android/map/OwnMapView.java +++ b/app/src/main/java/org/blitzortung/android/map/OwnMapView.java @@ -3,14 +3,14 @@ import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; -import android.util.Log; import android.view.GestureDetector; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; + import com.google.android.maps.MapView; import com.google.android.maps.Projection; -import org.blitzortung.android.app.Main; + import org.blitzortung.android.app.R; import java.util.HashSet; @@ -23,10 +23,7 @@ public class OwnMapView extends MapView { private View popUp = null; private GestureDetector gestureDetector; - - public interface ZoomListener { - void onZoom(int zoomLevel); - } + private float oldPixelSize = -1; public OwnMapView(Context context, AttributeSet attrs) { super(context, attrs); @@ -58,8 +55,6 @@ public boolean onDoubleTap(MotionEvent event) { }); } - private float oldPixelSize = -1; - @Override public void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); @@ -115,4 +110,8 @@ public synchronized View getPopup() { } return popUp; } + + public interface ZoomListener { + void onZoom(int zoomLevel); + } } diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/FadeOverlay.java b/app/src/main/java/org/blitzortung/android/map/overlay/FadeOverlay.java index 692929a6..4d0f4d13 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/FadeOverlay.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/FadeOverlay.java @@ -3,8 +3,10 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; + import com.google.android.maps.MapView; import com.google.android.maps.Overlay; + import org.blitzortung.android.map.overlay.color.ColorHandler; public class FadeOverlay extends Overlay { diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationOverlay.java b/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationOverlay.java index 6b1d02f3..1a4b1645 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationOverlay.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationOverlay.java @@ -11,6 +11,7 @@ import com.annimon.stream.function.Consumer; import com.google.android.maps.ItemizedOverlay; + import org.blitzortung.android.app.R; import org.blitzortung.android.app.view.PreferenceKey; import org.blitzortung.android.location.LocationEvent; @@ -31,6 +32,17 @@ public class OwnLocationOverlay extends ItemizedOverlay private OwnLocationOverlayItem item; private int zoomLevel; + private Consumer locationEventConsumer = new Consumer() { + @Override + public void accept(LocationEvent event) { + Location location = event.getLocation(); + + item = location != null ? new OwnLocationOverlayItem(location, 25000) : item; + + populate(); + refresh(); + } + }; public OwnLocationOverlay(Context context, OwnMapView mapView) { super(DEFAULT_DRAWABLE); @@ -82,18 +94,6 @@ public int size() { return item == null ? 0 : 1; } - private Consumer locationEventConsumer = new Consumer() { - @Override - public void accept(LocationEvent event) { - Location location = event.getLocation(); - - item = location != null ? new OwnLocationOverlayItem(location, 25000) : item; - - populate(); - refresh(); - } - }; - public Consumer getLocationEventConsumer() { return locationEventConsumer; } diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationOverlayItem.java b/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationOverlayItem.java index 7e1ed91f..a5cf5b8b 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationOverlayItem.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationOverlayItem.java @@ -1,21 +1,23 @@ package org.blitzortung.android.map.overlay; import android.location.Location; + import com.google.android.maps.OverlayItem; + import org.blitzortung.android.data.Coordsys; public class OwnLocationOverlayItem extends OverlayItem { - private final float radius; - - public OwnLocationOverlayItem(Location location, float radius) { - super(Coordsys.toMapCoords((float)location.getLongitude(), (float)location.getLatitude()), "", ""); - - this.radius = radius; - } - - public float getRadius() { - return radius; - } + private final float radius; + + public OwnLocationOverlayItem(Location location, float radius) { + super(Coordsys.toMapCoords((float) location.getLongitude(), (float) location.getLatitude()), "", ""); + + this.radius = radius; + } + + public float getRadius() { + return radius; + } } diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationShape.java b/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationShape.java index 3e0cf7ff..73f9c687 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationShape.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/OwnLocationShape.java @@ -6,25 +6,25 @@ public class OwnLocationShape extends Shape { - private final float size; - - public OwnLocationShape(float size) { - this.size = size; - } - - @Override - public void draw(Canvas canvas, Paint paint) { - paint.setStyle(Paint.Style.FILL); - paint.setColor(0x88555555); - canvas.drawCircle(0.0f, 0.0f, size / 1.3f, paint); - - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(size/4); - paint.setColor(0xffffffff); - canvas.drawLine(-size / 2, 0.0f, size / 2, 0.0f, paint); - canvas.drawLine(0.0f, -size / 2, 0.0f, size / 2, paint); - paint.setColor(0xff33aaff); - canvas.drawCircle(0.0f, 0.0f, size / 1.3f, paint); - } + private final float size; + + public OwnLocationShape(float size) { + this.size = size; + } + + @Override + public void draw(Canvas canvas, Paint paint) { + paint.setStyle(Paint.Style.FILL); + paint.setColor(0x88555555); + canvas.drawCircle(0.0f, 0.0f, size / 1.3f, paint); + + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeWidth(size / 4); + paint.setColor(0xffffffff); + canvas.drawLine(-size / 2, 0.0f, size / 2, 0.0f, paint); + canvas.drawLine(0.0f, -size / 2, 0.0f, size / 2, paint); + paint.setColor(0xff33aaff); + canvas.drawCircle(0.0f, 0.0f, size / 1.3f, paint); + } } diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantOverlayItem.java b/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantOverlayItem.java index 8e38169b..20bcb5e5 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantOverlayItem.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantOverlayItem.java @@ -1,28 +1,29 @@ package org.blitzortung.android.map.overlay; import com.google.android.maps.OverlayItem; + import org.blitzortung.android.data.Coordsys; import org.blitzortung.android.data.beans.Station; import org.blitzortung.android.data.beans.Station.State; public class ParticipantOverlayItem extends OverlayItem { - private final long lastDataTime; - - private final State participantState; + private final long lastDataTime; + + private final State participantState; public ParticipantOverlayItem(Station station) { - super(Coordsys.toMapCoords(station.getLongitude(), station.getLatitude()), station.getName(), ""); + super(Coordsys.toMapCoords(station.getLongitude(), station.getLatitude()), station.getName(), ""); + + lastDataTime = station.getOfflineSince(); + participantState = station.getState(); + } + + public long getLastDataTime() { + return lastDataTime; + } - lastDataTime = station.getOfflineSince(); - participantState = station.getState(); + public State getParticipantState() { + return participantState; } - - public long getLastDataTime() { - return lastDataTime; - } - - public State getParticipantState() { - return participantState; - } } diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantShape.java b/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantShape.java index 69063b2d..14976c65 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantShape.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantShape.java @@ -8,26 +8,26 @@ public class ParticipantShape extends Shape { private final RectF rect; - private int color; - - public ParticipantShape() { + private int color; + + public ParticipantShape() { rect = new RectF(); - color = 0x00000000; - } - - @Override - public void draw(Canvas canvas, Paint paint) { - paint.setColor(color); + color = 0x00000000; + } + + @Override + public void draw(Canvas canvas, Paint paint) { + paint.setColor(color); paint.setAlpha(0xff); paint.setStyle(Paint.Style.FILL); - canvas.drawRect(rect, paint); - } - + canvas.drawRect(rect, paint); + } + public void update(float size, int color) { float halfSize = size / 2f; rect.set(-halfSize, -halfSize, halfSize, halfSize); resize(rect.width(), rect.width()); - + this.color = color; } } diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantsOverlay.java b/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantsOverlay.java index de178f23..f6664ad0 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantsOverlay.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/ParticipantsOverlay.java @@ -4,6 +4,7 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.ShapeDrawable; import android.util.Log; + import org.blitzortung.android.app.Main; import org.blitzortung.android.app.R; import org.blitzortung.android.data.beans.Station; @@ -18,17 +19,15 @@ public class ParticipantsOverlay extends PopupOverlay implements LayerOverlay { - // VisibleForTesting - protected final ArrayList participants; - - private final ParticipantColorHandler colorHandler; - static private final Drawable DefaultDrawable; static { DefaultDrawable = new ShapeDrawable(new ParticipantShape()); } + // VisibleForTesting + protected final ArrayList participants; + private final ParticipantColorHandler colorHandler; private final EnumMap shapes; private final LayerOverlayComponent layerOverlayComponent; diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/PopupOverlay.java b/app/src/main/java/org/blitzortung/android/map/overlay/PopupOverlay.java index ef774d84..aeaf32d1 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/PopupOverlay.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/PopupOverlay.java @@ -4,10 +4,12 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; + import com.google.android.maps.GeoPoint; import com.google.android.maps.ItemizedOverlay; import com.google.android.maps.MapView; import com.google.android.maps.OverlayItem; + import org.blitzortung.android.app.R; import org.blitzortung.android.map.OwnMapActivity; import org.blitzortung.android.map.OwnMapView; @@ -15,6 +17,7 @@ public abstract class PopupOverlay extends ItemizedOverlay { private final OwnMapActivity activity; + boolean popupShown; public PopupOverlay(OwnMapActivity activity, Drawable defaultMarker) { super(defaultMarker); @@ -22,8 +25,6 @@ public PopupOverlay(OwnMapActivity activity, Drawable defaultMarker) { popupShown = false; } - boolean popupShown; - protected void showPopup(GeoPoint location, String text) { OwnMapView map = activity.getMapView(); diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/RasterShape.java b/app/src/main/java/org/blitzortung/android/map/overlay/RasterShape.java index 5e661e4f..c2971b81 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/RasterShape.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/RasterShape.java @@ -18,7 +18,7 @@ public class RasterShape extends Shape { private int textColor; public RasterShape() { - rect = new RectF(); + rect = new RectF(); } @Override diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/StrikeOverlayItem.java b/app/src/main/java/org/blitzortung/android/map/overlay/StrikeOverlayItem.java index 9a25a223..534c74b9 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/StrikeOverlayItem.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/StrikeOverlayItem.java @@ -5,38 +5,36 @@ import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.Shape; import android.location.Location; + import com.google.android.maps.GeoPoint; import com.google.android.maps.OverlayItem; import com.google.android.maps.Projection; + import org.blitzortung.android.data.Coordsys; -import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.beans.RasterParameters; import org.blitzortung.android.data.beans.Strike; +import org.blitzortung.android.data.beans.StrikeAbstract; public class StrikeOverlayItem extends OverlayItem implements Strike { - private final long timestamp; - - private final int multiplicity; - private static final Point center = new Point(); - private static final Point topLeft = new Point(); - private static final Point bottomRight = new Point(); + private final long timestamp; + private final int multiplicity; - public StrikeOverlayItem(StrikeAbstract strike) { - super(Coordsys.toMapCoords(strike.getLongitude(), strike.getLatitude()), "", ""); + public StrikeOverlayItem(StrikeAbstract strike) { + super(Coordsys.toMapCoords(strike.getLongitude(), strike.getLatitude()), "", ""); super.setMarker(new ShapeDrawable()); - timestamp = strike.getTimestamp(); - multiplicity = strike.getMultiplicity(); - } - + timestamp = strike.getTimestamp(); + multiplicity = strike.getMultiplicity(); + } + @Override - public long getTimestamp() { - return timestamp; - } + public long getTimestamp() { + return timestamp; + } @Override public Location getLocation(Location location) { @@ -48,8 +46,8 @@ public Location getLocation(Location location) { @Override public int getMultiplicity() { - return multiplicity; - } + return multiplicity; + } @Override public void setMarker(Drawable drawable) { @@ -57,13 +55,13 @@ public void setMarker(Drawable drawable) { } private ShapeDrawable getDrawable() { - return (ShapeDrawable)getMarker(0); + return (ShapeDrawable) getMarker(0); } - + public Shape getShape() { return getDrawable().getShape(); } - + public void setShape(Shape shape) { getDrawable().setShape(shape); } @@ -74,7 +72,7 @@ public void updateShape(RasterParameters rasterParameters, Projection projection if (shape == null) { shape = new RasterShape(); } - RasterShape rasterShape = (RasterShape)shape; + RasterShape rasterShape = (RasterShape) shape; float lon_delta = rasterParameters.getLongitudeDelta() / 2.0f * 1e6f; float lat_delta = rasterParameters.getLatitudeDelta() / 2.0f * 1e6f; diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/StrikeShape.java b/app/src/main/java/org/blitzortung/android/map/overlay/StrikeShape.java index 4c3f3339..db589680 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/StrikeShape.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/StrikeShape.java @@ -6,20 +6,20 @@ public class StrikeShape extends Shape { - private float size; - private int color; - - public StrikeShape() { - } - - @Override - public void draw(Canvas canvas, Paint paint) { - paint.setColor(color); - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(size/4); - canvas.drawLine(-size / 2, 0.0f, size / 2, 0.0f, paint); - canvas.drawLine(0.0f, -size / 2, 0.0f, size / 2, paint); - } + private float size; + private int color; + + public StrikeShape() { + } + + @Override + public void draw(Canvas canvas, Paint paint) { + paint.setColor(color); + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeWidth(size / 4); + canvas.drawLine(-size / 2, 0.0f, size / 2, 0.0f, paint); + canvas.drawLine(0.0f, -size / 2, 0.0f, size / 2, paint); + } public void update(float size, int color) { this.size = size; diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/StrikesOverlay.java b/app/src/main/java/org/blitzortung/android/map/overlay/StrikesOverlay.java index 6d1300f7..0b667412 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/StrikesOverlay.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/StrikesOverlay.java @@ -33,27 +33,21 @@ public class StrikesOverlay extends PopupOverlay implements LayerOverlay { - // VisibleForTesting - protected final ArrayList strikes; - - private final StrikeColorHandler colorHandler; - - private final LayerOverlayComponent layerOverlayComponent; - - private int zoomLevel; - - private RasterParameters rasterParameters = null; - static private final Drawable DefaultDrawable; - private long referenceTime; - static { StrikeShape shape = new StrikeShape(); shape.update(1, 0); DefaultDrawable = new ShapeDrawable(shape); } + // VisibleForTesting + protected final ArrayList strikes; + private final StrikeColorHandler colorHandler; + private final LayerOverlayComponent layerOverlayComponent; + private int zoomLevel; + private RasterParameters rasterParameters = null; + private long referenceTime; private Parameters parameters = Parameters.DEFAULT; public StrikesOverlay(OwnMapActivity mapActivity, StrikeColorHandler colorHandler) { @@ -184,14 +178,14 @@ public boolean hasRasterParameters() { return rasterParameters != null; } - public void setRasterParameters(RasterParameters rasterParameters) { - this.rasterParameters = rasterParameters; - } - public RasterParameters getRasterParameters() { return rasterParameters; } + public void setRasterParameters(RasterParameters rasterParameters) { + this.rasterParameters = rasterParameters; + } + public boolean hasRealtimeData() { return parameters.isRealtime(); } @@ -225,14 +219,14 @@ public Collection getStrikes() { return strikes; } - public void setReferenceTime(long referenceTime) { - this.referenceTime = referenceTime; - } - public long getReferenceTime() { return referenceTime; } + public void setReferenceTime(long referenceTime) { + this.referenceTime = referenceTime; + } + @Override public String getName() { return layerOverlayComponent.getName(); @@ -258,11 +252,11 @@ public void setVisibility(boolean visible) { layerOverlayComponent.setVisibility(visible); } - public void setParameters(Parameters parameters) { - this.parameters = parameters; - } - public Parameters getParameters() { return parameters; } + + public void setParameters(Parameters parameters) { + this.parameters = parameters; + } } \ No newline at end of file diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorHandler.java b/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorHandler.java index 09297dc7..60eb7c7c 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorHandler.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorHandler.java @@ -2,6 +2,7 @@ import android.content.SharedPreferences; import android.graphics.Color; + import org.blitzortung.android.app.view.PreferenceKey; import org.blitzortung.android.data.TimeIntervalWithOffset; diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorScheme.java b/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorScheme.java index dea139e7..525e1b2a 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorScheme.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorScheme.java @@ -1,18 +1,17 @@ package org.blitzortung.android.map.overlay.color; public enum ColorScheme { - BLITZORTUNG(new int[]{ 0xffe4f9f9, 0xffd8f360, 0xffdfbc51, 0xffe48044, 0xffe73c3b, 0xffb82e2d }), - RAINBOW(new int[]{ 0xffff0000, 0xffff9900, 0xffffff00, 0xff99ff22, 0xff00ffff, 0xff6699ff }), - TEMPERATURE(new int[]{ 0xffff5030, 0xffe78060, 0xffe0b0c0, 0xffc0c0f0, 0xff5080f0, 0xff4060ff}); - + BLITZORTUNG(new int[]{0xffe4f9f9, 0xffd8f360, 0xffdfbc51, 0xffe48044, 0xffe73c3b, 0xffb82e2d}), + RAINBOW(new int[]{0xffff0000, 0xffff9900, 0xffffff00, 0xff99ff22, 0xff00ffff, 0xff6699ff}), + TEMPERATURE(new int[]{0xffff5030, 0xffe78060, 0xffe0b0c0, 0xffc0c0f0, 0xff5080f0, 0xff4060ff}); + private final int[] colors; private ColorScheme(int[] colors) { this.colors = colors; } - public int[] getStrikeColors() - { + public int[] getStrikeColors() { return colors; } } diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorTarget.java b/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorTarget.java index 404bc124..4971ef14 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorTarget.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/color/ColorTarget.java @@ -1,6 +1,6 @@ package org.blitzortung.android.map.overlay.color; public enum ColorTarget { - SATELLITE, - STREETMAP + SATELLITE, + STREETMAP } diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/color/ParticipantColorHandler.java b/app/src/main/java/org/blitzortung/android/map/overlay/color/ParticipantColorHandler.java index 9e3aaac3..3e812b3a 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/color/ParticipantColorHandler.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/color/ParticipantColorHandler.java @@ -3,24 +3,24 @@ import android.content.SharedPreferences; public class ParticipantColorHandler extends ColorHandler { - - private final int[] satelliteViewColors = {0xff88ff22, 0xffff9900, 0xffff0000}; - - private final int[] mapColors = {0xff448811, 0xff884400, 0xff880000}; - public ParticipantColorHandler(SharedPreferences preferences) { - super(preferences); - } - - @Override - public int[] getColors(ColorTarget target) { - switch(target) { - case SATELLITE: - return satelliteViewColors; + private final int[] satelliteViewColors = {0xff88ff22, 0xffff9900, 0xffff0000}; - case STREETMAP: - return mapColors; - } - throw new IllegalStateException("Unhandled color target " + target); - } + private final int[] mapColors = {0xff448811, 0xff884400, 0xff880000}; + + public ParticipantColorHandler(SharedPreferences preferences) { + super(preferences); + } + + @Override + public int[] getColors(ColorTarget target) { + switch (target) { + case SATELLITE: + return satelliteViewColors; + + case STREETMAP: + return mapColors; + } + throw new IllegalStateException("Unhandled color target " + target); + } } diff --git a/app/src/main/java/org/blitzortung/android/map/overlay/color/StrikeColorHandler.java b/app/src/main/java/org/blitzortung/android/map/overlay/color/StrikeColorHandler.java index bf96830a..86128125 100644 --- a/app/src/main/java/org/blitzortung/android/map/overlay/color/StrikeColorHandler.java +++ b/app/src/main/java/org/blitzortung/android/map/overlay/color/StrikeColorHandler.java @@ -4,31 +4,31 @@ public class StrikeColorHandler extends ColorHandler { - public StrikeColorHandler(SharedPreferences preferences) { - super(preferences); - } + public StrikeColorHandler(SharedPreferences preferences) { + super(preferences); + } - @Override - public int[] getColors(ColorTarget target) { - switch(target) { - case SATELLITE: - return getColorScheme().getStrikeColors(); + @Override + public int[] getColors(ColorTarget target) { + switch (target) { + case SATELLITE: + return getColorScheme().getStrikeColors(); - case STREETMAP: - return modifyBrightness(getColorScheme().getStrikeColors(), 0.8f); - } - throw new IllegalStateException("Unhandled color target " + target); - } - - @Override - public int getTextColor(ColorTarget target) { - switch(target) { - case SATELLITE: - return 0xff000000; + case STREETMAP: + return modifyBrightness(getColorScheme().getStrikeColors(), 0.8f); + } + throw new IllegalStateException("Unhandled color target " + target); + } - case STREETMAP: - return 0xffffffff; - } - throw new IllegalStateException("Unhandled color target " + target); - } + @Override + public int getTextColor(ColorTarget target) { + switch (target) { + case SATELLITE: + return 0xff000000; + + case STREETMAP: + return 0xffffffff; + } + throw new IllegalStateException("Unhandled color target " + target); + } } diff --git a/app/src/main/java/org/blitzortung/android/preferences/SlidePreferences.java b/app/src/main/java/org/blitzortung/android/preferences/SlidePreferences.java index cf40de4c..c49c52d6 100644 --- a/app/src/main/java/org/blitzortung/android/preferences/SlidePreferences.java +++ b/app/src/main/java/org/blitzortung/android/preferences/SlidePreferences.java @@ -14,13 +14,11 @@ public class SlidePreferences extends DialogPreference implements SeekBar.OnSeek private static final String ATTRIBUTE_NAMESPACE = "http://schemas.android.com/apk/res/android"; private final Context context; - private TextView valueText; - private SeekBar slider; - private final String unitSuffix; - private final int defaultValue; private final int maximumValue; + private TextView valueText; + private SeekBar slider; private int currentValue; public SlidePreferences(Context context, AttributeSet attrs) { diff --git a/app/src/main/java/org/blitzortung/android/util/Period.java b/app/src/main/java/org/blitzortung/android/util/Period.java index 1786d48c..70030e22 100644 --- a/app/src/main/java/org/blitzortung/android/util/Period.java +++ b/app/src/main/java/org/blitzortung/android/util/Period.java @@ -2,18 +2,17 @@ public class Period { - public static long getCurrentTime() { - return System.currentTimeMillis() / 1000; - } - private long lastUpdateTime; - private int updateCount; - + public Period() { restart(); } - + + public static long getCurrentTime() { + return System.currentTimeMillis() / 1000; + } + public boolean shouldUpdate(long currentTime, int currentPeriod) { if (lastUpdateTime == 0) { lastUpdateTime = currentTime; @@ -25,22 +24,22 @@ public boolean shouldUpdate(long currentTime, int currentPeriod) { public long getLastUpdateTime() { return lastUpdateTime; } - + public void setLastUpdateTime(long lastUpdateTime) { this.lastUpdateTime = lastUpdateTime; } - + public boolean isNthUpdate(int countPeriod) { return (updateCount % countPeriod) == 0; } - + public long getCurrentUpdatePeriod(long currentTime, int currentPeriod) { return currentPeriod - (currentTime - lastUpdateTime); } - + public void restart() { lastUpdateTime = 0; - updateCount = 0; + updateCount = 0; } } diff --git a/app/src/main/java/org/blitzortung/android/util/TimeFormat.java b/app/src/main/java/org/blitzortung/android/util/TimeFormat.java index 05d01e8a..6df30aa9 100644 --- a/app/src/main/java/org/blitzortung/android/util/TimeFormat.java +++ b/app/src/main/java/org/blitzortung/android/util/TimeFormat.java @@ -6,36 +6,38 @@ public class TimeFormat { - private TimeFormat(){} - - private static final SimpleDateFormat DATE_TIME_MILLISECONDS_FORMATTER = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss.SSS"); - static { - DATE_TIME_MILLISECONDS_FORMATTER.setTimeZone(TimeZone.getTimeZone("UTC")); - } - - private static final SimpleDateFormat JSON_DATE_TIME_FORMATTER = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); - static { - JSON_DATE_TIME_FORMATTER.setTimeZone(TimeZone.getTimeZone("UTC")); - } + private static final SimpleDateFormat DATE_TIME_MILLISECONDS_FORMATTER = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss.SSS"); + private static final SimpleDateFormat JSON_DATE_TIME_FORMATTER = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); + + static { + DATE_TIME_MILLISECONDS_FORMATTER.setTimeZone(TimeZone.getTimeZone("UTC")); + } + + static { + JSON_DATE_TIME_FORMATTER.setTimeZone(TimeZone.getTimeZone("UTC")); + } + + private TimeFormat() { + } public static long parseTimeWithMilliseconds(String timestampString) { - try { - return DATE_TIME_MILLISECONDS_FORMATTER.parse(timestampString).getTime(); - } catch (ParseException e) { + try { + return DATE_TIME_MILLISECONDS_FORMATTER.parse(timestampString).getTime(); + } catch (ParseException e) { throw new IllegalArgumentException(String.format("Unable to parse millisecond time string '%s'", timestampString), e); } - } + } public static long parseTimestampWithMillisecondsFromFields(String[] fields) { String timeString = fields[0].replace("-", "") + "T" + fields[1]; return parseTimeWithMilliseconds(timeString.substring(0, timeString.length() - 6)); } - - public static long parseTime(String timestampString) { - try { - return JSON_DATE_TIME_FORMATTER.parse(timestampString).getTime(); - } catch (ParseException e) { + + public static long parseTime(String timestampString) { + try { + return JSON_DATE_TIME_FORMATTER.parse(timestampString).getTime(); + } catch (ParseException e) { throw new IllegalArgumentException(String.format("Unable to parse time string '%s'", timestampString), e); - } - } + } + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/rounded_box.xml b/app/src/main/res/drawable/rounded_box.xml index 88f1bbf4..bab8c90e 100644 --- a/app/src/main/res/drawable/rounded_box.xml +++ b/app/src/main/res/drawable/rounded_box.xml @@ -1,8 +1,13 @@ - - - + + + diff --git a/app/src/main/res/layout/alarm_dialog.xml b/app/src/main/res/layout/alarm_dialog.xml index 4254a190..b01e9c63 100644 --- a/app/src/main/res/layout/alarm_dialog.xml +++ b/app/src/main/res/layout/alarm_dialog.xml @@ -1,15 +1,13 @@ + android:id="@+id/alarm_dialog" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="vertical" + android:padding="10dp"> - + \ No newline at end of file diff --git a/app/src/main/res/layout/info_dialog.xml b/app/src/main/res/layout/info_dialog.xml index 8ce1d555..9b1afaf2 100644 --- a/app/src/main/res/layout/info_dialog.xml +++ b/app/src/main/res/layout/info_dialog.xml @@ -1,22 +1,22 @@ + android:id="@+id/info_dialog" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="vertical" + android:padding="10dp"> + android:id="@+id/info_text" + android:layout_width="wrap_content" + android:layout_height="fill_parent" + android:text="@string/info_text" + android:textColor="#FFF" /> + android:id="@+id/copyright_text" + android:layout_width="wrap_content" + android:layout_height="fill_parent" + android:text="@string/copyright" + android:textColor="#FFF" /> \ No newline at end of file diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml index 23097d92..1b388af4 100644 --- a/app/src/main/res/layout/main.xml +++ b/app/src/main/res/layout/main.xml @@ -1,19 +1,17 @@ - + - + + android:id="@+id/cell2" + layout="@layout/map_overlay" /> diff --git a/app/src/main/res/layout/main_debug.xml b/app/src/main/res/layout/main_debug.xml index 9e7e2e6e..46acc3bf 100644 --- a/app/src/main/res/layout/main_debug.xml +++ b/app/src/main/res/layout/main_debug.xml @@ -1,19 +1,17 @@ - + - + + android:id="@+id/cell2" + layout="@layout/map_overlay" /> diff --git a/app/src/main/res/layout/map_overlay.xml b/app/src/main/res/layout/map_overlay.xml index 76da60fe..82d33ff1 100644 --- a/app/src/main/res/layout/map_overlay.xml +++ b/app/src/main/res/layout/map_overlay.xml @@ -2,84 +2,75 @@ + android:id="@+id/cell1" + layout="@layout/overlay_top" /> - + - + - + - + - + - + - + - + - + diff --git a/app/src/main/res/layout/overlay_top.xml b/app/src/main/res/layout/overlay_top.xml index f32f50b9..83b793fb 100644 --- a/app/src/main/res/layout/overlay_top.xml +++ b/app/src/main/res/layout/overlay_top.xml @@ -12,12 +12,12 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:layout_weight="1" android:layout_marginLeft="4dp" android:layout_marginStart="4dp" + android:layout_weight="1" android:text="" - android:textSize="14sp" - android:textColor="@color/text_foreground" /> + android:textColor="@color/text_foreground" + android:textSize="14sp" /> + android:textColor="@color/text_foreground" + android:textSize="14sp" /> + android:layout_centerInParent="true" + android:src="@android:drawable/stat_notify_error" /> + android:id="@+id/layout_popup" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="horizontal" + android:padding="10dp"> + android:id="@+id/popup_text" + android:layout_width="wrap_content" + android:layout_height="fill_parent" + android:gravity="center" + android:text="" + android:textColor="#FFF" /> \ No newline at end of file diff --git a/app/src/main/res/layout/quick_settings_dialog.xml b/app/src/main/res/layout/quick_settings_dialog.xml index 428c1970..35c563ee 100644 --- a/app/src/main/res/layout/quick_settings_dialog.xml +++ b/app/src/main/res/layout/quick_settings_dialog.xml @@ -22,7 +22,7 @@ android:layout_height="wrap_content" android:entries="@array/regions" android:padding="10dp" - android:prompt="@string/region"/> + android:prompt="@string/region" /> + android:id="@+id/alarm_widget" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="@drawable/rounded_box" + android:orientation="vertical" + android:padding="10dp"> - + \ No newline at end of file diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu.xml index 720afef9..f1677755 100644 --- a/app/src/main/res/menu/main_menu.xml +++ b/app/src/main/res/menu/main_menu.xml @@ -2,14 +2,14 @@ + android:id="@+id/menu_preferences" + android:icon="@android:drawable/ic_menu_preferences" + android:title="@string/preferences" /> + android:id="@+id/menu_alarms" + android:icon="@android:drawable/ic_menu_view" + android:title="@string/alarms" /> + android:id="@+id/menu_info" + android:icon="@android:drawable/ic_menu_info_details" + android:title="@string/info" /> \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 086a1c2c..a310309a 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -181,7 +181,7 @@ 25 50 - + Datenquelle integrierte Datenquelle oder Zugriff auf blitzortung.org (Nur für Teilnehmer) diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index c91481fa..c03cc415 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -8,8 +8,8 @@ android:key="region" android:persistent="true" android:selectable="true" - android:title="@string/region" - android:summary="@string/region_summary" /> + android:summary="@string/region_summary" + android:title="@string/region" /> + android:summary="@string/raster_size_summary" + android:title="@string/raster_size" /> + android:summary="@string/interval_duration_summary" + android:title="@string/interval_duration" /> + android:summary="@string/map_settings_summary" + android:title="@string/map_settings"> + android:summary="@string/map_mode_summary" + android:title="@string/map_mode" /> + android:summary="@string/map_fade_summary" + android:text="%" + android:title="@string/map_fade" /> + android:summary="@string/color_scheme_summary" + android:title="@string/color_scheme" /> + android:summary="@string/show_participants_summary" + android:title="@string/show_participants" /> + android:summary="@string/show_location_summary" + android:title="@string/show_location" /> + android:summary="@string/data_settings_summary" + android:title="@string/data_settings"> + android:summary="@string/historic_timestep_summary" + android:title="@string/historic_timestep" /> + android:summary="@string/query_period_summary" + android:title="@string/query_period" /> + android:summary="@string/data_source_summary" + android:title="@string/data_source" /> + android:summary="@string/username_summary" + android:title="@string/username" /> + android:summary="@string/password_summary" + android:title="@string/password" /> + android:summary="@string/location_settings_summary" + android:title="@string/location_settings"> + android:summary="@string/location_mode_summary" + android:title="@string/location_mode" /> + android:summary="@string/location_longitude_summary" + android:title="@string/longitude" /> + android:summary="@string/location_latitude_summary" + android:title="@string/latitude" /> + android:summary="@string/alarm_settings_summary" + android:title="@string/alarm_settings"> + android:summary="@string/alarm_enabled_summary" + android:title="@string/alarm_enabled" /> + android:summary="@string/background_query_period_summary" + android:title="@string/background_query_period" /> + android:summary="@string/notification_distance_limit_summary" + android:title="@string/notification_distance_limit" /> + android:summary="@string/signaling_distance_limit_summary" + android:title="@string/signaling_distance_limit" /> + android:showDefault="true" + android:summary="@string/alarm_audio_signal_summary" + android:title="@string/alarm_audio_signal" /> + android:summary="@string/alarm_vibration_signal_summary" + android:text="" + android:title="@string/alarm_vibration_signal" /> @@ -228,15 +228,15 @@ android:key="measurement_unit" android:persistent="true" android:selectable="true" - android:title="@string/measurement_unit" - android:summary="@string/measurement_unit_summary" /> + android:summary="@string/measurement_unit_summary" + android:title="@string/measurement_unit" /> + android:summary="@string/do_not_sleep_summary" + android:title="@string/do_not_sleep" /> \ No newline at end of file diff --git a/app/src/main/res/xml/widget_provider.xml b/app/src/main/res/xml/widget_provider.xml index 229774ec..76dd3a95 100644 --- a/app/src/main/res/xml/widget_provider.xml +++ b/app/src/main/res/xml/widget_provider.xml @@ -1,9 +1,7 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/test/java/org/blitzortung/android/alert/AlertHandlerTest.java b/app/src/test/java/org/blitzortung/android/alert/AlertHandlerTest.java index 12f19767..8fece33b 100644 --- a/app/src/test/java/org/blitzortung/android/alert/AlertHandlerTest.java +++ b/app/src/test/java/org/blitzortung/android/alert/AlertHandlerTest.java @@ -9,12 +9,12 @@ import com.annimon.stream.function.Consumer; import com.google.common.collect.Lists; +import org.blitzortung.android.alert.data.AlertSector; +import org.blitzortung.android.alert.data.AlertStatus; 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.controller.NotificationHandler; import org.blitzortung.android.app.view.PreferenceKey; import org.blitzortung.android.data.beans.Strike; @@ -67,13 +67,13 @@ public class AlertHandlerTest { @Mock private SharedPreferences sharedPreferences; - + @Mock private Context context; - - @Mock + + @Mock private Vibrator vibrator; - + @Mock private NotificationHandler notificationHandler; @@ -87,7 +87,7 @@ public class AlertHandlerTest { private Consumer alertEventConsumer; private AlertHandler alertHandler; - + private Resources resources; @Before @@ -108,7 +108,7 @@ public void setUp() { when(sharedPreferences.getString(PreferenceKey.ALERT_SOUND_SIGNAL.toString(), "")).thenReturn(""); when(alertStatusHandler.getCurrentActivity(alertStatus)).thenReturn(alertResult); when(context.getResources()).thenReturn(resources); - + alertHandler = new AlertHandler(locationManager, sharedPreferences, context, vibrator, notificationHandler, alertObjectFactory, alertParameters); alertHandler.setAlertEventConsumer(alertEventConsumer); } @@ -178,14 +178,14 @@ public void testCheckStrikesWithAlarmEnabledAndLocationSet() { @Test public void testGetAlarmResult() { AlertResult returnedAlertResult = alertHandler.getAlarmResult(); - + assertThat(returnedAlertResult, is(nullValue())); verify(alertStatusHandler, times(0)).getCurrentActivity(alertStatus); makeAlarmsValid(); returnedAlertResult = alertHandler.getAlarmResult(); - + assertThat(returnedAlertResult, is(sameInstance(alertResult))); verify(alertStatusHandler, times(2)).getCurrentActivity(alertStatus); } @@ -230,17 +230,17 @@ public void testGetAlarmSectors() { when(alertStatus.getSectors()).thenReturn(alertSectors); final Collection returnedAlertSectors = alertHandler.getAlarmSectors(); - + assertThat(returnedAlertSectors, is(sameInstance(alertSectors))); verify(alertStatus, times(1)).getSectors(); } - + @Test public void testGetAlarmParameters() { final AlertParameters returnedAlertParameters = alertHandler.getAlertParameters(); - + assertThat(returnedAlertParameters, is(sameInstance(alertParameters))); } - - + + } diff --git a/app/src/test/java/org/blitzortung/android/alert/AlertLabelHandlerTest.java b/app/src/test/java/org/blitzortung/android/alert/AlertLabelHandlerTest.java index 92438628..2a5248f5 100644 --- a/app/src/test/java/org/blitzortung/android/alert/AlertLabelHandlerTest.java +++ b/app/src/test/java/org/blitzortung/android/alert/AlertLabelHandlerTest.java @@ -2,15 +2,14 @@ import android.content.res.Resources; -import org.blitzortung.android.alert.handler.AlertStatusHandler; import org.blitzortung.android.alert.data.AlertStatus; +import org.blitzortung.android.alert.handler.AlertStatusHandler; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricGradleTestRunner; -import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; @@ -29,7 +28,7 @@ public class AlertLabelHandlerTest { @Mock private AlertStatus alertStatus; - + @Mock private AlertResult alertResult; @@ -39,8 +38,7 @@ public class AlertLabelHandlerTest { private Resources resources; @Before - public void setUp() - { + public void setUp() { MockitoAnnotations.initMocks(this); resources = RuntimeEnvironment.application.getResources(); @@ -49,8 +47,7 @@ public void setUp() } @Test - public void testApplyWithNoAlarm() - { + public void testApplyWithNoAlarm() { alertLabelHandler.apply(null); verify(alertLabel, times(1)).setAlarmTextColor(0xff00ff00); @@ -58,8 +55,7 @@ public void testApplyWithNoAlarm() } @Test - public void testApplyWithAlarmInHighDistance() - { + public void testApplyWithAlarmInHighDistance() { mockAlarmInRange(50.1f, "SO"); alertLabelHandler.apply(alertResult); @@ -69,8 +65,7 @@ public void testApplyWithAlarmInHighDistance() } @Test - public void testApplyWithAlarmInIntermediateDistance() - { + public void testApplyWithAlarmInIntermediateDistance() { mockAlarmInRange(20.1f, "NW"); alertLabelHandler.apply(alertResult); @@ -80,8 +75,7 @@ public void testApplyWithAlarmInIntermediateDistance() } @Test - public void testApplyWithAlarmInMinimumRange() - { + public void testApplyWithAlarmInMinimumRange() { mockAlarmInRange(20f, "S"); alertLabelHandler.apply(alertResult); @@ -90,8 +84,7 @@ public void testApplyWithAlarmInMinimumRange() verify(alertLabel, times(1)).setAlarmText("20km S"); } - private void mockAlarmInRange(float distance, String sectorLabel) - { + private void mockAlarmInRange(float distance, String sectorLabel) { when(alertResult.getClosestStrikeDistance()).thenReturn(distance); when(alertResult.getDistanceUnitName()).thenReturn("km"); when(alertResult.getBearingName()).thenReturn(sectorLabel); diff --git a/app/src/test/java/org/blitzortung/android/alert/AlertParametersTest.java b/app/src/test/java/org/blitzortung/android/alert/AlertParametersTest.java index e10a8340..847d7b3b 100644 --- a/app/src/test/java/org/blitzortung/android/alert/AlertParametersTest.java +++ b/app/src/test/java/org/blitzortung/android/alert/AlertParametersTest.java @@ -4,7 +4,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; @@ -17,19 +16,19 @@ @RunWith(RobolectricTestRunner.class) @Config(manifest = "src/main/AndroidManifest.xml", sdk = 19) public class AlertParametersTest { - + private AlertParameters alertParameters; - + @Before public void setUp() { alertParameters = new AlertParameters(); alertParameters.updateSectorLabels(RuntimeEnvironment.application); } - + @Test public void testGetSectorLabels() { final String[] sectorLabels = alertParameters.getSectorLabels(); - + assertThat(sectorLabels, is(not(nullValue()))); assertThat(sectorLabels.length, is(8)); } @@ -41,14 +40,14 @@ public void testGetRangeSteps() { assertThat(rangeSteps, is(not(nullValue()))); assertThat(rangeSteps.length, is(6)); } - + @Test public void testGetSetMeasurementSystem() { assertThat(alertParameters.getMeasurementSystem(), is(nullValue())); - + alertParameters.setMeasurementSystem(MeasurementSystem.METRIC); assertThat(alertParameters.getMeasurementSystem(), is(MeasurementSystem.METRIC)); } - + } diff --git a/app/src/test/java/org/blitzortung/android/alert/handler/AlertSectorHandlerTest.java b/app/src/test/java/org/blitzortung/android/alert/handler/AlertSectorHandlerTest.java index 6a6fc6b0..b8a56742 100644 --- a/app/src/test/java/org/blitzortung/android/alert/handler/AlertSectorHandlerTest.java +++ b/app/src/test/java/org/blitzortung/android/alert/handler/AlertSectorHandlerTest.java @@ -1,7 +1,9 @@ package org.blitzortung.android.alert.handler; import android.location.Location; + import com.google.common.collect.Lists; + import org.blitzortung.android.alert.AlertParameters; import org.blitzortung.android.alert.data.AlertSector; import org.blitzortung.android.alert.data.AlertSectorRange; @@ -16,76 +18,66 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyFloat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) public class AlertSectorHandlerTest { - + + private final MeasurementSystem measurementSystem = MeasurementSystem.METRIC; @Mock private Strike strike; - @Mock private Location location; - @Mock private Location strikeLocation; - private long now; - private long thresholdTime; - @Mock private AlertSector alertSector; - @Mock private AlertSectorRange alertSectorRange1; - @Mock private AlertSectorRange alertSectorRange2; - @Mock private AlertParameters alertParameters; - - private final MeasurementSystem measurementSystem = MeasurementSystem.METRIC; - private AlertSectorHandler alertSectorHandler; private long beforeThresholdTime; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - + now = System.currentTimeMillis(); thresholdTime = now - 10 * 60 * 1000; beforeThresholdTime = thresholdTime - 1; - + alertSectorHandler = new AlertSectorHandler(alertParameters); alertSectorHandler.setCheckStrikeParameters(location, thresholdTime); - + when(alertSector.getRanges()).thenReturn(Lists.newArrayList(alertSectorRange1, alertSectorRange2)); when(alertParameters.getMeasurementSystem()).thenReturn(measurementSystem); when(alertSectorRange1.getRangeMaximum()).thenReturn(2.5f); when(alertSectorRange2.getRangeMaximum()).thenReturn(5f); } - + @Test - public void testCheckWithNullAsSector() - { + public void testCheckWithNullAsSector() { alertSectorHandler.checkStrike(null, strike); - + verify(location, times(0)).distanceTo(any(Location.class)); verify(alertParameters, times(0)).getMeasurementSystem(); } - + @Test - public void testCheckWithinThresholdTimeAndRange1() - { + public void testCheckWithinThresholdTimeAndRange1() { when(strike.getTimestamp()).thenReturn(thresholdTime); when(strike.getLocation(any(Location.class))).thenReturn(strikeLocation); when(location.distanceTo(strikeLocation)).thenReturn(2500f); - + alertSectorHandler.checkStrike(alertSector, strike); - + verify(alertSector, times(1)).updateClosestStrikeDistance(2.5f); verify(alertSectorRange1, times(1)).getRangeMaximum(); verify(alertSectorRange1, times(1)).addStrike(strike); @@ -93,8 +85,7 @@ public void testCheckWithinThresholdTimeAndRange1() } @Test - public void testCheckWithinThresholdTimeAndOutOfAllRanges() - { + public void testCheckWithinThresholdTimeAndOutOfAllRanges() { when(strike.getTimestamp()).thenReturn(thresholdTime); when(strike.getLocation(any(Location.class))).thenReturn(strikeLocation); when(location.distanceTo(strikeLocation)).thenReturn(5000.1f); @@ -109,8 +100,7 @@ public void testCheckWithinThresholdTimeAndOutOfAllRanges() } @Test - public void testCheckOutOfThresholdTimeAndWithinRange2() - { + public void testCheckOutOfThresholdTimeAndWithinRange2() { when(strike.getTimestamp()).thenReturn(beforeThresholdTime); when(strike.getLocation(any(Location.class))).thenReturn(strikeLocation); when(location.distanceTo(strikeLocation)).thenReturn(2500.1f); @@ -125,8 +115,7 @@ public void testCheckOutOfThresholdTimeAndWithinRange2() } @Test - public void testCheckOutOfThresholdTimeAndAllRanges() - { + public void testCheckOutOfThresholdTimeAndAllRanges() { when(strike.getTimestamp()).thenReturn(beforeThresholdTime); when(strike.getLocation(any(Location.class))).thenReturn(strikeLocation); when(location.distanceTo(strikeLocation)).thenReturn(5000.1f); diff --git a/app/src/test/java/org/blitzortung/android/alert/handler/AlertStatusHandlerTest.java b/app/src/test/java/org/blitzortung/android/alert/handler/AlertStatusHandlerTest.java index 23b31b9c..2d4f69b3 100644 --- a/app/src/test/java/org/blitzortung/android/alert/handler/AlertStatusHandlerTest.java +++ b/app/src/test/java/org/blitzortung/android/alert/handler/AlertStatusHandlerTest.java @@ -1,7 +1,9 @@ package org.blitzortung.android.alert.handler; import android.location.Location; + import com.google.common.collect.Lists; + import org.blitzortung.android.alert.AlertParameters; import org.blitzortung.android.alert.AlertResult; import org.blitzortung.android.alert.data.AlertSector; @@ -19,14 +21,20 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyLong; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) public class AlertStatusHandlerTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - + @Mock private AlertSectorHandler alertSectorHandler; @@ -46,7 +54,7 @@ public class AlertStatusHandlerTest { private Location location; private MeasurementSystem measurementSystem = MeasurementSystem.METRIC; - + private AlertStatusHandler alertStatusHandler; @Before @@ -176,7 +184,7 @@ public void testGetSectorWithClosestStrike() { final AlertSector sectorWithClosestStrike = alertStatusHandler.getSectorWithClosestStrike(alertStatus); assertThat(sectorWithClosestStrike, is(alertSector3)); } - + @Test public void testGetCurrentActivity() { AlertSector alertSector1 = mockAlarmSector("foo", 50f); @@ -184,7 +192,7 @@ public void testGetCurrentActivity() { when(alertStatus.getSectors()).thenReturn(Lists.newArrayList(alertSector1)); final AlertResult currentActivity = alertStatusHandler.getCurrentActivity(alertStatus); - + assertThat(currentActivity.getBearingName(), is("foo")); assertThat(currentActivity.getClosestStrikeDistance(), is(50f)); assertThat(currentActivity.getDistanceUnitName(), is("km")); diff --git a/app/src/test/java/org/blitzortung/android/alert/object/AlertResultTest.java b/app/src/test/java/org/blitzortung/android/alert/object/AlertResultTest.java index 150b54e3..79692e97 100644 --- a/app/src/test/java/org/blitzortung/android/alert/object/AlertResultTest.java +++ b/app/src/test/java/org/blitzortung/android/alert/object/AlertResultTest.java @@ -17,7 +17,7 @@ public class AlertResultTest { @Mock private AlertSector alertSector; - + private String distanceUnitName = "km"; private AlertResult alertResult; @@ -41,10 +41,9 @@ public void testGetSector() throws Exception { public void testGetDistance() throws Exception { assertThat(alertResult.getClosestStrikeDistance(), is(4567f)); } - + @Test - public void testGetDistanceUnit() - { + public void testGetDistanceUnit() { assertThat(alertResult.getDistanceUnitName(), is("km")); } } diff --git a/app/src/test/java/org/blitzortung/android/alert/object/AlertSectorRangeTest.java b/app/src/test/java/org/blitzortung/android/alert/object/AlertSectorRangeTest.java index 1d8daa32..9d42ecec 100644 --- a/app/src/test/java/org/blitzortung/android/alert/object/AlertSectorRangeTest.java +++ b/app/src/test/java/org/blitzortung/android/alert/object/AlertSectorRangeTest.java @@ -13,14 +13,14 @@ @RunWith(RobolectricTestRunner.class) public class AlertSectorRangeTest { - + private AlertSectorRange alertSectorRange; - + @Before public void setUp() { alertSectorRange = new AlertSectorRange(5.0f, 10.0f); } - + @Test public void testGetRangeMinimum() { assertThat(alertSectorRange.getRangeMinimum(), is(5.0f)); @@ -35,12 +35,12 @@ public void testGetRangeMaximum() { public void testGetStrikeCountInitialValue() { assertThat(alertSectorRange.getStrikeCount(), is(0)); } - + @Test public void testSetGetStrikeCount() { Strike strike = mock(Strike.class); when(strike.getMultiplicity()).thenReturn(1).thenReturn(2); - + alertSectorRange.addStrike(strike); assertThat(alertSectorRange.getStrikeCount(), is(1)); @@ -52,27 +52,27 @@ public void testSetGetStrikeCount() { public void testGetLatestStrikeTimestampInitialValue() { assertThat(alertSectorRange.getLatestStrikeTimestamp(), is(0l)); } - + @Test public void testGetLatestStrikeTimestamp() { Strike strike = mock(Strike.class); when(strike.getTimestamp()).thenReturn(1000l).thenReturn(5000l); - + alertSectorRange.addStrike(strike); assertThat(alertSectorRange.getLatestStrikeTimestamp(), is(1000l)); alertSectorRange.addStrike(strike); assertThat(alertSectorRange.getLatestStrikeTimestamp(), is(5000l)); } - + @Test public void testReset() { Strike strike = mock(Strike.class); when(strike.getTimestamp()).thenReturn(5000l); when(strike.getMultiplicity()).thenReturn(2); - + alertSectorRange.clearResults(); - + assertThat(alertSectorRange.getStrikeCount(), is(0)); assertThat(alertSectorRange.getLatestStrikeTimestamp(), is(0l)); } diff --git a/app/src/test/java/org/blitzortung/android/alert/object/AlertSectorTest.java b/app/src/test/java/org/blitzortung/android/alert/object/AlertSectorTest.java index d75ef93e..ee9988f8 100644 --- a/app/src/test/java/org/blitzortung/android/alert/object/AlertSectorTest.java +++ b/app/src/test/java/org/blitzortung/android/alert/object/AlertSectorTest.java @@ -19,14 +19,11 @@ @RunWith(RobolectricTestRunner.class) public class AlertSectorTest { + private final String sectorLabel = "foo"; @Mock private AlertObjectFactory alertObjectFactory; - @Mock private AlertParameters alertParameters; - - private final String sectorLabel = "foo"; - @Mock private AlertSectorRange alertSectorRange1; @@ -54,7 +51,7 @@ public void setUp() { @Test public void testClearResults() { alertSector.updateClosestStrikeDistance(10.0f); - + alertSector.clearResults(); //assertThat(alertSector.getClosestStrikeDistance()).isEqualTo(Float.POSITIVE_INFINITY); @@ -79,17 +76,16 @@ public void testGetMinimumSectorBearing() { public void testGetMaximumSectorBearing() { assertThat(alertSector.getMaximumSectorBearing()).isEqualTo(maximumBearing); } - + @Test public void testGetLabel() { assertThat(alertSector.getLabel()).isEqualTo(sectorLabel); } - + @Test - public void testGetClosestStrikeDistanceAndUpdateClosestStrikeDistance() - { + public void testGetClosestStrikeDistanceAndUpdateClosestStrikeDistance() { assertThat(alertSector.getClosestStrikeDistance()).isEqualTo(Float.POSITIVE_INFINITY); - + alertSector.updateClosestStrikeDistance(25.0f); assertThat(alertSector.getClosestStrikeDistance()).isEqualTo(25f); diff --git a/app/src/test/java/org/blitzortung/android/alert/object/AlertStatusTest.java b/app/src/test/java/org/blitzortung/android/alert/object/AlertStatusTest.java index 645c9a8f..63f2cef4 100644 --- a/app/src/test/java/org/blitzortung/android/alert/object/AlertStatusTest.java +++ b/app/src/test/java/org/blitzortung/android/alert/object/AlertStatusTest.java @@ -12,7 +12,9 @@ import java.util.Collection; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) public class AlertStatusTest { @@ -41,7 +43,7 @@ public void setUp() { alertStatus = new AlertStatus(alertObjectFactory, alertParameters); } - + @Test public void testConstruct() { verify(alertObjectFactory, times(1)).createAlarmSector(alertParameters, "foo", 90f, -90f); diff --git a/app/src/test/java/org/blitzortung/android/app/AppServiceTest.java b/app/src/test/java/org/blitzortung/android/app/AppServiceTest.java index 46cfe6e2..d91b2e24 100644 --- a/app/src/test/java/org/blitzortung/android/app/AppServiceTest.java +++ b/app/src/test/java/org/blitzortung/android/app/AppServiceTest.java @@ -20,17 +20,13 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.Shadows; import org.robolectric.annotation.Config; -import org.robolectric.fakes.RoboSharedPreferences; import org.robolectric.shadows.ShadowContextImpl; import org.robolectric.shadows.ShadowPreferenceManager; -import org.robolectric.shadows.util.PreferenceBuilder; -import java.util.Collections; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @@ -47,21 +43,16 @@ @Config(manifest = "src/main/AndroidManifest.xml", sdk = 19) public class AppServiceTest { + @Captor + ArgumentCaptor> dataChannelsCaptor; @Mock private Handler handler; - @Mock private Period period; - @Mock private DataHandler dataHandler; - @Mock private PowerManager powerManager; - - @Captor - ArgumentCaptor> dataChannelsCaptor; - private SharedPreferences sharedPreferences; private AppService appService; diff --git a/app/src/test/java/org/blitzortung/android/app/MainTest.java b/app/src/test/java/org/blitzortung/android/app/MainTest.java index 9f133ae2..747aaf81 100644 --- a/app/src/test/java/org/blitzortung/android/app/MainTest.java +++ b/app/src/test/java/org/blitzortung/android/app/MainTest.java @@ -13,7 +13,9 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) @Config(manifest = "src/main/AndroidManifest.xml", sdk = 19) @@ -50,8 +52,7 @@ public void testCreateStatusText() { @Test - public void testCreateStatusTextWithStrikeNumberSet() - { + public void testCreateStatusTextWithStrikeNumberSet() { when(strikesOverlay.getTotalNumberOfStrikes()).thenReturn(1234); main.setStatusString("foo"); @@ -63,8 +64,7 @@ public void testCreateStatusTextWithStrikeNumberSet() } @Test - public void testRunWithRasterAndListenerSet() - { + public void testRunWithRasterAndListenerSet() { when(strikesOverlay.hasRasterParameters()).thenReturn(true); main.setStatusString("foo"); diff --git a/app/src/test/java/org/blitzortung/android/app/controller/LocationHandlerTest.java b/app/src/test/java/org/blitzortung/android/app/controller/LocationHandlerTest.java index 3591336c..4c083aeb 100644 --- a/app/src/test/java/org/blitzortung/android/app/controller/LocationHandlerTest.java +++ b/app/src/test/java/org/blitzortung/android/app/controller/LocationHandlerTest.java @@ -28,19 +28,19 @@ @RunWith(RobolectricTestRunner.class) public class LocationHandlerTest { - + @Mock private Context context; - + @Mock private SharedPreferences sharedPreferences; - + @Mock private LocationManager locationManager; @Mock private Consumer locationListener; - + private LocationHandler locationHandler; @Before @@ -52,17 +52,17 @@ public void setUp() { when(context.getResources()).thenReturn(application.getResources()); when(locationManager.getAllProviders()).thenReturn(Lists.newArrayList("network", "gps")); setLocationProviderPrefs(LocationManager.NETWORK_PROVIDER); - + locationHandler = new LocationHandler(context, sharedPreferences); } - + @Test public void testInitialization() { verify(sharedPreferences, times(1)).getString(PreferenceKey.LOCATION_MODE.toString(), LocationHandler.Provider.NETWORK.getType()); verify(sharedPreferences, times(1)).registerOnSharedPreferenceChangeListener(locationHandler); verify(locationManager, times(1)).addGpsStatusListener(locationHandler); verify(locationManager, times(1)).removeUpdates(locationHandler); - verify(locationManager, times(1)).requestLocationUpdates(LocationHandler.Provider.NETWORK.getType(), 10000, 10, locationHandler); + verify(locationManager, times(1)).requestLocationUpdates(LocationHandler.Provider.NETWORK.getType(), 10000, 10, locationHandler); } @Test @@ -92,7 +92,7 @@ public void testSetUnknownProvider() { verify(locationManager, times(2)).removeUpdates(locationHandler); verify(locationManager, times(1)).requestLocationUpdates(anyString(), anyInt(), anyInt(), eq(locationHandler)); } - + private void setLocationProviderPrefs(String provider) { when(sharedPreferences.getString(PreferenceKey.LOCATION_MODE.toString(), LocationHandler.Provider.NETWORK.getType())).thenReturn(provider); } diff --git a/app/src/test/java/org/blitzortung/android/app/controller/NotificationHandlerTest.java b/app/src/test/java/org/blitzortung/android/app/controller/NotificationHandlerTest.java index 67dcb7f8..4d497d43 100644 --- a/app/src/test/java/org/blitzortung/android/app/controller/NotificationHandlerTest.java +++ b/app/src/test/java/org/blitzortung/android/app/controller/NotificationHandlerTest.java @@ -5,6 +5,7 @@ import android.app.NotificationManager; import android.content.Context; import android.content.res.Resources; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -16,36 +17,23 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) public class NotificationHandlerTest { - @Implements(Notification.class) - public class ShadowNotification { - @RealObject - private Notification realNotification; - - public void __constructor__(int icon, CharSequence tickerText, long when) { - realNotification.icon = icon; - realNotification.tickerText = tickerText; - realNotification.when = when; - } - } - @Mock private Activity activity; - @Mock private Resources resources; - @Mock private NotificationManager notificationManager; - private NotificationHandler notificationHandler; + @Before - public void setUp() - { + public void setUp() { MockitoAnnotations.initMocks(this); when(activity.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(notificationManager); @@ -84,4 +72,16 @@ public void testClearNotificationWithNullNotification() { notificationHandler.clearNotification(); } + @Implements(Notification.class) + public class ShadowNotification { + @RealObject + private Notification realNotification; + + public void __constructor__(int icon, CharSequence tickerText, long when) { + realNotification.icon = icon; + realNotification.tickerText = tickerText; + realNotification.when = when; + } + } + } diff --git a/app/src/test/java/org/blitzortung/android/data/ParametersControllerTest.java b/app/src/test/java/org/blitzortung/android/data/ParametersControllerTest.java index b81fd2c3..1b5a0bc6 100644 --- a/app/src/test/java/org/blitzortung/android/data/ParametersControllerTest.java +++ b/app/src/test/java/org/blitzortung/android/data/ParametersControllerTest.java @@ -8,7 +8,9 @@ import org.robolectric.RobolectricTestRunner; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; @RunWith(RobolectricTestRunner.class) public class ParametersControllerTest { diff --git a/app/src/test/java/org/blitzortung/android/data/beans/DefaultStrikeTest.java b/app/src/test/java/org/blitzortung/android/data/beans/DefaultStrikeTest.java index b5849b53..b61208db 100644 --- a/app/src/test/java/org/blitzortung/android/data/beans/DefaultStrikeTest.java +++ b/app/src/test/java/org/blitzortung/android/data/beans/DefaultStrikeTest.java @@ -13,15 +13,14 @@ public class DefaultStrikeTest { private DefaultStrike defaultStrike; @Test - public void testConstructAndRead() - { - defaultStrike = new DefaultStrike(1336826723123L, 11.0f, 49.0f, 12, 54.3f, (short)6, 12.3f); + public void testConstructAndRead() { + defaultStrike = new DefaultStrike(1336826723123L, 11.0f, 49.0f, 12, 54.3f, (short) 6, 12.3f); assertThat(defaultStrike.getTimestamp(), is(1336826723123L)); assertThat(defaultStrike.getLongitude(), is(11.0f)); assertThat(defaultStrike.getLatitude(), is(49.0f)); assertThat(defaultStrike.getLateralError(), is(12.3f)); assertThat(defaultStrike.getAmplitude(), is(54.3f)); - assertThat(defaultStrike.getStationCount(), is((short)6)); + assertThat(defaultStrike.getStationCount(), is((short) 6)); } } diff --git a/app/src/test/java/org/blitzortung/android/data/beans/RasterParametersTest.java b/app/src/test/java/org/blitzortung/android/data/beans/RasterParametersTest.java index 2a8726a0..4a6290e2 100644 --- a/app/src/test/java/org/blitzortung/android/data/beans/RasterParametersTest.java +++ b/app/src/test/java/org/blitzortung/android/data/beans/RasterParametersTest.java @@ -2,7 +2,9 @@ import android.graphics.Point; import android.graphics.RectF; + import com.google.android.maps.Projection; + import org.blitzortung.android.data.Coordsys; import org.blitzortung.android.data.provider.DataBuilder; import org.json.JSONException; @@ -17,17 +19,17 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) @Config(manifest = "src/main/AndroidManifest.xml", sdk = 19) public class RasterParametersTest { - private RasterParameters rasterParameters; - - @Mock - private JSONObject jsonObject; - private final float lon_start = -10; private final float lon_delta = 1; private final int lon_count = 40; @@ -35,6 +37,9 @@ public class RasterParametersTest { private final float lat_delta = 1.5f; private final int lat_count = 30; private final String info = ""; + private RasterParameters rasterParameters; + @Mock + private JSONObject jsonObject; @Before public void setUp() throws JSONException { @@ -42,8 +47,8 @@ public void setUp() throws JSONException { when(jsonObject.getDouble("x0")).thenReturn((double) lon_start); when(jsonObject.getDouble("y1")).thenReturn((double) lat_start); - when(jsonObject.getDouble("xd")).thenReturn((double)lon_delta); - when(jsonObject.getDouble("yd")).thenReturn((double)lat_delta); + when(jsonObject.getDouble("xd")).thenReturn((double) lon_delta); + when(jsonObject.getDouble("yd")).thenReturn((double) lat_delta); when(jsonObject.getInt("xc")).thenReturn(lon_count); when(jsonObject.getInt("yc")).thenReturn(lat_count); @@ -52,36 +57,31 @@ public void setUp() throws JSONException { } @Test - public void testGetCenterLongitude() - { + public void testGetCenterLongitude() { assertThat(rasterParameters.getCenterLongitude(0), is(lon_start + 0.5f * lon_delta)); assertThat(rasterParameters.getCenterLongitude(lon_count - 1), is(lon_start + (0.5f + lon_count - 1) * lon_delta)); } @Test - public void testGetCenterLatitude() - { + public void testGetCenterLatitude() { assertThat(rasterParameters.getCenterLatitude(0), is(lat_start - 0.5f * lat_delta)); assertThat(rasterParameters.getCenterLatitude(lat_count - 1), is(lat_start - (0.5f + lat_count - 1) * lat_delta)); } @Test - public void testGetLongitudeDelta() - { + public void testGetLongitudeDelta() { assertThat(rasterParameters.getLongitudeDelta(), is(lon_delta)); } @Test - public void testGetLatitudeDelta() - { + public void testGetLatitudeDelta() { assertThat(rasterParameters.getLatitudeDelta(), is(lat_delta)); } @Test - public void testGetRect() - { + public void testGetRect() { Projection projection = mock(Projection.class); when(projection.toPixels(eq(Coordsys.toMapCoords(lon_start, lat_start)), any(Point.class))).thenReturn(new Point(-5, 5)); @@ -97,21 +97,18 @@ public void testGetRect() } @Test - public void testToString() - { + public void testToString() { assertThat(rasterParameters.toString(), is("RasterParameters(-10.0000, 1.0000; 60.0000, 1.5000)")); } @Test - public void testGetLongitudeIndex() - { + public void testGetLongitudeIndex() { assertThat(rasterParameters.getLongitudeIndex(lon_start), is(0)); assertThat(rasterParameters.getLongitudeIndex(lon_start + lon_delta * lon_count), is(lon_count)); } @Test - public void testGetLatitudeIndex() - { + public void testGetLatitudeIndex() { assertThat(rasterParameters.getLatitudeIndex(lat_start), is(0)); assertThat(rasterParameters.getLatitudeIndex(lat_start - lat_delta * lat_count), is(lat_count)); } diff --git a/app/src/test/java/org/blitzortung/android/data/beans/StationTest.java b/app/src/test/java/org/blitzortung/android/data/beans/StationTest.java index 28a59264..fc38e41d 100644 --- a/app/src/test/java/org/blitzortung/android/data/beans/StationTest.java +++ b/app/src/test/java/org/blitzortung/android/data/beans/StationTest.java @@ -1,19 +1,12 @@ package org.blitzortung.android.data.beans; -import org.json.JSONArray; -import org.json.JSONException; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) public class StationTest { @@ -28,8 +21,7 @@ public void setUp() { } @Test - public void testConstructAndReadValues() - { + public void testConstructAndReadValues() { station = new Station("name", 11.0f, 49.0f, 1336826723123l); assertThat(station.getName(), is("name")); @@ -40,8 +32,7 @@ public void testConstructAndReadValues() } @Test - public void testCreateOnlineStation() - { + public void testCreateOnlineStation() { station = new Station("name", 11.0f, 49.0f, currentTime); assertThat(station.getState(), is(Station.State.ON)); diff --git a/app/src/test/java/org/blitzortung/android/data/beans/StrikeAbstractTest.java b/app/src/test/java/org/blitzortung/android/data/beans/StrikeAbstractTest.java index 287526e6..699e56e4 100644 --- a/app/src/test/java/org/blitzortung/android/data/beans/StrikeAbstractTest.java +++ b/app/src/test/java/org/blitzortung/android/data/beans/StrikeAbstractTest.java @@ -1,6 +1,7 @@ package org.blitzortung.android.data.beans; import android.location.Location; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -12,20 +13,11 @@ @RunWith(RobolectricTestRunner.class) public class StrikeAbstractTest { - static class StrikeAbstractForTest extends StrikeAbstract - { - public StrikeAbstractForTest() - { - super(1234l, 11.0f, 49.0f); - } - } - private StrikeAbstractForTest abstractStrike; @Before - public void setUp() - { - abstractStrike = new StrikeAbstractForTest(); + public void setUp() { + abstractStrike = new StrikeAbstractForTest(); } @Test @@ -56,4 +48,10 @@ public void testGetLocation() throws Exception { assertThat(location.getLatitude(), is(49.0)); assertThat(location.getAltitude(), is(0.0)); } + + static class StrikeAbstractForTest extends StrikeAbstract { + public StrikeAbstractForTest() { + super(1234l, 11.0f, 49.0f); + } + } } diff --git a/app/src/test/java/org/blitzortung/android/data/builder/DefaultStrikeBuilderTest.java b/app/src/test/java/org/blitzortung/android/data/builder/DefaultStrikeBuilderTest.java index 9f03a1be..15e1db7c 100644 --- a/app/src/test/java/org/blitzortung/android/data/builder/DefaultStrikeBuilderTest.java +++ b/app/src/test/java/org/blitzortung/android/data/builder/DefaultStrikeBuilderTest.java @@ -54,7 +54,7 @@ public void testBuildFromJson() throws JSONException { assertThat(strike.getLateralError()).isEqualTo(12.3f); assertThat(strike.getAltitude()).isEqualTo(0); assertThat(strike.getAmplitude()).isEqualTo(54.3f); - assertThat(strike.getStationCount()).isEqualTo((short)6); + assertThat(strike.getStationCount()).isEqualTo((short) 6); } diff --git a/app/src/test/java/org/blitzortung/android/data/provider/DataProviderTest.java b/app/src/test/java/org/blitzortung/android/data/provider/DataProviderTest.java index 90697b52..93f99cb6 100644 --- a/app/src/test/java/org/blitzortung/android/data/provider/DataProviderTest.java +++ b/app/src/test/java/org/blitzortung/android/data/provider/DataProviderTest.java @@ -1,9 +1,7 @@ package org.blitzortung.android.data.provider; import org.blitzortung.android.data.Parameters; -import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.beans.Station; -import org.blitzortung.android.data.beans.RasterParameters; import org.blitzortung.android.data.provider.result.ResultEvent; import org.junit.Test; import org.junit.runner.RunWith; @@ -17,6 +15,16 @@ @RunWith(RobolectricTestRunner.class) public class DataProviderTest { + @Test + public void testSetCredentials() { + DataProvider dataProvider = new DataProviderForTest(); + + dataProvider.setCredentials("foo", "bar"); + + assertThat(dataProvider.username, is("foo")); + assertThat(dataProvider.password, is("bar")); + } + class DataProviderForTest extends DataProvider { @Override @@ -59,14 +67,4 @@ public boolean isCapableOfHistoricalData() { return false; } } - - @Test - public void testSetCredentials() { - DataProvider dataProvider = new DataProviderForTest(); - - dataProvider.setCredentials("foo", "bar"); - - assertThat(dataProvider.username, is("foo")); - assertThat(dataProvider.password, is("bar")); - } } diff --git a/app/src/test/java/org/blitzortung/android/data/provider/ResultEventTest.java b/app/src/test/java/org/blitzortung/android/data/provider/ResultEventTest.java index 1021fa55..7819bc16 100644 --- a/app/src/test/java/org/blitzortung/android/data/provider/ResultEventTest.java +++ b/app/src/test/java/org/blitzortung/android/data/provider/ResultEventTest.java @@ -1,11 +1,12 @@ package org.blitzortung.android.data.provider; import com.google.common.collect.Lists; -import org.blitzortung.android.data.beans.*; -import org.blitzortung.android.data.beans.StrikeAbstract; + import org.blitzortung.android.data.beans.DefaultStrike; +import org.blitzortung.android.data.beans.RasterParameters; +import org.blitzortung.android.data.beans.Station; +import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.provider.result.ResultEvent; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @@ -14,7 +15,9 @@ import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNull.nullValue; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @RunWith(RobolectricTestRunner.class) diff --git a/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/IntervalTimerTest.java b/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/IntervalTimerTest.java index d2fa4667..b9326000 100644 --- a/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/IntervalTimerTest.java +++ b/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/IntervalTimerTest.java @@ -25,8 +25,7 @@ public void setUp() throws Exception { } @Test - public void testMultipleIntervals() - { + public void testMultipleIntervals() { intervalTimer.startInterval(currentTime - 3 * intervalLength); assertTrue(intervalTimer.hasNext()); @@ -41,5 +40,4 @@ public void testMultipleIntervals() } - } diff --git a/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactoryIntegrationTest.java b/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactoryIntegrationTest.java index 85368e1c..17681f47 100644 --- a/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactoryIntegrationTest.java +++ b/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactoryIntegrationTest.java @@ -1,7 +1,7 @@ package org.blitzortung.android.data.provider.blitzortung; -import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.beans.Station; +import org.blitzortung.android.data.beans.StrikeAbstract; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -15,8 +15,7 @@ public class MapBuilderFactoryIntegrationTest { private MapBuilderFactory mapBuilderFactory; @Before - public void setUp() - { + public void setUp() { mapBuilderFactory = new MapBuilderFactory(); } diff --git a/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactoryTest.java b/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactoryTest.java index ddd8478f..e48ef404 100644 --- a/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactoryTest.java +++ b/app/src/test/java/org/blitzortung/android/data/provider/blitzortung/MapBuilderFactoryTest.java @@ -1,7 +1,7 @@ package org.blitzortung.android.data.provider.blitzortung; -import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.beans.Station; +import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.provider.blitzortung.generic.LineSplitter; import org.junit.Before; import org.junit.Test; @@ -25,8 +25,7 @@ public class MapBuilderFactoryTest { private MapBuilderFactory mapBuilderFactory; @Before - public void setUp() - { + public void setUp() { MockitoAnnotations.initMocks(this); mapBuilderFactory = new MapBuilderFactory(strikeLineSplitter, stationLineSplitter); @@ -59,10 +58,10 @@ public void testStationBuilder() { MapBuilder stationMapBuilder = mapBuilderFactory.createStationMapBuilder(); when(stationLineSplitter.split("")).thenReturn( - new String[] { - "city;\"Egaldorf\"", - "pos;43.345542;11.465365;239", - "last_signal;\"2013-10-06 14:15:55\"" + new String[]{ + "city;\"Egaldorf\"", + "pos;43.345542;11.465365;239", + "last_signal;\"2013-10-06 14:15:55\"" } ); diff --git a/app/src/test/java/org/blitzortung/android/jsonrpc/JsonRpcClientTest.java b/app/src/test/java/org/blitzortung/android/jsonrpc/JsonRpcClientTest.java index 2112cf56..19372bda 100644 --- a/app/src/test/java/org/blitzortung/android/jsonrpc/JsonRpcClientTest.java +++ b/app/src/test/java/org/blitzortung/android/jsonrpc/JsonRpcClientTest.java @@ -1,6 +1,7 @@ package org.blitzortung.android.jsonrpc; import com.google.common.collect.Lists; + import org.json.JSONArray; import org.json.JSONException; import org.junit.Before; @@ -9,9 +10,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import java.util.List; import static org.hamcrest.core.Is.is; @@ -22,11 +21,9 @@ @Config(manifest = "src/main/AndroidManifest.xml", sdk = 19) public class JsonRpcClientTest { - private JsonRpcClient jsonRpcClient; - private final String uriString = "foo"; - private final String agentSuffix = "_VERSION"; + private JsonRpcClient jsonRpcClient; @Before public void setUp() { @@ -44,7 +41,7 @@ public void testBuildParameters() throws JSONException { assertThat(result.length(), is(2)); List resultObjects = Lists.newArrayList(); - for (int i=0; i overlays = Lists.newArrayList(); private OwnLocationOverlay ownLocationOverlay; @Mock @@ -112,11 +59,8 @@ public int hashCode() { private SharedPreferences sharedPreferences; - private final List overlays = Lists.newArrayList(); - @Before - public void setUp() - { + public void setUp() { MockitoAnnotations.initMocks(this); sharedPreferences = ShadowPreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application); @@ -131,8 +75,7 @@ public void setUp() } @Test - public void testConstruct() - { + public void testConstruct() { verify(mapView, times(1)).addZoomListener(any(OwnMapView.ZoomListener.class)); verify(mapView, times(1)).getZoomLevel(); @@ -141,8 +84,7 @@ public void testConstruct() } @Test - public void testSize() - { + public void testSize() { assertThat(ownLocationOverlay.size()).isEqualTo(0); enableOwnLocation(); @@ -155,8 +97,7 @@ public void testSize() } @Test - public void testCreateItem() - { + public void testCreateItem() { assertThat(ownLocationOverlay.createItem(0)).isNull(); enableOwnLocation(); @@ -169,38 +110,90 @@ public void testCreateItem() } @Test - public void testOnLocationChanged() - { + public void testOnLocationChanged() { ownLocationOverlay.getLocationEventConsumer().accept(new LocationEvent(mock(Location.class))); - + assertThat(ownLocationOverlay.size()).isEqualTo(0); } - + @Test - public void testOnLocationChangedWithNullLocation() - { + public void testOnLocationChangedWithNullLocation() { ownLocationOverlay.getLocationEventConsumer().accept(new LocationEvent(null)); assertThat(ownLocationOverlay.size()).isEqualTo(0); } @Test - public void testDisableOwnLocation() - { + public void testDisableOwnLocation() { ownLocationOverlay.getLocationEventConsumer().accept(new LocationEvent(mock(Location.class))); ownLocationOverlay.disableOwnLocation(); assertThat(ownLocationOverlay.size()).isEqualTo(0); } - + private void enableOwnLocation() { sharedPreferences.edit().putBoolean(PreferenceKey.SHOW_LOCATION.toString(), true).commit(); ownLocationOverlay.onSharedPreferenceChanged(sharedPreferences, PreferenceKey.SHOW_LOCATION.toString()); } - private void updateLocation() - { + private void updateLocation() { ownLocationOverlay.getLocationEventConsumer().accept(new LocationEvent(mock(Location.class))); } + + @SuppressWarnings({"UnusedDeclaration"}) + @Implements(OverlayItem.class) + public class ShadowOverlayItem { + private GeoPoint geoPoint; + private String title; + private String snippet; + + public void __constructor__(GeoPoint geoPoint, String title, String snippet) { + this.geoPoint = geoPoint; + this.title = title; + this.snippet = snippet; + } + + @Implementation + public GeoPoint getPoint() { + return geoPoint; + } + + @Implementation + public String getTitle() { + return title; + } + + @Implementation + public String getSnippet() { + return snippet; + } + + @Override + @Implementation + public boolean equals(Object o) { + if (o == null) return false; + //o = shadowOf(o); + //if (o == null) return false; + if (this == o) return true; + if (getClass() != o.getClass()) return false; + + ShadowOverlayItem that = (ShadowOverlayItem) o; + + return Strings.equals(title, that.title) + && Strings.equals(snippet, that.snippet) + && geoPoint == null ? that.geoPoint == null : + geoPoint.equals(that.geoPoint); + } + + @Override + @Implementation + public int hashCode() { + int result = 13; + result = title == null ? result : 19 * result + title.hashCode(); + result = snippet == null ? result : 19 * result + snippet.hashCode(); + result = geoPoint == null ? result : 19 * result + geoPoint.hashCode(); + return result; + } + } } diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/OwnLocationShapeTest.java b/app/src/test/java/org/blitzortung/android/map/overlay/OwnLocationShapeTest.java index b144d259..fbe61f5c 100644 --- a/app/src/test/java/org/blitzortung/android/map/overlay/OwnLocationShapeTest.java +++ b/app/src/test/java/org/blitzortung/android/map/overlay/OwnLocationShapeTest.java @@ -2,6 +2,7 @@ import android.graphics.Canvas; import android.graphics.Paint; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -9,23 +10,23 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; -import static org.mockito.Matchers.*; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyFloat; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @RunWith(RobolectricTestRunner.class) public class OwnLocationShapeTest { + private final int size = 12; @Mock private Canvas canvas; - @Mock private Paint paint; - private OwnLocationShape ownLocationShape; - private final int size = 12; - @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -34,8 +35,7 @@ public void setUp() { } @Test - public void testDraw() - { + public void testDraw() { ownLocationShape.draw(canvas, paint); verify(paint, times(2)).setStyle(any(Paint.Style.class)); diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/ParticipantShapeTest.java b/app/src/test/java/org/blitzortung/android/map/overlay/ParticipantShapeTest.java index 35d5355d..413f9edf 100644 --- a/app/src/test/java/org/blitzortung/android/map/overlay/ParticipantShapeTest.java +++ b/app/src/test/java/org/blitzortung/android/map/overlay/ParticipantShapeTest.java @@ -2,6 +2,7 @@ import android.graphics.Canvas; import android.graphics.Paint; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -17,18 +18,14 @@ @RunWith(RobolectricTestRunner.class) public class ParticipantShapeTest { + private final int color = 0x102030; + private final int size = 12; @Mock private Canvas canvas; - @Mock private Paint paint; - private ParticipantShape participantShape; - private final int color = 0x102030; - - private final int size = 12; - @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -37,8 +34,7 @@ public void setUp() { } @Test - public void testDraw() - { + public void testDraw() { participantShape.draw(canvas, paint); verify(paint, times(1)).setColor(color); diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/ParticipantsOverlayTest.java b/app/src/test/java/org/blitzortung/android/map/overlay/ParticipantsOverlayTest.java index 1dfe36f1..7e7d7108 100644 --- a/app/src/test/java/org/blitzortung/android/map/overlay/ParticipantsOverlayTest.java +++ b/app/src/test/java/org/blitzortung/android/map/overlay/ParticipantsOverlayTest.java @@ -6,9 +6,11 @@ import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.preference.PreferenceManager; + import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; import com.google.common.collect.Lists; + import org.blitzortung.android.data.beans.Station; import org.blitzortung.android.map.OwnMapActivity; import org.blitzortung.android.map.overlay.color.ParticipantColorHandler; @@ -28,21 +30,19 @@ import static org.hamcrest.core.IsNull.notNullValue; import static org.junit.Assert.assertThat; import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) @Config(manifest = "src/main/AndroidManifest.xml", sdk = 19) public class ParticipantsOverlayTest { - @Implements(PreferenceManager.class) - private static class ShadowPreferenceManager { - - @Implementation - public static SharedPreferences getDefaultSharedPreferences(Context context) { - return context.getSharedPreferences("", 0); - } - - } + private final int[] colors = new int[]{1, 2, 3}; private ParticipantsOverlay participantsOverlay; @Mock @@ -54,11 +54,8 @@ public static SharedPreferences getDefaultSharedPreferences(Context context) { @Mock private ParticipantColorHandler colorHandler; - private final int[] colors = new int[]{1,2,3}; - @Before - public void setUp() - { + public void setUp() { MockitoAnnotations.initMocks(this); when(colorHandler.getColors()).thenReturn(colors); @@ -68,14 +65,12 @@ public void setUp() } @Test - public void testConstruct() - { + public void testConstruct() { assertThat(participantsOverlay.size(), is(0)); } @Test - public void testSetParticipants() - { + public void testSetParticipants() { List stations = Lists.newArrayList(); participantsOverlay.setParticipants(stations); @@ -95,8 +90,7 @@ public void testSetParticipants() } @Test - public void testClear() - { + public void testClear() { participantsOverlay.setParticipants(Lists.newArrayList(mock(Station.class))); participantsOverlay.clear(); @@ -105,8 +99,7 @@ public void testClear() } @Test - public void testUpdateZoomLevel() - { + public void testUpdateZoomLevel() { participantsOverlay.updateZoomLevel(-10); //assertThat(participantsOverlay.shapeSize, is(1)); verify(participantsOverlay, times(1)).refresh(); @@ -122,8 +115,7 @@ public void testUpdateZoomLevel() } @Test - public void testRefresh() - { + public void testRefresh() { ParticipantOverlayItem participantOverlayItem = mock(ParticipantOverlayItem.class); participantsOverlay.participants.add(participantOverlayItem); @@ -150,10 +142,9 @@ public void testCreateItem() } @Test - public void testOnTapItem() - { + public void testOnTapItem() { ParticipantOverlayItem participantOverlayItem = mock(ParticipantOverlayItem.class); - GeoPoint point = new GeoPoint(11000000,49000000); + GeoPoint point = new GeoPoint(11000000, 49000000); when(participantOverlayItem.getPoint()).thenReturn(point); when(participantOverlayItem.getTitle()).thenReturn(""); @@ -166,12 +157,21 @@ public void testOnTapItem() } @Test - public void testOnTapMap() - { + public void testOnTapMap() { doReturn(false).when(participantsOverlay).clearPopup(); participantsOverlay.onTap(mock(GeoPoint.class), mock(MapView.class)); verify(participantsOverlay, times(1)).clearPopup(); } + + @Implements(PreferenceManager.class) + private static class ShadowPreferenceManager { + + @Implementation + public static SharedPreferences getDefaultSharedPreferences(Context context) { + return context.getSharedPreferences("", 0); + } + + } } diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/PopupOverlayTest.java b/app/src/test/java/org/blitzortung/android/map/overlay/PopupOverlayTest.java index 81e07647..bda9eb06 100644 --- a/app/src/test/java/org/blitzortung/android/map/overlay/PopupOverlayTest.java +++ b/app/src/test/java/org/blitzortung/android/map/overlay/PopupOverlayTest.java @@ -3,6 +3,7 @@ import android.graphics.drawable.Drawable; import android.view.View; import android.widget.TextView; + import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; import com.google.android.maps.OverlayItem; @@ -17,64 +18,42 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.robolectric.RobolectricGradleTestRunner; -import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(RobolectricGradleTestRunner.class) -@Config(manifest = "src/main/AndroidManifest.xml", sdk = 19, constants=BuildConfig.class) +@Config(manifest = "src/main/AndroidManifest.xml", sdk = 19, constants = BuildConfig.class) public class PopupOverlayTest { - class PopupOverlayItemForTest extends OverlayItem - { - public PopupOverlayItemForTest(GeoPoint geoPoint, String s, String s1) { - super(geoPoint, s, s1); - } - } - - class PopupOverlayForTest extends PopupOverlay<PopupOverlayItemForTest> - { - public PopupOverlayForTest(OwnMapActivity mapActivity, Drawable defaultMarker) - { - super(mapActivity, defaultMarker); - } - - @Override - protected PopupOverlayItemForTest createItem(int i) { - return null; - } - - @Override - public int size() { - return 0; - } - } - private PopupOverlayForTest popupOverlay; - @Mock private OwnMapActivity activity; @Before - public void setUp() - { + public void setUp() { popupOverlay = spy(new PopupOverlayForTest(activity, mock(Drawable.class))); } @Test - public void testSetGetActivity() - { + public void testSetGetActivity() { activity = mock(OwnMapActivity.class); assertThat(popupOverlay.getActivity(), is(activity)); } @Test - public void testShowPopup() - { + public void testShowPopup() { OwnMapView mapView = mock(OwnMapView.class); when(activity.getMapView()).thenReturn(mapView); @@ -98,8 +77,7 @@ public void testShowPopup() } @Test - public void testClearPopup() - { + public void testClearPopup() { OwnMapView mapView = mock(OwnMapView.class); when(activity.getMapView()).thenReturn(mapView); @@ -118,4 +96,26 @@ public void testClearPopup() assertFalse(popupOverlay.popupShown); } + + class PopupOverlayItemForTest extends OverlayItem { + public PopupOverlayItemForTest(GeoPoint geoPoint, String s, String s1) { + super(geoPoint, s, s1); + } + } + + class PopupOverlayForTest extends PopupOverlay<PopupOverlayItemForTest> { + public PopupOverlayForTest(OwnMapActivity mapActivity, Drawable defaultMarker) { + super(mapActivity, defaultMarker); + } + + @Override + protected PopupOverlayItemForTest createItem(int i) { + return null; + } + + @Override + public int size() { + return 0; + } + } } diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/RasterShapeTest.java b/app/src/test/java/org/blitzortung/android/map/overlay/RasterShapeTest.java index 8798e2f8..23d8fadb 100644 --- a/app/src/test/java/org/blitzortung/android/map/overlay/RasterShapeTest.java +++ b/app/src/test/java/org/blitzortung/android/map/overlay/RasterShapeTest.java @@ -4,6 +4,7 @@ import android.graphics.Paint; import android.graphics.Point; import android.graphics.RectF; + import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -14,7 +15,10 @@ import org.robolectric.annotation.Config; import static org.junit.Assert.assertFalse; -import static org.mockito.Matchers.*; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyFloat; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -22,24 +26,17 @@ @Config(manifest = "src/main/AndroidManifest.xml", sdk = 19) public class RasterShapeTest { + private final int color = 0x102030; + private final int multiplicity = 5; + private final int textColor = 0xa0b0c0; @Mock private Canvas canvas; - @Mock private Paint paint; - private Point topLeft = new Point(-3, -3); - private Point bottomRight = new Point(3, 3); - private RasterShape rasterShape; - private final int color = 0x102030; - - private final int multiplicity = 5; - - private final int textColor = 0xa0b0c0; - @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -49,8 +46,7 @@ public void setUp() { } @Test - public void testDraw() - { + public void testDraw() { rasterShape.draw(canvas, paint); verify(paint, times(1)).setColor(color); @@ -64,10 +60,9 @@ public void testDraw() } @Ignore - public void testDrawWithMultiplicityText() - { - topLeft = new Point(-4,-4); - bottomRight = new Point(4,4); + public void testDrawWithMultiplicityText() { + topLeft = new Point(-4, -4); + bottomRight = new Point(4, 4); rasterShape = new RasterShape(); rasterShape.update(topLeft, bottomRight, color, multiplicity, textColor); diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/StrikeOverlayItemTest.java b/app/src/test/java/org/blitzortung/android/map/overlay/StrikeOverlayItemTest.java index c3bb7271..5d37fe32 100644 --- a/app/src/test/java/org/blitzortung/android/map/overlay/StrikeOverlayItemTest.java +++ b/app/src/test/java/org/blitzortung/android/map/overlay/StrikeOverlayItemTest.java @@ -1,6 +1,7 @@ package org.blitzortung.android.map.overlay; import com.google.android.maps.GeoPoint; + import org.blitzortung.android.data.beans.StrikeAbstract; import org.junit.Before; import org.junit.Test; @@ -24,9 +25,9 @@ public class StrikeOverlayItemTest { private StrikeAbstract strike; private long time; + @Before - public void setUp() - { + public void setUp() { MockitoAnnotations.initMocks(this); time = System.currentTimeMillis(); @@ -40,8 +41,7 @@ public void setUp() } @Test - public void testConstruction() - { + public void testConstruction() { GeoPoint point = strikeOverlayItem.getPoint(); assertThat(point.getLongitudeE6(), is(11000000)); @@ -49,17 +49,14 @@ public void testConstruction() } @Test - public void testGetTimestamp() - { + public void testGetTimestamp() { assertThat(strikeOverlayItem.getTimestamp(), is(time)); } @Test - public void testGetMultiplicity() - { + public void testGetMultiplicity() { assertThat(strikeOverlayItem.getMultiplicity(), is(3)); } - } diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/StrikeShapeTest.java b/app/src/test/java/org/blitzortung/android/map/overlay/StrikeShapeTest.java index 7ecd68b4..c50cfe37 100644 --- a/app/src/test/java/org/blitzortung/android/map/overlay/StrikeShapeTest.java +++ b/app/src/test/java/org/blitzortung/android/map/overlay/StrikeShapeTest.java @@ -2,6 +2,7 @@ import android.graphics.Canvas; import android.graphics.Paint; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -19,18 +20,14 @@ @Config(manifest = "src/main/AndroidManifest.xml", sdk = 19) public class StrikeShapeTest { + private final int color = 0x102030; + private final int width = 12; @Mock private Canvas canvas; - @Mock private Paint paint; - private StrikeShape strikeShape; - private final int color = 0x102030; - - private final int width = 12; - @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -40,12 +37,11 @@ public void setUp() { } @Test - public void testDraw() - { + public void testDraw() { strikeShape.draw(canvas, paint); verify(paint, times(1)).setColor(color); - verify(paint, times(1)).setStrokeWidth(width/4); + verify(paint, times(1)).setStrokeWidth(width / 4); verify(canvas, times(2)).drawLine(anyFloat(), anyFloat(), anyFloat(), anyFloat(), eq(paint)); } diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/StrikesOverlayTest.java b/app/src/test/java/org/blitzortung/android/map/overlay/StrikesOverlayTest.java index aa941a73..b4b5b475 100644 --- a/app/src/test/java/org/blitzortung/android/map/overlay/StrikesOverlayTest.java +++ b/app/src/test/java/org/blitzortung/android/map/overlay/StrikesOverlayTest.java @@ -9,6 +9,7 @@ import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.Shape; import android.preference.PreferenceManager; + import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; import com.google.android.maps.Projection; @@ -17,8 +18,8 @@ import org.blitzortung.android.app.BuildConfig; import org.blitzortung.android.data.Parameters; import org.blitzortung.android.data.TimeIntervalWithOffset; -import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.data.beans.RasterParameters; +import org.blitzortung.android.data.beans.StrikeAbstract; import org.blitzortung.android.map.OwnMapActivity; import org.blitzortung.android.map.OwnMapView; import org.blitzortung.android.map.overlay.color.ColorHandler; @@ -29,7 +30,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricGradleTestRunner; -import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; @@ -38,22 +38,22 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.anyInt; +import static org.mockito.Mockito.anyLong; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(RobolectricGradleTestRunner.class) @Config(manifest = "src/main/AndroidManifest.xml", sdk = 19, constants = BuildConfig.class) public class StrikesOverlayTest { - @Implements(PreferenceManager.class) - private static class ShadowPreferenceManager { - - @Implementation - public static SharedPreferences getDefaultSharedPreferences(Context context) { - return context.getSharedPreferences("", 0); - } - - } - + private final int[] colors = new int[]{1, 2, 3}; private StrikesOverlay strikesOverlay; @Mock @@ -68,8 +68,6 @@ public static SharedPreferences getDefaultSharedPreferences(Context context) { @Mock private OwnMapView ownMapView; - private final int[] colors = new int[]{1, 2, 3}; - @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -199,7 +197,6 @@ public void testGetDrawableForRaster() { assertThat(drawable).isInstanceOf(ShapeDrawable.class); } - @Test public void testCreateItem() { final Parameters parameters = Parameters.builder().intervalDuration(100).build(); @@ -239,4 +236,14 @@ public void testOnTapMap() { verify(strikesOverlay, times(1)).clearPopup(); } + + @Implements(PreferenceManager.class) + private static class ShadowPreferenceManager { + + @Implementation + public static SharedPreferences getDefaultSharedPreferences(Context context) { + return context.getSharedPreferences("", 0); + } + + } } diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/color/ColorHandlerTest.java b/app/src/test/java/org/blitzortung/android/map/overlay/color/ColorHandlerTest.java index b5102596..76690af7 100644 --- a/app/src/test/java/org/blitzortung/android/map/overlay/color/ColorHandlerTest.java +++ b/app/src/test/java/org/blitzortung/android/map/overlay/color/ColorHandlerTest.java @@ -1,6 +1,7 @@ package org.blitzortung.android.map.overlay.color; import android.content.SharedPreferences; + import org.blitzortung.android.app.view.PreferenceKey; import org.blitzortung.android.data.TimeIntervalWithOffset; import org.junit.Before; @@ -12,31 +13,19 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) public class ColorHandlerTest { - static class ColorHandlerForTest extends ColorHandler { - - public ColorHandlerForTest(SharedPreferences sharedPreferences) - { - super(sharedPreferences); - } - - @Override - protected int[] getColors(ColorTarget target) { - return new int[0]; - } - } - - private ColorHandler colorHandler; - @Mock SharedPreferences sharedPreferences; - @Mock TimeIntervalWithOffset timeIntervalWithOffset; + private ColorHandler colorHandler; @Before public void setUp() { @@ -49,8 +38,7 @@ public void setUp() { } @Test - public void testGetColors() - { + public void testGetColors() { int[] colors = new int[]{1, 2, 3, 4, 5}; when(colorHandler.getColors()).thenReturn(colors); @@ -60,8 +48,7 @@ public void testGetColors() } @Test - public void testGetColorsForAlternativeMap() - { + public void testGetColorsForAlternativeMap() { when(sharedPreferences.getString("map_mode", ColorTarget.SATELLITE.toString())).thenReturn(ColorTarget.STREETMAP.toString()); colorHandler = spy(new ColorHandlerForTest(sharedPreferences)); @@ -74,8 +61,7 @@ public void testGetColorsForAlternativeMap() } @Test - public void testGetColor() - { + public void testGetColor() { when(colorHandler.getColors()).thenReturn(new int[]{1, 2, 3, 4, 5}); long now = System.currentTimeMillis(); @@ -103,16 +89,14 @@ public void testGetColor() } @Test - public void testGetTextColor() - { + public void testGetTextColor() { assertThat(colorHandler.getTextColor(), is(0xffffffff)); verify(colorHandler, times(1)).getTextColor(ColorTarget.SATELLITE); } @Test - public void testGetTextColorForAlternativeMap() - { + public void testGetTextColorForAlternativeMap() { when(sharedPreferences.getString("map_mode", ColorTarget.SATELLITE.toString())).thenReturn(ColorTarget.STREETMAP.toString()); colorHandler = spy(new ColorHandlerForTest(sharedPreferences)); @@ -120,4 +104,16 @@ public void testGetTextColorForAlternativeMap() verify(colorHandler, times(1)).getTextColor(ColorTarget.STREETMAP); } + + static class ColorHandlerForTest extends ColorHandler { + + public ColorHandlerForTest(SharedPreferences sharedPreferences) { + super(sharedPreferences); + } + + @Override + protected int[] getColors(ColorTarget target) { + return new int[0]; + } + } } diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/color/ParticipantColorHandlerTest.java b/app/src/test/java/org/blitzortung/android/map/overlay/color/ParticipantColorHandlerTest.java index b04c8c25..9226ce1d 100644 --- a/app/src/test/java/org/blitzortung/android/map/overlay/color/ParticipantColorHandlerTest.java +++ b/app/src/test/java/org/blitzortung/android/map/overlay/color/ParticipantColorHandlerTest.java @@ -1,7 +1,7 @@ package org.blitzortung.android.map.overlay.color; import android.content.SharedPreferences; -import org.blitzortung.android.app.Preferences; + import org.blitzortung.android.app.view.PreferenceKey; import org.junit.Before; import org.junit.Test; @@ -19,8 +19,7 @@ public class ParticipantColorHandlerTest { private ParticipantColorHandler participantColorHandler; @Before - public void setUp() - { + public void setUp() { MockitoAnnotations.initMocks(this); when(sharedPreferences.getString(PreferenceKey.MAP_TYPE.toString(), ColorTarget.SATELLITE.toString())).thenReturn(ColorTarget.SATELLITE.toString()); @@ -30,8 +29,7 @@ public void setUp() } @Test - public void testSatelliteColors() - { + public void testSatelliteColors() { int[] colors = participantColorHandler.getColors(ColorTarget.SATELLITE); assertThat(colors.length, is(3)); @@ -39,8 +37,7 @@ public void testSatelliteColors() } @Test - public void testMapColors() - { + public void testMapColors() { int[] colors = participantColorHandler.getColors(ColorTarget.STREETMAP); assertThat(colors.length, is(3)); diff --git a/app/src/test/java/org/blitzortung/android/map/overlay/color/StrikeColorHandlerTest.java b/app/src/test/java/org/blitzortung/android/map/overlay/color/StrikeColorHandlerTest.java index b89ff732..1ead5072 100644 --- a/app/src/test/java/org/blitzortung/android/map/overlay/color/StrikeColorHandlerTest.java +++ b/app/src/test/java/org/blitzortung/android/map/overlay/color/StrikeColorHandlerTest.java @@ -1,6 +1,7 @@ package org.blitzortung.android.map.overlay.color; import android.content.SharedPreferences; + import org.blitzortung.android.app.view.PreferenceKey; import org.junit.Before; import org.junit.Test; @@ -11,7 +12,12 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.anyFloat; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(RobolectricTestRunner.class) public class StrikeColorHandlerTest { @@ -21,8 +27,7 @@ public class StrikeColorHandlerTest { private StrikeColorHandler strikeColorHandler; @Before - public void setUp() - { + public void setUp() { MockitoAnnotations.initMocks(this); when(sharedPreferences.getString(PreferenceKey.MAP_TYPE.toString(), ColorTarget.SATELLITE.toString())).thenReturn(ColorTarget.SATELLITE.toString()); @@ -32,8 +37,7 @@ public void setUp() } @Test - public void testSatelliteColors() - { + public void testSatelliteColors() { int[] colors = strikeColorHandler.getColors(ColorTarget.SATELLITE); assertThat(colors.length, is(6)); @@ -41,8 +45,7 @@ public void testSatelliteColors() } @Test - public void testMapColors() - { + public void testMapColors() { int[] colors = strikeColorHandler.getColors(ColorTarget.STREETMAP); assertThat(colors.length, is(6)); diff --git a/lint.xml b/lint.xml index ee0eead5..049dab6c 100644 --- a/lint.xml +++ b/lint.xml @@ -1,3 +1,2 @@ <?xml version="1.0" encoding="UTF-8"?> -<lint> -</lint> \ No newline at end of file +<lint></lint> \ No newline at end of file