217 Commits
Author SHA1 Message Date
handte 6137fface2 Release 1.0.19
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-08-08 12:33:53 +02:00
handte 4588941a40 Update to 1.0.19-SNAPSHOT.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-08-08 12:11:58 +02:00
handte b943eb2028 Release 1.0.18
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-08-08 12:03:36 +02:00
handte 80e7a3e800 Ensure widget is updated on Android O.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-08-08 11:37:56 +02:00
handte 51f941f68e Add shadow to color dialog example.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-08-08 11:08:46 +02:00
handte 43a966e81f Add scroll view to color dialog.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-08-08 10:58:26 +02:00
handte e455bec77b Fix threading and video issues.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-08-07 15:18:26 +02:00
handte a7c4e82050 Fix concurrent modification.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-08-07 14:03:41 +02:00
handte 40b2a25633 Support customizable widget colors.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-08-06 15:34:58 +02:00
handte 34dccea36f Set group id and version.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-08-05 18:43:46 +02:00
handte 0c3188dec0 Explicitly set group id for app publication.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2021-08-05 18:31:54 +02:00
handte 21300cb695 Change environment vars.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2021-08-05 18:21:55 +02:00
handte 5afec93cbf Add more debug output to pipeline.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2021-08-05 18:17:42 +02:00
handte 482c4cb1e5 Modify path to include java 11.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2021-08-05 18:15:20 +02:00
handte 40794ccc88 Fix bug in path name.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2021-08-05 18:08:50 +02:00
handte f27f0d39b0 Use Java 11 during build.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2021-08-05 18:06:56 +02:00
handte 5acfb36369 Update gradle, fix and update app.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2021-08-05 17:55:49 +02:00
handte 38573fdc85 Handle longer prediction in d2.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-07-11 15:40:46 +02:00
handte a5ba028d55 Disable temp deployment.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-07-04 11:09:28 +02:00
handte dfa6288272 Change forecast resolution.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-07-04 10:58:25 +02:00
handte b62f6510bb Properly handle changing coordinates.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-07-04 09:46:04 +02:00
handte 5d8539282a Add weather station code for ESP8266.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-15 18:23:18 +02:00
handte e79315ba9f Update to 1.0.18-SNAPSHOT 2021-06-10 22:31:06 +02:00
handte a175a98236 Release 1.0.17
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-10 22:29:07 +02:00
handte 1f619a93db Immediately update widgets on configuration change.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-10 22:15:01 +02:00
handte 9f596c4f2c Fix terms fragement navigation no available in core graph.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-08 13:48:10 +02:00
handte e3105027ae Update to 1.0.17-SNAPSHOT.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-05 12:08:02 +02:00
handte 955230f233 Release 1.0.16
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-04 15:12:50 +02:00
handte c56a601e5c Fix shadow and update preview image.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-04 15:01:54 +02:00
handte 107cff1f86 Improved widget layout, fix refresh timings.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-04 13:29:56 +02:00
handte 89fbc26dd2 Fix null pointer on slow connections.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-03 20:52:23 +02:00
handte 58e5c45ef0 Update to 1.0.16-SNAPSHOT.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-03 19:59:40 +02:00
handte 352941098f Release 1.0.15
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-03 19:48:05 +02:00
handte e132e9cd32 Add widget preview image, reduce output during metadata processing.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-03 18:10:12 +02:00
handte 4e0078846c Finalize Android widgets, add reordering of cities.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-03 16:52:43 +02:00
handte 54bd77e090 Refactor endpoints for beta testing, begin widget implementation.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-06-02 23:21:16 +02:00
handte b4b4eec430 Replace icon fonts with icons.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-05-31 10:50:28 +02:00
handte e338fd6c47 Add metadata processing.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-05-19 14:42:09 +02:00
handte 66550094c8 Added device emulator to simplify testing.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-03-02 17:19:19 +01:00
jahn 1e9d00279f Merge pull request 'Fix android CI paths' (#158) from bugfix/android_ci_fix into master
LocationBasedServices/mowesta/pipeline/head This commit looks good
Reviewed-on: #158
2021-03-01 20:49:10 +01:00
jahn 6bb03cd52a Fix android CI paths
LocationBasedServices/mowesta/pipeline/head Build started...
LocationBasedServices/mowesta/pipeline/pr-master Build queued...
2021-03-01 20:47:56 +01:00
handte dde7331fd4 Merge pull request 'Add build flavors for urls' (#157) from feature/build_flavors into master
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
Reviewed-on: #157
2021-03-01 20:31:04 +01:00
jahn 54a4b3ba49 Add build flavors for urls
LocationBasedServices/mowesta/pipeline/head This commit looks good
LocationBasedServices/mowesta/pipeline/pr-master This commit looks good
2021-03-01 20:11:22 +01:00
boese fa828ad7ed Merge remote-tracking branch 'origin/master'
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-03-01 19:18:07 +01:00
boese e27823545c rename and add comments 2021-03-01 19:17:42 +01:00
jahn 342df70b38 Merge pull request 'feature/city_search' (#156) from feature/city_search into master
LocationBasedServices/mowesta/pipeline/head This commit looks good
Reviewed-on: #156
2021-03-01 19:00:43 +01:00
jahn 077d4ac9ed Fix android for new search location api
LocationBasedServices/mowesta/pipeline/pr-master This commit looks good
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-03-01 18:21:55 +01:00
jahn c56a24b18c Unify searchLocations and searchCities to a single endpoint
LocationBasedServices/mowesta/pipeline/pr-master There was a failure building this commit
2021-03-01 18:13:27 +01:00
jahn 57ac21c2e8 Merging feature/city_search
LocationBasedServices/mowesta/pipeline/pr-master This commit looks good
2021-03-01 17:32:50 +01:00
jahn de0bb9e9c6 City query filters results for cities
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
LocationBasedServices/mowesta/pipeline/pr-master There was a failure building this commit
2021-03-01 16:53:57 +01:00
boese 51e728ddfe clean code, add Condition, add Timespan
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-28 20:25:20 +01:00
boese aa8988bd9c clean code, add comments
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-28 18:27:10 +01:00
jahn 252ee01ca0 WIP city search
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-23 00:43:40 +01:00
boese 1ee872e668 change name of LocationWeatherService.java to AlexaIntentService, add Method for Resourcebundle and Language
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-22 16:33:43 +01:00
boese 5f6f9380e6 add Language_en.properties, fix some bugs
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-22 13:20:27 +01:00
boese 951c149b6b fix white spaces
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-18 22:23:09 +01:00
boese e36909dc06 test white spaces in Language_de.properties
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-18 22:03:13 +01:00
boese b3f6ff816b add all German Strings
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-18 21:34:18 +01:00
boese 3ab92847f5 fix bug in Resourcebundle
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-18 18:38:43 +01:00
boese 6025a0333c fix bug in Resourcebundle test3
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-17 20:52:01 +01:00
boese 37877642da fix bug in Resourcebundle test2
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-17 20:09:12 +01:00
boese 9ce2f9aa27 fix bug in Resourcebundle
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-17 19:42:31 +01:00
boese db788a36eb add Strings_de.properties
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-17 19:28:04 +01:00
boese f8339a36f7 add string properties file for german 2021-02-17 19:26:03 +01:00
handte f26355de41 Cleanup after test and add tool output to gitignore.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-15 16:57:21 +01:00
handte 11d8066a07 Update to 1.0.15-SNAPSHOT.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-15 00:04:22 +01:00
handte 36b5fc7957 Release 1.0.14.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-14 23:37:49 +01:00
handte 8aa383a002 Prevent ejb and war tests to run in parallel.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Add locking to ensure that ejb and war tests are serialized.
Revert changes to arquillian ports since they are useless.
2021-02-14 23:24:56 +01:00
handte 1d3c8335c7 Reduce build duration by running tasks in parallel.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
Allow gradle to execute build tasks in parallel.
Change ejb test ports to enable simultaneous execution with war tests.
2021-02-14 21:59:16 +01:00
handte aeee482128 Fix angular elements component styles.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-14 21:18:26 +01:00
handte 6bf3663c81 Add missing cors rules for resources.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-14 20:52:03 +01:00
handte 48519aefa5 Properly handle bitmaps during import.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-14 20:24:47 +01:00
handte 0d05a03f6e Update to 1.0.14-SNAPSHOT.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-14 18:53:33 +01:00
handte 4bff009cfc Release 1.0.13.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-14 18:50:58 +01:00
handte ba1b5ab29a Fix path names in route servlet.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-14 18:07:36 +01:00
handte 8bfce31f2e Properly compute regular grid coordinates.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-14 17:48:10 +01:00
handte bca818e734 Replace COSMO D2 nwp with ICON D2 nwp.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Remove cosmo d2 since it is no longer computed by DWD.
Add new icon d2 as drop-in replacement for cosmo.
Extend grip decoder to properly handle bitmap section.
Switch icon eu to use icosahedral coordinate system.
Rename inconsistent state boundary endpoint.
2021-02-14 17:23:32 +01:00
handte c95015c234 Update to 1.0.13-SNAPSHOT.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-14 00:14:25 +01:00
handte 3eced06154 Release 1.0.12.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-14 00:12:05 +01:00
handte 894b24a4ff Properly handle predictions that are not updated.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-13 23:51:49 +01:00
boese 5a3b0a62f6 fix bug in weather warning
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-08 21:10:57 +01:00
boese d34a88943a fix speechtext for weather warning
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-08 21:00:08 +01:00
boese 6a611d57d3 add weather warning in LocationWeatherService
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-08 20:48:41 +01:00
handte a3e213eea2 Add script to prepare test database that can be distributed.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-05 19:02:03 +01:00
Tobias Stottrop 9849d7c51e added feat/auth branch to jenkins
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-04 22:59:17 +01:00
boese e3d0122fb0 fix WeatherForecastIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-04 19:24:30 +01:00
boese 549c4b559b fix speechtext in ClothingRecommendationIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-01 19:14:56 +01:00
boese c4b92b734c fix speechtext in WeatherForecastIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-01 19:01:12 +01:00
boese ff763ec44c add Geolocation to ClothingRecommendationIntentHandler, delete logs, fix speechtext
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-01 18:48:09 +01:00
boese 912151ef2d add logs for test
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-01 18:18:01 +01:00
boese f341e8eb10 fix nullpointer
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-01 18:07:37 +01:00
boese 64af6ae5aa fix nullpointer (uppercasecity), add Geolocation to CurrentWeatherIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-01 17:48:47 +01:00
boese 1d64d0bd23 fix nullpointer (uppercasecity)
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-01 17:29:23 +01:00
boese bc19ba5fd0 add Geolocation of the User
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-02-01 16:47:16 +01:00
handte aea6edd08b Adapt dns names to separate production and development.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-30 02:06:36 +01:00
boese 9b62b46e0e Merge remote-tracking branch 'origin/master'
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-28 17:02:41 +01:00
boese dcad963c7c prioritize the weather type for ClothingRecommendationIntentHandler, add comments 2021-01-28 17:02:22 +01:00
handte f66a6e8a49 Change font structure, fix baseHref in angular setup.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Move fonts out of assets since it is not possible to stop angular from hashing it.
Fix wrong baseHref defintion (hopefully).
2021-01-26 15:55:55 +01:00
handte 51931b979f Add baseHref to production build.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-26 10:22:04 +01:00
handte d863b0927e Replace artifactory with nexus, remove string interpolation in Jenkinsfile.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-26 00:19:14 +01:00
boese bfaf634148 fix bugs in ClothingRecommendationIntentHandler, WeatherForecastIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-25 19:26:02 +01:00
boese e8760938af add ClothingRecommendationIntentHandler,ClothingWeatherToStringConverter, LocationWeatherService
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-25 18:41:36 +01:00
boese 5bb3275a54 add time slot to WeatherForecastIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-25 17:19:19 +01:00
handte d5362ff41d Suppress deprecation and fix test warnings in SDK.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-24 20:38:32 +01:00
handte 949a0d2770 Fix type in Android app, downgrade jackson on Android.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-24 20:08:06 +01:00
handte 8af818ffbe Reduce gradle warnings when building android code from command line.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Add workaround to handle Google's broken oss-license-plugin implementation.
Update robolectric to 4.5 to get rid of illegal reflective access warnings.
2021-01-24 19:19:52 +01:00
handte ac8b771ecf Cleanup Angular elements and improve nodejs build scripts to support incremental builds.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Change project structure to get rid of copied assets and configuration files.
Import fonts in css using absolute paths to avoid duplication by webpack pipeline.
Stage output of ng build executions in build directory to separate ng app and elements.
Change concat scripts to assemble final output in dist folder without modifying build directory.
Add video.js files to supported modules (https://github.com/videojs/video.js/issues/6978).
Move baseRef option in angular file to new location to get rid of deprecation warning.
Change name and location of scripts to avoid copying assets.
Change name of custom element to include mowesta brand name as prefix.
2021-01-24 16:25:11 +01:00
handte 3f25520284 Backup with tools to generate traces.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-21 22:38:20 +01:00
boese 2ef558894f fix bug in WeatherForecastIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-21 19:32:21 +01:00
boese b68b63a110 add Region/Land to WeatherForecastIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-21 19:13:52 +01:00
boese 9f2ec5fb38 test WeatherForecastIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-21 18:52:29 +01:00
boese 9564586f97 fix location search
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-21 18:21:07 +01:00
boese 4fdfeec9a5 fix speechtext for country/state to check location search
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-21 17:30:00 +01:00
boese ffb4b56073 fix speechtext in WeatherForecastIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-21 17:13:15 +01:00
boese b0d71102f3 fix WeatherForecastIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-21 16:51:26 +01:00
boese c784c85909 add ForecastWeatherToStringConverter
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-21 16:15:32 +01:00
boese b977a80ecc format temperature
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-21 09:38:21 +01:00
boese f3251a4139 fix location test4, fix WeatherForecastIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-18 21:40:47 +01:00
boese d5b82cddc8 fix location test3
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-18 20:42:29 +01:00
boese 7ad855a4aa fix location test WeatherForecastIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-18 19:47:04 +01:00
boese 9826392819 fix location test2
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-18 19:20:27 +01:00
boese 9e8a519bc7 fix location test1
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-18 18:55:40 +01:00
boese 2029d47b29 Merge remote-tracking branch 'remotes/origin/master' into feature/alexa
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-18 17:56:27 +01:00
boese 0622b4cbc5 fix nullpointer
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-18 17:56:06 +01:00
boese 474432d2a7 add country/state search in CurrentWeatherIntentHandler,
LocationBasedServices/mowesta/pipeline/head This commit looks good
add WeatherForecastIntentHandler
2021-01-18 17:53:59 +01:00
handte 135afc064b Upgrade to 1.0.12-SNAPSHOT.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-18 17:02:32 +01:00
handte 17006aafe3 Release 1.0.11.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-18 16:58:05 +01:00
handte e5aa030857 Disable deployment.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-15 22:54:42 +01:00
handte c8e0a7f16e Fix bugs in wind color scale and deploy to production.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-15 22:52:11 +01:00
boese 35d8f06e5d fix speechtext
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-14 21:09:41 +01:00
boese b967f318c7 add WeatherConditionType,
LocationBasedServices/mowesta/pipeline/head This commit looks good
add WeatherTypeToStringConverter,
fix String output
2021-01-14 20:06:34 +01:00
boese e1f28ffd23 Merge remote-tracking branch 'remotes/origin/master' into feature/alexa
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-13 18:45:37 +01:00
boese 6d5ce170bd add error message
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-13 18:45:02 +01:00
handte 4d1d87d8ef Improve splash screen logos and animation.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-12 10:54:18 +01:00
handte d032e2e577 Workaround to support injection.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-12 09:50:08 +01:00
handte 0a7e33503f Disable deployment again.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-11 22:23:49 +01:00
handte f62c5b41cf Use MHz instead of Hz on Android, deploy to production.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-11 22:22:43 +01:00
boese cdfc018c33 add CurrentWeatherIntentHandler
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-11 21:36:33 +01:00
handte 9a773ca13f Reduce ciss logo size in android app.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-11 19:55:31 +01:00
handte 1b80e9415f Add wind video rendering and app integration.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Extend api with additional weather video type for wind.
Add support for rendering wind videos to backend.
Add support for displaying wind videos to android and web app.
Upgrade android libraries to make lint happy.
Fix linting bugs and warnings related to android layouts.
Fix integer division bug in color scale renderer.
Extend scale generator tool to generate wind scale.
Add BFT wind speed scale to Android app.
Increase temperature resolution in android and web app.
2021-01-11 18:42:25 +01:00
handte 706f24f104 Add ciss and mfund logos to webapp.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-08 23:21:07 +01:00
boese 4029c15eb9 fix problems
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-08 08:50:54 +01:00
handte 6fd3209304 Change ear structure to allow multiple clients for ejb module.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Extract ejb module from war and deploy it individually so that it can be used from multiple jars.
Remove lucene and hibernate jars from ear to ensure that they are loaded from wildfly installation.
Add alexa web module to ear.
Remove swagger ui from alexa context root and replace index html with a simple test message.
Remove .dat files generated during test execution.
Change package name to keep the com.mowesta.service prefix for server-side code.
Remove dead/commented code from build.gralde and web.xml.
2021-01-07 09:10:15 +01:00
boese ffa3ff7d46 change web.xml, HelloWorldSkillServlet
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-06 19:46:53 +01:00
boese 83530a9a41 change Servlet
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-04 19:30:48 +01:00
boese 7ed7d8cfcf add module alexa
LocationBasedServices/mowesta/pipeline/head This commit looks good
2021-01-03 19:47:43 +01:00
boese aff152543c add alexa hello world 2021-01-03 19:37:20 +01:00
handte bb92acc66a Update webapp to Angular 11.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Update web application to use latest Angular version.
Replace 3rd party date range picker with new material implementation.
2020-12-20 22:52:44 +01:00
handte bfad0d8716 Added tool to compute distance to buildings.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-12-18 14:04:17 +01:00
handte a8028ff446 Minimal change to demo jenkins.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-12-15 09:47:21 +01:00
handte 32bcbf3647 Rename projects in Eclipse to avoid collisions, fix warnings and documentation.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-12-11 19:43:08 +01:00
handte 52ff3d660c Omit cities without proper country during import
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-12-02 15:43:45 +01:00
Marcus Handte e794d83ec5 Fix minor typo.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-11-24 21:30:00 +01:00
handte 95b82b133a Add JDNI setting to reduce data volume during testing, update jenkinsfile for beta system.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-11-24 19:48:01 +01:00
handte a66cc3bb0c Replace entity manager customization with custom persistence provider.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-11-24 16:55:11 +01:00
handte 87abaf05c1 Add more debug output to entity manager producer.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-11-24 12:16:16 +01:00
handte 3e575f96e6 Make all filesystem paths configurable via JNDI.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-11-23 14:55:36 +01:00
Marcus Handte a318d10f79 Fix dependency issues.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-11-12 21:40:46 +01:00
Marcus Handte 969d59c4c3 Add missing reactivestreams dependency.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-11-12 19:05:01 +01:00
Marcus Handte 66ba4e0d09 Switch to redhat version. 2020-11-12 18:39:47 +01:00
Marcus Handte e87199c024 Replace infinispan query with embedded.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2020-11-12 18:28:25 +01:00
Marcus Handte 7a6b7084ac Fix build for wildfly 20, upgrade android.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-11-12 17:36:04 +01:00
handte 42ed5a03e1 Upgrade Gradle/Android/Wildfly.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2020-11-09 18:45:37 +01:00
Adriano Markovic 8a564df34f Enhanced progress bar logic on admin's measurements export view.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-08-31 14:41:42 +02:00
handte 746faf92b1 Disable deployment.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-08-17 18:56:49 +02:00
handte de74b222af Increase video compression.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-08-17 18:56:19 +02:00
handte 66daf0c7b7 Disable deployment.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-08-16 13:03:18 +02:00
handte 7e0b4d88d5 Update Android plugin, fix deprecation warnings, enable deployment.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-08-16 12:45:15 +02:00
Adriano Markovic 543b3587eb Added CanDeactivatGuard to /measurements view, added popup dialog on already loaded time period, added cancel function to progress bar.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-08-13 15:10:47 +02:00
handte aa6d0cfab5 Update to 1.0.11-SNAPSHOT.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-08-13 12:34:05 +02:00
handte 84fd69dfdb Release 1.0.10.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-08-13 12:32:11 +02:00
handte 8c174f8581 Change carta urls, change border color on temperature video.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-08-13 12:22:43 +02:00
Adriano Markovic 6bd040272b Modified MeasurementSessionTest.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-08-10 13:02:22 +02:00
Adriano Markovic 2d2caaed09 Stopped initializing test devices and measurements.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-08-08 22:15:11 +02:00
Adriano Markovic cf99d87a66 Added admin measurement map feature to inspect and export measurements from all devices. 2020-08-08 21:55:39 +02:00
Adriano Markovic 778677ec40 DataTestBean modified to setup measurements with different coordinates. 2020-08-08 21:48:59 +02:00
Adriano Markovic 485f56e547 Merge branch 'master' of https://project.nes.uni-due.de/gitea/lbs/mowesta 2020-07-29 11:15:38 +02:00
handte 13080b113b Update device timestamp with new measurement.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-27 17:48:02 +02:00
Adriano Markovic d1fc3bee96 Added ETag caching to the admin endpoint for fetching all measurements. 2020-07-27 16:32:09 +02:00
Adriano Markovic 8bd0cf7bc2 Adjusted the AbstractCanDeactivate class to handle more generic use cases.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-23 01:45:57 +02:00
Adriano Markovic c306987b63 Added can-deactivate.guard for user confirmation on aborting the measurements export.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-23 00:54:30 +02:00
Adriano Markovic 84beb97a73 Implemented frontend export functionality for admin users. 2020-07-22 23:12:55 +02:00
Adriano Markovic 82b7b5544d Added endpoint for admin users for fetching measurements from all devices within a specified time range. 2020-07-22 22:22:29 +02:00
Adriano Markovic 942e42ae76 CorsResponseFilter NullPointerException fixed. 2020-07-22 22:08:18 +02:00
Adriano Markovic ed8846d950 Changed import statement due to build failure caused by circular dependencies between service <-> pipes packages.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-16 21:01:37 +02:00
Adriano Markovic 6bd27b2eff Merge branch 'master' of https://project.nes.uni-due.de/gitea/lbs/mowesta
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2020-07-15 21:54:20 +02:00
Adriano Markovic ef86399ba3 Added non-admin user export functionality to user settings. 2020-07-15 21:54:00 +02:00
handte 6b5f85fe5f Disable deployments.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-15 20:22:14 +02:00
handte 822f4044f7 Improve video rendering performance, change ordering, deploy.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Improve video rendering performance by optimizing drawing operations.
Change video rendering order from high detail to low detail.
Redeploy to production to test rendering tomorrow morning.
2020-07-15 20:20:24 +02:00
handte 7414860ace Update to 1.0.10-SNAPSHOT.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-15 00:33:56 +02:00
handte 582c1c6468 Release 1.0.9
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-15 00:00:00 +02:00
handte 192836a763 Disable deployments.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-14 23:08:10 +02:00
handte 5539048c54 Fix edge cases in algorithms, precompute projections, continue analyzer (wip), deploy.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Add workaround for edge cases in marching squares when edges lie on image borders.
Improve video rendering performance (5x faster) by precomputing projections.
Cleanup scale renderer code and continue work on analyzer (incomplete).
Enable deployement to test performance optimizations.
2020-07-14 23:05:42 +02:00
Adriano Markovic 61bb009959 Added saturn-datepicker package to the web-angular module. 2020-07-14 22:38:30 +02:00
handte 843b52b468 Disable deployment.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-13 20:02:19 +02:00
handte 1487957ea4 Finish video generation, modify video filter in backend, deploy.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Finish integration of isotherms and isobars.
Change filtering of videos to always return latest by category.
Temporarily enable deployment.
2020-07-13 19:58:21 +02:00
handte daf517bc6a Refactored video generation, added isolines.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-13 09:08:50 +02:00
handte c45b14d35a Improve video quality using variable bitrate encoding.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Switch constant bitrate encoding to variable bitrate encoding.
Adjust constant rate factor to balance bitrate and output quality.
2020-07-09 20:19:01 +02:00
handte 4734c0f7b7 Disable deployments.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-07 21:03:31 +02:00
handte 0272fb770e Deploy to server.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-07 21:02:53 +02:00
Adriano Markovic 0b357be701 Added LocationAutocompleteComponent to the weather-search web component project.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-07 17:49:28 +02:00
Adriano Markovic de8a4b8360 Small modification on the condition-map.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2020-07-07 17:28:53 +02:00
Adriano Markovic 83dc34fb53 Added location-autocomplete component.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2020-07-07 17:03:52 +02:00
Adriano Markovic 8a306727a7 Added a search box to the conditions map and refactored the component search-field.
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
2020-07-07 17:02:52 +02:00
handte 3a2eadad70 Disable deployment.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-06 23:10:22 +02:00
handte 6017db7599 Enable deployment, extend nominatim exporter.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-06 23:09:13 +02:00
Marcus Handte bc29648790 Fix build errors due to api update.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-06 18:27:05 +02:00
handte 0ba90a0bb2 Disable deployments.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-04 11:29:08 +02:00
handte 3ec70113e6 Change search ranking and labels in ui.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-04 09:32:29 +02:00
handte 0c3b968aee Update to 1.0.9-SNAPSHOT
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-03 11:23:10 +02:00
handte b7514953a6 Release 1.0.8
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-03 11:09:34 +02:00
handte 0483420af2 Reduce threshold from 75 to 10 percent.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-03 11:06:28 +02:00
handte a72613aa58 Finalize android-app for next release.
LocationBasedServices/mowesta/pipeline/head This commit looks good
Cleanup landscape view.
Fix linting warning.
Fix depcreation warnings.
Avoid object allocation during drawing.
2020-07-03 11:01:31 +02:00
handte b45311404c Finish visualization (finger animation needs updating).
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-07-03 01:02:01 +02:00
handte df19ff4b14 Started with forecast visualization.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-06-29 09:10:41 +02:00
handte fa6f76ba7d Add workaround to improve ux when dragging.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-06-26 21:44:39 +02:00
Marcus Handte 5aee1eb084 Update to 1.0.8-SNAPSHOT.
LocationBasedServices/mowesta/pipeline/head This commit looks good
2020-06-26 17:22:49 +02:00
728 changed files with 31177 additions and 95803 deletions
+4 -1
View File
@@ -17,7 +17,7 @@ target/
.factorypath
# netbeans
nbproject/private/
Bnbproject/private/
# intellij
.idea/
@@ -52,3 +52,6 @@ Package.resolved
#xcode
xcuserdata/
/temp/
#tools
service-tool/dwd-data/
Vendored
+26 -34
View File
@@ -3,17 +3,10 @@
// this groovy script is executed by jenkins
node {
def gradleInfo
def server = Artifactory.server 'project.nes.uni-due.de'
def gradleBuild = Artifactory.newGradleBuild()
gradleBuild.usesPlugin = true
gradleBuild.useWrapper = true
environment {
ANDROID_SDK_ROOT = '/var/lib/android-sdk'
}
// set environment variables
env.ANDROID_SDK_ROOT = '/var/lib/android-sdk'
env.JAVA_HOME = '/opt/openjdk-bin-11'
env.PATH = "${env.JAVA_HOME}/bin:${env.PATH}"
// checkout code from scm
stage('Checkout') {
@@ -26,34 +19,27 @@ node {
// configure the deployer based on the version
stage('Configure') {
version = sh(returnStdout: true, script: "./gradlew properties -q | grep \"version:\" | awk '{print \$2}'", label: "Detecting project version.").trim()
println "Version is: '${version}'"
if (version.endsWith("-SNAPSHOT")) {
println "Using internal-snapshots for publication."
gradleBuild.deployer server: server, repo: 'internal-snapshots'
} else {
println "Using internal-releases for publication."
gradleBuild.deployer server: server, repo: 'internal-releases'
release = true;
}
println "Version is: '${version}'"
release = (! version.endsWith("-SNAPSHOT"))
}
// build the source code with gradle
stage('Build') {
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: 'clean build', switches: switches
sh(script: './gradlew -Djenkins.build.number=' + env.BUILD_NUMBER + ' -Dandroid.keystore.password=$PASSWD clean build', label: "Building project.")
}
}
// deploy the maven publications to artifactory
// deploy the maven publications to nexus
stage ('Publish') {
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
}
if (env.BRANCH_NAME == "master") {
withCredentials([string(credentialsId: 'jenkins-nexus-password', variable: 'NEXUS')]) {
withCredentials([string(credentialsId: 'mowesta-keystore-password', variable: 'PASSWD')]) {
sh(script: './gradlew -Djenkins.build.number=' + env.BUILD_NUMBER + ' -Dandroid.keystore.password=$PASSWD -Djenkins.nexus.password=$NEXUS publishAllPublicationsToMavenRepository', label: "Publishing project.")
}
}
} else {
echo "Skipping deployment for non-release version or non-master branch."
echo "Skipping publication for non-release version or non-master branch."
}
}
@@ -61,12 +47,18 @@ node {
stage ('Deploy') {
// 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/"
}
echo "Deploying to production server ..."
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
sh 'scp -i $KEYFILE site-ear/build/libs/site-ear-' + version + '.ear wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-21-mowesta/standalone/deployments/mowesta.ear'
sh 'scp -i $KEYFILE android-app/build/outputs/apk/prod/release/*.apk wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
}
} else if (env.BRANCH_NAME == "master" || env.BRANCH_NAME == "feat/auth") {
echo "Deploying to beta server ..."
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
sh 'scp -i $KEYFILE site-ear/build/libs/site-ear-' + version + '.ear wildfly@apps-dev.nes.uni-due.de:/opt/wildfly-21-beta/standalone/deployments/mowesta.ear'
}
} else {
echo "Skipping deployment for non-release version or non-master branch."
echo "Skipping deployment for non-master branch."
}
}
+1
View File
@@ -13,3 +13,4 @@ To build the project, you will have to install [Java](http://www.oracle.com/tech
# Jenkins CI
Pull requests and new commits to any branch are automatically built by a Jenkins service. A Gitea webhook informs the service about changes to the repository. In addition, the service will automatically scan the lbs Gitea organization for new repositories every hour. Successful builds of new commits are indicated by a green tick on the commit page. The build status of pull requests is currently not shown in Gitea. However, you can go to the [Jenkins](https://project.nes.uni-due.de/jenkins/job/LocationBasedServices/job/mowesta/) service to view the result of builds including the console output. To modify the build process, you can change the Jenkinsfile groovy script in the root of the repository, if necessary.
+44 -18
View File
@@ -4,32 +4,42 @@ apply plugin: 'com.google.android.gms.oss-licenses-plugin'
description = "Mowesta Android App"
ext {
// android app dependencies
versionPlay = '17.0.0'
versionAndroidXCore = '1.2.0'
versionAndroidXCore = '1.3.1'
versionAndroidXCoreTest = '2.1.0'
versionAndroidXRecycler = '1.1.0'
versionAndroidXRecycler = '1.2.1'
versionAndroidXPaging = '2.1.2'
versionAndroidXCard = '1.0.0'
versionAndroidXCoordinator = '1.1.0'
versionAndroidXConstraint = '1.1.3'
versionAndroidXNavigation = '2.3.0'
versionAndroidXLifecycle = '2.2.0'
versionAndroidXSecurity = '1.1.0-alpha01'
versionAndroidXConstraint = '2.1.0'
versionAndroidXNavigation = '2.3.5'
versionAndroidXLifecycle = '2.3.1'
versionAndroidXSecurity = '1.1.0-alpha03'
versionAndroidXViewpager = '1.0.0'
versionGoogleMaterial = '1.1.0'
versionGoogleMaterial = '1.4.0'
versionAndroidXSwipeRefresh = '1.1.0'
versionExoPlayer = '2.11.5'
versionAndroidXWebkit = '1.4.0'
versionExoPlayer = '2.14.2'
versionApp = project.version
}
// remove project version to workaround bugs in
// oss-license-plugin that detects local libraries
// by checking for a version called "unspecified"
// see DependencyTask.groovy on GitHub at
// https://github.com/google/play-services-plugins
project.version = "unspecified"
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation project(":android-sdk")
implementation "javax.xml.bind:jaxb-api:${versionJaxb}"
implementation "androidx.appcompat:appcompat:${versionAndroidXAppcompat}"
implementation "com.google.android.material:material:${versionGoogleMaterial}"
@@ -51,6 +61,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-service:${versionAndroidXLifecycle}"
implementation "androidx.lifecycle:lifecycle-process:${versionAndroidXLifecycle}"
implementation "androidx.webkit:webkit:${versionAndroidXWebkit}"
implementation "com.google.android.exoplayer:exoplayer-core:${versionExoPlayer}"
implementation "com.google.android.exoplayer:exoplayer-ui:${versionExoPlayer}"
@@ -82,14 +93,15 @@ configurations {
}
}
android {
compileSdkVersion 29
compileSdkVersion 30
defaultConfig {
applicationId "com.mowesta.android.app"
minSdkVersion 19
targetSdkVersion 29
versionCode 7
versionName "${version}"
targetSdkVersion 30
versionCode 19
versionName "${versionApp}"
buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resValue "string", "application_long", "MoWeSta"
@@ -97,6 +109,11 @@ android {
vectorDrawables {
useSupportLibrary = true
}
javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation": "${projectDir}/src/main/sql/".toString()]
}
}
}
signingConfigs {
@@ -119,7 +136,19 @@ android {
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-dbg"
resValue "string", "application_long", "MoWeSta (Debug)"
}
}
flavorDimensions "backend"
productFlavors {
beta {
dimension "backend"
applicationIdSuffix ".beta"
resValue "string", "mowesta_url_default", "https://beta.mowesta.com/api"
resValue "string", "application_long", "B-MoWeSta"
}
prod {
dimension "backend"
resValue "string", "mowesta_url_default", "https://www.mowesta.com/api"
}
}
@@ -141,15 +170,12 @@ android {
abortOnError false
}
dexOptions {
javaMaxHeapSize "512m"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
}
// enable unchecked and deprecation warning during compilation
gradle.projectsEvaluated {
+42 -1
View File
@@ -38,7 +38,21 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MowestaReceiver">
<activity
android:name=".widget.ForecastWidgetActivity"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
<activity
android:name=".widget.MeasureWidgetActivity"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
<receiver android:name=".MowestaReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
@@ -46,6 +60,33 @@
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>
<receiver
android:name=".widget.ForecastWidgetProvider"
android:exported="true"
android:label="@string/widget_forecast_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_forecast" />
</receiver>
<receiver
android:exported="true"
android:name=".widget.MeasureWidgetProvider"
android:label="@string/widget_measure_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_measure" />
</receiver>
<receiver
android:name=".widget.WidgetReceiver"
android:exported="true"/>
<service android:name=".MowestaService" />
<service
android:name=".widget.WidgetService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"/>
</application>
</manifest>
@@ -7,6 +7,7 @@ import com.mowesta.android.app.repository.ClientFactory;
import com.mowesta.android.app.repository.DeviceRepository;
import com.mowesta.android.app.repository.FavoriteRepository;
import com.mowesta.android.app.repository.UserRepository;
import com.mowesta.android.app.repository.WidgetRepository;
/**
* An interface for the application context used
@@ -44,6 +45,13 @@ public interface IApp {
*/
FavoriteRepository getFavoriteRepository();
/**
* Returns a reference to the widget repository.
*
* @return The widget repository.
*/
WidgetRepository getWidgetRepository();
/**
* Returns a reference to the http client factory.
*
@@ -23,6 +23,7 @@ import com.mowesta.android.app.task.DatabaseTask;
import com.mowesta.android.app.task.RefreshTask;
import com.mowesta.android.app.task.SyncTask;
import com.mowesta.android.app.util.PermissionUtil;
import com.mowesta.android.feign.api.DefaultApi;
import java.io.File;
import java.io.IOException;
@@ -44,7 +45,7 @@ public class MowestaActivity extends AppCompatActivity {
/**
* One hour in milliseconds.
*/
private static final int ONE_HOUR = 60*60*1000;
private static final int DELAY_REFRESH = 15 * 60 * 1000;
/**
* The code used to request the permissions.
@@ -68,12 +69,18 @@ public class MowestaActivity extends AppCompatActivity {
protected DatabaseTask<FavoriteDatabase, Void, Long> favoriteTask = new DatabaseTask<>(
(input, database) -> database.getAccessor().getUpdateTime(),
(input, result) -> {
if (result != null && result < System.currentTimeMillis() - ONE_HOUR) {
FavoriteDatabase db = app.getFavoriteRepository().getDatabase();
if (result != null && result < System.currentTimeMillis() - DELAY_REFRESH) {
Log.d(TAG, "Starting automatic favorite synchronization.");
UserCredentials c = app.getUserRepository().getCredentials().getValue();
FavoriteDatabase db = app.getFavoriteRepository().getDatabase();
if (c != null) new SyncTask(db, null).execute(app.getClientFactory().createClient(c));
new RefreshTask(db, null).execute(app.getClientFactory().createClient());
DefaultApi client = app.getClientFactory().createClient(c);
if (c != null) {
new SyncTask(db, (success)-> {
new RefreshTask(db, null).execute(client);
}).execute(client);
} else {
new RefreshTask(db, null).execute(app.getClientFactory().createClient());
}
} else {
Log.d(TAG, "Ignoring request for favorite synchronization since data is up-to-date.");
}
@@ -97,6 +104,10 @@ public class MowestaActivity extends AppCompatActivity {
}
};
public MowestaActivity() {
super(R.layout.activity_app);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -104,7 +115,6 @@ public class MowestaActivity extends AppCompatActivity {
app = (IApp) getApplication();
favoriteTask.execute(null, app.getFavoriteRepository().getDatabase());
settings = app.getSettings();
setContentView(R.layout.activity_app);
installHttpCache();
}
@@ -185,6 +195,7 @@ public class MowestaActivity extends AppCompatActivity {
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case CODE_REQUEST_PERMISSIONS: {
boolean granted = true;
@@ -3,16 +3,26 @@ package com.mowesta.android.app;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.StrictMode;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.upstream.cache.Cache;
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.mowesta.android.app.database.Widget;
import com.mowesta.android.app.repository.ClientFactory;
import com.mowesta.android.app.repository.DeviceRepository;
import com.mowesta.android.app.repository.FavoriteRepository;
import com.mowesta.android.app.repository.UserRepository;
import com.mowesta.android.app.repository.WidgetRepository;
import com.mowesta.android.app.widget.AbstractWidgetProvider;
import com.mowesta.android.app.widget.ForecastWidgetProvider;
import com.mowesta.android.app.widget.MeasureWidgetProvider;
import com.mowesta.android.app.widget.WidgetReceiver;
import java.io.File;
@@ -24,6 +34,13 @@ import java.io.File;
*/
public class MowestaApp extends Application implements IApp {
/**
* The widget providers of the app.
*/
private AbstractWidgetProvider[] widgetProviders = {
new ForecastWidgetProvider(),
new MeasureWidgetProvider()
};
/**
* The user repository.
@@ -40,6 +57,11 @@ public class MowestaApp extends Application implements IApp {
*/
protected FavoriteRepository favoriteRepository;
/**
* The database for the widgets.
*/
protected WidgetRepository widgetRepository;
/**
* The application settings.
*/
@@ -58,9 +80,21 @@ public class MowestaApp extends Application implements IApp {
userRepository = new UserRepository.Builder().setTrace(false).build(this);
deviceRepository = new DeviceRepository.Builder().setTrace(false).build(this);
favoriteRepository = new FavoriteRepository(this);
widgetRepository = new WidgetRepository(this);
MowestaService.startService(this);
WidgetReceiver.updateWidgets(this);
WidgetReceiver.scheduleUpdates(this);
//if(BuildConfig.DEBUG)
// StrictMode.enableDefaults();
}
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
for (int i = widgetProviders.length - 1; i >= 0; i--) {
widgetProviders[i].triggerUpdates(this, false);
}
}
@Override
public Context getContext() {
@@ -80,6 +114,9 @@ public class MowestaApp extends Application implements IApp {
@Override
public FavoriteRepository getFavoriteRepository() { return favoriteRepository; }
@Override
public WidgetRepository getWidgetRepository() { return widgetRepository; }
@Override
public ClientFactory getClientFactory() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
@@ -0,0 +1,100 @@
package com.mowesta.android.app.adapter;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.recyclerview.widget.RecyclerView;
import com.mowesta.android.app.R;
import com.mowesta.android.app.databinding.ViewCityEntryBinding;
import com.mowesta.android.feign.model.City;
import java.util.List;
/**
* An adapter for a recycler view.
*
* @author Marcus
*/
public class CityEntryListAdapter extends RecyclerView.Adapter<CityEntryViewHolder> {
/**
* The listener.
*/
private @NonNull
CityEntryViewHolder.OnCitySelectedListener onCitySelectedListener;
/**
* The owner.
*/
private @NonNull
LifecycleOwner lifecycleOwner;
/**
* The cities to observe for updates.
*/
private @NonNull
LiveData<List<City>> cities;
/**
* The current selection.
*/
private @NonNull
LiveData<City> selection;
/**
* Creates a new adapter.
*
* @param lifecycleOwner The lifecycle owner.
* @param onCitySelectedListener The city selection listener.
*
*/
public CityEntryListAdapter(@NonNull LifecycleOwner lifecycleOwner, @NonNull CityEntryViewHolder.OnCitySelectedListener onCitySelectedListener, LiveData<List<City>> cities, LiveData<City> selection) {
this.setHasStableIds(true);
this.lifecycleOwner = lifecycleOwner;
this.onCitySelectedListener = onCitySelectedListener;
this.cities = cities;
this.selection = selection;
cities.observe(lifecycleOwner, (v)-> notifyDataSetChanged());
selection.observe(lifecycleOwner, (v)-> notifyDataSetChanged());
}
@NonNull
@Override
public CityEntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ViewCityEntryBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.view_city_entry, parent, false);
binding.setLifecycleOwner(lifecycleOwner);
binding.setListener(onCitySelectedListener);
return new CityEntryViewHolder(binding);
}
@Override
public void onBindViewHolder(@NonNull CityEntryViewHolder holder, int position) {
City city = getItem(position);
holder.setModel(city);
holder.setSelected(city != null && selection.getValue() != null && city.getId() != null && city.getId().equals(selection.getValue().getId()));
}
private City getItem(int position) {
List<City> c = cities.getValue();
return (c == null || position >= c.size()) ? null : c.get(position);
}
@Override
public int getItemCount() {
List<City> c = cities.getValue();
return c == null ? 0: c.size();
}
@Override
public long getItemId(int position) {
City c = getItem(position);
if (c == null || c.getId() == null)
return super.getItemId(position);
else return c.getId();
}
}
@@ -22,28 +22,17 @@ import java.util.zip.Inflater;
*/
public class CityEntryPagedListAdapter extends PagedListAdapter<City, CityEntryViewHolder> {
/**
* A listener that is informed when a city is selected.
*/
public interface OnCitySelectedListener {
/**
* Called when a city is selected.
*
* @param city The selected city.
*/
void onCitySelected(City city);
}
/**
* The listener.
*/
private @NonNull OnCitySelectedListener onCitySelectedListener;
private @NonNull
CityEntryViewHolder.OnCitySelectedListener onCitySelectedListener;
/**
* The owner.
*/
private @NonNull LifecycleOwner lifecycleOwner;
private @NonNull
LifecycleOwner lifecycleOwner;
/**
* Creates a new adapter.
@@ -51,7 +40,7 @@ public class CityEntryPagedListAdapter extends PagedListAdapter<City, CityEntryV
* @param lifecycleOwner The lifecycle owner.
* @param onCitySelectedListener The city selection listener.
*/
public CityEntryPagedListAdapter(@NonNull LifecycleOwner lifecycleOwner, @NonNull OnCitySelectedListener onCitySelectedListener) {
public CityEntryPagedListAdapter(@NonNull LifecycleOwner lifecycleOwner, @NonNull CityEntryViewHolder.OnCitySelectedListener onCitySelectedListener) {
super(new Callback());
this.lifecycleOwner = lifecycleOwner;
this.onCitySelectedListener = onCitySelectedListener;
@@ -14,6 +14,20 @@ import com.mowesta.android.feign.model.City;
*/
public class CityEntryViewHolder extends RecyclerView.ViewHolder {
/**
* A listener that is informed when a city is selected.
*
* @author Marcus
*/
public interface OnCitySelectedListener {
/**
* Called when a city is selected.
*
* @param city The selected city.
*/
void onCitySelected(City city);
}
/**
* The binding to update the contents.
@@ -38,4 +52,13 @@ public class CityEntryViewHolder extends RecyclerView.ViewHolder {
public void setModel(City city) {
this.binding.setModel(city);
}
/**
* Marks the city as selected.
*
* @param selected True to select.
*/
public void setSelected(boolean selected) {
this.binding.setSelected(selected);
}
}
@@ -0,0 +1,108 @@
package com.mowesta.android.app.adapter;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.PagedListAdapter;
import androidx.recyclerview.widget.DiffUtil;
import com.mowesta.android.app.R;
import com.mowesta.android.app.databinding.ViewDeviceEntryBinding;
import com.mowesta.android.app.fragment.DevicesFragment;
import com.mowesta.android.app.model.DevicesViewModel;
import com.mowesta.android.feign.model.City;
import com.mowesta.android.feign.model.Device;
/**
* A list adapter to display the list of devices.
*
* @author Marcus
*/
public class DeviceEntryPagedListAdapter extends PagedListAdapter<Device, DeviceEntryViewHolder> {
/**
* The lifecycle owner.
*/
private @NonNull
LifecycleOwner owner;
/**
* The click listener.
*/
private @NonNull
DeviceEntryViewHolder.OnDeviceSelectedListener listener;
/**
* The selected item.
*/
private @NonNull
LiveData<Device> selection;
/**
* Creates a new paged list adapter that will inform
* the listener about click events.
*
* @param owner The lifecycle owner.
* @param listener The listener.
*/
public DeviceEntryPagedListAdapter(@NonNull LifecycleOwner owner, @NonNull DeviceEntryViewHolder.OnDeviceSelectedListener listener) {
this(owner, listener, new MutableLiveData<>(null));
}
/**
* Creates a new paged list adapter that will inform
* the listener about click events and used the specified
* live data to color selections.
*
* @param owner The lifecycle owner.
* @param listener The listener.
* @param selection The current selection.
*/
public DeviceEntryPagedListAdapter(@NonNull LifecycleOwner owner, @NonNull DeviceEntryViewHolder.OnDeviceSelectedListener listener, @NonNull LiveData<Device> selection) {
super(new DeviceCallback());
this.owner = owner;
this.listener = listener;
this.selection = selection;
selection.observe(owner, (s) -> notifyDataSetChanged());
}
@NonNull
@Override
public DeviceEntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ViewDeviceEntryBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.view_device_entry, parent, false);
DeviceEntryViewHolder holder = new DeviceEntryViewHolder(binding);
binding.setListener(listener);
binding.setLifecycleOwner(owner);
return holder;
}
@Override
public void onBindViewHolder(@NonNull DeviceEntryViewHolder holder, int position) {
Device device = getItem(position);
holder.setModel(device);
holder.setSelected(device != null && selection.getValue() != null && device.getId() != null && device.getId().equals(selection.getValue().getId()));
}
/**
* A callback to determine whether two devices are the same.
*
* @author Marcus
*/
public static class DeviceCallback extends DiffUtil.ItemCallback<Device> {
@Override
public boolean areItemsTheSame(@NonNull Device oldItem, @NonNull Device newItem) {
return oldItem.getId() != null && oldItem.getId().equals(newItem.getId());
}
@Override
public boolean areContentsTheSame(@NonNull Device oldItem, @NonNull Device newItem) {
return oldItem.getId() != null && oldItem.getId().equals(newItem.getId());
}
}
}
@@ -0,0 +1,63 @@
package com.mowesta.android.app.adapter;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.mowesta.android.app.databinding.ViewDeviceEntryBinding;
import com.mowesta.android.feign.model.Device;
/**
* The view holder for the list of devices
*
* @author Marcus
*/
public class DeviceEntryViewHolder extends RecyclerView.ViewHolder {
/**
* A listener that is informed when a device is selected.
*/
public interface OnDeviceSelectedListener {
/**
* Called when a device is selected.
*
* @param device The selected device.
*/
void onDeviceSelected(Device device);
}
/**
* The binding with the device view.
*/
private ViewDeviceEntryBinding binding;
/**
* Creates a new view holder for the binding.
*
* @param binding The binding.
*/
public DeviceEntryViewHolder(@NonNull ViewDeviceEntryBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
/**
* Sets the model.
*
* @param device The device.
*/
public void setModel(Device device) {
this.binding.setModel(device);
}
/**
* Marks the city as selected.
*
* @param selected True to select.
*/
public void setSelected(boolean selected) {
this.binding.setSelected(selected);
}
}
@@ -11,7 +11,7 @@ import androidx.recyclerview.widget.DiffUtil;
import com.mowesta.android.app.R;
import com.mowesta.android.app.databinding.ViewDiagramEntryBinding;
import com.mowesta.android.app.model.DiagramEntry;
import com.mowesta.android.app.binding.DiagramEntry;
/**
* A paged list adapter for diagram entries.
@@ -3,7 +3,7 @@ package com.mowesta.android.app.adapter;
import androidx.recyclerview.widget.RecyclerView;
import com.mowesta.android.app.databinding.ViewDiagramEntryBinding;
import com.mowesta.android.app.model.DiagramEntry;
import com.mowesta.android.app.binding.DiagramEntry;
/**
* A view holder for recycler views that contain diagram entries.
@@ -2,6 +2,7 @@ package com.mowesta.android.app.arduino;
import android.app.Application;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
@@ -48,7 +49,7 @@ public abstract class NetworkTask {
/**
* A handler to register the timeout.
*/
protected @NonNull Handler handler = new Handler();
protected @NonNull Handler handler = new Handler(Looper.getMainLooper());
/**
@@ -4,20 +4,20 @@ import android.app.Application;
import android.content.Context;
import android.net.DhcpInfo;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull;
import com.mowesta.android.sdk.task.AbstractTask;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
@@ -76,7 +76,7 @@ public class TransferTask {
/**
* The handler to post the result.
*/
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
/**
* Creates a new task.
@@ -110,7 +110,7 @@ public class TransferTask {
*/
public void execute() {
WifiManager manager = (WifiManager)application.getSystemService(Context.WIFI_SERVICE);
AsyncTask.SERIAL_EXECUTOR.execute(() -> {
AbstractTask.SERIAL_EXECUTOR.execute(() -> {
try {
// sleep for a couple of seconds, since it
// will take some time to get an ip address
@@ -6,8 +6,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.NetworkInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.util.Log;
@@ -55,7 +53,7 @@ public class WifiTask extends NetworkTask {
if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
Log.d(TAG, "Received network state changed.");
if (intent.hasExtra(WifiManager.EXTRA_NETWORK_INFO)) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
android.net.NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (info != null) {
Log.d(TAG, "Received network info: " + info);
if (info.isConnected() && isWifiConnected()) {
@@ -119,7 +117,7 @@ public class WifiTask extends NetworkTask {
Log.d(TAG, "Wifi was disabled, turning it on.");
didEnableWifi = manager.setWifiEnabled(true);
}
WifiConfiguration existing = findConfiguration();
android.net.wifi.WifiConfiguration existing = findConfiguration();
if (existing == null) {
networkId = manager.addNetwork(createConfiguration());
manager.saveConfiguration();
@@ -171,8 +169,8 @@ public class WifiTask extends NetworkTask {
*/
private int getMaximumPriority() throws SecurityException {
int result = 1;
List<WifiConfiguration> configurations = manager.getConfiguredNetworks();
for (WifiConfiguration configuration: configurations) {
List<android.net.wifi.WifiConfiguration> configurations = manager.getConfiguredNetworks();
for (android.net.wifi.WifiConfiguration configuration: configurations) {
result = Math.max(result, configuration.priority);
}
return result;
@@ -184,10 +182,10 @@ public class WifiTask extends NetworkTask {
* @return The network configuration, if present already.
* @throws SecurityException Thrown if we are missing a permission.
*/
private WifiConfiguration findConfiguration() throws SecurityException {
private android.net.wifi.WifiConfiguration findConfiguration() throws SecurityException {
String ssid = getSsid();
List<WifiConfiguration> configurations = manager.getConfiguredNetworks();
for (WifiConfiguration configuration: configurations) {
List<android.net.wifi.WifiConfiguration> configurations = manager.getConfiguredNetworks();
for (android.net.wifi.WifiConfiguration configuration: configurations) {
if (ssid.equals(configuration.SSID)) {
return configuration;
}
@@ -200,19 +198,19 @@ public class WifiTask extends NetworkTask {
*
* @return The network configuration.
*/
private WifiConfiguration createConfiguration() {
WifiConfiguration result = new WifiConfiguration();
private android.net.wifi.WifiConfiguration createConfiguration() {
android.net.wifi.WifiConfiguration result = new android.net.wifi.WifiConfiguration();
result.SSID = getSsid();
result.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
result.allowedProtocols.set(WifiConfiguration.Protocol.RSN); // For WPA2
result.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
result.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
result.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
result.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
result.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
result.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
result.allowedAuthAlgorithms.set(android.net.wifi.WifiConfiguration.AuthAlgorithm.OPEN);
result.allowedProtocols.set(android.net.wifi.WifiConfiguration.Protocol.RSN); // For WPA2
result.allowedKeyManagement.set(android.net.wifi.WifiConfiguration.KeyMgmt.WPA_PSK);
result.allowedKeyManagement.set(android.net.wifi.WifiConfiguration.KeyMgmt.WPA_EAP);
result.allowedPairwiseCiphers.set(android.net.wifi.WifiConfiguration.PairwiseCipher.TKIP);
result.allowedPairwiseCiphers.set(android.net.wifi.WifiConfiguration.PairwiseCipher.CCMP);
result.allowedGroupCiphers.set(android.net.wifi.WifiConfiguration.GroupCipher.TKIP);
result.allowedGroupCiphers.set(android.net.wifi.WifiConfiguration.GroupCipher.CCMP);
result.preSharedKey = String.format("\"%s\"", ArduinoConfig.ARDUINO_PWD);
result.status = WifiConfiguration.Status.ENABLED;
result.status = android.net.wifi.WifiConfiguration.Status.ENABLED;
try {
int priority = getMaximumPriority() + 400;
Log.d(TAG, "Setting maximum priority to " + priority + ".");
@@ -1,9 +1,7 @@
package com.mowesta.android.app.model;
package com.mowesta.android.app.binding;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
@@ -12,16 +10,14 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.TooltipCompat;
import androidx.constraintlayout.widget.Guideline;
import androidx.core.text.HtmlCompat;
import androidx.databinding.BindingAdapter;
import com.google.android.material.textfield.TextInputLayout;
import com.mowesta.android.app.R;
import com.mowesta.android.app.database.Favorite;
import com.mowesta.android.app.model.FormStatus;
import com.mowesta.android.app.util.DateFormatter;
import com.mowesta.android.app.util.UnitUtils;
import com.mowesta.android.app.view.WeatherIcon;
import com.mowesta.android.app.view.WeatherView;
import com.mowesta.android.feign.model.City;
import com.mowesta.android.feign.model.Country;
import com.mowesta.android.feign.model.Device;
@@ -478,15 +474,19 @@ public class BindingAdapters {
* @param condition The weather condition.
*/
@BindingAdapter("weatherIcon")
public static void setWeatherIcon(WeatherView view, @Nullable WeatherCondition condition) {
if (condition == null || condition.getType() == null) {
view.setText("");
public static void setWeatherIcon(ImageView view, @Nullable WeatherCondition condition) {
Integer resource = null;
if (condition != null && condition.getType() != null) {
resource = BindingTransforms.getIcon(condition.getType(), false);
}
if (resource == null) {
view.setImageResource(android.R.color.transparent);
view.setContentDescription(null);
TooltipCompat.setTooltipText(view, null);
} else {
int res = BindingTransforms.getText(condition.getType());
String str = view.getContext().getString(res);
view.setType(BindingTransforms.getIcon(condition.getType(), false));
view.setImageResource(resource);
view.setContentDescription(str);
TooltipCompat.setTooltipText(view, str);
}
@@ -499,16 +499,16 @@ public class BindingAdapters {
* @param condition The weather condition.
*/
@BindingAdapter("directionIcon")
public static void setDirectionIcon(WeatherView view, @Nullable WeatherCondition condition) {
public static void setDirectionIcon(ImageView view, @Nullable WeatherCondition condition) {
if (condition == null || condition.getWindDirection() == null) {
view.setType(null);
view.setImageResource(android.R.color.transparent);
view.setRotation(0);
view.setContentDescription(null);
TooltipCompat.setTooltipText(view, null);
} else {
int res = BindingTransforms.getText(condition.getWindDirection());
String str = view.getContext().getString(res);
view.setType(WeatherIcon.WIND_DIRECTION);
view.setImageResource(R.drawable.ic_wind_deg_normal_24);
view.setRotation(BindingTransforms.getRotation(condition.getWindDirection()));
view.setContentDescription(str);
TooltipCompat.setTooltipText(view, str);
@@ -817,7 +817,7 @@ public class BindingAdapters {
@BindingAdapter("measurementValue")
public static void setMeasurementValue(TextView view, @Nullable MeasurementViewModel.MeasurementValue value) {
public static void setMeasurementValue(TextView view, @Nullable MeasurementValue value) {
Resources r = view.getContext().getResources();
if (value == null || !value.hasValue()) {
view.setText(null);
@@ -832,7 +832,7 @@ public class BindingAdapters {
} else if (o instanceof Double) {
switch (value.getType()) {
case CPU_FREQUENCY:
valueText = r.getString(R.string.format_frequency, ((Double)o).floatValue());
valueText = r.getString(R.string.format_frequency, ((Double)o).floatValue() / 1000000);
break;
case SOLAR_VOLTAGE:
case BATTERY_VOLTAGE:
@@ -868,7 +868,7 @@ public class BindingAdapters {
}
@BindingAdapter("measurementVisibility")
public static void setMeasurementVisibility(View view, @Nullable MeasurementViewModel.MeasurementValue value) {
public static void setMeasurementVisibility(View view, @Nullable MeasurementValue value) {
if (value == null || !value.hasValue()) {
view.setVisibility(View.GONE);
} else {
@@ -1,4 +1,4 @@
package com.mowesta.android.app.model;
package com.mowesta.android.app.binding;
import android.content.Context;
@@ -6,8 +6,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mowesta.android.app.R;
import com.mowesta.android.app.view.JamIcon;
import com.mowesta.android.app.view.WeatherIcon;
import com.mowesta.android.feign.model.Device;
import com.mowesta.android.feign.model.WeatherCondition;
import com.mowesta.android.feign.model.WeatherVideo;
@@ -218,6 +216,8 @@ public class BindingTransforms {
return R.string.video_type_pressure;
case PRECIPITATION:
return R.string.video_type_precipitation;
case WIND:
return R.string.video_type_wind;
default:
return R.string.video_type_temperature;
}
@@ -233,56 +233,56 @@ public class BindingTransforms {
* to return the regular (day) representation.
* @return The weather icon, which may be null.
*/
public static @Nullable WeatherIcon getIcon(@Nullable WeatherCondition.TypeEnum value, boolean alternate) {
public static @Nullable Integer getIcon(@Nullable WeatherCondition.TypeEnum value, boolean alternate) {
if (value == null) return null;
switch (value) {
case UNKNOWN:
break;
case CLEAR_SKY:
case MAINLY_CLEAR:
return alternate ? WeatherIcon.NIGHT_CLEAR : WeatherIcon.DAY_SUNNY;
return alternate ? R.drawable.ic_night_clear_normal_24 : R.drawable.ic_day_sunny_normal_24;
case PARTLY_CLOUDY:
return alternate ? WeatherIcon.NIGHT_CLOUDY : WeatherIcon.DAY_CLOUDY;
return alternate ? R.drawable.ic_night_cloudy_normal_24 : R.drawable.ic_day_cloudy_normal_24;
case CLOUDY:
return WeatherIcon.CLOUDY;
return R.drawable.ic_cloudy_normal_24;
case FOG:
case FOG_DEPOSITING_RIME:
return alternate ? WeatherIcon.NIGHT_FOG : WeatherIcon.DAY_FOG;
return alternate ? R.drawable.ic_night_fog_normal_24 : R.drawable.ic_day_fog_normal_24;
case SLIGHT_DRIZZLE:
case MODERATE_DRIZZLE:
return alternate ? WeatherIcon.NIGHT_SPRINKLE : WeatherIcon.DAY_SPRINKLE;
return alternate ? R.drawable.ic_night_sprinkle_normal_24 : R.drawable.ic_day_sprinkle_normal_24;
case HEAVY_DRIZZLE:
return WeatherIcon.SPRINKLE;
return R.drawable.ic_sprinkle_normal_24;
case DRIZZLE_FREEZING_SLIGHT:
case RAIN_FREEZING_SLIGHT:
case DRIZZLE_FREEZING_MODERATE_HEAVY:
case RAIN_FREEZING_MODERATE_HEAVY:
return WeatherIcon.SNOWFLAKE_COLD;
return R.drawable.ic_snowflake_cold_normal_24;
case SLIGHT_RAIN_NOT_FREEZING:
case MODERATE_RAIN_NOT_FREEZING:
return alternate ? WeatherIcon.NIGHT_RAIN : WeatherIcon.DAY_RAIN;
return alternate ? R.drawable.ic_night_rain_normal_24 : R.drawable.ic_day_rain_normal_24;
case HEAVY_RAIN_NOT_FREEZING:
return WeatherIcon.RAIN;
return R.drawable.ic_rain_normal_24;
case SLIGHT_FALL_OF_SNOWFLAKES:
case MODERATE_FALL_OF_SNOWFLAKES:
return alternate ? WeatherIcon.NIGHT_SNOW : WeatherIcon.DAY_SNOW;
return alternate ? R.drawable.ic_night_snow_normal_24 : R.drawable.ic_day_snow_normal_24;
case HEAVY_FALL_OF_SNOWFLAKES:
case SNOW_GRAINS:
return WeatherIcon.SNOW;
return R.drawable.ic_snow_normal_24;
case RAIN_SHOWER_SLIGHT:
return alternate ? WeatherIcon.NIGHT_SHOWERS : WeatherIcon.DAY_SHOWERS;
return alternate ? R.drawable.ic_night_showers_normal_24 : R.drawable.ic_day_showers_normal_24;
case RAIN_SHOWER_MODERATE_HEAVY:
return WeatherIcon.SHOWERS;
return R.drawable.ic_showers_normal_24;
case RAIN_SHOWER_VIOLENT:
return WeatherIcon.STORM_SHOWERS;
return R.drawable.ic_storm_showers_normal_24;
case SNOW_SHOWER_SLIGHT:
return alternate ? WeatherIcon.NIGHT_RAIN_MIX : WeatherIcon.DAY_RAIN_MIX;
return alternate ? R.drawable.ic_night_rain_mix_normal_24 : R.drawable.ic_day_rain_mix_normal_24;
case SNOW_SHOWER_MODERATE_HEAVY:
return WeatherIcon.RAIN_MIX;
return R.drawable.ic_rain_mix_normal_24;
case THUNDERSTORM_SLIGHT_MODERATE:
return alternate ? WeatherIcon.NIGHT_THUNDERSTORM : WeatherIcon.DAY_THUNDERSTORM;
return alternate ? R.drawable.ic_night_thunderstorm_normal_24 : R.drawable.ic_day_thunderstorm_normal_24;
case THUNDERSTORM_HAIL_HEAVY:
return WeatherIcon.THUNDERSTORM;
return R.drawable.ic_thunderstorm_normal_24;
}
return null;
}
@@ -294,6 +294,7 @@ public class BindingTransforms {
* @return The label.
*/
public static int getOsLabel(Device.OsEnum os) {
if (os == null) return 0;
switch (os) {
case IOS:
return R.string.label_device_type_ios;
@@ -312,6 +313,7 @@ public class BindingTransforms {
* @return The icon.
*/
public static int getOsIcon(Device.OsEnum os) {
if (os == null) return 0;
switch (os) {
case IOS:
return R.drawable.ic_phone_iphone_normal_24;
@@ -329,7 +331,7 @@ public class BindingTransforms {
* @param type the type.
* @return The label or 0 if the type is null.
*/
public static int getMeasurementTypeLabel(MeasurementViewModel.MeasurementType type) {
public static int getMeasurementTypeLabel(MeasurementType type) {
switch (type) {
case CPU_FREQUENCY:
return R.string.measurement_type_cpu_frequency;
@@ -356,39 +358,6 @@ public class BindingTransforms {
}
/**
* Returns the jam icon for the measurement type.
*
* @param type The measurement type.
* @return The jam icon.
*/
public static JamIcon getMeasurementTypeIcon(MeasurementViewModel.MeasurementType type) {
switch (type) {
case CPU_FREQUENCY:
return JamIcon.JAM_ACTIVITY;
case SOLAR_VOLTAGE:
return JamIcon.JAM_SUN;
case SCREEN_ENABLED:
return JamIcon.JAM_SCREEN;
case BATTERY_VOLTAGE:
return JamIcon.JAM_BATTERY_HALF_F;
case CPU_TEMPERATURE:
return JamIcon.JAM_PHONE;
case SENSOR_HUMIDITY:
return JamIcon.JAM_WATER_DROP;
case SENSOR_PRESSURE:
return JamIcon.JAM_DASHBOARD;
case BATTERY_CHARGING:
return JamIcon.JAM_BATTERY_CHARGING;
case BATTERY_TEMPERATURE:
return JamIcon.JAM_BATTERY;
case SENSOR_TEMPERATURE:
return JamIcon.JAM_TEMPERATURE;
}
return JamIcon.JAM_INFO;
}
@@ -1,4 +1,4 @@
package com.mowesta.android.app.model;
package com.mowesta.android.app.binding;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -0,0 +1,146 @@
package com.mowesta.android.app.binding;
import java.util.ArrayList;
import java.util.List;
/**
* The types of measurement context.
*
* @author Sebastian
*/
public enum MeasurementType {
/**
* A boolean to identify whether the battery is charging.
* e.g. true false
*/
BATTERY_CHARGING(Boolean.class),
/**
* The temperature reading of the battery (double value in centigrade, can be read through ACTION_BATTERY_CHANGED).
* e.g. 37.1, -1.3
*/
BATTERY_TEMPERATURE(Double.class),
/**
* A temperature reading of a temperature sensor (double value in centigrade, TYPE_TEMERATURE on Android).
* e.g. 37.1, -1.3
*/
SENSOR_TEMPERATURE(Double.class),
/**
* A pressure reading of a barometer sensor (double value in hPa, TYPE_BAROMETER on Android).
* e.g. 1000.0, 998.26127
*/
SENSOR_PRESSURE(Double.class),
/**
* A humidity reading of a humidity sensor (double value as relative humidity in %, TYPE_RELATIVE_HUMIDITY on Android).
* range: 0-1 (0->0%, 1->100%, 0.5->50%)
*/
SENSOR_HUMIDITY(Double.class),
/**
* The temperature of the cpu (double value in centigrade, can be read by analyzing the proc file system).
* e.g. 37.1 -1.3
*/
CPU_TEMPERATURE(Double.class),
/**
* The current frequency of the cpu (double value in mhz, can be read by analyzing the proc file system).
*/
CPU_FREQUENCY(Double.class),
/**
* A boolean to determine whether the screen is on (true) or off (false).
*/
SCREEN_ENABLED(Boolean.class),
/**
* The voltage of the battery (used to monitor the battery of the weather station).
* e.g. 3.77 -> 3.77 Volt
*/
BATTERY_VOLTAGE(Double.class),
/**
* The voltage of the solar panel (used to estimate whether the weather station is located in the sun).
* e.g. 3.77 -> 3.77 Volt
*/
SOLAR_VOLTAGE(Double.class);
/**
* The data type.
*/
private Class<?> type;
/**
* Creates a measurement type with the specified data type.
*
* @param type The data type expected for the measurement.
*/
private MeasurementType(Class<?> type) {
this.type = type;
}
/**
* Returns the data type.
*
* @return The data type.
*/
public Class<?> getType() {
return type;
}
/**
* Parses the data and returns a java array with the type
* represented by this constant or an empty array, if the
* data cannot be parsed.
*
* @param value The value to parse.
* @return The java object.
*/
public Object[] getValues(String value) {
List<Object> result = new ArrayList<>();
if (value != null) {
String[] substrings = value.split(",");
if (type == Boolean.class) {
for (String s : substrings) {
Boolean b = (Boolean) parseValue(s);
if (b != null) result.add(b);
}
} else if (type == Double.class) {
for (String s : substrings) {
Double d = (Double) parseValue(s);
if (d != null) result.add(d);
}
}
}
return result.toArray(new Object[result.size()]);
}
/**
* Parses a single value.
*
* @param value The string value.
* @return The parsed value.
*/
private Object parseValue(String value) {
if (value == null) return null;
value = value.trim();
if (type == Boolean.class) {
if ("true".equalsIgnoreCase(value)) return Boolean.TRUE;
if ("false".equalsIgnoreCase(value)) return Boolean.FALSE;
return null;
} else if (type == Double.class) {
try {
return Double.valueOf(Double.parseDouble(value));
} catch (NumberFormatException e) {
return null;
}
} else {
return null;
}
}
}
@@ -0,0 +1,89 @@
package com.mowesta.android.app.binding;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* Represents a single measurement value.
*
* @author Marcus
*/
public class MeasurementValue {
/**
* The log tag.
*/
private static final String TAG = "MeasurementValue";
/**
* The measurement type.
*/
private @NonNull
MeasurementType type;
/**
* The measurement value.
*/
private @Nullable
String value;
/**
* The extracted values.
*/
private @NonNull
Object[] values;
public MeasurementValue(@NonNull MeasurementType type, @Nullable String value) {
this.type = type;
this.value = value;
this.values = parseValues();
}
/**
* Tries to parse the value based on the type.
*
* @return The values.
*/
private @NonNull
Object[] parseValues() {
try {
return type.getValues(value);
} catch (Exception e) {
Log.e(TAG, "Failed to parse " + type.name() + " from '" + value + "'.", e);
return new Object[0];
}
}
/**
* Returns the type.
*
* @return The type.
*/
@NonNull
public MeasurementType getType() {
return type;
}
/**
* Returns the value(s).
*
* @return The values.
*/
@NonNull
public Object[] getValues() {
return values;
}
/**
* Determines whether this value has at
* least one data item.
*
* @return True if the value has at least one data item..
*/
public boolean hasValue() {
return values.length > 0;
}
}
@@ -9,6 +9,7 @@ import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.TypeConverters;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mowesta.android.feign.model.City;
@@ -48,7 +49,7 @@ public class Favorite {
/**
* The object mapper to serialize strings.
*/
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final ObjectMapper MAPPER = new ObjectMapper().configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true);
/**
* The type of the favorite.
@@ -1,5 +1,7 @@
package com.mowesta.android.app.database;
import android.location.Location;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
@@ -23,10 +25,20 @@ public interface FavoriteAccessor {
/**
* Returns a live data list of active favorites.
*
* @return The list of active favorites.
*/
@Query("select * from favorite where not deleted order by position")
LiveData<List<Favorite>> getActive();
/**
* Returns the active locations that exhibit a certain type.
*
* @param type The location type.
* @return The list of active favorites.
*/
@Query("select * from favorite where not deleted and type=:type order by position")
List<Favorite> getActive(int type);
/**
* returns the oldest entry in the database to determine whether
@@ -0,0 +1,397 @@
package com.mowesta.android.app.database;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
/**
* A class to memorize the information about a widget.
*/
@Entity(tableName = "widget", indices = {
@Index({"type", "ref"})
})
public class Widget {
/**
* The log tag.
*/
private static final String TAG = "Widget";
/**
* The object mapper to serialize strings.
*/
private static final ObjectMapper MAPPER = new ObjectMapper().configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true);
/**
* A constant to refer to an invalid type.
*/
public static final int TYPE_INVALID = 0;
/**
* The widget type that shows a forecast. The data id will be a reference to a city.
* The data will be the city and the content will be the forecast.
*/
public static final int TYPE_FORECAST = 1;
/**
* The type that shows a measurement. The data id will be a reference to a device.
* The data will be the device and the content will be the measurement.
*/
public static final int TYPE_MEASURE = 2;
/**
* The type of the widget.
*/
@ColumnInfo(name = "type")
@NonNull
private int type;
/**
* The id of the state of the widget.
*/
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
private long id;
/**
* The reference id of the widget. This
* is the id assigned by the widget host.
*/
@ColumnInfo(name = "ref")
private int reference;
/**
* The id pointing to some data in the
* mowesta backend. The type depends
* on the widget type.
*/
@ColumnInfo(name = "dataId")
private long dataId;
/**
* The update timestamp of the last
* data update.
*/
@ColumnInfo(name = "dataTime")
private long dataTime;
/**
* The widget data which depends on
* the type.
*/
@ColumnInfo(name = "dataValue")
private String dataValue;
/**
* The update timestamp of the last
* content update.
*/
@ColumnInfo(name = "contentTime")
private long contentTime;
/**
* The widget content which depends on
* the type.
*/
@ColumnInfo(name = "contentValue")
private String contentValue;
/**
* A flag to store a temperature unit. True for
* degree celsius, false for Fahrenheit.
*/
@ColumnInfo(name = "celsius")
private boolean celsius;
/**
* A flag to store a unit system. True for si
* false for imperial.
*/
@ColumnInfo(name = "si")
private boolean si;
/**
* The color of the widget text.
*/
@ColumnInfo(name = "color")
private int color;
/**
* Returns the widget type.
*
* @return The widget type.
*/
public int getType() {
return type;
}
/**
* Sets the widget type.
*
* @param type The type.
*/
public void setType(int type) {
this.type = type;
}
/**
* Returns the widget id.
*
* @return The id.
*/
public long getId() {
return id;
}
/**
* Sets the widget id.
*
* @param id The widget id.
*/
public void setId(long id) {
this.id = id;
}
/**
* Returns the widget reference assigned
* by the widget host.
*
* @return The reference.
*/
public int getReference() {
return reference;
}
/**
* Sets the widget reference assigned
* by the host.
*
* @param reference The reference.
*/
public void setReference(int reference) {
this.reference = reference;
}
/**
* Returns the data id pointing to the
* server object.
*
* @return The data id.
*/
public long getDataId() {
return dataId;
}
/**
* Sets the data id pointing to the server
* object.
*
* @param dataId The data id.
*/
public void setDataId(long dataId) {
this.dataId = dataId;
}
/**
* Returns the data time.
*
* @return The data time.
*/
public long getDataTime() {
return dataTime;
}
/**
* Sets the data time.
*
* @param dataTime The data time.
*/
public void setDataTime(long dataTime) {
this.dataTime = dataTime;
}
/**
* Sets the data value.
*
* @return The data value.
*/
public String getDataValue() {
return dataValue;
}
/**
* Returns the data value.
*
* @param dataValue The data value.
*/
public void setDataValue(String dataValue) {
this.dataValue = dataValue;
}
/**
* Returns the content time.
*
* @return The content time.
*/
public long getContentTime() {
return contentTime;
}
/**
* Sets the content time.
*
* @param contentTime The content time.
*/
public void setContentTime(long contentTime) {
this.contentTime = contentTime;
}
/**
* Returns the content value.
*
* @return The content value.
*/
public String getContentValue() {
return contentValue;
}
/**
* Sets the content value.
*
* @param contentValue The content value.
*/
public void setContentValue(String contentValue) {
this.contentValue = contentValue;
}
/**
* Deserializes the content value as the specified type.
*
* @param type The type.
* @param <T> The type.
* @return The deserialized value or null, if deserialization fails.
*/
public <T> T getContent(Class<T> type) {
try {
String value = getContentValue();
if (value == null) return null;
else return MAPPER.readValue(value, type);
} catch (Exception e) {
Log.e(TAG, "Failed to deserialize widget content.", e);
return null;
}
}
/**
* Sets the content value by serializing the content as string.
*
* @param content The content to set.
* @param <T> The type.
*/
public <T> void setContent(T content) {
try {
if (content == null) setContentValue(null);
else setContentValue(MAPPER.writeValueAsString(content));
} catch (Exception e) {
Log.e(TAG, "Failed to serialize widget content.", e);
}
}
/**
* Deserializes the widget data from its string representation.
*
* @param type The type.
* @param <T> The type.
* @return The data or null, if something fails.
*/
public <T> T getData(Class<T> type) {
try {
String value = getDataValue();
if (value == null) return null;
else return MAPPER.readValue(value, type);
} catch (Exception e) {
Log.e(TAG, "Failed to deserialize widget data.", e);
return null;
}
}
/**
* Sets the widget data value by serializing the data.
*
* @param data The data.
* @param <T> The type.
*/
public <T> void setData(T data) {
try {
if (data == null) setDataValue(null);
else setDataValue(MAPPER.writeValueAsString(data));
} catch (IOException e) {
Log.e(TAG, "Failed to serialize widget data.", e);
}
}
/**
* Determines whether the temperature is shown as celsius.
*
* @return True if celsius, false for fahrenheit.
*/
public boolean isCelsius() {
return celsius;
}
/**
* Determines whether the temperature is shown as celsius.
*
* @param celsius True if celsius, false for fahrenheit.
*/
public void setCelsius(boolean celsius) {
this.celsius = celsius;
}
/**
* Determines the unit system. True for si, false
* for imperial.
*
* @return True for si, false for imperial.
*/
public boolean isSi() {
return si;
}
/**
* Sets the unit system. True for si, false
* for imperial.
*
* @param si True for si, false for imperial.
*/
public void setSi(boolean si) {
this.si = si;
}
/**
* Returns the text color.
*
* @return The text color.
*/
public int getColor() {
return color;
}
/**
* Sets the text color.
*
* @param color The text color.
*/
public void setColor(int color) {
this.color = color;
}
}
@@ -0,0 +1,61 @@
package com.mowesta.android.app.database;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;
import java.util.List;
/**
* The widget access to manipulate the stored widget data.
*
* @author Marcus
*/
@Dao
public interface WidgetAccessor {
/**
* Returns the widget with the specified id.
*
* @param id The id.
* @return The widget.
*/
@Query("select * from widget where id=:id")
Widget get(long id);
/**
* Returns all widgets with the specified type and reference.
*
* @param type The type.
* @param reference The reference.
* @return The widgets matching the type and reference. There
* should be only zero or one.
*/
@Query("select * from widget where type=:type and ref=:reference")
List<Widget> get(int type, int reference);
/**
* Inserts a widget into the databases.
*
* @param widget The widget to insert.
*/
@Insert
void add(Widget widget);
/**
* Updates the widget, if it exists.
*
* @param widget The widget to update.
*/
@Update
void update(Widget widget);
/**
* Deletes all widgets with the specified type and reference
* from the database.
*/
@Query("delete from widget where type=:type and ref=:reference")
void delete(int type, int reference);
}
@@ -0,0 +1,62 @@
package com.mowesta.android.app.database;
import android.graphics.Color;
import androidx.room.AutoMigration;
import androidx.room.Database;
import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;
import java.util.ArrayList;
import java.util.List;
/**
* The database to store the widget information.
*
* @author Marcus
*/
@Database(entities = { Widget.class }, version = 4, exportSchema = true)
public abstract class WidgetDatabase extends RoomDatabase {
/**
* Adds a non-null color column to the widget entry. This requires
* us to copy the data, since sql lite cannot dynamically add or
* remove constraints.
*/
private static final Migration MIGRATION_3_4 = new Migration(3, 4) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("DROP INDEX IF EXISTS `index_widget_type_ref`");
database.execSQL("ALTER TABLE `widget` ADD COLUMN `color` INTEGER");
database.execSQL("UPDATE `widget` SET `color` = ?", new Object[] { Color.rgb(255, 255, 255) } );
database.execSQL("CREATE TABLE IF NOT EXISTS `new_widget` (`type` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `ref` INTEGER NOT NULL, `dataId` INTEGER NOT NULL, `dataTime` INTEGER NOT NULL, `dataValue` TEXT, `contentTime` INTEGER NOT NULL, `contentValue` TEXT, `celsius` INTEGER NOT NULL, `si` INTEGER NOT NULL, `color` INTEGER NOT NULL)");
database.execSQL("INSERT INTO `new_widget` SELECT * FROM `widget`");
database.execSQL("DROP TABLE `widget`");
database.execSQL("ALTER TABLE `new_widget` RENAME TO `widget`");
database.execSQL("CREATE INDEX IF NOT EXISTS `index_widget_type_ref` ON `widget` (`type`, `ref`)");
}
};
/**
* Returns an array with all migrations.
*
* @return The array with migrations.
*/
public static Migration[] getMigrations() {
return new Migration[] {
MIGRATION_3_4
};
}
/**
* Returns the widget accessor.
*
* @return The widget accessor.
*/
public abstract WidgetAccessor getAccessor();
}
@@ -71,18 +71,17 @@ public abstract class AbstractDiagramFragment extends AbstractNetworkFragment {
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_unit_system:
UnitSystemDialogFragment system = new UnitSystemDialogFragment();
system.show(getChildFragmentManager(), "system");
return true;
case R.id.action_temperature_unit:
TemperatureUnitDialogFragment unit = new TemperatureUnitDialogFragment();
unit.show(getChildFragmentManager(), "unit");
return true;
default:
return super.onOptionsItemSelected(item);
int itemId = item.getItemId();
if (itemId == R.id.action_unit_system) {
UnitSystemDialogFragment system = new UnitSystemDialogFragment();
system.show(getChildFragmentManager(), "system");
return true;
} else if (itemId == R.id.action_temperature_unit) {
TemperatureUnitDialogFragment unit = new TemperatureUnitDialogFragment();
unit.show(getChildFragmentManager(), "unit");
return true;
}
return super.onOptionsItemSelected(item);
}
@@ -82,19 +82,19 @@ public abstract class AbstractPlaceFragment extends AbstractNetworkFragment {
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_favorite_add:
getPlaceViewModel().addFavorite();
return true;
case R.id.action_favorite_remove:
getPlaceViewModel().removeFavorite();
return true;
case R.id.action_wikipedia:
openWikipedia();
return true;
case R.id.action_google_maps:
openGoogleMaps();
return true;
int itemId = item.getItemId();
if (itemId == R.id.action_favorite_add) {
getPlaceViewModel().addFavorite();
return true;
} else if (itemId == R.id.action_favorite_remove) {
getPlaceViewModel().removeFavorite();
return true;
} else if (itemId == R.id.action_wikipedia) {
openWikipedia();
return true;
} else if (itemId == R.id.action_google_maps) {
openGoogleMaps();
return true;
}
return false;
}
@@ -2,6 +2,7 @@ package com.mowesta.android.app.fragment;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -53,29 +54,32 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
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:
case TIME:
pager.setCurrentItem(2, true);
break;
case HOUR:
pager.setCurrentItem(3, true);
break;
}
}
});
pager.setAdapter(new ForecastAdapter(this));
TabLayout tabs = view.findViewById(R.id.tabs);
new TabLayoutMediator(tabs, pager, (tab, position) -> {
switch (position) {
case 0:
tab.setText(R.string.city_info_day);
tab.setText(R.string.city_info_gradient);
break;
case 1:
tab.setText(R.string.city_info_day);
break;
case 2:
tab.setText(R.string.city_info_time);
break;
default:
@@ -85,6 +89,7 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
}).attach();
}
/**
* The adapter for the pager that displays the different time granularities.
*
@@ -100,16 +105,20 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
@NonNull
@Override
public Fragment createFragment(int position) {
ForecastRecyclerFragment fragment = new ForecastRecyclerFragment();
Bundle bundle = new Bundle();
bundle.putInt("page", position);
fragment.setArguments(bundle);
return fragment;
if (position == 0) {
return new CityGradientFragment();
} else {
ForecastRecyclerFragment fragment = new ForecastRecyclerFragment();
Bundle bundle = new Bundle();
bundle.putInt("page", position - 1);
fragment.setArguments(bundle);
return fragment;
}
}
@Override
public int getItemCount() {
return 3;
return 4;
}
}
@@ -123,7 +132,7 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
public static class ForecastRecyclerFragment extends CityFragment.ChildFragment {
/** A handler to post updates. */
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
@Nullable
@Override
@@ -426,5 +435,4 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
}
}
@@ -25,7 +25,7 @@ import com.locoslab.android.leafless.MapView;
import com.mowesta.android.app.R;
import com.mowesta.android.app.databinding.FragmentCityBinding;
import com.mowesta.android.app.model.AbstractPlaceViewModel;
import com.mowesta.android.app.model.BindingTransforms;
import com.mowesta.android.app.binding.BindingTransforms;
import com.mowesta.android.app.model.CityViewModel;
import com.mowesta.android.app.util.MapViewUtil;
@@ -85,16 +85,14 @@ public class CityFragment extends AbstractPlaceFragment {
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_customize:
getChildFragmentManager()
.beginTransaction()
.add(new CustomizeDialogFragment(), "customize")
.commit();
return true;
default:
return super.onOptionsItemSelected(item);
if (item.getItemId() == R.id.action_customize) {
getChildFragmentManager()
.beginTransaction()
.add(new CustomizeDialogFragment(), "customize")
.commit();
return true;
}
return super.onOptionsItemSelected(item);
}
@Nullable
@@ -0,0 +1,284 @@
package com.mowesta.android.app.fragment;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.appbar.AppBarLayout;
import com.mowesta.android.app.R;
import com.mowesta.android.app.databinding.FragmentGradientBinding;
import com.mowesta.android.app.model.CustomizeViewModel;
import com.mowesta.android.app.util.DateFormatter;
import com.mowesta.android.app.util.TimeUtils;
import com.mowesta.android.app.view.DataView;
import com.mowesta.android.app.view.TimeView;
import com.mowesta.android.app.view.color.CloudDepthColorScheme;
import com.mowesta.android.app.view.color.HumidityColorScheme;
import com.mowesta.android.app.view.color.PrecipitationColorScheme;
import com.mowesta.android.app.view.color.PressureColorScheme;
import com.mowesta.android.app.view.color.ScientificTemperatureColorScheme;
import com.mowesta.android.app.view.color.WhiteCloudColorScheme;
import com.mowesta.android.feign.model.WeatherCondition;
/**
* The fragment to show the overview as a bunch of gradients.
*
* @author Marcus
*/
public class CityGradientFragment extends CityFragment.ChildFragment {
/**
* The timeout after which we reset the view.
*/
private static final int TIMEOUT_REMOVER = 10000;
/**
* The view binding.
*/
private FragmentGradientBinding binding;
/**
* The time utilities.
*/
private TimeUtils timeUtils = new TimeUtils(System.currentTimeMillis(), null);
/**
* The view pager of the parent.
*/
private ViewPager2 pager;
/**
* The date formatter.
*/
private DateFormatter dateFormatter;
/**
* The handler to post the removal of
*/
private Handler handler = new Handler(Looper.getMainLooper());
/**
* The animator for the progress bar.
*/
private ValueAnimator animator;
/**
* The weather condition to display as text.
*/
private WeatherCondition condition = new WeatherCondition();
private boolean closed = false;
private Runnable remover = () -> {
updateSelection(null);
animator.cancel();
binding.gradientText.setVisibility(View.GONE);
};
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
dateFormatter = new DateFormatter(getContext());
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_gradient, container, false);
// this is quite ugly, but we need to disable the view pager and collapse the toolbar
pager = getActivity().findViewById(R.id.pager);
AppBarLayout layout = getActivity().findViewById(R.id.layout_appbar);
binding.gradientProgress1.setMax(TIMEOUT_REMOVER);
binding.gradientProgress2.setMax(TIMEOUT_REMOVER);
animator = ValueAnimator.ofInt(TIMEOUT_REMOVER, 0);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(TIMEOUT_REMOVER);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation){
int value = (Integer)animation.getAnimatedValue();
binding.gradientProgress1.setProgress(value);
binding.gradientProgress2.setProgress(value);
binding.gradientText.setAlpha(Math.min(1, Math.max(0, value / 1000f)));
}
});
binding.gradientScroll.setOnTouchListener(binding.gradientTouch.createOnTouchListener(new TimeView.OnSlideListener() {
@Override
public void onSlide(float relative) {
if (!hasData()) return;
animator.cancel();
binding.gradientProgress1.setProgress(TIMEOUT_REMOVER);
binding.gradientProgress2.setProgress(TIMEOUT_REMOVER);
binding.gradientText.setAlpha(1);
handler.removeCallbacks(remover);
if (!closed) {
layout.setExpanded(false, true);
closed = true;
}
pager.setUserInputEnabled(false);
updateSelection(relative);
updateCondition(relative);
binding.gradientText.setVisibility(View.VISIBLE);
updateGuide(relative);
}
@Override
public void onSlideEnd() {
pager.setUserInputEnabled(true);
closed = false;
animator.start();
handler.postDelayed(remover, TIMEOUT_REMOVER);
}
}));
binding.setLifecycleOwner(getViewLifecycleOwner());
binding.gradientText.setVisibility(View.GONE);
binding.gradientTemperature.setColorScheme(new ScientificTemperatureColorScheme());
binding.gradientCloud.setColorScheme(new WhiteCloudColorScheme());
binding.gradientCloud.setSecondaryColorScheme(new CloudDepthColorScheme());
binding.gradientPreciptiation.setColorScheme(new PrecipitationColorScheme());
binding.gradientHumidity.setColorScheme(new HumidityColorScheme());
getCityViewModel().getHour().observe(getViewLifecycleOwner(), (list) -> {
if (list == null) return;
int housrs = 0;
for (int i = 0; i < list.size(); i++) {
housrs += list.get(i).getCondition().getValue().getDuration();
}
Double[] temp = new Double[housrs];
Double[] cloud = new Double[housrs];
Double[] depth = new Double[housrs];
Double[] prec = new Double[housrs];
Double[] pres = new Double[housrs];
Double[] wind = new Double[housrs];
Double[] hum = new Double[housrs];
Long[] hours = new Long[housrs];
int index = 0;
for (int i = 0; i < list.size(); i++) {
WeatherCondition wc = list.get(i).getCondition().getValue();
for (int j = 0; j < wc.getDuration(); j++) {
temp[index] = wc.getTemperature();
cloud[index] = wc.getCloudCoverage();
prec[index] = wc.getPrecipitation();
pres[index] = wc.getPressure();
depth[index] = wc.getCloudDepth();
wind[index] = wc.getWindSpeed();
hum[index] = wc.getHumidity();
hours[index] = wc.getTime() + j * 3600000;
index += 1;
}
}
binding.gradientCloud.setSecondaryData(depth);
binding.gradientTemperature.setData(temp);
binding.gradientPressure.setData(pres);
binding.gradientCloud.setData(cloud);
binding.gradientPreciptiation.setData(prec);
binding.gradientWindSpeed.setData(wind);
binding.gradientHumidity.setData(hum);
binding.gradientTouch.setData(hours);
});
getCityViewModel().getForecast().observe(getViewLifecycleOwner(), (forecast) -> {
if (forecast != null) {
// 1013,25 hPa * [ 1 − 6,5 * Höhe / (288150 m) ]5,255
double avg = 1013.25 * Math.pow(1 - 6.5 * forecast.getSurfaceHeight() / 288150.0, 5.255);
binding.gradientPressure.setColorScheme(new PressureColorScheme(avg, avg - 20, avg + 10));
}
});
getCityViewModel().getCity().observe(getViewLifecycleOwner(), (city) -> {
if (city != null) {
binding.gradientTouch.setTimezone(city.getTimezone());
timeUtils = new TimeUtils(System.currentTimeMillis(), city.getTimezone());
}
});
// observe changes to the settings that affect us
CustomizeViewModel customizeViewModel = new ViewModelProvider(this).get(CustomizeViewModel.class);
customizeViewModel.getTemperatureUnit().observe(getViewLifecycleOwner(), (u)-> {
Float selection = binding.gradientTouch.getSelection();
if (selection != null) updateCondition(selection);
});
customizeViewModel.getUnitSystem().observe(getViewLifecycleOwner(), (s) -> {
Float selection = binding.gradientTouch.getSelection();
if (selection != null) updateCondition(selection);
});
return binding.getRoot();
}
private boolean hasData() {
return binding.gradientTouch.getData() != null && binding.gradientTouch.getData().length > 0;
}
private void updateSelection(Float selection) {
binding.gradientTemperature.setSelection(selection);
binding.gradientWindSpeed.setSelection(selection);
binding.gradientPreciptiation.setSelection(selection);
binding.gradientHumidity.setSelection(selection);
binding.gradientPressure.setSelection(selection);
binding.gradientCloud.setSelection(selection);
binding.gradientTouch.setSelection(selection);
}
private void updateCondition(float selection) {
long time = binding.gradientTouch.getDataAt(selection);
condition.setTime(time);
condition.setWindSpeed(binding.gradientWindSpeed.getDataAt(selection));
condition.setPrecipitation(binding.gradientPreciptiation.getDataAt(selection));
condition.setHumidity(binding.gradientHumidity.getDataAt(selection));
condition.setPressure(binding.gradientPressure.getDataAt(selection));
condition.setCloudCoverage(binding.gradientCloud.getDataAt(selection));
condition.setTemperature(binding.gradientTemperature.getDataAt(selection));
String day = timeUtils.getDayName(getContext(), time);
String hour = dateFormatter.asTime(time, binding.gradientTouch.getTimezone());
binding.gradientTime.setText(getString(R.string.format_two_parts, day, hour));
binding.setModel(condition);
}
private void updateGuide(float relative) {
float px = 64 * getResources().getDisplayMetrics().density;
float max = 128 * getResources().getDisplayMetrics().density;
int size = binding.gradientTouch.getDirection() == DataView.Direction.HORIZONTAL ?
binding.gradientConstraint.getWidth():binding.gradientConstraint.getHeight();
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams)binding.gradientText.getLayoutParams();
float percent = size == 0 ? 0 : px / size;
float delta = size == 0 ? 0 : max / size;
if (binding.gradientTouch.getDirection() == DataView.Direction.VERTICAL) {
if (relative - delta < 0) {
binding.guideGradient.setGuidelinePercent(relative + 2 * percent);
params.bottomToTop = -1;
params.topToBottom = R.id.guide_gradient;
} else {
binding.guideGradient.setGuidelinePercent(relative - percent);
params.topToBottom = -1;
params.bottomToTop = R.id.guide_gradient;
}
} else {
if (relative > 0.5) {
binding.guideGradient.setGuidelinePercent(relative - percent);
params.leftToLeft = -1;
params.rightToRight = R.id.guide_gradient;
} else {
binding.guideGradient.setGuidelinePercent(relative + percent);
params.leftToLeft = R.id.guide_gradient;
params.rightToRight = -1;
}
}
binding.gradientText.setLayoutParams(params);
}
@Override
public void onPause() {
handler.removeCallbacks(remover);
remover.run();
super.onPause();
}
}
@@ -17,7 +17,7 @@ import com.locoslab.android.leafless.MapView;
import com.locoslab.android.leafless.polyline.Polyline;
import com.mowesta.android.app.R;
import com.mowesta.android.app.databinding.FragmentCityInfoBinding;
import com.mowesta.android.app.model.BindingTransforms;
import com.mowesta.android.app.binding.BindingTransforms;
import com.mowesta.android.app.model.CityViewModel;
import com.mowesta.android.app.model.ConditionViewModel;
import com.mowesta.android.app.util.MapViewUtil;
@@ -45,13 +45,7 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
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);
}
MapViewUtil.setupInteractiveMap(mapView, getResources().getBoolean(R.bool.dark_mode));
CityViewModel model = new ViewModelProvider(getParentFragment().getParentFragment()).get(CityViewModel.class);
ConditionViewModel condition = new ViewModelProvider(this).get(ConditionViewModel.class);
Runnable updateCondition = () -> {
@@ -96,8 +90,8 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
appController.navigate(R.id.destination_station, bundle, opts.build());
}
});
NavController cityController = Navigation.findNavController(getActivity(), R.id.navigation_city);
binding.setConditionListener(m -> {
NavController cityController = Navigation.findNavController(getActivity(), R.id.navigation_city);
cityController.navigate(R.id.destination_city_forecast);
});
binding.setLifecycleOwner(getViewLifecycleOwner());
@@ -36,6 +36,11 @@ import java.util.List;
*/
public class CityVideoFragment extends CityFragment.ChildFragment {
/**
* The mediator to update the tabs.
*/
private TabLayoutMediator mediator;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@@ -49,32 +54,40 @@ public class CityVideoFragment extends CityFragment.ChildFragment {
TabLayout tabs = view.findViewById(R.id.tabs);
List<Integer> pages = new ArrayList<>();
CityViewModel model = getCityViewModel();
pager.setAdapter(new VideoAdpter(this, pages));
updateMediator(tabs, pager, pages);
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();
updateMediator(tabs, pager, pages);
};
model.getCosmoEurope().observe(getViewLifecycleOwner(), videoObserver);
model.getIconEurope().observe(getViewLifecycleOwner(), videoObserver);
model.getIconGlobal().observe(getViewLifecycleOwner(), videoObserver);
}
private void updateMediator(TabLayout tabs, ViewPager2 pager, List<Integer> pages) {
if (mediator != null && mediator.isAttached()) mediator.detach();
mediator = 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;
}
});
mediator.attach();
}
/**
* The adapter for the pager that displays the different videos.
*
@@ -88,9 +88,11 @@ public class CollectionFragment extends Fragment {
// add a funky animation
if (savedInstanceState == null) {
List<View> views = new ArrayList<>();
views.add(binding.collectionNotePermission);
views.add(binding.collectionNoteLocation);
views.add(binding.collectionNoteData);
views.add(binding.collectionNoteEnable);
views.add(binding.privacyMeasureSwitch);
views.add(binding.collectionNotePermission);
views.add(binding.buttonContinue);
AnimatorSet set = new AnimatorSet();
ObjectAnimator first = ObjectAnimator.ofFloat(binding.logoSun, "translationY", DisplayUtils.dpToPixels(getContext(), 90), 0f);
@@ -0,0 +1,72 @@
package com.mowesta.android.app.fragment;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.DialogFragment;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.mowesta.android.app.R;
import com.mowesta.android.app.databinding.DialogColorBinding;
import com.mowesta.android.app.model.ColorViewModel;
/**
* A dialog fragment to display a color picker. The fragment uses the parent's color view model
* to communicate with the caller.
*
* @author Marcus
*/
public class ColorDialogFragment extends DialogFragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
ColorViewModel model = new ViewModelProvider(getParentFragment()).get(ColorViewModel.class);
DialogColorBinding binding = DataBindingUtil.inflate(inflater, R.layout.dialog_color, container, false);
binding.setModel(model);
binding.setLifecycleOwner(getViewLifecycleOwner());
View view = inflater.inflate(R.layout.dialog_color, null);
binding.colorSliderRed.setValue(model.getRed().getValue());
binding.colorSliderGreen.setValue(model.getGreen().getValue());
binding.colorSliderBlue.setValue(model.getBlue().getValue());
binding.colorSliderRed.addOnChangeListener((slider, value, fromUser) -> {
if (fromUser) model.getRed().setValue(value);
});
binding.colorSliderGreen.addOnChangeListener((slider, value, fromUser) -> {
if (fromUser) model.getGreen().setValue(value);
});
binding.colorSliderBlue.addOnChangeListener((slider, value, fromUser) -> {
if (fromUser) model.getBlue().setValue(value);
});
model.getColor().observe(getViewLifecycleOwner(), (color) -> {
binding.colorResultText.setTextColor(color);
binding.colorResultImage.setColorFilter(color);
});
binding.buttonOk.setOnClickListener((v) -> {
model.setState(ColorViewModel.State.CONFIRMED);
dismiss();
});
binding.buttonCancel.setOnClickListener((v) -> {
model.setState(ColorViewModel.State.DISMISSED);
dismiss();
});
return binding.getRoot();
}
@Override
public void onCancel(@NonNull DialogInterface dialog) {
ColorViewModel model = new ViewModelProvider(getParentFragment()).get(ColorViewModel.class);
model.setState(ColorViewModel.State.DISMISSED);
super.onCancel(dialog);
}
}
@@ -5,6 +5,7 @@ import android.animation.ObjectAnimator;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
@@ -176,7 +177,7 @@ public class ConnectFragment extends Fragment {
/**
* The handler to post events asynchronously.
*/
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
@Nullable
@Override
@@ -11,7 +11,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.NavOptions;
@@ -27,14 +26,11 @@ import com.locoslab.android.leafless.polyline.Polyline;
import com.mowesta.android.app.R;
import com.mowesta.android.app.adapter.CityEntryPagedListAdapter;
import com.mowesta.android.app.databinding.FragmentCountryBinding;
import com.mowesta.android.app.databinding.FragmentStateBinding;
import com.mowesta.android.app.model.AbstractPlaceViewModel;
import com.mowesta.android.app.model.BindingTransforms;
import com.mowesta.android.app.binding.BindingTransforms;
import com.mowesta.android.app.model.CountryViewModel;
import com.mowesta.android.app.model.StateViewModel;
import com.mowesta.android.app.util.MapViewUtil;
import com.mowesta.android.feign.model.Country;
import com.mowesta.android.feign.model.State;
import java.util.ArrayList;
import java.util.List;
@@ -109,7 +105,7 @@ public class CountryFragment extends AbstractPlaceFragment {
model.getCities().observe(getViewLifecycleOwner(), (list) -> adapter.submitList(list));
recyclerView.setAdapter(adapter);
MapView mapView = view.findViewById(R.id.map_detail);
MapViewUtil.setupInteractiveMap(mapView);
MapViewUtil.setupInteractiveMap(mapView, getResources().getBoolean(R.bool.dark_mode));
Runnable updateMap = () -> {
MapViewUtil.removePolylines(mapView, polylines);
polylines.clear();
@@ -11,20 +11,18 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.NavOptions;
import androidx.navigation.Navigation;
import androidx.paging.PagedListAdapter;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.mowesta.android.app.IApp;
import com.mowesta.android.app.R;
import com.mowesta.android.app.adapter.DeviceEntryPagedListAdapter;
import com.mowesta.android.app.databinding.FragmentDevicesBinding;
import com.mowesta.android.app.databinding.ViewDeviceEntryBinding;
import com.mowesta.android.app.model.AbstractNetworkViewModel;
import com.mowesta.android.app.model.DevicesViewModel;
import com.mowesta.android.feign.model.Device;
@@ -103,103 +101,4 @@ public class DevicesFragment extends AbstractNetworkFragment {
}
/**
* The view holder for the list of devices
*
* @author Marcus
*/
private static class DeviceEntryViewHolder extends RecyclerView.ViewHolder {
/**
* The binding with the device view.
*/
private ViewDeviceEntryBinding binding;
/**
* Creates a new view holder for the binding.
*
* @param binding The binding.
*/
public DeviceEntryViewHolder(@NonNull ViewDeviceEntryBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
/**
* Sets the model.
*
* @param device The device.
*/
public void setModel(Device device) {
this.binding.setModel(device);
}
}
/**
* A callback to determine whether two devices are the same.
*
* @author Marcus
*/
private static class DeviceCallback extends DiffUtil.ItemCallback<Device> {
@Override
public boolean areItemsTheSame(@NonNull Device oldItem, @NonNull Device newItem) {
return oldItem.getId() != null && oldItem.getId().equals(newItem.getId());
}
@Override
public boolean areContentsTheSame(@NonNull Device oldItem, @NonNull Device newItem) {
return oldItem.getId() != null && oldItem.getId().equals(newItem.getId());
}
}
/**
* A list adapter to display the list of devices.
*
* @author Marcus
*/
private static class DeviceEntryPagedListAdapter extends PagedListAdapter<Device, DeviceEntryViewHolder> {
/**
* The lifecycle owner.
*/
private @NonNull
LifecycleOwner owner;
/**
* The click listener.
*/
private @NonNull
DevicesViewModel.OnDeviceSelectedListener listener;
/**
* Creates a new paged list adapter that will inform
* the listener about click events.
*
* @param owner The lifecycle owner.
* @param listener The listener.
*/
public DeviceEntryPagedListAdapter(@NonNull LifecycleOwner owner, @NonNull DevicesViewModel.OnDeviceSelectedListener listener) {
super(new DeviceCallback());
this.owner = owner;
this.listener = listener;
}
@NonNull
@Override
public DeviceEntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ViewDeviceEntryBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.view_device_entry, parent, false);
DeviceEntryViewHolder holder = new DeviceEntryViewHolder(binding);
binding.setListener(listener);
binding.setLifecycleOwner(owner);
return holder;
}
@Override
public void onBindViewHolder(@NonNull DeviceEntryViewHolder holder, int position) {
holder.setModel(getItem(position));
}
}
}
@@ -85,10 +85,20 @@ public class DrawerFragment extends AbstractNetworkFragment {
@Override
public void onResume() {
super.onResume();
// navigate to settings, if user pressed notification
preventSplashScreen();
handleNotificationIntent();
}
/**
* Prevent going back to the splash screen if opened through deep link.
*/
private void preventSplashScreen() {
NavController nav = Navigation.findNavController(getActivity().findViewById(R.id.navigation_app));
if (nav.getGraph().getId() != R.id.navigation_core) {
nav.setGraph(R.navigation.navigation_core);
}
}
/**
* Checks if the intent was generated by the background service and
* opens the settings screen, if this is the case
@@ -114,7 +124,6 @@ public class DrawerFragment extends AbstractNetworkFragment {
return view;
}
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
@@ -17,6 +17,7 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.NavOptions;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -26,8 +27,10 @@ import com.mowesta.android.app.databinding.ViewFavoriteEntryBinding;
import com.mowesta.android.app.model.CustomizeViewModel;
import com.mowesta.android.app.model.FavoritesViewModel;
import com.mowesta.android.app.model.FavoritesViewModel.OnFavoriteSelectedListener;
import com.mowesta.android.app.task.DatabaseTask;
import com.mowesta.android.app.util.TabletUtil;
import java.util.ArrayList;
import java.util.List;
/**
@@ -79,6 +82,52 @@ public class FavoritesFragment extends Fragment {
}
}
}));
ItemTouchHelper touchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
private int selection;
private int target;
private List<Favorite> favorites;
@Override
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
return makeMovementFlags(ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0);
}
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
int fromPosition = viewHolder.getBindingAdapterPosition();
int toPosition = target.getBindingAdapterPosition();
this.target = toPosition;
recyclerView.getAdapter().notifyItemMoved(fromPosition, toPosition);
return false;
}
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
// nothing to do
}
@Override
public void onSelectedChanged(@Nullable RecyclerView.ViewHolder viewHolder, int actionState) {
super.onSelectedChanged(viewHolder, actionState);
swipeRefreshLayout.setEnabled(actionState == ItemTouchHelper.ACTION_STATE_IDLE);
if (actionState == ItemTouchHelper.ACTION_STATE_IDLE) {
List<Favorite> current = model.getFavorites().getValue();
if (selection != -1 && target != -1 && current == favorites) {
favorites.add(target, favorites.remove(selection));
model.updateFavorites(favorites);
}
selection = -1;
target = -1;
favorites = null;
} else if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
favorites = model.getFavorites().getValue();
selection = viewHolder.getBindingAdapterPosition();
target = -1;
}
}
});
touchHelper.attachToRecyclerView(recyclerView);
CustomizeViewModel customize = new ViewModelProvider(getActivity()).get(CustomizeViewModel.class);
customize.getUnitSystem().observe(getViewLifecycleOwner(), (v) -> recyclerView.getAdapter().notifyDataSetChanged());
customize.getTemperatureUnit().observe(getViewLifecycleOwner(), (v) -> recyclerView.getAdapter().notifyDataSetChanged());
@@ -126,6 +175,7 @@ public class FavoritesFragment extends Fragment {
*/
private @NonNull ViewFavoriteEntryBinding binding;
/**
* Creates a new view holder.
*
@@ -144,6 +194,16 @@ public class FavoritesFragment extends Fragment {
*/
public void setModel(Favorite favorite) {
this.binding.setModel(favorite);
binding.getRoot().setVisibility(favorite == null || favorite.getCity() == null ? View.GONE : View.VISIBLE);
}
/**
* Returns the favorite which may be null.
*
* @return The favorite.
*/
public Favorite getModel() {
return binding.getModel();
}
}
@@ -206,6 +266,7 @@ public class FavoritesFragment extends Fragment {
public int getItemCount() {
return (liveData.getValue() == null)?0: liveData.getValue().size();
}
}
}
@@ -0,0 +1,163 @@
package com.mowesta.android.app.fragment;
import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.renderscript.ScriptGroup;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import com.mowesta.android.app.IApp;
import com.mowesta.android.app.R;
import com.mowesta.android.app.adapter.CityEntryListAdapter;
import com.mowesta.android.app.database.Widget;
import com.mowesta.android.app.database.WidgetDatabase;
import com.mowesta.android.app.databinding.FragmentForecastWidgetBinding;
import com.mowesta.android.app.model.AbstractNetworkViewModel;
import com.mowesta.android.app.model.ColorViewModel;
import com.mowesta.android.app.model.ForecastWidgetViewModel;
import com.mowesta.android.app.task.DatabaseTask;
import com.mowesta.android.app.widget.ForecastWidgetProvider;
import com.mowesta.android.app.widget.WidgetReceiver;
import com.mowesta.android.app.widget.WidgetService;
import com.mowesta.android.feign.model.City;
/**
* A fragment to configure the forecast widget.
*
* @author Marcus
*/
public class ForecastWidgetFragment extends AbstractNetworkFragment {
/**
* The bundle extra to store the widget id.
*/
private static final String EXTRA_WIDGET_ID = "widget_id";
@Override
protected AbstractNetworkViewModel getNetworkViewModel() {
return new ViewModelProvider(this).get(ForecastWidgetViewModel.class);
}
/**
* Returns the widget id that is currently configured.
*
* @return The widget id that is currently configured.
*/
public int getWidgetId() {
return getArguments().getInt(EXTRA_WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
/**
* Creates a new instance with the widget id.
*
* @param widgetId The widget id.
* @return The instance.
*/
public static ForecastWidgetFragment newInstance(int widgetId) {
Bundle b = new Bundle();
b.putInt(EXTRA_WIDGET_ID, widgetId);
ForecastWidgetFragment fragment = new ForecastWidgetFragment();
fragment.setArguments(b);
return fragment;
}
@Nullable
@Override
protected View getErrorAnchorView() {
return getView().findViewById(R.id.layout_coordinator);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
FragmentForecastWidgetBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_forecast_widget, container, false);
ForecastWidgetViewModel model = new ViewModelProvider(this).get(ForecastWidgetViewModel.class);
binding.setLifecycleOwner(getViewLifecycleOwner());
binding.setModel(model);
model.getColor().observe(getViewLifecycleOwner(), (color) -> {
binding.buttonColor.setColorFilter(color);
});
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ForecastWidgetViewModel model = new ViewModelProvider(this).get(ForecastWidgetViewModel.class);
ColorViewModel color = new ViewModelProvider(this).get(ColorViewModel.class);
color.getState().observe(getViewLifecycleOwner(), state -> {
if (state == ColorViewModel.State.CONFIRMED) {
model.getColor().setValue(color.getColor().getValue());
}
});
RecyclerView recyclerView = view.findViewById(R.id.recycler);
recyclerView.setAdapter(new CityEntryListAdapter(
getViewLifecycleOwner(),
(selection)-> model.getSelection().setValue(selection),
model.getCities(),
model.getSelection()));
model.getFinished().observe(getViewLifecycleOwner(), (c) -> {
if (c != null) finish(c, model.getCelsius().getValue(), model.getColor().getValue());
});
model.getDialog().observe(getViewLifecycleOwner(), (d) -> {
if (d) {
color.setColor(model.getColor().getValue());
color.setState(ColorViewModel.State.VISIBLE);
ColorDialogFragment cdf = new ColorDialogFragment();
cdf.show(getChildFragmentManager(), "color");
model.getDialog().setValue(false);
}
});
}
/**
* Finishes the the configuration and stores the widget configuration in the database.
*
* @param city The city.
* @param color The color.
* @param celsius A flag to indicate whether the widget uses celsius or fahrenheit.
*/
public void finish(City city, boolean celsius, int color) {
Activity activity = getActivity();
Context app = activity.getApplicationContext();
DatabaseTask<WidgetDatabase, Integer, Widget> task = new DatabaseTask<>((input, database)-> {
long now = System.currentTimeMillis();
Widget w = new Widget();
w.setReference(input);
w.setType(Widget.TYPE_FORECAST);
w.setCelsius(celsius);
w.setDataId(city.getId());
w.setData(city);
w.setDataTime(now);
w.setColor(color);
database.getAccessor().add(w);
return w;
}, (input, result) -> {
ForecastWidgetProvider provider = new ForecastWidgetProvider();
provider.triggerUpdate(app, input, true);
if (!activity.isDestroyed()) {
activity.finish();
}
});
WidgetReceiver.scheduleUpdates(app);
int id = getWidgetId();
task.execute(id, ((IApp)activity.getApplicationContext()).getWidgetRepository().getDatabase());
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
activity.setResult(Activity.RESULT_OK, resultValue);
}
}
@@ -52,7 +52,16 @@ public class LoginFragment extends Fragment {
Navigation.findNavController(binding.getRoot()).navigate(R.id.destination_devices, null, b.build());
break;
case COLLECTION:
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_login_collection);
try {
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_login_collection);
} catch (IllegalArgumentException e) {
// this is most likely bug in the navigation library, since it cannot find the
// node in the xml file which is technically impossible (probably a race during loading)
NavOptions.Builder builder = new NavOptions.Builder().setPopUpTo(R.id.destination_login, true);
builder.setEnterAnim(R.anim.slide_in_right);
builder.setExitAnim(R.anim.slide_out_left);
Navigation.findNavController(binding.getRoot()).navigate(R.id.destination_collection, null, builder.build());
}
break;
}
@@ -0,0 +1,236 @@
package com.mowesta.android.app.fragment;
import android.app.Activity;
import android.app.Application;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavDeepLinkBuilder;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.mowesta.android.app.IApp;
import com.mowesta.android.app.MowestaActivity;
import com.mowesta.android.app.MowestaSettings;
import com.mowesta.android.app.R;
import com.mowesta.android.app.adapter.DeviceEntryPagedListAdapter;
import com.mowesta.android.app.database.Widget;
import com.mowesta.android.app.database.WidgetDatabase;
import com.mowesta.android.app.databinding.FragmentMeasureWidgetBinding;
import com.mowesta.android.app.model.AbstractNetworkViewModel;
import com.mowesta.android.app.model.ColorViewModel;
import com.mowesta.android.app.model.MeasureWidgetViewModel;
import com.mowesta.android.app.task.DatabaseTask;
import com.mowesta.android.app.widget.MeasureWidgetProvider;
import com.mowesta.android.app.widget.WidgetReceiver;
import com.mowesta.android.feign.model.Device;
import java.util.ArrayList;
import java.util.List;
/**
* A fragment to configure the measure widget.
*
* @author Marcus
*/
public class MeasureWidgetFragment extends AbstractNetworkFragment {
/**
* The bundle extra to store the widget id.
*/
private static final String EXTRA_WIDGET_ID = "widget_id";
@Override
protected AbstractNetworkViewModel getNetworkViewModel() {
return new ViewModelProvider(this).get(MeasureWidgetViewModel.class);
}
/**
* Returns the widget id that is currently configured.
*
* @return The widget id that is currently configured.
*/
public int getWidgetId() {
return getArguments().getInt(EXTRA_WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
/**
* Creates a new instance with the widget id.
*
* @param widgetId The widget id.
* @return The instance.
*/
public static MeasureWidgetFragment newInstance(int widgetId) {
Bundle b = new Bundle();
b.putInt(EXTRA_WIDGET_ID, widgetId);
MeasureWidgetFragment fragment = new MeasureWidgetFragment();
fragment.setArguments(b);
return fragment;
}
@Nullable
@Override
protected View getErrorAnchorView() {
return getView().findViewById(R.id.layout_coordinator);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
FragmentMeasureWidgetBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_measure_widget, container, false);
MeasureWidgetViewModel model = new ViewModelProvider(this).get(MeasureWidgetViewModel.class);
binding.setLifecycleOwner(getViewLifecycleOwner());
binding.setModel(model);
List<String> systems = getSystemEntries();
binding.customizeSystem.setAdapter(createAdapter(systems));
List<String> temperatures = getTemperatureEntries();
binding.customizeTemperature.setAdapter(createAdapter(temperatures));
model.getSi().observe(getViewLifecycleOwner(), (value) -> {
binding.customizeSystem.setText(systems.get(value?0:1), false);
});
model.getCelsius().observe(getViewLifecycleOwner(), (value) -> {
binding.customizeTemperature.setText(temperatures.get(value?0:1), false);
});
binding.customizeSystem.setOnItemClickListener((parent, view, position, id) -> {
model.getSi().setValue(position == 0);
});
binding.customizeTemperature.setOnItemClickListener((parent, view, position, id) -> {
model.getCelsius().setValue(position == 0);
});
model.getColor().observe(getViewLifecycleOwner(), (color) -> {
binding.buttonColor.setColorFilter(color);
});
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
MeasureWidgetViewModel model = new ViewModelProvider(this).get(MeasureWidgetViewModel.class);
ColorViewModel color = new ViewModelProvider(this).get(ColorViewModel.class);
color.getState().observe(getViewLifecycleOwner(), state -> {
if (state == ColorViewModel.State.CONFIRMED) {
model.getColor().setValue(color.getColor().getValue());
}
});
RecyclerView recyclerView = view.findViewById(R.id.recycler);
DeviceEntryPagedListAdapter adapter = new DeviceEntryPagedListAdapter(getViewLifecycleOwner(), (device) -> {
model.getSelection().setValue(device);
}, model.getSelection());
IApp app = (IApp)getContext().getApplicationContext();
app.getUserRepository().getCredentials().observe(getViewLifecycleOwner(), (c) -> model.setUserCredentials(c));
SwipeRefreshLayout swipeRefreshLayout = view.findViewById(R.id.swipe_refresh);
model.getDevices().observe(getViewLifecycleOwner(), (list) -> {
adapter.submitList(list);
swipeRefreshLayout.setRefreshing(false);
});
recyclerView.setAdapter(adapter);
swipeRefreshLayout.setOnRefreshListener(() -> model.reload());
model.getFinished().observe(getViewLifecycleOwner(), (c) -> {
if (c != null) finish(c, model.getCelsius().getValue(), model.getSi().getValue(), model.getColor().getValue());
});
model.getLogin().observe(getViewLifecycleOwner(), (v) -> {
if (v) {
startActivity(new Intent(getContext(), MowestaActivity.class));
getActivity().finish();
}
});
model.getDialog().observe(getViewLifecycleOwner(), (d) -> {
if (d) {
color.setColor(model.getColor().getValue());
color.setState(ColorViewModel.State.VISIBLE);
ColorDialogFragment cdf = new ColorDialogFragment();
cdf.show(getChildFragmentManager(), "color");
model.getDialog().setValue(false);
}
});
}
/**
* Creates an array adapter using the customize view entry.
*
* @param strings The strings.
* @return The array adapter.
*/
private ArrayAdapter<String> createAdapter(List<String> strings) {
return new ArrayAdapter<>(getContext(), R.layout.view_customize_entry, strings);
}
/**
* Returns the strings in the system combobox.
*
* @return The strings.
*/
private List<String> getSystemEntries() {
List<String> result = new ArrayList<>(3);
result.add(getString(R.string.customize_system_standard));
result.add(getString(R.string.customize_system_imperial));
return result;
}
/**
* Returns the strings in the temperature combobx.
*
* @return The strings.
*/
private List<String> getTemperatureEntries() {
List<String> result = new ArrayList<>(3);
result.add(getString(R.string.customize_temperature_celsius));
result.add(getString(R.string.customize_temperature_fahrenheit));
return result;
}
/**
* Finishes the the configuration and stores the widget configuration in the database.
*
* @param device The device.
* @param celsius A flag to indicate whether the widget uses celsius or fahrenheit.
* @param color The widget color.
* @param si A flag to indicate which measurement unit system.
*/
public void finish(Device device, boolean celsius, boolean si, int color) {
Activity activity = getActivity();
Context app = activity.getApplicationContext();
DatabaseTask<WidgetDatabase, Integer, Widget> task = new DatabaseTask<>((input, database)-> {
long now = System.currentTimeMillis();
Widget w = new Widget();
w.setReference(input);
w.setType(Widget.TYPE_MEASURE);
w.setCelsius(celsius);
w.setColor(color);
w.setSi(si);
w.setDataId(device.getId());
w.setData(device);
w.setDataTime(now);
database.getAccessor().add(w);
return w;
}, (input, result) -> {
MeasureWidgetProvider provider = new MeasureWidgetProvider();
provider.triggerUpdate(app, input, true);
if (!activity.isDestroyed()) {
activity.finish();
}
});
WidgetReceiver.scheduleUpdates(app);
int id = getWidgetId();
task.execute(id, ((IApp)activity.getApplicationContext()).getWidgetRepository().getDatabase());
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
activity.setResult(Activity.RESULT_OK, resultValue);
}
}
@@ -334,7 +334,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
setClickListener(KEY_ABOUT_TERMS, new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Navigation.findNavController(getActivity(), R.id.navigation_app).navigate(R.id.destination_terms);
Navigation.findNavController(getActivity(), R.id.navigation_app).navigate(R.id.destination_review);
return false;
}
});
@@ -432,7 +432,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
b.setTitle(R.string.setting_privacy_reset_title);
b.setMessage(R.string.setting_privacy_reset_message);
b.setIcon(R.drawable.ic_delete_forever_normal_24);
b.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
b.setPositiveButton(R.string.button_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// stop the service and its background processing
@@ -460,7 +460,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
}).execute();
}
});
b.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
b.setNegativeButton(R.string.button_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// nothing to be done
@@ -16,6 +16,7 @@ import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -54,7 +55,7 @@ public class SplashFragment extends Fragment {
/**
* The handler.
*/
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
/**
* The settings to check states.
@@ -78,6 +79,7 @@ public class SplashFragment extends Fragment {
View title = root.findViewById(R.id.splash_title);
View subtitle = root.findViewById(R.id.splash_subtitle);
View world = root.findViewById(R.id.splash_world);
View logos = root.findViewById(R.id.logo_panel);
AnimatorSet set = new AnimatorSet();
ValueAnimator gradientAnimator = ValueAnimator.ofFloat(0, 1);
gradientAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
@@ -93,6 +95,10 @@ public class SplashFragment extends Fragment {
ObjectAnimator worldAnimator = ObjectAnimator.ofFloat(world, "alpha", 0, 1);
worldAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
worldAnimator.setDuration(750);
logos.setAlpha(0);
ObjectAnimator logoAnimator = ObjectAnimator.ofFloat(logos, "alpha", 0, 1);
logoAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
logoAnimator.setDuration(750);
ObjectAnimator sunAnimator = ObjectAnimator.ofFloat(sun, "alpha", 0, 1);
sunAnimator.setInterpolator(new LinearInterpolator());
sunAnimator.setDuration(150);
@@ -105,6 +111,7 @@ public class SplashFragment extends Fragment {
set.playTogether(sunAnimator, titleAnimator, subtitleAnimator);
set.play(worldAnimator).after(sunAnimator);
set.play(logoAnimator).after(sunAnimator);
set.play(gradientAnimator).after(sunAnimator);
set.start();
return root;
@@ -1,7 +1,6 @@
package com.mowesta.android.app.fragment;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -12,7 +11,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.NavOptions;
@@ -29,7 +27,7 @@ import com.mowesta.android.app.R;
import com.mowesta.android.app.adapter.CityEntryPagedListAdapter;
import com.mowesta.android.app.databinding.FragmentStateBinding;
import com.mowesta.android.app.model.AbstractPlaceViewModel;
import com.mowesta.android.app.model.BindingTransforms;
import com.mowesta.android.app.binding.BindingTransforms;
import com.mowesta.android.app.model.StateViewModel;
import com.mowesta.android.app.util.MapViewUtil;
import com.mowesta.android.feign.model.State;
@@ -108,7 +106,7 @@ public class StateFragment extends AbstractPlaceFragment {
model.getCities().observe(getViewLifecycleOwner(), (list) -> adapter.submitList(list));
recyclerView.setAdapter(adapter);
MapView mapView = view.findViewById(R.id.map_detail);
MapViewUtil.setupInteractiveMap(mapView);
MapViewUtil.setupInteractiveMap(mapView, getResources().getBoolean(R.bool.dark_mode));
Runnable updateMap = () -> {
MapViewUtil.removePolylines(mapView, polylines);
polylines.clear();
@@ -1,12 +1,8 @@
package com.mowesta.android.app.fragment;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
@@ -15,7 +11,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
@@ -29,20 +24,12 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.locoslab.android.leafless.MapView;
import com.locoslab.android.leafless.marker.Marker;
import com.locoslab.library.geometry.wgs.Coordinate;
import com.mowesta.android.app.MowestaSettings;
import com.mowesta.android.app.R;
import com.mowesta.android.app.adapter.CityEntryPagedListAdapter;
import com.mowesta.android.app.adapter.DiagramEntryPagedListAdapter;
import com.mowesta.android.app.databinding.FragmentStateBinding;
import com.mowesta.android.app.databinding.FragmentStationBinding;
import com.mowesta.android.app.model.AbstractNetworkViewModel;
import com.mowesta.android.app.model.BindingTransforms;
import com.mowesta.android.app.model.DiagramEntry;
import com.mowesta.android.app.model.StateViewModel;
import com.mowesta.android.app.model.StationViewModel;
import com.mowesta.android.app.model.StationsViewModel;
import com.mowesta.android.app.util.MapViewUtil;
import com.mowesta.android.feign.model.State;
import com.mowesta.android.feign.model.WeatherReport;
import com.mowesta.android.feign.model.WeatherStation;
@@ -122,7 +109,7 @@ public class StationFragment extends AbstractDiagramFragment {
model.getReports().observe(getViewLifecycleOwner(), (list) -> adapter.submitList(list));
recyclerView.setAdapter(adapter);
MapView mapView = view.findViewById(R.id.map_detail);
MapViewUtil.setupInteractiveMap(mapView);
MapViewUtil.setupInteractiveMap(mapView, getResources().getBoolean(R.bool.dark_mode));
Runnable updateMap = () -> {
if (model.getStation().getValue() != null) {
WeatherStation s = model.getStation().getValue();
@@ -24,6 +24,7 @@ import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.LifecycleOwner;
@@ -33,11 +34,14 @@ import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import androidx.webkit.WebViewAssetLoader;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
@@ -165,7 +169,9 @@ public class TermsFragment extends Fragment {
super.onViewCreated(view, savedInstanceState);
int url = getArguments().getInt("url", 0);
webView = (WebView) view.findViewById(R.id.web_view);
webView.getSettings().setAllowFileAccessFromFileURLs(true);
final WebViewAssetLoader assetLoader = new WebViewAssetLoader.Builder()
.addPathHandler("/assets/", new WebViewAssetLoader.AssetsPathHandler(view.getContext()))
.build();
webView.setWebViewClient(new WebViewClient() {
@Override
@SuppressWarnings("deprecation")
@@ -179,6 +185,20 @@ public class TermsFragment extends Fragment {
}
return true;
}
@Override
@RequiresApi(21)
public WebResourceResponse shouldInterceptRequest(WebView view,
WebResourceRequest request) {
return assetLoader.shouldInterceptRequest(request.getUrl());
}
@Override
@SuppressWarnings("deprecation") // for API < 21
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
return assetLoader.shouldInterceptRequest(Uri.parse(url));
}
});
if (url != 0) {
webView.loadUrl(getResources().getString(url));
@@ -6,10 +6,12 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;
@@ -23,14 +25,15 @@ import androidx.preference.PreferenceManager;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.SimpleExoPlayer;
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.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
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;
@@ -154,7 +157,7 @@ public class VideoFragment extends AbstractNetworkFragment {
/**
* The handler for the timing.
*/
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
/**
* The date formatter.
@@ -272,12 +275,15 @@ public class VideoFragment extends AbstractNetworkFragment {
model.exoPlayer = new SimpleExoPlayer.Builder(getContext()).build();
model.scaler.setContent(video.getWidth(), video.getHeight());
IApp app = (IApp)getActivity().getApplication();
DataSource.Factory dataSourceFactory = new CacheDataSourceFactory
(app.getMediaCache(), new DefaultHttpDataSourceFactory( Util.getUserAgent
(getContext(), getContext().getPackageName()), null));
MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(video.getUrl()));
model.exoPlayer.prepare(videoSource);
DefaultHttpDataSource.Factory hf = new DefaultHttpDataSource.Factory();
hf.setUserAgent(Util.getUserAgent(getContext(), getContext().getPackageName()));
CacheDataSource.Factory cdf = new CacheDataSource.Factory();
cdf.setUpstreamDataSourceFactory(hf);
cdf.setCache(app.getMediaCache());
MediaSource videoSource = new ProgressiveMediaSource.Factory(cdf)
.createMediaSource(MediaItem.fromUri(video.getUrl()));
model.exoPlayer.setMediaSource(videoSource);
model.exoPlayer.prepare();
model.exoPlayer.setPlayWhenReady(true);
model.scaleUrl = video.getScale();
model.reload();
@@ -311,7 +317,8 @@ public class VideoFragment extends AbstractNetworkFragment {
@Override
public void onResume() {
super.onResume();
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Window window = getActivity().getWindow();
if (window != null) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
if (video != null) {
handler.postDelayed(timer, 500);
if (model.markerX != null && model.markerY != null) {
@@ -326,7 +333,8 @@ public class VideoFragment extends AbstractNetworkFragment {
@Override
public void onPause() {
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Window window = getActivity().getWindow();
if (window != null) window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
marker.removeOnLayoutChangeListener(markerListener);
handler.removeCallbacks(timer);
super.onPause();
@@ -1,6 +1,7 @@
package com.mowesta.android.app.model;
import android.app.Application;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
@@ -16,6 +17,11 @@ import com.mowesta.android.app.repository.ClientFactory;
*/
public abstract class AbstractNetworkViewModel extends AndroidViewModel {
/**
* The log tag.
*/
private static final String TAG = "NetworkViewModel";
/**
* A class to store a parameter together with a request code.
*
@@ -87,15 +93,15 @@ public abstract class AbstractNetworkViewModel extends AndroidViewModel {
*/
public AbstractNetworkViewModel(@NonNull Application application) {
super(application);
this.requests.observeForever((v) -> printState());
this.error.observeForever((v) -> printState());
//this.requests.observeForever((v) -> printState());
//this.error.observeForever((v) -> printState());
}
/**
* Prints the internal state of the model.
*/
private void printState() {
System.out.println(getClass().getSimpleName() + " " + requestCode + " " + error.getValue() + " " + requests.getValue());
Log.d(TAG, getClass().getSimpleName() + " " + requestCode + " " + error.getValue() + " " + requests.getValue());
}
@@ -181,7 +187,7 @@ public abstract class AbstractNetworkViewModel extends AndroidViewModel {
this.requests.setValue(0);
this.error.setValue(Boolean.FALSE);
requestCode += 1;
printState();
//printState();
return requestCode;
}
@@ -1,20 +1,16 @@
package com.mowesta.android.app.model;
import android.app.Application;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.DataSource;
import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;
import androidx.paging.PositionalDataSource;
import com.mowesta.android.app.IApp;
import com.mowesta.android.app.repository.ClientFactory;
import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.feign.model.City;
import com.mowesta.android.feign.model.CityPage;
@@ -36,7 +32,7 @@ public class CitiesViewModel extends AbstractNetworkViewModel {
/**
* A handler to run on the main thread.
*/
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
/**
* Creates the view model.
@@ -11,8 +11,7 @@ import com.mowesta.android.app.database.Favorite;
import com.mowesta.android.app.database.FavoriteDatabase;
import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.app.task.DatabaseTask;
import com.mowesta.android.app.util.DateFormatter;
import com.mowesta.android.app.util.TimeUtils;
import com.mowesta.android.app.util.WeatherAggregate;
import com.mowesta.android.feign.api.DefaultApi;
import com.mowesta.android.feign.model.City;
import org.geojson.Geometry;
@@ -254,8 +253,6 @@ public class CityViewModel extends AbstractPlaceViewModel {
forecast.observeForever((c)-> updateConditions());
city.observeForever((c)-> { updateConditions(); updateVideos(); updateLinks(); } );
videos.observeForever((c) -> updateVideos());
}
@Override
@@ -397,9 +394,9 @@ public class CityViewModel extends AbstractPlaceViewModel {
*/
private void updateVideos() {
if (city.getValue() == null || videos.getValue() == null) {
iconEurope.setValue(null);
iconGlobal.setValue(null);
cosmoEurope.setValue(null);
iconEurope.setValue(new ArrayList<>());
iconGlobal.setValue(new ArrayList<>());
cosmoEurope.setValue(new ArrayList<>());
} else {
List<VideoViewModel> ieu = new ArrayList<>();
List<VideoViewModel> igl = new ArrayList<>();
@@ -444,86 +441,10 @@ public class CityViewModel extends AbstractPlaceViewModel {
day.setValue(null);
time.setValue(null);
} else {
DateFormatter df = new DateFormatter(getApplication());
long now = System.currentTimeMillis();
String tz = city.getValue().getTimezone();
TimeUtils d = new TimeUtils(now, tz);
List<WeatherCondition> wc = new ArrayList<>(forecast.getValue().getConditions());
Collections.sort(wc, (a, b) -> (int)(a.getTime() - b.getTime()));
List<ConditionViewModel> hours = new ArrayList<>();
List<List<WeatherCondition>> days = new ArrayList<>();
List<List<WeatherCondition>> times = new ArrayList<>();
List<WeatherCondition> currentDay = null;
List<WeatherCondition> currentTime = null;
for (WeatherCondition c: wc) {
long end = d.getEnd(c);
ConditionViewModel vm = new ConditionViewModel(getApplication());
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<>();
currentDay.add(c);
} else {
if (d.isSameDay(d.getTime(currentDay), c.getTime())) {
currentDay.add(c);
} else {
days.add(currentDay);
currentDay = new ArrayList<>();
currentDay.add(c);
}
}
if (!d.isSameDay(d.getTime(currentDay), end)) {
days.add(currentDay);
currentDay = new ArrayList<>();
currentDay.add(c);
}
if (currentTime == null) {
currentTime = new ArrayList<>();
currentTime.add(c);
} else {
if (d.isSameSlot(d.getTime(currentTime), c.getTime())) {
currentTime.add(c);
} else {
times.add(currentTime);
currentTime = new ArrayList<>();
currentTime.add(c);
}
}
if (!d.isSameSlot(d.getTime(currentTime), end)) {
times.add(currentTime);
currentTime = new ArrayList<>();
currentTime.add(c);
}
}
if (currentDay != null) days.add(currentDay);
if (currentTime != null) times.add(currentTime);
List<SummaryViewModel> models = new ArrayList<>();
for (List<WeatherCondition> ds: days) {
long time = d.getTime(ds);
String title = d.getDayName(getApplication(), time);
SummaryViewModel summary = new SummaryViewModel(getApplication());
WeatherCondition[] data = new WeatherCondition[ds.size()];
data = ds.toArray(data);
summary.setData(title, getApplication().getString(R.string.label_full_day), data, tz);
models.add(summary);
}
day.setValue(models);
models = new ArrayList<>();
for (List<WeatherCondition> ts: times) {
long time = d.getTime(ts);
String title = d.getDayName(getApplication(), time);
int slot = d.getSlotName(time);
SummaryViewModel summary = new SummaryViewModel(getApplication());
WeatherCondition[] data = new WeatherCondition[ts.size()];
data = ts.toArray(data);
summary.setData(title, getApplication().getString(slot), data, tz);
models.add(summary);
}
time.setValue(models);
hour.setValue(hours);
WeatherAggregate a = WeatherAggregate.getAggregate(getApplication(), city.getValue().getTimezone(), forecast.getValue().getConditions());
hour.setValue(a.getHours());
day.setValue(a.getDays());
time.setValue(a.getTimes());
}
}
@@ -0,0 +1,121 @@
package com.mowesta.android.app.model;
import android.graphics.Color;
import android.view.View;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;
/**
* The view model for the color picker dialog.
*
* @author Marcus
*/
public class ColorViewModel extends ViewModel {
/**
* The dialog state.
*/
public static enum State {
/** The dialog is hidden. */
HIDDEN,
/** The dialog is visible. */
VISIBLE,
/** The dialog is confirmed. */
CONFIRMED,
/** The dialog is dismissed. */
DISMISSED
}
/** The red component from 0-255 */
private final MutableLiveData<Float> red = new MutableLiveData<>(Float.valueOf(255));
/** The green component from 0-255 */
private final MutableLiveData<Float> green = new MutableLiveData<>(Float.valueOf(255));
/** The blue component from 0-255 */
private final MutableLiveData<Float> blue = new MutableLiveData<>(Float.valueOf(255));
/** The computed color as RGB */
private final MutableLiveData<Integer> color = new MutableLiveData<Integer>();
/** The dialog state. */
private final MutableLiveData<State> state = new MutableLiveData<>(State.HIDDEN);
/**
* Creates a new model.
*/
public ColorViewModel() {
Observer<Float> observer = (v) -> {
color.setValue(Color.rgb(red.getValue().intValue(), green.getValue().intValue(), blue.getValue().intValue()));
};
red.observeForever(observer);
green.observeForever(observer);
blue.observeForever(observer);
observer.onChanged(0f);
}
/**
* Returns live data with the state.
*
* @return The live data with the state.
*/
public LiveData<State> getState() {
return state;
}
/**
* Returns the color.
*
* @return The color.
*/
public LiveData<Integer> getColor() {
return color;
}
/**
* The blue component 0-255.
*
* @return The blue component.
*/
public MutableLiveData<Float> getBlue() {
return blue;
}
/**
* The red component 0-255.
*
* @return The red component.
*/
public MutableLiveData<Float> getRed() {
return red;
}
/**
* The green component 0-255.
*
* @return The green component.
*/
public MutableLiveData<Float> getGreen() {
return green;
}
/**
* Sets the color.
*
* @param rgb The rgb color.
*/
public void setColor(int rgb) {
red.setValue(Float.valueOf((rgb >> 16) & 0xff));
green.setValue(Float.valueOf((rgb >> 8) & 0xff));
blue.setValue(Float.valueOf((rgb >> 0) & 0xff));
}
/**
* Sets the dialog state.
*
* @param state The state.
*/
public void setState(State state) {
this.state.setValue(state);
}
}
@@ -4,7 +4,6 @@ import android.app.Application;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
@@ -1,12 +1,10 @@
package com.mowesta.android.app.model;
import android.app.Application;
import android.app.Presentation;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.DataSource;
@@ -14,10 +12,8 @@ import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;
import androidx.paging.PositionalDataSource;
import com.mowesta.android.app.IApp;
import com.mowesta.android.app.database.Favorite;
import com.mowesta.android.app.database.FavoriteDatabase;
import com.mowesta.android.app.repository.ClientFactory;
import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.app.task.DatabaseTask;
import com.mowesta.android.feign.api.DefaultApi;
@@ -25,7 +21,6 @@ import com.mowesta.android.feign.model.City;
import com.mowesta.android.feign.model.CityPage;
import com.mowesta.android.feign.model.Country;
import com.mowesta.android.feign.model.LocationReference;
import com.mowesta.android.feign.model.State;
import org.geojson.Geometry;
@@ -61,7 +56,7 @@ public class CountryViewModel extends AbstractPlaceViewModel {
/**
* The handler to run on main.
*/
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
/**
* The loader for the country.
@@ -7,7 +7,6 @@ import android.content.res.Resources;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;
import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
import com.mowesta.android.app.MowestaSettings;
@@ -1,8 +1,8 @@
package com.mowesta.android.app.model;
import android.app.Application;
import android.icu.util.Measure;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
@@ -12,6 +12,7 @@ import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;
import androidx.paging.PositionalDataSource;
import com.mowesta.android.app.binding.DiagramEntry;
import com.mowesta.android.app.repository.UserCredentials;
import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.feign.model.Device;
@@ -59,7 +60,7 @@ public class DeviceViewModel extends AbstractNetworkViewModel {
/**
* The handler to run on main.
*/
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
/**
* Creates a new view model.
@@ -2,6 +2,7 @@ package com.mowesta.android.app.model;
import android.app.Application;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
@@ -13,11 +14,8 @@ import androidx.paging.PositionalDataSource;
import com.mowesta.android.app.repository.UserCredentials;
import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.feign.api.DefaultApi;
import com.mowesta.android.feign.model.Device;
import com.mowesta.android.feign.model.DevicePage;
import com.mowesta.android.feign.model.WeatherStation;
import com.mowesta.android.feign.model.WeatherStationPage;
import java.util.ArrayList;
@@ -28,18 +26,6 @@ import java.util.ArrayList;
*/
public class DevicesViewModel extends AbstractNetworkViewModel {
/**
* A listener that is informed when a device is selected.
*/
public interface OnDeviceSelectedListener {
/**
* Called when a device is selected.
*
* @param device The selected device.
*/
void onDeviceSelected(Device device);
}
/**
* The list with the user's devices.
@@ -54,7 +40,7 @@ public class DevicesViewModel extends AbstractNetworkViewModel {
/**
* The handler to debounce the updates to the search term.
*/
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
/**
* Creates the view model.
@@ -78,7 +64,7 @@ public class DevicesViewModel extends AbstractNetworkViewModel {
}, config);
builder.setFetchExecutor((r) -> handler.post(r));
devices = builder.build();
credentials.removeObserver((c) -> {
credentials.observeForever((c) -> {
reload();
});
}
@@ -94,6 +80,7 @@ public class DevicesViewModel extends AbstractNetworkViewModel {
@Override
public void reload() {
error.setValue(false);
PagedList<Device> list = devices.getValue();
if (list != null) {
list.getDataSource().invalidate();
@@ -108,6 +95,14 @@ public class DevicesViewModel extends AbstractNetworkViewModel {
return devices;
}
/**
* Returns a live data object to access the credentials.
*
* @return The credentials.
*/
public LiveData<UserCredentials> getCredentials() {
return credentials;
}
/**
* A data source for the paging framework that loads the
@@ -2,7 +2,6 @@ package com.mowesta.android.app.model;
import android.app.Application;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
@@ -15,6 +14,7 @@ import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.feign.model.LocationHierarchyPage;
import android.os.Handler;
import android.os.Looper;
import java.util.Collections;
@@ -51,7 +51,7 @@ public class DrawerViewModel extends AbstractNetworkViewModel {
/**
* A handler to debounce the search.
*/
final Handler handler = new Handler();
final Handler handler = new Handler(Looper.getMainLooper());
/**
* The task to perform the search.
@@ -12,9 +12,15 @@ import com.mowesta.android.app.database.Favorite;
import com.mowesta.android.app.database.FavoriteDatabase;
import com.mowesta.android.app.repository.UserCredentials;
import com.mowesta.android.app.repository.UserRepository;
import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.app.task.DatabaseTask;
import com.mowesta.android.app.task.RefreshTask;
import com.mowesta.android.app.task.SyncTask;
import com.mowesta.android.feign.api.DefaultApi;
import com.mowesta.android.feign.model.LocationReference;
import com.mowesta.android.feign.model.Settings;
import java.util.ArrayList;
import java.util.List;
/**
@@ -38,6 +44,55 @@ public class FavoritesViewModel extends AndroidViewModel {
void onFavoriteSelected(Favorite favorite);
}
/**
*The task that applies reorderings to the backend.
*/
private ApiTask<List<Favorite>, Void> remoteReorderTask = new ApiTask<>((input, client)->{
Settings settings = client.getCurrentUserSettings();
List<LocationReference> oldReferences = settings.getLocations();
List<LocationReference> newReferences = new ArrayList<>();
for (Favorite f: input) {
search: for (int i = 0; i < oldReferences.size(); i++) {
LocationReference r = oldReferences.get(i);
if (r.getType() == f.getType() && r.getId() != null && r.getId().equals(f.getId())) {
newReferences.add(r);
oldReferences.remove(i);
break search;
}
}
}
newReferences.addAll(oldReferences);
settings.setLocations(newReferences);
client.setCurrentUserSettings(settings);
return null;
},(input, output)->{
// nothing to do
}, (input, status)->{
// ignore for now
});
/**
* The tasks that performs a local reordering in the database.
*/
private DatabaseTask<FavoriteDatabase, List<Favorite>, Void> localReoderTask = new DatabaseTask<>(
(list, database) -> {
database.runInTransaction(() -> {
for (int i = 0; i < list.size(); i++) {
Favorite input = list.get(i);
Favorite target = database.getAccessor().findById(input.getType(), input.getId());
if (target != null && !target.isDeleted()) {
target.setPosition(i);
database.getAccessor().update(target);
}
}
});
return null;
}, (input, output) -> {
updateRemote(input);
});
/**
* The live data list of favorites from the database.
*/
@@ -130,4 +185,26 @@ public class FavoritesViewModel extends AndroidViewModel {
}
}
/**
* Updates the order of the favorites locally and remotely.
*
* @param favorites The favorites.
*/
public void updateFavorites(List<Favorite> favorites) {
localReoderTask.execute(favorites, getFavoriteDatabase());
}
/**
* Updates the favorites remotely.
*
* @param favorites The favorites.
*/
private void updateRemote(List<Favorite> favorites) {
UserCredentials c = getUserRepository().getCredentials().getValue();
if (c != null) {
remoteReorderTask.execute(favorites, getApp().getClientFactory().createClient(c));
}
}
}
@@ -0,0 +1,192 @@
package com.mowesta.android.app.model;
import android.app.Application;
import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import com.mowesta.android.app.R;
import com.mowesta.android.app.database.Favorite;
import com.mowesta.android.app.database.FavoriteDatabase;
import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.app.task.DatabaseTask;
import com.mowesta.android.feign.model.City;
import com.mowesta.android.feign.model.CityPage;
import com.mowesta.android.feign.model.LocationReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* A view model for a forecast widget. It provides possibilities to search for cities with a term
* and a list of favorites.
*
* @author Johannes
*/
public class ForecastWidgetViewModel extends AbstractNetworkViewModel {
/**
* The log tag.
*/
private static final String TAG = "ForecastWidgetViewModel";
/**
* A handler to post updates.
*/
private final Handler handler = new Handler(Looper.getMainLooper());
/** A flag to indicate whether the submit button can be pressed. */
private final MutableLiveData<Boolean> valid = new MutableLiveData<>(Boolean.FALSE);
/** The selected city, once the submit button has been pressed. */
private final MutableLiveData<City> finished = new MutableLiveData<>(null);
/** The search term. */
private final MutableLiveData<String> term = new MutableLiveData<>("");
/** The currently selected city. */
private final MutableLiveData<City> selection = new MutableLiveData<>(null);
/** The cities that are displayed in the list. */
private final MutableLiveData<List<City>> cities = new MutableLiveData<>(new ArrayList<>());
/** A boolean to indicate the temperature scale. */
private final MutableLiveData<Boolean> celsius = new MutableLiveData<>(Boolean.TRUE);
/** The color for the widget. */
private final MutableLiveData<Integer> color = new MutableLiveData<>(Color.rgb(255, 255, 255));
/** A boolean to indicate that the dialog should be opened. */
private final MutableLiveData<Boolean> dialog = new MutableLiveData<>(Boolean.FALSE);
/** The favorites of the user that are displayed, if there is no search term. */
private final MutableLiveData<List<City>> favorites = new MutableLiveData<>(new ArrayList<>());
private ApiTask<RequestParameter<String>, CityPage> searchTask = new ApiTask<>(
(input, client) -> {
CityPage cities = client.searchCities(getApplication().getString(R.string.language_code), input.getValue(), 0, 20, null);
return cities;
},
(input, result) -> {
completeRequest(input, () -> cities.setValue(result.getElements()));
},
(input, status) -> {
finishRequest(input, true);
});
private DatabaseTask<FavoriteDatabase, Void, List<City>> favoritesTask = new DatabaseTask<>((input, database)-> {
List<Favorite> fs = database.getAccessor().getActive(LocationReference.TypeEnum.CITY.ordinal());
List<City> rs = new ArrayList<>();
for (Favorite f: fs) {
City c = f.getCity();
if (c != null) rs.add(c);
}
return rs;
}, (input, output) -> {
favorites.setValue(output);
if (term.getValue().length() == 0) {
cities.setValue(output);
}
});
/**
* Creates a new view model.
*
* @param application The application.
*/
public ForecastWidgetViewModel(@NonNull Application application) {
super(application);
term.observeForever(v -> executeSearch(v));
selection.observeForever(v -> valid.setValue(v != null));
favoritesTask.execute(null, getApp().getFavoriteRepository().getDatabase());
}
/*
public LiveData<LocationHierarchyPage> getResults() {
return results;
}*/
public MutableLiveData<String> getTerm() {
return term;
}
@Override
public void reload() {
this.term.setValue(term.getValue());
}
private void executeSearch(final String term) {
long code = newRequestCode();
selection.setValue(null);
if (term.length() == 0) {
cities.setValue(favorites.getValue());
} else if (term.length() < 3) {
cities.setValue(new ArrayList<>());
} else {
cities.setValue(new ArrayList<>());
startRequest(code);
handler.postDelayed(() -> {
if (isCurrentRequest(code)) {
searchTask.execute(new RequestParameter<>(code, term), getClientFactory().createClient());
}
}, 250);
}
}
public MutableLiveData<List<City>> getCities() {
return cities;
}
public MutableLiveData<Boolean> getValid() {
return valid;
}
public MutableLiveData<Boolean> getCelsius() {
return celsius;
}
public MutableLiveData<City> getFinished() {
return finished;
}
public MutableLiveData<City> getSelection() {
return selection;
}
public MutableLiveData<Integer> getColor() {
return color;
}
public MutableLiveData<Boolean> getDialog() {
return dialog;
}
public void setCelsius(boolean value) {
this.celsius.setValue(value);
}
public void onSave() {
City c = selection.getValue();
if (c != null) {
finished.setValue(c);
}
}
public void onColor() {
dialog.setValue(Boolean.TRUE);
}
private static CityPage emptyPage() {
CityPage result = new CityPage();
result.setElements(Collections.emptyList());
result.setTotal(0);
result.setOffset(0);
result.setSize(20);
return result;
}
}
@@ -1,21 +1,10 @@
package com.mowesta.android.app.model;
import android.content.Context;
import android.location.Location;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.BindingAdapter;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.mowesta.android.app.R;
import com.mowesta.android.feign.model.LocationHierarchy;
import java.util.Map;
/**
* The view model for a location view.
*/
@@ -2,6 +2,7 @@ package com.mowesta.android.app.model;
import android.app.Application;
import android.os.Build;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
@@ -10,11 +11,14 @@ import androidx.lifecycle.MutableLiveData;
import com.mowesta.android.app.IApp;
import com.mowesta.android.app.R;
import com.mowesta.android.app.database.FavoriteDatabase;
import com.mowesta.android.app.repository.ClientFactory;
import com.mowesta.android.app.repository.DeviceRepository;
import com.mowesta.android.app.repository.UserCredentials;
import com.mowesta.android.app.repository.UserRepository;
import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.app.task.RefreshTask;
import com.mowesta.android.app.task.SyncTask;
import com.mowesta.android.feign.api.DefaultApi;
import com.mowesta.android.feign.model.Device;
import com.mowesta.android.feign.model.DeviceHandle;
@@ -114,8 +118,11 @@ public class LoginViewModel extends AndroidViewModel {
info.setOs(DeviceInfo.OsEnum.ANDROID);
return client.createDevice(info);
}, (input, result) -> {
if (input != null) getUserRepository().setCredentials(input);
getDeviceRepository().setDevice(result);
if (input != null) {
getUserRepository().setCredentials(input);
syncFavorites();
}
destination.setValue(Destination.COLLECTION);
}, (input, status) -> {
checking.setValue(false);
@@ -135,6 +142,7 @@ public class LoginViewModel extends AndroidViewModel {
getUserRepository().setCredentials((UserCredentials)input[0]);
getDeviceRepository().setDevice(result);
destination.setValue(Destination.DEVICES);
syncFavorites();
}, (input, status) -> {
checking.setValue(false);
if (status == 403) {
@@ -154,6 +162,7 @@ public class LoginViewModel extends AndroidViewModel {
(input, result)-> {
getUserRepository().setCredentials(input);
destination.setValue(Destination.DEVICES);
syncFavorites();
}, (input, status) -> {
checking.setValue(false);
if (status == 403) {
@@ -448,5 +457,27 @@ public class LoginViewModel extends AndroidViewModel {
}
private FavoriteDatabase getFavoriteDatabase() {
return ((IApp)getApplication()).getFavoriteRepository().getDatabase();
}
/**
* Triggers the synchronization of the favorites.
*/
private void syncFavorites() {
Log.d("LoginViewModel", "Syncing favorites.");
UserCredentials credentials = getUserRepository().getCredentials().getValue();
DefaultApi api = getClientFactory().createClient(credentials);
RefreshTask refreshTask = new RefreshTask(getFavoriteDatabase(), (success)-> {
Log.d("LoginViewModel", "Refresh complete: " + success);
});
SyncTask syncTask = new SyncTask(getFavoriteDatabase(), (success)-> {
Log.d("LoginViewModel", "Sync complete: " + success);
refreshTask.execute(api);
});
syncTask.execute(api);
}
}
@@ -0,0 +1,155 @@
package com.mowesta.android.app.model;
import android.app.Application;
import android.graphics.Color;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import com.mowesta.android.feign.model.Device;
/**
* The view model to configure a measure widget.
*
* @author Marcus
*/
public class MeasureWidgetViewModel extends DevicesViewModel {
/** A flag to indicate whether the submit button can be pressed. */
private final MutableLiveData<Boolean> valid = new MutableLiveData<>(Boolean.FALSE);
/** The selected device, once the submit button has been pressed. */
private final MutableLiveData<Device> finished = new MutableLiveData<>(null);
/** A flag to indicate that the user pressed the login button. */
private final MutableLiveData<Boolean> login = new MutableLiveData<>(Boolean.FALSE);
/** The currently selected device. */
private final MutableLiveData<Device> selection = new MutableLiveData<>(null);
/** A boolean to indicate the temperature scale. */
private final MutableLiveData<Boolean> celsius = new MutableLiveData<>(Boolean.TRUE);
/** A boolean to indicate the temperature scale. */
private final MutableLiveData<Boolean> si = new MutableLiveData<>(Boolean.TRUE);
/** The color for the widget. */
private final MutableLiveData<Integer> color = new MutableLiveData<>(Color.rgb(255, 255, 255));
/** A boolean to indicate that the dialog should be opened. */
private final MutableLiveData<Boolean> dialog = new MutableLiveData<>(Boolean.FALSE);
/**
* Creates the view model.
*
* @param application The application.
*/
public MeasureWidgetViewModel(@NonNull Application application) {
super(application);
selection.observeForever(v -> valid.setValue(v != null));
}
/**
* Called when the user presses the save button.
*/
public void onSave() {
Device d = selection.getValue();
if (d != null) {
finished.setValue(d);
}
}
/**
* Called if the user pressed the login button.
*/
public void onLogin() {
login.setValue(Boolean.TRUE);
}
public void setCelsius(boolean value) {
this.celsius.setValue(value);
}
public void setSi(boolean value) {
this.si.setValue(value);
}
/**
* Returns the live data with the unit system.
*
* @return The live data.
*/
public MutableLiveData<Boolean> getSi() {
return si;
}
/**
* Returns the live data with the temperature unit.
*
* @return The live data.
*/
public MutableLiveData<Boolean> getCelsius() {
return celsius;
}
/**
* Returns the live data with the model validity.
*
* @return The live data.
*/
public MutableLiveData<Boolean> getValid() {
return valid;
}
/**
* Returns the live data with the selected device.
*
* @return The live data.
*/
public MutableLiveData<Device> getSelection() {
return selection;
}
/**
* Returns the live data with the final selection.
*
* @return The live data.
*/
public MutableLiveData<Device> getFinished() {
return finished;
}
/**
* Returns the live data with the final selection.
*
* @return The live data.
*/
public MutableLiveData<Boolean> getLogin() { return login; }
/**
* Returns the current color.
*
* @return The color.
*/
public MutableLiveData<Integer> getColor() {
return color;
}
/**
* Returns a boolean to signal that the color picker shall be opened.
*
* @return The dialog state.
*/
public MutableLiveData<Boolean> getDialog() {
return dialog;
}
/**
* Called when the color button is pressed.
*/
public void onColor() {
dialog.setValue(Boolean.TRUE);
}
}
@@ -1,7 +1,6 @@
package com.mowesta.android.app.model;
import android.app.Application;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -9,244 +8,21 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.mowesta.android.app.binding.MeasurementType;
import com.mowesta.android.app.binding.MeasurementValue;
import com.mowesta.android.feign.model.Measurement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The view model to display a single measurement
* in a bottom sheet dialog.
* The view model to display a single measurement in a bottom sheet dialog.
*
* @author Marcus
*/
public class MeasurementViewModel extends AndroidViewModel {
/**
* The types of measurement context.
*
* @author Sebastian
*/
public enum MeasurementType {
/**
* A boolean to identify whether the battery is charging.
* e.g. true false
*/
BATTERY_CHARGING(Boolean.class),
/**
* The temperature reading of the battery (double value in centigrade, can be read through ACTION_BATTERY_CHANGED).
* e.g. 37.1, -1.3
*/
BATTERY_TEMPERATURE(Double.class),
/**
* A temperature reading of a temperature sensor (double value in centigrade, TYPE_TEMERATURE on Android).
* e.g. 37.1, -1.3
*/
SENSOR_TEMPERATURE(Double.class),
/**
* A pressure reading of a barometer sensor (double value in hPa, TYPE_BAROMETER on Android).
* e.g. 1000.0, 998.26127
*/
SENSOR_PRESSURE(Double.class),
/**
* A humidity reading of a humidity sensor (double value as relative humidity in %, TYPE_RELATIVE_HUMIDITY on Android).
* range: 0-1 (0->0%, 1->100%, 0.5->50%)
*/
SENSOR_HUMIDITY(Double.class),
/**
* The temperature of the cpu (double value in centigrade, can be read by analyzing the proc file system).
* e.g. 37.1 -1.3
*/
CPU_TEMPERATURE(Double.class),
/**
* The current frequency of the cpu (double value in mhz, can be read by analyzing the proc file system).
*/
CPU_FREQUENCY(Double.class),
/**
* A boolean to determine whether the screen is on (true) or off (false).
*/
SCREEN_ENABLED(Boolean.class),
/**
* The voltage of the battery (used to monitor the battery of the weather station).
* e.g. 3.77 -> 3.77 Volt
*/
BATTERY_VOLTAGE(Double.class),
/**
* The voltage of the solar panel (used to estimate whether the weather station is located in the sun).
* e.g. 3.77 -> 3.77 Volt
*/
SOLAR_VOLTAGE(Double.class);
/**
* The data type.
*/
private Class<?> type;
/**
* Creates a measurement type with the specified data type.
*
* @param type The data type expected for the measurement.
*/
private MeasurementType(Class<?> type) {
this.type = type;
}
/**
* Returns the data type.
*
* @return The data type.
*/
public Class<?> getType() {
return type;
}
/**
* Parses the data and returns a java array with the type
* represented by this constant or an empty array, if the
* data cannot be parsed.
*
* @param value The value to parse.
* @return The java object.
*/
public Object[] getValues(String value) {
List<Object> result = new ArrayList<>();
if (value != null) {
String[] substrings = value.split(",");
if (type == Boolean.class) {
for (String s: substrings) {
Boolean b = (Boolean)parseValue(s);
if (b != null) result.add(b);
}
} else if (type == Double.class) {
for (String s: substrings) {
Double d = (Double)parseValue(s);
if (d != null) result.add(d);
}
}
}
return result.toArray(new Object[result.size()]);
}
/**
* Parses a single value.
*
* @param value The string value.
* @return The parsed value.
*/
private Object parseValue(String value) {
if (value == null) return null;
value = value.trim();
if (type == Boolean.class) {
if ("true".equalsIgnoreCase(value)) return Boolean.TRUE;
if ("false".equalsIgnoreCase(value)) return Boolean.FALSE;
return null;
} else if (type == Double.class) {
try {
return Double.valueOf(Double.parseDouble(value));
} catch (NumberFormatException e) {
return null;
}
} else {
return null;
}
}
}
/**
* Represents a single measurement value.
*
* @author Marcus
*/
public static class MeasurementValue {
/**
* The log tag.
*/
private static final String TAG = "MeasurementValue";
/**
* The measurement type.
*/
private @NonNull MeasurementType type;
/**
* The measurement value.
*/
private @Nullable String value;
/**
* The extracted values.
*/
private @NonNull Object[] values;
public MeasurementValue(@NonNull MeasurementType type, @Nullable String value) {
this.type = type;
this.value = value;
this.values = parseValues();
}
/**
* Tries to parse the value based on the type.
*
* @return The values.
*/
private @NonNull Object[] parseValues() {
try {
return type.getValues(value);
} catch (Exception e) {
Log.e(TAG, "Failed to parse " + type.name() + " from '" + value + "'.", e);
return new Object[0];
}
}
/**
* Returns the type.
*
* @return The type.
*/
@NonNull
public MeasurementType getType() {
return type;
}
/**
* Returns the value(s).
*
* @return The values.
*/
@NonNull
public Object[] getValues() {
return values;
}
/**
* Determines whether this value has at
* least one data item.
*
* @return True if the value has at least one data item..
*/
public boolean hasValue() {
return values.length > 0;
}
}
/**
* The measurement.
*/
@@ -1,7 +1,6 @@
package com.mowesta.android.app.model;
import android.app.Application;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -9,16 +8,8 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.mowesta.android.feign.model.Measurement;
import com.mowesta.android.feign.model.WeatherReport;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The view model to display a single weather report
* in a bottom sheet dialog.
@@ -12,7 +12,6 @@ import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.os.ConfigurationCompat;
import androidx.core.os.LocaleListCompat;
import androidx.lifecycle.AndroidViewModel;
@@ -146,6 +145,7 @@ public class SetupViewModel extends AndroidViewModel {
}
}
@Override
@SuppressWarnings("deprecation")
public void onStatusChanged(String provider, int status, Bundle extras) { }
@Override
public void onProviderEnabled(String provider) { }
@@ -1,11 +1,10 @@
package com.mowesta.android.app.model;
import android.app.Application;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.DataSource;
@@ -13,17 +12,13 @@ import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;
import androidx.paging.PositionalDataSource;
import com.mowesta.android.app.IApp;
import com.mowesta.android.app.database.Favorite;
import com.mowesta.android.app.database.FavoriteDatabase;
import com.mowesta.android.app.repository.ClientFactory;
import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.app.task.DatabaseTask;
import com.mowesta.android.app.task.TaskStatus;
import com.mowesta.android.feign.api.DefaultApi;
import com.mowesta.android.feign.model.City;
import com.mowesta.android.feign.model.CityPage;
import com.mowesta.android.feign.model.Country;
import com.mowesta.android.feign.model.LocationReference;
import com.mowesta.android.feign.model.State;
@@ -60,7 +55,7 @@ public class StateViewModel extends AbstractPlaceViewModel {
/**
* A handler to run on main.
*/
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
/**
* The loader for the state.
@@ -1,12 +1,11 @@
package com.mowesta.android.app.model;
import android.app.Application;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.DataSource;
@@ -14,8 +13,7 @@ import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;
import androidx.paging.PositionalDataSource;
import com.mowesta.android.app.IApp;
import com.mowesta.android.app.repository.ClientFactory;
import com.mowesta.android.app.binding.DiagramEntry;
import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.feign.model.WeatherReport;
import com.mowesta.android.feign.model.WeatherReportPage;
@@ -23,7 +21,6 @@ import com.mowesta.android.feign.model.WeatherStation;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
/**
* The view model to show a page with the weather station and
@@ -65,7 +62,7 @@ public class StationViewModel extends AbstractNetworkViewModel {
/**
* The handler to run on main.
*/
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
/**
* Creates a new view model.
@@ -1,33 +1,17 @@
package com.mowesta.android.app.model;
import android.app.Application;
import android.os.AsyncTask;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.DataSource;
import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;
import androidx.paging.PagedListAdapter;
import androidx.paging.PositionalDataSource;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.mowesta.android.app.IApp;
import com.mowesta.android.app.R;
import com.mowesta.android.app.databinding.ViewStationEntryBinding;
import com.mowesta.android.app.repository.ClientFactory;
import com.mowesta.android.app.task.ApiTask;
import com.mowesta.android.feign.model.City;
import com.mowesta.android.feign.model.CityPage;
import com.mowesta.android.feign.model.WeatherStation;
import com.mowesta.android.feign.model.WeatherStationPage;
@@ -64,7 +48,7 @@ public class StationsViewModel extends AbstractNetworkViewModel {
/**
* The handler to debounce the updates to the search term.
*/
private Handler handler = new Handler();
private Handler handler = new Handler(Looper.getMainLooper());
/**
* Creates the view model.
@@ -3,7 +3,6 @@ package com.mowesta.android.app.model;
import android.app.Application;
import androidx.annotation.Nullable;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
@@ -1,12 +1,7 @@
package com.mowesta.android.app.model;
import android.annotation.SuppressLint;
import android.app.Application;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.provider.MediaStore;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
@@ -16,9 +11,6 @@ import androidx.lifecycle.MutableLiveData;
import com.mowesta.android.app.task.ImageTask;
import com.mowesta.android.feign.model.WeatherVideo;
import java.io.InputStream;
import java.net.URL;
/**
* The view model for weather videos.
*
@@ -0,0 +1,39 @@
package com.mowesta.android.app.repository;
import androidx.room.Room;
import com.mowesta.android.app.IApp;
import com.mowesta.android.app.database.FavoriteDatabase;
import com.mowesta.android.app.database.WidgetDatabase;
/**
* A repository to access the widget database.
*
* @author Marcus
*/
public class WidgetRepository extends Repository {
/**
* The widget database.
*/
private WidgetDatabase database;
/**
* Creates the repository.
*
* @param application The application.
*/
public WidgetRepository(IApp application) {
super(application);
database = Room.databaseBuilder(application.getContext(), WidgetDatabase .class, "widgets").addMigrations(WidgetDatabase.getMigrations()).build();
}
/**
* Returns the database.
*
* @return The database.
*/
public WidgetDatabase getDatabase() {
return database;
}
}
@@ -1,10 +1,10 @@
package com.mowesta.android.app.task;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
import android.util.Log;
import com.mowesta.android.feign.api.DefaultApi;
import com.mowesta.android.sdk.task.AbstractTask;
import feign.FeignException;
@@ -44,7 +44,7 @@ public class ApiTask<I, O> {
/**
* Called when the call fails.
*
* @parma input The input of the call.
* @param input The input of the call.
* @param status The error code of the call.
*/
void onError(I input, int status);
@@ -102,19 +102,17 @@ public class ApiTask<I, O> {
/**
* Triggers the execution of the task in the background.
*
* @param client the api client.
* @param input The input.
* @param client the api client.
*/
@SuppressWarnings("unchecked")
@SuppressLint("StaticFieldLeak")
public void execute(final I input, final DefaultApi client) {
new AsyncTask<I, Void, O>() {
new AbstractTask<O>(true) {
private Exception e;
@Override
@SafeVarargs
protected final O doInBackground( I... is) {
protected final O doInBackground() {
try {
return call.exeucte(is[0], client);
return call.exeucte(input, client);
} catch (Exception e) {
Log.d(TAG, "Exception while executing api task.", e);
this.e = e;
@@ -135,7 +133,7 @@ public class ApiTask<I, O> {
successListener.onSuccess(input, o);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, input);
}.execute();
}
}
@@ -1,10 +1,11 @@
package com.mowesta.android.app.task;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
import androidx.room.RoomDatabase;
import com.mowesta.android.sdk.task.AbstractTask;
/**
* A task that interacts with a room database. Note that this
* task is executed on the serial executor to ensure that it
@@ -82,14 +83,12 @@ public class DatabaseTask<D extends RoomDatabase, I, O> {
* @param database The database.
* @param input The input.
*/
@SuppressWarnings("unchecked")
@SuppressLint("StaticFieldLeak")
public void execute(final I input, final D database) {
new AsyncTask<I, Void, O>() {
new AbstractTask<O>(false) {
@Override
@SafeVarargs
protected final O doInBackground(I... is) {
return call.exeucte(is[0], database);
protected final O doInBackground() {
return call.exeucte(input, database);
}
@Override
@@ -97,7 +96,7 @@ public class DatabaseTask<D extends RoomDatabase, I, O> {
super.onPostExecute(o);
resultListener.onResult(input, o);
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, input);
}.execute();
}
}
@@ -3,12 +3,13 @@ package com.mowesta.android.app.task;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mowesta.android.sdk.task.AbstractTask;
import java.io.InputStream;
import java.net.URL;
@@ -54,12 +55,11 @@ public class ImageTask {
*
* @param url The url to download.
*/
@SuppressWarnings("unchecked")
@SuppressLint("StaticFieldLeak")
public void execute(final @NonNull String url) {
AsyncTask task = new AsyncTask<Void, Void, Bitmap>() {
new AbstractTask<Bitmap>(true) {
@Override
protected Bitmap doInBackground(@SuppressLint("StaticFieldLeak") Void... voids) {
protected Bitmap doInBackground() {
try {
InputStream in = new URL(url).openStream();
return BitmapFactory.decodeStream(in);
@@ -73,8 +73,7 @@ public class ImageTask {
protected void onPostExecute(Bitmap bitmap) {
listener.onResult(url, bitmap);
}
};
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[])new Void[0]);
}.execute();
}
@@ -1,13 +1,13 @@
package com.mowesta.android.app.task;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
import com.mowesta.android.app.database.Favorite;
import com.mowesta.android.app.database.FavoriteDatabase;
import com.mowesta.android.feign.api.DefaultApi;
import com.mowesta.android.feign.model.City;
import com.mowesta.android.feign.model.CityPage;
import com.mowesta.android.sdk.task.AbstractTask;
import java.util.ArrayList;
import java.util.List;
@@ -80,6 +80,8 @@ public class RefreshTask {
return null;
}, (input, output) -> { });
/**
* Creates a new refresh task.
*
@@ -99,23 +101,42 @@ public class RefreshTask {
*/
@SuppressLint("StaticFieldLeak")
public void execute(DefaultApi client) {
new AsyncTask<Void, Void, Boolean>() {
new AbstractTask<Boolean>(true) {
@Override
protected Boolean doInBackground(Void... voids) {
protected Boolean doInBackground() {
List<Favorite> favorites = database.getAccessor().getAll();
List<Favorite> modified = new ArrayList<>();
try {
for (Favorite f: favorites) {
if (! f.isDeleted() && refresh(client, f)) {
modified.add(f);
final List<Favorite> modified = new ArrayList<>();
final List<Favorite> unmodified = new ArrayList<>();
final boolean[] result = new boolean[] { true };
for (Favorite f: favorites) {
ApiTask<Favorite, Boolean> loadTask = new ApiTask<Favorite, Boolean>((input, client)-> {
return (! f.isDeleted() && refresh(client, f));
}, (favorite, updated)-> {
synchronized (modified) {
if (updated) modified.add(favorite);
else unmodified.add(favorite);
modified.notifyAll();;
}
}
if (modified.size() > 0) updateTask.execute(modified, database);
return true;
} catch (Exception e) {
if (modified.size() > 0) updateTask.execute(modified, database);
return false;
}, (favorite, failure)-> {
synchronized (modified) {
unmodified.add(favorite);
result[0] = false;
modified.notifyAll();
}
});
loadTask.execute(f, client);
}
synchronized (modified) {
try {
while (modified.size() + unmodified.size() < favorites.size()) {
modified.wait();
}
} catch (InterruptedException e) {
return false;
}
}
if (modified.size() > 0) updateTask.execute(modified, database);
return result[0];
}
@Override
@@ -123,7 +144,7 @@ public class RefreshTask {
super.onPostExecute(aBoolean);
if (completionListener != null) completionListener.onCompletion(aBoolean);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}.execute();
}
/**
@@ -1,20 +1,18 @@
package com.mowesta.android.app.task;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
import com.mowesta.android.app.database.Favorite;
import com.mowesta.android.app.database.FavoriteDatabase;
import com.mowesta.android.feign.api.DefaultApi;
import com.mowesta.android.feign.model.LocationReference;
import com.mowesta.android.feign.model.Settings;
import com.mowesta.android.sdk.task.AbstractTask;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* A task that will synchronize the entries in the local favorite
@@ -76,9 +74,9 @@ public class SyncTask {
*/
@SuppressLint("StaticFieldLeak")
public void execute(DefaultApi client) {
new AsyncTask<Void, Void, Boolean>() {
new AbstractTask<Boolean>(false) {
@Override
protected Boolean doInBackground(Void... voids) {
protected Boolean doInBackground() {
List<Favorite> favorites = database.getAccessor().getAll();
try {
List<Favorite> favs = new ArrayList<>(favorites);
@@ -168,7 +166,7 @@ public class SyncTask {
if (completionListener != null) completionListener.onCompletion(result);
}
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}.execute();
}
@@ -1,6 +1,7 @@
package com.mowesta.android.app.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
@@ -38,8 +39,8 @@ public class DateFormatter {
* @return The formatted date with time.
*/
public String asDateTime(long time, @Nullable String timezone) {
Date date = getDate(time, timezone);
return getDateFormat().format(date) + " " + getTimeFormat().format(date);
Calendar date = getDate(time, timezone);
return format(getDateFormat(), date) + " " + format(getTimeFormat(), date);
}
/**
@@ -50,7 +51,7 @@ public class DateFormatter {
* @return The formatted date.
*/
public String asDate(long time, @Nullable String timezone) {
return getDateFormat().format(getDate(time, timezone));
return format(getDateFormat(), getDate(time, timezone));
}
/**
@@ -61,7 +62,7 @@ public class DateFormatter {
* @return The formatted time.
*/
public String asTime(long time, @Nullable String timezone) {
return getTimeFormat().format(getDate(time, timezone));
return format(getTimeFormat(), getDate(time, timezone));
}
/**
@@ -71,13 +72,26 @@ public class DateFormatter {
* @param timezone The timezone or null to use the host timezone.
* @return The date.
*/
private Date getDate(long time, @Nullable String timezone) {
private Calendar getDate(long time, @Nullable String timezone) {
Calendar c = Calendar.getInstance();
if (timezone != null) {
c.setTimeZone(TimeZone.getTimeZone(timezone));
}
c.setTimeInMillis(time);
return c.getTime();
return c;
}
/**
* Formats the time in the calendar using the format.
*
* @param format The format.
* @param c The calendar.
* @return The string.
*/
private String format(DateFormat format, Calendar c) {
format.setCalendar(c);
return format.format(c.getTime());
}
/**
@@ -34,9 +34,14 @@ import java.util.List;
public class MapViewUtil {
/**
* The url.
* The url for a light mode tile map.
*/
private static final String URL = "https://cloud.locoslab.com/carta/get/{z}/{x}/{y}.png";
private static final String URL_LIGHT = "https://www.mowesta.com/carta/tile/{z}/{x}/{y}.png";
/**
* The url for a dark mode tile map.
*/
private static final String URL_DARK = "https://www.mowesta.com/carta/tile/dark/{z}/{x}/{y}.png";
/**
@@ -153,7 +158,7 @@ public class MapViewUtil {
*/
public static void setupNonInteractiveMap(MapView mapView) {
setupInteraction(mapView, false);
setupTileLayer(mapView);
setupTileLayer(mapView, false);
}
/**
@@ -176,19 +181,21 @@ public class MapViewUtil {
* Configures an interactive map view.
*
* @param mapView The map view.
* @param darkMode True to enable dark mode, false otherwise
*/
public static void setupInteractiveMap(MapView mapView) {
public static void setupInteractiveMap(MapView mapView, boolean darkMode) {
setupInteraction(mapView, true);
setupTileLayer(mapView);
setupTileLayer(mapView, darkMode);
}
/**
* Adds a tile layer to the map.
*
* @param mapView The map view.
* @param darkMode True to use dark mode.
*/
private static void setupTileLayer(MapView mapView) {
TileLayerOptions options = new TileLayerOptions(URL);
private static void setupTileLayer(MapView mapView, boolean darkMode) {
TileLayerOptions options = new TileLayerOptions(darkMode?URL_DARK:URL_LIGHT);
options.minZoom = 4;
options.maxZoom = 18;
TileLayer layer = new TileLayer(options);
@@ -52,6 +52,42 @@ public class UnitUtils {
return speed * 3.6;
}
/**
* Returns the class on the Beaufort scale for a wind speed
* given in meter per second.
*
* @param value The wind speed.
* @return The beaufort scale (0-12).
*/
public static int mpsToBFT(double value) {
if (value < 0.5d)
return 0;
else if (value < 1.6d)
return 1;
else if (value < 3.4d)
return 2;
else if (value < 5.6d)
return 3;
else if (value < 8.0d)
return 4;
else if (value < 10.8d)
return 5;
else if (value < 13.9d)
return 6;
else if (value < 17.2d)
return 7;
else if (value < 20.8d)
return 8;
else if (value < 24.5d)
return 9;
else if (value < 28.5d)
return 10;
else if (value < 32.7d)
return 11;
else
return 12;
}
/**
* Converts the pressure given in hpa into
* psi.
@@ -119,25 +155,42 @@ public class UnitUtils {
* Returns the temperature as string.
*
* @param context The context.
* @param celsisus The degree in celisus.
* @param celsius The degree in celsius.
* @return The formatted string as defined by the user's preferences.
*/
public static String getTemperature(@NonNull Context context, double celsisus) {
public static String getTemperature(@NonNull Context context, double celsius) {
MowestaSettings.TemperatureUnit unit = getSettings(context).getTemperatureUnit();
return getTemperature(context, celsius, unit);
}
/**
* Returns the temperature formated to a particular unit.
*
* @param context The context.
* @param celsius The degrees celsius.
* @param unit The unit.
* @return The string.
*/
public static String getTemperature(@NonNull Context context, double celsius, @NonNull MowestaSettings.TemperatureUnit unit) {
if (unit == MowestaSettings.TemperatureUnit.CELSIUS) {
return context.getString(R.string.format_temperature_celsius, round(celsisus));
return context.getString(R.string.format_temperature_celsius, celsius);
} else {
int fahrenheit = round(celsiusToFahrenheit(celsisus));
double fahrenheit = celsiusToFahrenheit(celsius);
if (unit == MowestaSettings.TemperatureUnit.FAHRENHEIT) {
return context.getString(R.string.format_temperature_fahrenheit, fahrenheit);
} else {
return context.getString(R.string.format_temperature_both, round(celsisus), fahrenheit);
return context.getString(R.string.format_temperature_both, celsius, fahrenheit);
}
}
}
public static String getPressure(@NonNull Context context, double hpa) {
MowestaSettings.UnitSystem system = getSettings(context).getUnitSystem();
return getPressure(context, hpa, system);
}
public static String getPressure(@NonNull Context context, double hpa, MowestaSettings.UnitSystem system) {
if (system == MowestaSettings.UnitSystem.STANDARD) {
return context.getString(R.string.format_pressure_si, hpa);
} else {
@@ -152,20 +205,23 @@ public class UnitUtils {
public static String getWindSpeed(@NonNull Context context, double mps) {
MowestaSettings.UnitSystem system = getSettings(context).getUnitSystem();
mps = Math.abs(mps); // make sure this is a positive value
if (system == MowestaSettings.UnitSystem.STANDARD) {
return context.getString(R.string.format_wind_speed_si, round(mpsToKmph(mps)));
return context.getString(R.string.format_wind_speed_si, round(mpsToKmph(mps)), mpsToBFT(mps));
} else {
double mph = mpsToMph(mps);
if (system == MowestaSettings.UnitSystem.IMPERIAL) {
return context.getString(R.string.format_wind_speed_im, round(mph));
return context.getString(R.string.format_wind_speed_im, round(mph), mpsToBFT(mps));
} else {
return context.getString(R.string.format_wind_speed_both, round(mpsToKmph(mps)), round(mph));
}
}
}
public static String getPrecipitation(@NonNull Context context, double mm) {
MowestaSettings.UnitSystem system = getSettings(context).getUnitSystem();
mm = Math.max(0, mm); // make sure this is positive
if (system == MowestaSettings.UnitSystem.STANDARD) {
return context.getString(R.string.format_precipitation_si, mm);
} else {
@@ -180,6 +236,7 @@ public class UnitUtils {
public static String getSnowDepth(@NonNull Context context, double m) {
MowestaSettings.UnitSystem system = getSettings(context).getUnitSystem();
m = Math.max(0, m); // make sure this is positive
if (system == MowestaSettings.UnitSystem.STANDARD) {
return context.getString(R.string.format_snow_si, m);
} else {
@@ -0,0 +1,164 @@
package com.mowesta.android.app.util;
import android.app.Application;
import android.content.Context;
import androidx.annotation.NonNull;
import com.mowesta.android.app.R;
import com.mowesta.android.app.model.ConditionViewModel;
import com.mowesta.android.app.model.SummaryViewModel;
import com.mowesta.android.feign.model.WeatherCondition;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* A utility class to aggregate the weather conditions based on a particular
* time zone.
*/
public class WeatherAggregate {
/**
* The days.
*/
private List<SummaryViewModel> days;
/**
* The times.
*/
private List<SummaryViewModel> times;
/**
* The hours.
*/
private List<ConditionViewModel> hours;
/**
* Creates a new aggregate.
*
* @param days The day models.
* @param times The time models.
* @param hours The hour models.
*/
protected WeatherAggregate(@NonNull List<SummaryViewModel> days, @NonNull List<SummaryViewModel> times, @NonNull List<ConditionViewModel> hours) {
this.days = days;
this.hours = hours;
this.times = times;
}
/**
* Returns the hour models.
*
* @return The hour models.
*/
public List<ConditionViewModel> getHours() {
return hours;
}
/**
* Returns the day models.
*
* @return The day models.
*/
public List<SummaryViewModel> getDays() {
return days;
}
/**
* Returns the time-of-day models.
*
* @return The time of day models.
*/
public List<SummaryViewModel> getTimes() {
return times;
}
/**
* Computes and aggregates the forecasts using the timezone of the city.
* This is pretty messy, but it is also not really simple.
*
* @param context The context.
* @param tz The time zone.
* @param wc The weather conditions to aggregate.
* @return The aggregated conditions.
*/
public static WeatherAggregate getAggregate(@NonNull Context context, @NonNull String tz, @NonNull List<WeatherCondition> wc) {
DateFormatter df = new DateFormatter(context);
long now = System.currentTimeMillis();
TimeUtils d = new TimeUtils(now, tz);
Collections.sort(wc, (a, b) -> (int)(a.getTime() - b.getTime()));
List<ConditionViewModel> hourModels = new ArrayList<>();
List<List<WeatherCondition>> days = new ArrayList<>();
List<List<WeatherCondition>> times = new ArrayList<>();
List<WeatherCondition> currentDay = null;
List<WeatherCondition> currentTime = null;
for (WeatherCondition c: wc) {
long end = d.getEnd(c);
ConditionViewModel vm = new ConditionViewModel((Application) context.getApplicationContext());
long time = c.getTime();
String title = d.getDayName(context, time);
String subtitle = context.getString(R.string.format_two_parts, df.asTime(time, tz), df.asDate(time, tz));
vm.setData(title, subtitle, c, tz);
hourModels.add(vm);
if (currentDay == null) {
currentDay = new ArrayList<>();
currentDay.add(c);
} else {
if (d.isSameDay(d.getTime(currentDay), c.getTime())) {
currentDay.add(c);
} else {
days.add(currentDay);
currentDay = new ArrayList<>();
currentDay.add(c);
}
}
if (!d.isSameDay(d.getTime(currentDay), end)) {
days.add(currentDay);
currentDay = new ArrayList<>();
currentDay.add(c);
}
if (currentTime == null) {
currentTime = new ArrayList<>();
currentTime.add(c);
} else {
if (d.isSameSlot(d.getTime(currentTime), c.getTime())) {
currentTime.add(c);
} else {
times.add(currentTime);
currentTime = new ArrayList<>();
currentTime.add(c);
}
}
if (!d.isSameSlot(d.getTime(currentTime), end)) {
times.add(currentTime);
currentTime = new ArrayList<>();
currentTime.add(c);
}
}
if (currentDay != null) days.add(currentDay);
if (currentTime != null) times.add(currentTime);
List<SummaryViewModel> dayModels = new ArrayList<>();
for (List<WeatherCondition> ds: days) {
long time = d.getTime(ds);
String title = d.getDayName(context, time);
SummaryViewModel summary = new SummaryViewModel((Application) context.getApplicationContext());
WeatherCondition[] data = new WeatherCondition[ds.size()];
data = ds.toArray(data);
summary.setData(title, context.getString(R.string.label_full_day), data, tz);
dayModels.add(summary);
}
List<SummaryViewModel> timeModels = new ArrayList<>();
for (List<WeatherCondition> ts: times) {
long time = d.getTime(ts);
String title = d.getDayName(context, time);
int slot = d.getSlotName(time);
SummaryViewModel summary = new SummaryViewModel((Application) context.getApplicationContext());
WeatherCondition[] data = new WeatherCondition[ts.size()];
data = ts.toArray(data);
summary.setData(title, context.getString(slot), data, tz);
timeModels.add(summary);
}
return new WeatherAggregate(dayModels, timeModels, hourModels);
}
}
@@ -0,0 +1,275 @@
package com.mowesta.android.app.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.res.ResourcesCompat;
import com.mowesta.android.app.R;
/**
* A base class for views that show data. Besides from storing the
* values this view also contains some funky logic to create a
* magnifier effect.
*
* @param <T> The type of data to display.
*/
public abstract class DataView<T> extends View {
/** The drawing direction of the gradient. */
public enum Direction {
/** Draw from left to right. */
HORIZONTAL,
/** Draw from top to bottom. */
VERTICAL;
};
/**
* The drawing direction.
*/
@NonNull
protected Direction direction = Direction.VERTICAL;
/**
* A bitmap to draw the magnifier effect.
*/
protected Bitmap bitmap;
/**
* The bitmap size in dp.
*/
protected int bitmapSize;
/**
* The data of the view.
*/
@Nullable
protected T[] data;
/**
* The current selection or null.
*/
@Nullable
protected Float selection;
@NonNull
protected Paint bitmapBorderPaint = new Paint();
/**
* The color for the background.
*/
private int colorNormal;
/**
* The canvas to draw on the bitmap.
*/
private Canvas bitmapCanvas;
/**
* Creates a new view.
*
* @param context The context.
*/
public DataView(Context context) {
super(context);
init(context, null);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
*/
public DataView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
* @param defStyleAttr The style attrs.
*/
public DataView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
* @param defStyleAttr The style attrs.
* @param defStyleRes The style res.
*/
@TargetApi(21)
public DataView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
/**
* Initializes the view.
*
* @param context The context.
* @param attrs The attribute set.
*/
private void init(Context context, @Nullable AttributeSet attrs) {
colorNormal = ResourcesCompat.getColor(context.getResources(), R.color.normal, null);
DisplayMetrics m = getResources().getDisplayMetrics();
bitmapSize = (int)(m.density * 48 + 0.5);
bitmapBorderPaint.setColor(ResourcesCompat.getColor(context.getResources(), R.color.inverse, null));
bitmapBorderPaint.setStyle(Paint.Style.STROKE);
bitmapBorderPaint.setStrokeWidth(4);
if (attrs != null) {
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.DataView);
int type = ta.getInt(R.styleable.DataView_direction,-1);
if (type >= 0 && type < Direction.values().length) {
this.direction = Direction.values()[type];
}
ta.recycle();
}
}
/**
* Sets the drawing direction.
*
* @param direction The drawing direction.
*/
public void setDirection(@NonNull Direction direction) {
this.direction = direction;
updateBitmap();
}
/**
* Returns the drawing direction.
*
* @return The drawing direction.
*/
@NonNull
public Direction getDirection() {
return direction;
}
/**
* Sets the current data.
*
* @param data The data.
*/
public void setData(@Nullable T[] data) {
this.data = data;
}
/**
* Returns the current data.
*
* @return The current data.
*/
@Nullable
public T[] getData() {
return data;
}
/**
* Returns the data at the relative position.
*
* @param pos The relative position.
* @return The data.
*/
@Nullable
public T getDataAt(float pos) {
if (data == null || data.length == 0) return null;
int idx = (int)((data.length - 1) * pos);
idx = Math.min(Math.max(0, idx), data.length - 1);
return data[idx];
}
@Override
protected void onDraw(Canvas canvas) {
long now = System.currentTimeMillis();
super.onDraw(canvas);
onDrawData(now, canvas);
if (selection != null) {
bitmap.eraseColor(colorNormal);
if (getBackground() != null) {
getBackground().draw(bitmapCanvas);
}
bitmapCanvas.save();
if (direction == Direction.VERTICAL) {
bitmapCanvas.scale(1, 3);
bitmapCanvas.translate(0, -selection * getHeight() + bitmapSize / 6f);
} else {
bitmapCanvas.scale(3, 1);
bitmapCanvas.translate(-selection * getWidth() + bitmapSize / 6f, 0);
}
onDrawData(now, bitmapCanvas);
bitmapCanvas.restore();
if (direction == Direction.VERTICAL) {
bitmapCanvas.drawLine(0, 1, bitmap.getWidth(), 1, bitmapBorderPaint);
bitmapCanvas.drawLine(0, bitmap.getHeight() - 2, bitmap.getWidth(), bitmap.getHeight() - 2, bitmapBorderPaint);
canvas.drawBitmap(bitmap, 0, selection * getHeight() - bitmapSize / 2, null);
} else {
bitmapCanvas.drawLine( 1, 0, 1, bitmap.getHeight(), bitmapBorderPaint);
bitmapCanvas.drawLine(bitmap.getWidth() - 2, 0, bitmap.getWidth() - 2, bitmap.getHeight(), bitmapBorderPaint);
canvas.drawBitmap(bitmap, selection * getWidth() - bitmapSize / 2, 0, null);
}
}
}
public void setSelection(@Nullable Float selection) {
this.selection = selection;
invalidate();
}
@Nullable
public Float getSelection() {
return selection;
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
updateBitmap();
}
protected abstract void onDrawData(long time, Canvas canvas);
/**
* Recomputes the bitmap based on the size.
*/
private void updateBitmap() {
if (bitmap != null) {
bitmap.recycle();
bitmap = null;
bitmapCanvas = null;
}
if (direction == Direction.VERTICAL) {
if (getWidth() > 0) {
bitmap = Bitmap.createBitmap(getWidth(), bitmapSize, Bitmap.Config.ARGB_8888);
bitmapCanvas = new Canvas(bitmap);
}
} else {
if (getHeight() > 0) {
bitmap = Bitmap.createBitmap(bitmapSize, getHeight(), Bitmap.Config.ARGB_8888);
bitmapCanvas = new Canvas(bitmap);
}
}
}
}
@@ -0,0 +1,323 @@
package com.mowesta.android.app.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.res.ResourcesCompat;
import com.mowesta.android.app.R;
import java.util.Random;
/**
* A gradient view that shows rain drops. This is used for the
* precipitation.
*
* @author Marcus
*/
public class DropView extends GradientView {
/**
* The threshold for rain.
*/
private static final double DROP_THRESHOLD = 0.1;
/**
* The maximum number of water drops to simulate.
*/
private static final int MAXIMUM_DROPS = 45;
/**
* The speed of the drops in dp.
*/
private static final int DROP_SPEED = 20;
/**
* The random number generator for drops.
*/
private Random random = new Random();
/**
* The drawable for a water drop.
*/
private Drawable drawable;
/**
* The sum of all rain used to skew the random
* number generator.
*/
private double sqrtSum;
/**
* The square roots of the data.
*/
private double[] sqrts;
/**
* The water drops.
*/
private WaterDrop[] drops = null;
/**
* Creates a new view.
*
* @param context The context.
*/
public DropView(Context context) {
super(context);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
*/
public DropView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
* @param defStyleAttr The style.
*/
public DropView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
* @param defStyleAttr The style.
* @param defStyleRes The style res.
*/
public DropView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
/**
* Initializes the view.
*
* @param context The context.
*/
private void init(Context context) {
drawable = AppCompatResources.getDrawable(context, R.drawable.fg_water_drop);
}
@Override
public void setData(Double[] data) {
super.setData(data);
sqrtSum = 0;
if (data != null) {
sqrts = new double[data.length];
for (int i = 0; i < data.length; i++) {
if (data[i] > DROP_THRESHOLD) {
sqrts[i] = Math.sqrt(data[i]);
sqrtSum += sqrts[i];
}
}
} else {
sqrts = null;
}
updateDrops();
}
@Override
public void setDirection(@NonNull Direction direction) {
super.setDirection(direction);
updateDrops();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
updateDrops();
}
/**
* Updates the drops after the data or size has changed.
*/
private void updateDrops() {
if (data != null && data.length > 0 && sqrtSum > 0) {
int count = Math.min((int) sqrtSum + 5, MAXIMUM_DROPS);
drops = new WaterDrop[count];
float density = getResources().getDisplayMetrics().density;
for (int i = 0; i < drops.length; i++) {
drops[i] = new WaterDrop(density);
}
postInvalidateOnAnimation();
}
}
@Override
protected void onDrawData(long time, Canvas canvas) {
super.onDrawData(time, canvas);
if (drops != null) {
for (int i = 0; i < drops.length; i++) {
drops[i].animate(time);
drops[i].draw(canvas);
}
postInvalidateOnAnimation();
}
}
/**
* A class to emulate a single water drop.
*/
private class WaterDrop {
/**
* The current time.
*/
private long time;
/**
* The left corner.
*/
private float x;
/**
* The top corner.
*/
private float y;
/**
* The remaining distance that this drop will
* travel (in y direction) before it fades out.
*/
private float distance;
/**
* The speed at which the drop moves down in
* pixels per second.
*/
private int speed;
/**
* The size of the current drop in pixels.
*/
private float size;
/**
* The alpha value used for drawing.
*/
private float alpha;
/**
* The screen density to compute random sizes
* in dp.
*/
private float density;
/**
* Creates a new drop.
*
* @param density The screen density.
*/
private WaterDrop(float density) {
this.density = density;
}
/**
* Computes a new random starting location for the water drop
* as well as the size, movement speed (larger drops are faster)
* and the distance to travel.
*/
private void reset() {
int value = random.nextInt(5);
size = this.density * (value + 3);
float speedFactor = 0.5f + (value + 1) / 10f;
speed = (int)(speedFactor * density * DROP_SPEED);
float percent = random.nextFloat();
double position = percent * sqrtSum;
double current = 0;
for (int i = 0; i < data.length; i++) {
if (data[i] > DROP_THRESHOLD) current += sqrts[i];
if (current >= position) {
int start = i;
int end = i;
for (int j = start - 1; j >= Math.max(0, i - 8); j--) {
if (data[j] > data[i]) start = j;
else break;
}
for (int j = end + i; j < Math.min(data.length, i + 8); j++) {
if (data[j] > data[i]) end = j;
else break;
}
if (direction == Direction.VERTICAL) {
float dh = getHeight() / (float)data.length;
y = dh * (start - random.nextFloat());
x = (getWidth() - size) * random.nextFloat();
distance = dh * (end + random.nextFloat()) - y;
} else {
float dw = getWidth() / (float)data.length;
y = getHeight() * random.nextFloat();
x = dw * (i + random.nextFloat());
distance = (getHeight() - y) * random.nextFloat();
}
break;
}
}
alpha = 0.5f;
}
/**
* Animates the drop for the current time.
*
* @param time The current time.
*/
public void animate(long time) {
if (this.time == 0) {
reset();
} else {
moveBy(time - this.time);
if (alpha <= 0) {
reset();
}
}
this.time = time;
}
/**
* Moves the animation forward by a delta t in millis.
*
* @param delta The delta t in millis.
*/
private void moveBy(long delta) {
int shift = (int)(size * (random.nextFloat() - .5f));
float dx = delta / 1000f;
float newy = y + dx * speed;
x = x + dx * shift;
distance -= newy - y;
alpha = (float)Math.min(1, Math.max(0, 1 + distance / (size / 2)));
y = newy;
}
/**
* Draws the drop in its current state.
*
* @param canvas The canvas to draw onto.
*/
public void draw(Canvas canvas) {
int a = (int)Math.max(0, Math.min(255, alpha * 255));
drawable.setAlpha(a);
int ix = (int)x;
int iy = (int)y;
int s = (int)(size * alpha);
drawable.setBounds(ix, iy, ix + s, iy + s);
drawable.draw(canvas);
}
}
}
@@ -0,0 +1,106 @@
package com.mowesta.android.app.view;
import android.content.Context;
import android.util.AttributeSet;
import androidx.annotation.Nullable;
import com.google.android.gms.common.SignInButton;
import com.mowesta.android.app.view.color.IColorScheme;
/**
* A gradient view that joins two data items to get a color.
* This is required to join the cloud depth and coverage.
*
* @author Marcus
*/
public class DualGradientView extends GradientView {
/**
* The secondary data.
*/
@Nullable
private Double[] secondaryData;
/**
* The secondary color scheme.
*/
@Nullable
private IColorScheme secondaryColorScheme;
/**
* Creates a new view.
*
* @param context The context.
*/
public DualGradientView(Context context) {
super(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
*/
public DualGradientView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
* @param defStyleAttr The default attributes.
*/
public DualGradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
* @param defStyleAttr The default attributes.
* @param defStyleRes The default res.
*/
public DualGradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
/**
* Sets the secondary color scheme.
*
* @param secondaryColorScheme The secondary color scheme.
*/
public void setSecondaryColorScheme(@Nullable IColorScheme secondaryColorScheme) {
this.secondaryColorScheme = secondaryColorScheme;
updateColors();
updateGradient();
}
/**
* Sets the secondary data.
*
* @param secondaryData The secondary data.
*/
public void setSecondaryData(@Nullable Double[] secondaryData) {
this.secondaryData = secondaryData;
updateColors();
updateGradient();
}
@Override
protected void updateColors() {
super.updateColors();
if (colors != null && secondaryData != null && secondaryColorScheme != null && secondaryData.length == colors.length) {
for (int i = 0; i < colors.length; i++) {
int cover = colors[i];
int other = secondaryColorScheme.getColor(secondaryData[i]);
colors[i] = (cover & 0xFF000000) | (other & 0x00FFFFFF);
}
}
}
}
@@ -0,0 +1,199 @@
package com.mowesta.android.app.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mowesta.android.app.view.color.IColorScheme;
/**
* A view to display weather information as a gradient that is
* drawn efficiently using the graphics card of the device.
*
* @author Marcus
*/
public class GradientView extends DataView<Double> {
/**
* The color scheme.
*/
@Nullable
protected IColorScheme colorScheme;
/**
* The colors for the data.
*/
@Nullable
protected int[] colors;
/**
* The positions for the data.
*/
@Nullable
protected float[] positions;
/**
* The gradient for the data.
*/
@Nullable
protected LinearGradient gradient;
/**
* The paint to draw the gradient.
*/
protected Paint paint = new Paint();
/**
* Creates a new view.
*
* @param context The context.
*/
public GradientView(Context context) {
super(context);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attrs.
*/
public GradientView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attrs.
* @param defStyleAttr The default style.
*/
public GradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attrs.
* @param defStyleAttr The default style.
* @param defStyleRes The default res.
*/
@TargetApi(21)
public GradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
/**
* Initializes the view.
*
* @param context The context.
*/
private void init(Context context) {
paint.setStyle(Paint.Style.FILL);
}
@Override
public void setData(Double[] data) {
this.data = data;
updatePositions();
updateColors();
updateGradient();
}
/**
* Returns the color scheme to render the data.
*
* @return The color scheme.
*/
@Nullable
public IColorScheme getColorScheme() {
return colorScheme;
}
/**
* Sets the color scheme to render the data.
*
* @param colorScheme The color scheme.
*/
public void setColorScheme(@Nullable IColorScheme colorScheme) {
this.colorScheme = colorScheme;
updateColors();
updateGradient();
}
@Override
public void setDirection(@NonNull Direction direction) {
this.direction = direction;
updateGradient();
}
@Override
protected void onDrawData(long time, Canvas canvas) {
if (gradient != null) {
paint.setShader(gradient);
canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
}
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
updateGradient();
}
/**
* Computes the gradient to draw the data.
*/
protected void updateGradient() {
if (colors == null || positions == null) {
gradient = null;
} else {
float x = direction == Direction.HORIZONTAL ? getWidth(): 0;
float y = direction == Direction.HORIZONTAL ? 0 : getHeight();
gradient = new LinearGradient(0, 0, x, y, colors, positions, Shader.TileMode.CLAMP);
}
}
/**
* Updates the positions of the gradient.
*/
protected void updatePositions() {
if (data == null) {
positions = null;
} else {
positions = new float[data.length];
for (int i = 0; i < positions.length; i++) {
positions[i] = 0.5f/data.length + i/(float)data.length;
}
}
}
/**
* Updates the colors of the gradient.
*/
protected void updateColors() {
if (data == null || colorScheme == null) {
colors = null;
} else {
colors = new int[data.length];
for (int i = 0; i < colors.length; i++) {
colors[i] = colorScheme.getColor(data[i]);
}
}
}
}
@@ -1,931 +0,0 @@
package com.mowesta.android.app.view;
/**
* An enumeration with text constants to generate jam
* icons with the jam font.
*
* @author Marcus
*/
public enum JamIcon {
JAM_FIVE_HUNDRED_PX("\ue900"),
JAM_ACTIVITY("\ue901"),
JAM_AIRBNB("\ue902"),
JAM_ALARM_CLOCK_F("\ue903"),
JAM_ALARM_CLOCK("\ue904"),
JAM_ALERT_F("\ue905"),
JAM_ALERT("\ue906"),
JAM_ALIEN_F("\ue907"),
JAM_ALIEN("\ue908"),
JAM_ALIGN_CENTER("\ue909"),
JAM_ALIGN_JUSTIFY("\ue90a"),
JAM_ALIGN_LEFT("\ue90b"),
JAM_ALIGN_RIGHT("\ue90c"),
JAM_AMAZON("\ue90d"),
JAM_ANCHOR("\ue90e"),
JAM_ANDROID_CIRCLE("\ue90f"),
JAM_ANDROID_SQUARE("\ue910"),
JAM_ANDROID("\ue911"),
JAM_APERTURE("\ue912"),
JAM_APPLE_CIRCLE("\ue913"),
JAM_APPLE_SQUARE("\ue914"),
JAM_APPLE("\ue915"),
JAM_ARCHIVE_F("\ue916"),
JAM_ARCHIVE("\ue917"),
JAM_ARROW_CIRCLE_DOWN_F("\ue918"),
JAM_ARROW_CIRCLE_DOWN_LEFT_F("\ue919"),
JAM_ARROW_CIRCLE_DOWN_LEFT("\ue91a"),
JAM_ARROW_CIRCLE_DOWN_RIGHT_F("\ue91b"),
JAM_ARROW_CIRCLE_DOWN_RIGHT("\ue91c"),
JAM_ARROW_CIRCLE_DOWN("\ue91d"),
JAM_ARROW_CIRCLE_LEFT_F("\ue91e"),
JAM_ARROW_CIRCLE_LEFT("\ue91f"),
JAM_ARROW_CIRCLE_RIGHT_F("\ue920"),
JAM_ARROW_CIRCLE_RIGHT("\ue921"),
JAM_ARROW_CIRCLE_UP_F("\ue922"),
JAM_ARROW_CIRCLE_UP_LEFT_F("\ue923"),
JAM_ARROW_CIRCLE_UP_LEFT("\ue924"),
JAM_ARROW_CIRCLE_UP_RIGHT_F("\ue925"),
JAM_ARROW_CIRCLE_UP_RIGHT("\ue926"),
JAM_ARROW_CIRCLE_UP("\ue927"),
JAM_ARROW_DOWN_LEFT("\ue928"),
JAM_ARROW_DOWN_RIGHT("\ue929"),
JAM_ARROW_DOWN("\ue92a"),
JAM_ARROW_LEFT("\ue92b"),
JAM_ARROW_RIGHT("\ue92c"),
JAM_ARROW_SQUARE_DOWN_F("\ue92d"),
JAM_ARROW_SQUARE_DOWN_LEFT_F("\ue92e"),
JAM_ARROW_SQUARE_DOWN_LEFT("\ue92f"),
JAM_ARROW_SQUARE_DOWN_RIGHT_F("\ue930"),
JAM_ARROW_SQUARE_DOWN_RIGHT("\ue931"),
JAM_ARROW_SQUARE_DOWN("\ue932"),
JAM_ARROW_SQUARE_LEFT_F("\ue933"),
JAM_ARROW_SQUARE_LEFT("\ue934"),
JAM_ARROW_SQUARE_RIGHT_F("\ue935"),
JAM_ARROW_SQUARE_RIGHT("\ue936"),
JAM_ARROW_SQUARE_UP_F("\ue937"),
JAM_ARROW_SQUARE_UP_LEFT_F("\ue938"),
JAM_ARROW_SQUARE_UP_LEFT("\ue939"),
JAM_ARROW_SQUARE_UP_RIGHT_F("\ue93a"),
JAM_ARROW_SQUARE_UP_RIGHT("\ue93b"),
JAM_ARROW_SQUARE_UP("\ue93c"),
JAM_ARROW_UP_LEFT("\ue93d"),
JAM_ARROW_UP_RIGHT("\ue93e"),
JAM_ARROW_UP("\ue93f"),
JAM_ARROWS_CORNERS("\ue940"),
JAM_ARROWS_FULLSCREEN("\ue941"),
JAM_ARROWS_H("\ue942"),
JAM_ARROWS_V("\ue943"),
JAM_ATTACHMENT("\ue944"),
JAM_BACKGROUND_COLOR("\ue945"),
JAM_BACKPACK_F("\ue946"),
JAM_BACKPACK("\ue947"),
JAM_BACKWARD_CIRCLE_F("\ue948"),
JAM_BACKWARD_CIRCLE("\ue949"),
JAM_BACKWARD_SQUARE_F("\ue94a"),
JAM_BACKWARD_SQUARE("\ue94b"),
JAM_BACKWARD("\ue94c"),
JAM_BAIDU_CIRCLE("\ue94d"),
JAM_BAIDU_SQUARE("\ue94e"),
JAM_BAIDU("\ue94f"),
JAM_BANDAGE_F("\ue950"),
JAM_BANDAGE("\ue951"),
JAM_BAR_CHART("\ue952"),
JAM_BASEBALL("\ue953"),
JAM_BASKETBALL("\ue954"),
JAM_BATHTUB_F("\ue955"),
JAM_BATHTUB("\ue956"),
JAM_BATTERY_CHARGING_F("\ue957"),
JAM_BATTERY_CHARGING("\ue958"),
JAM_BATTERY_F("\ue959"),
JAM_BATTERY_HALF_F("\ue95a"),
JAM_BATTERY_HALF("\ue95b"),
JAM_BATTERY_ONE_QUARTER_F("\ue95c"),
JAM_BATTERY_ONE_QUARTER("\ue95d"),
JAM_BATTERY_THREE_QUARTERS_F("\ue95e"),
JAM_BATTERY_THREE_QUARTERS("\ue95f"),
JAM_BATTERY("\ue960"),
JAM_BEATPORT_CIRCLE("\ue961"),
JAM_BEATPORT_SQUARE("\ue962"),
JAM_BEATPORT("\ue963"),
JAM_BEER_F("\ue964"),
JAM_BEER("\ue965"),
JAM_BEHANCE_CIRCLE("\ue966"),
JAM_BEHANCE_SQUARE("\ue967"),
JAM_BEHANCE("\ue968"),
JAM_BELL_F("\ue969"),
JAM_BELL_OFF_F("\ue96a"),
JAM_BELL_OFF("\ue96b"),
JAM_BELL("\ue96c"),
JAM_BING_CIRCLE("\ue96d"),
JAM_BING_SQUARE("\ue96e"),
JAM_BING("\ue96f"),
JAM_BIRTHDAY_CAKE_F("\ue970"),
JAM_BIRTHDAY_CAKE("\ue971"),
JAM_BLOGGER_CIRCLE("\ue972"),
JAM_BLOGGER_SQUARE("\ue973"),
JAM_BLOGGER("\ue974"),
JAM_BLUETOOTH("\ue975"),
JAM_BOLD("\ue976"),
JAM_BOOK_F("\ue977"),
JAM_BOOK("\ue978"),
JAM_BOOKMARK_F("\ue979"),
JAM_BOOKMARK_MINUS_F("\ue97a"),
JAM_BOOKMARK_MINUS("\ue97b"),
JAM_BOOKMARK_PLUS_F("\ue97c"),
JAM_BOOKMARK_PLUS("\ue97d"),
JAM_BOOKMARK_REMOVE_F("\ue97e"),
JAM_BOOKMARK_REMOVE("\ue97f"),
JAM_BOOKMARK("\ue980"),
JAM_BOTTLE_F("\ue981"),
JAM_BOTTLE("\ue982"),
JAM_BOX_F("\ue983"),
JAM_BOX("\ue984"),
JAM_BRANCH_F("\ue985"),
JAM_BRANCH("\ue986"),
JAM_BRIGHTNESS_DOWN_F("\ue987"),
JAM_BRIGHTNESS_DOWN("\ue988"),
JAM_BRIGHTNESS_UP_F("\ue989"),
JAM_BRIGHTNESS_UP("\ue98a"),
JAM_BRIGHTNESS("\ue98b"),
JAM_BRUSH_F("\ue98c"),
JAM_BRUSH("\ue98d"),
JAM_BUG_F("\ue98e"),
JAM_BUG("\ue98f"),
JAM_BUILDING_F("\ue990"),
JAM_BUILDING("\ue991"),
JAM_BUS_F("\ue992"),
JAM_BUS("\ue993"),
JAM_CACTUS_F("\ue994"),
JAM_CACTUS("\ue995"),
JAM_CALCULATOR("\ue996"),
JAM_CALENDAR_ALT_F("\ue997"),
JAM_CALENDAR_ALT("\ue998"),
JAM_CALENDAR_F("\ue999"),
JAM_CALENDAR("\ue99a"),
JAM_CAMERA_ALT_F("\ue99b"),
JAM_CAMERA_ALT("\ue99c"),
JAM_CAMERA_F("\ue99d"),
JAM_CAMERA("\ue99e"),
JAM_CANDLE_F("\ue99f"),
JAM_CANDLE("\ue9a0"),
JAM_CAPSULE_F("\ue9a1"),
JAM_CAPSULE("\ue9a2"),
JAM_CAR_F("\ue9a3"),
JAM_CAR("\ue9a4"),
JAM_CASTLE_F("\ue9a5"),
JAM_CASTLE("\ue9a6"),
JAM_CHECK("\ue9a7"),
JAM_CHEVRON_CIRCLE_DOWN_F("\ue9a8"),
JAM_CHEVRON_CIRCLE_DOWN_LEFT_F("\ue9a9"),
JAM_CHEVRON_CIRCLE_DOWN_LEFT("\ue9aa"),
JAM_CHEVRON_CIRCLE_DOWN_RIGHT_F("\ue9ab"),
JAM_CHEVRON_CIRCLE_DOWN_RIGHT("\ue9ac"),
JAM_CHEVRON_CIRCLE_DOWN("\ue9ad"),
JAM_CHEVRON_CIRCLE_LEFT_F("\ue9ae"),
JAM_CHEVRON_CIRCLE_LEFT("\ue9af"),
JAM_CHEVRON_CIRCLE_RIGHT_F("\ue9b0"),
JAM_CHEVRON_CIRCLE_RIGHT("\ue9b1"),
JAM_CHEVRON_CIRCLE_UP_F("\ue9b2"),
JAM_CHEVRON_CIRCLE_UP_LEFT_F("\ue9b3"),
JAM_CHEVRON_CIRCLE_UP_LEFT("\ue9b4"),
JAM_CHEVRON_CIRCLE_UP_RIGHT_F("\ue9b5"),
JAM_CHEVRON_CIRCLE_UP_RIGHT("\ue9b6"),
JAM_CHEVRON_CIRCLE_UP("\ue9b7"),
JAM_CHEVRON_DOWN_LEFT("\ue9b8"),
JAM_CHEVRON_DOWN_RIGHT("\ue9b9"),
JAM_CHEVRON_DOWN("\ue9ba"),
JAM_CHEVRON_LEFT("\ue9bb"),
JAM_CHEVRON_RIGHT("\ue9bc"),
JAM_CHEVRON_SQUARE_DOWN_F("\ue9bd"),
JAM_CHEVRON_SQUARE_DOWN_LEFT_F("\ue9be"),
JAM_CHEVRON_SQUARE_DOWN_LEFT("\ue9bf"),
JAM_CHEVRON_SQUARE_DOWN_RIGHT_F("\ue9c0"),
JAM_CHEVRON_SQUARE_DOWN_RIGHT("\ue9c1"),
JAM_CHEVRON_SQUARE_DOWN("\ue9c2"),
JAM_CHEVRON_SQUARE_LEFT_F("\ue9c3"),
JAM_CHEVRON_SQUARE_LEFT("\ue9c4"),
JAM_CHEVRON_SQUARE_RIGHT_F("\ue9c5"),
JAM_CHEVRON_SQUARE_RIGHT("\ue9c6"),
JAM_CHEVRON_SQUARE_UP_F("\ue9c7"),
JAM_CHEVRON_SQUARE_UP_LEFT_F("\ue9c8"),
JAM_CHEVRON_SQUARE_UP_LEFT("\ue9c9"),
JAM_CHEVRON_SQUARE_UP_RIGHT_F("\ue9ca"),
JAM_CHEVRON_SQUARE_UP_RIGHT("\ue9cb"),
JAM_CHEVRON_SQUARE_UP("\ue9cc"),
JAM_CHEVRON_UP_LEFT("\ue9cd"),
JAM_CHEVRON_UP_RIGHT("\ue9ce"),
JAM_CHEVRON_UP("\ue9cf"),
JAM_CHEVRONS_CIRCLE_DOWN_F("\ue9d0"),
JAM_CHEVRONS_CIRCLE_DOWN_LEFT_F("\ue9d1"),
JAM_CHEVRONS_CIRCLE_DOWN_LEFT("\ue9d2"),
JAM_CHEVRONS_CIRCLE_DOWN_RIGHT_F("\ue9d3"),
JAM_CHEVRONS_CIRCLE_DOWN_RIGHT("\ue9d4"),
JAM_CHEVRONS_CIRCLE_DOWN("\ue9d5"),
JAM_CHEVRONS_CIRCLE_LEFT_F("\ue9d6"),
JAM_CHEVRONS_CIRCLE_LEFT("\ue9d7"),
JAM_CHEVRONS_CIRCLE_RIGHT_F("\ue9d8"),
JAM_CHEVRONS_CIRCLE_RIGHT("\ue9d9"),
JAM_CHEVRONS_CIRCLE_UP_F("\ue9da"),
JAM_CHEVRONS_CIRCLE_UP_LEFT_F("\ue9db"),
JAM_CHEVRONS_CIRCLE_UP_LEFT("\ue9dc"),
JAM_CHEVRONS_CIRCLE_UP_RIGHT_F("\ue9dd"),
JAM_CHEVRONS_CIRCLE_UP_RIGHT("\ue9de"),
JAM_CHEVRONS_CIRCLE_UP("\ue9df"),
JAM_CHEVRONS_DOWN_LEFT("\ue9e0"),
JAM_CHEVRONS_DOWN_RIGHT("\ue9e1"),
JAM_CHEVRONS_DOWN("\ue9e2"),
JAM_CHEVRONS_LEFT("\ue9e3"),
JAM_CHEVRONS_RIGHT("\ue9e4"),
JAM_CHEVRONS_SQUARE_DOWN_F("\ue9e5"),
JAM_CHEVRONS_SQUARE_DOWN_LEFT_F("\ue9e6"),
JAM_CHEVRONS_SQUARE_DOWN_LEFT("\ue9e7"),
JAM_CHEVRONS_SQUARE_DOWN_RIGHT_F("\ue9e8"),
JAM_CHEVRONS_SQUARE_DOWN_RIGHT("\ue9e9"),
JAM_CHEVRONS_SQUARE_DOWN("\ue9ea"),
JAM_CHEVRONS_SQUARE_LEFT_F("\ue9eb"),
JAM_CHEVRONS_SQUARE_LEFT("\ue9ec"),
JAM_CHEVRONS_SQUARE_RIGHT_F("\ue9ed"),
JAM_CHEVRONS_SQUARE_RIGHT("\ue9ee"),
JAM_CHEVRONS_SQUARE_UP_F("\ue9ef"),
JAM_CHEVRONS_SQUARE_UP_LEFT_F("\ue9f0"),
JAM_CHEVRONS_SQUARE_UP_LEFT("\ue9f1"),
JAM_CHEVRONS_SQUARE_UP_RIGHT_F("\ue9f2"),
JAM_CHEVRONS_SQUARE_UP_RIGHT("\ue9f3"),
JAM_CHEVRONS_SQUARE_UP("\ue9f4"),
JAM_CHEVRONS_UP_LEFT("\ue9f5"),
JAM_CHEVRONS_UP_RIGHT("\ue9f6"),
JAM_CHEVRONS_UP("\ue9f7"),
JAM_CHRONOMETER_F("\ue9f8"),
JAM_CHRONOMETER("\ue9f9"),
JAM_CIRCLE_F("\ue9fa"),
JAM_CIRCLE("\ue9fb"),
JAM_CLEAR_FORMAT("\ue9fc"),
JAM_CLIPBOARD_F("\ue9fd"),
JAM_CLIPBOARD("\ue9fe"),
JAM_CLOCK_F("\ue9ff"),
JAM_CLOCK("\uea00"),
JAM_CLOSE_CIRCLE_F("\uea01"),
JAM_CLOSE_CIRCLE("\uea02"),
JAM_CLOSE_RECTANGLE_F("\uea03"),
JAM_CLOSE_RECTANGLE("\uea04"),
JAM_CLOSE("\uea05"),
JAM_CLOUD_F("\uea06"),
JAM_CLOUD_RAIN_F("\uea07"),
JAM_CLOUD_RAIN("\uea08"),
JAM_CLOUD_SNOW_F("\uea09"),
JAM_CLOUD_SNOW("\uea0a"),
JAM_CLOUD_THUNDER_F("\uea0b"),
JAM_CLOUD_THUNDER("\uea0c"),
JAM_CLOUD("\uea0d"),
JAM_CODEPEN_CIRCLE("\uea0e"),
JAM_CODEPEN_SQUARE("\uea0f"),
JAM_CODEPEN("\uea10"),
JAM_COFFEE_CUP_F("\uea11"),
JAM_COFFEE_CUP("\uea12"),
JAM_COFFEE("\uea13"),
JAM_COG_F("\uea14"),
JAM_COG("\uea15"),
JAM_COGS_F("\uea16"),
JAM_COGS("\uea17"),
JAM_COIN_F("\uea18"),
JAM_COIN("\uea19"),
JAM_COLOR("\uea1a"),
JAM_COMPASS_F("\uea1b"),
JAM_COMPASS("\uea1c"),
JAM_COMPUTER_ALT_F("\uea1d"),
JAM_COMPUTER_ALT("\uea1e"),
JAM_COMPUTER_F("\uea1f"),
JAM_COMPUTER("\uea20"),
JAM_CREDIT_CARD_F("\uea21"),
JAM_CREDIT_CARD("\uea22"),
JAM_CROP("\uea23"),
JAM_CROWN_F("\uea24"),
JAM_CROWN("\uea25"),
JAM_CUTLERY_F("\uea26"),
JAM_CUTLERY("\uea27"),
JAM_CUTTER_F("\uea28"),
JAM_CUTTER("\uea29"),
JAM_DASHBOARD_F("\uea2a"),
JAM_DASHBOARD("\uea2b"),
JAM_DATABASE_F("\uea2c"),
JAM_DATABASE("\uea2d"),
JAM_DEEZER_CIRCLE("\uea2e"),
JAM_DEEZER_SQUARE("\uea2f"),
JAM_DEEZER("\uea30"),
JAM_DELETE_F("\uea31"),
JAM_DELETE("\uea32"),
JAM_DEVIANTART_CIRCLE("\uea33"),
JAM_DEVIANTART_SQUARE("\uea34"),
JAM_DEVIANTART("\uea35"),
JAM_DIGG("\uea36"),
JAM_DIRECTION_F("\uea37"),
JAM_DIRECTION("\uea38"),
JAM_DIRECTIONS_F("\uea39"),
JAM_DIRECTIONS("\uea3a"),
JAM_DISC_F("\uea3b"),
JAM_DISC("\uea3c"),
JAM_DISQUS_CIRCLE("\uea3d"),
JAM_DISQUS_SQUARE("\uea3e"),
JAM_DISQUS("\uea3f"),
JAM_DJ_F("\uea40"),
JAM_DJ("\uea41"),
JAM_DNA("\uea42"),
JAM_DOCUMENT_F("\uea43"),
JAM_DOCUMENT("\uea44"),
JAM_DOOR("\uea45"),
JAM_DOWNLOAD("\uea46"),
JAM_DRUPAL_CIRCLE("\uea47"),
JAM_DRUPAL_SQUARE("\uea48"),
JAM_DRUPAL("\uea49"),
JAM_EBAY("\uea4a"),
JAM_EGG_F("\uea4b"),
JAM_EGG("\uea4c"),
JAM_EGGS_F("\uea4d"),
JAM_EGGS("\uea4e"),
JAM_EJECT_CIRCLE_F("\uea4f"),
JAM_EJECT_CIRCLE("\uea50"),
JAM_EJECT_SQUARE_F("\uea51"),
JAM_EJECT_SQUARE("\uea52"),
JAM_EJECT("\uea53"),
JAM_ENVELOPE_F("\uea54"),
JAM_ENVELOPE_OPEN_F("\uea55"),
JAM_ENVELOPE_OPEN("\uea56"),
JAM_ENVELOPE("\uea57"),
JAM_EXTINGUISHER_F("\uea58"),
JAM_EXTINGUISHER("\uea59"),
JAM_EYE_CLOSE_F("\uea5a"),
JAM_EYE_CLOSE("\uea5b"),
JAM_EYE_F("\uea5c"),
JAM_EYE("\uea5d"),
JAM_EYEDROPPER_F("\uea5e"),
JAM_EYEDROPPER("\uea5f"),
JAM_FACEBOOK_CIRCLE("\uea60"),
JAM_FACEBOOK_SQUARE("\uea61"),
JAM_FACEBOOK("\uea62"),
JAM_FAST_BACKWARD_CIRCLE_F("\uea63"),
JAM_FAST_BACKWARD_CIRCLE("\uea64"),
JAM_FAST_BACKWARD_SQUARE_F("\uea65"),
JAM_FAST_BACKWARD_SQUARE("\uea66"),
JAM_FAST_BACKWARD("\uea67"),
JAM_FAST_FORWARD_CIRCLE_F("\uea68"),
JAM_FAST_FORWARD_CIRCLE("\uea69"),
JAM_FAST_FORWARD_SQUARE_F("\uea6a"),
JAM_FAST_FORWARD_SQUARE("\uea6b"),
JAM_FAST_FORWARD("\uea6c"),
JAM_FEATHER_F("\uea6d"),
JAM_FEATHER("\uea6e"),
JAM_FEMALE("\uea6f"),
JAM_FILE_F("\uea70"),
JAM_FILE("\uea71"),
JAM_FILES_F("\uea72"),
JAM_FILES("\uea73"),
JAM_FILTER_F("\uea74"),
JAM_FILTER("\uea75"),
JAM_FINGERPRINT("\uea76"),
JAM_FIRST_AID_F("\uea77"),
JAM_FIRST_AID("\uea78"),
JAM_FISH("\uea79"),
JAM_FIVERR_CIRCLE("\uea7a"),
JAM_FIVERR_SQUARE("\uea7b"),
JAM_FIVERR("\uea7c"),
JAM_FLAG_F("\uea7d"),
JAM_FLAG("\uea7e"),
JAM_FLAME_F("\uea7f"),
JAM_FLAME("\uea80"),
JAM_FLASHLIGHT_OFF_F("\uea81"),
JAM_FLASHLIGHT_OFF("\uea82"),
JAM_FLASHLIGHT_ON_F("\uea83"),
JAM_FLASHLIGHT_ON("\uea84"),
JAM_FLASK("\uea85"),
JAM_FLICKR_CIRCLE("\uea86"),
JAM_FLICKR_SQUARE("\uea87"),
JAM_FLICKR("\uea88"),
JAM_FLOWER("\uea89"),
JAM_FOLDER_F("\uea8a"),
JAM_FOLDER_OPEN_F("\uea8b"),
JAM_FOLDER_OPEN("\uea8c"),
JAM_FOLDER_ZIP_F("\uea8d"),
JAM_FOLDER_ZIP("\uea8e"),
JAM_FOLDER("\uea8f"),
JAM_FOOTBALL("\uea90"),
JAM_FORK_F("\uea91"),
JAM_FORK("\uea92"),
JAM_FORWARD_CIRCLE_F("\uea93"),
JAM_FORWARD_CIRCLE("\uea94"),
JAM_FORWARD_SQUARE_F("\uea95"),
JAM_FORWARD_SQUARE("\uea96"),
JAM_FORWARD("\uea97"),
JAM_FOURSQUARE("\uea98"),
JAM_GAMEPAD_F("\uea99"),
JAM_GAMEPAD_RETRO_F("\uea9a"),
JAM_GAMEPAD_RETRO("\uea9b"),
JAM_GAMEPAD("\uea9c"),
JAM_GHOST_F("\uea9d"),
JAM_GHOST_ORG_CIRCLE("\uea9e"),
JAM_GHOST_ORG_SQUARE("\uea9f"),
JAM_GHOST_ORG("\ueaa0"),
JAM_GHOST("\ueaa1"),
JAM_GIFT_F("\ueaa2"),
JAM_GIFT("\ueaa3"),
JAM_GITHUB_CIRCLE("\ueaa4"),
JAM_GITHUB_SQUARE("\ueaa5"),
JAM_GITHUB("\ueaa6"),
JAM_GITLAB_CIRCLE("\ueaa7"),
JAM_GITLAB_SQUARE("\ueaa8"),
JAM_GITLAB("\ueaa9"),
JAM_GLASS_EMPTY("\ueaaa"),
JAM_GLASS_FILLED_F("\ueaab"),
JAM_GLASS_FILLED("\ueaac"),
JAM_GLUE_F("\ueaad"),
JAM_GLUE("\ueaae"),
JAM_GOOGLE_CIRCLE("\ueaaf"),
JAM_GOOGLE_PLAY_CIRCLE("\ueab0"),
JAM_GOOGLE_PLAY_SQUARE("\ueab1"),
JAM_GOOGLE_PLAY("\ueab2"),
JAM_GOOGLE_PLUS_CIRCLE("\ueab3"),
JAM_GOOGLE_PLUS_SQUARE("\ueab4"),
JAM_GOOGLE_PLUS("\ueab5"),
JAM_GOOGLE_SQUARE("\ueab6"),
JAM_GOOGLE("\ueab7"),
JAM_GPS_F("\ueab8"),
JAM_GPS("\ueab9"),
JAM_GRID_F("\ueaba"),
JAM_GRID("\ueabb"),
JAM_HAIRDRYER_F("\ueabc"),
JAM_HAIRDRYER("\ueabd"),
JAM_HAMMER_F("\ueabe"),
JAM_HAMMER("\ueabf"),
JAM_HASHTAG("\ueac0"),
JAM_HEADER_1("\ueac1"),
JAM_HEADER_2("\ueac2"),
JAM_HEADER_3("\ueac3"),
JAM_HEADER_4("\ueac4"),
JAM_HEADER_5("\ueac5"),
JAM_HEADER_6("\ueac6"),
JAM_HEADER("\ueac7"),
JAM_HEADSET_F("\ueac8"),
JAM_HEADSET("\ueac9"),
JAM_HEART_F("\ueaca"),
JAM_HEART("\ueacb"),
JAM_HELMET_F("\ueacc"),
JAM_HELMET("\ueacd"),
JAM_HELP_F("\ueace"),
JAM_HELP("\ueacf"),
JAM_HIGHLIGHTER_F("\uead0"),
JAM_HIGHLIGHTER("\uead1"),
JAM_HISTORY("\uead2"),
JAM_HOME_F("\uead3"),
JAM_HOME("\uead4"),
JAM_HOURGLASS_F("\uead5"),
JAM_HOURGLASS("\uead6"),
JAM_ICE_CREAM_F("\uead7"),
JAM_ICE_CREAM("\uead8"),
JAM_ID_CARD_F("\uead9"),
JAM_ID_CARD("\ueada"),
JAM_INBOX_F("\ueadb"),
JAM_INBOX("\ueadc"),
JAM_INBOXES_F("\ueadd"),
JAM_INBOXES("\ueade"),
JAM_INDENT("\ueadf"),
JAM_INFINITE("\ueae0"),
JAM_INFO_F("\ueae1"),
JAM_INFO("\ueae2"),
JAM_INSTAGRAM("\ueae3"),
JAM_INSTANT_PICTURE_F("\ueae4"),
JAM_INSTANT_PICTURE("\ueae5"),
JAM_ITALIC("\ueae6"),
JAM_JOYSTICK_F("\ueae7"),
JAM_JOYSTICK("\ueae8"),
JAM_KEY_F("\ueae9"),
JAM_KEY("\ueaea"),
JAM_KEYBOARD_F("\ueaeb"),
JAM_KEYBOARD("\ueaec"),
JAM_LANGUAGE("\ueaed"),
JAM_LAYERS_F("\ueaee"),
JAM_LAYERS("\ueaef"),
JAM_LAYOUT_F("\ueaf0"),
JAM_LAYOUT("\ueaf1"),
JAM_LEAF_F("\ueaf2"),
JAM_LEAF("\ueaf3"),
JAM_LIFEBUOY_F("\ueaf4"),
JAM_LIFEBUOY("\ueaf5"),
JAM_LIGHTBULB_F("\ueaf6"),
JAM_LIGHTBULB("\ueaf7"),
JAM_LINE("\ueaf8"),
JAM_LINK("\ueaf9"),
JAM_LINKEDIN_CIRCLE("\ueafa"),
JAM_LINKEDIN_SQUARE("\ueafb"),
JAM_LINKEDIN("\ueafc"),
JAM_LOG_IN("\ueafd"),
JAM_LOG_OUT("\ueafe"),
JAM_LUGGAGE_F("\ueaff"),
JAM_LUGGAGE("\ueb00"),
JAM_MAGIC_F("\ueb01"),
JAM_MAGIC("\ueb02"),
JAM_MAGNET_F("\ueb03"),
JAM_MAGNET("\ueb04"),
JAM_MALE("\ueb05"),
JAM_MAP_F("\ueb06"),
JAM_MAP_MARKER_F("\ueb07"),
JAM_MAP_MARKER("\ueb08"),
JAM_MAP("\ueb09"),
JAM_MASK_F("\ueb0a"),
JAM_MASK("\ueb0b"),
JAM_MEDAL_F("\ueb0c"),
JAM_MEDAL("\ueb0d"),
JAM_MEDICAL("\ueb0e"),
JAM_MEDIUM_CIRCLE("\ueb0f"),
JAM_MEDIUM_SQUARE("\ueb10"),
JAM_MEDIUM("\ueb11"),
JAM_MENU("\ueb12"),
JAM_MERGE_F("\ueb13"),
JAM_MERGE("\ueb14"),
JAM_MESSAGE_ALT_F("\ueb15"),
JAM_MESSAGE_ALT_WRITING_F("\ueb16"),
JAM_MESSAGE_ALT_WRITING("\ueb17"),
JAM_MESSAGE_ALT("\ueb18"),
JAM_MESSAGE_F("\ueb19"),
JAM_MESSAGE_WRITING_F("\ueb1a"),
JAM_MESSAGE_WRITING("\ueb1b"),
JAM_MESSAGE("\ueb1c"),
JAM_MESSAGES_ALT_F("\ueb1d"),
JAM_MESSAGES_ALT("\ueb1e"),
JAM_MESSAGES_F("\ueb1f"),
JAM_MESSAGES("\ueb20"),
JAM_MESSENGER("\ueb21"),
JAM_MIC_ALT("\ueb22"),
JAM_MIC_CIRCLE_F("\ueb23"),
JAM_MIC_CIRCLE("\ueb24"),
JAM_MIC_F("\ueb25"),
JAM_MIC_SQUARE_F("\ueb26"),
JAM_MIC_SQUARE("\ueb27"),
JAM_MIC("\ueb28"),
JAM_MICROCHIP_F("\ueb29"),
JAM_MICROCHIP("\ueb2a"),
JAM_MINUS_CIRCLE_F("\ueb2b"),
JAM_MINUS_CIRCLE("\ueb2c"),
JAM_MINUS_RECTANGLE_F("\ueb2d"),
JAM_MINUS_RECTANGLE("\ueb2e"),
JAM_MINUS("\ueb2f"),
JAM_MOON_F("\ueb30"),
JAM_MOON("\ueb31"),
JAM_MORE_HORIZONTAL_F("\ueb32"),
JAM_MORE_HORIZONTAL("\ueb33"),
JAM_MORE_VERTICAL_F("\ueb34"),
JAM_MORE_VERTICAL("\ueb35"),
JAM_MOUNTAIN_F("\ueb36"),
JAM_MOUNTAIN("\ueb37"),
JAM_MOVE_ALT("\ueb38"),
JAM_MOVE("\ueb39"),
JAM_MOVIE("\ueb3a"),
JAM_MUG_F("\ueb3b"),
JAM_MUG("\ueb3c"),
JAM_MUSIC_F("\ueb3d"),
JAM_MUSIC("\ueb3e"),
JAM_MYSPACE_CIRCLE("\ueb3f"),
JAM_MYSPACE_SQUARE("\ueb40"),
JAM_MYSPACE("\ueb41"),
JAM_NAPSTER_CIRCLE("\ueb42"),
JAM_NAPSTER_SQUARE("\ueb43"),
JAM_NAPSTER("\ueb44"),
JAM_NEWSLETTER_F("\ueb45"),
JAM_NEWSLETTER("\ueb46"),
JAM_NEWSPAPER_F("\ueb47"),
JAM_NEWSPAPER("\ueb48"),
JAM_NPM("\ueb49"),
JAM_ODNOKLASSNIKI_CIRCLE("\ueb4a"),
JAM_ODNOKLASSNIKI_SQUARE("\ueb4b"),
JAM_ODNOKLASSNIKI("\ueb4c"),
JAM_OPERA_CIRCLE("\ueb4d"),
JAM_OPERA_SQUARE("\ueb4e"),
JAM_OPERA("\ueb4f"),
JAM_ORDERED_LIST("\ueb50"),
JAM_PADLOCK_ALT_F("\ueb51"),
JAM_PADLOCK_ALT_OPEN_F("\ueb52"),
JAM_PADLOCK_ALT_OPEN("\ueb53"),
JAM_PADLOCK_ALT("\ueb54"),
JAM_PADLOCK_F("\ueb55"),
JAM_PADLOCK_OPEN_F("\ueb56"),
JAM_PADLOCK_OPEN("\ueb57"),
JAM_PADLOCK("\ueb58"),
JAM_PAPER_PLANE_F("\ueb59"),
JAM_PAPER_PLANE("\ueb5a"),
JAM_PATREON_CIRCLE("\ueb5b"),
JAM_PATREON_SQUARE("\ueb5c"),
JAM_PATREON("\ueb5d"),
JAM_PAUSE("\ueb5e"),
JAM_PAYPAL_CIRCLE("\ueb5f"),
JAM_PAYPAL_SQUARE("\ueb60"),
JAM_PAYPAL("\ueb61"),
JAM_PEN_F("\ueb62"),
JAM_PEN("\ueb63"),
JAM_PENCIL_F("\ueb64"),
JAM_PENCIL("\ueb65"),
JAM_PERISCOPE_CIRCLE("\ueb66"),
JAM_PERISCOPE_SQUARE("\ueb67"),
JAM_PERISCOPE("\ueb68"),
JAM_PHONE_F("\ueb69"),
JAM_PHONE("\ueb6a"),
JAM_PICTURE_F("\ueb6b"),
JAM_PICTURE("\ueb6c"),
JAM_PICTURES_F("\ueb6d"),
JAM_PICTURES("\ueb6e"),
JAM_PIE_CHART_ALT("\ueb6f"),
JAM_PIE_CHART_F("\ueb70"),
JAM_PIE_CHART("\ueb71"),
JAM_PIN_ALT_F("\ueb72"),
JAM_PIN_ALT("\ueb73"),
JAM_PIN_F("\ueb74"),
JAM_PIN("\ueb75"),
JAM_PINTEREST_CIRCLE("\ueb76"),
JAM_PINTEREST_SQUARE("\ueb77"),
JAM_PINTEREST("\ueb78"),
JAM_PIZZA_SLICE("\ueb79"),
JAM_PLANE_F("\ueb7a"),
JAM_PLANE("\ueb7b"),
JAM_PLAY_CIRCLE_F("\ueb7c"),
JAM_PLAY_CIRCLE("\ueb7d"),
JAM_PLAY_SQUARE_F("\ueb7e"),
JAM_PLAY_SQUARE("\ueb7f"),
JAM_PLAY("\ueb80"),
JAM_PLUG_F("\ueb81"),
JAM_PLUG("\ueb82"),
JAM_PLUS_CIRCLE_F("\ueb83"),
JAM_PLUS_CIRCLE("\ueb84"),
JAM_PLUS_RECTANGLE_F("\ueb85"),
JAM_PLUS_RECTANGLE("\ueb86"),
JAM_PLUS("\ueb87"),
JAM_POCKET_WATCH_F("\ueb88"),
JAM_POCKET_WATCH("\ueb89"),
JAM_PODCAST("\ueb8a"),
JAM_POWER("\ueb8b"),
JAM_PRINTER_F("\ueb8c"),
JAM_PRINTER("\ueb8d"),
JAM_QR_CODE("\ueb8e"),
JAM_QUORA_CIRCLE("\ueb8f"),
JAM_QUORA_SQUARE("\ueb90"),
JAM_QUORA("\ueb91"),
JAM_RAINBOW("\ueb92"),
JAM_REC("\ueb93"),
JAM_RECTANGLE_F("\ueb94"),
JAM_RECTANGLE("\ueb95"),
JAM_REDDIT("\ueb96"),
JAM_REDO("\ueb97"),
JAM_REFRESH_REVERSE("\ueb98"),
JAM_REFRESH("\ueb99"),
JAM_REPEAT("\ueb9a"),
JAM_ROCKET_F("\ueb9b"),
JAM_ROCKET("\ueb9c"),
JAM_RSS_FEED("\ueb9d"),
JAM_RUBBER("\ueb9e"),
JAM_RULER_F("\ueb9f"),
JAM_RULER("\ueba0"),
JAM_SAVE_F("\ueba1"),
JAM_SAVE("\ueba2"),
JAM_SCISSORS("\ueba3"),
JAM_SCREEN_F("\ueba4"),
JAM_SCREEN("\ueba5"),
JAM_SCREWDRIVER_F("\ueba6"),
JAM_SCREWDRIVER("\ueba7"),
JAM_SEARCH_FOLDER("\ueba8"),
JAM_SEARCH_MINUS("\ueba9"),
JAM_SEARCH_PLUS("\uebaa"),
JAM_SEARCH("\uebab"),
JAM_SET_BACKWARD_CIRCLE_F("\uebac"),
JAM_SET_BACKWARD_CIRCLE("\uebad"),
JAM_SET_BACKWARD_SQUARE_F("\uebae"),
JAM_SET_BACKWARD_SQUARE("\uebaf"),
JAM_SET_BACKWARD("\uebb0"),
JAM_SET_FORWARD_CIRCLE_F("\uebb1"),
JAM_SET_FORWARD_CIRCLE("\uebb2"),
JAM_SET_FORWARD_SQUARE_F("\uebb3"),
JAM_SET_FORWARD_SQUARE("\uebb4"),
JAM_SET_FORWARD("\uebb5"),
JAM_SET_SQUARE_F("\uebb6"),
JAM_SET_SQUARE("\uebb7"),
JAM_SETTINGS_ALT("\uebb8"),
JAM_SHARE_ALT_F("\uebb9"),
JAM_SHARE_ALT("\uebba"),
JAM_SHARE("\uebbb"),
JAM_SHIELD_CHECK_F("\uebbc"),
JAM_SHIELD_CHECK("\uebbd"),
JAM_SHIELD_CLOSE_F("\uebbe"),
JAM_SHIELD_CLOSE("\uebbf"),
JAM_SHIELD_F("\uebc0"),
JAM_SHIELD_HALF("\uebc1"),
JAM_SHIELD_MINUS_F("\uebc2"),
JAM_SHIELD_MINUS("\uebc3"),
JAM_SHIELD_PLUS_F("\uebc4"),
JAM_SHIELD_PLUS("\uebc5"),
JAM_SHIELD("\uebc6"),
JAM_SHOPIFY_CIRCLE("\uebc7"),
JAM_SHOPIFY_SQUARE("\uebc8"),
JAM_SHOPIFY("\uebc9"),
JAM_SHOPPING_BAG_ALT_F("\uebca"),
JAM_SHOPPING_BAG_ALT("\uebcb"),
JAM_SHOPPING_BAG_F("\uebcc"),
JAM_SHOPPING_BAG("\uebcd"),
JAM_SHOPPING_CART("\uebce"),
JAM_SHUFFLE("\uebcf"),
JAM_SIGNAL("\uebd0"),
JAM_SITEMAP_F("\uebd1"),
JAM_SITEMAP("\uebd2"),
JAM_SKULL_F("\uebd3"),
JAM_SKULL("\uebd4"),
JAM_SKYPE_CIRCLE("\uebd5"),
JAM_SKYPE_SQUARE("\uebd6"),
JAM_SKYPE("\uebd7"),
JAM_SLACK_CIRCLE("\uebd8"),
JAM_SLACK_SQUARE("\uebd9"),
JAM_SLACK("\uebda"),
JAM_SMILEY_F("\uebdb"),
JAM_SMILEY("\uebdc"),
JAM_SNAPCHAT_CIRCLE("\uebdd"),
JAM_SNAPCHAT_SQUARE("\uebde"),
JAM_SNAPCHAT("\uebdf"),
JAM_SNOWBOARD_F("\uebe0"),
JAM_SNOWBOARD("\uebe1"),
JAM_SNOWFLAKE("\uebe2"),
JAM_SOUNDCLOUD("\uebe3"),
JAM_SPEAKER_F("\uebe4"),
JAM_SPEAKER("\uebe5"),
JAM_SPOTIFY("\uebe6"),
JAM_SQUARE_F("\uebe7"),
JAM_SQUARE("\uebe8"),
JAM_SQUARESPACE_CIRCLE("\uebe9"),
JAM_SQUARESPACE_SQUARE("\uebea"),
JAM_SQUARESPACE("\uebeb"),
JAM_STACKOVERFLOW_CIRCLE("\uebec"),
JAM_STACKOVERFLOW_SQUARE("\uebed"),
JAM_STACKOVERFLOW("\uebee"),
JAM_STAMP_F("\uebef"),
JAM_STAMP("\uebf0"),
JAM_STAR_F("\uebf1"),
JAM_STAR_FULL("\uebf2"),
JAM_STAR_HALF("\uebf3"),
JAM_STAR("\uebf4"),
JAM_STATION("\uebf5"),
JAM_STOP_SIGN("\uebf6"),
JAM_STOP("\uebf7"),
JAM_STORE("\uebf8"),
JAM_STRIKETHROUGH("\uebf9"),
JAM_STUMBLEUPON_CIRCLE("\uebfa"),
JAM_STUMBLEUPON_SQUARE("\uebfb"),
JAM_STUMBLEUPON("\uebfc"),
JAM_SUN_F("\uebfd"),
JAM_SUN("\uebfe"),
JAM_SWITCH_LEFT_F("\uebff"),
JAM_SWITCH_LEFT("\uec00"),
JAM_SWITCH_RIGHT_F("\uec01"),
JAM_SWITCH_RIGHT("\uec02"),
JAM_SWORD_F("\uec03"),
JAM_SWORD("\uec04"),
JAM_TABLET_F("\uec05"),
JAM_TABLET("\uec06"),
JAM_TAG_F("\uec07"),
JAM_TAG("\uec08"),
JAM_TAGS_F("\uec09"),
JAM_TAGS("\uec0a"),
JAM_TARGET("\uec0b"),
JAM_TASK_LIST_F("\uec0c"),
JAM_TASK_LIST("\uec0d"),
JAM_TEMPERATURE("\uec0e"),
JAM_TERMINAL("\uec0f"),
JAM_THUNDER_F("\uec10"),
JAM_THUNDER("\uec11"),
JAM_TICKET_F("\uec12"),
JAM_TICKET("\uec13"),
JAM_TOOLS_F("\uec14"),
JAM_TOOLS("\uec15"),
JAM_TORCH_F("\uec16"),
JAM_TORCH("\uec17"),
JAM_TOTEM("\uec18"),
JAM_TRAIN_F("\uec19"),
JAM_TRAIN("\uec1a"),
JAM_TRANSGENDER("\uec1b"),
JAM_TRASH_ALT_F("\uec1c"),
JAM_TRASH_ALT("\uec1d"),
JAM_TRASH_F("\uec1e"),
JAM_TRASH("\uec1f"),
JAM_TREE_ALT_F("\uec20"),
JAM_TREE_ALT("\uec21"),
JAM_TREE_F("\uec22"),
JAM_TREE("\uec23"),
JAM_TRELLO("\uec24"),
JAM_TRIANGLE_DANGER_F("\uec25"),
JAM_TRIANGLE_DANGER("\uec26"),
JAM_TRIANGLE_F("\uec27"),
JAM_TRIANGLE("\uec28"),
JAM_TROPHY_F("\uec29"),
JAM_TROPHY("\uec2a"),
JAM_TUBE("\uec2b"),
JAM_TUMBLR_CIRCLE("\uec2c"),
JAM_TUMBLR_SQUARE("\uec2d"),
JAM_TUMBLR("\uec2e"),
JAM_TWITCH("\uec2f"),
JAM_TWITTER_CIRCLE("\uec30"),
JAM_TWITTER_SQUARE("\uec31"),
JAM_TWITTER("\uec32"),
JAM_UMBRELLA_CLOSED_F("\uec33"),
JAM_UMBRELLA_CLOSED("\uec34"),
JAM_UMBRELLA_F("\uec35"),
JAM_UMBRELLA("\uec36"),
JAM_UNDERLINE("\uec37"),
JAM_UNDO("\uec38"),
JAM_UNINDENT("\uec39"),
JAM_UNIVERSE("\uec3a"),
JAM_UNORDERED_LIST("\uec3b"),
JAM_UNSPLASH_CIRCLE("\uec3c"),
JAM_UNSPLASH_SQUARE("\uec3d"),
JAM_UNSPLASH("\uec3e"),
JAM_UPLOAD("\uec3f"),
JAM_USER_CIRCLE("\uec40"),
JAM_USER_MINUS("\uec41"),
JAM_USER_PLUS("\uec42"),
JAM_USER_REMOVE("\uec43"),
JAM_USER_SQUARE("\uec44"),
JAM_USER("\uec45"),
JAM_USERS("\uec46"),
JAM_VIADEO("\uec47"),
JAM_VIBER_CIRCLE("\uec48"),
JAM_VIBER_SQUARE("\uec49"),
JAM_VIBER("\uec4a"),
JAM_VIDEO_CAMERA_F("\uec4b"),
JAM_VIDEO_CAMERA_VINTAGE_F("\uec4c"),
JAM_VIDEO_CAMERA_VINTAGE("\uec4d"),
JAM_VIDEO_CAMERA("\uec4e"),
JAM_VIMEO_CIRCLE("\uec4f"),
JAM_VIMEO_SQUARE("\uec50"),
JAM_VIMEO("\uec51"),
JAM_VINE_CIRCLE("\uec52"),
JAM_VINE_SQUARE("\uec53"),
JAM_VINE("\uec54"),
JAM_VOICEMAIL("\uec55"),
JAM_VOLUME_CIRCLE_F("\uec56"),
JAM_VOLUME_CIRCLE("\uec57"),
JAM_VOLUME_DOWN_CIRCLE_F("\uec58"),
JAM_VOLUME_DOWN_CIRCLE("\uec59"),
JAM_VOLUME_DOWN_SQUARE_F("\uec5a"),
JAM_VOLUME_DOWN_SQUARE("\uec5b"),
JAM_VOLUME_DOWN("\uec5c"),
JAM_VOLUME_MUTE_CIRCLE_F("\uec5d"),
JAM_VOLUME_MUTE_CIRCLE("\uec5e"),
JAM_VOLUME_MUTE_SQUARE_F("\uec5f"),
JAM_VOLUME_MUTE_SQUARE("\uec60"),
JAM_VOLUME_MUTE("\uec61"),
JAM_VOLUME_SQUARE_F("\uec62"),
JAM_VOLUME_SQUARE("\uec63"),
JAM_VOLUME_UP_CIRCLE_F("\uec64"),
JAM_VOLUME_UP_CIRCLE("\uec65"),
JAM_VOLUME_UP_SQUARE_F("\uec66"),
JAM_VOLUME_UP_SQUARE("\uec67"),
JAM_VOLUME_UP("\uec68"),
JAM_VOLUME("\uec69"),
JAM_WATCH_F("\uec6a"),
JAM_WATCH("\uec6b"),
JAM_WATER_DROP_F("\uec6c"),
JAM_WATER_DROP("\uec6d"),
JAM_WHATSAPP("\uec6e"),
JAM_WIFI("\uec6f"),
JAM_WIKIPEDIA("\uec70"),
JAM_WORDPRESS("\uec71"),
JAM_WORLD("\uec72"),
JAM_WRENCH_F("\uec73"),
JAM_WRENCH("\uec74"),
JAM_WRITE_F("\uec75"),
JAM_WRITE("\uec76"),
JAM_YAHOO_CIRCLE("\uec77"),
JAM_YAHOO_SQUARE("\uec78"),
JAM_YAHOO("\uec79"),
JAM_YELP_CIRCLE("\uec7a"),
JAM_YELP_SQUARE("\uec7b"),
JAM_YELP("\uec7c"),
JAM_YOUTUBE_CIRCLE("\uec7d"),
JAM_YOUTUBE_SQUARE("\uec7e"),
JAM_YOUTUBE("\uec7f");
/**
* The value associated with the icon.
*/
private final String value;
/**
* Creates a jam icon with the value.
*
* @param value The value.
*/
private JamIcon(String value) {
this.value = value;
}
/**
* Returns the string value of the icon.
*
* @return The string value of the icon.
*/
public String getValue() {
return value;
}
}
@@ -1,102 +0,0 @@
package com.mowesta.android.app.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.content.res.ResourcesCompat;
import com.mowesta.android.app.R;
/**
* A widget that displays a jam icon. The icon
* can be configured via the jam attribute.
*
* @author Marcus
*/
public class JamView extends AppCompatTextView {
/**
* The icon type to display.
*/
JamIcon type;
/**
* Creates a weather view.
*
* @param context The context.
*/
public JamView(Context context) {
super(context);
}
/**
* Creates the weather view.
*
* @param context The context.
* @param attrs The attributes.
*/
public JamView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
/**
* Creates the weather view.
*
* @param context The context.
* @param attrs The attributes.
* @param defStyleAttr The theme.
*/
public JamView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
/**
* Initializes the view from the attributes.
*
* @param attrs The attributes.
*/
public void init(AttributeSet attrs) {
if (! isInEditMode()) {
setTypeface(ResourcesCompat.getFont(getContext(), R.font.jam), Typeface.NORMAL);
if (attrs == null) return;
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.JamView);
int type = ta.getInt(R.styleable.JamView_jam,-1);
if (type >= 0 && type < JamIcon.values().length) {
JamIcon icon = JamIcon.values()[type];
setText(icon.getValue());
} else {
setText("");
}
ta.recycle();
} else {
setText("O");
}
}
/**
* Sets the icon type.
*
* @param type The icon type.
*/
public void setType(JamIcon type) {
this.type = type;
if (!isInEditMode()) {
setText(type == null ? "" : type.getValue());
}
}
/**
* Returns the icon type.
*
* @return The icon type.
*/
public JamIcon getType() {
return type;
}
}
@@ -0,0 +1,330 @@
package com.mowesta.android.app.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.res.ResourcesCompat;
import com.locoslab.library.geometry.util.clipper.Clipper;
import com.mowesta.android.app.R;
import java.util.Random;
/**
* This data view generates particles moving at a data-dependent
* speed. The particles are drawn as a linear gradient. The size
* of the gradient also depends on the speed. This view is used
* to draw the wind speed.
*
* @author Marcus
*/
public class ParticleView extends DataView<Double> {
/**
* A random number generator to share across all
* particles.
*/
@NonNull
private Random random = new Random();
/**
* The particles that store their current position.
*/
@Nullable
private Particle[] particles;
/**
* The paint to draw the particles.
*/
@NonNull
private Paint paint = new Paint();
/**
* A factor to speed up or slow down the motion. This
* factor is multiplied by the speed in meter per second
* to get the motion in pixels per second.
*/
private float speedFactor = 10;
/**
* The relative length of the particle tails. This
* is used to derive the maximum length.
*/
private float relativeLength = .5f;
/**
* The relative height of the particle tails. This
* is used to derive the stroke width.
*/
private float relativeHeight = .5f;
/**
* The randomized start time.
*/
private int randomizeTime = 2000;
/**
* Creates a new view.
*
* @param context The context.
*/
public ParticleView(Context context) {
super(context);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attrs.
*/
public ParticleView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attrs.
* @param defStyleAttr The default style attrs.
*/
public ParticleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attrs.
* @param defStyleAttr The default style attrs.
* @param defStyleRes The default style res.
*/
@TargetApi(21)
public ParticleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
/**
* Initializes the view.
*
* @param context The context.
*/
private void init(Context context) {
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeCap(Paint.Cap.ROUND);
}
@Override
protected void onDrawData(long time, Canvas canvas) {
if (particles != null) {
for (int i = particles.length - 1; i >= 0; i--) {
particles[i].animate(time);
particles[i].draw(canvas, paint);
}
postInvalidateOnAnimation();
}
}
@Override
public void setData(@Nullable Double[] data) {
super.setData(data);
updateParticles();
}
@Override
public void setDirection(@NonNull Direction direction) {
super.setDirection(direction);
updateParticles();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
updateParticles();
}
/**
* Re-computes the particle's based on the data and the direction.
*/
private void updateParticles() {
int width = getWidth();
int height = getHeight();
if (data == null || data.length == 0 || width == 0 || height == 0) {
particles = null;
} else {
Direction dir = direction==Direction.VERTICAL?Direction.HORIZONTAL:Direction.VERTICAL;
int color = ResourcesCompat.getColor(getResources(), R.color.particle, null);
double max = 0;
for (int i = 0; i < data.length; i++)
max = Math.max(max, data[i]);
particles = new Particle[data.length];
float cell = (direction == Direction.VERTICAL?height:width) / (float)data.length;
float length = (direction == Direction.VERTICAL?width:height) * relativeLength;
float size = direction == Direction.VERTICAL?width:height;
paint.setStrokeWidth(cell * relativeHeight);
for (int i = 0; i < data.length; i++) {
RectF rect = direction == Direction.VERTICAL ? new RectF(0, cell * i, size, cell * (i + 1)) :
new RectF(cell * i, 0, cell * (i + 1), size);
float speed = (float)(speedFactor * data[i]);
float tail = (float)(max == 0 ? 0 : (data[i] / max)) * length;
particles[i] = new Particle(random, rect, dir, color, speed, tail, randomizeTime);
}
}
}
/**
* A single particle that moves into horizontal or vertical direction.
*
* @author Marcus
*/
private static class Particle {
/** A random number generator to make the particle less predictable. */
@NonNull
private Random random;
/** The movement direction (horizontal: left to right, vertical: top to bottom). */
@NonNull
private Direction direction;
/** The rectangle in which we draw. */
@NonNull
private RectF rect;
/** The current x-position of the particle (head). */
private float x;
/** The current y-position of the particle (head). */
private float y;
/** The length of the particle's tail. */
private float length;
/** The movement speed in pixels per second. */
private float speed;
/** The time used to randomize restarts. */
private int randomize;
/** The time when the particle's position was last computed. */
private long time;
/** A gradient to quickly draw the particle. */
@NonNull
private LinearGradient gradient;
/** The translation matrix to avoid object allocations. */
@NonNull
private Matrix matrix = new Matrix();
/**
* A single particle that moves either vertically or horizontally.
*
* @param random A random number generator.
* @param rect The rectangle in which the particle moves.
* @param direction The direction to move (left to right or top to bottom).
* @param speed The movement speed in pixels per second.
* @param length The length of the tail of the particle.
* @param randomize The time used to randomize the restart when the particle moved off the screen.
*/
public Particle(@NonNull Random random, @NonNull RectF rect, @NonNull Direction direction, int color, float speed, float length, int randomize) {
this.random = random;
this.direction = direction;
this.rect = rect;
this.speed = speed;
this.length = length;
this.randomize = randomize;
gradient = new LinearGradient(0, 0,
direction == Direction.HORIZONTAL?length:0,
direction == Direction.HORIZONTAL?0:length,
new int[] { 0x00ffffff, color },
new float[] { 0f, 1f}, Shader.TileMode.CLAMP);
}
/**
* Draws the particle onto the canvas.
*
* @param c The canvas.
* @param paint The paint to draw with.
*/
public void draw(Canvas c, Paint paint) {
float xs = (direction == Direction.HORIZONTAL)? x - length: x;
float ys = (direction == Direction.HORIZONTAL)? y : y - length;
matrix.setTranslate(xs, ys);
gradient.setLocalMatrix(matrix);
paint.setShader(gradient);
c.drawLine(xs , ys, x, y, paint);
}
/**
* Computes the animation state based on the time.
*
* @param time The time.
*/
public void animate(long time) {
if (this.time == 0 || isFinished()) {
reset(this.time == 0);
} else {
moveBy(time - this.time);
}
this.time = time;
}
/**
* Determines whether the particle has moved out of sight.
*
* @return True if it has moved out of sight. False otherwise.
*/
private boolean isFinished() {
if (direction == Direction.HORIZONTAL) {
return x - length > rect.right;
} else {
return y - length > rect.bottom;
}
}
/**
* Resets the particle to a new initial position.
*
* @param init True, if the positions shall be randomly distributed.
*/
private void reset(boolean init) {
float movement = random.nextInt(randomize) / 1000f * speed;
if (direction == Direction.HORIZONTAL) {
x = rect.left - movement + (init?rect.width() * random.nextFloat():0);
y = rect.top + (rect.bottom - rect.top) * 0.5f;
} else {
x = rect.left + (rect.right - rect.left) * 0.5f;
y = rect.top - movement + (init?rect.height() * random.nextFloat():0);
}
}
/**
* Moves the particle depending on the time passed.
*
* @param delta The time passed in milliseconds.
*/
private void moveBy(long delta) {
float movement = delta / 1000f * speed;
if (direction == Direction.HORIZONTAL) {
x += movement;
} else {
y += movement;
}
}
}
}
@@ -0,0 +1,429 @@
package com.mowesta.android.app.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.res.ResourcesCompat;
import com.mowesta.android.app.R;
import com.mowesta.android.app.util.TimeUtils;
/**
* The view to display the time and to handle touch events.
*
* @author Marcus
*/
public class TimeView extends DataView<Long> {
/**
* An interface for listeners that want to be
* informed about touch events.
*
* @author Marcus
*/
public interface OnSlideListener {
/**
* Called when there is a slide event on the view at
* the specified relative position.
*
* @param relative The relative position (0 to 1).
*/
void onSlide(float relative);
void onSlideEnd();
}
/**
* A listener to handle the touch events on the view.
*
*/
private static class TouchListener implements View.OnTouchListener {
/** The epsilon to ignore duplicate events. */
private float EPSILON = 0.0001f;
/** The time view that is observed by this listener. */
private TimeView view;
/** A cache for the view position.*/
private int[] viewPosition = new int[2];
/**
* If down, the id of the pointer that we are tracking.
*/
private int id = 0;
/**
* A boolean to memorize whether we already saw a finger going down.
*/
private boolean down = false;
/**
* The last relative position that we saw.
*/
private float position = 0;
@NonNull
private OnSlideListener listener;
public TouchListener(@NonNull TimeView view, @NonNull OnSlideListener listener) {
this.view = view;
this.listener = listener;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
updateViewPosition();
int index = event.getActionIndex();
int mask = event.getActionMasked();
boolean onView = isOnView(event);
switch (mask) {
case MotionEvent.ACTION_DOWN:
if (! down && onView) {
down = true;
id = event.getPointerId(index);
position = getPosition(event);
listener.onSlide(position);
};
break;
case MotionEvent.ACTION_MOVE:
if (down && id == event.getPointerId(index)) {
float np = getPosition(event);
if (Math.abs(np - position) > EPSILON) {
position = np;
listener.onSlide(position);
}
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (down && id == event.getPointerId(index)) {
down = false;
listener.onSlideEnd();
return true;
}
break;
}
return down;
}
private void updateViewPosition() {
view.getLocationOnScreen(viewPosition);
}
private float getPosition(MotionEvent event) {
if (view.getDirection() == Direction.HORIZONTAL) {
if (view.getWidth() == 0) return 0;
float x = event.getRawX();
return Math.min(1, Math.max(0, (x - viewPosition[0]) / view.getWidth()));
} else {
if (view.getHeight() == 0) return 0;
float y = event.getRawY();
return Math.min(1, Math.max(0, (y - viewPosition[1]) / view.getHeight()));
}
}
private boolean isOnView(MotionEvent event) {
float x = event.getRawX();
float y = event.getRawY();
return x >= viewPosition[0] && x < viewPosition[0] + view.getWidth()
&& y >= viewPosition[1] && y < viewPosition[1] + view.getHeight();
}
}
/**
* The timezone.
*/
private String timezone;
/**
* The positions to draw lines.
*/
private float[] positions;
/**
* The lengths of the lines at the positions.
*/
private float[] lengths;
/**
* The paint to draw the lines.
*/
private Paint paint = new Paint();
/**
* The paint to draw the current time.
*/
private Paint paintNow = new Paint();
/**
* The circle animation.
*/
private TouchCircleAnimation animation = new TouchCircleAnimation(this);
/**
* Creates a new view.
*
* @param context The context.
*/
public TimeView(Context context) {
super(context);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
*/
public TimeView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
* @param defStyleAttr The default attributes.
*/
public TimeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
/**
* Creates a new view.
*
* @param context The context.
* @param attrs The attributes.
* @param defStyleAttr The default attributes.
* @param defStyleRes The default style.
*/
@TargetApi(21)
public TimeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
/**
* Initializes the view.
*
* @param context The context.
*/
private void init(Context context) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
paint.setStrokeWidth((int)(1f * displayMetrics.density + .5f));
paint.setColor(ResourcesCompat.getColor(context.getResources(), R.color.inverse, null));
paint.setAntiAlias(true);
paintNow.setStrokeWidth((int)(2f * displayMetrics.density + .5f));
paintNow.setColor(ResourcesCompat.getColor(context.getResources(), R.color.primary, null));
paintNow.setAntiAlias(true);
}
/**
* Creates an touch listener for this view.
*
* @param listener The listener to keep track of events.
* @return The touch listener.
*/
public View.OnTouchListener createOnTouchListener(@NonNull OnSlideListener listener) {
return new TouchListener(this, listener);
}
/**
* Sets the timezone to draw the hours.
*
* @param timezone The timezone.
*/
public void setTimezone(String timezone) {
this.timezone = timezone;
updateTimes();
}
/**
* Returns the time zone.
*
* @return The timezone.
*/
public String getTimezone() {
return timezone;
}
@Override
public void setData(@Nullable Long[] data) {
super.setData(data);
updateTimes();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
updateTimes();
}
@Override
protected void onDrawData(long time, Canvas canvas) {
animation.animate(time);
animation.draw(canvas);
if (positions != null) {
// draw now
for (int i = 1; i < data.length; i++) {
if (time > data[i - 1] && time <= data[i]) {
float fraction = (data[i] - time) / (data[i] - data[i - 1]);
float pos = (direction == Direction.VERTICAL?getHeight():getWidth()) * (i + fraction) / data.length;
float end = direction == Direction.VERTICAL?getWidth():getHeight();
if (direction == Direction.VERTICAL) {
canvas.drawLine(0, pos, end, pos, paintNow);
} else {
canvas.drawLine(pos, 0, pos, end, paintNow);
}
}
}
// draw grid
float center = (direction == Direction.VERTICAL?getWidth():getHeight()) / 2f;
for (int i = 0; i < positions.length; i++) {
float xs = direction == Direction.VERTICAL?center - .5f * lengths[i]:positions[i];
float xe = direction == Direction.VERTICAL?center + .5f * lengths[i]:positions[i];
float ys = direction == Direction.HORIZONTAL?center - .5f * lengths[i]:positions[i];
float ye = direction == Direction.HORIZONTAL?center + .5f * lengths[i]:positions[i];
canvas.drawLine(xs, ys, xe, ye, paint);
}
}
}
public void updateTimes() {
if (data == null || data.length == 0) {
lengths = null;
positions = null;
} else {
int[] hours = new int[data.length];
TimeUtils time = new TimeUtils(System.currentTimeMillis(), timezone);
int ranges = 0;
for (int i = 0; i < data.length; i++) {
hours[i] = time.getHour(data[i]);
if (hours[i] % 6 == 0) {
ranges += 1;
}
}
positions = new float[ranges];
lengths = new float[ranges];
int index = 0;
int total = direction == Direction.VERTICAL?getHeight():getWidth();
int max = direction == Direction.VERTICAL?getWidth():getHeight();
for (int i = 0; i < data.length; i++) {
if (hours[i] % 6 == 0) {
positions[index] = ((float)total / data.length) * (i + .5f);
lengths[index] = hours[i] == 0 ? (max * .75f): (max * 0.25f);
index += 1;
}
}
}
}
private class TouchCircleAnimation {
/** The center of the click. */
float cx, cy;
/** The animated radius. */
float radius;
/** The animated alpha value. */
float alpha;
/** The speed at which the circle expands. */
float expand = 500;
/**
* The speed at which the alpha value decays.
*/
float fade = 2f;
/** The Animation time. */
long time = 0;
/** The number of repeatitions. */
int repeat = 0;
/** A boolean to indicate when done. */
boolean done = false;
/** The paint to draw. */
Paint paint = new Paint();
/** The view. */
DataView<?> view;
/** The finger drawable. */
Drawable touch;
public TouchCircleAnimation(DataView<?> view) {
this.view = view;
this.touch = AppCompatResources.getDrawable(view.getContext(), R.drawable.ic_touch_app_normal_24);
paint.setColor(ResourcesCompat.getColor(view.getResources(), R.color.accent, null));
paint.setStyle(Paint.Style.FILL);
}
public void animate(long now) {
if (time == 0) {
reset();
} else {
updateBy(now - time);
if (alpha < 0) {
reset();
}
}
time = now;
done = repeat > 3;
}
private void updateBy(long delta) {
float dx = delta / 1000f;
alpha -= dx * fade;
radius += dx * expand;
}
public void draw(Canvas c) {
if (!done) {
if (repeat > 1) {
int a = (int)Math.min(255, Math.max(0, 255 * alpha));
paint.setAlpha(Math.min(255, a + 128));
c.drawCircle(cx, cy, radius, paint);
touch.setAlpha(a);
touch.draw(c);
}
postInvalidateOnAnimation();
}
}
public void reset() {
cx = getWidth() / 2;
cy = getHeight() / 2;
if (view.direction == Direction.VERTICAL) {
cy = cy / 2f;
}
int padding = (int)(Math.min(getWidth(), getHeight()) * 0.1f);
int size = Math.min(getWidth(), getHeight()) / 2 - padding;
touch.setBounds((int)cx - size, (int)cy - size, (int)cx + size, (int) cy + size);
radius = 1;
alpha = 1;
repeat += 1;
}
}
}
@@ -1,163 +0,0 @@
package com.mowesta.android.app.view;
/**
* The weather icon codes extracted from the css file.
*/
@SuppressWarnings({"unused", "javadoc"})
public enum WeatherIcon {
DAY_SUNNY("\uf00d"),
DAY_CLOUDY("\uf002"),
DAY_CLOUDY_GUSTS("\uf000"),
DAY_CLOUDY_WINDY("\uf001"),
DAY_FOG("\uf003"),
DAY_HAIL("\uf004"),
DAY_HAZE("\uf0b6"),
DAY_LIGHTNING("\uf005"),
DAY_RAIN("\uf008"),
DAY_RAIN_MIX("\uf006"),
DAY_RAIN_WIND("\uf007"),
DAY_SHOWERS("\uf009"),
DAY_SLEET("\uf0b2"),
DAY_SLEET_STORM("\uf068"),
DAY_SNOW("\uf00a"),
DAY_SNOW_THUNDERSTORM("\uf06b"),
DAY_SNOW_WIND("\uf065"),
DAY_SPRINKLE("\uf00b"),
DAY_STORM_SHOWERS("\uf00e"),
DAY_SUNNY_OVERCAST("\uf00c"),
DAY_THUNDERSTORM("\uf010"),
DAY_WINDY("\uf085"),
SOLAR_ECLIPSE("\uf06e"),
HOT("\uf072"),
DAY_CLOUDY_HIGH("\uf07d"),
DAY_LIGHT_WIND("\uf0c4"),
NIGHT_CLEAR("\uf02e"),
NIGHT_ALT_CLOUDY("\uf086"),
NIGHT_ALT_CLOUDY_GUSTS("\uf022"),
NIGHT_ALT_CLOUDY_WINDY("\uf023"),
NIGHT_ALT_HAIL("\uf024"),
NIGHT_ALT_LIGHTNING("\uf025"),
NIGHT_ALT_RAIN("\uf028"),
NIGHT_ALT_RAIN_MIX("\uf026"),
NIGHT_ALT_RAIN_WIND("\uf027"),
NIGHT_ALT_SHOWERS("\uf029"),
NIGHT_ALT_SLEET("\uf0b4"),
NIGHT_ALT_SLEET_STORM("\uf06a"),
NIGHT_ALT_SNOW("\uf02a"),
NIGHT_ALT_SNOW_THUNDERSTORM("\uf06d"),
NIGHT_ALT_SNOW_WIND("\uf067"),
NIGHT_ALT_SPRINKLE("\uf02b"),
NIGHT_ALT_STORM_SHOWERS("\uf02c"),
NIGHT_ALT_THUNDERSTORM("\uf02d"),
NIGHT_CLOUDY("\uf031"),
NIGHT_CLOUDY_GUSTS("\uf02f"),
NIGHT_CLOUDY_WINDY("\uf030"),
NIGHT_FOG("\uf04a"),
NIGHT_HAIL("\uf032"),
NIGHT_LIGHTNING("\uf033"),
NIGHT_PARTLY_CLOUDY("\uf083"),
NIGHT_RAIN("\uf036"),
NIGHT_RAIN_MIX("\uf034"),
NIGHT_RAIN_WIND("\uf035"),
NIGHT_SHOWERS("\uf037"),
NIGHT_SLEET("\uf0b3"),
NIGHT_SLEET_STORM("\uf069"),
NIGHT_SNOW("\uf038"),
NIGHT_SNOW_THUNDERSTORM("\uf06c"),
NIGHT_SNOW_WIND("\uf066"),
NIGHT_SPRINKLE("\uf039"),
NIGHT_STORM_SHOWERS("\uf03a"),
NIGHT_THUNDERSTORM("\uf03b"),
LUNAR_ECLIPSE("\uf070"),
STARS("\uf077"),
STORM_SHOWERS("\uf01d"),
THUNDERSTORM("\uf01e"),
NIGHT_ALT_CLOUDY_HIGH("\uf07e"),
NIGHT_CLOUDY_HIGH("\uf080"),
NIGHT_ALT_PARTLY_CLOUDY("\uf081"),
CLOUD("\uf041"),
CLOUDY("\uf013"),
CLOUDY_GUSTS("\uf011"),
CLOUDY_WINDY("\uf012"),
FOG("\uf014"),
HAIL("\uf015"),
RAIN("\uf019"),
RAIN_MIX("\uf017"),
RAIN_WIND("\uf018"),
SHOWERS("\uf01a"),
SLEET("\uf0b5"),
SNOW("\uf01b"),
SPRINKLE("\uf01c"),
SNOW_WIND("\uf064"),
SMOG("\uf074"),
SMOKE("\uf062"),
LIGHTNING("\uf016"),
RAINDROPS("\uf04e"),
RAINDROP("\uf078"),
DUST("\uf063"),
SNOWFLAKE_COLD("\uf076"),
WINDY("\uf021"),
STRONG_WIND("\uf050"),
SANDSTORM("\uf082"),
EARTHQUAKE("\uf0c6"),
FIRE("\uf0c7"),
FLOOD("\uf07c"),
METEOR("\uf071"),
TSUNAMI("\uf0c5"),
VOLCANO("\uf0c8"),
HURRICANE("\uf073"),
TORNADO("\uf056"),
SMALL_CRAFT_ADVISORY("\uf0cc"),
GALE_WARNING("\uf0cd"),
STORM_WARNING("\uf0ce"),
HURRICANE_WARNING("\uf0cf"),
WIND_DIRECTION("\uf0b1"),
ALIEN("\uf075"),
CELSIUS("\uf03c"),
FAHRENHEIT("\uf045"),
DEGREES("\uf042"),
THERMOMETER("\uf055"),
THERMOMETER_EXTERIOR("\uf053"),
THERMOMETER_INTERNAL("\uf054"),
CLOUD_DOWN("\uf03d"),
CLOUD_UP("\uf040"),
CLOUD_REFRESH("\uf03e"),
HORIZON("\uf047"),
HORIZON_ALT("\uf046"),
SUNRISE("\uf051"),
SUNSET("\uf052"),
MOONRISE("\uf0c9"),
MOONSET("\uf0ca"),
REFRESH("\uf04c"),
REFRESH_ALT("\uf04b"),
UMBRELLA("\uf084"),
BAROMETER("\uf079"),
HUMIDITY("\uf07a"),
NA("\uf07b"),
TRAIN("\uf0cb");
/**
* The value associated with the icon.
*/
private final String value;
/**
* Creates a weather icon with the value.
*
* @param value The value.
*/
private WeatherIcon(String value) {
this.value = value;
}
/**
* Returns the string value of the icon.
*
* @return The string value of the icon.
*/
public String getValue() {
return value;
}
}
@@ -1,105 +0,0 @@
package com.mowesta.android.app.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.content.res.ResourcesCompat;
import com.mowesta.android.app.R;
/**
* A view that displays an icon from the weather icon set. Note
* that this view will not show the correct preview in the
* development tools, since there seems to be a bug in the current
* version of the layout editor in Android Studio that prevents
* the loading of custom fonts.
*
* @author Marcus
*/
public class WeatherView extends AppCompatTextView {
/**
* The icon type to display.
*/
WeatherIcon type;
/**
* Creates a weather view.
*
* @param context The context.
*/
public WeatherView(Context context) {
super(context);
}
/**
* Creates the weather view.
*
* @param context The context.
* @param attrs The attributes.
*/
public WeatherView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
/**
* Creates the weather view.
*
* @param context The context.
* @param attrs The attributes.
* @param defStyleAttr The theme.
*/
public WeatherView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
/**
* Initializes the view from the attributes.
*
* @param attrs The attributes.
*/
public void init(AttributeSet attrs) {
if (! isInEditMode()) {
setTypeface(ResourcesCompat.getFont(getContext(), R.font.weather), Typeface.NORMAL);
if (attrs == null) return;
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.WeatherView);
int type = ta.getInt(R.styleable.WeatherView_weather,-1);
if (type >= 0 && type < WeatherIcon.values().length) {
WeatherIcon icon = WeatherIcon.values()[type];
setText(icon.getValue());
} else {
setText("");
}
ta.recycle();
} else {
setText("O");
}
}
/**
* Sets the icon type.
*
* @param type The icon type.
*/
public void setType(WeatherIcon type) {
this.type = type;
if (!isInEditMode()) {
setText(type == null ? "" : type.getValue());
}
}
/**
* Returns the icon type.
*
* @return The icon type.
*/
public WeatherIcon getType() {
return type;
}
}
@@ -0,0 +1,32 @@
package com.mowesta.android.app.view.color;
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
import java.util.ArrayList;
import java.util.List;
/**
* A color scheme for the cloud depth.
*
* @author Marcus
*/
public class CloudDepthColorScheme extends InterpolatedColorScheme {
/**
* The list of supports.
*/
private static List<ColorSupport> SUPPORT = new ArrayList<>();
static {
SUPPORT.add(new ColorSupport(0, 0x00FFFFFF));
SUPPORT.add(new ColorSupport(1, 0xFF999999));
}
/**
* Creates a new color scheme to render the cloud depth.
*/
public CloudDepthColorScheme() {
super(SUPPORT, new LinearInterpolation());
}
}
@@ -0,0 +1,32 @@
package com.mowesta.android.app.view.color;
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
import java.util.ArrayList;
import java.util.List;
/**
* The color scheme for relative humidity.
*
* @author Marcus
*/
public class HumidityColorScheme extends InterpolatedColorScheme {
/**
* The support vector with the temperature to color mapping.
*/
private static List<ColorSupport> SUPPORT = new ArrayList<>();
static {
SUPPORT.add(new ColorSupport(0, 0x0042BAD0));
SUPPORT.add(new ColorSupport(100, 0xFF42BAD0));
}
/**
* Creates a color scheme.
*/
public HumidityColorScheme() {
super(SUPPORT, new LinearInterpolation());
}
}
@@ -0,0 +1,19 @@
package com.mowesta.android.app.view.color;
/**
* A color scheme is responsible for mapping a data
* value to an ARGB color.
*
* @author Marcus
*/
public interface IColorScheme {
/**
* Returns the color for the data value.
*
* @param value The data value.
* @return The ARGB value with 8 bit resolution.
*/
int getColor(double value);
}
@@ -0,0 +1,202 @@
package com.mowesta.android.app.view.color;
import com.mowesta.android.app.view.interpolation.IDataInterpolation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* A color scheme for temperature given in degrees Kelvin.
*
* @author Marcus
*/
public class InterpolatedColorScheme implements IColorScheme {
/**
* A support point that defines the color for a particular value.
*
* @author Marcus
*/
public static class ColorSupport implements Comparable<ColorSupport> {
/**
* The value.
*/
protected double value;
/**
* The red component.
*/
protected int red;
/**
* The green component (0 - 255).
*/
protected int green;
/**
* The blue component.
*/
protected int blue;
/**
* The alpha component.
*/
protected int alpha;
/**
* Creates the support for the specified color.
*
* @param value The value that should exhibit the color.
* @param argb The color value.
*/
public ColorSupport(double value, int argb) {
this(value, (argb >> 24) & 0xff, (argb >> 16) & 0xff, (argb >> 8) & 0xff, argb & 0xff);
}
/**
* Creates a new support at a particular value.
*
* @param value The data value that should exhibit the color.
* @param a The alpha value.
* @param r The red value.
* @param g The green value.
* @param b The blue value.
*/
public ColorSupport(double value, int a, int r, int g, int b) {
this.value = value;
this.alpha = a & 0xff;
this.red = r & 0xff;
this.green = g & 0xff;
this.blue = b & 0xff;
}
/**
* Returns the value.
*
* @return The value.
*/
public double getValue() {
return value;
}
/**
* Returns the color as ARGB int.
*
* @return The color as ARGB int.
*/
public int getColor() {
return alpha << 24 | red << 16 | green << 8 | blue;
}
/**
* Returns the blue component (0-255).
*
* @return The blue component.
*/
public int getRed() {
return red;
}
/**
* Returns the blue component (0-255).
*
* @return The blue component.
*/
public int getGreen() {
return green;
}
/**
* Returns the blue component (0-255).
*
* @return The blue component.
*/
public int getAlpha() {
return alpha;
}
/**
* Returns the blue component (0-255).
*
* @return The blue component.
*/
public int getBlue() {
return blue;
}
@Override
public int compareTo(ColorSupport o) {
return Double.compare(value, o.value);
}
}
/**
* The supporting points.
*/
protected List<ColorSupport> supports;
/**
* The interpolation strategy.
*/
protected IDataInterpolation interpolation;
/**
* Creates an interpolated color scheme.
*
* @param supports The supports.
* @param interpolation The interpolation strategy.
*/
public InterpolatedColorScheme(List<ColorSupport> supports, IDataInterpolation interpolation) {
if (supports.isEmpty()) throw new IllegalArgumentException("At least one color support point must be specified.");
this.supports = new ArrayList<>(supports);
this.interpolation = interpolation;
Collections.sort(supports);
}
@Override
public int getColor(double data) {
// data is smaller than any support, return lowest support color
if (data < supports.get(0).getValue()) return supports.get(0).getColor();
for (int i = 1; i < supports.size(); i++) {
if (supports.get(i).getValue() > data) {
return getColor(supports.get(i - 1), supports.get(i), data);
}
}
// data is larger than any support, return highest support color
return supports.get(supports.size() - 1).getColor();
}
/**
* Computes the interpolated color for the value.
*
* @param from The lower support.
* @param to The higher support.
* @param value The data value.
* @return The interpolated color.
*/
private int getColor(ColorSupport from, ColorSupport to, double value) {
double fraction = (value - from.getValue()) / (double)(to.getValue() - from.getValue());
int alpha = getColor(from.getAlpha(), to.getAlpha(), fraction);
int red = getColor(from.getRed(), to.getRed(), fraction);
int green = getColor(from.getGreen(), to.getGreen(), fraction);
int blue = getColor(from.getBlue(), to.getBlue(), fraction);
return alpha << 24 | red << 16 | green << 8 | blue;
}
/**
* Computes the interpolated color value and ensures that it
* lies within the target bounds.
*
* @param from The start color value.
* @param to The to color value.
* @param fraction The fraction between from and to.
* @return The color value.
*/
private int getColor(int from, int to, double fraction) {
double r = interpolation.interpolate(from, to, fraction);
return Math.min(255, Math.max(0, (int)Math.round(r)));
}
}
@@ -0,0 +1,37 @@
package com.mowesta.android.app.view.color;
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
import java.util.ArrayList;
import java.util.List;
/**
* The color scheme for precipitation (rain, snow, etc.).
* @author Marcus
*
*/
public class PrecipitationColorScheme extends InterpolatedColorScheme {
/**
* The support vector with the temperature to color mapping.
*/
private static List<ColorSupport> SUPPORT = new ArrayList<>();
static {
SUPPORT.add(new ColorSupport(0, 0x0000000));
SUPPORT.add(new ColorSupport(0.1, 0x88008800));
SUPPORT.add(new ColorSupport(1, 0xFF00FF00)); // Nieselregen (<1)
SUPPORT.add(new ColorSupport(10, 0xFF00FFFF));
SUPPORT.add(new ColorSupport(20, 0xFF0000FF)); // Starkregen (>20)
SUPPORT.add(new ColorSupport(20, 0xFF880000));
SUPPORT.add(new ColorSupport(35, 0xFFFF0000)); // Unwetter (>35)
}
/**
* Creates a color scheme.
*/
public PrecipitationColorScheme() {
super(SUPPORT, new LinearInterpolation());
}
}
@@ -0,0 +1,46 @@
package com.mowesta.android.app.view.color;
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
import java.util.ArrayList;
import java.util.List;
/**
* A color scheme that makes low pressure zones blue and high
* pressure zones red.
*
* @author Marcus
*
*/
public class PressureColorScheme extends InterpolatedColorScheme {
/**
* Creates a pressure color scheme.
*
* @param avg The average value.
* @param min The minimum value.
* @param max The maximum value.
*/
public PressureColorScheme(double avg, double min, double max) {
super(createSupport(avg, min, max), new LinearInterpolation());
}
/**
* Creates the support for the color scheme based on the average,
* minimum and maximum values.
*
* @param avg The average.
* @param min The minimum.
* @param max The maximum.
* @return The support for the scheme.
*/
private static List<ColorSupport> createSupport(double avg, double min, double max) {
List<ColorSupport> result = new ArrayList<>();
result.add(new ColorSupport(min, 255, 0, 0, 0));
result.add(new ColorSupport(avg, 255, 0, 0, 255));
result.add(new ColorSupport(max, 255, 255, 0, 255));
return result;
}
}

Some files were not shown because too many files have changed in this diff Show More