8 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
handte f4c9999368 Release 1.0.5
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-06-14 22:24:19 +02:00
handte b681689f09 Update to 1.0.5-SNAPSHOT
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-06-13 00:16:50 +02:00
41 changed files with 1259 additions and 134 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 4
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.
*
@@ -1,10 +1,8 @@
package com.mowesta.android.app.fragment;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
@@ -28,6 +26,7 @@ import com.mowesta.android.app.model.CityViewModel;
import com.mowesta.android.app.model.ConditionViewModel;
import com.mowesta.android.app.model.SummaryViewModel;
import com.mowesta.android.app.util.TabletUtil;
import com.mowesta.android.feign.model.WeatherCondition;
import java.util.List;
@@ -51,7 +50,23 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ViewPager2 pager = view.findViewById(R.id.pager);
CityViewModel model = getCityViewModel();
pager.setAdapter(new ForecastAdapter(this));
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
if (request != null) {
switch (request.getType()) {
case DAY:
pager.setCurrentItem(0, true);
break;
case TIME:
pager.setCurrentItem(1, true);
break;
case HOUR:
pager.setCurrentItem(2, true);
break;
}
}
});
TabLayout tabs = view.findViewById(R.id.tabs);
new TabLayoutMediator(tabs, pager, (tab, position) -> {
switch (position) {
@@ -105,6 +120,9 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
*/
public static class ForecastRecyclerFragment extends CityFragment.ChildFragment {
/** A handler to post updates. */
private Handler handler = new Handler();
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@@ -121,20 +139,107 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
switch (page) {
case 0:
TabletUtil.setGridLayout(recyclerView, 400);
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), getCityViewModel().getDay()));
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), model.getDay(), (summary) -> {
if (summary == null || summary.getFirstCondition() == null) return;
long time = summary.getFirstCondition().getTime();
List<SummaryViewModel> models = model.getTime().getValue();
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.ForecastType.TIME, i));
break;
}
}
}));
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
if (request == null) return;
if (request.getType() == CityViewModel.ForecastType.DAY) {
recyclerView.post(() -> {
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
model.getNavigation().setValue(null);
});
}
});
break;
case 1:
TabletUtil.setGridLayout(recyclerView, 400);
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), getCityViewModel().getTime()));
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), model.getTime(), (summary) -> {
if (summary == null || summary.getFirstCondition() == null) return;
long time = summary.getFirstCondition().getTime();
List<ConditionViewModel> models = model.getHour().getValue();
for (int i = 0; i < models.size(); i++) {
ConditionViewModel c = models.get(i);
WeatherCondition wc = c.getCondition().getValue();
if (wc != null && wc.getTime() == time) {
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.ForecastType.HOUR, i));
break;
}
}
}));
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
if (request == null) return;
if (request.getType() == CityViewModel.ForecastType.TIME) {
recyclerView.post(() -> {
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
model.getNavigation().setValue(null);
});
}
});
break;
default:
TabletUtil.setGridLayout(recyclerView, 250);
recyclerView.setAdapter(new ConditionAdapter(getViewLifecycleOwner(), getCityViewModel().getHour()));
TabletUtil.setGridLayout(recyclerView, 300);
recyclerView.setAdapter(new ConditionAdapter(getViewLifecycleOwner(), getCityViewModel().getHour(), (condition) -> {
if (condition == null || condition.getCondition().getValue() == null) return;
long time = condition.getCondition().getValue().getTime();
List<SummaryViewModel> models = model.getDay().getValue();
for (int i = 0; i < models.size(); i++) {
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.ForecastType.DAY, i));
break;
}
}
}));
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
if (request == null) return;
if (request.getType() == CityViewModel.ForecastType.HOUR) {
recyclerView.post(() -> {
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
model.getNavigation().setValue(null);
});
}
});
break;
}
}
}
/**
* Scrolls a recycler view to the specified position using a smooth scroll effect
* that ist limited in motion.
*
* @param view The view.
* @param position The position.
*/
private static void scrollRecyclerViewToPosition(RecyclerView view, int position) {
GridLayoutManager layout = (GridLayoutManager)view.getLayoutManager();
int current = layout.findFirstVisibleItemPosition();
int last = layout.findLastVisibleItemPosition();
int diff = Math.max(1, last - current) * 3;
if (Math.abs(current - position) > diff) {
if (current < position) current = position - diff;
else current = position + diff;
}
view.scrollToPosition(current);
view.post(() -> {
view.smoothScrollToPosition(position);
});
}
/**
* A recycler view adapter that can display a list of weather summaries.
*
@@ -150,10 +255,22 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
* The live data that provides updates.
*/
private LiveData<List<SummaryViewModel>> model;
/**
* The click listener for the summary model.
*/
private SummaryViewModel.OnSummarySelectedListener listener;
public SummaryAdapter(LifecycleOwner lifecycleOwner, LiveData<List<SummaryViewModel>> model) {
/**
* Creates a new adapter.
*
* @param lifecycleOwner The lifecycle owner.
* @param model The model to observe.
* @param listener The listener to handle clicks.
*/
public SummaryAdapter(LifecycleOwner lifecycleOwner, LiveData<List<SummaryViewModel>> model, SummaryViewModel.OnSummarySelectedListener listener) {
this.lifecycleOwner = lifecycleOwner;
this.model = model;
this.listener = listener;
this.model.observe(lifecycleOwner, (data)-> {
this.notifyDataSetChanged();
});
@@ -164,6 +281,7 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
public SummaryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ViewSummaryBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.view_summary, parent, false);
binding.setLifecycleOwner(lifecycleOwner);
binding.setListener(listener);
SummaryViewHolder holder = new SummaryViewHolder(binding);
return holder;
}
@@ -231,15 +349,21 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
*/
private LiveData<List<ConditionViewModel>> model;
/**
* The listener for the cards.
*/
private ConditionViewModel.OnConditionSelectedListener listener;
/**
* Creates a new adapter for weather conditions.
*
* @param lifecycleOwner The lifecycle owner.
* @param model The list of weather conditions to show.
*/
public ConditionAdapter(LifecycleOwner lifecycleOwner, LiveData<List<ConditionViewModel>> model) {
public ConditionAdapter(LifecycleOwner lifecycleOwner, LiveData<List<ConditionViewModel>> model, ConditionViewModel.OnConditionSelectedListener listener) {
this.lifecycleOwner = lifecycleOwner;
this.model = model;
this.listener = listener;
this.model.observe(lifecycleOwner, (data)-> {
this.notifyDataSetChanged();
});
@@ -250,6 +374,7 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
public ConditionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ViewConditionBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.view_condition, parent, false);
binding.setLifecycleOwner(lifecycleOwner);
binding.setListener(listener);
ConditionViewHolder holder = new ConditionViewHolder(binding);
return holder;
}
@@ -46,6 +46,12 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
FragmentCityInfoBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_city_info, container, false);
MapView mapView = binding.getRoot().findViewById(R.id.map_detail);
MapViewUtil.setupInteractiveMap(mapView);
// reduce brightness of map (technically, we should generate a night mode in leafless but this needs to be fixed in the library)
if (getResources().getBoolean(R.bool.dark_mode)) {
mapView.setAlpha(0.5f);
} else {
mapView.setAlpha(1f);
}
CityViewModel model = new ViewModelProvider(getParentFragment().getParentFragment()).get(CityViewModel.class);
ConditionViewModel condition = new ViewModelProvider(this).get(ConditionViewModel.class);
Runnable updateCondition = () -> {
@@ -77,7 +83,7 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
model.getBoundary().observe(getViewLifecycleOwner(), (b) -> updateMap.run());
binding.setModel(model);
binding.setCondition(condition);
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
NavController appController = Navigation.findNavController(getActivity(), R.id.navigation_app);
binding.setStationListener(new CityViewModel.OnStationSelectedListener() {
@Override
public void onStationSelected(WeatherStation station) {
@@ -85,9 +91,13 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
NavOptions.Builder opts = new NavOptions.Builder().setEnterAnim(R.anim.slide_in_right).setExitAnim(R.anim.slide_out_left);
Bundle bundle = new Bundle();
bundle.putLong("id", station.getId());
controller.navigate(R.id.destination_station, bundle, opts.build());
appController.navigate(R.id.destination_station, bundle, opts.build());
}
});
NavController cityController = Navigation.findNavController(getActivity(), R.id.navigation_city);
binding.setConditionListener(m -> {
cityController.navigate(R.id.destination_city_forecast);
});
binding.setLifecycleOwner(getViewLifecycleOwner());
return binding.getRoot();
}
@@ -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;
@@ -8,45 +10,42 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.view.WindowManager;
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;
/**
@@ -54,7 +53,7 @@ import java.io.IOException;
*
* @author Marcus
*/
public class VideoFragment extends Fragment {
public class VideoFragment extends AbstractNetworkFragment {
/**
* The log tag.
@@ -211,19 +210,18 @@ public class VideoFragment extends Fragment {
double hps = video.getFph() / (double)video.getFps();
long hours = (long)(secs / hps);
long time = video.getTime() + (video.getStart() + hours) * 60 * 60 * 1000;
int dayRes = timeUtils.getDayName(time);
String day;
if (dayRes != 0) {
day = getString(dayRes);
} else {
day = formatter.asDate(time, timezone);
}
String day = timeUtils.getDayName(getContext(), time);
String hour = formatter.asTime(time, timezone);
overlay.setText(getResources().getString(R.string.format_two_lines, day, hour));
handler.postDelayed(this.timer, 500);
};
@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) {
@@ -232,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();
@@ -267,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);
});
@@ -293,6 +311,7 @@ public class VideoFragment extends Fragment {
@Override
public void onResume() {
super.onResume();
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
if (video != null) {
handler.postDelayed(timer, 500);
if (model.markerX != null && model.markerY != null) {
@@ -307,6 +326,7 @@ public class VideoFragment extends Fragment {
@Override
public void onPause() {
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
marker.removeOnLayoutChangeListener(markerListener);
handler.removeCallbacks(timer);
super.onPause();
@@ -352,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).
@@ -364,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.
*/
@@ -379,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);
}
}
}
}
@@ -575,7 +575,7 @@ public class BindingAdapters {
}
@BindingAdapter("datetime")
public static void setGuidelinePosition(@NonNull TextView textView, @Nullable DiagramEntry<?> entry) {
public static void setDiagramDateTime(@NonNull TextView textView, @Nullable DiagramEntry<?> entry) {
if (entry == null) {
textView.setText("");
} else {
@@ -47,6 +47,53 @@ 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 list type to navigate to. */
private @NonNull
ForecastType type;
/** The condition to navigate to. */
private @NonNull int position;
/**
* Creates a new request.
*
* @param type The type.
* @param position The position.
*/
public NavigationRequest(@NonNull ForecastType type, @NonNull int position) {
this.type = type;
this.position = position;
}
/**
* Returns the list type to navigate to.
*
* @return The type.
*/
@NonNull
public ForecastType getType() {
return type;
}
/**
* Returns the position to navigate to.
*
* @return The position.
*/
@NonNull
public int getPosition() {
return position;
}
}
/**
* The current weather condition.
@@ -108,6 +155,11 @@ public class CityViewModel extends AbstractPlaceViewModel {
*/
private final MutableLiveData<Geometry> boundary = new MutableLiveData<>();
/**
* The livedata to handle navigation between the different forecast fragments.
*/
private final MutableLiveData<NavigationRequest> navigation = new MutableLiveData<>();
/**
* The loader for the city data.
*/
@@ -132,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); });
@@ -186,6 +238,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
super(application);
id.observeForever((value) -> {
long code = newRequestCode();
navigation.setValue(null);
favorite.setValue(null);
forecast.setValue(null);
city.setValue(null);
@@ -201,6 +254,8 @@ public class CityViewModel extends AbstractPlaceViewModel {
forecast.observeForever((c)-> updateConditions());
city.observeForever((c)-> { updateConditions(); updateVideos(); updateLinks(); } );
videos.observeForever((c) -> updateVideos());
}
@Override
@@ -220,6 +275,15 @@ public class CityViewModel extends AbstractPlaceViewModel {
return favorite;
}
/**
* Returns the navigation live data to handle transition between views.
*
* @return The navigation.
*/
public MutableLiveData<NavigationRequest> getNavigation() {
return navigation;
}
/**
* Returns the city.
*
@@ -394,8 +458,10 @@ public class CityViewModel extends AbstractPlaceViewModel {
for (WeatherCondition c: wc) {
long end = d.getEnd(c);
ConditionViewModel vm = new ConditionViewModel(getApplication());
int title = d.getDayName(c.getTime());
vm.setData(title == 0 ? null: getApplication().getString(title), null, c, tz);
long time = c.getTime();
String title = d.getDayName(getApplication(), time);
String subtitle = getApplication().getString(R.string.format_two_parts, df.asTime(time, tz), df.asDate(time, tz));
vm.setData(title, subtitle, c, tz);
hours.add(vm);
if (currentDay == null) {
currentDay = new ArrayList<>();
@@ -437,9 +503,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
List<SummaryViewModel> models = new ArrayList<>();
for (List<WeatherCondition> ds: days) {
long time = d.getTime(ds);
String title = df.asDate(time, tz);
int res = d.getDayName(time);
if (res != 0) title = getApplication().getString(res);
String title = d.getDayName(getApplication(), time);
SummaryViewModel summary = new SummaryViewModel(getApplication());
WeatherCondition[] data = new WeatherCondition[ds.size()];
data = ds.toArray(data);
@@ -450,9 +514,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
models = new ArrayList<>();
for (List<WeatherCondition> ts: times) {
long time = d.getTime(ts);
String title = df.asDate(time, tz);
int res = d.getDayName(time);
if (res != 0) title = getApplication().getString(res);
String title = d.getDayName(getApplication(), time);
int slot = d.getSlotName(time);
SummaryViewModel summary = new SummaryViewModel(getApplication());
WeatherCondition[] data = new WeatherCondition[ts.size()];
@@ -18,6 +18,21 @@ import com.mowesta.android.feign.model.WeatherCondition;
*/
public class ConditionViewModel extends CustomizeViewModel {
/**
* A click listener for weather condition cards.
*/
public interface OnConditionSelectedListener {
/**
* Called when the condition is selected.
*
* @param model The condition that has been clicked.
*/
void onConditionSelected(ConditionViewModel model);
}
/**
* The title to display.
*/
@@ -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;
}
}
@@ -18,6 +18,19 @@ import com.mowesta.android.feign.model.WeatherCondition;
*/
public class SummaryViewModel extends CustomizeViewModel {
/**
* A click listener for the summary view model.
*/
public interface OnSummarySelectedListener {
/**
* Called when the summary is selected.
*
* @param model The model with the summary.
*/
void onSummarySelected(SummaryViewModel model);
}
/**
* The minimum values.
*/
@@ -127,6 +140,29 @@ public class SummaryViewModel extends CustomizeViewModel {
updateSubtitle();
}
/**
* Returns the first condition contained in the data or null.
*
* @return The first condition or null.
*/
@Nullable
public WeatherCondition getFirstCondition() {
if (conditions == null || conditions.length < 1) return null;
return conditions[0];
}
/**
* Returns the last condition contained in the data or null.
*
* @return The last condition contained in the data.
*/
@Nullable
public WeatherCondition getLastCondition() {
if (conditions == null || conditions.length < 1) return null;
return conditions[conditions.length - 1];
}
/**
* Determines whether the min and max values are set.
*
@@ -1,9 +1,18 @@
package com.mowesta.android.app.util;
import android.content.Context;
import android.content.res.Resources;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.os.ConfigurationCompat;
import com.mowesta.android.app.R;
import com.mowesta.android.feign.model.WeatherCondition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
@@ -49,20 +58,25 @@ public class TimeUtils {
/**
* Returns the resource id of the "special" day.
*
* @param context The context.
* @param time The time.
* @return The day name.
*/
public int getDayName(long time) {
public String getDayName(Context context, long time) {
c.setTimeInMillis(time);
update(temp1);
if (equals(temp1, yesterday)) {
return R.string.date_yesterday;
return context.getString(R.string.date_yesterday);
} else if (equals(temp1, today)) {
return R.string.date_today;
return context.getString(R.string.date_today);
} else if (equals(temp1, tomorrow)) {
return R.string.date_tomorrow;
return context.getString(R.string.date_tomorrow);
} else {
return 0;
c.setTimeInMillis(time);
SimpleDateFormat sdf = new SimpleDateFormat("EEEE",
ConfigurationCompat.getLocales(context.getResources().getConfiguration()).get(0));
sdf.setCalendar(c);
return sdf.format(new Date(time));
}
}
@@ -2,17 +2,21 @@ package com.mowesta.android.app.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.DrawFilter;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.Gravity;
import androidx.appcompat.widget.AppCompatTextView;
import com.google.android.material.textview.MaterialTextView;
/**
* A text view that draws vertical text.
*
* @author Marcus
*/
public class VerticalTextView extends AppCompatTextView {
public class VerticalTextView extends MaterialTextView {
/**
* The drawing direction.
@@ -73,14 +77,23 @@ public class VerticalTextView extends AppCompatTextView {
@Override
protected void onDraw(Canvas canvas) {
TextPaint textPaint = getPaint();
textPaint.setColor( getCurrentTextColor() );
textPaint.drawableState = getDrawableState();
canvas.save();
if (topDown) {
canvas.translate(getWidth(), 0);
canvas.rotate(90);
} else {
canvas.translate(0, getHeight());
canvas.rotate(-90);
canvas.translate( 0, getHeight() );
canvas.rotate( -90 );
}
canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
getLayout().draw(canvas);
canvas.translate( getCompoundPaddingLeft(),
getExtendedPaddingTop() );
getLayout().draw( canvas );
canvas.setDrawFilter(new DrawFilter() {
});
canvas.restore();
}
}
@@ -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>
@@ -7,6 +7,7 @@
<variable name="model" type="com.mowesta.android.app.model.CityViewModel" />
<variable name="stationListener" type="com.mowesta.android.app.model.CityViewModel.OnStationSelectedListener" />
<variable name="condition" type="com.mowesta.android.app.model.ConditionViewModel" />
<variable name="conditionListener" type="com.mowesta.android.app.model.ConditionViewModel.OnConditionSelectedListener" />
</data>
<androidx.core.widget.NestedScrollView
@@ -35,6 +36,7 @@
android:layout_weight="1"
android:layout_height="wrap_content"
layout="@layout/view_condition"
app:listener="@{conditionListener}"
app:model="@{condition}" />
@@ -7,6 +7,7 @@
<variable name="model" type="com.mowesta.android.app.model.CityViewModel" />
<variable name="stationListener" type="com.mowesta.android.app.model.CityViewModel.OnStationSelectedListener" />
<variable name="condition" type="com.mowesta.android.app.model.ConditionViewModel" />
<variable name="conditionListener" type="com.mowesta.android.app.model.ConditionViewModel.OnConditionSelectedListener" />
</data>
<androidx.core.widget.NestedScrollView
@@ -21,6 +22,7 @@
<include
layout="@layout/view_condition"
app:listener="@{conditionListener}"
app:model="@{condition}" />
<include layout="@layout/view_city_detail"
@@ -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>
@@ -26,7 +26,7 @@
app:boxBackgroundColor="@color/accent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextColor="@color/black"
app:hintTextColor="?attr/colorControlNormal"
app:endIconMode="clear_text"
app:startIconDrawable="@drawable/ic_search_normal_24">
<com.google.android.material.textfield.TextInputEditText
@@ -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>
@@ -7,11 +7,18 @@
<variable
name="model"
type="com.mowesta.android.app.model.ConditionViewModel" />
<variable
name="listener"
type="com.mowesta.android.app.model.ConditionViewModel.OnConditionSelectedListener" />
</data>
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:onClick="@{ () -> listener.onConditionSelected(model) }"
app:rippleColor="@color/accent"
android:visibility="@{ (model.condition == null) ? View.GONE : View.VISIBLE }"
app:cardElevation="4dp"
android:layout_margin="8dp">
@@ -23,15 +23,15 @@
tools:text="10.3.2020\n8.30"
datetime="@{model}"
android:gravity="center|bottom"
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
android:textAppearance="?attr/textAppearanceCaption"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="100dp"/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/black"/>
android:layout_height="1dp"
android:background="@color/inverse"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="36dp"
@@ -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>
@@ -7,11 +7,18 @@
<variable
name="model"
type="com.mowesta.android.app.model.SummaryViewModel" />
<variable
name="listener"
type="com.mowesta.android.app.model.SummaryViewModel.OnSummarySelectedListener" />
</data>
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:onClick="@{ () -> listener.onSummarySelected(model) }"
app:rippleColor="@color/accent"
app:cardElevation="4dp"
android:layout_margin="8dp">
@@ -34,7 +41,7 @@
weatherIcon="@{model.min}"
android:textSize="40dp"/>
<com.mowesta.android.app.view.WeatherView
android:layout_width="80dp"
android:layout_width="70dp"
android:layout_height="60dp"
android:layout_marginEnd="10dp"
android:layout_gravity="center_vertical"
@@ -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>
@@ -2,4 +2,5 @@
<resources>
<color name="separator">#555555</color>
<color name="bg_search">#333333</color>
<color name="inverse">#a0ffffff</color>
</resources>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<bool name="dark_mode">true</bool>
</resources>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="match_parent_limit">
<item name="android:layout_width">520dp</item>
<item name="android:layout_width">510dp</item>
</style>
</resources>
@@ -9,4 +9,5 @@
<color name="accentTransparent">#B0f9a825</color>
<color name="separator">#eeeeee</color>
<color name="bg_search">#fefefe</color>
<color name="inverse">#a0000000</color>
</resources>
@@ -24,6 +24,7 @@
<string name="format_two_names" translatable="false">%s, %s</string>
<string name="format_two_parts" translatable="false">%s | %s</string>
<integer name="terms_version_current">1</integer>
<bool name="development_mode_default">false</bool>
<bool name="privacy_measure_default">false</bool>
@@ -35,7 +36,9 @@
<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.4'
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));
}
}