Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f641f5749c | ||
|
|
a0458b963c | ||
|
|
3403907775 | ||
|
|
768bb996d9 | ||
|
|
a008d3612b | ||
|
|
6bb9330a20 | ||
|
|
ec384792fa | ||
|
|
a954034c72 | ||
|
|
832ce77f74 | ||
|
|
9ea731af06 | ||
|
|
6763e2eefd | ||
|
|
7786e594f2 | ||
|
|
a5c4ff33aa | ||
|
|
9e38572e8e | ||
|
|
015fdf713c | ||
|
|
0d67b29189 | ||
|
|
886b175084 | ||
|
|
799ad2c5b8 | ||
|
|
471bfa3c34 | ||
|
|
4fd35d8a8d | ||
|
|
0d3bf7a991 | ||
|
|
9b7360752d | ||
|
|
ae3483761c |
Vendored
+14
-3
@@ -5,7 +5,7 @@ node {
|
||||
|
||||
// set environment variables
|
||||
env.ANDROID_SDK_ROOT = '/var/lib/android-sdk'
|
||||
env.JAVA_HOME = '/opt/openjdk-bin-17'
|
||||
env.JAVA_HOME = '/opt/openjdk-bin-21'
|
||||
env.PATH = "${env.JAVA_HOME}/bin:${env.PATH}"
|
||||
|
||||
// checkout code from scm
|
||||
@@ -46,13 +46,24 @@ node {
|
||||
// deploy the build output on the server
|
||||
stage ('Deploy') {
|
||||
// release = true; // uncomment to temporary enable snapshot deployments
|
||||
|
||||
// copy android bundles to apps pro
|
||||
if (env.BRANCH_NAME == "master") {
|
||||
echo "Copying android bundles to production server ..."
|
||||
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
|
||||
sh 'scp -i $KEYFILE android-app/build/outputs/apk/prod/release/*.apk wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
|
||||
sh 'scp -i $KEYFILE android-app/build/outputs/bundle/prodRelease/*.aab wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
|
||||
}
|
||||
} else {
|
||||
echo "Skip copying of android bundles for non-master branch."
|
||||
}
|
||||
|
||||
// deploy service to apps pro or apps dev
|
||||
if (env.BRANCH_NAME == "master" && release) {
|
||||
echo "Deploying to production server ..."
|
||||
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "KEYFILE")]) {
|
||||
sh 'scp -i $KEYFILE service-war/build/libs/service-war-' + version + '.war wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-31-mowesta/standalone/deployments/service-war.war'
|
||||
sh 'scp -i $KEYFILE web-war/build/libs/web-war-' + version + '.war wildfly@apps-pro.nes.uni-due.de:/opt/wildfly-31-mowesta/standalone/deployments/web-war.war'
|
||||
// sh 'scp -i $KEYFILE android-app/build/outputs/apk/prod/release/*.apk wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
|
||||
// sh 'scp -i $KEYFILE android-app/build/outputs/bundle/prodRelease/*.aab wildfly@apps-pro.nes.uni-due.de:/opt/android/mowesta/'
|
||||
}
|
||||
} else if (env.BRANCH_NAME == "master") {
|
||||
echo "Deploying to beta server ..."
|
||||
|
||||
@@ -40,6 +40,10 @@ compileJava {
|
||||
dependsOn 'generateClient'
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
dependsOn 'generateClient'
|
||||
}
|
||||
|
||||
task generateClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
|
||||
dependsOn ':service-api:resolve'
|
||||
generatorName = "java"
|
||||
|
||||
+37
-32
@@ -7,24 +7,25 @@ description = "MoWeSta Android App"
|
||||
|
||||
ext {
|
||||
// android app dependencies
|
||||
versionPlay = '17.0.0'
|
||||
versionPlay = '17.3.0'
|
||||
versionAndroidXCore = '1.3.1'
|
||||
versionAndroidXCoreTest = '2.1.0'
|
||||
versionAndroidXRecycler = '1.2.1'
|
||||
versionAndroidXCoreTest = '2.2.0'
|
||||
versionAndroidXRecycler = '1.4.0'
|
||||
versionAndroidXPaging = '2.1.2'
|
||||
versionAndroidXCard = '1.0.0'
|
||||
versionAndroidXCoordinator = '1.2.0'
|
||||
versionAndroidXConstraint = '2.1.4'
|
||||
versionAndroidXNavigation = '2.5.3'
|
||||
versionAndroidXLifecycle = '2.5.1'
|
||||
versionAndroidXCoordinator = '1.3.0'
|
||||
versionAndroidXConstraint = '2.2.2'
|
||||
versionAndroidXNavigation = '2.10.1'
|
||||
versionAndroidXLifecycle = '2.10.0'
|
||||
versionAndroidXSecurity = '1.0.0'
|
||||
versionAndroidXViewpager = '1.0.0'
|
||||
versionAndroidXWork = '2.7.1'
|
||||
versionGoogleMaterial = '1.7.0'
|
||||
versionAndroidXSwipeRefresh = '1.1.0'
|
||||
versionAndroidXWebkit = '1.5.0'
|
||||
versionExoPlayer = '2.18.1'
|
||||
versionApp = project.version
|
||||
versionAndroidXViewpager = '1.1.0'
|
||||
versionAndroidXWork = '2.10.5'
|
||||
versionGoogleMaterial = '1.14.0'
|
||||
versionAndroidXSwipeRefresh = '1.2.0'
|
||||
versionAndroidXWebkit = '1.17.0'
|
||||
versionExoPlayer = '1.6.0'
|
||||
versionAndroidXProfileInstaller = '1.4.1'
|
||||
versionApp = '1.4.2'
|
||||
}
|
||||
|
||||
// remove project version to workaround bugs in
|
||||
@@ -34,11 +35,9 @@ ext {
|
||||
// https://github.com/google/play-services-plugins
|
||||
project.version = "unspecified"
|
||||
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation project(":android-sdk")
|
||||
implementation project(":android-api")
|
||||
|
||||
implementation "jakarta.xml.bind:jakarta.xml.bind-api:${versionJaxb}"
|
||||
implementation "androidx.appcompat:appcompat:${versionAndroidXAppcompat}"
|
||||
@@ -64,9 +63,9 @@ dependencies {
|
||||
|
||||
implementation "androidx.webkit:webkit:${versionAndroidXWebkit}"
|
||||
|
||||
implementation "com.google.android.exoplayer:exoplayer-core:${versionExoPlayer}"
|
||||
implementation "com.google.android.exoplayer:exoplayer-ui:${versionExoPlayer}"
|
||||
|
||||
implementation "androidx.media3:media3-exoplayer:${versionExoPlayer}"
|
||||
implementation "androidx.media3:media3-exoplayer-dash:${versionExoPlayer}"
|
||||
implementation "androidx.media3:media3-ui:${versionExoPlayer}"
|
||||
|
||||
implementation "androidx.room:room-runtime:${versionAndroidXRoom}"
|
||||
annotationProcessor "androidx.room:room-compiler:${versionAndroidXRoom}"
|
||||
@@ -80,6 +79,7 @@ dependencies {
|
||||
androidTestImplementation "androidx.navigation:navigation-testing:${versionAndroidXNavigation}"
|
||||
|
||||
implementation "com.google.android.gms:play-services-oss-licenses:${versionPlay}"
|
||||
implementation "androidx.profileinstaller:profileinstaller:${versionAndroidXProfileInstaller}"
|
||||
|
||||
testImplementation "junit:junit:${versionJunit}"
|
||||
testImplementation "androidx.test:core:${versionAndroidXTest}"
|
||||
@@ -95,12 +95,12 @@ configurations {
|
||||
|
||||
|
||||
android {
|
||||
compileSdkVersion 33
|
||||
defaultConfig {
|
||||
applicationId "com.mowesta.android.app"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 33
|
||||
versionCode 30
|
||||
minSdkVersion 24
|
||||
compileSdk 36
|
||||
targetSdkVersion 36
|
||||
versionCode 33
|
||||
versionName "${versionApp}"
|
||||
buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
@@ -125,10 +125,16 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
// add signing config if key is provided via system property
|
||||
if (System.properties['android.keystore.password'] != null) signingConfig signingConfigs.release
|
||||
}
|
||||
@@ -155,6 +161,7 @@ android {
|
||||
|
||||
buildFeatures {
|
||||
dataBinding = true
|
||||
buildConfig = true
|
||||
}
|
||||
|
||||
testOptions {
|
||||
@@ -163,11 +170,6 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
lint {
|
||||
abortOnError false
|
||||
disable 'RelativeOverlap', 'FragmentTagUsage', 'VectorPath'
|
||||
@@ -205,7 +207,10 @@ eclipse {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(Test).configureEach {
|
||||
failOnNoDiscoveredTests = false
|
||||
}
|
||||
|
||||
if (System.properties['android.keystore.password'] != null) {
|
||||
build.dependsOn "bundle"
|
||||
}
|
||||
|
||||
|
||||
Vendored
+30
-15
@@ -1,21 +1,36 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
# Disable symbol and name obfuscation while preserving R8 code shrinking and bytecode optimization
|
||||
-dontobfuscate
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
# Preserve stack traces and line numbers for debugging
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
# Keep Jackson annotations and reflection targets
|
||||
-dontwarn com.fasterxml.jackson.**
|
||||
|
||||
-dontwarn feign.**
|
||||
|
||||
# Keep API interfaces and model classes used for serialization/reflection
|
||||
-keep class com.mowesta.android.feign.model.** { *; }
|
||||
-keep interface com.mowesta.android.feign.api.** { *; }
|
||||
-keep class org.geojson.** { *; }
|
||||
|
||||
# Keep app data classes serialized with Jackson
|
||||
-keep class com.mowesta.android.app.repository.UserCredentials { *; }
|
||||
-keep class com.mowesta.android.app.arduino.ArduinoConfig { *; }
|
||||
-keepclassmembers class * {
|
||||
@com.fasterxml.jackson.annotation.* <fields>;
|
||||
@com.fasterxml.jackson.annotation.* <methods>;
|
||||
}
|
||||
|
||||
# Suppress warnings for optional/runtime dependencies
|
||||
-dontwarn javax.validation.**
|
||||
-dontwarn javax.xml.bind.**
|
||||
-dontwarn org.bouncycastle.**
|
||||
-dontwarn org.conscrypt.**
|
||||
-dontwarn org.openjsse.**
|
||||
-dontwarn org.slf4j.**
|
||||
@@ -5,19 +5,15 @@
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
|
||||
<uses-sdk tools:overrideLibrary="androidx.security" />
|
||||
|
||||
|
||||
<application android:name=".MowestaApp"
|
||||
tools:targetApi="24"
|
||||
android:networkSecurityConfig="@xml/network"
|
||||
@@ -52,14 +48,6 @@
|
||||
<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>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name=".widget.ForecastWidgetProvider"
|
||||
android:exported="true"
|
||||
@@ -80,6 +68,5 @@
|
||||
<meta-data android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_measure" />
|
||||
</receiver>
|
||||
<service android:name=".MowestaService" android:exported="true"/>
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.mowesta.android.app;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.android.exoplayer2.upstream.cache.Cache;
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.datasource.cache.Cache;
|
||||
import com.mowesta.android.app.repository.ClientFactory;
|
||||
import com.mowesta.android.app.repository.DeviceRepository;
|
||||
import com.mowesta.android.app.repository.FavoriteRepository;
|
||||
@@ -64,6 +66,7 @@ public interface IApp {
|
||||
*
|
||||
* @return The cache to store videos.
|
||||
*/
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
Cache getMediaCache();
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
package com.mowesta.android.app;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.net.http.HttpResponseCache;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -21,11 +18,6 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.navigation.NavBackStackEntry;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.NavDirections;
|
||||
import androidx.navigation.NavOptionsBuilder;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
@@ -35,10 +27,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.app.widget.PeriodicWidgetWorker;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.sdk.SdkRepository;
|
||||
import com.mowesta.android.sdk.task.ClearTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -113,24 +102,6 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The listener that observes the activation of the mowesta sdk service
|
||||
* and checks for the permissions.
|
||||
*/
|
||||
private OnSharedPreferenceChangeListener preferenceListener = (prefs, key) -> {
|
||||
if (MowestaSettings.PRIVACY_MEASURE.equals(key)) {
|
||||
if (settings.isPrivacyMeasure()) {
|
||||
if (!PermissionUtil.hasBackgroundPermissions(this) ||
|
||||
!PermissionUtil.hasNotificationPermission(this))
|
||||
requestPermissions(false);
|
||||
else MowestaService.startService(this);
|
||||
} else {
|
||||
MowestaService.stopService(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public MowestaActivity() {
|
||||
super(R.layout.activity_app);
|
||||
}
|
||||
@@ -151,50 +122,6 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
setIntent(intent);
|
||||
}
|
||||
|
||||
// got to navigation drawer when user presses notification
|
||||
private void handleNotificationIntent() {
|
||||
Intent intent = getIntent();
|
||||
if (intent.hasExtra(getString(R.string.mowesta_sdk_notification_activity_extra_name))) {
|
||||
String value = intent.getStringExtra(getString(R.string.mowesta_sdk_notification_activity_extra_name));
|
||||
if (value != null && value.equals(getString(R.string.mowesta_sdk_notification_activity_extra_value))) {
|
||||
NavController controller = Navigation.findNavController(this, R.id.navigation_app);
|
||||
if (controller.getGraph().getId() == R.id.navigation_core) {
|
||||
controller.navigate(R.id.action_drawer);
|
||||
} else {
|
||||
boolean hasDrawer = false;
|
||||
for (NavBackStackEntry entry: controller.getBackQueue()) {
|
||||
if (entry.getDestination().getId() == R.id.destination_drawer) {
|
||||
hasDrawer = true;
|
||||
}
|
||||
}
|
||||
if (hasDrawer) {
|
||||
controller.navigate(R.id.action_drawer);
|
||||
} else {
|
||||
controller.navigate(R.id.action_core);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
settings.getPreferences().registerOnSharedPreferenceChangeListener(preferenceListener);
|
||||
handleNotificationIntent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostResume() {
|
||||
super.onPostResume();
|
||||
MowestaService.startService(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
settings.getPreferences().unregisterOnSharedPreferenceChangeListener(preferenceListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
@@ -255,7 +182,6 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
case CODE_REQUEST_POST_NOTIFICATION: {
|
||||
if (!PermissionUtil.hasBackgroundPermissions(this))
|
||||
requestPermissions(true);
|
||||
else MowestaService.startService(this);
|
||||
break;
|
||||
}
|
||||
case CODE_REQUEST_BACKGROUND_PERMISSIONS:
|
||||
@@ -269,12 +195,7 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
}
|
||||
Log.d(TAG, "Permission result: " + b.toString());
|
||||
if (!granted) {
|
||||
settings.setPrivacyMeasure(false);
|
||||
showMissingPermission(requestCode == CODE_REQUEST_FOREGROUND_PERMISSIONS);
|
||||
} else {
|
||||
if (!PermissionUtil.hasBackgroundPermissions(this))
|
||||
settings.setPrivacyMeasure(false);
|
||||
else MowestaService.startService(this);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4,18 +4,16 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.StrictMode;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider;
|
||||
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 androidx.media3.database.StandaloneDatabaseProvider;
|
||||
import androidx.media3.datasource.cache.Cache;
|
||||
import androidx.media3.datasource.cache.LeastRecentlyUsedCacheEvictor;
|
||||
import androidx.media3.datasource.cache.SimpleCache;
|
||||
import com.mowesta.android.app.repository.ClientFactory;
|
||||
import com.mowesta.android.app.repository.DeviceRepository;
|
||||
import com.mowesta.android.app.repository.FavoriteRepository;
|
||||
@@ -34,6 +32,7 @@ import java.io.File;
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
@UnstableApi
|
||||
public class MowestaApp extends Application implements IApp {
|
||||
|
||||
/** The log tag. */
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.mowesta.android.app;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* A broadcast receiver that starts the background service after
|
||||
* a reboot and when the package is updated.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class MowestaReceiver extends BroadcastReceiver {
|
||||
|
||||
/**
|
||||
* The log tag of the receiver.
|
||||
*/
|
||||
private static final String TAG = "MowestaBootReceiver";
|
||||
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// should not happen but nobody likes crashing apps in background
|
||||
if (intent == null || context == null) return;
|
||||
Log.d(TAG, "Received an intent with action " + intent.getAction() + ".");
|
||||
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) ||
|
||||
Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
|
||||
MowestaService.startService(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.mowesta.android.app;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
||||
import com.mowesta.android.app.util.PermissionUtil;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.sdk.SdkService;
|
||||
|
||||
/**
|
||||
* A service to perform background measurements.
|
||||
*
|
||||
* @author Marcus, Katharina, Arman
|
||||
*/
|
||||
public class MowestaService extends SdkService {
|
||||
|
||||
@Override
|
||||
protected boolean isEnabled() {
|
||||
IApp app = (IApp)getApplication();
|
||||
MowestaSettings settings = app.getSettings();
|
||||
return settings.isPrivacyMeasure() && app.getDeviceRepository().getHandle().getValue() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultApi createApiClient() {
|
||||
IApp app = (IApp)getApplication();
|
||||
String handle = app.getDeviceRepository().getHandle().getValue();
|
||||
return app.getClientFactory().createClient(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the service.
|
||||
*
|
||||
* @param context A context object.
|
||||
*/
|
||||
public static void startService(Context context) {
|
||||
if (!PermissionUtil.hasBackgroundPermissions(context)) return;
|
||||
IApp app = (IApp)context.getApplicationContext();
|
||||
MowestaSettings settings = app.getSettings();
|
||||
if (!settings.isPrivacyMeasure() || app.getDeviceRepository().getHandle().getValue() == null) return;
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context, MowestaService.class);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
context.startService(intent);
|
||||
} else {
|
||||
context.startForegroundService(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the running service.
|
||||
*
|
||||
* @param context A context object.
|
||||
*/
|
||||
public static void stopService(Context context) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context, MowestaService.class);
|
||||
context.stopService(intent);
|
||||
}
|
||||
}
|
||||
@@ -6,16 +6,13 @@ import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.mowesta.android.sdk.SdkSettings;
|
||||
|
||||
/**
|
||||
* A utility class to manage the settings.
|
||||
*/
|
||||
public class MowestaSettings extends SdkSettings {
|
||||
public class MowestaSettings {
|
||||
|
||||
/**
|
||||
* An enumeration with the unit system used throughout
|
||||
@@ -99,14 +96,53 @@ public class MowestaSettings extends SdkSettings {
|
||||
public static final String TEMPERATURE_UNIT = "temperature_unit";
|
||||
|
||||
/**
|
||||
* Creates the settings with the context.
|
||||
* The shared preferences for the application.
|
||||
*/
|
||||
protected @NonNull SharedPreferences preferences;
|
||||
|
||||
/**
|
||||
* The application context.
|
||||
*/
|
||||
protected @NonNull Application application;
|
||||
|
||||
/**
|
||||
* Creates a new settings object to query and modify the
|
||||
* settings.
|
||||
*
|
||||
* @param application The context.
|
||||
* @param application The application.
|
||||
*/
|
||||
public MowestaSettings(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
this.preferences = PreferenceManager.getDefaultSharedPreferences(application);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the underlying shared preferences.
|
||||
*
|
||||
* @return The preferences.
|
||||
*/
|
||||
public @NonNull SharedPreferences getPreferences() {
|
||||
return preferences;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the application context.
|
||||
*
|
||||
* @return The application context
|
||||
*/
|
||||
public @NonNull
|
||||
Context getContext() { return application.getApplicationContext(); }
|
||||
|
||||
/**
|
||||
* Returns the application resources.
|
||||
*
|
||||
* @return The application resources.
|
||||
*/
|
||||
public @NonNull
|
||||
Resources getResources() { return getContext().getResources(); }
|
||||
|
||||
/**
|
||||
* Determines whether the current terms are accepted.
|
||||
*
|
||||
|
||||
@@ -10,7 +10,7 @@ import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mowesta.android.sdk.task.AbstractTask;
|
||||
import com.mowesta.android.app.task.AbstractTask;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
|
||||
@@ -858,6 +858,7 @@ public class BindingAdapters {
|
||||
if (valueText != null) {
|
||||
if (text == null) {
|
||||
text = valueText;
|
||||
break; // only use first value (since it looks bad otherwise)
|
||||
} else {
|
||||
text = view.getResources().getString(R.string.format_two_lines, text, valueText);
|
||||
}
|
||||
|
||||
+1
-2
@@ -16,11 +16,10 @@ import android.widget.FrameLayout;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||
import androidx.media3.ui.AspectRatioFrameLayout;
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
|
||||
@@ -98,7 +98,7 @@ public class CityFragment extends AbstractPlaceFragment {
|
||||
NavController controller = Navigation.findNavController(root.findViewById(R.id.navigation_city));
|
||||
NavigationUI.setupWithNavController(binding.bottomNavigation, controller);
|
||||
AppBarConfiguration.Builder builder = new AppBarConfiguration.Builder(R.id.destination_drawer);
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().onBackPressed(); return true; });
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().getOnBackPressedDispatcher().onBackPressed(); return true; });
|
||||
NavigationUI.setupWithNavController(layout, toolbar, controller, builder.build());
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.databinding.FragmentCollectionBinding;
|
||||
import com.mowesta.android.app.util.DisplayUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The fragment to onboard the user with data collection.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class CollectionFragment extends Fragment {
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*/
|
||||
private MowestaSettings settings;
|
||||
|
||||
/**
|
||||
* The view binding.
|
||||
*/
|
||||
private FragmentCollectionBinding binding;
|
||||
|
||||
/**
|
||||
* Keeps track of preference and updates the state of the switch.
|
||||
*/
|
||||
private OnSharedPreferenceChangeListener preferenceListener = new OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
binding.privacyMeasureSwitch.setChecked(settings.isPrivacyMeasure());
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.settings = ((IApp)getContext().getApplicationContext()).getSettings();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_collection, container, false);
|
||||
binding.buttonContinue.setOnClickListener((v) -> {
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_collection_drawer);
|
||||
settings.setCollectionShown(true);
|
||||
}
|
||||
);
|
||||
binding.privacyMeasureSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
boolean current = settings.isPrivacyMeasure();
|
||||
if (current != isChecked) {
|
||||
settings.setPrivacyMeasure(isChecked);
|
||||
}
|
||||
}
|
||||
});
|
||||
binding.logoFair.setOnClickListener((v) -> openBrowser(R.string.fair_url));
|
||||
binding.logoUde.setOnClickListener((v) -> openBrowser(R.string.ude_url));
|
||||
// add a funky animation
|
||||
if (savedInstanceState == null) {
|
||||
List<View> views = new ArrayList<>();
|
||||
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);
|
||||
first.setDuration(1000);
|
||||
first.setInterpolator(new OvershootInterpolator());
|
||||
ObjectAnimator last = ObjectAnimator.ofFloat(binding.logoSun, "translationX", DisplayUtils.dpToPixels(getContext(), 90), 0f);
|
||||
last.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
last.setDuration(1000);
|
||||
set.playTogether(first, last);
|
||||
for (View view: views) {
|
||||
view.setAlpha(0);
|
||||
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view, "alpha", 0, 1);
|
||||
objectAnimator.setInterpolator(new LinearInterpolator());
|
||||
objectAnimator.setDuration(100);
|
||||
set.play(objectAnimator).after(last);
|
||||
last = objectAnimator;
|
||||
}
|
||||
set.start();
|
||||
}
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the url to which the resource string is pointing in a browser.
|
||||
*
|
||||
* @param res The resource pointing to a string representing the url.
|
||||
*/
|
||||
private void openBrowser(int res) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(getResources().getString(res)));
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Snackbar.make(getView(), R.string.message_no_browser, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
settings.getPreferences().registerOnSharedPreferenceChangeListener(preferenceListener);
|
||||
binding.privacyMeasureSwitch.setChecked(settings.isPrivacyMeasure());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
settings.getPreferences().unregisterOnSharedPreferenceChangeListener(preferenceListener);
|
||||
}
|
||||
}
|
||||
@@ -218,7 +218,7 @@ public class ConnectFragment extends Fragment {
|
||||
});
|
||||
Args args = Args.fromBundle(getArguments());
|
||||
if (args == null) {
|
||||
getActivity().onBackPressed();
|
||||
getActivity().getOnBackPressedDispatcher().onBackPressed();
|
||||
} else {
|
||||
model.init(args);
|
||||
}
|
||||
@@ -293,7 +293,7 @@ public class ConnectFragment extends Fragment {
|
||||
if (binding != null) {
|
||||
binding.connectSun.setAlpha(0f);
|
||||
TypedValue typedValue = new TypedValue();
|
||||
getActivity().getTheme().resolveAttribute(R.attr.colorControlNormal, typedValue, true);
|
||||
getActivity().getTheme().resolveAttribute(androidx.appcompat.R.attr.colorControlNormal, typedValue, true);
|
||||
int color = ContextCompat.getColor(getActivity(), typedValue.resourceId);
|
||||
ImageViewCompat.setImageTintList(binding.connectConfigure, ColorStateList.valueOf(color));
|
||||
ImageViewCompat.setImageTintList(binding.connectDevice, ColorStateList.valueOf(color));
|
||||
|
||||
@@ -83,7 +83,7 @@ public class CountryFragment extends AbstractPlaceFragment {
|
||||
binding.setModel(model);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
AppBarConfiguration.Builder builder = new AppBarConfiguration.Builder();
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().onBackPressed(); return true; });
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().getOnBackPressedDispatcher().onBackPressed(); return true; });
|
||||
NavigationUI.setupWithNavController(layout, toolbar, controller, builder.build());
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class DeviceFragment extends AbstractDiagramFragment {
|
||||
binding.setModel(model);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
AppBarConfiguration.Builder builder = new AppBarConfiguration.Builder();
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().onBackPressed(); return true; });
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().getOnBackPressedDispatcher().onBackPressed(); return true; });
|
||||
NavigationUI.setupWithNavController(layout, toolbar, controller, builder.build());
|
||||
IApp app = (IApp)getContext().getApplicationContext();
|
||||
app.getUserRepository().getCredentials().observe(getViewLifecycleOwner(), (c) -> model.setUserCredentials(c));
|
||||
|
||||
@@ -79,28 +79,6 @@ public class DrawerFragment extends AbstractNetworkFragment {
|
||||
return new ViewModelProvider(this).get(DrawerViewModel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
handleNotificationIntent();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the intent was generated by the background service and
|
||||
* opens the settings screen, if this is the case
|
||||
*/
|
||||
private void handleNotificationIntent() {
|
||||
Intent intent = getActivity().getIntent();
|
||||
if (intent.hasExtra(getString(R.string.mowesta_sdk_notification_activity_extra_name))) {
|
||||
String value = intent.getStringExtra(getString(R.string.mowesta_sdk_notification_activity_extra_name));
|
||||
if (value != null && value.equals(getString(R.string.mowesta_sdk_notification_activity_extra_value))) {
|
||||
getActivity().setIntent(new Intent());
|
||||
Navigation.findNavController(getView().findViewById(R.id.navigation_drawer)).navigate(R.id.destination_settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
+45
-27
@@ -5,6 +5,7 @@ import android.appwidget.AppWidgetManager;
|
||||
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;
|
||||
@@ -25,6 +26,7 @@ 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.AbstractWidgetProvider;
|
||||
import com.mowesta.android.app.widget.ForecastWidgetProvider;
|
||||
import com.mowesta.android.app.widget.PeriodicWidgetWorker;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
@@ -36,6 +38,11 @@ import com.mowesta.android.feign.model.City;
|
||||
*/
|
||||
public class ForecastWidgetFragment extends AbstractNetworkFragment {
|
||||
|
||||
/**
|
||||
* The log tag.
|
||||
*/
|
||||
private static final String TAG = "ForecastWidgetFragment";
|
||||
|
||||
/**
|
||||
* The bundle extra to store the widget id.
|
||||
*/
|
||||
@@ -105,7 +112,14 @@ public class ForecastWidgetFragment extends AbstractNetworkFragment {
|
||||
model.getCities(),
|
||||
model.getSelection()));
|
||||
model.getFinished().observe(getViewLifecycleOwner(), (c) -> {
|
||||
if (c != null) finish(c, model.getCelsius().getValue(), model.getColor().getValue());
|
||||
Activity activity = getActivity();
|
||||
if (c != null) {
|
||||
try {
|
||||
finish(activity, c, model.getCelsius().getValue(), model.getColor().getValue());
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to finish.", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
model.getDialog().observe(getViewLifecycleOwner(), (d) -> {
|
||||
if (d) {
|
||||
@@ -125,37 +139,41 @@ public class ForecastWidgetFragment extends AbstractNetworkFragment {
|
||||
* @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();
|
||||
public void finish(Activity activity, City city, boolean celsius, int color) {
|
||||
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;
|
||||
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.runInTransaction(() -> {
|
||||
Log.d(TAG, "Added widget of type " + Widget.TYPE_FORECAST + " with id " + input + ".");
|
||||
database.getAccessor().delete(Widget.TYPE_FORECAST, input);
|
||||
database.getAccessor().add(w);
|
||||
});
|
||||
return w;
|
||||
}, (input, result) -> {
|
||||
ForecastWidgetProvider provider = new ForecastWidgetProvider();
|
||||
provider.triggerUpdate(app, input, true);
|
||||
if (!activity.isDestroyed()) {
|
||||
activity.finish();
|
||||
try {
|
||||
if (!activity.isDestroyed()) {
|
||||
ForecastWidgetProvider provider = new ForecastWidgetProvider();
|
||||
provider.loadWidget(app, input);
|
||||
provider.triggerUpdate(app, input, true);
|
||||
PeriodicWidgetWorker.scheduleUpdates(app);
|
||||
Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, input);
|
||||
activity.setResult(Activity.RESULT_OK, resultValue);
|
||||
activity.finish();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Log.e(TAG, "Failed to update widget.", e);
|
||||
}
|
||||
});
|
||||
|
||||
PeriodicWidgetWorker.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);
|
||||
task.execute(getWidgetId(), ((IApp)activity.getApplicationContext()).getWidgetRepository().getDatabase());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -51,16 +51,16 @@ public class LoginFragment extends Fragment {
|
||||
NavOptions.Builder b = new NavOptions.Builder().setPopUpTo(R.id.destination_favorites, false);
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.destination_devices, null, b.build());
|
||||
break;
|
||||
case COLLECTION:
|
||||
case DRAWER:
|
||||
try {
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_login_collection);
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_login_drawer);
|
||||
} 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());
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_login_drawer, null, builder.build());
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
+28
-16
@@ -1,9 +1,7 @@
|
||||
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;
|
||||
@@ -17,13 +15,11 @@ 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;
|
||||
@@ -47,6 +43,11 @@ import java.util.List;
|
||||
*/
|
||||
public class MeasureWidgetFragment extends AbstractNetworkFragment {
|
||||
|
||||
/**
|
||||
* The log tag.
|
||||
*/
|
||||
private static final String TAG = "MeasureWidgetFragment";
|
||||
|
||||
/**
|
||||
* The bundle extra to store the widget id.
|
||||
*/
|
||||
@@ -139,7 +140,14 @@ public class MeasureWidgetFragment extends AbstractNetworkFragment {
|
||||
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());
|
||||
Activity activity = getActivity();
|
||||
if (c != null) {
|
||||
try {
|
||||
finish(activity, c, model.getCelsius().getValue(), model.getSi().getValue(), model.getColor().getValue());
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to finish.", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
model.getLogin().observe(getViewLifecycleOwner(), (v) -> {
|
||||
if (v) {
|
||||
@@ -195,13 +203,13 @@ public class MeasureWidgetFragment extends AbstractNetworkFragment {
|
||||
/**
|
||||
* Finishes the the configuration and stores the widget configuration in the database.
|
||||
*
|
||||
* @param activity The activity.
|
||||
* @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();
|
||||
public void finish(Activity activity, Device device, boolean celsius, boolean si, int color) {
|
||||
Context app = activity.getApplicationContext();
|
||||
DatabaseTask<WidgetDatabase, Integer, Widget> task = new DatabaseTask<>((input, database)-> {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -214,21 +222,25 @@ public class MeasureWidgetFragment extends AbstractNetworkFragment {
|
||||
w.setDataId(device.getId());
|
||||
w.setData(device);
|
||||
w.setDataTime(now);
|
||||
database.getAccessor().add(w);
|
||||
database.runInTransaction(() -> {
|
||||
database.getAccessor().delete(Widget.TYPE_MEASURE, input);
|
||||
database.getAccessor().add(w);
|
||||
Log.d(TAG, "Added widget of type " + Widget.TYPE_MEASURE + " with id " + input + ".");
|
||||
});
|
||||
return w;
|
||||
}, (input, result) -> {
|
||||
MeasureWidgetProvider provider = new MeasureWidgetProvider();
|
||||
provider.triggerUpdate(app, input, true);
|
||||
if (!activity.isDestroyed()) {
|
||||
MeasureWidgetProvider provider = new MeasureWidgetProvider();
|
||||
provider.loadWidget(app, input);
|
||||
provider.triggerUpdate(app, input, true);
|
||||
PeriodicWidgetWorker.scheduleUpdates(app);
|
||||
Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, input);
|
||||
activity.setResult(Activity.RESULT_OK, resultValue);
|
||||
activity.finish();
|
||||
}
|
||||
});
|
||||
PeriodicWidgetWorker.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);
|
||||
task.execute(getWidgetId(), ((IApp)activity.getApplicationContext()).getWidgetRepository().getDatabase());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,14 +8,9 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.mowesta.android.app.BuildConfig;
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.MowestaApp;
|
||||
import com.mowesta.android.app.MowestaService;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.database.FavoriteDatabase;
|
||||
import com.mowesta.android.app.repository.DeviceRepository;
|
||||
import com.mowesta.android.app.task.DatabaseTask;
|
||||
import com.mowesta.android.sdk.SdkRepository;
|
||||
import com.mowesta.android.sdk.task.ClearTask;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
@@ -24,9 +19,6 @@ import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
@@ -160,7 +152,6 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
bindReset();
|
||||
bindTerms();
|
||||
bindLicenses();
|
||||
bindSdkSettings();
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -239,7 +230,6 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
// there are no notification settings on older devices
|
||||
getPreferenceScreen().removePreference(category);
|
||||
} else {
|
||||
setClickListener(KEY_NOTIFICATION_APP, createNotificationSettingsListener(getActivity().getPackageName(), getString(R.string.mowesta_sdk_notification_channel_id)));
|
||||
setClickListener(KEY_NOTIFICATION_OS, createNotificationSettingsListener("android", "FOREGROUND_SERVICE"));
|
||||
}
|
||||
}
|
||||
@@ -353,20 +343,6 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds the sdk settings.
|
||||
*/
|
||||
private void bindSdkSettings() {
|
||||
setClickListener(KEY_DEVELOPMENT_CLEAR_CACHE, new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
new ClearTask(SdkRepository.getInstance(getActivity().getApplication()), false, () -> {
|
||||
Toast.makeText(preference.getContext(), R.string.setting_development_clear_message, Toast.LENGTH_SHORT).show();
|
||||
}).execute();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the developmentGroup mode.
|
||||
@@ -437,26 +413,13 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
// stop the service and its background processing
|
||||
Log.d(TAG, "Resetting the device.");
|
||||
Activity activity = getActivity();
|
||||
MowestaService.stopService(activity);
|
||||
// reset the settings
|
||||
MowestaApp app = (MowestaApp)activity.getApplication();
|
||||
SdkRepository sdk = SdkRepository.getInstance(app);
|
||||
MowestaSettings settings = app.getSettings();
|
||||
settings.setPrivacyMeasure(false);
|
||||
settings.setCollectionShown(false);
|
||||
app.getUserRepository().clearCredentials();
|
||||
app.getDeviceRepository().clearDevice();
|
||||
new ClearTask(sdk, true, ()-> {
|
||||
new DatabaseTask<FavoriteDatabase, Void, Void>
|
||||
((input, database)-> {
|
||||
Log.d(TAG, "Clearing database.");
|
||||
database.getAccessor().clearAll();
|
||||
return null;
|
||||
},(input, result)-> {
|
||||
Log.d(TAG, "Finishing the activity.");
|
||||
activity.finish();
|
||||
}).execute(null, app.getFavoriteRepository().getDatabase());
|
||||
}).execute();
|
||||
}
|
||||
});
|
||||
b.setNegativeButton(R.string.button_no, new DialogInterface.OnClickListener() {
|
||||
|
||||
@@ -45,8 +45,6 @@ public class SplashFragment extends Fragment {
|
||||
Navigation.findNavController(getView()).navigate(R.id.action_splash_terms);
|
||||
} else if (shouldShowLogin()) {
|
||||
Navigation.findNavController(getView()).navigate(R.id.action_splash_login);
|
||||
} else if (shouldShowCollection()) {
|
||||
Navigation.findNavController(getView()).navigate(R.id.action_splash_collection);
|
||||
} else {
|
||||
Navigation.findNavController(getView()).navigate(R.id.action_splash_drawer);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class StateFragment extends AbstractPlaceFragment {
|
||||
binding.setModel(model);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
AppBarConfiguration.Builder builder = new AppBarConfiguration.Builder();
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().onBackPressed(); return true; });
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().getOnBackPressedDispatcher().onBackPressed(); return true; });
|
||||
NavigationUI.setupWithNavController(layout, toolbar, controller, builder.build());
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class StationFragment extends AbstractDiagramFragment {
|
||||
binding.setModel(model);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
AppBarConfiguration.Builder builder = new AppBarConfiguration.Builder();
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().onBackPressed(); return true; });
|
||||
builder.setFallbackOnNavigateUpListener(() -> { getActivity().getOnBackPressedDispatcher().onBackPressed(); return true; });
|
||||
NavigationUI.setupWithNavController(layout, toolbar, controller, builder.build());
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -19,21 +19,23 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
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.ExoPlayer;
|
||||
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.StyledPlayerView;
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
|
||||
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.exoplayer.source.MediaSource;
|
||||
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
|
||||
import androidx.media3.ui.AspectRatioFrameLayout;
|
||||
import androidx.media3.ui.PlayerView;
|
||||
import androidx.media3.datasource.DefaultHttpDataSource;
|
||||
import androidx.media3.datasource.cache.CacheDataSource;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
@@ -186,7 +188,7 @@ public class VideoFragment extends AbstractNetworkFragment {
|
||||
/**
|
||||
* The player.
|
||||
*/
|
||||
private StyledPlayerView player;
|
||||
private PlayerView player;
|
||||
|
||||
/**
|
||||
* The weather video to compute the timings.
|
||||
@@ -231,12 +233,13 @@ public class VideoFragment extends AbstractNetworkFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
model = new ViewModelProvider(this).get(ExoPlayerViewModel.class);
|
||||
ImageButton zoomButton = view.findViewById(R.id.video_zoom);
|
||||
player = view.findViewById(R.id.video_view);
|
||||
player.setShowBuffering(StyledPlayerView.SHOW_BUFFERING_ALWAYS);
|
||||
player.setShowBuffering(PlayerView.SHOW_BUFFERING_ALWAYS);
|
||||
overlay = view.findViewById(R.id.video_time);
|
||||
View frame = LayoutInflater.from(view.getContext()).inflate(R.layout.view_marker, player.getOverlayFrameLayout(), true);
|
||||
marker = frame.findViewById(R.id.video_marker);
|
||||
@@ -346,6 +349,7 @@ public class VideoFragment extends AbstractNetworkFragment {
|
||||
* @param width The width.
|
||||
* @param height The height.
|
||||
*/
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
private void updateVideo(int width, int height) {
|
||||
model.scaler.setScreen(width, height);
|
||||
double scale = model.scaler.getScale();
|
||||
|
||||
@@ -2,15 +2,17 @@ package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
|
||||
import com.google.android.exoplayer2.upstream.AssetDataSource;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.exoplayer.source.MediaSource;
|
||||
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
|
||||
import androidx.media3.datasource.AssetDataSource;
|
||||
import androidx.media3.datasource.DataSource;
|
||||
|
||||
public class AdvertiseViewModel extends AndroidViewModel {
|
||||
|
||||
@@ -20,6 +22,7 @@ public class AdvertiseViewModel extends AndroidViewModel {
|
||||
|
||||
private MutableLiveData<Boolean> open = new MutableLiveData<>(Boolean.FALSE);
|
||||
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
public AdvertiseViewModel(Application app) {
|
||||
super(app);
|
||||
ExoPlayer.Builder builder = new ExoPlayer.Builder(app);
|
||||
|
||||
@@ -196,7 +196,7 @@ public class DeviceViewModel extends AbstractNetworkViewModel {
|
||||
|
||||
@Override
|
||||
public void loadInitial(@NonNull LoadInitialParams params, @NonNull LoadInitialCallback<DiagramEntry<Measurement>> callback) {
|
||||
ApiTask<Long, MeasurementPage> task = new ApiTask<>((id, client) -> { return client.getDeviceMeasurements(now, id, 0l, params.requestedStartPosition, params.requestedLoadSize ); },
|
||||
ApiTask<Long, MeasurementPage> task = new ApiTask<>((id, client) -> { return client.getDeviceMeasurements(id, 0L, now, params.requestedStartPosition, params.requestedLoadSize ); },
|
||||
(id, page) -> { completeRequest(requestCode, () -> callback.onResult(toEntries(page.getElements()), params.requestedStartPosition, page.getTotal())); },
|
||||
(id, status) -> { finishRequest(requestCode, true); });
|
||||
if (isCurrentRequest(requestCode)) {
|
||||
@@ -211,7 +211,7 @@ public class DeviceViewModel extends AbstractNetworkViewModel {
|
||||
|
||||
@Override
|
||||
public void loadRange(@NonNull LoadRangeParams params, @NonNull LoadRangeCallback<DiagramEntry<Measurement>> callback) {
|
||||
ApiTask<Long, MeasurementPage> task = new ApiTask<>((id, client) -> { return client.getDeviceMeasurements(now, id, 0l, params.startPosition, params.loadSize ); },
|
||||
ApiTask<Long, MeasurementPage> task = new ApiTask<>((id, client) -> { return client.getDeviceMeasurements(id, 0L, now, params.startPosition, params.loadSize ); },
|
||||
(id, page) -> { completeRequest(requestCode, () -> callback.onResult(toEntries(page.getElements()))); },
|
||||
(id, status) -> { finishRequest(requestCode, true); });
|
||||
if (id != null && credentials != null && isCurrentRequest(requestCode)) {
|
||||
|
||||
@@ -35,7 +35,7 @@ public class LoginViewModel extends AndroidViewModel {
|
||||
/**
|
||||
* Constants to model different destinations to go to.
|
||||
*/
|
||||
public enum Destination { DEVICES, COLLECTION};
|
||||
public enum Destination { DEVICES, DRAWER};
|
||||
|
||||
|
||||
/**
|
||||
@@ -123,7 +123,7 @@ public class LoginViewModel extends AndroidViewModel {
|
||||
getUserRepository().setCredentials(input);
|
||||
syncFavorites();
|
||||
}
|
||||
destination.setValue(Destination.COLLECTION);
|
||||
destination.setValue(Destination.DRAWER);
|
||||
}, (input, status) -> {
|
||||
checking.setValue(false);
|
||||
if (status == 403) {
|
||||
|
||||
@@ -201,7 +201,7 @@ public class StationViewModel extends AbstractNetworkViewModel {
|
||||
|
||||
@Override
|
||||
public void loadInitial(@NonNull LoadInitialParams params, @NonNull LoadInitialCallback<DiagramEntry<WeatherReport>> callback) {
|
||||
ApiTask<Long, WeatherReportPage> task = new ApiTask<>((id, client) -> { return client.getStationReports(now, id, 0l, params.requestedStartPosition, params.requestedLoadSize ); },
|
||||
ApiTask<Long, WeatherReportPage> task = new ApiTask<>((id, client) -> { return client.getStationReports(id, 0L, now, params.requestedStartPosition, params.requestedLoadSize ); },
|
||||
(id, page) -> { completeRequest(requestCode, () -> callback.onResult(toEntries(page.getElements()), params.requestedStartPosition, page.getTotal())); },
|
||||
(id, status) -> { finishRequest(requestCode, true); });
|
||||
if (id != null && isCurrentRequest(requestCode)) {
|
||||
@@ -212,7 +212,7 @@ public class StationViewModel extends AbstractNetworkViewModel {
|
||||
|
||||
@Override
|
||||
public void loadRange(@NonNull LoadRangeParams params, @NonNull LoadRangeCallback<DiagramEntry<WeatherReport>> callback) {
|
||||
ApiTask<Long, WeatherReportPage> task = new ApiTask<>((id, client) -> { return client.getStationReports(now, id, 0l, params.startPosition, params.loadSize ); },
|
||||
ApiTask<Long, WeatherReportPage> task = new ApiTask<>((id, client) -> { return client.getStationReports(id, 0l, now, params.startPosition, params.loadSize ); },
|
||||
(id, page) -> { completeRequest(requestCode, () -> callback.onResult(toEntries(page.getElements()))); },
|
||||
(id, status) -> { finishRequest(requestCode, true); });
|
||||
if (id != null && isCurrentRequest(requestCode)) {
|
||||
|
||||
@@ -117,7 +117,7 @@ public class ClientFactory {
|
||||
String p = credentials.getPassword();
|
||||
String user = l == null ? "" : l;
|
||||
String pass = p == null ? "" : p;
|
||||
return "Basic " + new String(Base64.encode((user + ":" + pass).getBytes(ISO_8859_1), 0), ASCII);
|
||||
return "Basic " + new String(Base64.encode((user + ":" + pass).getBytes(ISO_8859_1), Base64.NO_WRAP), ASCII);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.mowesta.android.app.task;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
/**
|
||||
* The base class for tasks. This is a drop in replacement for Android's async task,
|
||||
* which is now deprecated.
|
||||
*
|
||||
* @param <Result>
|
||||
*/
|
||||
public abstract class AbstractTask<Result> {
|
||||
|
||||
/**
|
||||
* The log tag of the task.
|
||||
*/
|
||||
private static final String TAG = "Task";
|
||||
|
||||
/**
|
||||
* The executor to execute a couple of tasks in parallel. We limit this to
|
||||
* 4 threads to avoid excessive sever loads.
|
||||
*/
|
||||
public static ExecutorService POOL_EXECUTOR = Executors.newFixedThreadPool(4);
|
||||
|
||||
/**
|
||||
* The executor used to run tasks sequentially. This is used to ensure that
|
||||
* tasks requiring a specific order will respect the scheduling order.
|
||||
*/
|
||||
public static ExecutorService SERIAL_EXECUTOR = Executors.newSingleThreadExecutor();
|
||||
|
||||
private static int counter = 0;
|
||||
|
||||
/**
|
||||
* A flag to indicate whether the execution will take place on the pooled
|
||||
* or on a serial executor.
|
||||
*/
|
||||
private final boolean pooled;
|
||||
|
||||
/**
|
||||
* The flag to determine whether the task is canceled.
|
||||
*/
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* A flag to prevent the duplicate task execution.
|
||||
*/
|
||||
private boolean executed;
|
||||
|
||||
/**
|
||||
* The handler to perform execution
|
||||
*/
|
||||
protected final Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/**
|
||||
* Creates a new task executed on a serial executor.
|
||||
*/
|
||||
public AbstractTask() {
|
||||
this.pooled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new task that is running on a serial executor (false
|
||||
* or thred pool executor (true).
|
||||
*
|
||||
* @param pooled True to run the task on a thread pool, false to
|
||||
* run it on a serial executor.
|
||||
*/
|
||||
public AbstractTask(boolean pooled) {
|
||||
this.pooled = pooled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the execution will take place on a pool (true)
|
||||
* or on a serial executor (false).
|
||||
*
|
||||
* @return True for pooled execution, false for serial execution.
|
||||
*/
|
||||
public boolean isPooled() {
|
||||
return pooled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the task on the executor.
|
||||
*/
|
||||
public void execute() {
|
||||
int c;
|
||||
synchronized (this) {
|
||||
counter += 1;
|
||||
c = counter;
|
||||
if (executed) throw new RuntimeException("Cannot execute task twice.");
|
||||
executed = true;
|
||||
}
|
||||
ExecutorService target = pooled?POOL_EXECUTOR:SERIAL_EXECUTOR;
|
||||
try {
|
||||
Log.v(TAG, "Schedule " + c + " (" + pooled + ")");
|
||||
target.execute(() -> {
|
||||
try {
|
||||
Log.v(TAG, "Running " + c);
|
||||
Result r = doInBackground();
|
||||
handler.post(() -> {
|
||||
try {
|
||||
onPostExecute(r);
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Unexpected exception while executing post execute.", e);
|
||||
}
|
||||
});
|
||||
Log.v(TAG, "Completed " + c);
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Unexpected exception while executing in background.", e);
|
||||
}
|
||||
});
|
||||
} catch (RejectedExecutionException e) {
|
||||
Log.d(TAG, "Scheduling of task failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the canceled flag on the task, if not set already and
|
||||
* notifies the monitor associated with this object.
|
||||
*/
|
||||
public void cancel() {
|
||||
synchronized (this) {
|
||||
cancelled = true;
|
||||
this.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the task is canceled.
|
||||
*
|
||||
* @return True to cancel.
|
||||
*/
|
||||
public boolean isCancelled() {
|
||||
synchronized (this) {
|
||||
return cancelled;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The method that will be called on a background thread.
|
||||
*
|
||||
* @return The result value.
|
||||
*/
|
||||
protected abstract Result doInBackground();
|
||||
|
||||
/**
|
||||
* The method that wil be called.
|
||||
*
|
||||
* @param result The result.
|
||||
*/
|
||||
protected void onPostExecute(Result result) { }
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.sdk.task.AbstractTask;
|
||||
|
||||
import feign.FeignException;
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ import android.annotation.SuppressLint;
|
||||
|
||||
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
|
||||
|
||||
@@ -8,8 +8,6 @@ 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;
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ 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;
|
||||
|
||||
@@ -7,7 +7,6 @@ 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.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ColoredSnackbar {
|
||||
*/
|
||||
public static Snackbar make(View view, CharSequence text, int duration) {
|
||||
Snackbar snackbar = Snackbar.make(view, text, duration);
|
||||
snackbar.getView().setBackgroundColor(getAttribute(view.getContext(), R.attr.colorAccent));
|
||||
snackbar.getView().setBackgroundColor(getAttribute(view.getContext(), androidx.appcompat.R.attr.colorAccent));
|
||||
List<View> views = new ArrayList<>();
|
||||
views.add(snackbar.getView());
|
||||
while (! views.isEmpty()) {
|
||||
|
||||
@@ -7,8 +7,10 @@ import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.database.Widget;
|
||||
import com.mowesta.android.app.database.WidgetAccessor;
|
||||
import com.mowesta.android.app.database.WidgetDatabase;
|
||||
@@ -143,11 +145,26 @@ public abstract class AbstractWidgetProvider extends AppWidgetProvider {
|
||||
if (widget != null) {
|
||||
Log.d(TAG, "Finish database query for widget " + input + ".");
|
||||
updateWidget(context, widget);
|
||||
} else {
|
||||
loadWidget(context, id);
|
||||
}
|
||||
});
|
||||
task.execute(id, getWidgetDatabase(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a remote view that shows that the widget is loading.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param id The id.
|
||||
*/
|
||||
public void loadWidget(Context context, int id) {
|
||||
Log.d(TAG, "Building loading view for widget " + id + ".");
|
||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_loading);
|
||||
appWidgetManager.updateAppWidget(id, views);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the widget dimensions for the app widget. If the options
|
||||
* cannot be retrieved, the width and height will be 0.
|
||||
@@ -166,6 +183,9 @@ public abstract class AbstractWidgetProvider extends AppWidgetProvider {
|
||||
int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, 0);
|
||||
int maxHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, 0);
|
||||
Log.d(TAG, String.format("Widget %d: Width(%d-%d) Height(%d-%d)", id, minWidth, maxWidth, minHeight, maxHeight));
|
||||
if (maxWidth == 0 && maxHeight == 0) {
|
||||
return new int[] { 100, 100 };
|
||||
}
|
||||
if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
return new int[] { minWidth, maxHeight };
|
||||
} else {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mowesta.android.app.widget;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@@ -41,4 +42,9 @@ public class ForecastWidgetActivity extends AppCompatActivity {
|
||||
setResult(RESULT_CANCELED, resultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
Log.d("ForecastWidgetActivity", "onStop");
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -6,7 +6,9 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
@@ -119,7 +121,9 @@ public class ForecastWidgetProvider extends AbstractWidgetProvider {
|
||||
views.setTextViewText(R.id.widget_condition_temperature, UnitUtils.toSpanned(UnitUtils.getTemperature(context, condition.getTemperature(), unit)));
|
||||
}
|
||||
}
|
||||
float scale = context.getResources().getDisplayMetrics().scaledDensity / context.getResources().getDisplayMetrics().density;
|
||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||
float scaledDensity = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, dm);
|
||||
float scale = scaledDensity / dm.density;
|
||||
Log.d(TAG, "Building remote views done.");
|
||||
int[] widgetDimension = getWidgetDimensions(context, widget.getReference());
|
||||
int width = widgetDimension[0];
|
||||
|
||||
@@ -5,9 +5,12 @@ import android.appwidget.AppWidgetManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spanned;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import androidx.navigation.NavDeepLinkBuilder;
|
||||
@@ -68,7 +71,11 @@ public class MeasureWidgetProvider extends AbstractWidgetProvider {
|
||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||
MowestaSettings.TemperatureUnit unit = widget.isCelsius()?MowestaSettings.TemperatureUnit.CELSIUS:MowestaSettings.TemperatureUnit.FAHRENHEIT;
|
||||
MowestaSettings.UnitSystem system = widget.isSi()?MowestaSettings.UnitSystem.STANDARD:MowestaSettings.UnitSystem.IMPERIAL;
|
||||
float scale = context.getResources().getDisplayMetrics().scaledDensity / context.getResources().getDisplayMetrics().density;
|
||||
|
||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||
float scaledDensity = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, dm);
|
||||
float scale = scaledDensity / dm.density;
|
||||
|
||||
int[] widgetDimension = getWidgetDimensions(context, widget.getReference());
|
||||
int width = widgetDimension[0];
|
||||
int height = widgetDimension[1];
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.mowesta.android.feign.model.MeasurementPage;
|
||||
import com.mowesta.android.feign.model.WeatherForecast;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* A worker that updates a widget. The widget reference
|
||||
@@ -81,12 +80,16 @@ public class OnetimeWidgetWorker extends Worker {
|
||||
|
||||
public static void updateWidget(Context context, int type, int reference) {
|
||||
Log.d(TAG, "Scheduling update for widget " + type + " " + reference + ".");
|
||||
WorkManager workManager = WorkManager.getInstance(context);
|
||||
OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(OnetimeWidgetWorker.class);
|
||||
builder.setInputData(OnetimeWidgetWorker.createData(type, reference));
|
||||
builder.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST);
|
||||
OneTimeWorkRequest request = builder.build();
|
||||
workManager.beginWith(request).enqueue();
|
||||
try {
|
||||
WorkManager workManager = WorkManager.getInstance(context);
|
||||
OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(OnetimeWidgetWorker.class);
|
||||
builder.setInputData(OnetimeWidgetWorker.createData(type, reference));
|
||||
builder.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST);
|
||||
OneTimeWorkRequest request = builder.build();
|
||||
workManager.beginWith(request).enqueue();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to schedule update for widget " + type + " " + reference + ".", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,94 +108,99 @@ public class OnetimeWidgetWorker extends Worker {
|
||||
|
||||
@Override
|
||||
public Result doWork() {
|
||||
Log.d(TAG, "Performing update for widget " + type + " " + reference + ".");
|
||||
if (type == Widget.TYPE_INVALID || reference == AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
Log.d(TAG, "Received an invalid request for type " + type + " and reference " + reference + ".");
|
||||
return Result.success();
|
||||
}
|
||||
WidgetDatabase database = app.getWidgetRepository().getDatabase();
|
||||
WidgetAccessor accessor = database.getAccessor();
|
||||
List<Widget> widgets = accessor.get(type, reference);
|
||||
if (widgets.isEmpty()) {
|
||||
Log.d(TAG, "Received a request for removed widget with type " + type + " and reference " + reference + ".");
|
||||
return Result.success();
|
||||
}
|
||||
Widget widget = widgets.get(0);
|
||||
if (type == Widget.TYPE_FORECAST) {
|
||||
try {
|
||||
DefaultApi api = app.getClientFactory().createClient();
|
||||
long time = System.currentTimeMillis();
|
||||
City[] city = new City[] { widget.getData(City.class) };
|
||||
long[] dataTime = new long[] { widget.getDataTime() };
|
||||
if (city[0] == null || time - dataTime[0] > DELAY_DATA) {
|
||||
city[0] = api.getCity(widget.getDataId());
|
||||
dataTime[0] = time;
|
||||
}
|
||||
WeatherForecast[] content = new WeatherForecast[] { widget.getContent(WeatherForecast.class) };
|
||||
long[] contentTime = new long[] { widget.getContentTime() };
|
||||
if (content[0] == null || time - contentTime[0] > DELAY_CONTENT) {
|
||||
content[0] = api.getCityForecast(widget.getDataId());
|
||||
contentTime[0] = time;
|
||||
}
|
||||
database.runInTransaction(() -> {
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w == null) return;
|
||||
w.setDataTime(dataTime[0]);
|
||||
w.setData(city[0]);
|
||||
w.setContentTime(contentTime[0]);
|
||||
w.setContent(content[0]);
|
||||
accessor.update(w);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to update widget state with type " + type + " and reference " + reference + ".", e);
|
||||
try {
|
||||
Log.d(TAG, "Performing update for widget " + type + " " + reference + ".");
|
||||
if (type == Widget.TYPE_INVALID || reference == AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
Log.d(TAG, "Received an invalid request for type " + type + " and reference " + reference + ".");
|
||||
return Result.success();
|
||||
}
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w != null) {
|
||||
handler.post(()-> {
|
||||
ForecastWidgetProvider provider = new ForecastWidgetProvider();
|
||||
provider.updateWidget(app.getContext(), w);
|
||||
});
|
||||
WidgetDatabase database = app.getWidgetRepository().getDatabase();
|
||||
WidgetAccessor accessor = database.getAccessor();
|
||||
List<Widget> widgets = accessor.get(type, reference);
|
||||
if (widgets.isEmpty()) {
|
||||
Log.d(TAG, "Received a request for removed widget with type " + type + " and reference " + reference + ".");
|
||||
return Result.success();
|
||||
}
|
||||
} else if (type == Widget.TYPE_MEASURE) {
|
||||
try {
|
||||
DefaultApi api = app.getClientFactory().createClient(app.getUserRepository().getCredentials().getValue());
|
||||
long time = System.currentTimeMillis();
|
||||
Device[] device = new Device[] { widget.getData(Device.class) };
|
||||
long[] dataTime = new long[] { widget.getDataTime() };
|
||||
if (device[0] == null || time - dataTime[0] > DELAY_DATA) {
|
||||
device[0] = api.getDevice(widget.getDataId());
|
||||
dataTime[0] = time;
|
||||
}
|
||||
Measurement[] content = new Measurement[] { widget.getContent(Measurement.class) };
|
||||
long[] contentTime = new long[] { widget.getContentTime() };
|
||||
if (content[0] == null || time - contentTime[0] > DELAY_CONTENT) {
|
||||
MeasurementPage page = api.getDeviceMeasurements(time, widget.getDataId(), 0l, 0, 1);
|
||||
if (page.getElements().size() > 0) {
|
||||
content[0] = page.getElements().get(0);
|
||||
Widget widget = widgets.get(0);
|
||||
if (type == Widget.TYPE_FORECAST) {
|
||||
try {
|
||||
DefaultApi api = app.getClientFactory().createClient();
|
||||
long time = System.currentTimeMillis();
|
||||
City[] city = new City[] { widget.getData(City.class) };
|
||||
long[] dataTime = new long[] { widget.getDataTime() };
|
||||
if (city[0] == null || time - dataTime[0] > DELAY_DATA) {
|
||||
city[0] = api.getCity(widget.getDataId());
|
||||
dataTime[0] = time;
|
||||
}
|
||||
WeatherForecast[] content = new WeatherForecast[] { widget.getContent(WeatherForecast.class) };
|
||||
long[] contentTime = new long[] { widget.getContentTime() };
|
||||
if (content[0] == null || time - contentTime[0] > DELAY_CONTENT) {
|
||||
content[0] = api.getCityForecast(widget.getDataId());
|
||||
contentTime[0] = time;
|
||||
}
|
||||
database.runInTransaction(() -> {
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w == null) return;
|
||||
w.setDataTime(dataTime[0]);
|
||||
w.setData(city[0]);
|
||||
w.setContentTime(contentTime[0]);
|
||||
w.setContent(content[0]);
|
||||
accessor.update(w);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to update widget state with type " + type + " and reference " + reference + ".", e);
|
||||
}
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w != null) {
|
||||
handler.post(()-> {
|
||||
ForecastWidgetProvider provider = new ForecastWidgetProvider();
|
||||
provider.updateWidget(app.getContext(), w);
|
||||
});
|
||||
}
|
||||
} else if (type == Widget.TYPE_MEASURE) {
|
||||
try {
|
||||
DefaultApi api = app.getClientFactory().createClient(app.getUserRepository().getCredentials().getValue());
|
||||
long time = System.currentTimeMillis();
|
||||
Device[] device = new Device[] { widget.getData(Device.class) };
|
||||
long[] dataTime = new long[] { widget.getDataTime() };
|
||||
if (device[0] == null || time - dataTime[0] > DELAY_DATA) {
|
||||
device[0] = api.getDevice(widget.getDataId());
|
||||
dataTime[0] = time;
|
||||
}
|
||||
Measurement[] content = new Measurement[] { widget.getContent(Measurement.class) };
|
||||
long[] contentTime = new long[] { widget.getContentTime() };
|
||||
if (content[0] == null || time - contentTime[0] > DELAY_CONTENT) {
|
||||
MeasurementPage page = api.getDeviceMeasurements(widget.getDataId(), 0L, time, 0, 1);
|
||||
if (page.getElements().size() > 0) {
|
||||
content[0] = page.getElements().get(0);
|
||||
contentTime[0] = time;
|
||||
}
|
||||
}
|
||||
database.runInTransaction(() -> {
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w == null) return;
|
||||
w.setDataTime(dataTime[0]);
|
||||
w.setData(device[0]);
|
||||
w.setContentTime(contentTime[0]);
|
||||
w.setContent(content[0]);
|
||||
accessor.update(w);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to update widget state with type " + type + " and reference " + reference + ".", e);
|
||||
}
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w != null) {
|
||||
handler.post(()-> {
|
||||
MeasureWidgetProvider provider = new MeasureWidgetProvider();
|
||||
provider.updateWidget(app.getContext(), w);
|
||||
});
|
||||
}
|
||||
database.runInTransaction(() -> {
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w == null) return;
|
||||
w.setDataTime(dataTime[0]);
|
||||
w.setData(device[0]);
|
||||
w.setContentTime(contentTime[0]);
|
||||
w.setContent(content[0]);
|
||||
accessor.update(w);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to update widget state with type " + type + " and reference " + reference + ".", e);
|
||||
}
|
||||
Widget w = accessor.get(widget.getId());
|
||||
if (w != null) {
|
||||
handler.post(()-> {
|
||||
MeasureWidgetProvider provider = new MeasureWidgetProvider();
|
||||
provider.updateWidget(app.getContext(), w);
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Failed to perform background update.", e);
|
||||
}
|
||||
// Indicate whether the work finished successfully with the Result
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
tools:context=".MowestaActivity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="false"
|
||||
android:id="@+id/layout_coordinator">
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/layout_coordinator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
@@ -10,4 +12,4 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -60,7 +60,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="180dp">
|
||||
|
||||
<com.google.android.exoplayer2.ui.StyledPlayerView
|
||||
<androidx.media3.ui.PlayerView
|
||||
android:id="@+id/video_view"
|
||||
android:layout_alignParentBottom="true"
|
||||
app:use_controller="false"
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@color/primary"
|
||||
app:itemIconTint="@drawable/selector_navigation"
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:inputType="text"
|
||||
android:hint="@string/action_search"
|
||||
android:text="@={model.term}" />
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
<com.google.android.exoplayer2.ui.StyledPlayerView
|
||||
<androidx.media3.ui.PlayerView
|
||||
android:id="@+id/video_view"
|
||||
android:layout_centerInParent="true"
|
||||
app:resize_mode="zoom"
|
||||
|
||||
@@ -7,14 +7,17 @@
|
||||
android:id="@+id/layout_appbar"
|
||||
android:theme="@style/ThemeOverlay.MaterialComponents.Dark"
|
||||
app:liftOnScroll="true"
|
||||
android:fitsSystemWindows="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="128dp">
|
||||
android:layout_height="@dimen/appbar_height">
|
||||
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:id="@+id/layout_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
app:contentScrim="?attr/colorPrimary"
|
||||
app:statusBarScrim="?attr/colorPrimary"
|
||||
app:collapsedTitleTextAppearance="@style/TextAppearance.Mowesta.AppBar.Collapsed"
|
||||
app:expandedTitleTextAppearance="@style/TextAppearance.Mowesta.AppBar.Expanded"
|
||||
app:expandedTitleMarginStart="40dp"
|
||||
@@ -29,6 +32,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="8dp"
|
||||
android:fitsSystemWindows="true"
|
||||
app:srcCompat="@drawable/icon_launch_sun"
|
||||
android:scaleType="fitEnd"
|
||||
app:layout_collapseMode="parallax" />
|
||||
|
||||
@@ -5,14 +5,17 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:theme="@style/ThemeOverlay.MaterialComponents.Dark"
|
||||
android:id="@+id/layout_appbar"
|
||||
android:fitsSystemWindows="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="128dp">
|
||||
android:layout_height="@dimen/appbar_height">
|
||||
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:id="@+id/layout_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
app:contentScrim="?attr/colorPrimary"
|
||||
app:statusBarScrim="?attr/colorPrimary"
|
||||
app:collapsedTitleTextAppearance="@style/TextAppearance.Mowesta.AppBar.Collapsed"
|
||||
app:expandedTitleTextAppearance="@style/TextAppearance.Mowesta.AppBar.Expanded"
|
||||
app:expandedTitleMarginStart="40dp"
|
||||
@@ -24,7 +27,8 @@
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
<com.locoslab.android.leafless.MapView
|
||||
android:id="@+id/map"
|
||||
android:layout_centerInParent="true"
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/widget_measure"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
tools:layout_width="110dp"
|
||||
tools:layout_height="40dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_device_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/white"
|
||||
android:shadowColor="@color/black"
|
||||
android:paddingStart="1dp"
|
||||
android:paddingEnd="1dp"
|
||||
android:textStyle="bold"
|
||||
android:shadowRadius="3"
|
||||
android:shadowDx="1"
|
||||
android:shadowDy="1"
|
||||
android:textSize="12sp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="@string/widget_loading" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -33,12 +33,12 @@
|
||||
app:exitAnim="@anim/slide_out_left"
|
||||
app:destination="@id/destination_login" />
|
||||
<action
|
||||
android:id="@+id/action_splash_collection"
|
||||
android:id="@+id/action_splash_core"
|
||||
app:popUpTo="@id/destination_splash"
|
||||
app:popUpToInclusive="true"
|
||||
app:enterAnim="@anim/slide_in_right"
|
||||
app:exitAnim="@anim/slide_out_left"
|
||||
app:destination="@id/destination_collection" />
|
||||
app:destination="@id/navigation_core" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/destination_terms"
|
||||
@@ -66,24 +66,11 @@
|
||||
android:label="@string/navigation_login"
|
||||
tools:layout="@layout/fragment_login">
|
||||
<action
|
||||
android:id="@+id/action_login_collection"
|
||||
android:id="@+id/action_login_drawer"
|
||||
app:popUpTo="@id/destination_login"
|
||||
app:popUpToInclusive="true"
|
||||
app:enterAnim="@anim/slide_in_right"
|
||||
app:exitAnim="@anim/slide_out_left"
|
||||
app:destination="@id/destination_collection" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/destination_collection"
|
||||
android:name="com.mowesta.android.app.fragment.CollectionFragment"
|
||||
android:label="@string/navigation_login"
|
||||
tools:layout="@layout/fragment_login">
|
||||
<action
|
||||
android:id="@+id/action_collection_drawer"
|
||||
app:popUpTo="@id/destination_collection"
|
||||
app:popUpToInclusive="true"
|
||||
app:enterAnim="@anim/slide_in_right"
|
||||
app:exitAnim="@anim/slide_out_left"
|
||||
app:destination="@id/navigation_core" />
|
||||
</fragment>
|
||||
|
||||
|
||||
@@ -313,6 +313,7 @@
|
||||
<string name="widget_measure_time">Uhrzeit</string>
|
||||
<string name="widget_measure_date">Datum</string>
|
||||
<string name="widget_measure_explain">Um die Messungen Deiner Geräte auf Deinem Startbildschirm anzeigen zu können, musst Du Dich leider erst mit Deinem Konto anmelden.</string>
|
||||
<string name="widget_loading">Lädt…</string>
|
||||
|
||||
<string name="color_dialog_open">Farbe anpassen</string>
|
||||
<string name="color_dialog_example">Beispiel</string>
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
<dimen name="space_medium">8dp</dimen>
|
||||
<dimen name="max_font_headline">34sp</dimen>
|
||||
<dimen name="min_font_headline">18sp</dimen>
|
||||
<dimen name="appbar_height">176dp</dimen>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -318,6 +318,7 @@
|
||||
<string name="widget_measure_time">Time</string>
|
||||
<string name="widget_measure_date">Date</string>
|
||||
<string name="widget_measure_explain">To display the measurements of your devices on your home screen, you have to set up your account.</string>
|
||||
<string name="widget_loading">Loading…</string>
|
||||
|
||||
<string name="color_dialog_open">Adjust color</string>
|
||||
<string name="color_dialog_example">Example</string>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<resources>
|
||||
<style name="Theme.Mowesta" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="colorPrimary">@color/primary</item>
|
||||
<item name="colorPrimaryDark">@color/primaryDark</item>
|
||||
<item name="colorAccent">@color/accent</item>
|
||||
<item name="android:navigationBarColor" tools:targetApi="21">@color/primary</item>
|
||||
<item name="android:navigationBarColor" >@color/primary</item>
|
||||
<item name="fontFamily">@font/text</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
</style>
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
<style name="TextAppearance.Mowesta.TabLayout" parent="TextAppearance.MaterialComponents.Button">
|
||||
<item name="android:letterSpacing" tools:targetApi="21">0</item>
|
||||
<item name="android:letterSpacing">0</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<PreferenceCategory android:title="@string/setting_category_privacy" >
|
||||
<CheckBoxPreference
|
||||
android:icon="@drawable/ic_ac_unit_normal_24"
|
||||
android:key="privacy_measure"
|
||||
android:defaultValue="@bool/privacy_measure_default"
|
||||
android:summary="@string/setting_privacy_measure_summary"
|
||||
android:title="@string/setting_privacy_measure_title" />
|
||||
<Preference
|
||||
android:icon="@drawable/ic_delete_forever_normal_24"
|
||||
android:key="privacy_reset"
|
||||
@@ -21,11 +15,6 @@
|
||||
android:key="notification_app"
|
||||
android:summary="@string/setting_notification_app_summary"
|
||||
android:title="@string/setting_notification_app_title" />
|
||||
<Preference
|
||||
android:icon="@drawable/ic_android_normal_24"
|
||||
android:key="notification_os"
|
||||
android:summary="@string/setting_notification_os_summary"
|
||||
android:title="@string/setting_notification_os_title" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/setting_category_about" >
|
||||
@@ -66,24 +55,6 @@
|
||||
android:key="development_clear_cache"
|
||||
android:title="@string/setting_development_clear_title"
|
||||
android:summary="@string/setting_development_clear_summary"/>
|
||||
<CheckBoxPreference
|
||||
android:icon="@drawable/ic_storage_normal_24"
|
||||
android:key="mowesta_sdk_use_cache"
|
||||
android:defaultValue="@bool/mowesta_sdk_use_cache_default"
|
||||
android:summary="@string/setting_development_cache_summary"
|
||||
android:title="@string/setting_development_cache_title" />
|
||||
<CheckBoxPreference
|
||||
android:icon="@drawable/ic_gps_fixed_normal_24"
|
||||
android:key="mowesta_sdk_use_gps"
|
||||
android:defaultValue="@bool/mowesta_sdk_use_gps_default"
|
||||
android:summary="@string/setting_development_gps_summary"
|
||||
android:title="@string/setting_development_gps_title" />
|
||||
<CheckBoxPreference
|
||||
android:icon="@drawable/ic_wifi_normal_24"
|
||||
android:key="mowesta_sdk_use_network"
|
||||
android:defaultValue="@bool/mowesta_sdk_use_network_default"
|
||||
android:summary="@string/setting_development_net_summary"
|
||||
android:title="@string/setting_development_net_title" />
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
|
||||
android:minWidth="250dp"
|
||||
android:minHeight="80dp"
|
||||
android:minResizeHeight="40dp"
|
||||
@@ -9,5 +9,7 @@
|
||||
android:widgetCategory="home_screen"
|
||||
android:configure="com.mowesta.android.app.widget.ForecastWidgetActivity"
|
||||
android:initialLayout="@layout/widget_forecast"
|
||||
tools:targetApi="28"
|
||||
android:widgetFeatures="reconfigurable"
|
||||
android:updatePeriodMillis="43200000">
|
||||
</appwidget-provider>
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
|
||||
android:minWidth="110dp"
|
||||
android:minHeight="110dp"
|
||||
android:minResizeWidth="110dp"
|
||||
@@ -9,5 +9,7 @@
|
||||
android:widgetCategory="home_screen"
|
||||
android:configure="com.mowesta.android.app.widget.MeasureWidgetActivity"
|
||||
android:initialLayout="@layout/widget_measure"
|
||||
tools:targetApi="28"
|
||||
android:widgetFeatures="reconfigurable"
|
||||
android:updatePeriodMillis="43200000">
|
||||
</appwidget-provider>
|
||||
@@ -10,17 +10,19 @@ description = "MoWeSta Android SDK"
|
||||
project.version = "unspecified"
|
||||
|
||||
android {
|
||||
compileSdkVersion 33
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 33
|
||||
minSdkVersion 24
|
||||
compileSdk 35
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
}
|
||||
|
||||
testOptions.unitTests.includeAndroidResources = true
|
||||
testOptions {
|
||||
targetSdk 35
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
@@ -30,6 +32,7 @@ android {
|
||||
}
|
||||
lint {
|
||||
quiet true
|
||||
targetSdk 35
|
||||
}
|
||||
namespace 'com.mowesta.android.sdk'
|
||||
|
||||
@@ -47,6 +50,7 @@ dependencies {
|
||||
testImplementation "junit:junit:${versionJunit}"
|
||||
testImplementation "org.robolectric:robolectric:${versionRobolectric}"
|
||||
testImplementation "androidx.test:core:${versionAndroidXTest}"
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.mowesta.android.sdk.util.CapabilityManager;
|
||||
import com.mowesta.android.sdk.util.ChannelManager;
|
||||
import com.mowesta.android.sdk.task.UploadTask;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
@@ -29,6 +30,7 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
@@ -43,6 +45,8 @@ import android.os.SystemClock;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.ServiceCompat;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
import android.util.Log;
|
||||
@@ -112,7 +116,6 @@ public abstract class SdkService extends Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
}
|
||||
|
||||
@@ -238,7 +241,8 @@ public abstract class SdkService extends Service {
|
||||
super.onCreate();
|
||||
channelManager = new ChannelManager(getApplication());
|
||||
channelManager.createChannel();
|
||||
startForeground(channelManager.getNotificationId(), channelManager.createNotification(R.string.mowesta_sdk_notification_content_idle));
|
||||
int foregroundType = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ? ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION: 8;
|
||||
ServiceCompat.startForeground(this, channelManager.getNotificationId(), channelManager.createNotification(R.string.mowesta_sdk_notification_content_idle), foregroundType);
|
||||
repository = SdkRepository.getInstance(this.getApplication());
|
||||
capabilityManager = new CapabilityManager(getApplication());
|
||||
repository.getUploading().observeForever(uploadListener);
|
||||
@@ -545,7 +549,6 @@ public abstract class SdkService extends Service {
|
||||
/**
|
||||
* Starts a wifi scan.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void startWifi() {
|
||||
Log.d(TAG, "Acquiring wifi lock.");
|
||||
debugLog("Acquiring wifi lock");
|
||||
|
||||
+27
-22
@@ -3,12 +3,15 @@ import java.util.concurrent.locks.ReentrantLock
|
||||
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.3.1'
|
||||
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.4'
|
||||
classpath 'com.android.tools.build:gradle:9.5.1'
|
||||
classpath 'com.google.android.gms:oss-licenses-plugin:0.13.0'
|
||||
classpath 'org.handte.gradle:gradle-android-eclipse:1.0.0'
|
||||
classpath "gradle.plugin.org.openbakery:plugin:0.21.0"
|
||||
classpath "org.openbakery:xcode-plugin:0.24.+"
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
url('https://openbakery.org/repository/')
|
||||
}
|
||||
maven {
|
||||
url = 'https://project.nes.uni-due.de/nexus/repository/maven-public';
|
||||
credentials { username = 'public'; password = 'public' }
|
||||
@@ -17,26 +20,17 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
plugins.withType(JavaPlugin) {
|
||||
afterEvaluate {
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(17)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
// set version for our project
|
||||
group = 'com.mowesta'
|
||||
version = '1.1.2'
|
||||
version = '1.1.3-SNAPSHOT'
|
||||
|
||||
// set versions for our libraries
|
||||
ext {
|
||||
// api dependencies
|
||||
versionJavaee = '10.0.0'
|
||||
versionJaxb = '4.0.1'
|
||||
versionJaxb = '4.0.5'
|
||||
versionAnnotation = '1.3.2'
|
||||
versionSwagger = '2.2.16'
|
||||
versionGeojson = '1.8.1'
|
||||
@@ -59,15 +53,15 @@ allprojects {
|
||||
versionPostgres = '42.7.1'
|
||||
versionMapstruct = '1.5.5.Final'
|
||||
// shared android dependencies
|
||||
versionAndroidXTest = '1.4.0'
|
||||
versionAndroidXAppcompat = '1.5.1'
|
||||
versionAndroidXRoom = '2.4.3'
|
||||
versionAndroidXPreference = '1.2.0'
|
||||
versionRobolectric = '4.9'
|
||||
versionAndroidXTest = '1.7.0'
|
||||
versionAndroidXAppcompat = '1.8.0'
|
||||
versionAndroidXRoom = '2.6.1'
|
||||
versionAndroidXPreference = '1.2.1'
|
||||
versionRobolectric = '4.14.1'
|
||||
// locoslab libraries and code
|
||||
versionGeometry = '1.4.0'
|
||||
versionCarta = '1.3.0'
|
||||
versionGrib2 = '1.0.0'
|
||||
versionGrib2 = '1.0.2'
|
||||
versionAuth = '1.1.0'
|
||||
// tools
|
||||
versionCli = '1.4'
|
||||
@@ -77,7 +71,18 @@ allprojects {
|
||||
subprojects {
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'eclipse'
|
||||
|
||||
|
||||
plugins.withType(JavaPlugin) {
|
||||
afterEvaluate {
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (name.equals('android-app')) {
|
||||
// custom apk configuration
|
||||
publishing {
|
||||
@@ -114,7 +119,7 @@ subprojects {
|
||||
apply plugin: 'java-library'
|
||||
|
||||
task sourcesJar(type: Jar) {
|
||||
classifier = 'sources'
|
||||
archiveClassifier = 'sources'
|
||||
from(sourceSets.main.allJava)
|
||||
}
|
||||
|
||||
|
||||
+13
-2
@@ -1,4 +1,15 @@
|
||||
android.enableJetifier=true
|
||||
android.javaCompile.suppressSourceTargetDeprecationWarning=true
|
||||
android.enableJetifier=false
|
||||
android.useAndroidX=true
|
||||
org.gradle.jvmargs=-Xmx4g
|
||||
org.gradle.jvmargs=-Xmx8g
|
||||
org.gradle.parallel=true
|
||||
|
||||
# Enabled parallel sync for Gradle 9.4+
|
||||
org.gradle.tooling.parallel=true
|
||||
android.defaults.buildfeatures.resvalues=true
|
||||
android.enableAppCompileTimeRClass=false
|
||||
android.uniquePackageNames=false
|
||||
android.r8.strictFullModeForKeepRules=false
|
||||
android.r8.optimizedResourceShrinking=false
|
||||
android.builtInKotlin=false
|
||||
android.newDsl=false
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#Mon May 23 12:33:06 CEST 2022
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.0-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -444,7 +444,7 @@
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastSwiftUpdateCheck = 1340;
|
||||
LastUpgradeCheck = 1340;
|
||||
LastUpgradeCheck = 1620;
|
||||
TargetAttributes = {
|
||||
2C163306283A27D300F78CEE = {
|
||||
CreatedOnToolsVersion = 13.4;
|
||||
@@ -658,6 +658,7 @@
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
@@ -719,6 +720,7 @@
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
@@ -744,7 +746,7 @@
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
CURRENT_PROJECT_VERSION = 6;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"App/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = 2KS4Z77UGE;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
@@ -759,12 +761,12 @@
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.3;
|
||||
MARKETING_VERSION = 1.4;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.mowesta.app;
|
||||
PRODUCT_NAME = MoWeSta;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
@@ -780,7 +782,7 @@
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
CURRENT_PROJECT_VERSION = 6;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"App/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = 2KS4Z77UGE;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
@@ -795,12 +797,12 @@
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 14.1;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.3;
|
||||
MARKETING_VERSION = 1.4;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.mowesta.app;
|
||||
PRODUCT_NAME = MoWeSta;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
@@ -812,7 +814,6 @@
|
||||
2C163334283A27D600F78CEE /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
@@ -832,7 +833,6 @@
|
||||
2C163335283A27D600F78CEE /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
@@ -852,7 +852,6 @@
|
||||
2C163337283A27D600F78CEE /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_TEAM = 2KS4Z77UGE;
|
||||
@@ -870,7 +869,6 @@
|
||||
2C163338283A27D600F78CEE /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_TEAM = 2KS4Z77UGE;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1340"
|
||||
LastUpgradeVersion = "1620"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -17,7 +17,7 @@
|
||||
BlueprintIdentifier = "2C163306283A27D300F78CEE"
|
||||
BuildableName = "MoWeSta.app"
|
||||
BlueprintName = "App"
|
||||
ReferencedContainer = "container:App.xcodeproj">
|
||||
ReferencedContainer = "container:app.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
@@ -35,7 +35,7 @@
|
||||
BlueprintIdentifier = "2C16331B283A27D600F78CEE"
|
||||
BuildableName = "AppTests.xctest"
|
||||
BlueprintName = "AppTests"
|
||||
ReferencedContainer = "container:App.xcodeproj">
|
||||
ReferencedContainer = "container:app.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
<TestableReference
|
||||
@@ -45,7 +45,7 @@
|
||||
BlueprintIdentifier = "2C163325283A27D600F78CEE"
|
||||
BuildableName = "AppUITests.xctest"
|
||||
BlueprintName = "AppUITests"
|
||||
ReferencedContainer = "container:App.xcodeproj">
|
||||
ReferencedContainer = "container:app.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
@@ -67,7 +67,7 @@
|
||||
BlueprintIdentifier = "2C163306283A27D300F78CEE"
|
||||
BuildableName = "MoWeSta.app"
|
||||
BlueprintName = "App"
|
||||
ReferencedContainer = "container:App.xcodeproj">
|
||||
ReferencedContainer = "container:app.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
@@ -84,7 +84,7 @@
|
||||
BlueprintIdentifier = "2C163306283A27D300F78CEE"
|
||||
BuildableName = "MoWeSta.app"
|
||||
BlueprintName = "App"
|
||||
ReferencedContainer = "container:App.xcodeproj">
|
||||
ReferencedContainer = "container:app.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
|
||||
@@ -99,7 +99,8 @@ public class AppState: ObservableObject {
|
||||
|
||||
private init() {
|
||||
self.keyChain = KeyChain(server: "www.mowesta.com")
|
||||
updateUrl()
|
||||
UserDefaults.standard.register(defaults: ["accountUrl": "https://www.mowesta.com/api/"])
|
||||
updateUrl()
|
||||
if let data = UserDefaults.standard.object(forKey: "device") as? Data,
|
||||
let value = try? JSONDecoder().decode(Device.self, from: data) {
|
||||
loadedDevice = value
|
||||
|
||||
@@ -121,6 +121,7 @@ struct GradientView: View {
|
||||
.frame(width: proxy.size.width, height: scaledSize)
|
||||
.background(linearGradient[i])
|
||||
.offset(x: 0, y: scaledOffset)
|
||||
.id(pivot)
|
||||
}
|
||||
}
|
||||
.frame(width: proxy.size.width, height: size)
|
||||
@@ -143,6 +144,7 @@ struct GradientView: View {
|
||||
Rectangle()
|
||||
.frame(width: 1)
|
||||
.frame(maxHeight: .infinity)
|
||||
|
||||
ZStack(alignment: .topLeading) {
|
||||
Rectangle()
|
||||
.fixedSize()
|
||||
@@ -150,14 +152,13 @@ struct GradientView: View {
|
||||
.frame(width: scaledSize, height: proxy.size.height)
|
||||
.background(colorMode == .dark ? Color.black : Color.white)
|
||||
.offset(x: scaledOffset, y: 0)
|
||||
|
||||
|
||||
Rectangle()
|
||||
.fixedSize()
|
||||
.foregroundColor(.clear)
|
||||
.frame(width: scaledSize, height: proxy.size.height)
|
||||
.background(background)
|
||||
.offset(x: scaledOffset, y: 0)
|
||||
|
||||
ForEach(linearGradient.indices, id: \.self) { i in
|
||||
Rectangle()
|
||||
.fixedSize()
|
||||
@@ -165,6 +166,7 @@ struct GradientView: View {
|
||||
.frame(width: scaledSize, height: proxy.size.height)
|
||||
.background(linearGradient[i])
|
||||
.offset(x: scaledOffset, y: 0)
|
||||
.id(pivot)
|
||||
}
|
||||
}
|
||||
.frame(width: size, height: proxy.size.height)
|
||||
|
||||
@@ -18,7 +18,7 @@ dependencies {
|
||||
testImplementation "junit:junit:${versionJunit}"
|
||||
testImplementation "org.glassfish.jaxb:jaxb-runtime:${versionJaxb}"
|
||||
|
||||
compileClasspath "jakarta.platform:jakarta.jakartaee-api:${versionJavaee}"
|
||||
compileOnly "jakarta.platform:jakarta.jakartaee-api:${versionJavaee}"
|
||||
|
||||
// explicity require jakarta jaxrs integration for swagger
|
||||
swagger "io.swagger.core.v3:swagger-jaxrs2-jakarta:${versionSwagger}"
|
||||
@@ -49,3 +49,6 @@ publishing {
|
||||
}
|
||||
}
|
||||
|
||||
publishMavenPublicationToMavenRepository {
|
||||
dependsOn 'resolve'
|
||||
}
|
||||
@@ -89,6 +89,8 @@ public enum WeatherType {
|
||||
// 99 = starkes gewitter mit graupel oder hagel (nur cosmo-d2)
|
||||
// https://www.dwd.de/DE/forschung/wettervorhersage/num_modellierung/01_num_vorhersagemodelle/01c_wetterinterpretation/wetter_interpretation.pdf?__blob=publicationFile&v=6
|
||||
if (code == 99) code = 96;
|
||||
// workaround for sandstorm (that should not be present), make it fog
|
||||
if (code == 8) code = 45;
|
||||
for (WeatherType weatherInterpretationType : values()) {
|
||||
if (weatherInterpretationType.code == code) {
|
||||
return weatherInterpretationType;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,7 @@ dependencies {
|
||||
task nominatimExporter(type: Jar) {
|
||||
dependsOn += ':service-data:build'
|
||||
duplicatesStrategy = 'exclude'
|
||||
classifier = 'nominatim'
|
||||
archiveClassifier = 'nominatim'
|
||||
manifest {
|
||||
attributes 'Main-Class': 'com.mowesta.tool.nominatim.NominatimExporter'
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.mowesta.tool.paper.LocationClassifier.TripResult;
|
||||
|
||||
public class DeviceTemperatureEval {
|
||||
|
||||
public static final File folder = new File("mowesta-dump");
|
||||
public static final File folder = new File("/Users/Marcus/git/mowesta-data-and-other/mowesta-dump");
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// hunga tonga vulcano
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
package com.mowesta.tool.paper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.locoslab.library.geometry.wgs.HaversineDistance;
|
||||
import com.mowesta.api.Coordinate;
|
||||
import com.mowesta.api.device.Device;
|
||||
import com.mowesta.api.device.OperatingSystem;
|
||||
import com.mowesta.api.measurement.Measurement;
|
||||
import com.mowesta.tool.analysis.WeatherResolver;
|
||||
import com.mowesta.tool.analysis.WeatherResolver.DataType;
|
||||
import com.mowesta.tool.analysis.WeatherResolver.Resolution;
|
||||
import com.mowesta.tool.paper.Algo.ErrorSummary;
|
||||
import com.mowesta.tool.paper.LocationClassifier.TripResult;
|
||||
|
||||
public class PrepareDataForTorch {
|
||||
|
||||
public static class MeasurementData {
|
||||
public double temperature;
|
||||
public long timestamp;
|
||||
public double distance;
|
||||
public boolean active;
|
||||
}
|
||||
|
||||
|
||||
public static class TripData {
|
||||
public long timestamp;
|
||||
public double temperature;
|
||||
public List<MeasurementData> measurements = new ArrayList<MeasurementData>();
|
||||
}
|
||||
|
||||
|
||||
public static class DeviceData {
|
||||
public long id;
|
||||
public String model;
|
||||
public String manufacturer;
|
||||
public List<TripData> trips = new ArrayList<TripData>();
|
||||
}
|
||||
|
||||
public static class ExperimentData {
|
||||
public List<DeviceData> devices = new ArrayList<DeviceData>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static final File folder = new File("/Users/Marcus/git/mowesta-data-and-other/mowesta-dump");
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// hunga tonga vulcano
|
||||
long start = getDate("2019-01-01 0:00");
|
||||
long end = getDate("2023-01-01 00:00");
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ExperimentData result = new ExperimentData();
|
||||
|
||||
List<Device> devices = readFile(new File(folder, "devices.json"), Device.class);
|
||||
for (Device d: devices) {
|
||||
if (d.getId() == 24963415l) continue; // stationary tablet (will cause out-of-memory)
|
||||
if (d.getId() == 20488695l) {
|
||||
// System.out.println("Dev: " + d.getManufacturer() + " " + d.getModel());
|
||||
}
|
||||
if (d.getId() == 20488695l) continue; // device with 1 degree precision
|
||||
if (d.getId() == 35723568l) continue; // t: 0.9 - 9.5
|
||||
if (d.getId() == 40549928l) continue; // one of our test devices
|
||||
|
||||
|
||||
//if (d.getId() != 11626535l) continue;
|
||||
if (d.getOs() == OperatingSystem.ANDROID) {
|
||||
List<Measurement> ms = readFile(new File(folder, "measurement-" + d.getId() + ".json" ), Measurement.class);
|
||||
ms = ms.stream().filter(m->m.getTime() > start && m.getTime() < end).collect(Collectors.toList());
|
||||
Collections.sort(ms, (a, b) -> Long.compare(a.getTime(), b.getTime()));
|
||||
List<TripResult> trips = getTrips(ms, System.currentTimeMillis());
|
||||
List<TripResult> walking = trips.stream().filter(t -> t.getDistance() > 300 && t.getSpeed() < 2 && t.getDuration() > 5 * 60 * 1000).collect(Collectors.toList());
|
||||
List<TripResult> walkingWithTruth = walking.stream().filter(t -> getStationTemperature(t) != null).collect(Collectors.toList());
|
||||
if (walking.size() > 100 && walkingWithTruth.size() > 0) {
|
||||
DeviceData dev = new DeviceData();
|
||||
dev.id = d.getId();
|
||||
dev.model = d.getModel();
|
||||
dev.manufacturer = d.getManufacturer();
|
||||
result.devices.add(dev);
|
||||
for (TripResult t: walkingWithTruth) {
|
||||
TripData trip = new TripData();
|
||||
trip.timestamp = t.origin.getTime();
|
||||
trip.temperature = getStationTemperature(t);
|
||||
dev.trips.add(trip);
|
||||
Measurement previous = t.origin;
|
||||
for (Measurement m : t.motion) {
|
||||
Double temperature = Mse.getDeviceTemperature(m);
|
||||
if (temperature == null) continue;
|
||||
Boolean active = Mse.isActive(m);
|
||||
MeasurementData md = new MeasurementData();
|
||||
md.distance = HaversineDistance.getDistance(previous.getCoordinate().getLongitude(), previous.getCoordinate().getLatitude(), m.getCoordinate().getLongitude(), m.getCoordinate().getLatitude());
|
||||
md.temperature = temperature;
|
||||
md.timestamp = m.getTime();
|
||||
md.active = active;
|
||||
previous = m;
|
||||
trip.measurements.add(md);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mapper.writeValue(new File("output.json"), result);
|
||||
|
||||
}
|
||||
|
||||
public static void appendError(StringBuilder b, List<double[]> map) {
|
||||
ErrorSummary s = Algo.errors(map);
|
||||
append(b, s.mae);
|
||||
append(b, s.rms);
|
||||
append(b, s.max);
|
||||
for (int i = 0; i< s.distribution.length; i++) {
|
||||
//append(b, s.distribution[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void append(StringBuilder b, double value) {
|
||||
b.append(("" + value).replace(".", ",") + ";");
|
||||
}
|
||||
|
||||
public static List<double[]> getAllPairs(List<Measurement> ms) {
|
||||
List<double[]> result = new ArrayList<>();
|
||||
for (Measurement m: ms) {
|
||||
Double station = Mse.getStationTemperature(m);
|
||||
Double device = Mse.getDeviceTemperature(m);
|
||||
if (station != null && device != null) {
|
||||
result.add(new double[] { device, station });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<double[]> getTripPairs(List<TripResult> trips) {
|
||||
List<double[]> result = new ArrayList<>();
|
||||
for (TripResult r: trips) {
|
||||
for (Measurement m: r.motion) {
|
||||
Double station = Mse.getStationTemperature(m);
|
||||
Double device = Mse.getDeviceTemperature(m);
|
||||
if (station != null && device != null) {
|
||||
result.add(new double[] { device, station });
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static List<double[]> getPairs(List<TripResult> walking, double time, boolean noActive) {
|
||||
List<double[]> outside = new ArrayList<>();
|
||||
walking.forEach(t -> {
|
||||
double station = getStationTemperature(t);
|
||||
Double temperature = getDeviceTemperatureAt(t, time, noActive);
|
||||
if (temperature != null) {
|
||||
outside.add(new double[] { temperature, station });
|
||||
}
|
||||
});
|
||||
return outside;
|
||||
}
|
||||
|
||||
|
||||
public static Double getDeviceTemperatureAt(TripResult t, double minute, boolean noActive) {
|
||||
Measurement first = t.origin;
|
||||
double firstMinute = 0;
|
||||
Measurement last = t.destination;
|
||||
double lastMinute = getMinuteForMeasurement(t.origin, last);
|
||||
if (minute > lastMinute) {
|
||||
return null;
|
||||
}
|
||||
for (Measurement m: t.motion) {
|
||||
double curr = getMinuteForMeasurement(t.origin, m);
|
||||
if (curr <= minute) {
|
||||
if (minute - curr < minute - firstMinute) {
|
||||
first = m;
|
||||
firstMinute = curr;
|
||||
}
|
||||
} else {
|
||||
if (curr - minute < lastMinute - minute) {
|
||||
last = m;
|
||||
lastMinute = curr;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (noActive) {
|
||||
// filter trips with active measurements
|
||||
if (Mse.isActive(last) || Mse.isActive(first)) return null;
|
||||
int count = 1;
|
||||
for (Measurement m: t.motion) {
|
||||
if (Mse.isActive(m)) {
|
||||
count -= 1;
|
||||
if (count == 0)
|
||||
return null;
|
||||
}
|
||||
if (m == last) break;
|
||||
}
|
||||
}
|
||||
// linear interpolation
|
||||
double ft = Mse.getDeviceTemperature(first);
|
||||
double lt = Mse.getDeviceTemperature(last);
|
||||
if (lastMinute == firstMinute) return ft;
|
||||
double percent = (minute - firstMinute) / (lastMinute - firstMinute);
|
||||
//System.out.println("perc: " + percent);
|
||||
double res = percent * lt + (1 - percent) * ft;
|
||||
//System.out.println("FT: " + ft + " LT: " + lt + " Timing: " + firstMinute + " " + lastMinute + " " + minute + " = " + res);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static double getMinuteForMeasurement(Measurement origin, Measurement m) {
|
||||
return (m.getTime() - origin.getTime()) / 60000d;
|
||||
}
|
||||
|
||||
public static Double getStationTemperature(TripResult t) {
|
||||
Double r = Mse.getStationTemperature(t.origin);
|
||||
if (r == null) {
|
||||
for (Measurement m: t.motion) {
|
||||
r = Mse.getStationTemperature(m);
|
||||
if (r != null) break;
|
||||
}
|
||||
if (r == null) {
|
||||
//r = Mse.getStationTemperature(t.destination);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
public static List<TripResult> getTrips(List<Measurement> ms, long now) {
|
||||
List<TripResult> results = new ArrayList<>();
|
||||
TripResult result;
|
||||
while ((result = LocationClassifier.computeNextTrip(ms, now)) != null) {
|
||||
results.add(result);
|
||||
ms = result.remainder;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public static Measurement getMeasurement(TripResult result, double minute, double threshold) {
|
||||
List<Measurement> candidates = result.motion.stream().filter(m -> {
|
||||
double min = (m.getTime() - result.origin.getTime()) / 60000d;
|
||||
return min > minute - 0.5 * threshold && min <= minute + 0.5 * threshold;
|
||||
}).collect(Collectors.toList());
|
||||
if (candidates.isEmpty()) return null;
|
||||
else return candidates.get(0);
|
||||
}
|
||||
|
||||
|
||||
public static String toString(Date date) {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static long getDate(String string) throws ParseException {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
Date date = df.parse(string);
|
||||
return date.getTime();
|
||||
}
|
||||
|
||||
|
||||
public static <T> List<T> readFile(File file, Class<T> type) throws Exception {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
List<T> result = new ArrayList<>();
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file, StandardCharsets.UTF_8))) {
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
result.add(mapper.readValue(line, type));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -25,17 +25,17 @@ public class VideoGeneratorExample {
|
||||
* @throws IOException Thrown if the files cannot be read.
|
||||
*/
|
||||
public static void main(String[] args) throws IOException {
|
||||
Time time = new Time(2024, 3, 12);
|
||||
Time time = new Time(2026, 7, 29);
|
||||
|
||||
NumericPrediction[] predictions = new NumericPrediction[] {
|
||||
// new NumericPrediction(PredictionType.ICON_GLOBAL, new File("/Users/marcus/Data/mowesta/test")),
|
||||
// new NumericPrediction(PredictionType.ICON_GLOBAL, new File("dwd-data/global")),
|
||||
new NumericPrediction(PredictionType.COSMO_EUROPE, new File("dwd-data/germany")),
|
||||
// new NumericPrediction(PredictionType.ICON_EUROPE, new File("dwd-data/eu"))
|
||||
// new NumericPrediction(PredictionType.ICON_EUROPE, new File("dwd-data/eu"))
|
||||
};
|
||||
String[] prefixes = new String[] {
|
||||
// "global",
|
||||
"global",
|
||||
"germany",
|
||||
// "europe"
|
||||
"europe"
|
||||
};
|
||||
for (NumericPrediction prediction: predictions) {
|
||||
if (!prediction.isAvailable(time)) {
|
||||
@@ -48,7 +48,7 @@ public class VideoGeneratorExample {
|
||||
if (p.isAvailable(time)) {
|
||||
VideoGenerator videoGenerator = new VideoGenerator(p, c.createComposer(time));
|
||||
long start = System.currentTimeMillis();
|
||||
Variable variable = Variable.CLCT;
|
||||
Variable variable = Variable.PMSL;
|
||||
String name = "video-" + prefixes[i] + "-" + variable.getFolder();
|
||||
videoGenerator.createVideo(variable, time, 8, 10, new File(name + ".mp4"), new File(name + ".jpg"), (kfr, ifr) -> {
|
||||
System.out.println("Key: " + kfr + " Int:" + ifr);
|
||||
|
||||
@@ -117,3 +117,6 @@ sourceSets {
|
||||
}
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
dependsOn 'compileJava'
|
||||
}
|
||||
+3
-2
@@ -19,8 +19,9 @@ import java.util.logging.Level;
|
||||
import com.locoslab.library.grib2.Grib2Data;
|
||||
import com.locoslab.library.grib2.Grib2File;
|
||||
import com.locoslab.library.grib2.data.DoubleArray;
|
||||
import com.locoslab.library.grib2.decoder.SimpleDataDecoder;
|
||||
import com.locoslab.library.grib2.decoder.SimpleStreamDecoder;
|
||||
import com.locoslab.library.grib2.decoder.Decoder;
|
||||
import com.locoslab.library.grib2.decoder.CcsdsDataDecoder;
|
||||
import com.mowesta.api.Coordinate;
|
||||
import com.mowesta.api.weather.SoilType;
|
||||
import com.mowesta.api.weather.WeatherCondition;
|
||||
@@ -279,7 +280,7 @@ public class WeatherForecastSyncSessionBean extends AbstractSyncSessionBean {
|
||||
try {
|
||||
Grib2Data data = grib2.nextData();
|
||||
hours.add(hour);
|
||||
SimpleDataDecoder decoder = new SimpleDataDecoder(data);
|
||||
Decoder decoder = new CcsdsDataDecoder(data);
|
||||
IDataSource ds = new Grib2MixedSource(longitudes, latitudes, new SimpleStreamDecoder(decoder));
|
||||
prepareData(v, hour, ds);
|
||||
counter += 1;
|
||||
|
||||
@@ -18,7 +18,7 @@ task downloadGalleon(type: Copy) {
|
||||
// create wildfly server
|
||||
task provisionWildfly(type: JavaExec) {
|
||||
dependsOn 'downloadGalleon'
|
||||
main = '-jar'
|
||||
mainClass = '-jar'
|
||||
args "${project.buildDir}/galleon/galleon-cli-${versionGalleon}.jar", 'provision', "${project.projectDir}/src/galleon.xml", "--dir=${project.projectDir}/wildfly"
|
||||
onlyIf { !file("${project.projectDir}/wildfly").exists() }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id "com.github.node-gradle.node" version "2.2.4"
|
||||
id "com.github.node-gradle.node" version "7.1.0"
|
||||
id 'org.openapi.generator' version '6.0.0'
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ node {
|
||||
download = true
|
||||
}
|
||||
|
||||
class IoNodeTask extends com.moowork.gradle.node.task.NodeTask {
|
||||
abstract class IoNodeTask extends com.github.gradle.node.task.NodeTask {
|
||||
@InputDirectory
|
||||
File inputDir;
|
||||
@OutputDirectory
|
||||
|
||||
@@ -92,8 +92,6 @@
|
||||
<mat-card-subtitle style="margin-left: 15px;">{{ res.strings('manage_system_load_subtitle') }}</mat-card-subtitle>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
@if(canGetCpuLoad()){
|
||||
@if (getCpuLoad() <= 40) {}}
|
||||
<div>
|
||||
<svg height="400" viewBox="-200 -200 400 400" xmlns="http://www.w3.org/2000/svg" >
|
||||
<!--Border Circle-->
|
||||
|
||||
Reference in New Issue
Block a user