6 Commits
Author SHA1 Message Date
Marcus Handte 220325f1ed Release 1.0.6
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-06-16 23:24:50 +02:00
handte 124f570e9d Prevent non-finite sensor values in sdk.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-06-16 21:04:10 +02:00
handte 77a0ec44c6 Improve handling of broken measurements.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-06-16 20:40:01 +02:00
handte 7e93d8bcdd Extend video api model, reorder app videos.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-06-16 20:15:47 +02:00
handte 585bfc7635 Disable non-release deployments, add color scale tool.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-06-16 09:37:00 +02:00
handte 61501c54ba Update to 1.0.6-SNAPSHOT
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-06-14 23:00:47 +02:00
26 changed files with 930 additions and 104 deletions
Vendored
+9 -6
View File
@@ -21,6 +21,7 @@ node {
}
def version = ''
def release = false;
// configure the deployer based on the version
stage('Configure') {
@@ -28,10 +29,11 @@ node {
println "Version is: '${version}'"
if (version.endsWith("-SNAPSHOT")) {
println "Using internal-snapshots for publication."
gradleBuild.deployer server: server, repo: 'internal-snapshots'
gradleBuild.deployer server: server, repo: 'internal-snapshots'
} else {
println "Using internal-releases for publication."
gradleBuild.deployer server: server, repo: 'internal-releases'
gradleBuild.deployer server: server, repo: 'internal-releases'
release = true;
}
}
@@ -45,25 +47,26 @@ node {
// deploy the maven publications to artifactory
stage ('Publish') {
if (env.BRANCH_NAME == "master") {
if (env.BRANCH_NAME == "master" && release) {
withCredentials([string(credentialsId: 'mowesta-keystore-password', variable: 'PASSWD')]) {
def switches = "-Djenkins.build.number=${env.BUILD_NUMBER} -Dandroid.keystore.password=${PASSWD}".toString()
gradleInfo = gradleBuild.run buildFile: 'build.gradle', tasks: 'artifactoryPublish', switches: switches
}
} else {
echo "Skipping deployment for non-master branch."
echo "Skipping deployment for non-release version or non-master branch."
}
}
// deploy the build output on the server
stage ('Deploy') {
if (env.BRANCH_NAME == "master") {
// release = true; // uncomment to temporary enable snapshot deployments
if (env.BRANCH_NAME == "master" && release) {
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "keyfile")]) {
sh "scp -i ${keyfile} site-ear/build/libs/site-ear-${version}.ear wildfly@apps.nes.uni-due.de:/opt/wildfly-17-mowesta/standalone/deployments/mowesta.ear"
sh "scp -i ${keyfile} android-app/build/outputs/apk/release/*.apk wildfly@apps.nes.uni-due.de:/opt/android/mowesta/"
}
} else {
echo "Skipping deployment for non-master branch."
echo "Skipping deployment for non-release version or non-master branch."
}
}
+1 -1
View File
@@ -88,7 +88,7 @@ android {
applicationId "com.mowesta.android.app"
minSdkVersion 19
targetSdkVersion 29
versionCode 5
versionCode 6
versionName "${version}"
buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -72,6 +72,11 @@ public class MowestaSettings extends SdkSettings {
*/
public static final String SHOW_PRESSURE = "show_pressure";
/**
* The key to a boolean to show/hide the scale on videos.
*/
public static final String SHOW_SCALE = "show_scale";
/**
* Creates the settings with the context.
*
@@ -146,14 +146,14 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
for (int i = 0; i < models.size(); i++) {
SummaryViewModel s = models.get(i);
if (s.getFirstCondition() != null && s.getFirstCondition().getTime() == time) {
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.NavigationRequest.ListType.TIME, i));
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.ForecastType.TIME, i));
break;
}
}
}));
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
if (request == null) return;
if (request.getType() == CityViewModel.NavigationRequest.ListType.DAY) {
if (request.getType() == CityViewModel.ForecastType.DAY) {
recyclerView.post(() -> {
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
model.getNavigation().setValue(null);
@@ -171,14 +171,14 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
ConditionViewModel c = models.get(i);
WeatherCondition wc = c.getCondition().getValue();
if (wc != null && wc.getTime() == time) {
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.NavigationRequest.ListType.HOUR, i));
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.ForecastType.HOUR, i));
break;
}
}
}));
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
if (request == null) return;
if (request.getType() == CityViewModel.NavigationRequest.ListType.TIME) {
if (request.getType() == CityViewModel.ForecastType.TIME) {
recyclerView.post(() -> {
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
model.getNavigation().setValue(null);
@@ -196,14 +196,14 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
SummaryViewModel s = models.get(i);
if (s.getFirstCondition() != null && s.getLastCondition() != null
&& s.getLastCondition().getTime() >= time && s.getFirstCondition().getTime() <= time) {
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.NavigationRequest.ListType.DAY, i));
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.ForecastType.DAY, i));
break;
}
}
}));
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
if (request == null) return;
if (request.getType() == CityViewModel.NavigationRequest.ListType.HOUR) {
if (request.getType() == CityViewModel.ForecastType.HOUR) {
recyclerView.post(() -> {
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
model.getNavigation().setValue(null);
@@ -94,10 +94,8 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
appController.navigate(R.id.destination_station, bundle, opts.build());
}
});
System.out.println("XXXX");
NavController cityController = Navigation.findNavController(getActivity(), R.id.navigation_city);
binding.setConditionListener(m -> {
System.out.println("here");
cityController.navigate(R.id.destination_city_forecast);
});
binding.setLifecycleOwner(getViewLifecycleOwner());
@@ -11,6 +11,7 @@ import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;
@@ -25,6 +26,7 @@ import com.mowesta.android.app.model.CityViewModel;
import com.mowesta.android.app.model.VideoViewModel;
import com.mowesta.android.app.util.TabletUtil;
import java.util.ArrayList;
import java.util.List;
/**
@@ -44,21 +46,33 @@ public class CityVideoFragment extends CityFragment.ChildFragment {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ViewPager2 pager = view.findViewById(R.id.pager);
pager.setAdapter(new VideoAdpter(this));
TabLayout tabs = view.findViewById(R.id.tabs);
new TabLayoutMediator(tabs, pager, (tab, position) -> {
switch (position) {
case 0:
tab.setText(R.string.video_source_icon_global);
break;
case 1:
tab.setText(R.string.video_source_icon_europe);
break;
default:
tab.setText(R.string.video_source_cosmo_europe);
break;
}
}).attach();
List<Integer> pages = new ArrayList<>();
CityViewModel model = getCityViewModel();
Observer<List<VideoViewModel>> videoObserver = (v) -> {
pages.clear();
if (model.getIconGlobal().getValue().size() > 0) pages.add(0, 0);
if (model.getIconEurope().getValue().size() > 0) pages.add(0, 1);
if (model.getCosmoEurope().getValue().size() > 0) pages.add(0, 2);
pager.setAdapter(new VideoAdpter(this, pages));
new TabLayoutMediator(tabs, pager, (tab, position) -> {
int page = pages.get(position);
switch (page) {
case 0:
tab.setText(R.string.video_source_icon_global);
break;
case 1:
tab.setText(R.string.video_source_icon_europe);
break;
default:
tab.setText(R.string.video_source_cosmo_europe);
break;
}
}).attach();
};
model.getCosmoEurope().observe(getViewLifecycleOwner(), videoObserver);
model.getIconEurope().observe(getViewLifecycleOwner(), videoObserver);
model.getIconGlobal().observe(getViewLifecycleOwner(), videoObserver);
}
/**
@@ -68,8 +82,11 @@ public class CityVideoFragment extends CityFragment.ChildFragment {
*/
private static class VideoAdpter extends FragmentStateAdapter {
public VideoAdpter(@NonNull Fragment fragment) {
private List<Integer> pages;
public VideoAdpter(@NonNull Fragment fragment, @NonNull List<Integer> pages) {
super(fragment);
this.pages = pages;
}
@NonNull
@@ -77,14 +94,14 @@ public class CityVideoFragment extends CityFragment.ChildFragment {
public Fragment createFragment(int position) {
VideoRecyclerFragment fragment = new VideoRecyclerFragment();
Bundle bundle = new Bundle();
bundle.putInt("page", position);
bundle.putInt("page", pages.get(position));
fragment.setArguments(bundle);
return fragment;
}
@Override
public int getItemCount() {
return 3;
return pages.size();
}
}
@@ -106,7 +123,7 @@ public class CityVideoFragment extends CityFragment.ChildFragment {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
RecyclerView recyclerView = getView().findViewById(R.id.recycler);
TabletUtil.setGridLayout(recyclerView, 600);
TabletUtil.setGridLayout(recyclerView, 400);
CityViewModel model = getCityViewModel();
int page = getArguments().getInt("page");
VideoViewModel.OnVideoSelectedListener listener = (video) -> {
@@ -1,6 +1,8 @@
package com.mowesta.android.app.fragment;
import android.app.Application;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -9,45 +11,41 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.database.DefaultDatabaseProvider;
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.google.android.exoplayer2.util.Util;
import com.mowesta.android.app.IApp;
import com.mowesta.android.app.MowestaSettings;
import com.mowesta.android.app.R;
import com.mowesta.android.app.adapter.PreferenceLiveData;
import com.mowesta.android.app.model.AbstractNetworkViewModel;
import com.mowesta.android.app.task.ImageTask;
import com.mowesta.android.app.util.ContentScaler;
import com.mowesta.android.app.util.DateFormatter;
import com.mowesta.android.app.util.MercatorPositioner;
import com.mowesta.android.app.util.TimeUtils;
import com.mowesta.android.app.view.MarkerView;
import com.mowesta.android.app.view.WeatherView;
import com.mowesta.android.feign.model.City;
import com.mowesta.android.feign.model.WeatherVideo;
import java.io.File;
import java.io.IOException;
/**
@@ -55,7 +53,7 @@ import java.io.IOException;
*
* @author Marcus
*/
public class VideoFragment extends Fragment {
public class VideoFragment extends AbstractNetworkFragment {
/**
* The log tag.
@@ -219,6 +217,11 @@ public class VideoFragment extends Fragment {
};
@Override
protected AbstractNetworkViewModel getNetworkViewModel() {
return new ViewModelProvider(this).get(ExoPlayerViewModel.class);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@@ -227,15 +230,29 @@ public class VideoFragment extends Fragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
model = new ViewModelProvider(this).get(ExoPlayerViewModel.class);
ImageButton scaleButton = view.findViewById(R.id.video_scale);
ImageButton zoomButton = view.findViewById(R.id.video_zoom);
player = view.findViewById(R.id.video_view);
player.setShowBuffering(PlayerView.SHOW_BUFFERING_ALWAYS);
overlay = view.findViewById(R.id.video_time);
marker = new MarkerView(view.getContext());
marker.setLayoutParams(new FrameLayout.LayoutParams
(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
player.getOverlayFrameLayout().addView(marker);
View frame = LayoutInflater.from(view.getContext()).inflate(R.layout.view_marker, player.getOverlayFrameLayout(), true);
marker = frame.findViewById(R.id.video_marker);
ImageView scaleImage = frame.findViewById(R.id.video_scale_image);
View scaleBackground = frame.findViewById(R.id.video_scale_background);
ImageButton scaleButton = view.findViewById(R.id.video_scale);
scaleButton.setOnClickListener((v) -> {
model.showScale.setValue(!model.showScale.getValue());
});
model.showScale.observe(getViewLifecycleOwner(), (v) -> {
int visible = v?View.VISIBLE:View.GONE;
scaleBackground.setVisibility(visible);
scaleImage.setVisibility(visible);
int img = v?R.drawable.ic_remove_circle_normal_24:R.drawable.ic_remove_circle_outline_normal_24;
int txt = v?R.string.button_hide_scale:R.string.button_show_scale;
scaleButton.setContentDescription(getString(txt));
scaleButton.setImageResource(img);
});
Args args = Args.fromBundle(getArguments());
if (args != null) {
video = args.getVideo();
@@ -262,23 +279,29 @@ public class VideoFragment extends Fragment {
.createMediaSource(Uri.parse(video.getUrl()));
model.exoPlayer.prepare(videoSource);
model.exoPlayer.setPlayWhenReady(true);
model.scaleUrl = video.getScale();
model.reload();
}
player.setPlayer(model.exoPlayer);
model.scaleImage.observe(getViewLifecycleOwner(), (b)-> {
scaleImage.setImageBitmap(b);
});
model.mode.observe(getViewLifecycleOwner(), (mode) -> {
if (mode == ContentScaler.ScaleMode.FIT) {
scaleButton.setImageResource(R.drawable.ic_zoom_out_map_normal_24);
scaleButton.setContentDescription(getString(R.string.button_fill_screen));
zoomButton.setImageResource(R.drawable.ic_zoom_out_map_normal_24);
zoomButton.setContentDescription(getString(R.string.button_fill_screen));
player.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
} else {
scaleButton.setImageResource(R.drawable.ic_aspect_ratio_normal_24);
scaleButton.setContentDescription(getString(R.string.button_fit_screen));
zoomButton.setImageResource(R.drawable.ic_aspect_ratio_normal_24);
zoomButton.setContentDescription(getString(R.string.button_fit_screen));
player.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
}
if (model.markerX != null && model.markerY != null) {
updateVideo(marker.getWidth(), marker.getHeight());
}
});
scaleButton.setOnClickListener((v) -> {
zoomButton.setOnClickListener((v) -> {
model.mode.setValue(model.mode.getValue() == ContentScaler.ScaleMode.FILL?
ContentScaler.ScaleMode.FIT: ContentScaler.ScaleMode.FILL);
});
@@ -349,7 +372,7 @@ public class VideoFragment extends Fragment {
* The view model to store the exo player instance when
* the view is destroyed.
*/
public static class ExoPlayerViewModel extends AndroidViewModel {
public static class ExoPlayerViewModel extends AbstractNetworkViewModel {
/**
* The exo player (initialized only once).
@@ -361,6 +384,11 @@ public class VideoFragment extends Fragment {
*/
final MutableLiveData<ContentScaler.ScaleMode> mode = new MutableLiveData<>(ContentScaler.ScaleMode.FILL);
/**
* A boolean preference to show the scale.
*/
final PreferenceLiveData showScale;
/**
* The relative position of the marker in x.
*/
@@ -376,15 +404,39 @@ public class VideoFragment extends Fragment {
*/
final ContentScaler scaler = new ContentScaler();
/**
* The scale image.
*/
final MutableLiveData<Bitmap> scaleImage = new MutableLiveData<>();
/**
* The weather video's scale image.
*/
String scaleUrl;
/**
* Creates a view model.
*/
public ExoPlayerViewModel(Application application) {
super(application);
MowestaSettings s = new MowestaSettings(application);
showScale = new PreferenceLiveData(s.getPreferences(), MowestaSettings.SHOW_SCALE,
s.getContext().getResources().getBoolean(R.bool.show_scale_defaut));
mode.observeForever((m)->scaler.setMode(m));
}
@Override
public void reload() {
long requestCode = newRequestCode();
scaleImage.setValue(null);
if (scaleUrl != null) {
new ImageTask((url, bitmap)-> {
if (bitmap == null) finishRequest(requestCode, true);
else completeRequest(requestCode, () -> scaleImage.setValue(bitmap));
}).execute(scaleUrl);
}
}
}
}
@@ -47,16 +47,17 @@ public class CityViewModel extends AbstractPlaceViewModel {
void onStationSelected(WeatherStation station);
}
/** The view types to navigate to. */
public enum ForecastType { DAY, TIME, HOUR }
/**
* A navigation request caused by a click on a summary.
*/
public static class NavigationRequest {
/** The view types to navigate to. */
public enum ListType { DAY, TIME, HOUR }
/** The list type to navigate to. */
private @NonNull ListType type;
private @NonNull
ForecastType type;
/** The condition to navigate to. */
private @NonNull int position;
@@ -66,7 +67,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
* @param type The type.
* @param position The position.
*/
public NavigationRequest(@NonNull ListType type, @NonNull int position) {
public NavigationRequest(@NonNull ForecastType type, @NonNull int position) {
this.type = type;
this.position = position;
}
@@ -77,7 +78,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
* @return The type.
*/
@NonNull
public ListType getType() {
public ForecastType getType() {
return type;
}
@@ -183,7 +184,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
(input, status) -> { finishRequest(input, true); });
private final ApiTask<RequestParameter<Long>, List<WeatherVideo>> videoLoader = new ApiTask<>
((input, client) -> client.getLatestCityVideos(input.getValue()),
((input, client) -> client.getLatestCityVideos(input.getValue()),
(input, result) -> { completeRequest(input, () -> videos.setValue(result)); },
(input, status) -> { finishRequest(input, true); });
@@ -253,6 +254,8 @@ public class CityViewModel extends AbstractPlaceViewModel {
forecast.observeForever((c)-> updateConditions());
city.observeForever((c)-> { updateConditions(); updateVideos(); updateLinks(); } );
videos.observeForever((c) -> updateVideos());
}
@Override
@@ -144,7 +144,6 @@ public class LoginViewModel extends AndroidViewModel {
} else {
failure.setValue(R.string.login_failure_network);
}
System.out.println("Failure is: " + status);
});
@@ -0,0 +1,168 @@
package com.mowesta.android.app.model;
import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import java.text.Normalizer;
public class SetupViewModel extends AndroidViewModel {
final MutableLiveData<String> networkName = new MutableLiveData<>("");
final MutableLiveData<FormStatus> networkNameStatus = new MutableLiveData<>();
final MutableLiveData<String> networkPassword = new MutableLiveData<>("");
final MutableLiveData<FormStatus> networkPasswordStatus = new MutableLiveData<>();
final MutableLiveData<String> deviceName = new MutableLiveData<>("");
final MutableLiveData<FormStatus> deviceNameStatus = new MutableLiveData<>();
final MutableLiveData<String> longitude = new MutableLiveData<>("");
final MutableLiveData<FormStatus> longitudeStatus = new MutableLiveData<>();
final MutableLiveData<String> latitude = new MutableLiveData<>("");
final MutableLiveData<FormStatus> latitudeStatus = new MutableLiveData<>();
final MutableLiveData<Boolean> manualPosition = new MutableLiveData<>(Boolean.FALSE);
final MutableLiveData<Boolean> gpsRegistered = new MutableLiveData<>(Boolean.FALSE);
final MutableLiveData<Boolean> gpsEnabled = new MutableLiveData<>(Boolean.TRUE);
final MutableLiveData<Boolean> valid = new MutableLiveData<>(Boolean.FALSE);
/**
* Creates the view model.
*
* @param application The application.
*/
public SetupViewModel(@NonNull Application application) {
super(application);
Observer<Boolean> gpsEnabledListener = (b) -> { gpsEnabled.setValue(!gpsRegistered.getValue() && !manualPosition.getValue()); };
manualPosition.observeForever(gpsEnabledListener);
gpsRegistered.observeForever(gpsEnabledListener);
}
/**
* Returns the live data with the network name.
*
* @return The live data with the network name.
*/
public MutableLiveData<String> getNetworkName() {
return networkName;
}
/**
* Returns the live data with the status for the network name.
*
* @return The live data with the status for the network name.
*/
public MutableLiveData<FormStatus> getNetworkNameStatus() {
return networkNameStatus;
}
/**
* Returns the live data with the network password.
*
* @return The live data with the network password.
*/
public MutableLiveData<String> getNetworkPassword() {
return networkPassword;
}
/**
* Returns the live data with the status for the network password.
*
* @return The live data with the status for the network password.
*/
public MutableLiveData<FormStatus> getNetworkPasswordStatus() {
return networkPasswordStatus;
}
/**
* Returns the live data with the device name.
*
* @return The live data with the device name.
*/
public MutableLiveData<String> getDeviceName() {
return deviceName;
}
/**
* Returns the live data with the status for the device name.
*
* @return The live data with the status for the device name.
*/
public MutableLiveData<FormStatus> getDeviceNameStatus() {
return deviceNameStatus;
}
/**
* The live data with the longitude.
*
* @return The live data with the longitude.
*/
public MutableLiveData<String> getLongitude() {
return longitude;
}
/**
* The live data with the longitude status.
*
* @return The live data with the longitude status.
*/
public MutableLiveData<FormStatus> getLongitudeStatus() {
return longitudeStatus;
}
/**
* The live data with the latitude.
*
* @return The live data with the latitude.
*/
public MutableLiveData<String> getLatitude() {
return latitude;
}
/**
* The live data with the latitude status.
*
* @return The live data with the latitude status.
*/
public MutableLiveData<FormStatus> getLatitudeStatus() {
return latitudeStatus;
}
/**
* The live data with the gps state.
*
* @return The live data with the gps state.
*/
public MutableLiveData<Boolean> getGpsRegistered() {
return gpsRegistered;
}
/**
* The live data with the switch state.
*
* @return The live data with the switch state.
*/
public MutableLiveData<Boolean> getManualPosition() {
return manualPosition;
}
/**
* Returns the enabled state of the gps button.
*
* @return The enabled state of the gps button.
*/
public MutableLiveData<Boolean> getGpsEnabled() {
return gpsEnabled;
}
/**
* Returns the live data with the final validity
* state of the form.
*
* @return The live data with the form validity.
*/
public MutableLiveData<Boolean> getValid() {
return valid;
}
}
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners
android:bottomRightRadius="4dp"
android:bottomLeftRadius="4dp"
android:topLeftRadius="4dp"
android:topRightRadius="4dp"/>
</shape>
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM17,13L7,13v-2h10v2z"/>
</vector>
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M7,11v2h10v-2L7,11zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</vector>
@@ -0,0 +1,233 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="android.view.View" />
<variable
name="model"
type="com.mowesta.android.app.model.SetupViewModel" />
<variable
name="infoButtonListener"
type="Runnable" />
<variable
name="gpsButtonListener"
type="Runnable" />
<variable
name="readyButtonListener"
type="Runnable" />
</data>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/setup_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_medium"
android:text="@string/setup_title"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline4" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/setup_explain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_medium"
android:text="@string/setup_explain"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/setup_button_info"
style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_medium"
android:background="@drawable/ripple_accent_round"
android:clickable="true"
android:focusable="true"
android:onClick="@{ () -> infoButtonListener.run() }"
android:gravity="center"
android:minHeight="48dp"
android:text="@string/setup_link"
android:textColor="@color/primary"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_medium"
android:orientation="horizontal">
<Button
android:id="@+id/setup_button_gps"
android:enabled="@{ model.gpsEnabled }"
android:onClick="@{ () -> gpsButtonListener.run() }"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setup_button_gps" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Switch
android:id="@+id/setup_switch_manual"
android:checked="@={ model.manualPosition }"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setup_button_manual" />
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/setup_longitude"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/space_medium"
android:layout_marginEnd="@dimen/space_medium"
app:err="@{ model.longitudeStatus }"
app:errorEnabled="true"
app:startIconDrawable="@drawable/ic_gps_fixed_normal_24">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_hint_longitude"
android:inputType="numberDecimal|numberSigned"
android:enabled="@{ model.manualPosition }"
android:text="@={model.longitude}" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/setup_latitude"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/space_medium"
android:layout_marginEnd="@dimen/space_medium"
app:err="@{ model.latitudeStatus }"
app:errorEnabled="true"
app:startIconDrawable="@drawable/ic_gps_fixed_normal_24">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_hint_latitude"
android:inputType="numberDecimal|numberSigned"
android:enabled="@{ model.manualPosition }"
android:text="@={model.latitude}" />
</com.google.android.material.textfield.TextInputLayout>
<Space
android:layout_width="0dp"
android:layout_height="@dimen/space_medium"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/setup_network_name"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/space_medium"
android:layout_marginEnd="@dimen/space_medium"
app:counterEnabled="true"
app:counterMaxLength="32"
app:err="@{ model.networkNameStatus }"
app:errorEnabled="true"
app:startIconDrawable="@drawable/ic_wifi_normal_24">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_hint_wlan_name"
android:inputType="text"
android:text="@={model.networkName}" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/setup_network_password"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/space_medium"
android:layout_marginEnd="@dimen/space_medium"
app:counterEnabled="true"
app:endIconMode="password_toggle"
app:err="@{ model.networkPasswordStatus }"
app:errorEnabled="true"
app:startIconDrawable="@drawable/ic_lock_outline_normal_24">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_hint_wlan_password"
android:inputType="textPassword"
android:text="@={model.networkPassword}" />
</com.google.android.material.textfield.TextInputLayout>
<Space
android:layout_width="0dp"
android:layout_height="@dimen/space_medium"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/setup_device_name"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/space_medium"
android:layout_marginEnd="@dimen/space_medium"
app:counterEnabled="true"
app:counterMaxLength="32"
app:err="@{ model.deviceNameStatus }"
app:errorEnabled="true"
app:startIconDrawable="@drawable/ic_memory_black_24dp">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_hint_device_name"
android:inputType="text"
android:text="@={model.deviceName}" />
</com.google.android.material.textfield.TextInputLayout>
<Space
android:layout_width="0dp"
android:layout_height="@dimen/space_medium"/>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/setup_prepare"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_medium"
android:text="@string/setup_prepare"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button_login"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_medium"
android:enabled="@{ model.valid }"
android:onClick="@{ () -> readyButtonListener.run() }"
android:text="@string/setup_button_ready"
app:backgroundTint="@color/accent" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</layout>
@@ -17,6 +17,7 @@
<com.google.android.material.card.MaterialCardView
android:id="@+id/video_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/accent"
@@ -29,25 +30,38 @@
tools:text="Tomorrow\n22.30"
android:id="@+id/video_time"
android:textAppearance="?attr/textAppearanceBody1"
android:minWidth="120dp"
android:minWidth="140dp"
android:padding="8dp"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</com.google.android.material.card.MaterialCardView>
<ImageButton
android:id="@+id/video_scale"
android:id="@+id/video_zoom"
android:background="@drawable/ripple_accent_round"
android:tint="@color/accent"
android:layout_margin="8dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:contentDescription="@string/button_fit_screen"
android:layout_width="48dp"
android:layout_height="48dp"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_aspect_ratio_normal_24" />
<ImageButton
android:id="@+id/video_scale"
android:background="@drawable/ripple_accent_round"
android:tint="@color/accent"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/video_zoom"
android:layout_margin="8dp"
android:contentDescription="@string/button_hide_scale"
android:layout_width="48dp"
android:layout_height="48dp"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_remove_circle_normal_24" />
</RelativeLayout>
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mowesta.android.app.view.MarkerView
android:id="@+id/video_marker"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View
android:id="@+id/video_scale_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_white_round"
android:alpha=".6"
android:layout_alignStart="@id/video_scale_image"
android:layout_alignEnd="@id/video_scale_image"
android:layout_alignTop="@id/video_scale_image"
android:layout_alignBottom="@id/video_scale_image"/>
<ImageView
android:id="@+id/video_scale_image"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="@null"
android:layout_width="290dp"
android:layout_margin="8dp"
android:padding="8dp"
android:adjustViewBounds="true"
android:scaleType="fitEnd"
android:layout_height="wrap_content"
tools:src="@drawable/logo_fair" />
</RelativeLayout>
@@ -19,6 +19,34 @@
<!-- video controls -->
<string name="button_fit_screen">Anzeige anpasen</string>
<string name="button_fill_screen">Anzeige füllen</string>
<string name="button_show_scale">Farbskala anzeigen</string>
<string name="button_hide_scale">Farbskala verbergen</string>
<!-- setup weather station -->
<string name="setup_title">Arduinoeinrichtung</string>
<string name="setup_explain">Für den Fall, dass Du eine Arduino-basierte Wetterstation mit unseren Anleitungen und unserem Code bei Github gebastelt hast, kannst Du sie hier einrichten. Dafür brauchen wir Deinen Standort, Deine Wifieinstellungen und einen Gerätenamen.</string>
<string name="setup_prepare">Bitte schalte Deine Wetterstation ein und halte den Knopf lange gedrückt, um in den Einrichtungsmodus zu wechseln, bevor Du fortfährst.</string>
<string name="setup_link">Du hast keine Ahnung worum es hier geht? <b>Hier</b> findest Du weitere Informationen.</string>
<string name="setup_hint_wlan_name">Netzwerkname</string>
<string name="setup_hint_wlan_password">Netzwerkpasswort</string>
<string name="setup_hint_device_name">Gerätename</string>
<string name="setup_device_name_default">Arduino</string>
<string name="setup_hint_longitude">Längengrad</string>
<string name="setup_hint_latitude">Breitengrad</string>
<string name="setup_button_manual">Manuelle Standorteingabe</string>
<string name="setup_button_gps">GPS-Standort bestimmen</string>
<string name="setup_message_wait_gps">Bestimme GPS-Standort</string>
<string name="setup_message_no_gps">Bitte schalte Deinen GPS-Empfänger ein</string>
<string name="setup_error_longitude">Ungültiger Längengrad, der Wert muss zwischen -180 und +180 Grad liegen.</string>
<string name="setup_error_latitude">Ungültiger Breitengrad, der Wert muss zwischen -90 und +90 Grad liegen.</string>
<string name="setup_message_creating">Erstelle MoWeSta Gerät</string>
<string name="setup_message_searching">Suche nach WiFi Netzwerken</string>
<string name="setup_message_connecting">Verbindung wird hergestellt</string>
<string name="setup_message_transfering">Wetterstation wird eingerichtet</string>
<string name="setup_message_success">Einrichtung abgeschlossen</string>
<string name="setup_message_failed">Einrichtung fehlgeschlagen</string>
<string name="setup_button_try_again">Nochmal versuchen</string>
<string name="setup_button_ready">Fortfahren</string>
<!-- login and register -->
<string name="login_url_register">https://www.mowesta.com/app/de/register</string>
@@ -36,6 +36,7 @@
<bool name="show_snow_default">true</bool>
<bool name="show_pressure_default">true</bool>
<bool name="show_humidity_default">true</bool>
<bool name="show_scale_defaut">true</bool>
<bool name="dark_mode">false</bool>
@@ -19,6 +19,35 @@
<!-- video controls -->
<string name="button_fit_screen">Match screen</string>
<string name="button_fill_screen">Fill screen</string>
<string name="button_show_scale">Show color scale</string>
<string name="button_hide_scale">Hide color scale</string>
<!-- setup weather station -->
<string name="setup_title">Arduino Setup</string>
<string name="setup_explain">If you assembled an Arduino-based weather station using our tutorials and code on Github, you can set it up here. To configure your weather station, we need your location and your Wifi network settings as well as a device name.</string>
<string name="setup_prepare">Please turn on your weather station and long press the button to enter setup mode before you continue.</string>
<string name="setup_link">You don\'t know what this is? <b>Here</b> you can get more information.</string>
<string name="setup_hint_wlan_name">Network name</string>
<string name="setup_hint_wlan_password">Network password</string>
<string name="setup_hint_device_name">Device name</string>
<string name="setup_device_name_default">Arduino</string>
<string name="setup_hint_longitude">Longitude</string>
<string name="setup_hint_latitude">Latitude</string>
<string name="setup_button_manual">Use manual position</string>
<string name="setup_button_gps">Get GPS position</string>
<string name="setup_message_wait_gps">Acquiring position from GPS</string>
<string name="setup_message_no_gps">Please enable your GPS receiver</string>
<string name="setup_error_longitude">Invalid longitude, must range from -180 to +180 degrees.</string>
<string name="setup_error_latitude">Invalid latitude, must range from -90 to +90 degrees.</string>
<string name="setup_message_creating">Creating MoWeSta device</string>
<string name="setup_message_searching">Searching for WiFi networks</string>
<string name="setup_message_connecting">Connecting to WiFi network</string>
<string name="setup_message_transfering">Configuring weather station</string>
<string name="setup_message_success">Setup complete</string>
<string name="setup_message_failed">Setup failed</string>
<string name="setup_button_try_again">Try again</string>
<string name="setup_button_ready">Ready</string>
<!-- login and register -->
<string name="login_url_register">https://www.mowesta.com/app/en/register</string>
@@ -347,12 +347,16 @@ public class MeasureTask extends AsyncTask<Void, Void, Void> {
public void onSensorChanged(SensorEvent event) {
if (event != null && event.values.length > 0) {
double value = event.values[0];
synchronized (running) {
if (running.contains(this)) {
data.put(type, "" + value);
unregisterSensorListener();
running.remove(this);
running.notify();
if (Double.isInfinite(value) || Double.isNaN(value)) {
Log.d(TAG, "Ignoring non-finite sensor value.");
} else {
synchronized (running) {
if (running.contains(this)) {
data.put(type, "" + value);
unregisterSensorListener();
running.remove(this);
running.notify();
}
}
}
}
+1 -1
View File
@@ -29,7 +29,7 @@ allprojects {
// set version for our project
group = 'com.mowesta'
version = '1.0.5'
version = '1.0.6'
// set versions for our libraries
ext {
@@ -122,7 +122,14 @@ public class WeatherVideo {
@ApiModelProperty(value="The url of a preview image.", required=true)
private String preview;
/**
* The url of a preview image.
*/
@XmlAttribute(required = true)
@ApiModelProperty(value="The url of a scale image.", required=true)
private String scale;
/**
* Returns the southWest.
*
@@ -356,7 +363,22 @@ public class WeatherVideo {
public void setPreview(String preview) {
this.preview = preview;
}
/**
* Returns the scale image that accompanies the video.
*
* @return The url of the scale image of the video.
*/
public String getScale() {
return scale;
}
/**
* Sets the scale image url of the video.
*
* @param scale The scale image url of the video.
*/
public void setScale(String scale) {
this.scale = scale;
}
}
@@ -14,6 +14,22 @@ import com.mowesta.data.process.color.IColorScheme;
*/
public class ColorScaleRenderer {
/**
* An interface to generate a label.
*/
public interface LabelProvider {
/**
* Generates the label for a value.
*
* @param value The value.
* @return The label.
*/
String getLabel(double value);
}
/**
* The color scheme to render.
*/
@@ -21,15 +37,21 @@ public class ColorScaleRenderer {
/**
* The minimum value to render.
*/
private double min = -45;
private double min = -40;
/**
* The maximum value to render.
*/
private double max = 45;
private double max = 40;
/**
* The tick at which we render text.
*/
private double tick = 15;
private double tick = 10;
/**
* The label provider.
*/
private LabelProvider provider;
/**
* The text color.
*/
@@ -40,8 +62,9 @@ public class ColorScaleRenderer {
*
* @param colorScheme The scheme to render.
*/
public ColorScaleRenderer(IColorScheme colorScheme) {
public ColorScaleRenderer(IColorScheme colorScheme, LabelProvider provider) {
this.colorScheme = colorScheme;
this.provider = provider;
}
/**
@@ -53,19 +76,20 @@ public class ColorScaleRenderer {
* @param y The y coordinate.
* @param width The width of the scale.
* @param height The height of the scale.
* @param labelFormat A format string to generate the labels.
*/
public void renderColorScale(Graphics2D g, int x, int y, int width, int height, String labelFormat) {
public void renderColorScale(Graphics2D g, int x, int y, int width, int height) {
int scaleHeight = height;
int offsetX = width;
int scaleWidth = 0;
if (labelFormat != null) {
if (provider != null) {
scaleHeight = height - getFontHeight(g);
offsetX = getTextWidth(g, labelFormat, min) / 2;
scaleWidth = width - offsetX - getTextWidth(g, labelFormat, max) / 2;
offsetX = getTextWidth(g, min) / 2;
scaleWidth = width - offsetX - getTextWidth(g, max) / 2;
}
renderScale(g, x + offsetX, y, scaleWidth, scaleHeight);
if (labelFormat != null) renderText(g, labelFormat, x + offsetX, y + height, scaleWidth);
if (provider != null) {
renderText(g, x + offsetX, y + height - g.getFontMetrics().getMaxDescent(), scaleWidth);
}
}
/**
@@ -82,12 +106,11 @@ public class ColorScaleRenderer {
* Computes the text width for the label.
*
* @param g The graphics context.
* @param label The label format.
* @param value The value.
* @return The text width for the rendered text.
*/
private int getTextWidth(Graphics2D g, String label, double value) {
char[] chars = String.format(label, value).toCharArray();
private int getTextWidth(Graphics2D g, double value) {
char[] chars = provider.getLabel(value).toCharArray();
FontMetrics m = g.getFontMetrics();
return m.charsWidth(chars, 0, chars.length);
}
@@ -97,17 +120,16 @@ public class ColorScaleRenderer {
* individual labels will be centered horizontally.
*
* @param g The graphics context.
* @param labelFormat The label format.
* @param x The x coordinate to start.
* @param y The y coordinate to end.
* @param width The width to write.
*/
private void renderText(Graphics2D g, String labelFormat, int x, int y, int width) {
private void renderText(Graphics2D g, int x, int y, int width) {
g.setColor(color);
int shift = (int)(Math.abs(max - min) / (double)tick);
double step = width / shift;
for (int i = 0; i < shift + 1; i++) {
String s = String.format(labelFormat, min + i * tick);
String s = provider.getLabel(min + i * tick);
char[] t = s.toCharArray();
FontMetrics m = g.getFontMetrics();
int offset = m.charsWidth(t, 0, t.length) / 2;
@@ -132,5 +154,41 @@ public class ColorScaleRenderer {
g.drawLine(x + i, y, x + i, y + height);
}
}
/**
* Sets the tick where to draw a value.
*
* @param tick The tick to draw a value.
*/
public void setTick(double tick) {
this.tick = tick;
}
/**
* The maximum value.
*
* @param max The minimum value.
*/
public void setMax(double max) {
this.max = max;
}
/**
* The minimum value.
*
* @param min The minimum value to render.
*/
public void setMin(double min) {
this.min = min;
}
/**
* Sets the text color.
*
* @param color The text color.
*/
public void setColor(Color color) {
this.color = color;
}
}
@@ -54,8 +54,12 @@ public class MeasurementSessionBean extends AbstractUserSpecificSessionBean {
MeasurementEntity existing = MeasurementEntity.findByDeviceAndTime(em, device, m.getTime());
if (existing == null) {
MeasurementEntity e = createMeasurement(device, m);
em.persist(e);
result.add(e);
if (e.getCoordinate() == null) {
log.log(Level.WARNING, "Ignoring measurement without (valid) gps position.", e);
} else {
em.persist(e);
result.add(e);
}
} else {
log.log(Level.WARNING, "Ignoring duplicate upload of measurement " + m.getTime() + " for device " + device.getId() + ".");
result.add(existing);
@@ -101,21 +105,27 @@ public class MeasurementSessionBean extends AbstractUserSpecificSessionBean {
e.setVersion(m.getVersion());
e.setTime(m.getTime());
if (m.getHumidity() != null) {
e.setHumidity(m.getHumidity());
e.setHumidity(getValidDouble("Humidity", m.getHumidity()));
} else {
e.setHumidity(getMeasurementAverage(m, MeasurementType.SENSOR_HUMIDITY));
}
if (m.getPressure() != null) {
e.setPressure(m.getPressure());
e.setPressure(getValidDouble("Pressure", m.getPressure()));
} else {
e.setPressure(getMeasurementAverage(m, MeasurementType.SENSOR_PRESSURE));
}
if (m.getTemperature() != null) {
e.setTemperature(m.getTemperature());
e.setTemperature(getValidDouble("Temperature", m.getTemperature()));
} else {
e.setTemperature(getMeasurementAverage(m, MeasurementType.SENSOR_TEMPERATURE));
}
if (m.getCoordinate() != null) e.setCoordinate(new EmbeddedCoordinate(m.getCoordinate().getLongitude(), m.getCoordinate().getLatitude()));
if (m.getCoordinate() != null) {
Double longitude = getValidDouble("Longitude", m.getCoordinate().getLongitude());
Double latitude = getValidDouble("Latitude", m.getCoordinate().getLatitude());
if (longitude != null && latitude != null) {
e.setCoordinate(new EmbeddedCoordinate(longitude, latitude));
}
}
e.setData(new HashMap<>());
if (m.getData() != null) {
for (Map.Entry<MeasurementType, String> entry: m.getData().entrySet()) {
@@ -142,6 +152,26 @@ public class MeasurementSessionBean extends AbstractUserSpecificSessionBean {
}
return e;
}
/**
* Returns a valid (non-nan and non-infinite) double or null.
*
* @param name The name to log.
* @param value The value to check.
* @return Null or a valid double.
*/
protected Double getValidDouble(String name, Double value) {
if (value == null) return null;
if (value.isNaN()) {
log.log(Level.INFO, "Ignoring NaN in field " + name + ".");
return null;
} else if (value.isInfinite()) {
log.log(Level.INFO, "Ignoring infinite value in field " + name + ".");
return null;
} else {
return value;
}
}
/**
* Computes the average value of the data specified by the
@@ -159,7 +189,7 @@ public class MeasurementSessionBean extends AbstractUserSpecificSessionBean {
for (Object o: data) {
result += (Double)o;
}
return Double.valueOf(result / data.length);
return getValidDouble(t.name(), Double.valueOf(result / data.length));
}
/**
@@ -291,8 +291,7 @@ public class WeatherVideoSyncSessionBean extends AbstractSyncSessionBean {
/**
* Returns the video configuration for the source.
*
* @param source
* The prediction source.
* @param type The prediction type.
* @return The configuration.
*/
protected VideoConfiguration getVideoConfiguration(PredictionType type) {
@@ -439,6 +438,7 @@ public class WeatherVideoSyncSessionBean extends AbstractSyncSessionBean {
v.setTime(getTime(time, type.getHour()));
v.setUrl(DeploymentConstants.URL_VIDEO + name);
v.setPreview(DeploymentConstants.URL_VIDEO + base + ".jpg");
v.setScale(DeploymentConstants.URL_VIDEO + "scale_" + vt.name().toLowerCase() + ".png");
return v;
} catch (IllegalArgumentException e) {
log.log(Level.INFO, "Failed to parse video from file name (" + name + ").", e);
@@ -0,0 +1,94 @@
package com.mowesta.tool.process;
import com.mowesta.data.process.color.CloudDepthColorScheme;
import com.mowesta.data.process.color.PrecipitationColorScheme;
import com.mowesta.data.process.color.PressureColorScheme;
import com.mowesta.data.process.color.ScientificTemperatureColorScheme;
import com.mowesta.data.process.color.WhiteCloudColorScheme;
import com.mowesta.data.process.image.ColorScaleRenderer;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* Generates the scale pictures.
*/
public class ImageScaleGenerator {
public static int WIDTH = 500;
public static int HEIGHT = 50;
public static float FONT_SIZE = 16f;
public static double TEMP_MIN = -40;
public static double TEMP_MAX = 40;
public static double TEMP_TICK = 10;
public static double CLOUD_MIN = 0;
public static double CLOUD_MAX = 1;
public static double CLOUD_TICK = 0.1;
public static double PRECIPITATION_MIN = 0;
public static double PRECIPITATION_MAX = 40;
public static double PRECIPITATION_TICK = 10;
public static double PRESSURE_MIN = -1;
public static double PRESSURE_MAX = 1;
public static double PRESSURE_TICK = 1;
/**
* Generates the scale pictures.
*
*
* @param args The arguments.
*/
public static void main(String[] args) throws IOException {
ColorScaleRenderer temp = new ColorScaleRenderer(new ScientificTemperatureColorScheme(), (v) -> String.format("%.0f°C", v));
temp.setMax(TEMP_MAX);
temp.setMin(TEMP_MIN);
temp.setTick(TEMP_TICK);
render(temp, "C:/users/marcus/desktop/temperature.png");
ColorScaleRenderer cloud = new ColorScaleRenderer(new CloudDepthColorScheme(), (v) -> String.format("%.0f%%", 100 * v));
cloud.setMax(CLOUD_MAX);
cloud.setMin(CLOUD_MIN);
cloud.setTick(CLOUD_TICK);
render(cloud, "C:/users/marcus/desktop/cloud.png");
ColorScaleRenderer precipitation = new ColorScaleRenderer(new PrecipitationColorScheme(), (v) -> String.format("%.0f kg/hm²", v));
precipitation.setMax(PRECIPITATION_MAX);
precipitation.setMin(PRECIPITATION_MIN);
precipitation.setTick(PRECIPITATION_TICK);
render(precipitation, "C:/users/marcus/desktop/precipitation.png");
ColorScaleRenderer pressure = new ColorScaleRenderer(new PressureColorScheme(0, -1, 1), (v) -> {
if (v == 0) return "Ø";
if (v > 0) return "max";
else return "min";
});
pressure.setMax(PRESSURE_MAX);
pressure.setMin(PRESSURE_MIN);
pressure.setTick(PRESSURE_TICK);
render(pressure, "C:/users/marcus/desktop/pressure.png");
}
public static void render(ColorScaleRenderer renderer, String filename) throws IOException {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = image.createGraphics();
graphics.setFont(graphics.getFont().deriveFont(FONT_SIZE).deriveFont(Font.BOLD));
renderer.renderColorScale(graphics, 0, 0, WIDTH, HEIGHT);
ImageIO.write(image, "png", new File(filename));
}
}