Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17006aafe3 | ||
|
|
e5aa030857 | ||
|
|
c8e0a7f16e | ||
|
|
35d8f06e5d | ||
|
|
b967f318c7 | ||
|
|
e1f28ffd23 | ||
|
|
6d5ce170bd | ||
|
|
4d1d87d8ef | ||
|
|
d032e2e577 | ||
|
|
0a7e33503f | ||
|
|
f62c5b41cf | ||
|
|
cdfc018c33 | ||
|
|
9a773ca13f | ||
|
|
1b80e9415f | ||
|
|
706f24f104 | ||
|
|
4029c15eb9 | ||
|
|
6fd3209304 | ||
|
|
ffa3ff7d46 | ||
|
|
83530a9a41 | ||
|
|
7ed7d8cfcf | ||
|
|
aff152543c | ||
|
|
bb92acc66a | ||
|
|
bfad0d8716 | ||
|
|
a8028ff446 | ||
|
|
32bcbf3647 | ||
|
|
52ff3d660c | ||
|
|
e794d83ec5 | ||
|
|
95b82b133a | ||
|
|
a66cc3bb0c | ||
|
|
87abaf05c1 | ||
|
|
3e575f96e6 | ||
|
|
a318d10f79 | ||
|
|
969d59c4c3 | ||
|
|
66ba4e0d09 | ||
|
|
e87199c024 | ||
|
|
7a6b7084ac | ||
|
|
42ed5a03e1 | ||
|
|
8a564df34f | ||
|
|
746faf92b1 | ||
|
|
de74b222af | ||
|
|
66daf0c7b7 | ||
|
|
7e0b4d88d5 | ||
|
|
543b3587eb | ||
|
|
aa6d0cfab5 | ||
|
|
84fd69dfdb | ||
|
|
8c174f8581 | ||
|
|
6bd040272b | ||
|
|
2d2caaed09 | ||
|
|
cf99d87a66 | ||
|
|
778677ec40 | ||
|
|
485f56e547 | ||
|
|
13080b113b | ||
|
|
d1fc3bee96 | ||
|
|
8bd0cf7bc2 | ||
|
|
c306987b63 | ||
|
|
84beb97a73 | ||
|
|
82b7b5544d | ||
|
|
942e42ae76 | ||
|
|
ed8846d950 | ||
|
|
6bd27b2eff | ||
|
|
ef86399ba3 | ||
|
|
6b5f85fe5f | ||
|
|
822f4044f7 | ||
|
|
7414860ace | ||
|
|
582c1c6468 | ||
|
|
192836a763 | ||
|
|
5539048c54 | ||
|
|
61bb009959 | ||
|
|
843b52b468 | ||
|
|
1487957ea4 | ||
|
|
daf517bc6a | ||
|
|
c45b14d35a | ||
|
|
4734c0f7b7 | ||
|
|
0272fb770e | ||
|
|
0b357be701 | ||
|
|
de8a4b8360 | ||
|
|
83dc34fb53 | ||
|
|
8a306727a7 | ||
|
|
3a2eadad70 | ||
|
|
6017db7599 | ||
|
|
bc29648790 | ||
|
|
0ba90a0bb2 | ||
|
|
3ec70113e6 | ||
|
|
0c3b968aee | ||
|
|
b7514953a6 | ||
|
|
0483420af2 | ||
|
|
a72613aa58 | ||
|
|
b45311404c | ||
|
|
df19ff4b14 | ||
|
|
fa6f76ba7d | ||
|
|
5aee1eb084 | ||
|
|
6ef6ab4e67 | ||
|
|
ddf50c4fe1 | ||
|
|
2a8b231e4f | ||
|
|
a8d6643111 | ||
|
|
431b1627df | ||
|
|
f35ba34473 | ||
|
|
284f5d30bb | ||
|
|
72dfb593ce | ||
|
|
7ce521079e | ||
|
|
354776e64a | ||
|
|
21b642fc17 | ||
|
|
8d02c77ad0 | ||
|
|
fdd894c8d0 | ||
|
|
ee46cefeb0 | ||
|
|
eb72336ad0 | ||
|
|
abd400f2cd | ||
|
|
42fc44ce8f | ||
|
|
5205d45f75 | ||
|
|
0cb2413eac | ||
|
|
72ca9ac5dc | ||
|
|
b224c1d2eb | ||
|
|
8fce9a52d8 | ||
|
|
13c6ccd3da | ||
|
|
c9b1b85a57 | ||
|
|
cca2ca819e | ||
|
|
37f701902b | ||
|
|
c8a4c7b081 | ||
|
|
4981deddb9 | ||
|
|
a3dca92976 | ||
|
|
220325f1ed | ||
|
|
124f570e9d | ||
|
|
77a0ec44c6 | ||
|
|
7e93d8bcdd | ||
|
|
e72afae503 | ||
|
|
a83314e997 | ||
|
|
585bfc7635 | ||
|
|
8179510ea8 | ||
|
|
61501c54ba | ||
|
|
f4c9999368 | ||
|
|
b681689f09 | ||
|
|
f8ff826106 | ||
|
|
dfb0469fa6 | ||
|
|
d293bd66ef |
Vendored
+18
-9
@@ -21,6 +21,7 @@ node {
|
||||
}
|
||||
|
||||
def version = ''
|
||||
def release = false;
|
||||
|
||||
// configure the deployer based on the version
|
||||
stage('Configure') {
|
||||
@@ -28,10 +29,11 @@ node {
|
||||
println "Version is: '${version}'"
|
||||
if (version.endsWith("-SNAPSHOT")) {
|
||||
println "Using internal-snapshots for publication."
|
||||
gradleBuild.deployer server: server, repo: 'internal-snapshots'
|
||||
gradleBuild.deployer server: server, repo: 'internal-snapshots'
|
||||
} else {
|
||||
println "Using internal-releases for publication."
|
||||
gradleBuild.deployer server: server, repo: 'internal-releases'
|
||||
gradleBuild.deployer server: server, repo: 'internal-releases'
|
||||
release = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,23 +47,30 @@ node {
|
||||
|
||||
// deploy the maven publications to artifactory
|
||||
stage ('Publish') {
|
||||
if (env.BRANCH_NAME == "master") {
|
||||
if (env.BRANCH_NAME == "master" && release) {
|
||||
withCredentials([string(credentialsId: 'mowesta-keystore-password', variable: 'PASSWD')]) {
|
||||
def switches = "-Djenkins.build.number=${env.BUILD_NUMBER} -Dandroid.keystore.password=${PASSWD}".toString()
|
||||
gradleInfo = gradleBuild.run buildFile: 'build.gradle', tasks: 'artifactoryPublish', switches: switches
|
||||
}
|
||||
} else {
|
||||
echo "Skipping deployment for non-master branch."
|
||||
echo "Skipping deployment for non-release version or non-master branch."
|
||||
}
|
||||
}
|
||||
|
||||
// deploy the build output on the server
|
||||
stage ('Deploy') {
|
||||
if (env.BRANCH_NAME == "master") {
|
||||
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "keyfile")]) {
|
||||
sh "scp -i ${keyfile} site-ear/build/libs/site-ear-${version}.ear wildfly@apps.nes.uni-due.de:/opt/wildfly-17-mowesta/standalone/deployments/mowesta.ear"
|
||||
sh "scp -i ${keyfile} android-app/build/outputs/apk/release/*.apk wildfly@apps.nes.uni-due.de:/opt/android/mowesta/"
|
||||
}
|
||||
// release = true; // uncomment to temporary enable snapshot deployments
|
||||
if (env.BRANCH_NAME == "master" && release) {
|
||||
echo "Deploying to production server ..."
|
||||
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "keyfile")]) {
|
||||
sh "scp -i ${keyfile} site-ear/build/libs/site-ear-${version}.ear wildfly@apps.nes.uni-due.de:/opt/wildfly-21-mowesta/standalone/deployments/mowesta.ear"
|
||||
sh "scp -i ${keyfile} android-app/build/outputs/apk/release/*.apk wildfly@apps.nes.uni-due.de:/opt/android/mowesta/"
|
||||
}
|
||||
} else if (env.BRANCH_NAME == "master") {
|
||||
echo "Deploying to beta server ..."
|
||||
withCredentials([sshUserPrivateKey(credentialsId: "mowesta-server-key", keyFileVariable: "keyfile")]) {
|
||||
sh "scp -i ${keyfile} site-ear/build/libs/site-ear-${version}.ear wildfly@apps.nes.uni-due.de:/opt/wildfly-21-beta/standalone/deployments/mowesta.ear"
|
||||
}
|
||||
} else {
|
||||
echo "Skipping deployment for non-master branch."
|
||||
}
|
||||
|
||||
@@ -13,3 +13,4 @@ To build the project, you will have to install [Java](http://www.oracle.com/tech
|
||||
# Jenkins CI
|
||||
|
||||
Pull requests and new commits to any branch are automatically built by a Jenkins service. A Gitea webhook informs the service about changes to the repository. In addition, the service will automatically scan the lbs Gitea organization for new repositories every hour. Successful builds of new commits are indicated by a green tick on the commit page. The build status of pull requests is currently not shown in Gitea. However, you can go to the [Jenkins](https://project.nes.uni-due.de/jenkins/job/LocationBasedServices/job/mowesta/) service to view the result of builds including the console output. To modify the build process, you can change the Jenkinsfile groovy script in the root of the repository, if necessary.
|
||||
|
||||
|
||||
@@ -13,13 +13,13 @@ ext {
|
||||
versionAndroidXPaging = '2.1.2'
|
||||
versionAndroidXCard = '1.0.0'
|
||||
versionAndroidXCoordinator = '1.1.0'
|
||||
versionAndroidXConstraint = '1.1.3'
|
||||
versionAndroidXNavigation = '2.3.0-beta01'
|
||||
versionAndroidXConstraint = '2.0.4'
|
||||
versionAndroidXNavigation = '2.3.2'
|
||||
versionAndroidXLifecycle = '2.2.0'
|
||||
versionAndroidXSecurity = '1.0.0-rc02'
|
||||
versionAndroidXSecurity = '1.1.0-alpha03'
|
||||
versionAndroidXViewpager = '1.0.0'
|
||||
versionGoogleMaterial = '1.1.0'
|
||||
versionAndroidXSwipeRefresh = '1.0.0'
|
||||
versionGoogleMaterial = '1.2.1'
|
||||
versionAndroidXSwipeRefresh = '1.1.0'
|
||||
versionExoPlayer = '2.11.5'
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ android {
|
||||
applicationId "com.mowesta.android.app"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 29
|
||||
versionCode 3
|
||||
versionCode 11
|
||||
versionName "${version}"
|
||||
buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
<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>
|
||||
<service android:name=".MowestaService" />
|
||||
</application>
|
||||
|
||||
@@ -58,4 +58,11 @@ public interface IApp {
|
||||
*/
|
||||
Cache getMediaCache();
|
||||
|
||||
/**
|
||||
* Returns a settings instance.
|
||||
*
|
||||
* @return The settings instance.
|
||||
*/
|
||||
MowestaSettings getSettings();
|
||||
|
||||
}
|
||||
|
||||
@@ -5,24 +5,19 @@ 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.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.Manifest;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.PermissionChecker;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.mowesta.android.app.database.FavoriteDatabase;
|
||||
import com.mowesta.android.app.generated.callback.OnClickListener;
|
||||
import com.mowesta.android.app.repository.UserCredentials;
|
||||
import com.mowesta.android.app.task.DatabaseTask;
|
||||
import com.mowesta.android.app.task.RefreshTask;
|
||||
@@ -94,7 +89,7 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
private OnSharedPreferenceChangeListener preferenceListener = (prefs, key) -> {
|
||||
if (MowestaSettings.PRIVACY_MEASURE.equals(key)) {
|
||||
if (settings.isPrivacyMeasure()) {
|
||||
if (!PermissionUtil.hasPermissions(this)) requestPermissions();
|
||||
if (!PermissionUtil.hasBackgroundPermissions(this)) requestPermissions();
|
||||
else MowestaService.startService(this);
|
||||
} else {
|
||||
MowestaService.stopService(this);
|
||||
@@ -108,11 +103,18 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
app = (IApp) getApplication();
|
||||
favoriteTask.execute(null, app.getFavoriteRepository().getDatabase());
|
||||
settings = new MowestaSettings(getApplication());
|
||||
settings = app.getSettings();
|
||||
setContentView(R.layout.activity_app);
|
||||
installHttpCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
// got to navigation drawer when user presses notification
|
||||
setIntent(intent);
|
||||
Navigation.findNavController(this, R.id.navigation_app).navigate(R.id.action_drawer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
@@ -160,9 +162,18 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
/**
|
||||
* Method to request location permission for the app.
|
||||
*/
|
||||
private void requestPermissions() {
|
||||
public void requestPermissions() {
|
||||
Log.d(TAG, "Requesting permissions.");
|
||||
ActivityCompat.requestPermissions(this, PermissionUtil.getNonGrantedPermissions(this), CODE_REQUEST_PERMISSIONS);
|
||||
requestPermissions(PermissionUtil.getNonGrantedBackgroundPermissions(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the permissions.
|
||||
*
|
||||
* @param permissions The permissions to request.
|
||||
*/
|
||||
public void requestPermissions(String[] permissions) {
|
||||
ActivityCompat.requestPermissions(this, permissions, CODE_REQUEST_PERMISSIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,21 +197,7 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
Log.d(TAG, "Permission result: " + b.toString());
|
||||
if (!granted) {
|
||||
settings.setPrivacyMeasure(false);
|
||||
View coordinator = findViewById(R.id.layout_coordinator);
|
||||
Snackbar.make(coordinator, R.string.message_no_permission, Snackbar.LENGTH_LONG )
|
||||
.setAction(R.string.button_configure, (view) -> {
|
||||
// go to app settings
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
Snackbar.make(coordinator, R.string.message_configure_failed,
|
||||
Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}).show();
|
||||
showMissingPermission();
|
||||
} else {
|
||||
MowestaService.startService(this);
|
||||
}
|
||||
@@ -211,4 +208,25 @@ public class MowestaActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a snackbar indicating a missing permission.
|
||||
*/
|
||||
public void showMissingPermission() {
|
||||
View coordinator = findViewById(R.id.layout_coordinator);
|
||||
Snackbar.make(coordinator, R.string.message_no_permission, Snackbar.LENGTH_LONG )
|
||||
.setAction(R.string.button_configure, (view) -> {
|
||||
// go to app settings
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
Snackbar.make(coordinator, R.string.message_configure_failed,
|
||||
Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +40,11 @@ public class MowestaApp extends Application implements IApp {
|
||||
*/
|
||||
protected FavoriteRepository favoriteRepository;
|
||||
|
||||
/**
|
||||
* The application settings.
|
||||
*/
|
||||
protected MowestaSettings settings;
|
||||
|
||||
/**
|
||||
* The cache to store videos.
|
||||
*/
|
||||
@@ -49,6 +54,7 @@ public class MowestaApp extends Application implements IApp {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
settings = new MowestaSettings(this);
|
||||
userRepository = new UserRepository.Builder().setTrace(false).build(this);
|
||||
deviceRepository = new DeviceRepository.Builder().setTrace(false).build(this);
|
||||
favoriteRepository = new FavoriteRepository(this);
|
||||
@@ -96,5 +102,10 @@ public class MowestaApp extends Application implements IApp {
|
||||
}
|
||||
return mediaCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MowestaSettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* A broadcast receiver that registers the background activites at
|
||||
* device boot time.
|
||||
* A broadcast receiver that starts the background service after
|
||||
* a reboot and when the package is updated.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
@@ -24,7 +24,8 @@ public class MowestaReceiver extends BroadcastReceiver {
|
||||
// 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())) {
|
||||
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) ||
|
||||
Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
|
||||
MowestaService.startService(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.mowesta.android.app;
|
||||
|
||||
import android.app.Application;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
@@ -9,7 +7,6 @@ import android.os.Build;
|
||||
import com.mowesta.android.app.util.PermissionUtil;
|
||||
import com.mowesta.android.feign.api.DefaultApi;
|
||||
import com.mowesta.android.sdk.SdkService;
|
||||
import com.mowesta.android.sdk.util.CapabilityManager;
|
||||
|
||||
/**
|
||||
* A service to perform background measurements.
|
||||
@@ -21,7 +18,7 @@ public class MowestaService extends SdkService {
|
||||
@Override
|
||||
protected boolean isEnabled() {
|
||||
IApp app = (IApp)getApplication();
|
||||
MowestaSettings settings = new MowestaSettings(getApplication());
|
||||
MowestaSettings settings = app.getSettings();
|
||||
return settings.isPrivacyMeasure() && app.getDeviceRepository().getHandle().getValue() != null;
|
||||
}
|
||||
|
||||
@@ -38,9 +35,9 @@ public class MowestaService extends SdkService {
|
||||
* @param context A context object.
|
||||
*/
|
||||
public static void startService(Context context) {
|
||||
if (!PermissionUtil.hasPermissions(context)) return;
|
||||
if (!PermissionUtil.hasBackgroundPermissions(context)) return;
|
||||
IApp app = (IApp)context.getApplicationContext();
|
||||
MowestaSettings settings = new MowestaSettings((Application)context.getApplicationContext());
|
||||
MowestaSettings settings = app.getSettings();
|
||||
if (!settings.isPrivacyMeasure() || app.getDeviceRepository().getHandle().getValue() == null) return;
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context, MowestaService.class);
|
||||
|
||||
@@ -7,6 +7,7 @@ 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;
|
||||
@@ -16,6 +17,22 @@ import com.mowesta.android.sdk.SdkSettings;
|
||||
*/
|
||||
public class MowestaSettings extends SdkSettings {
|
||||
|
||||
/**
|
||||
* An enumeration with the unit system used throughout
|
||||
* the application.
|
||||
*/
|
||||
public enum UnitSystem {
|
||||
BOTH, STANDARD, IMPERIAL
|
||||
}
|
||||
|
||||
/**
|
||||
* An enumeration with the temperature unit to
|
||||
* use throughout the application.
|
||||
*/
|
||||
public enum TemperatureUnit {
|
||||
BOTH, CELSIUS, FAHRENHEIT
|
||||
}
|
||||
|
||||
/**
|
||||
* The key to an integer to store the current version of the terms that the user has accepted.
|
||||
*/
|
||||
@@ -36,12 +53,6 @@ public class MowestaSettings extends SdkSettings {
|
||||
*/
|
||||
public static final String COLLECTION_SHOWN = "collection_shown";
|
||||
|
||||
/**
|
||||
* The key to a boolean to store whether the diagram will use
|
||||
* celsius (true) or fahrenheit (false).
|
||||
*/
|
||||
public static final String TEMPERATURE_CELSIUS = "temperature_celsius";
|
||||
|
||||
/**
|
||||
* The key to a boolean to show/hide the precipitation.
|
||||
*/
|
||||
@@ -72,6 +83,21 @@ public class MowestaSettings extends SdkSettings {
|
||||
*/
|
||||
public static final String SHOW_PRESSURE = "show_pressure";
|
||||
|
||||
/**
|
||||
* The key to a boolean to show/hide the scale on videos.
|
||||
*/
|
||||
public static final String SHOW_SCALE = "show_scale";
|
||||
|
||||
/**
|
||||
* The unit system to be used in the application.
|
||||
*/
|
||||
public static final String UNIT_SYSTEM = "unit_system";
|
||||
|
||||
/**
|
||||
* The temperature unit to be used in the application.
|
||||
*/
|
||||
public static final String TEMPERATURE_UNIT = "temperature_unit";
|
||||
|
||||
/**
|
||||
* Creates the settings with the context.
|
||||
*
|
||||
@@ -166,41 +192,6 @@ public class MowestaSettings extends SdkSettings {
|
||||
e.apply();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the diagram uses celsius or fahrenheit.
|
||||
*
|
||||
* @return True if the diagram uses celsius, false if fahrenheit
|
||||
*/
|
||||
public boolean isTemperatureCelsius() {
|
||||
boolean defaultValue = getResources().getBoolean(R.bool.temperature_celsius_default);
|
||||
return preferences.getBoolean(TEMPERATURE_CELSIUS, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the boolean to indicate whether the diagram uses fahrenheit
|
||||
* or celsius.
|
||||
*
|
||||
* @param value The value.
|
||||
*/
|
||||
public void setTemperatureCelsius(boolean value) {
|
||||
SharedPreferences.Editor e = preferences.edit();
|
||||
e.putBoolean(TEMPERATURE_CELSIUS, value);
|
||||
e.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the temperature is in celsisus or fahrenheit without object allocation.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return True if temperature is in celsius.
|
||||
*/
|
||||
public static boolean isTemperatureCelsisus(@NonNull Context context) {
|
||||
boolean defaultValue = context.getResources().getBoolean(R.bool.temperature_celsius_default);
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return preferences.getBoolean(TEMPERATURE_CELSIUS, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the cloud coverage is shown.
|
||||
*
|
||||
@@ -329,6 +320,53 @@ public class MowestaSettings extends SdkSettings {
|
||||
e.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the temperature unit.
|
||||
*
|
||||
* @return The temperature unit.
|
||||
*/
|
||||
public TemperatureUnit getTemperatureUnit() {
|
||||
int index = preferences.getInt(TEMPERATURE_UNIT, TemperatureUnit.BOTH.ordinal());
|
||||
index = Math.max(0, Math.min(index, TemperatureUnit.values().length - 1));
|
||||
return TemperatureUnit.values()[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temperature unit.
|
||||
*
|
||||
* @param unit The temperature unit.
|
||||
*/
|
||||
public void setTemperatureUnit(@NonNull TemperatureUnit unit) {
|
||||
SharedPreferences.Editor e = preferences.edit();
|
||||
e.putInt(TEMPERATURE_UNIT, unit.ordinal());
|
||||
e.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unit system.
|
||||
*
|
||||
* @return The unit system.
|
||||
*/
|
||||
public UnitSystem getUnitSystem() {
|
||||
int index = preferences.getInt(UNIT_SYSTEM, UnitSystem.BOTH.ordinal());
|
||||
index = Math.max(0, Math.min(index, UnitSystem.values().length - 1));
|
||||
return UnitSystem.values()[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the unit system.
|
||||
*
|
||||
* @param system The unit system.
|
||||
*/
|
||||
public void setUnitSystem(@NonNull UnitSystem system) {
|
||||
SharedPreferences.Editor e = preferences.edit();
|
||||
e.putInt(UNIT_SYSTEM, system.ordinal());
|
||||
e.apply();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package com.mowesta.android.app.adapter;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
/**
|
||||
* A live data object for preferences that store an enumeration value
|
||||
* as an ordinal int in the preferences.
|
||||
*
|
||||
* @param <T> The type.
|
||||
*/
|
||||
public class EnumPreferenceLiveData<T extends Enum<T>> extends LiveData<T> {
|
||||
|
||||
/**
|
||||
* The key.
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* The default value.
|
||||
*/
|
||||
private T defaultValue;
|
||||
|
||||
/**
|
||||
* The enumeration type.
|
||||
*/
|
||||
private Class<T> type;
|
||||
|
||||
/**
|
||||
* The preferences to attach to.
|
||||
*/
|
||||
private SharedPreferences preferences;
|
||||
|
||||
/**
|
||||
* The listener to track changes to the value.
|
||||
*/
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String k) {
|
||||
if (key.equals(k)) {
|
||||
T newValue = loadValue();
|
||||
if (newValue != getValue()) {
|
||||
setValue(newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new preference live data object for the shared preferences
|
||||
* using the key assuming that it stores int values that are representing
|
||||
* the ordinal number of the specified enumeration type.
|
||||
*
|
||||
* @param preferences The preferences.
|
||||
* @param type The enumeration type.
|
||||
* @param key The key.
|
||||
* @param defaultValue The default value.
|
||||
*/
|
||||
public EnumPreferenceLiveData(@NonNull SharedPreferences preferences, @NonNull Class<T> type, @NonNull String key, @NonNull T defaultValue) {
|
||||
this.key = key;
|
||||
this.type = type;
|
||||
this.preferences = preferences;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the current value.
|
||||
*
|
||||
* @return The current value.
|
||||
*/
|
||||
private T loadValue() {
|
||||
int index = preferences.getInt(key, defaultValue.ordinal());
|
||||
index = Math.max(0, Math.min(index, type.getEnumConstants().length - 1));
|
||||
return type.getEnumConstants()[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(T value) {
|
||||
super.setValue(value);
|
||||
if (value != loadValue()) {
|
||||
SharedPreferences.Editor e = preferences.edit();
|
||||
e.putInt(key, value.ordinal());
|
||||
e.apply();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActive() {
|
||||
super.onActive();
|
||||
preferences.registerOnSharedPreferenceChangeListener(listener);
|
||||
setValue(loadValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInactive() {
|
||||
super.onInactive();
|
||||
preferences.unregisterOnSharedPreferenceChangeListener(listener);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.mowesta.android.app.arduino;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* The device configuration of the weather station.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
@JsonAutoDetect(creatorVisibility = JsonAutoDetect.Visibility.ANY,
|
||||
fieldVisibility = JsonAutoDetect.Visibility.ANY,
|
||||
getterVisibility = JsonAutoDetect.Visibility.NONE,
|
||||
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
|
||||
setterVisibility = JsonAutoDetect.Visibility.NONE)
|
||||
public class ArduinoConfig {
|
||||
|
||||
/**
|
||||
* The network name of the weather station.
|
||||
*/
|
||||
public static final String ARDUINO_SSID = "MoWeSta - WiFi";
|
||||
/**
|
||||
* The network password of the weather station.
|
||||
*/
|
||||
public static final String ARDUINO_PWD = "mowesta123456wifi";
|
||||
|
||||
/**
|
||||
* The ip address of the weather station.
|
||||
*/
|
||||
public static final String ARDUINO_IP = "192.168.4.1";
|
||||
|
||||
/**
|
||||
* The port of the weather station.
|
||||
*/
|
||||
public static final short ARDUINO_PORT = 8080;
|
||||
|
||||
/** The network ssid field. */
|
||||
@JsonProperty("ssid")
|
||||
private String ssid;
|
||||
/** The network password field. */
|
||||
@JsonProperty("password")
|
||||
private String password;
|
||||
/** The device token field. */
|
||||
@JsonProperty("token")
|
||||
private String token;
|
||||
/** The device id field. */
|
||||
@JsonProperty("id")
|
||||
private String id;
|
||||
/** The ssid field. */
|
||||
@JsonProperty("latitude")
|
||||
private String latitude;
|
||||
/** The ssid field. */
|
||||
@JsonProperty("longitude")
|
||||
private String longitude;
|
||||
|
||||
/**
|
||||
* Creates a new device configuration.
|
||||
*
|
||||
* @param id The device id.
|
||||
* @param token The token.
|
||||
* @param ssid The ssid.
|
||||
* @param password The password.
|
||||
* @param longitude The longitude.
|
||||
* @param latitude The latitude.
|
||||
*/
|
||||
public ArduinoConfig(long id, String token, String ssid, String password, double longitude, double latitude) {
|
||||
this.ssid = ssid;
|
||||
this.token = token;
|
||||
this.password = password;
|
||||
this.id = "" + id;
|
||||
this.latitude = "" + latitude;
|
||||
this.longitude = "" + longitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the json representation of the device config.
|
||||
*
|
||||
* @return The json representation.
|
||||
* @throws IOException Thrown if something fails.
|
||||
*/
|
||||
public String toJson() throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.writeValueAsString(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.mowesta.android.app.arduino;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.wifi.WifiNetworkSpecifier;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* The process to connect to the wifi network for Android Q using
|
||||
* the new api exposed by the connectivity manager. For devices
|
||||
* that are running an Android version lower than Q, use the wifi
|
||||
* variant of the process.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
@TargetApi(29)
|
||||
public class ConnectivityTask extends NetworkTask {
|
||||
|
||||
/**
|
||||
* The log tag.
|
||||
*/
|
||||
private static final String TAG = "ConnectivityTask";
|
||||
|
||||
/**
|
||||
* The connectivity manager.
|
||||
*/
|
||||
private @NonNull ConnectivityManager manager;
|
||||
|
||||
/**
|
||||
* The callback as long as the request is running.
|
||||
*/
|
||||
private ConnectivityManager.NetworkCallback callback;
|
||||
|
||||
/**
|
||||
* A runnable that will destroy the request.
|
||||
*/
|
||||
private Runnable timeout = () -> {
|
||||
Log.d(TAG, "Wifi connection timeout expired.");
|
||||
abort(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new process.
|
||||
*
|
||||
* @param application The application.
|
||||
* @param listener The listener to keep track of changes.
|
||||
*/
|
||||
public ConnectivityTask(@NonNull Application application, @NonNull OnNetworkChangedListener listener) {
|
||||
super(application, listener);
|
||||
this.manager = (ConnectivityManager)application.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the network.
|
||||
*/
|
||||
private void connect() {
|
||||
WifiNetworkSpecifier.Builder specifier = new WifiNetworkSpecifier.Builder();
|
||||
specifier.setSsid(ArduinoConfig.ARDUINO_SSID);
|
||||
specifier.setWpa2Passphrase(ArduinoConfig.ARDUINO_PWD);
|
||||
NetworkRequest request = new NetworkRequest.Builder()
|
||||
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
|
||||
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||
.setNetworkSpecifier(specifier.build())
|
||||
.build();
|
||||
callback = new ConnectivityManager.NetworkCallback() {
|
||||
@Override
|
||||
public void onAvailable(@NonNull Network network) {
|
||||
super.onAvailable(network);
|
||||
manager.bindProcessToNetwork(network);
|
||||
handler.removeCallbacks(timeout);
|
||||
handler.post(() -> listener.onNetworkChanged(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLost(@NonNull Network network) {
|
||||
super.onLost(network);
|
||||
handler.postDelayed(timeout, ABORT_TIMEOUT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnavailable() {
|
||||
super.onUnavailable();
|
||||
handler.postDelayed(timeout, ABORT_TIMEOUT);
|
||||
}
|
||||
};
|
||||
manager.requestNetwork(request, callback);
|
||||
handler.postDelayed(timeout, NETWORK_TIMEOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aborts the process.
|
||||
*/
|
||||
public void cancel() {
|
||||
abort(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aborts the request and optionally signals the network
|
||||
* as being unavailable.
|
||||
*
|
||||
* @param signal True to signal the failure to the network
|
||||
* listener.
|
||||
*/
|
||||
private void abort(boolean signal) {
|
||||
if (callback != null) {
|
||||
manager.unregisterNetworkCallback(callback);
|
||||
callback = null;
|
||||
}
|
||||
manager.bindProcessToNetwork(null);
|
||||
handler.removeCallbacks(timeout);
|
||||
if (signal) {
|
||||
listener.onNetworkChanged(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.mowesta.android.app.arduino;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* An abstract base class for networking processes that connect to
|
||||
* wifi.
|
||||
*/
|
||||
public abstract class NetworkTask {
|
||||
|
||||
/**
|
||||
* An interface for listeners that need to be informed, if
|
||||
* the network becomes available.
|
||||
*/
|
||||
public interface OnNetworkChangedListener {
|
||||
|
||||
/**
|
||||
* Called when the network becomes available or unavailable.
|
||||
*
|
||||
* @param available True, if available, false otherwise.
|
||||
*/
|
||||
void onNetworkChanged(boolean available);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the process, if we cannot connect after 60 seconds.
|
||||
*/
|
||||
public static final int NETWORK_TIMEOUT = 60000;
|
||||
|
||||
/**
|
||||
* Aborts the process after 10 seconds.
|
||||
*/
|
||||
public static final int ABORT_TIMEOUT = 10000;
|
||||
|
||||
/**
|
||||
* A reference to the application.
|
||||
*/
|
||||
protected @NonNull Application application;
|
||||
|
||||
/**
|
||||
* A reference to the listener.
|
||||
*/
|
||||
protected @NonNull OnNetworkChangedListener listener;
|
||||
|
||||
/**
|
||||
* A handler to register the timeout.
|
||||
*/
|
||||
protected @NonNull Handler handler = new Handler();
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new networking process.
|
||||
*
|
||||
* @param application The application.
|
||||
* @param listener The listener.
|
||||
*/
|
||||
public NetworkTask(@NonNull Application application, @NonNull OnNetworkChangedListener listener) {
|
||||
this.listener = listener;
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cancels the process without
|
||||
* signalling it to the listener.
|
||||
*/
|
||||
public abstract void cancel();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package com.mowesta.android.app.arduino;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.net.DhcpInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* A task to transfer the data to the arduino. The task first
|
||||
* waits for a few seconds
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class TransferTask {
|
||||
|
||||
/**
|
||||
* A listener to keep track of the completion.
|
||||
*/
|
||||
public interface OnCompletionListener {
|
||||
/**
|
||||
* Called when the process completes.
|
||||
*
|
||||
* @param success True to indicate success, false
|
||||
* to indicate a failure.
|
||||
*/
|
||||
void onCompletion(boolean success);
|
||||
}
|
||||
|
||||
/**
|
||||
* The tag for logging.
|
||||
*/
|
||||
private static final String TAG = "TransferTask";
|
||||
|
||||
/**
|
||||
* The configuration to transfer.
|
||||
*/
|
||||
@NonNull
|
||||
private ArduinoConfig config;
|
||||
|
||||
/**
|
||||
* The listener to call.
|
||||
*/
|
||||
@NonNull
|
||||
private OnCompletionListener listener;
|
||||
|
||||
/**
|
||||
* The canceled flag.
|
||||
*/
|
||||
private boolean canceled;
|
||||
|
||||
/**
|
||||
* The socket, if we are current transmitting.
|
||||
*/
|
||||
private Socket socket;
|
||||
|
||||
/**
|
||||
* The application.
|
||||
*/
|
||||
private Application application;
|
||||
|
||||
/**
|
||||
* The handler to post the result.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
|
||||
/**
|
||||
* Creates a new task.
|
||||
*
|
||||
* @param application The application.
|
||||
* @param config The config.
|
||||
* @param listener The listener.
|
||||
*/
|
||||
public TransferTask(@NonNull Application application, @NonNull ArduinoConfig config, @NonNull OnCompletionListener listener) {
|
||||
this.config = config;
|
||||
this.application = application;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the task.
|
||||
*/
|
||||
public synchronized void cancel() {
|
||||
this.canceled = true;
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the task.
|
||||
*/
|
||||
public void execute() {
|
||||
WifiManager manager = (WifiManager)application.getSystemService(Context.WIFI_SERVICE);
|
||||
AsyncTask.SERIAL_EXECUTOR.execute(() -> {
|
||||
try {
|
||||
// sleep for a couple of seconds, since it
|
||||
// will take some time to get an ip address
|
||||
try {
|
||||
int gateway = (192 & 0xff) << 24 | (168 & 0xff) << 16 | (4 & 0xff) << 8 | (1 & 0xff);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
DhcpInfo info = manager.getDhcpInfo();
|
||||
if (info == null || info.gateway != gateway) {
|
||||
Log.d(TAG, "Waiting for dhcp info.");
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Failed to wait.");
|
||||
}
|
||||
synchronized (TransferTask.this) {
|
||||
if (canceled) return;
|
||||
Log.d(TAG, "Create socket.");
|
||||
socket = new Socket(ArduinoConfig.ARDUINO_IP, ArduinoConfig.ARDUINO_PORT);
|
||||
}
|
||||
try {
|
||||
Log.d(TAG, "Write data.");
|
||||
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
|
||||
w.write(config.toJson());
|
||||
w.write("\n\n");
|
||||
w.flush();
|
||||
synchronized (TransferTask.this) {
|
||||
if (canceled) return;
|
||||
}
|
||||
Log.d(TAG, "Read data.");
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
boolean success = false;
|
||||
String line;
|
||||
while ((line = r.readLine()) != null) {
|
||||
if (line.length() == 0) {
|
||||
break;
|
||||
} else {
|
||||
Log.d(TAG, "Read line: " + line);
|
||||
success = success | line.toLowerCase(Locale.US).contains("success");
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "Post success: " + success);
|
||||
post(success);
|
||||
} finally {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "Exception while transferring data.", e);
|
||||
post(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts the success value, if not cancelled.
|
||||
*
|
||||
* @param success The success value.
|
||||
*/
|
||||
private void post(boolean success) {
|
||||
handler.post(()-> {
|
||||
if (!canceled) {
|
||||
listener.onCompletion(success);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
package com.mowesta.android.app.arduino;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Application;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The network process that connects automatically to the Arduino.
|
||||
* Note that this class is intended for devices that are running
|
||||
* Android versions below Q. For Q, use the connectivity manager
|
||||
* network process.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
@SuppressLint("Deprecation")
|
||||
@SuppressWarnings("deprecation")
|
||||
public class WifiTask extends NetworkTask {
|
||||
|
||||
/**
|
||||
* The log tag.
|
||||
*/
|
||||
private static final String TAG = "WifiTask";
|
||||
|
||||
/**
|
||||
* The manager.
|
||||
*/
|
||||
private @NonNull WifiManager manager;
|
||||
|
||||
/**
|
||||
* The timeout.
|
||||
*/
|
||||
private @NonNull Runnable timeout = () -> {
|
||||
Log.d(TAG, "Wifi connection timeout expired.");
|
||||
cancel(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* The receiver that is informed when the network state changes.
|
||||
*/
|
||||
private BroadcastReceiver stateChangeReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
|
||||
Log.d(TAG, "Received network state changed.");
|
||||
if (intent.hasExtra(WifiManager.EXTRA_NETWORK_INFO)) {
|
||||
android.net.NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||
if (info != null) {
|
||||
Log.d(TAG, "Received network info: " + info);
|
||||
if (info.isConnected() && isWifiConnected()) {
|
||||
Log.d(TAG, "Connected to the device network.");
|
||||
if (!didSignalSuccess) {
|
||||
Log.d(TAG, "Signaling success.");
|
||||
didSignalSuccess = true;
|
||||
listener.onNetworkChanged(true);
|
||||
handler.removeCallbacks(timeout);
|
||||
}
|
||||
} else if (didSignalSuccess && (!info.isConnected() || !isWifiConnected())) {
|
||||
Log.d(TAG, "Disconnected after connect, aborting.");
|
||||
handler.postDelayed(timeout, ABORT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Network state changed includes no network info, ignoring.");
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Received unexpected action: " + intent.getAction());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** A flag to memorize whether the stateChangeReceiver is registered. */
|
||||
private boolean stateChangeReceiverRegistered = false;
|
||||
|
||||
/**
|
||||
* The wifi configuration that we might have added, if any.
|
||||
*/
|
||||
private int networkId = -1;
|
||||
|
||||
/**
|
||||
* A flag to memorize whether we enabled wifi.
|
||||
*/
|
||||
private boolean didEnableWifi = false;
|
||||
|
||||
/**
|
||||
* A flag to memorize whether we already signaled success.
|
||||
*/
|
||||
private boolean didSignalSuccess = false;
|
||||
|
||||
/**
|
||||
* Creates a new task.
|
||||
*
|
||||
* @param application The application.
|
||||
* @param listener The listener.
|
||||
*/
|
||||
public WifiTask(@NonNull Application application, @NonNull OnNetworkChangedListener listener) {
|
||||
super(application, listener);
|
||||
manager = (WifiManager)application.getSystemService(Context.WIFI_SERVICE);
|
||||
connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the task starts to configure the wifi networks.
|
||||
*/
|
||||
private void connect() {
|
||||
try {
|
||||
if (! manager.isWifiEnabled()) {
|
||||
Log.d(TAG, "Wifi was disabled, turning it on.");
|
||||
didEnableWifi = manager.setWifiEnabled(true);
|
||||
}
|
||||
android.net.wifi.WifiConfiguration existing = findConfiguration();
|
||||
if (existing == null) {
|
||||
networkId = manager.addNetwork(createConfiguration());
|
||||
manager.saveConfiguration();
|
||||
}
|
||||
stateChangeReceiverRegistered = true;
|
||||
application.registerReceiver(stateChangeReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
|
||||
if (isWifiConnected()) {
|
||||
Log.d(TAG, "Wifi was connected already.");
|
||||
didSignalSuccess = true;
|
||||
listener.onNetworkChanged(true);
|
||||
} else {
|
||||
Log.d(TAG, "Wifi network is wrong, trigger detection.");
|
||||
manager.disconnect();
|
||||
if (existing != null) {
|
||||
manager.enableNetwork(existing.networkId, true);
|
||||
} else {
|
||||
manager.enableNetwork(networkId, true);
|
||||
}
|
||||
manager.reconnect();
|
||||
}
|
||||
handler.postDelayed(timeout, NETWORK_TIMEOUT);
|
||||
} catch (SecurityException e) {
|
||||
Log.d(TAG, "Failed to connect due to security exception.", e);
|
||||
cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the network is connected to a mowesta device.
|
||||
*
|
||||
* @return True if connected, false otherwise.
|
||||
*/
|
||||
private boolean isWifiConnected() {
|
||||
WifiInfo info = manager.getConnectionInfo();
|
||||
if (info != null) {
|
||||
Log.d(TAG, "Connected to network: " + info.getSSID());
|
||||
return getSsid().equals(info.getSSID());
|
||||
} else {
|
||||
Log.d(TAG, "Not connected to network.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the maximum network priority.
|
||||
*
|
||||
* @return The maximum network priority.
|
||||
* @throws SecurityException Thrown if we are missing a permission.
|
||||
*/
|
||||
private int getMaximumPriority() throws SecurityException {
|
||||
int result = 1;
|
||||
List<android.net.wifi.WifiConfiguration> configurations = manager.getConfiguredNetworks();
|
||||
for (android.net.wifi.WifiConfiguration configuration: configurations) {
|
||||
result = Math.max(result, configuration.priority);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the mowesta network configuration, if present.
|
||||
*
|
||||
* @return The network configuration, if present already.
|
||||
* @throws SecurityException Thrown if we are missing a permission.
|
||||
*/
|
||||
private android.net.wifi.WifiConfiguration findConfiguration() throws SecurityException {
|
||||
String ssid = getSsid();
|
||||
List<android.net.wifi.WifiConfiguration> configurations = manager.getConfiguredNetworks();
|
||||
for (android.net.wifi.WifiConfiguration configuration: configurations) {
|
||||
if (ssid.equals(configuration.SSID)) {
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the network configuration for a wpa2 wifi network.
|
||||
*
|
||||
* @return The network configuration.
|
||||
*/
|
||||
private android.net.wifi.WifiConfiguration createConfiguration() {
|
||||
android.net.wifi.WifiConfiguration result = new android.net.wifi.WifiConfiguration();
|
||||
result.SSID = getSsid();
|
||||
result.allowedAuthAlgorithms.set(android.net.wifi.WifiConfiguration.AuthAlgorithm.OPEN);
|
||||
result.allowedProtocols.set(android.net.wifi.WifiConfiguration.Protocol.RSN); // For WPA2
|
||||
result.allowedKeyManagement.set(android.net.wifi.WifiConfiguration.KeyMgmt.WPA_PSK);
|
||||
result.allowedKeyManagement.set(android.net.wifi.WifiConfiguration.KeyMgmt.WPA_EAP);
|
||||
result.allowedPairwiseCiphers.set(android.net.wifi.WifiConfiguration.PairwiseCipher.TKIP);
|
||||
result.allowedPairwiseCiphers.set(android.net.wifi.WifiConfiguration.PairwiseCipher.CCMP);
|
||||
result.allowedGroupCiphers.set(android.net.wifi.WifiConfiguration.GroupCipher.TKIP);
|
||||
result.allowedGroupCiphers.set(android.net.wifi.WifiConfiguration.GroupCipher.CCMP);
|
||||
result.preSharedKey = String.format("\"%s\"", ArduinoConfig.ARDUINO_PWD);
|
||||
result.status = android.net.wifi.WifiConfiguration.Status.ENABLED;
|
||||
try {
|
||||
int priority = getMaximumPriority() + 400;
|
||||
Log.d(TAG, "Setting maximum priority to " + priority + ".");
|
||||
result.priority = priority;
|
||||
} catch (SecurityException e) {
|
||||
Log.d(TAG, "Failed to get priority, using default value.", e);
|
||||
result.priority = 500;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the mowesta wifi configuration, if we have added it.
|
||||
*/
|
||||
private void removeConfiguration() {
|
||||
if (networkId != -1) {
|
||||
manager.removeNetwork(networkId);
|
||||
manager.saveConfiguration();
|
||||
networkId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the network listener.
|
||||
*/
|
||||
private void removeStateChangeReceiver() {
|
||||
if (stateChangeReceiverRegistered) {
|
||||
application.unregisterReceiver(stateChangeReceiver);
|
||||
stateChangeReceiverRegistered = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables wifi, if we enabled it.
|
||||
*/
|
||||
private void disableWifi() {
|
||||
if (didEnableWifi) {
|
||||
manager.setWifiEnabled(false);
|
||||
didEnableWifi = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ssid of the mowesta device.
|
||||
*
|
||||
* @return The ssid.
|
||||
*/
|
||||
private String getSsid() {
|
||||
return String.format("\"%s\"", ArduinoConfig.ARDUINO_SSID);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
cancel(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the process and optionally signals it.
|
||||
*
|
||||
* @param signal True to signal the event.
|
||||
*/
|
||||
private void cancel(boolean signal) {
|
||||
removeConfiguration();
|
||||
removeStateChangeReceiver();
|
||||
disableWifi();
|
||||
handler.removeCallbacks(timeout);
|
||||
if (signal) {
|
||||
listener.onNetworkChanged(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-18
@@ -10,6 +10,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
|
||||
@@ -30,13 +31,15 @@ public abstract class AbstractDiagramFragment extends AbstractNetworkFragment {
|
||||
* A preference listener that is running as long as we are resumed.
|
||||
*/
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener unitListener = (prefs, key) -> {
|
||||
if (MowestaSettings.TEMPERATURE_CELSIUS.equals(key)) onUnitChanged();
|
||||
if (MowestaSettings.TEMPERATURE_UNIT.equals(key) || MowestaSettings.UNIT_SYSTEM.equals(key)) {
|
||||
onRefreshDiagram();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
settings = new MowestaSettings(getActivity().getApplication());
|
||||
settings = ((IApp)getContext().getApplicationContext()).getSettings();
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
@@ -45,7 +48,7 @@ public abstract class AbstractDiagramFragment extends AbstractNetworkFragment {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
settings.getPreferences().registerOnSharedPreferenceChangeListener(unitListener);
|
||||
onUnitChanged();
|
||||
onRefreshDiagram();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,31 +61,27 @@ public abstract class AbstractDiagramFragment extends AbstractNetworkFragment {
|
||||
* Called whenever the unit changes. Subclasses may overwrite this,
|
||||
* but should call through to super.
|
||||
*/
|
||||
public void onUnitChanged() {
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
public abstract void onRefreshDiagram();
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_unit, menu);
|
||||
boolean celsius = settings.isTemperatureCelsius();
|
||||
menu.findItem(R.id.unit_celsius).setVisible(celsius);
|
||||
menu.findItem(R.id.unit_fahrenheit).setVisible(!celsius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.unit_fahrenheit:
|
||||
settings.setTemperatureCelsius(true);
|
||||
return true;
|
||||
case R.id.unit_celsius:
|
||||
settings.setTemperatureCelsius(false);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.action_unit_system) {
|
||||
UnitSystemDialogFragment system = new UnitSystemDialogFragment();
|
||||
system.show(getChildFragmentManager(), "system");
|
||||
return true;
|
||||
} else if (itemId == R.id.action_temperature_unit) {
|
||||
TemperatureUnitDialogFragment unit = new TemperatureUnitDialogFragment();
|
||||
unit.show(getChildFragmentManager(), "unit");
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+13
-13
@@ -82,19 +82,19 @@ public abstract class AbstractPlaceFragment extends AbstractNetworkFragment {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_favorite_add:
|
||||
getPlaceViewModel().addFavorite();
|
||||
return true;
|
||||
case R.id.action_favorite_remove:
|
||||
getPlaceViewModel().removeFavorite();
|
||||
return true;
|
||||
case R.id.action_wikipedia:
|
||||
openWikipedia();
|
||||
return true;
|
||||
case R.id.action_google_maps:
|
||||
openGoogleMaps();
|
||||
return true;
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.action_favorite_add) {
|
||||
getPlaceViewModel().addFavorite();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_favorite_remove) {
|
||||
getPlaceViewModel().removeFavorite();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_wikipedia) {
|
||||
openWikipedia();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_google_maps) {
|
||||
openGoogleMaps();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+166
-17
@@ -1,10 +1,8 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -14,6 +12,8 @@ import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
@@ -25,7 +25,10 @@ import com.mowesta.android.app.databinding.ViewSummaryBinding;
|
||||
import com.mowesta.android.app.databinding.ViewConditionBinding;
|
||||
import com.mowesta.android.app.model.CityViewModel;
|
||||
import com.mowesta.android.app.model.ConditionViewModel;
|
||||
import com.mowesta.android.app.model.CustomizeViewModel;
|
||||
import com.mowesta.android.app.model.SummaryViewModel;
|
||||
import com.mowesta.android.app.util.TabletUtil;
|
||||
import com.mowesta.android.feign.model.WeatherCondition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -49,14 +52,33 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
ViewPager2 pager = view.findViewById(R.id.pager);
|
||||
CityViewModel model = getCityViewModel();
|
||||
pager.setAdapter(new ForecastAdapter(this));
|
||||
TabLayout tabs = view.findViewById(R.id.tabs);
|
||||
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
|
||||
if (request != null) {
|
||||
switch (request.getType()) {
|
||||
case DAY:
|
||||
pager.setCurrentItem(1, true);
|
||||
break;
|
||||
case TIME:
|
||||
pager.setCurrentItem(2, true);
|
||||
break;
|
||||
case HOUR:
|
||||
pager.setCurrentItem(3, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
TabLayout tabs = getActivity().findViewById(R.id.tabs);
|
||||
new TabLayoutMediator(tabs, pager, (tab, position) -> {
|
||||
switch (position) {
|
||||
case 0:
|
||||
tab.setText(R.string.city_info_day);
|
||||
tab.setText(R.string.city_info_gradient);
|
||||
break;
|
||||
case 1:
|
||||
tab.setText(R.string.city_info_day);
|
||||
break;
|
||||
case 2:
|
||||
tab.setText(R.string.city_info_time);
|
||||
break;
|
||||
default:
|
||||
@@ -81,16 +103,20 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
ForecastRecyclerFragment fragment = new ForecastRecyclerFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("page", position);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
if (position == 0) {
|
||||
return new CityGradientFragment();
|
||||
} else {
|
||||
ForecastRecyclerFragment fragment = new ForecastRecyclerFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("page", position - 1);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +129,9 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
*/
|
||||
public static class ForecastRecyclerFragment extends CityFragment.ChildFragment {
|
||||
|
||||
/** A handler to post updates. */
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@@ -118,18 +147,119 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
int page = getArguments().getInt("page");
|
||||
switch (page) {
|
||||
case 0:
|
||||
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), getCityViewModel().getDay()));
|
||||
TabletUtil.setGridLayout(recyclerView, 400);
|
||||
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), model.getDay(), (summary) -> {
|
||||
if (summary == null || summary.getFirstCondition() == null) return;
|
||||
long time = summary.getFirstCondition().getTime();
|
||||
List<SummaryViewModel> models = model.getTime().getValue();
|
||||
for (int i = 0; i < models.size(); i++) {
|
||||
SummaryViewModel s = models.get(i);
|
||||
if (s.getFirstCondition() != null && s.getFirstCondition().getTime() == time) {
|
||||
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.ForecastType.TIME, i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}));
|
||||
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
|
||||
if (request == null) return;
|
||||
if (request.getType() == CityViewModel.ForecastType.DAY) {
|
||||
recyclerView.post(() -> {
|
||||
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
|
||||
model.getNavigation().setValue(null);
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 1:
|
||||
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), getCityViewModel().getTime()));
|
||||
TabletUtil.setGridLayout(recyclerView, 400);
|
||||
recyclerView.setAdapter(new SummaryAdapter(getViewLifecycleOwner(), model.getTime(), (summary) -> {
|
||||
if (summary == null || summary.getFirstCondition() == null) return;
|
||||
long time = summary.getFirstCondition().getTime();
|
||||
List<ConditionViewModel> models = model.getHour().getValue();
|
||||
for (int i = 0; i < models.size(); i++) {
|
||||
ConditionViewModel c = models.get(i);
|
||||
WeatherCondition wc = c.getCondition().getValue();
|
||||
if (wc != null && wc.getTime() == time) {
|
||||
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.ForecastType.HOUR, i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}));
|
||||
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
|
||||
if (request == null) return;
|
||||
if (request.getType() == CityViewModel.ForecastType.TIME) {
|
||||
recyclerView.post(() -> {
|
||||
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
|
||||
model.getNavigation().setValue(null);
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
recyclerView.setAdapter(new ConditionAdapter(getViewLifecycleOwner(), getCityViewModel().getHour()));
|
||||
TabletUtil.setGridLayout(recyclerView, 300);
|
||||
recyclerView.setAdapter(new ConditionAdapter(getViewLifecycleOwner(), getCityViewModel().getHour(), (condition) -> {
|
||||
if (condition == null || condition.getCondition().getValue() == null) return;
|
||||
long time = condition.getCondition().getValue().getTime();
|
||||
List<SummaryViewModel> models = model.getDay().getValue();
|
||||
for (int i = 0; i < models.size(); i++) {
|
||||
SummaryViewModel s = models.get(i);
|
||||
if (s.getFirstCondition() != null && s.getLastCondition() != null
|
||||
&& s.getLastCondition().getTime() >= time && s.getFirstCondition().getTime() <= time) {
|
||||
model.getNavigation().setValue(new CityViewModel.NavigationRequest(CityViewModel.ForecastType.DAY, i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}));
|
||||
model.getNavigation().observe(getViewLifecycleOwner(), (request) -> {
|
||||
if (request == null) return;
|
||||
if (request.getType() == CityViewModel.ForecastType.HOUR) {
|
||||
recyclerView.post(() -> {
|
||||
scrollRecyclerViewToPosition(recyclerView, request.getPosition());
|
||||
model.getNavigation().setValue(null);
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Customization
|
||||
CustomizeViewModel customize = new ViewModelProvider(getActivity()).get(CustomizeViewModel.class);
|
||||
customize.getTemperatureUnit().observe(getViewLifecycleOwner(), (v) -> updateRecycler(recyclerView) );
|
||||
customize.getUnitSystem().observe(getViewLifecycleOwner(), (v) -> updateRecycler(recyclerView) );
|
||||
}
|
||||
|
||||
private void updateRecycler(RecyclerView view) {
|
||||
int count = view.getAdapter().getItemCount();
|
||||
if (count > 0) {
|
||||
view.getAdapter().notifyItemRangeChanged(0, count);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls a recycler view to the specified position using a smooth scroll effect
|
||||
* that ist limited in motion.
|
||||
*
|
||||
* @param view The view.
|
||||
* @param position The position.
|
||||
*/
|
||||
private static void scrollRecyclerViewToPosition(RecyclerView view, int position) {
|
||||
GridLayoutManager layout = (GridLayoutManager)view.getLayoutManager();
|
||||
int current = layout.findFirstVisibleItemPosition();
|
||||
int last = layout.findLastVisibleItemPosition();
|
||||
int diff = Math.max(1, last - current) * 3;
|
||||
if (Math.abs(current - position) > diff) {
|
||||
if (current < position) current = position - diff;
|
||||
else current = position + diff;
|
||||
}
|
||||
view.scrollToPosition(current);
|
||||
view.post(() -> {
|
||||
view.smoothScrollToPosition(position);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A recycler view adapter that can display a list of weather summaries.
|
||||
*
|
||||
@@ -145,10 +275,22 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
* The live data that provides updates.
|
||||
*/
|
||||
private LiveData<List<SummaryViewModel>> model;
|
||||
/**
|
||||
* The click listener for the summary model.
|
||||
*/
|
||||
private SummaryViewModel.OnSummarySelectedListener listener;
|
||||
|
||||
public SummaryAdapter(LifecycleOwner lifecycleOwner, LiveData<List<SummaryViewModel>> model) {
|
||||
/**
|
||||
* Creates a new adapter.
|
||||
*
|
||||
* @param lifecycleOwner The lifecycle owner.
|
||||
* @param model The model to observe.
|
||||
* @param listener The listener to handle clicks.
|
||||
*/
|
||||
public SummaryAdapter(LifecycleOwner lifecycleOwner, LiveData<List<SummaryViewModel>> model, SummaryViewModel.OnSummarySelectedListener listener) {
|
||||
this.lifecycleOwner = lifecycleOwner;
|
||||
this.model = model;
|
||||
this.listener = listener;
|
||||
this.model.observe(lifecycleOwner, (data)-> {
|
||||
this.notifyDataSetChanged();
|
||||
});
|
||||
@@ -159,6 +301,7 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
public SummaryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
ViewSummaryBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.view_summary, parent, false);
|
||||
binding.setLifecycleOwner(lifecycleOwner);
|
||||
binding.setListener(listener);
|
||||
SummaryViewHolder holder = new SummaryViewHolder(binding);
|
||||
return holder;
|
||||
}
|
||||
@@ -226,15 +369,21 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
*/
|
||||
private LiveData<List<ConditionViewModel>> model;
|
||||
|
||||
/**
|
||||
* The listener for the cards.
|
||||
*/
|
||||
private ConditionViewModel.OnConditionSelectedListener listener;
|
||||
|
||||
/**
|
||||
* Creates a new adapter for weather conditions.
|
||||
*
|
||||
* @param lifecycleOwner The lifecycle owner.
|
||||
* @param model The list of weather conditions to show.
|
||||
*/
|
||||
public ConditionAdapter(LifecycleOwner lifecycleOwner, LiveData<List<ConditionViewModel>> model) {
|
||||
public ConditionAdapter(LifecycleOwner lifecycleOwner, LiveData<List<ConditionViewModel>> model, ConditionViewModel.OnConditionSelectedListener listener) {
|
||||
this.lifecycleOwner = lifecycleOwner;
|
||||
this.model = model;
|
||||
this.listener = listener;
|
||||
this.model.observe(lifecycleOwner, (data)-> {
|
||||
this.notifyDataSetChanged();
|
||||
});
|
||||
@@ -245,6 +394,7 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
public ConditionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
ViewConditionBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.view_condition, parent, false);
|
||||
binding.setLifecycleOwner(lifecycleOwner);
|
||||
binding.setListener(listener);
|
||||
ConditionViewHolder holder = new ConditionViewHolder(binding);
|
||||
return holder;
|
||||
}
|
||||
@@ -283,5 +433,4 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -85,16 +85,14 @@ public class CityFragment extends AbstractPlaceFragment {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_customize:
|
||||
getChildFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(new CustomizeDialogFragment(), "customize")
|
||||
.commit();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
if (item.getItemId() == R.id.action_customize) {
|
||||
getChildFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(new CustomizeDialogFragment(), "customize")
|
||||
.commit();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.databinding.FragmentGradientBinding;
|
||||
import com.mowesta.android.app.model.CustomizeViewModel;
|
||||
import com.mowesta.android.app.util.DateFormatter;
|
||||
import com.mowesta.android.app.util.TimeUtils;
|
||||
import com.mowesta.android.app.view.DataView;
|
||||
import com.mowesta.android.app.view.TimeView;
|
||||
import com.mowesta.android.app.view.color.CloudDepthColorScheme;
|
||||
import com.mowesta.android.app.view.color.HumidityColorScheme;
|
||||
import com.mowesta.android.app.view.color.PrecipitationColorScheme;
|
||||
import com.mowesta.android.app.view.color.PressureColorScheme;
|
||||
import com.mowesta.android.app.view.color.ScientificTemperatureColorScheme;
|
||||
import com.mowesta.android.app.view.color.WhiteCloudColorScheme;
|
||||
import com.mowesta.android.feign.model.WeatherCondition;
|
||||
|
||||
/**
|
||||
* The fragment to show the overview as a bunch of gradients.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class CityGradientFragment extends CityFragment.ChildFragment {
|
||||
|
||||
/**
|
||||
* The timeout after which we reset the view.
|
||||
*/
|
||||
private static final int TIMEOUT_REMOVER = 10000;
|
||||
|
||||
/**
|
||||
* The view binding.
|
||||
*/
|
||||
private FragmentGradientBinding binding;
|
||||
|
||||
/**
|
||||
* The time utilities.
|
||||
*/
|
||||
private TimeUtils timeUtils = new TimeUtils(System.currentTimeMillis(), null);
|
||||
|
||||
/**
|
||||
* The view pager of the parent.
|
||||
*/
|
||||
private ViewPager2 pager;
|
||||
|
||||
/**
|
||||
* The date formatter.
|
||||
*/
|
||||
private DateFormatter dateFormatter;
|
||||
|
||||
/**
|
||||
* The handler to post the removal of
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
|
||||
/**
|
||||
* The animator for the progress bar.
|
||||
*/
|
||||
private ValueAnimator animator;
|
||||
|
||||
/**
|
||||
* The weather condition to display as text.
|
||||
*/
|
||||
private WeatherCondition condition = new WeatherCondition();
|
||||
|
||||
private boolean closed = false;
|
||||
|
||||
private Runnable remover = () -> {
|
||||
updateSelection(null);
|
||||
animator.cancel();
|
||||
binding.gradientText.setVisibility(View.GONE);
|
||||
};
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
dateFormatter = new DateFormatter(getContext());
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_gradient, container, false);
|
||||
// this is quite ugly, but we need to disable the view pager and collapse the toolbar
|
||||
pager = getActivity().findViewById(R.id.pager);
|
||||
AppBarLayout layout = getActivity().findViewById(R.id.layout_appbar);
|
||||
binding.gradientProgress1.setMax(TIMEOUT_REMOVER);
|
||||
binding.gradientProgress2.setMax(TIMEOUT_REMOVER);
|
||||
animator = ValueAnimator.ofInt(TIMEOUT_REMOVER, 0);
|
||||
animator.setInterpolator(new LinearInterpolator());
|
||||
animator.setDuration(TIMEOUT_REMOVER);
|
||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation){
|
||||
int value = (Integer)animation.getAnimatedValue();
|
||||
binding.gradientProgress1.setProgress(value);
|
||||
binding.gradientProgress2.setProgress(value);
|
||||
binding.gradientText.setAlpha(Math.min(1, Math.max(0, value / 1000f)));
|
||||
}
|
||||
});
|
||||
binding.gradientScroll.setOnTouchListener(binding.gradientTouch.createOnTouchListener(new TimeView.OnSlideListener() {
|
||||
@Override
|
||||
public void onSlide(float relative) {
|
||||
if (!hasData()) return;
|
||||
animator.cancel();
|
||||
binding.gradientProgress1.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientProgress2.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientText.setAlpha(1);
|
||||
handler.removeCallbacks(remover);
|
||||
if (!closed) {
|
||||
layout.setExpanded(false, true);
|
||||
closed = true;
|
||||
}
|
||||
pager.setUserInputEnabled(false);
|
||||
updateSelection(relative);
|
||||
updateCondition(relative);
|
||||
binding.gradientText.setVisibility(View.VISIBLE);
|
||||
updateGuide(relative);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlideEnd() {
|
||||
pager.setUserInputEnabled(true);
|
||||
closed = false;
|
||||
animator.start();
|
||||
handler.postDelayed(remover, TIMEOUT_REMOVER);
|
||||
}
|
||||
}));
|
||||
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
binding.gradientText.setVisibility(View.GONE);
|
||||
binding.gradientTemperature.setColorScheme(new ScientificTemperatureColorScheme());
|
||||
binding.gradientCloud.setColorScheme(new WhiteCloudColorScheme());
|
||||
binding.gradientCloud.setSecondaryColorScheme(new CloudDepthColorScheme());
|
||||
binding.gradientPreciptiation.setColorScheme(new PrecipitationColorScheme());
|
||||
binding.gradientHumidity.setColorScheme(new HumidityColorScheme());
|
||||
getCityViewModel().getHour().observe(getViewLifecycleOwner(), (list) -> {
|
||||
if (list == null) return;
|
||||
int housrs = 0;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
housrs += list.get(i).getCondition().getValue().getDuration();
|
||||
}
|
||||
Double[] temp = new Double[housrs];
|
||||
Double[] cloud = new Double[housrs];
|
||||
Double[] depth = new Double[housrs];
|
||||
Double[] prec = new Double[housrs];
|
||||
Double[] pres = new Double[housrs];
|
||||
Double[] wind = new Double[housrs];
|
||||
Double[] hum = new Double[housrs];
|
||||
Long[] hours = new Long[housrs];
|
||||
int index = 0;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
WeatherCondition wc = list.get(i).getCondition().getValue();
|
||||
for (int j = 0; j < wc.getDuration(); j++) {
|
||||
temp[index] = wc.getTemperature();
|
||||
cloud[index] = wc.getCloudCoverage();
|
||||
prec[index] = wc.getPrecipitation();
|
||||
pres[index] = wc.getPressure();
|
||||
depth[index] = wc.getCloudDepth();
|
||||
wind[index] = wc.getWindSpeed();
|
||||
hum[index] = wc.getHumidity();
|
||||
hours[index] = wc.getTime() + j * 3600000;
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
binding.gradientCloud.setSecondaryData(depth);
|
||||
binding.gradientTemperature.setData(temp);
|
||||
binding.gradientPressure.setData(pres);
|
||||
binding.gradientCloud.setData(cloud);
|
||||
binding.gradientPreciptiation.setData(prec);
|
||||
binding.gradientWindSpeed.setData(wind);
|
||||
binding.gradientHumidity.setData(hum);
|
||||
binding.gradientTouch.setData(hours);
|
||||
});
|
||||
getCityViewModel().getForecast().observe(getViewLifecycleOwner(), (forecast) -> {
|
||||
if (forecast != null) {
|
||||
// 1013,25 hPa * [ 1 − 6,5 * Höhe / (288150 m) ]5,255
|
||||
double avg = 1013.25 * Math.pow(1 - 6.5 * forecast.getSurfaceHeight() / 288150.0, 5.255);
|
||||
binding.gradientPressure.setColorScheme(new PressureColorScheme(avg, avg - 20, avg + 10));
|
||||
}
|
||||
});
|
||||
getCityViewModel().getCity().observe(getViewLifecycleOwner(), (city) -> {
|
||||
if (city != null) {
|
||||
binding.gradientTouch.setTimezone(city.getTimezone());
|
||||
timeUtils = new TimeUtils(System.currentTimeMillis(), city.getTimezone());
|
||||
}
|
||||
});
|
||||
// observe changes to the settings that affect us
|
||||
CustomizeViewModel customizeViewModel = new ViewModelProvider(this).get(CustomizeViewModel.class);
|
||||
customizeViewModel.getTemperatureUnit().observe(getViewLifecycleOwner(), (u)-> {
|
||||
Float selection = binding.gradientTouch.getSelection();
|
||||
if (selection != null) updateCondition(selection);
|
||||
});
|
||||
customizeViewModel.getUnitSystem().observe(getViewLifecycleOwner(), (s) -> {
|
||||
Float selection = binding.gradientTouch.getSelection();
|
||||
if (selection != null) updateCondition(selection);
|
||||
});
|
||||
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private boolean hasData() {
|
||||
return binding.gradientTouch.getData() != null && binding.gradientTouch.getData().length > 0;
|
||||
}
|
||||
|
||||
private void updateSelection(Float selection) {
|
||||
binding.gradientTemperature.setSelection(selection);
|
||||
binding.gradientWindSpeed.setSelection(selection);
|
||||
binding.gradientPreciptiation.setSelection(selection);
|
||||
binding.gradientHumidity.setSelection(selection);
|
||||
binding.gradientPressure.setSelection(selection);
|
||||
binding.gradientCloud.setSelection(selection);
|
||||
binding.gradientTouch.setSelection(selection);
|
||||
}
|
||||
|
||||
private void updateCondition(float selection) {
|
||||
long time = binding.gradientTouch.getDataAt(selection);
|
||||
condition.setTime(time);
|
||||
condition.setWindSpeed(binding.gradientWindSpeed.getDataAt(selection));
|
||||
condition.setPrecipitation(binding.gradientPreciptiation.getDataAt(selection));
|
||||
condition.setHumidity(binding.gradientHumidity.getDataAt(selection));
|
||||
condition.setPressure(binding.gradientPressure.getDataAt(selection));
|
||||
condition.setCloudCoverage(binding.gradientCloud.getDataAt(selection));
|
||||
condition.setTemperature(binding.gradientTemperature.getDataAt(selection));
|
||||
String day = timeUtils.getDayName(getContext(), time);
|
||||
String hour = dateFormatter.asTime(time, binding.gradientTouch.getTimezone());
|
||||
binding.gradientTime.setText(getString(R.string.format_two_parts, day, hour));
|
||||
binding.setModel(condition);
|
||||
}
|
||||
|
||||
private void updateGuide(float relative) {
|
||||
float px = 64 * getResources().getDisplayMetrics().density;
|
||||
float max = 128 * getResources().getDisplayMetrics().density;
|
||||
int size = binding.gradientTouch.getDirection() == DataView.Direction.HORIZONTAL ?
|
||||
binding.gradientConstraint.getWidth():binding.gradientConstraint.getHeight();
|
||||
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams)binding.gradientText.getLayoutParams();
|
||||
float percent = size == 0 ? 0 : px / size;
|
||||
float delta = size == 0 ? 0 : max / size;
|
||||
if (binding.gradientTouch.getDirection() == DataView.Direction.VERTICAL) {
|
||||
if (relative - delta < 0) {
|
||||
binding.guideGradient.setGuidelinePercent(relative + 2 * percent);
|
||||
params.bottomToTop = -1;
|
||||
params.topToBottom = R.id.guide_gradient;
|
||||
} else {
|
||||
binding.guideGradient.setGuidelinePercent(relative - percent);
|
||||
params.topToBottom = -1;
|
||||
params.bottomToTop = R.id.guide_gradient;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (relative > 0.5) {
|
||||
binding.guideGradient.setGuidelinePercent(relative - percent);
|
||||
params.leftToLeft = -1;
|
||||
params.rightToRight = R.id.guide_gradient;
|
||||
} else {
|
||||
binding.guideGradient.setGuidelinePercent(relative + percent);
|
||||
params.leftToLeft = R.id.guide_gradient;
|
||||
params.rightToRight = -1;
|
||||
}
|
||||
}
|
||||
binding.gradientText.setLayoutParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
handler.removeCallbacks(remover);
|
||||
remover.run();
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
FragmentCityInfoBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_city_info, container, false);
|
||||
MapView mapView = binding.getRoot().findViewById(R.id.map_detail);
|
||||
MapViewUtil.setupInteractiveMap(mapView);
|
||||
MapViewUtil.setupInteractiveMap(mapView, getResources().getBoolean(R.bool.dark_mode));
|
||||
CityViewModel model = new ViewModelProvider(getParentFragment().getParentFragment()).get(CityViewModel.class);
|
||||
ConditionViewModel condition = new ViewModelProvider(this).get(ConditionViewModel.class);
|
||||
Runnable updateCondition = () -> {
|
||||
@@ -77,7 +77,9 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
|
||||
model.getBoundary().observe(getViewLifecycleOwner(), (b) -> updateMap.run());
|
||||
binding.setModel(model);
|
||||
binding.setCondition(condition);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
condition.getUnitSystem().observe(getViewLifecycleOwner(), (s) -> updateCondition.run());
|
||||
condition.getTemperatureUnit().observe(getViewLifecycleOwner(), (s) -> updateCondition.run());
|
||||
NavController appController = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
binding.setStationListener(new CityViewModel.OnStationSelectedListener() {
|
||||
@Override
|
||||
public void onStationSelected(WeatherStation station) {
|
||||
@@ -85,9 +87,13 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
|
||||
NavOptions.Builder opts = new NavOptions.Builder().setEnterAnim(R.anim.slide_in_right).setExitAnim(R.anim.slide_out_left);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong("id", station.getId());
|
||||
controller.navigate(R.id.destination_station, bundle, opts.build());
|
||||
appController.navigate(R.id.destination_station, bundle, opts.build());
|
||||
}
|
||||
});
|
||||
NavController cityController = Navigation.findNavController(getActivity(), R.id.navigation_city);
|
||||
binding.setConditionListener(m -> {
|
||||
cityController.navigate(R.id.destination_city_forecast);
|
||||
});
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -23,7 +24,9 @@ import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.databinding.ViewVideoBinding;
|
||||
import com.mowesta.android.app.model.CityViewModel;
|
||||
import com.mowesta.android.app.model.VideoViewModel;
|
||||
import com.mowesta.android.app.util.TabletUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -43,21 +46,33 @@ public class CityVideoFragment extends CityFragment.ChildFragment {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
ViewPager2 pager = view.findViewById(R.id.pager);
|
||||
pager.setAdapter(new VideoAdpter(this));
|
||||
TabLayout tabs = view.findViewById(R.id.tabs);
|
||||
new TabLayoutMediator(tabs, pager, (tab, position) -> {
|
||||
switch (position) {
|
||||
case 0:
|
||||
tab.setText(R.string.video_source_icon_global);
|
||||
break;
|
||||
case 1:
|
||||
tab.setText(R.string.video_source_icon_europe);
|
||||
break;
|
||||
default:
|
||||
tab.setText(R.string.video_source_cosmo_europe);
|
||||
break;
|
||||
}
|
||||
}).attach();
|
||||
List<Integer> pages = new ArrayList<>();
|
||||
CityViewModel model = getCityViewModel();
|
||||
Observer<List<VideoViewModel>> videoObserver = (v) -> {
|
||||
pages.clear();
|
||||
if (model.getIconGlobal().getValue().size() > 0) pages.add(0, 0);
|
||||
if (model.getIconEurope().getValue().size() > 0) pages.add(0, 1);
|
||||
if (model.getCosmoEurope().getValue().size() > 0) pages.add(0, 2);
|
||||
pager.setAdapter(new VideoAdpter(this, pages));
|
||||
new TabLayoutMediator(tabs, pager, (tab, position) -> {
|
||||
int page = pages.get(position);
|
||||
switch (page) {
|
||||
case 0:
|
||||
tab.setText(R.string.video_source_icon_global);
|
||||
break;
|
||||
case 1:
|
||||
tab.setText(R.string.video_source_icon_europe);
|
||||
break;
|
||||
default:
|
||||
tab.setText(R.string.video_source_cosmo_europe);
|
||||
break;
|
||||
}
|
||||
}).attach();
|
||||
};
|
||||
model.getCosmoEurope().observe(getViewLifecycleOwner(), videoObserver);
|
||||
model.getIconEurope().observe(getViewLifecycleOwner(), videoObserver);
|
||||
model.getIconGlobal().observe(getViewLifecycleOwner(), videoObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,8 +82,11 @@ public class CityVideoFragment extends CityFragment.ChildFragment {
|
||||
*/
|
||||
private static class VideoAdpter extends FragmentStateAdapter {
|
||||
|
||||
public VideoAdpter(@NonNull Fragment fragment) {
|
||||
private List<Integer> pages;
|
||||
|
||||
public VideoAdpter(@NonNull Fragment fragment, @NonNull List<Integer> pages) {
|
||||
super(fragment);
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -76,14 +94,14 @@ public class CityVideoFragment extends CityFragment.ChildFragment {
|
||||
public Fragment createFragment(int position) {
|
||||
VideoRecyclerFragment fragment = new VideoRecyclerFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("page", position);
|
||||
bundle.putInt("page", pages.get(position));
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 3;
|
||||
return pages.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +123,7 @@ public class CityVideoFragment extends CityFragment.ChildFragment {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
RecyclerView recyclerView = getView().findViewById(R.id.recycler);
|
||||
TabletUtil.setGridLayout(recyclerView, 400);
|
||||
CityViewModel model = getCityViewModel();
|
||||
int page = getArguments().getInt("page");
|
||||
VideoViewModel.OnVideoSelectedListener listener = (video) -> {
|
||||
|
||||
@@ -23,6 +23,7 @@ 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;
|
||||
@@ -61,7 +62,7 @@ public class CollectionFragment extends Fragment {
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.settings = new MowestaSettings(getActivity().getApplication());
|
||||
this.settings = ((IApp)getContext().getApplicationContext()).getSettings();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -87,9 +88,11 @@ public class CollectionFragment extends Fragment {
|
||||
// add a funky animation
|
||||
if (savedInstanceState == null) {
|
||||
List<View> views = new ArrayList<>();
|
||||
views.add(binding.collectionNotePermission);
|
||||
views.add(binding.collectionNoteLocation);
|
||||
views.add(binding.collectionNoteData);
|
||||
views.add(binding.collectionNoteEnable);
|
||||
views.add(binding.privacyMeasureSwitch);
|
||||
views.add(binding.collectionNotePermission);
|
||||
views.add(binding.buttonContinue);
|
||||
AnimatorSet set = new AnimatorSet();
|
||||
ObjectAnimator first = ObjectAnimator.ofFloat(binding.logoSun, "translationY", DisplayUtils.dpToPixels(getContext(), 90), 0f);
|
||||
@@ -109,7 +112,7 @@ public class CollectionFragment extends Fragment {
|
||||
}
|
||||
set.start();
|
||||
}
|
||||
return binding.getRoot();
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,302 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewPropertyAnimator;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.animation.AnimationSet;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.widget.ImageViewCompat;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.NavOptions;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.databinding.FragmentConnectBinding;
|
||||
import com.mowesta.android.app.model.ConnectViewModel;
|
||||
import com.mowesta.android.app.util.DisplayUtils;
|
||||
import com.mowesta.android.feign.model.DeviceHandle;
|
||||
|
||||
/**
|
||||
* The fragment to connect a weather station which primarily shows a progress
|
||||
* animation while the process is running in the view model.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class ConnectFragment extends Fragment {
|
||||
|
||||
/**
|
||||
* The arguments for this fragment, provided by the setup fragment
|
||||
* and forwarded to the view model.
|
||||
*/
|
||||
public static class Args {
|
||||
|
||||
/** The longitude. **/
|
||||
private double longitude;
|
||||
/** The latitude. **/
|
||||
private double latitude;
|
||||
/** The wifi ssid. **/
|
||||
private String network;
|
||||
/** The wifi password. **/
|
||||
private String password;
|
||||
/** The device name. **/
|
||||
private String device;
|
||||
|
||||
/**
|
||||
* Creates a new set of arguments.
|
||||
*
|
||||
* @param device The device.
|
||||
* @param network The network.
|
||||
* @param password The password.
|
||||
* @param longitude The longitude.
|
||||
* @param latitude The latitude.
|
||||
*/
|
||||
public Args(String device, String network, String password, double longitude, double latitude) {
|
||||
this.device = device;
|
||||
this.network = network;
|
||||
this.password = password;
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the latitude.
|
||||
*
|
||||
* @return The latitude.
|
||||
*/
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the longitude.
|
||||
*
|
||||
* @return The longitude.
|
||||
*/
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the device name.
|
||||
*
|
||||
* @return The device name.
|
||||
*/
|
||||
public String getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the network name.
|
||||
*
|
||||
* @return The network name.
|
||||
*/
|
||||
public String getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the network password.
|
||||
*
|
||||
* @return The network password.
|
||||
*/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a bundle from the arguments.
|
||||
*
|
||||
* @return A bundle from the arguments.
|
||||
*/
|
||||
public @NonNull Bundle asBundle() {
|
||||
Bundle result = new Bundle();
|
||||
result.putDouble("longitude", longitude);
|
||||
result.putDouble("latitude", latitude);
|
||||
result.putString("network", network);
|
||||
result.putString("password", password);
|
||||
result.putString("device", device);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the arguments from the bundle, if possible.
|
||||
*
|
||||
* @param bundle The bundle.
|
||||
* @return The args or null.
|
||||
*/
|
||||
public static @Nullable Args fromBundle(@Nullable Bundle bundle) {
|
||||
if (bundle == null) return null;
|
||||
double longitude = bundle.getDouble("longitude", -190);
|
||||
if (longitude < -180) return null;
|
||||
double latitude = bundle.getDouble("latitude", -100);
|
||||
if (latitude < -90) return null;
|
||||
String network = bundle.getString("network", null);
|
||||
if (network == null) return null;
|
||||
String password = bundle.getString("password", null);
|
||||
if (password == null) return null;
|
||||
String device = bundle.getString("device", null);
|
||||
if (device == null) return null;
|
||||
return new Args(device, network, password, longitude, latitude);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The current animation set.
|
||||
*/
|
||||
private AnimatorSet animation;
|
||||
|
||||
/**
|
||||
* The binding to access the views.
|
||||
*/
|
||||
private FragmentConnectBinding binding;
|
||||
|
||||
/**
|
||||
* The runnable to navigate to the device, when the setup
|
||||
* completes.
|
||||
*/
|
||||
private Runnable navigator;
|
||||
|
||||
/**
|
||||
* The handler to post events asynchronously.
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_connect, container, false);
|
||||
ConnectViewModel model = new ViewModelProvider(this).get(ConnectViewModel.class);
|
||||
binding.setModel(model);
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
binding.setRetryListener(() -> {
|
||||
model.retry();
|
||||
});
|
||||
Observer<ConnectViewModel.State> animator = (state) -> {
|
||||
if (! model.getRetryVisible().getValue()) {
|
||||
startAnimation(state);
|
||||
}
|
||||
};
|
||||
model.getState().observe(getViewLifecycleOwner(), animator);
|
||||
model.getRetryVisible().observe(getViewLifecycleOwner(), (stopped) -> {
|
||||
if (stopped) {
|
||||
cancelAnimations();
|
||||
} else {
|
||||
startAnimation(model.getState().getValue());
|
||||
}
|
||||
});
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
navigator = () -> {
|
||||
NavOptions.Builder opts = new NavOptions.Builder().setEnterAnim(R.anim.slide_in_right)
|
||||
.setExitAnim(R.anim.slide_out_left).setPopUpTo(R.id.destination_drawer, false);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong("id", model.getDeviceHandle().getId());
|
||||
controller.navigate(R.id.destination_device, bundle, opts.build());
|
||||
};
|
||||
|
||||
model.getState().observe(getViewLifecycleOwner(), (state) -> {
|
||||
if (state == ConnectViewModel.State.COMPLETE) {
|
||||
handler.postDelayed(navigator, 5000);
|
||||
}
|
||||
});
|
||||
Args args = Args.fromBundle(getArguments());
|
||||
if (args == null) {
|
||||
getActivity().onBackPressed();
|
||||
} else {
|
||||
model.init(args);
|
||||
}
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
cancelAnimations();
|
||||
handler.removeCallbacks(navigator);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts an animation that depends on the state.
|
||||
*
|
||||
* @param state The state.
|
||||
*/
|
||||
private void startAnimation(ConnectViewModel.State state) {
|
||||
cancelAnimations();
|
||||
if (state != null) {
|
||||
ImageView v = null;
|
||||
switch (state) {
|
||||
case DEVICE:
|
||||
v = binding.connectDevice;
|
||||
break;
|
||||
case NETWORK:
|
||||
v = binding.connectNetwork;
|
||||
break;
|
||||
case CONFIGURE:
|
||||
v = binding.connectConfigure;
|
||||
break;
|
||||
case COMPLETE:
|
||||
animation = new AnimatorSet();
|
||||
ObjectAnimator blend = ObjectAnimator.ofFloat(binding.connectSun, "alpha", 0f, 1f);
|
||||
blend.setInterpolator(new LinearInterpolator());
|
||||
blend.setDuration(5000);
|
||||
ObjectAnimator move = ObjectAnimator.ofFloat(binding.connectSun, "translationY", DisplayUtils.dpToPixels(getContext(), 48), 0f);
|
||||
move.setInterpolator(new LinearInterpolator());
|
||||
move.setDuration(5000);
|
||||
animation.playTogether(blend, move);
|
||||
animation.start();
|
||||
break;
|
||||
}
|
||||
if (v != null) {
|
||||
int color = ContextCompat.getColor(getActivity(), R.color.accent);
|
||||
ImageViewCompat.setImageTintList(v, ColorStateList.valueOf(color));
|
||||
ObjectAnimator scaleX = ObjectAnimator.ofFloat(v, "scaleX", 1f, 1.4f, 1f);
|
||||
ObjectAnimator scaleY = ObjectAnimator.ofFloat(v, "scaleY", 1f, 1.4f, 1f);
|
||||
scaleX.setRepeatCount(ObjectAnimator.INFINITE);
|
||||
scaleX.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
scaleX.setDuration(750);
|
||||
scaleY.setRepeatCount(ObjectAnimator.INFINITE);
|
||||
scaleY.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
scaleY.setDuration(750);
|
||||
animation = new AnimatorSet();
|
||||
animation.playTogether(scaleX, scaleY);
|
||||
animation.start();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels all running animations and resets the view state.
|
||||
*/
|
||||
private void cancelAnimations() {
|
||||
if (animation != null) {
|
||||
animation.cancel();
|
||||
animation = null;
|
||||
}
|
||||
if (binding != null) {
|
||||
binding.connectSun.setAlpha(0f);
|
||||
TypedValue typedValue = new TypedValue();
|
||||
getActivity().getTheme().resolveAttribute(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));
|
||||
ImageViewCompat.setImageTintList(binding.connectNetwork, ColorStateList.valueOf(color));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class CountryFragment extends AbstractPlaceFragment {
|
||||
model.getCities().observe(getViewLifecycleOwner(), (list) -> adapter.submitList(list));
|
||||
recyclerView.setAdapter(adapter);
|
||||
MapView mapView = view.findViewById(R.id.map_detail);
|
||||
MapViewUtil.setupInteractiveMap(mapView);
|
||||
MapViewUtil.setupInteractiveMap(mapView, getResources().getBoolean(R.bool.dark_mode));
|
||||
Runnable updateMap = () -> {
|
||||
MapViewUtil.removePolylines(mapView, polylines);
|
||||
polylines.clear();
|
||||
|
||||
+51
@@ -4,6 +4,8 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -11,10 +13,14 @@ import androidx.databinding.DataBindingUtil;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.databinding.DialogCustomizeBinding;
|
||||
import com.mowesta.android.app.model.CustomizeViewModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A bottom sheet dialog that enables the user to customize the weather data.
|
||||
*
|
||||
@@ -30,7 +36,52 @@ public class CustomizeDialogFragment extends BottomSheetDialogFragment {
|
||||
binding.setModel(model);
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
binding.setCloseListener(() -> { this.dismiss(); });
|
||||
List<String> systems = getSystemEntries();
|
||||
binding.customizeSystem.setAdapter(createAdapter(systems));
|
||||
List<String> temperatures = getTemperatureEntries();
|
||||
binding.customizeTemperature.setAdapter(createAdapter(temperatures));
|
||||
model.getUnitSystem().observe(getViewLifecycleOwner(), (value) -> {
|
||||
if (value != null) {
|
||||
binding.customizeSystem.setText(systems.get(value.ordinal()), false);
|
||||
}
|
||||
});
|
||||
model.getTemperatureUnit().observe(getViewLifecycleOwner(), (value) -> {
|
||||
if (value != null) {
|
||||
binding.customizeTemperature.setText(temperatures.get(value.ordinal()), false);
|
||||
}
|
||||
});
|
||||
binding.customizeSystem.setOnItemClickListener((parent, view, position, id) -> {
|
||||
if (position >= 0 && position < MowestaSettings.UnitSystem.values().length) {
|
||||
model.getUnitSystem().setValue(MowestaSettings.UnitSystem.values()[position]);
|
||||
}
|
||||
});
|
||||
binding.customizeTemperature.setOnItemClickListener((parent, view, position, id) -> {
|
||||
if (position >= 0 && position < MowestaSettings.TemperatureUnit.values().length) {
|
||||
model.getTemperatureUnit().setValue(MowestaSettings.TemperatureUnit.values()[position]);
|
||||
}
|
||||
});
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private ArrayAdapter<String> createAdapter(List<String> strings) {
|
||||
return new ArrayAdapter<>(getContext(), R.layout.view_customize_entry, strings);
|
||||
}
|
||||
|
||||
private List<String> getSystemEntries() {
|
||||
List<String> result = new ArrayList<>(3);
|
||||
result.add(getString(R.string.customize_system_both));
|
||||
result.add(getString(R.string.customize_system_standard));
|
||||
result.add(getString(R.string.customize_system_imperial));
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<String> getTemperatureEntries() {
|
||||
List<String> result = new ArrayList<>(3);
|
||||
result.add(getString(R.string.customize_temperature_both));
|
||||
result.add(getString(R.string.customize_temperature_celsius));
|
||||
result.add(getString(R.string.customize_temperature_fahrenheit));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -102,8 +102,7 @@ public class DeviceFragment extends AbstractDiagramFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnitChanged() {
|
||||
super.onUnitChanged();
|
||||
public void onRefreshDiagram() {
|
||||
RecyclerView recyclerView = getView().findViewById(R.id.recycler);
|
||||
recyclerView.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,12 @@ public class DevicesFragment extends AbstractNetworkFragment {
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
FragmentDevicesBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_devices, container, false);
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
binding.setAddButtonListener(() -> {
|
||||
NavOptions.Builder opts = new NavOptions.Builder().setEnterAnim(R.anim.slide_in_right).setExitAnim(R.anim.slide_out_left);
|
||||
Bundle bundle = new Bundle();
|
||||
controller.navigate(R.id.destination_setup, bundle, opts.build());
|
||||
});
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -13,6 +15,8 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -23,7 +27,9 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.cursoradapter.widget.CursorAdapter;
|
||||
import androidx.customview.widget.Openable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.NavController;
|
||||
@@ -41,6 +47,7 @@ import com.mowesta.android.app.model.AbstractNetworkViewModel;
|
||||
import com.mowesta.android.app.model.DrawerViewModel;
|
||||
import com.mowesta.android.app.model.LocationViewModel;
|
||||
import com.mowesta.android.app.repository.UserCredentials;
|
||||
import com.mowesta.android.app.util.DisplayUtils;
|
||||
import com.mowesta.android.feign.model.LocationHierarchy;
|
||||
import com.mowesta.android.feign.model.LocationHierarchyPage;
|
||||
|
||||
@@ -75,6 +82,28 @@ public class DrawerFragment extends AbstractNetworkFragment {
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
// navigate to settings, if user pressed notification
|
||||
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))) {
|
||||
Navigation.findNavController(getView().findViewById(R.id.navigation_drawer)).navigate(R.id.destination_settings);
|
||||
getActivity().setIntent(new Intent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@@ -155,7 +184,18 @@ public class DrawerFragment extends AbstractNetworkFragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
NavController navController = Navigation.findNavController(view.findViewById(R.id.navigation_drawer));
|
||||
AppBarConfiguration.Builder builder = new AppBarConfiguration.Builder(R.id.destination_favorites);
|
||||
builder.setOpenableLayout(view.findViewById(R.id.layout_drawer));
|
||||
View drawer = view.findViewById(R.id.layout_drawer);
|
||||
if (drawer != null) builder.setOpenableLayout((Openable)drawer);
|
||||
View sun = view.findViewById(R.id.logo_sun);
|
||||
AnimatorSet set = new AnimatorSet();
|
||||
ObjectAnimator first = ObjectAnimator.ofFloat(sun, "translationY", DisplayUtils.dpToPixels(getContext(), 120), 0f);
|
||||
first.setDuration(750);
|
||||
first.setInterpolator(new OvershootInterpolator());
|
||||
ObjectAnimator last = ObjectAnimator.ofFloat(sun, "translationX", DisplayUtils.dpToPixels(getContext(), 120), 0f);
|
||||
last.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
last.setDuration(750);
|
||||
set.playTogether(first, last);
|
||||
set.start();
|
||||
Toolbar toolbar = view.findViewById(R.id.toolbar);
|
||||
CollapsingToolbarLayout layout = view.findViewById(R.id.layout_toolbar);
|
||||
NavigationUI.setupWithNavController(layout, toolbar, navController, builder.build());
|
||||
|
||||
@@ -23,8 +23,10 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.database.Favorite;
|
||||
import com.mowesta.android.app.databinding.ViewFavoriteEntryBinding;
|
||||
import com.mowesta.android.app.model.CustomizeViewModel;
|
||||
import com.mowesta.android.app.model.FavoritesViewModel;
|
||||
import com.mowesta.android.app.model.FavoritesViewModel.OnFavoriteSelectedListener;
|
||||
import com.mowesta.android.app.util.TabletUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -51,6 +53,7 @@ public class FavoritesFragment extends Fragment {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
RecyclerView recyclerView = view.findViewById(R.id.recycler);
|
||||
TabletUtil.setGridLayout(recyclerView, 300);
|
||||
SwipeRefreshLayout swipeRefreshLayout = view.findViewById(R.id.swipe_refresh);
|
||||
FavoritesViewModel model = new ViewModelProvider(getActivity()).get(FavoritesViewModel.class);
|
||||
model.getRefreshing().observe(getViewLifecycleOwner(), (refreshing) -> {
|
||||
@@ -76,6 +79,9 @@ public class FavoritesFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
}));
|
||||
CustomizeViewModel customize = new ViewModelProvider(getActivity()).get(CustomizeViewModel.class);
|
||||
customize.getUnitSystem().observe(getViewLifecycleOwner(), (v) -> recyclerView.getAdapter().notifyDataSetChanged());
|
||||
customize.getTemperatureUnit().observe(getViewLifecycleOwner(), (v) -> recyclerView.getAdapter().notifyDataSetChanged());
|
||||
View layoutHelp = view.findViewById(R.id.favorites_help);
|
||||
View layoutList = view.findViewById(R.id.favorites_list);
|
||||
model.getFavorites().observe(getViewLifecycleOwner(), (list)-> {
|
||||
@@ -88,7 +94,11 @@ public class FavoritesFragment extends Fragment {
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_unit, menu);
|
||||
inflater.inflate(R.menu.menu_refresh, menu);
|
||||
// remove this item, since it would not have an effect here
|
||||
MenuItem item = menu.findItem(R.id.action_unit_system);
|
||||
if (item != null) item.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,6 +107,9 @@ public class FavoritesFragment extends Fragment {
|
||||
FavoritesViewModel model = new ViewModelProvider(getActivity()).get(FavoritesViewModel.class);
|
||||
model.refresh();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_temperature_unit) {
|
||||
TemperatureUnitDialogFragment unit = new TemperatureUnitDialogFragment();
|
||||
unit.show(getChildFragmentManager(), "unit");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,16 @@ public class LoginFragment extends Fragment {
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.destination_devices, null, b.build());
|
||||
break;
|
||||
case COLLECTION:
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_login_collection);
|
||||
try {
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_login_collection);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// this is most likely bug in the navigation library, since it cannot find the
|
||||
// node in the xml file which is technically impossible (probably a race during loading)
|
||||
NavOptions.Builder builder = new NavOptions.Builder().setPopUpTo(R.id.destination_login, true);
|
||||
builder.setEnterAnim(R.anim.slide_in_right);
|
||||
builder.setExitAnim(R.anim.slide_out_left);
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.destination_collection, null, builder.build());
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
|
||||
View v = super.onCreateView(paramLayoutInflater, paramViewGroup, paramBundle);
|
||||
settings = new MowestaSettings(getActivity().getApplication());
|
||||
this.settings = ((IApp)getContext().getApplicationContext()).getSettings();
|
||||
updateBuild();
|
||||
updateNotification();
|
||||
bindDevice();
|
||||
@@ -442,7 +442,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
// reset the settings
|
||||
MowestaApp app = (MowestaApp)activity.getApplication();
|
||||
SdkRepository sdk = SdkRepository.getInstance(app);
|
||||
MowestaSettings settings = new MowestaSettings(app);
|
||||
MowestaSettings settings = app.getSettings();
|
||||
settings.setPrivacyMeasure(false);
|
||||
settings.setCollectionShown(false);
|
||||
app.getUserRepository().clearCredentials();
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewPropertyAnimator;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.NavOptions;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.mowesta.android.app.MowestaActivity;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.databinding.FragmentSetupBinding;
|
||||
import com.mowesta.android.app.model.SetupViewModel;
|
||||
import com.mowesta.android.app.util.DisplayUtils;
|
||||
import com.mowesta.android.app.util.PermissionUtil;
|
||||
|
||||
/**
|
||||
* The setup fragment that is used to add a weather station to
|
||||
* the account.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class SetupFragment extends Fragment {
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
FragmentSetupBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_setup, container, false);
|
||||
SetupViewModel model = new ViewModelProvider(this).get(SetupViewModel.class);
|
||||
model.getManualPosition().observe(getViewLifecycleOwner(), (manualPosition) -> {
|
||||
if (! manualPosition) {
|
||||
binding.setupNetworkName.requestFocus();
|
||||
}
|
||||
});
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
binding.setModel(model);
|
||||
binding.setInfoButtonListener(() -> {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(getString(R.string.setup_url)));
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Snackbar.make(container, R.string.message_no_browser, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
binding.setGpsButtonListener(() -> {
|
||||
SetupViewModel.GpsStatus status = model.registerGpsReceiver();
|
||||
switch (status) {
|
||||
case PROHIBITED:
|
||||
((MowestaActivity)getActivity()).requestPermissions(PermissionUtil.getForegroundPermissions(getActivity()));
|
||||
break;
|
||||
case DISABLED:
|
||||
Snackbar.make(container, R.string.setup_error_gps_disabled, Snackbar.LENGTH_LONG).setAction(R.string.button_configure, (v) -> {
|
||||
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
try {
|
||||
startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
// should never happen
|
||||
}
|
||||
}).show();
|
||||
break;
|
||||
default:
|
||||
// success
|
||||
break;
|
||||
}
|
||||
});
|
||||
NavController controller = Navigation.findNavController(getActivity(), R.id.navigation_app);
|
||||
binding.setReadyButtonListener(() -> {
|
||||
model.unregisterGpsReciever();
|
||||
ConnectFragment.Args args = model.getArgs();
|
||||
if (args != null) {
|
||||
NavOptions.Builder opts = new NavOptions.Builder().setEnterAnim(R.anim.slide_in_right).setExitAnim(R.anim.slide_out_left);
|
||||
controller.navigate(R.id.destination_connect, args.asBundle(), opts.build());
|
||||
}
|
||||
});
|
||||
if (model.isAnimate()) {
|
||||
model.setAnimate(false); // only animate on first entry
|
||||
binding.setupLayout.setAlpha(0);
|
||||
AnimatorSet set = new AnimatorSet();
|
||||
ObjectAnimator rotate = ObjectAnimator.ofFloat(binding.setupIcon, "rotation", 360*10f, 0f);
|
||||
rotate.setDuration(2000);
|
||||
rotate.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
ObjectAnimator scaleX = ObjectAnimator.ofFloat(binding.setupIcon, "scaleX", 10, 1f);
|
||||
scaleX.setInterpolator(new LinearInterpolator());
|
||||
scaleX.setDuration(750);
|
||||
ObjectAnimator scaleY = ObjectAnimator.ofFloat(binding.setupIcon, "scaleY", 10, 1f);
|
||||
scaleY.setInterpolator(new LinearInterpolator());
|
||||
scaleY.setDuration(750);
|
||||
float offset = DisplayUtils.dpToPixels(getContext(), 48 * 5);
|
||||
ObjectAnimator moveX = ObjectAnimator.ofFloat(binding.setupIcon, "translationY", offset, 0f);
|
||||
moveX.setInterpolator(new LinearInterpolator());
|
||||
moveX.setDuration(750);
|
||||
ObjectAnimator moveY = ObjectAnimator.ofFloat(binding.setupIcon, "translationX", -offset, 0f);
|
||||
moveY.setInterpolator(new LinearInterpolator());
|
||||
moveY.setDuration(750);
|
||||
ObjectAnimator blend = ObjectAnimator.ofFloat(binding.setupLayout, "alpha", 0f, 1f);
|
||||
blend.setInterpolator(new LinearInterpolator());
|
||||
blend.setDuration(1000);
|
||||
AnimatorSet m = new AnimatorSet();
|
||||
m.playTogether(scaleX, scaleY, moveX, moveY);
|
||||
|
||||
set.playSequentially(m, blend);
|
||||
AnimatorSet second = new AnimatorSet();
|
||||
second.playTogether(set, rotate);
|
||||
second.start();
|
||||
}
|
||||
return binding.getRoot();
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class SplashFragment extends Fragment {
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
settings = new MowestaSettings(getActivity().getApplication());
|
||||
this.settings = ((IApp)getContext().getApplicationContext()).getSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,6 +78,7 @@ public class SplashFragment extends Fragment {
|
||||
View title = root.findViewById(R.id.splash_title);
|
||||
View subtitle = root.findViewById(R.id.splash_subtitle);
|
||||
View world = root.findViewById(R.id.splash_world);
|
||||
View logos = root.findViewById(R.id.logo_panel);
|
||||
AnimatorSet set = new AnimatorSet();
|
||||
ValueAnimator gradientAnimator = ValueAnimator.ofFloat(0, 1);
|
||||
gradientAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
@@ -93,6 +94,10 @@ public class SplashFragment extends Fragment {
|
||||
ObjectAnimator worldAnimator = ObjectAnimator.ofFloat(world, "alpha", 0, 1);
|
||||
worldAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
worldAnimator.setDuration(750);
|
||||
logos.setAlpha(0);
|
||||
ObjectAnimator logoAnimator = ObjectAnimator.ofFloat(logos, "alpha", 0, 1);
|
||||
logoAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
logoAnimator.setDuration(750);
|
||||
ObjectAnimator sunAnimator = ObjectAnimator.ofFloat(sun, "alpha", 0, 1);
|
||||
sunAnimator.setInterpolator(new LinearInterpolator());
|
||||
sunAnimator.setDuration(150);
|
||||
@@ -105,6 +110,7 @@ public class SplashFragment extends Fragment {
|
||||
|
||||
set.playTogether(sunAnimator, titleAnimator, subtitleAnimator);
|
||||
set.play(worldAnimator).after(sunAnimator);
|
||||
set.play(logoAnimator).after(sunAnimator);
|
||||
set.play(gradientAnimator).after(sunAnimator);
|
||||
set.start();
|
||||
return root;
|
||||
|
||||
@@ -108,7 +108,7 @@ public class StateFragment extends AbstractPlaceFragment {
|
||||
model.getCities().observe(getViewLifecycleOwner(), (list) -> adapter.submitList(list));
|
||||
recyclerView.setAdapter(adapter);
|
||||
MapView mapView = view.findViewById(R.id.map_detail);
|
||||
MapViewUtil.setupInteractiveMap(mapView);
|
||||
MapViewUtil.setupInteractiveMap(mapView, getResources().getBoolean(R.bool.dark_mode));
|
||||
Runnable updateMap = () -> {
|
||||
MapViewUtil.removePolylines(mapView, polylines);
|
||||
polylines.clear();
|
||||
|
||||
@@ -122,7 +122,7 @@ public class StationFragment extends AbstractDiagramFragment {
|
||||
model.getReports().observe(getViewLifecycleOwner(), (list) -> adapter.submitList(list));
|
||||
recyclerView.setAdapter(adapter);
|
||||
MapView mapView = view.findViewById(R.id.map_detail);
|
||||
MapViewUtil.setupInteractiveMap(mapView);
|
||||
MapViewUtil.setupInteractiveMap(mapView, getResources().getBoolean(R.bool.dark_mode));
|
||||
Runnable updateMap = () -> {
|
||||
if (model.getStation().getValue() != null) {
|
||||
WeatherStation s = model.getStation().getValue();
|
||||
@@ -169,8 +169,7 @@ public class StationFragment extends AbstractDiagramFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnitChanged() {
|
||||
super.onUnitChanged();
|
||||
public void onRefreshDiagram() {
|
||||
RecyclerView recyclerView = getView().findViewById(R.id.recycler);
|
||||
recyclerView.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
|
||||
/**
|
||||
* A dialog that enables the user to select the temperature.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class TemperatureUnitDialogFragment extends DialogFragment {
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*/
|
||||
private MowestaSettings settings;
|
||||
/**
|
||||
* The selected uni.
|
||||
*/
|
||||
private MowestaSettings.TemperatureUnit unit;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
settings = new MowestaSettings(getActivity().getApplication());
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());
|
||||
builder.setIcon(R.drawable.ic_thermometer_normal_24);
|
||||
builder.setTitle(R.string.customize_hint_temperature);
|
||||
CharSequence[] items = new CharSequence[] {
|
||||
getString(R.string.customize_temperature_both),
|
||||
getString(R.string.customize_temperature_celsius),
|
||||
getString(R.string.customize_temperature_fahrenheit)
|
||||
};
|
||||
unit = settings.getTemperatureUnit();
|
||||
int select = unit.ordinal();
|
||||
builder.setSingleChoiceItems(items, select, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
MowestaSettings.TemperatureUnit[] v = MowestaSettings.TemperatureUnit.values();
|
||||
if (which >= 0 && which < v.length) {
|
||||
unit = v[which];
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setNeutralButton(android.R.string.cancel, (dialog, which) -> {
|
||||
dismiss();
|
||||
});
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
settings.setTemperatureUnit(unit);
|
||||
dismiss();
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class TermsFragment extends Fragment {
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
binding.setModel(model);
|
||||
binding.setContinueListener(() -> {
|
||||
MowestaSettings settings = new MowestaSettings(getActivity().getApplication());
|
||||
MowestaSettings settings = ((IApp)getContext().getApplicationContext()).getSettings();
|
||||
settings.markTermsAccepted();
|
||||
if (shouldShowLogin()) {
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_terms_login);
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
|
||||
/**
|
||||
* A dialog fragment to enable the user to select the unit system.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class UnitSystemDialogFragment extends DialogFragment {
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*/
|
||||
private MowestaSettings settings;
|
||||
/**
|
||||
* The selected system.
|
||||
*/
|
||||
private MowestaSettings.UnitSystem system;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
settings = new MowestaSettings(getActivity().getApplication());
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());
|
||||
builder.setIcon(R.drawable.ic_barometer_normal_24);
|
||||
builder.setTitle(R.string.customize_hint_system);
|
||||
CharSequence[] items = new CharSequence[] {
|
||||
getString(R.string.customize_system_both),
|
||||
getString(R.string.customize_system_standard),
|
||||
getString(R.string.customize_system_imperial)
|
||||
};
|
||||
system = settings.getUnitSystem();
|
||||
int select = system.ordinal();
|
||||
builder.setSingleChoiceItems(items, select, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
MowestaSettings.UnitSystem[] v = MowestaSettings.UnitSystem.values();
|
||||
if (which >= 0 && which < v.length) {
|
||||
system = v[which];
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setNeutralButton(android.R.string.cancel, (dialog, which) -> {
|
||||
dismiss();
|
||||
});
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
settings.setUnitSystem(system);
|
||||
dismiss();
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -8,45 +10,42 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
import com.google.android.exoplayer2.database.DefaultDatabaseProvider;
|
||||
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||
import com.google.android.exoplayer2.ui.PlayerView;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
|
||||
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.adapter.PreferenceLiveData;
|
||||
import com.mowesta.android.app.model.AbstractNetworkViewModel;
|
||||
import com.mowesta.android.app.task.ImageTask;
|
||||
import com.mowesta.android.app.util.ContentScaler;
|
||||
import com.mowesta.android.app.util.DateFormatter;
|
||||
import com.mowesta.android.app.util.MercatorPositioner;
|
||||
import com.mowesta.android.app.util.TimeUtils;
|
||||
import com.mowesta.android.app.view.MarkerView;
|
||||
import com.mowesta.android.app.view.WeatherView;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
import com.mowesta.android.feign.model.WeatherVideo;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@@ -54,7 +53,7 @@ import java.io.IOException;
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class VideoFragment extends Fragment {
|
||||
public class VideoFragment extends AbstractNetworkFragment {
|
||||
|
||||
/**
|
||||
* The log tag.
|
||||
@@ -211,19 +210,18 @@ public class VideoFragment extends Fragment {
|
||||
double hps = video.getFph() / (double)video.getFps();
|
||||
long hours = (long)(secs / hps);
|
||||
long time = video.getTime() + (video.getStart() + hours) * 60 * 60 * 1000;
|
||||
int dayRes = timeUtils.getDayName(time);
|
||||
String day;
|
||||
if (dayRes != 0) {
|
||||
day = getString(dayRes);
|
||||
} else {
|
||||
day = formatter.asDate(time, timezone);
|
||||
}
|
||||
String day = timeUtils.getDayName(getContext(), time);
|
||||
String hour = formatter.asTime(time, timezone);
|
||||
overlay.setText(getResources().getString(R.string.format_two_lines, day, hour));
|
||||
handler.postDelayed(this.timer, 500);
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
protected AbstractNetworkViewModel getNetworkViewModel() {
|
||||
return new ViewModelProvider(this).get(ExoPlayerViewModel.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@@ -232,15 +230,29 @@ public class VideoFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
model = new ViewModelProvider(this).get(ExoPlayerViewModel.class);
|
||||
ImageButton scaleButton = view.findViewById(R.id.video_scale);
|
||||
ImageButton zoomButton = view.findViewById(R.id.video_zoom);
|
||||
player = view.findViewById(R.id.video_view);
|
||||
player.setShowBuffering(PlayerView.SHOW_BUFFERING_ALWAYS);
|
||||
overlay = view.findViewById(R.id.video_time);
|
||||
marker = new MarkerView(view.getContext());
|
||||
marker.setLayoutParams(new FrameLayout.LayoutParams
|
||||
(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
player.getOverlayFrameLayout().addView(marker);
|
||||
View frame = LayoutInflater.from(view.getContext()).inflate(R.layout.view_marker, player.getOverlayFrameLayout(), true);
|
||||
marker = frame.findViewById(R.id.video_marker);
|
||||
ImageView scaleImage = frame.findViewById(R.id.video_scale_image);
|
||||
View scaleBackground = frame.findViewById(R.id.video_scale_background);
|
||||
ImageButton scaleButton = view.findViewById(R.id.video_scale);
|
||||
scaleButton.setOnClickListener((v) -> {
|
||||
model.showScale.setValue(!model.showScale.getValue());
|
||||
});
|
||||
model.showScale.observe(getViewLifecycleOwner(), (v) -> {
|
||||
int visible = v?View.VISIBLE:View.GONE;
|
||||
scaleBackground.setVisibility(visible);
|
||||
scaleImage.setVisibility(visible);
|
||||
int img = v?R.drawable.ic_remove_circle_normal_24:R.drawable.ic_remove_circle_outline_normal_24;
|
||||
int txt = v?R.string.button_hide_scale:R.string.button_show_scale;
|
||||
scaleButton.setContentDescription(getString(txt));
|
||||
scaleButton.setImageResource(img);
|
||||
});
|
||||
Args args = Args.fromBundle(getArguments());
|
||||
if (args != null) {
|
||||
video = args.getVideo();
|
||||
@@ -267,23 +279,29 @@ public class VideoFragment extends Fragment {
|
||||
.createMediaSource(Uri.parse(video.getUrl()));
|
||||
model.exoPlayer.prepare(videoSource);
|
||||
model.exoPlayer.setPlayWhenReady(true);
|
||||
model.scaleUrl = video.getScale();
|
||||
model.reload();
|
||||
}
|
||||
player.setPlayer(model.exoPlayer);
|
||||
model.scaleImage.observe(getViewLifecycleOwner(), (b)-> {
|
||||
scaleImage.setImageBitmap(b);
|
||||
});
|
||||
|
||||
model.mode.observe(getViewLifecycleOwner(), (mode) -> {
|
||||
if (mode == ContentScaler.ScaleMode.FIT) {
|
||||
scaleButton.setImageResource(R.drawable.ic_zoom_out_map_normal_24);
|
||||
scaleButton.setContentDescription(getString(R.string.button_fill_screen));
|
||||
zoomButton.setImageResource(R.drawable.ic_zoom_out_map_normal_24);
|
||||
zoomButton.setContentDescription(getString(R.string.button_fill_screen));
|
||||
player.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
|
||||
} else {
|
||||
scaleButton.setImageResource(R.drawable.ic_aspect_ratio_normal_24);
|
||||
scaleButton.setContentDescription(getString(R.string.button_fit_screen));
|
||||
zoomButton.setImageResource(R.drawable.ic_aspect_ratio_normal_24);
|
||||
zoomButton.setContentDescription(getString(R.string.button_fit_screen));
|
||||
player.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
|
||||
}
|
||||
if (model.markerX != null && model.markerY != null) {
|
||||
updateVideo(marker.getWidth(), marker.getHeight());
|
||||
}
|
||||
});
|
||||
scaleButton.setOnClickListener((v) -> {
|
||||
zoomButton.setOnClickListener((v) -> {
|
||||
model.mode.setValue(model.mode.getValue() == ContentScaler.ScaleMode.FILL?
|
||||
ContentScaler.ScaleMode.FIT: ContentScaler.ScaleMode.FILL);
|
||||
});
|
||||
@@ -293,6 +311,7 @@ public class VideoFragment extends Fragment {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
if (video != null) {
|
||||
handler.postDelayed(timer, 500);
|
||||
if (model.markerX != null && model.markerY != null) {
|
||||
@@ -307,6 +326,7 @@ public class VideoFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
marker.removeOnLayoutChangeListener(markerListener);
|
||||
handler.removeCallbacks(timer);
|
||||
super.onPause();
|
||||
@@ -352,7 +372,7 @@ public class VideoFragment extends Fragment {
|
||||
* The view model to store the exo player instance when
|
||||
* the view is destroyed.
|
||||
*/
|
||||
public static class ExoPlayerViewModel extends AndroidViewModel {
|
||||
public static class ExoPlayerViewModel extends AbstractNetworkViewModel {
|
||||
|
||||
/**
|
||||
* The exo player (initialized only once).
|
||||
@@ -364,6 +384,11 @@ public class VideoFragment extends Fragment {
|
||||
*/
|
||||
final MutableLiveData<ContentScaler.ScaleMode> mode = new MutableLiveData<>(ContentScaler.ScaleMode.FILL);
|
||||
|
||||
/**
|
||||
* A boolean preference to show the scale.
|
||||
*/
|
||||
final PreferenceLiveData showScale;
|
||||
|
||||
/**
|
||||
* The relative position of the marker in x.
|
||||
*/
|
||||
@@ -379,15 +404,39 @@ public class VideoFragment extends Fragment {
|
||||
*/
|
||||
final ContentScaler scaler = new ContentScaler();
|
||||
|
||||
/**
|
||||
* The scale image.
|
||||
*/
|
||||
final MutableLiveData<Bitmap> scaleImage = new MutableLiveData<>();
|
||||
|
||||
/**
|
||||
* The weather video's scale image.
|
||||
*/
|
||||
String scaleUrl;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a view model.
|
||||
*/
|
||||
public ExoPlayerViewModel(Application application) {
|
||||
super(application);
|
||||
MowestaSettings s = ((IApp)application).getSettings();
|
||||
showScale = new PreferenceLiveData(s.getPreferences(), MowestaSettings.SHOW_SCALE,
|
||||
s.getContext().getResources().getBoolean(R.bool.show_scale_defaut));
|
||||
mode.observeForever((m)->scaler.setMode(m));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
long requestCode = newRequestCode();
|
||||
scaleImage.setValue(null);
|
||||
if (scaleUrl != null) {
|
||||
new ImageTask((url, bitmap)-> {
|
||||
if (bitmap == null) finishRequest(requestCode, true);
|
||||
else completeRequest(requestCode, () -> scaleImage.setValue(bitmap));
|
||||
}).execute(scaleUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
@@ -9,12 +12,14 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.TooltipCompat;
|
||||
import androidx.constraintlayout.widget.Guideline;
|
||||
import androidx.core.text.HtmlCompat;
|
||||
import androidx.databinding.BindingAdapter;
|
||||
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.database.Favorite;
|
||||
import com.mowesta.android.app.util.DateFormatter;
|
||||
import com.mowesta.android.app.util.UnitUtils;
|
||||
import com.mowesta.android.app.view.WeatherIcon;
|
||||
import com.mowesta.android.app.view.WeatherView;
|
||||
import com.mowesta.android.feign.model.City;
|
||||
@@ -57,7 +62,7 @@ public class BindingAdapters {
|
||||
*/
|
||||
@BindingAdapter("err")
|
||||
public static void setFormStatus(TextInputLayout input, FormStatus status) {
|
||||
if (status.isValid()) {
|
||||
if (status == null || status.isValid()) {
|
||||
input.setError(null);
|
||||
} else {
|
||||
if (status.getMessage() == 0) {
|
||||
@@ -227,6 +232,12 @@ public class BindingAdapters {
|
||||
case TOWN:
|
||||
res = R.string.city_type_town;
|
||||
break;
|
||||
case SUBURB:
|
||||
res = R.string.city_type_suburb;
|
||||
break;
|
||||
case VILLAGE:
|
||||
res = R.string.city_type_village;
|
||||
break;
|
||||
}
|
||||
if (city.isCapital()) {
|
||||
res = R.string.city_type_capital;
|
||||
@@ -330,7 +341,7 @@ public class BindingAdapters {
|
||||
@BindingAdapter("stationAltitude")
|
||||
public static void setStationAltitude(@NonNull TextView view, @Nullable WeatherStation station) {
|
||||
if (station == null || station.getAltitude() == null) view.setText("");
|
||||
else view.setText(view.getResources().getString(R.string.format_altitude, station.getAltitude()));
|
||||
else view.setText(UnitUtils.toSpanned(UnitUtils.getAltitude(view.getContext(), station.getAltitude())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -368,9 +379,7 @@ public class BindingAdapters {
|
||||
public static void setTemperature(TextView view, @Nullable WeatherCondition condition) {
|
||||
if (condition == null || condition.getTemperature() == null) view.setText("");
|
||||
else {
|
||||
int centigrade = (int) Math.round(condition.getTemperature());
|
||||
int fahrenheit = (int) Math.round((condition.getTemperature() * 9 / 5) + 32);
|
||||
view.setText(view.getContext().getResources().getString(R.string.format_temperature, centigrade, fahrenheit));
|
||||
view.setText(UnitUtils.toSpanned(UnitUtils.getTemperature(view.getContext(), condition.getTemperature())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +392,7 @@ public class BindingAdapters {
|
||||
@BindingAdapter("humidity")
|
||||
public static void setHumidity(TextView view, @Nullable WeatherCondition condition) {
|
||||
if (condition == null || condition.getHumidity() == null) view.setText("");
|
||||
else view.setText(view.getContext().getResources().getString(R.string.format_humidity, condition.getHumidity()));
|
||||
else view.setText(UnitUtils.toSpanned(view.getContext().getResources().getString(R.string.format_humidity, condition.getHumidity())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -395,7 +404,7 @@ public class BindingAdapters {
|
||||
@BindingAdapter("cloudCoverage")
|
||||
public static void setCloudCoverage(TextView view, @Nullable WeatherCondition condition) {
|
||||
if (condition == null || condition.getCloudCoverage() == null) view.setText("");
|
||||
else view.setText(view.getContext().getResources().getString(R.string.format_cloud_coverage, condition.getCloudCoverage() * 100));
|
||||
else view.setText(UnitUtils.toSpanned(view.getContext().getResources().getString(R.string.format_cloud_coverage, condition.getCloudCoverage() * 100)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -407,7 +416,7 @@ public class BindingAdapters {
|
||||
@BindingAdapter("pressure")
|
||||
public static void setPressure(TextView view, @Nullable WeatherCondition condition) {
|
||||
if (condition == null || condition.getPressure() == null) view.setText("");
|
||||
else view.setText(view.getContext().getResources().getString(R.string.format_pressure, condition.getPressure()));
|
||||
else view.setText(UnitUtils.toSpanned(UnitUtils.getPressure(view.getContext(), condition.getPressure())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -420,9 +429,7 @@ public class BindingAdapters {
|
||||
public static void setWindSpeed(TextView view, @Nullable WeatherCondition condition) {
|
||||
if (condition == null || condition.getWindSpeed() == null) view.setText("");
|
||||
else {
|
||||
int kmph = (int) Math.round(condition.getWindSpeed() * 3.6);
|
||||
int mph = (int) Math.round(condition.getWindSpeed() * 3.6 * 0.6213711922373339136);
|
||||
view.setText(view.getContext().getResources().getString(R.string.format_wind_speed, kmph, mph));
|
||||
view.setText(UnitUtils.toSpanned(UnitUtils.getWindSpeed(view.getContext(), condition.getWindSpeed())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,7 +442,7 @@ public class BindingAdapters {
|
||||
@BindingAdapter("precipitation")
|
||||
public static void setPrecipitation(TextView view, @Nullable WeatherCondition condition) {
|
||||
if (condition == null || condition.getPrecipitation() == null) view.setText("");
|
||||
else view.setText(view.getContext().getResources().getString(R.string.format_precipitation, condition.getPrecipitation()));
|
||||
else view.setText(UnitUtils.toSpanned(UnitUtils.getPrecipitation(view.getContext(), condition.getPrecipitation())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,7 +454,7 @@ public class BindingAdapters {
|
||||
@BindingAdapter("snow")
|
||||
public static void setSnow(TextView view, @Nullable WeatherCondition condition) {
|
||||
if (condition == null || condition.getSnowDepth() == null) view.setText("");
|
||||
else view.setText(view.getContext().getResources().getString(R.string.format_snow, condition.getSnowDepth()));
|
||||
else view.setText(UnitUtils.toSpanned(UnitUtils.getSnowDepth(view.getContext(), condition.getSnowDepth())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -575,7 +582,7 @@ public class BindingAdapters {
|
||||
}
|
||||
|
||||
@BindingAdapter("datetime")
|
||||
public static void setGuidelinePosition(@NonNull TextView textView, @Nullable DiagramEntry<?> entry) {
|
||||
public static void setDiagramDateTime(@NonNull TextView textView, @Nullable DiagramEntry<?> entry) {
|
||||
if (entry == null) {
|
||||
textView.setText("");
|
||||
} else {
|
||||
@@ -590,8 +597,7 @@ public class BindingAdapters {
|
||||
view.setVisibility(View.GONE);
|
||||
} else {
|
||||
view.setVisibility(View.VISIBLE);
|
||||
float temp = BindingTransforms.getTemperature(view.getContext(), entry.getTemperature().getAbsoluteValue());
|
||||
view.setText(view.getResources().getString(R.string.format_compact, temp));
|
||||
view.setText(UnitUtils.getDiagramTemperature(view.getContext(), entry.getTemperature().getAbsoluteValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,7 +607,7 @@ public class BindingAdapters {
|
||||
view.setVisibility(View.GONE);
|
||||
} else {
|
||||
view.setVisibility(View.VISIBLE);
|
||||
view.setText(view.getResources().getString(R.string.format_compact, (float)entry.getPressure().getAbsoluteValue()));
|
||||
view.setText(UnitUtils.getDiagramPressure(view.getContext(), entry.getPressure().getAbsoluteValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,9 +627,7 @@ public class BindingAdapters {
|
||||
if (data == null) {
|
||||
view.setText(R.string.label_not_available);
|
||||
} else {
|
||||
int centigrade = (int) Math.round(data);
|
||||
int fahrenheit = (int) Math.round((data * 9 / 5) + 32);
|
||||
view.setText(view.getContext().getResources().getString(R.string.format_temperature, centigrade, fahrenheit));
|
||||
view.setText(UnitUtils.toSpanned(UnitUtils.getTemperature(view.getContext(), data)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -632,7 +636,7 @@ public class BindingAdapters {
|
||||
if (data == null) {
|
||||
view.setText(R.string.label_not_available);
|
||||
} else {
|
||||
view.setText(view.getResources().getString(R.string.format_pressure, data.floatValue()));
|
||||
view.setText(UnitUtils.toSpanned(UnitUtils.getPressure(view.getContext(), data)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -641,7 +645,7 @@ public class BindingAdapters {
|
||||
if (data == null) {
|
||||
view.setText(R.string.label_not_available);
|
||||
} else {
|
||||
view.setText(view.getResources().getString(R.string.format_humidity, data.floatValue()));
|
||||
view.setText(UnitUtils.toSpanned(view.getResources().getString(R.string.format_humidity, data.floatValue())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -814,6 +818,7 @@ public class BindingAdapters {
|
||||
|
||||
@BindingAdapter("measurementValue")
|
||||
public static void setMeasurementValue(TextView view, @Nullable MeasurementViewModel.MeasurementValue value) {
|
||||
Resources r = view.getContext().getResources();
|
||||
if (value == null || !value.hasValue()) {
|
||||
view.setText(null);
|
||||
} else {
|
||||
@@ -823,17 +828,30 @@ public class BindingAdapters {
|
||||
String valueText = null;
|
||||
if (o != null) {
|
||||
if (o instanceof Boolean) {
|
||||
valueText = view.getResources().getString(((Boolean)o) ? R.string.measurement_data_true : R.string.measurement_data_false);
|
||||
valueText = r.getString(((Boolean)o) ? R.string.measurement_data_true : R.string.measurement_data_false);
|
||||
} else if (o instanceof Double) {
|
||||
int format = BindingTransforms.getMeasurementTypeFormat(value.getType());
|
||||
if (format == 0) {
|
||||
valueText = o.toString();
|
||||
} else if (format == R.string.format_temperature) {
|
||||
int centigrade = (int) Math.round((Double)o);
|
||||
int fahrenheit = (int) Math.round((((Double)o) * 9 / 5) + 32);
|
||||
valueText = view.getResources().getString(R.string.format_temperature, centigrade, fahrenheit);
|
||||
} else {
|
||||
valueText = view.getResources().getString(format, ((Double)o).floatValue());
|
||||
switch (value.getType()) {
|
||||
case CPU_FREQUENCY:
|
||||
valueText = r.getString(R.string.format_frequency, ((Double)o).floatValue() / 1000000);
|
||||
break;
|
||||
case SOLAR_VOLTAGE:
|
||||
case BATTERY_VOLTAGE:
|
||||
valueText = r.getString(R.string.format_voltage, ((Double)o).floatValue());
|
||||
break;
|
||||
case SENSOR_HUMIDITY:
|
||||
valueText = r.getString(R.string.format_humidity, ((Double)o).floatValue());
|
||||
break;
|
||||
case SENSOR_PRESSURE:
|
||||
valueText = UnitUtils.getPressure(view.getContext(), (Double)o).toString();
|
||||
break;
|
||||
case CPU_TEMPERATURE:
|
||||
case BATTERY_TEMPERATURE:
|
||||
case SENSOR_TEMPERATURE:
|
||||
valueText = UnitUtils.getTemperature(view.getContext(), (Double)o).toString();
|
||||
break;
|
||||
default:
|
||||
valueText = o.toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -845,7 +863,7 @@ public class BindingAdapters {
|
||||
}
|
||||
}
|
||||
}
|
||||
view.setText(text);
|
||||
view.setText(UnitUtils.toSpanned(text));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.view.JamIcon;
|
||||
import com.mowesta.android.app.view.WeatherIcon;
|
||||
@@ -23,23 +22,6 @@ import java.util.Map;
|
||||
public class BindingTransforms {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the temperature as float in celsius or fahrenheit based on
|
||||
* the user's current settings.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param celsius The temperature in celsius.
|
||||
* @return The temperature in celsisus or fahrenheit.
|
||||
*/
|
||||
public static float getTemperature(@NonNull Context context, double celsius) {
|
||||
if (MowestaSettings.isTemperatureCelsisus(context)) {
|
||||
return (float)celsius;
|
||||
} else {
|
||||
return (float) Math.round((celsius * 9 / 5) + 32);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the best (non-null) name from a map of names given the current
|
||||
* language settings and the preference for short values.
|
||||
@@ -236,6 +218,8 @@ public class BindingTransforms {
|
||||
return R.string.video_type_pressure;
|
||||
case PRECIPITATION:
|
||||
return R.string.video_type_precipitation;
|
||||
case WIND:
|
||||
return R.string.video_type_wind;
|
||||
default:
|
||||
return R.string.video_type_temperature;
|
||||
}
|
||||
@@ -336,7 +320,7 @@ public class BindingTransforms {
|
||||
case ANDROID:
|
||||
return R.drawable.ic_android_normal_24;
|
||||
case ARDUINO:
|
||||
return R.drawable.ic_memory_black_24dp;
|
||||
return R.drawable.ic_memory_normal_24dp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -373,31 +357,6 @@ public class BindingTransforms {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the format to be used for the measurement type, if the type's data is double.
|
||||
*
|
||||
* @param type The type.
|
||||
* @return The format or 0.
|
||||
*/
|
||||
public static int getMeasurementTypeFormat(MeasurementViewModel.MeasurementType type) {
|
||||
switch (type) {
|
||||
case CPU_FREQUENCY:
|
||||
return R.string.format_frequency;
|
||||
case SOLAR_VOLTAGE:
|
||||
case BATTERY_VOLTAGE:
|
||||
return R.string.format_voltage;
|
||||
case SENSOR_HUMIDITY:
|
||||
return R.string.format_humidity;
|
||||
case SENSOR_PRESSURE:
|
||||
return R.string.format_pressure;
|
||||
case CPU_TEMPERATURE:
|
||||
case BATTERY_TEMPERATURE:
|
||||
case SENSOR_TEMPERATURE:
|
||||
return R.string.format_temperature;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the jam icon for the measurement type.
|
||||
|
||||
@@ -47,6 +47,53 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
void onStationSelected(WeatherStation station);
|
||||
}
|
||||
|
||||
/** The view types to navigate to. */
|
||||
public enum ForecastType { DAY, TIME, HOUR }
|
||||
|
||||
/**
|
||||
* A navigation request caused by a click on a summary.
|
||||
*/
|
||||
public static class NavigationRequest {
|
||||
|
||||
/** The list type to navigate to. */
|
||||
private @NonNull
|
||||
ForecastType type;
|
||||
/** The condition to navigate to. */
|
||||
private @NonNull int position;
|
||||
|
||||
/**
|
||||
* Creates a new request.
|
||||
*
|
||||
* @param type The type.
|
||||
* @param position The position.
|
||||
*/
|
||||
public NavigationRequest(@NonNull ForecastType type, @NonNull int position) {
|
||||
this.type = type;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list type to navigate to.
|
||||
*
|
||||
* @return The type.
|
||||
*/
|
||||
@NonNull
|
||||
public ForecastType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position to navigate to.
|
||||
*
|
||||
* @return The position.
|
||||
*/
|
||||
@NonNull
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The current weather condition.
|
||||
@@ -108,6 +155,11 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
*/
|
||||
private final MutableLiveData<Geometry> boundary = new MutableLiveData<>();
|
||||
|
||||
/**
|
||||
* The livedata to handle navigation between the different forecast fragments.
|
||||
*/
|
||||
private final MutableLiveData<NavigationRequest> navigation = new MutableLiveData<>();
|
||||
|
||||
/**
|
||||
* The loader for the city data.
|
||||
*/
|
||||
@@ -132,7 +184,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
(input, status) -> { finishRequest(input, true); });
|
||||
|
||||
private final ApiTask<RequestParameter<Long>, List<WeatherVideo>> videoLoader = new ApiTask<>
|
||||
((input, client) -> client.getLatestCityVideos(input.getValue()),
|
||||
((input, client) -> client.getLatestCityVideos(input.getValue()),
|
||||
(input, result) -> { completeRequest(input, () -> videos.setValue(result)); },
|
||||
(input, status) -> { finishRequest(input, true); });
|
||||
|
||||
@@ -186,6 +238,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
super(application);
|
||||
id.observeForever((value) -> {
|
||||
long code = newRequestCode();
|
||||
navigation.setValue(null);
|
||||
favorite.setValue(null);
|
||||
forecast.setValue(null);
|
||||
city.setValue(null);
|
||||
@@ -201,6 +254,8 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
forecast.observeForever((c)-> updateConditions());
|
||||
city.observeForever((c)-> { updateConditions(); updateVideos(); updateLinks(); } );
|
||||
videos.observeForever((c) -> updateVideos());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,6 +275,15 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
return favorite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the navigation live data to handle transition between views.
|
||||
*
|
||||
* @return The navigation.
|
||||
*/
|
||||
public MutableLiveData<NavigationRequest> getNavigation() {
|
||||
return navigation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the city.
|
||||
*
|
||||
@@ -394,8 +458,10 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
for (WeatherCondition c: wc) {
|
||||
long end = d.getEnd(c);
|
||||
ConditionViewModel vm = new ConditionViewModel(getApplication());
|
||||
int title = d.getDayName(c.getTime());
|
||||
vm.setData(title == 0 ? null: getApplication().getString(title), null, c, tz);
|
||||
long time = c.getTime();
|
||||
String title = d.getDayName(getApplication(), time);
|
||||
String subtitle = getApplication().getString(R.string.format_two_parts, df.asTime(time, tz), df.asDate(time, tz));
|
||||
vm.setData(title, subtitle, c, tz);
|
||||
hours.add(vm);
|
||||
if (currentDay == null) {
|
||||
currentDay = new ArrayList<>();
|
||||
@@ -437,9 +503,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
List<SummaryViewModel> models = new ArrayList<>();
|
||||
for (List<WeatherCondition> ds: days) {
|
||||
long time = d.getTime(ds);
|
||||
String title = df.asDate(time, tz);
|
||||
int res = d.getDayName(time);
|
||||
if (res != 0) title = getApplication().getString(res);
|
||||
String title = d.getDayName(getApplication(), time);
|
||||
SummaryViewModel summary = new SummaryViewModel(getApplication());
|
||||
WeatherCondition[] data = new WeatherCondition[ds.size()];
|
||||
data = ds.toArray(data);
|
||||
@@ -450,9 +514,7 @@ public class CityViewModel extends AbstractPlaceViewModel {
|
||||
models = new ArrayList<>();
|
||||
for (List<WeatherCondition> ts: times) {
|
||||
long time = d.getTime(ts);
|
||||
String title = df.asDate(time, tz);
|
||||
int res = d.getDayName(time);
|
||||
if (res != 0) title = getApplication().getString(res);
|
||||
String title = d.getDayName(getApplication(), time);
|
||||
int slot = d.getSlotName(time);
|
||||
SummaryViewModel summary = new SummaryViewModel(getApplication());
|
||||
WeatherCondition[] data = new WeatherCondition[ts.size()];
|
||||
|
||||
@@ -18,6 +18,21 @@ import com.mowesta.android.feign.model.WeatherCondition;
|
||||
*/
|
||||
public class ConditionViewModel extends CustomizeViewModel {
|
||||
|
||||
/**
|
||||
* A click listener for weather condition cards.
|
||||
*/
|
||||
public interface OnConditionSelectedListener {
|
||||
|
||||
/**
|
||||
* Called when the condition is selected.
|
||||
*
|
||||
* @param model The condition that has been clicked.
|
||||
*/
|
||||
void onConditionSelected(ConditionViewModel model);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The title to display.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.mowesta.android.app.IApp;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.arduino.ArduinoConfig;
|
||||
import com.mowesta.android.app.arduino.ConnectivityTask;
|
||||
import com.mowesta.android.app.arduino.NetworkTask;
|
||||
import com.mowesta.android.app.arduino.TransferTask;
|
||||
import com.mowesta.android.app.arduino.WifiTask;
|
||||
import com.mowesta.android.app.fragment.ConnectFragment;
|
||||
import com.mowesta.android.app.task.ApiTask;
|
||||
import com.mowesta.android.feign.model.DeviceHandle;
|
||||
import com.mowesta.android.feign.model.DeviceInfo;
|
||||
|
||||
/**
|
||||
* The view model to configure a device.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class ConnectViewModel extends AndroidViewModel {
|
||||
|
||||
/**
|
||||
* The state of the connection process.
|
||||
*/
|
||||
public enum State {
|
||||
/**
|
||||
* We are creating the device.
|
||||
*/
|
||||
DEVICE,
|
||||
/**
|
||||
* We are connecting to the network.
|
||||
*/
|
||||
NETWORK,
|
||||
/**
|
||||
* We are transferring the data to the station.
|
||||
*/
|
||||
CONFIGURE,
|
||||
/**
|
||||
* The process has been completed successfully.
|
||||
*/
|
||||
COMPLETE;
|
||||
}
|
||||
|
||||
/**
|
||||
* The log tag.
|
||||
*/
|
||||
private static final String TAG = "ConnectViewModel";
|
||||
|
||||
/** The current state of the process. */
|
||||
final MutableLiveData<State> state = new MutableLiveData<>(null);
|
||||
|
||||
/** The text to display in the center of the screen. */
|
||||
final MutableLiveData<Integer> messageText = new MutableLiveData<>(R.string.connect_message_creating);
|
||||
|
||||
/** A flag to show the retry button. */
|
||||
final MutableLiveData<Boolean> retryVisible = new MutableLiveData<>(Boolean.FALSE);
|
||||
|
||||
/**
|
||||
* The arguments of the connect fragment with the latitude, longitude,
|
||||
* ssid name and password.
|
||||
*/
|
||||
private ConnectFragment.Args arguments;
|
||||
|
||||
/**
|
||||
* The device handle that is created as the first step.
|
||||
*/
|
||||
private DeviceHandle deviceHandle;
|
||||
|
||||
/**
|
||||
* The network task that is created as the second step.
|
||||
*/
|
||||
private NetworkTask networkTask;
|
||||
|
||||
/**
|
||||
* The transfer task that is created as the third step.
|
||||
*/
|
||||
private TransferTask transferTask;
|
||||
|
||||
/** Flag to indicate whether the process is cancelled. */
|
||||
private boolean cancelled;
|
||||
|
||||
/** The task to create the device handle for the new device. */
|
||||
private ApiTask<Void, DeviceHandle> createDeviceTask = new ApiTask<>((input, client) -> {
|
||||
DeviceInfo info = new DeviceInfo();
|
||||
info.setOs(DeviceInfo.OsEnum.ARDUINO);
|
||||
info.setManufacturer(getApplication().getString(R.string.setup_device_manufacturer));
|
||||
info.setModel(arguments.getDevice());
|
||||
info.setDevice(getApplication().getString(R.string.setup_device_name_default));
|
||||
return client.createDevice(info);
|
||||
}, (input, result) -> {
|
||||
this.deviceHandle = result;
|
||||
if (cancelled) {
|
||||
deleteDevice();
|
||||
} else {
|
||||
this.state.setValue(State.NETWORK);
|
||||
retry();
|
||||
}
|
||||
}, (input, status) -> {
|
||||
messageText.setValue(R.string.connect_message_create_failed);
|
||||
retryVisible.setValue(Boolean.TRUE);
|
||||
});
|
||||
|
||||
/** The task to delete the device, if the view model is disposed without successful completion. */
|
||||
private ApiTask<Long, Long> deleteDeviceTask = new ApiTask<>((input, client) -> {
|
||||
client.deleteDevice(input);
|
||||
return input;
|
||||
}, (input, result) -> {
|
||||
Log.d(TAG, "Device " + result + " deleted successfully.");
|
||||
}, (input, status) -> {
|
||||
Log.d(TAG, "Failed to delete device " + input + ".");
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new view model.
|
||||
*
|
||||
* @param application The application.
|
||||
*/
|
||||
public ConnectViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text to display in the center of the screen.
|
||||
*
|
||||
* @return The text.
|
||||
*/
|
||||
public LiveData<Integer> getMessageText() {
|
||||
return messageText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boolean to determine whether the retry button
|
||||
* is visible.
|
||||
*
|
||||
* @return The boolean with the visibility of the retry button.
|
||||
*/
|
||||
public LiveData<Boolean> getRetryVisible() {
|
||||
return retryVisible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LiveData<State> getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the connect fragment to set the arguments configured
|
||||
* through the setup fragment.
|
||||
*
|
||||
* @param arguments The arguments
|
||||
*/
|
||||
public void init(ConnectFragment.Args arguments) {
|
||||
if (this.arguments == null) {
|
||||
this.arguments = arguments;
|
||||
state.setValue(State.DEVICE);
|
||||
retry();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the device handle.
|
||||
*
|
||||
* @return The device handle.
|
||||
*/
|
||||
public DeviceHandle getDeviceHandle() {
|
||||
return deviceHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the next step based on the current state
|
||||
* of the process.
|
||||
*/
|
||||
public void retry() {
|
||||
retryVisible.setValue(Boolean.FALSE);
|
||||
if (state.getValue() == State.DEVICE) {
|
||||
IApp app = (IApp)getApplication();
|
||||
messageText.setValue(R.string.connect_message_creating);
|
||||
createDeviceTask.execute(null, app.getClientFactory().createClient(app.getUserRepository().getCredentials().getValue()));
|
||||
} else if (state.getValue() == State.NETWORK) {
|
||||
messageText.setValue(R.string.connect_message_searching);
|
||||
NetworkTask.OnNetworkChangedListener listener = (value) -> {
|
||||
if (value) {
|
||||
state.setValue(State.CONFIGURE);
|
||||
retry();
|
||||
} else {
|
||||
state.setValue(State.NETWORK);
|
||||
stopTasks();
|
||||
messageText.setValue(R.string.connect_message_search_failed);
|
||||
retryVisible.setValue(true);
|
||||
}
|
||||
};
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
networkTask = new ConnectivityTask(getApplication(), listener);
|
||||
} else {
|
||||
networkTask = new WifiTask(getApplication(), listener);
|
||||
}
|
||||
} else if (state.getValue() == State.CONFIGURE) {
|
||||
messageText.setValue(R.string.connect_message_transfering);
|
||||
transferTask = new TransferTask(getApplication(), getConfig(), (success) -> {
|
||||
if (!success) {
|
||||
state.setValue(State.NETWORK);
|
||||
stopTasks();
|
||||
messageText.setValue(R.string.connect_message_transfer_failed);
|
||||
retryVisible.setValue(true);
|
||||
} else {
|
||||
state.setValue(State.COMPLETE);
|
||||
stopTasks();
|
||||
messageText.setValue(R.string.connect_message_success);
|
||||
}
|
||||
});
|
||||
transferTask.execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the arduino configuration.
|
||||
*
|
||||
* @return The arduino configuration.
|
||||
*/
|
||||
private ArduinoConfig getConfig() {
|
||||
return new ArduinoConfig
|
||||
(deviceHandle.getId(), deviceHandle.getToken(),
|
||||
arguments.getNetwork(), arguments.getPassword(),
|
||||
arguments.getLongitude(), arguments.getLatitude());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cancels any ongoing progress.
|
||||
*/
|
||||
private void stopTasks() {
|
||||
if (networkTask != null) {
|
||||
networkTask.cancel();
|
||||
networkTask = null;
|
||||
}
|
||||
if (transferTask != null) {
|
||||
transferTask.cancel();
|
||||
transferTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the device.
|
||||
*/
|
||||
private void deleteDevice() {
|
||||
if (deviceHandle != null) {
|
||||
IApp app = (IApp)getApplication();
|
||||
deleteDeviceTask.execute(deviceHandle.getId(), app.getClientFactory().createClient
|
||||
(app.getUserRepository().getCredentials().getValue()));
|
||||
deviceHandle = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCleared() {
|
||||
super.onCleared();
|
||||
stopTasks();
|
||||
this.cancelled = true;
|
||||
if (state.getValue() != State.COMPLETE) {
|
||||
deleteDevice();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.mowesta.android.app.MowestaSettings;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.adapter.EnumPreferenceLiveData;
|
||||
import com.mowesta.android.app.adapter.PreferenceLiveData;
|
||||
|
||||
/**
|
||||
@@ -19,6 +20,16 @@ import com.mowesta.android.app.adapter.PreferenceLiveData;
|
||||
*/
|
||||
public class CustomizeViewModel extends AndroidViewModel {
|
||||
|
||||
/**
|
||||
* The live data with the temperature unit.
|
||||
*/
|
||||
private final EnumPreferenceLiveData<MowestaSettings.TemperatureUnit> temperatureUnit;
|
||||
|
||||
/**
|
||||
* The live data with the unit system.
|
||||
*/
|
||||
private final EnumPreferenceLiveData<MowestaSettings.UnitSystem> unitSystem;
|
||||
|
||||
/**
|
||||
* The live data with the precipitation.
|
||||
*/
|
||||
@@ -59,6 +70,8 @@ public class CustomizeViewModel extends AndroidViewModel {
|
||||
super(application);
|
||||
Resources r = application.getResources();
|
||||
SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(application);
|
||||
unitSystem = new EnumPreferenceLiveData<>(p, MowestaSettings.UnitSystem.class, MowestaSettings.UNIT_SYSTEM, MowestaSettings.UnitSystem.BOTH);
|
||||
temperatureUnit = new EnumPreferenceLiveData<>(p, MowestaSettings.TemperatureUnit.class, MowestaSettings.TEMPERATURE_UNIT, MowestaSettings.TemperatureUnit.BOTH);
|
||||
showPressure = new PreferenceLiveData(p, MowestaSettings.SHOW_PRESSURE, r.getBoolean(R.bool.show_pressure_default));
|
||||
showSnow = new PreferenceLiveData(p, MowestaSettings.SHOW_SNOW, r.getBoolean(R.bool.show_snow_default));
|
||||
showHumidity = new PreferenceLiveData(p, MowestaSettings.SHOW_HUMIDITY, r.getBoolean(R.bool.show_humidity_default));
|
||||
@@ -121,5 +134,21 @@ public class CustomizeViewModel extends AndroidViewModel {
|
||||
return showWind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a live data object to configure the temperature unit.
|
||||
*
|
||||
* @return A live data object to get and configure the temperature unit.
|
||||
*/
|
||||
public EnumPreferenceLiveData<MowestaSettings.TemperatureUnit> getTemperatureUnit() {
|
||||
return temperatureUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a live data object to configure the unit system.
|
||||
*
|
||||
* @return A live data object to configure the unit system.
|
||||
*/
|
||||
public EnumPreferenceLiveData<MowestaSettings.UnitSystem> getUnitSystem() {
|
||||
return unitSystem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,12 @@ public class DevicesViewModel extends AbstractNetworkViewModel {
|
||||
public void loadInitial(@NonNull LoadInitialParams params, @NonNull LoadInitialCallback<Device> callback) {
|
||||
ApiTask<Void, DevicePage> task = new ApiTask<>((v, client) -> { return client.getCurrentUserDevices(0, params.requestedLoadSize ); },
|
||||
(v, page) -> { completeRequest(requestCode, () -> callback.onResult(page.getElements(), 0, page.getTotal())); },
|
||||
(v, status) -> { finishRequest(requestCode, true); });
|
||||
(v, status) -> {
|
||||
if (status == 403) {
|
||||
getApp().getUserRepository().login(getApp().getUserRepository().getCredentials().getValue());
|
||||
}
|
||||
finishRequest(requestCode, true);
|
||||
});
|
||||
if (isCurrentRequest(requestCode)) {
|
||||
if (credentials == null) {
|
||||
callback.onResult(new ArrayList<>(), 0, 0);
|
||||
|
||||
@@ -195,7 +195,7 @@ public class DiagramEntry<T> {
|
||||
*/
|
||||
public static DiagramEntry<Measurement> from(Measurement measurement) {
|
||||
DiagramValue temperature = createValue(measurement.getTemperature(), -40, 40);
|
||||
DiagramValue humidity = createValue(measurement.getHumidity(), 0, 1);
|
||||
DiagramValue humidity = createValue(measurement.getHumidity(), 0, 100);
|
||||
DiagramValue pressure = createValue(measurement.getPressure(), 700, 1200);
|
||||
return new DiagramEntry<>(measurement.getId(), measurement.getTime(), measurement, temperature, humidity, pressure);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,6 @@ public class LoginViewModel extends AndroidViewModel {
|
||||
} else {
|
||||
failure.setValue(R.string.login_failure_network);
|
||||
}
|
||||
System.out.println("Failure is: " + status);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,549 @@
|
||||
package com.mowesta.android.app.model;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
import androidx.core.os.LocaleListCompat;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.fragment.ConnectFragment;
|
||||
import com.mowesta.android.app.util.PermissionUtil;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* The view model to setup an adruino weather station.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class SetupViewModel extends AndroidViewModel {
|
||||
|
||||
/**
|
||||
* The gps status returned when registering a receiver.
|
||||
*/
|
||||
public enum GpsStatus {
|
||||
/** Gps registered. */
|
||||
SUCCESS,
|
||||
/** Gps permission missing. */
|
||||
PROHIBITED,
|
||||
/** Gps disabled. */
|
||||
DISABLED,
|
||||
}
|
||||
|
||||
/**
|
||||
* The view model.
|
||||
*/
|
||||
private static final String TAG = "SetupViewModel";
|
||||
|
||||
/**
|
||||
* The network name.
|
||||
*/
|
||||
final MutableLiveData<String> networkName = new MutableLiveData<>("");
|
||||
|
||||
/**
|
||||
* The validation status of the network name.
|
||||
*/
|
||||
final MutableLiveData<FormStatus> networkNameStatus = new MutableLiveData<>();
|
||||
|
||||
/**
|
||||
* The network password.
|
||||
*/
|
||||
final MutableLiveData<String> networkPassword = new MutableLiveData<>("");
|
||||
|
||||
/**
|
||||
* The validation status of the password.
|
||||
*/
|
||||
final MutableLiveData<FormStatus> networkPasswordStatus = new MutableLiveData<>();
|
||||
|
||||
/**
|
||||
* The device name.
|
||||
*/
|
||||
final MutableLiveData<String> deviceName = new MutableLiveData<>("");
|
||||
|
||||
/**
|
||||
* The validation status of the device name.
|
||||
*/
|
||||
final MutableLiveData<FormStatus> deviceNameStatus = new MutableLiveData<>();
|
||||
|
||||
/**
|
||||
* The longitude as string when entered manually.
|
||||
*/
|
||||
final MutableLiveData<String> longitude = new MutableLiveData<>("");
|
||||
|
||||
/**
|
||||
* The validation status of the longitude.
|
||||
*/
|
||||
final MutableLiveData<FormStatus> longitudeStatus = new MutableLiveData<>();
|
||||
|
||||
/**
|
||||
* The latitude as string when entered manually.
|
||||
*/
|
||||
final MutableLiveData<String> latitude = new MutableLiveData<>("");
|
||||
|
||||
/**
|
||||
* The validation status of the latitude when entered manually.
|
||||
*/
|
||||
final MutableLiveData<FormStatus> latitudeStatus = new MutableLiveData<>();
|
||||
|
||||
/**
|
||||
* The boolean to store whether the user wants to enter the position manually.
|
||||
*/
|
||||
final MutableLiveData<Boolean> manualPosition = new MutableLiveData<>(Boolean.FALSE);
|
||||
|
||||
/**
|
||||
* The boolean to determine whether a gps receiver is registered.
|
||||
*/
|
||||
final MutableLiveData<Boolean> gpsRegistered = new MutableLiveData<>(Boolean.FALSE);
|
||||
|
||||
/**
|
||||
* The boolean to store whether the user can press the gps button. This is
|
||||
* only enabled, when the user is not using a manual position and the gps
|
||||
* is not yet registered.
|
||||
*/
|
||||
final MutableLiveData<Boolean> gpsEnabled = new MutableLiveData<>(Boolean.TRUE);
|
||||
|
||||
/**
|
||||
* The validation status of the whole form.
|
||||
*/
|
||||
final MutableLiveData<Boolean> valid = new MutableLiveData<>(Boolean.FALSE);
|
||||
|
||||
/**
|
||||
* A flag to indicate whether the animation should be played. This is used
|
||||
* to ensure that the "over the top" animation is only played when the view
|
||||
* model is new.
|
||||
*/
|
||||
private boolean animate = true;
|
||||
|
||||
/**
|
||||
* The location listener to receive location updates.
|
||||
*/
|
||||
final LocationListener locationListener = new LocationListener() {
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
if (location.getAccuracy() < 100) {
|
||||
latitude.setValue(SetupViewModel.this.toString(location.getLatitude()));
|
||||
longitude.setValue(SetupViewModel.this.toString(location.getLongitude()));
|
||||
unregisterGpsReciever();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) { }
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) { }
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) { }
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the view model.
|
||||
*
|
||||
* @param application The application.
|
||||
*/
|
||||
public SetupViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
Observer<Boolean> gpsEnabledListener = (b) -> { gpsEnabled.setValue(!gpsRegistered.getValue() && !manualPosition.getValue()); };
|
||||
manualPosition.observeForever(gpsEnabledListener);
|
||||
manualPosition.observeForever((v) -> { if (v) unregisterGpsReciever(); });
|
||||
gpsRegistered.observeForever(gpsEnabledListener);
|
||||
networkName.observeForever((v) -> { validateNetworkName(); validate(); });
|
||||
networkPassword.observeForever((v) -> { validateNetworkPassword(); validate(); });
|
||||
deviceName.observeForever((v) -> { validateDeviceName(); validate(); });
|
||||
manualPosition.observeForever((v) -> { validateLatitude(); validateLongitude(); validate(); });
|
||||
longitude.observeForever((v) -> { validateLongitude(); validate(); });
|
||||
latitude.observeForever((v) -> { validateLatitude(); validate(); });
|
||||
deviceName.setValue(application.getString(R.string.setup_device_name_default));
|
||||
networkName.setValue(loadNetworkName(application));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to get the current wifi network name to which the device is connected
|
||||
* or returns an empty string, if this is not possible.
|
||||
*
|
||||
* @param application The applicaiton.
|
||||
* @return The network name.
|
||||
*/
|
||||
private String loadNetworkName(Application application) {
|
||||
try {
|
||||
String result = "";
|
||||
WifiManager manager = (WifiManager)application.getSystemService(Context.WIFI_SERVICE);
|
||||
if (manager != null) {
|
||||
WifiInfo info = manager.getConnectionInfo();
|
||||
if (info != null) {
|
||||
String ssid = info.getSSID();
|
||||
if (ssid != null && ssid.length() > 2 && ssid.startsWith("\"") && ssid.endsWith("\"")) {
|
||||
result = ssid.substring(1, ssid.length() - 1);
|
||||
} else {
|
||||
Log.d(TAG, "Ignoring invalid ssid: " + ssid);
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Failed to get connection info.");
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Failed to find wifi manager.");
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Failed to load network.", e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the live data with the network name.
|
||||
*
|
||||
* @return The live data with the network name.
|
||||
*/
|
||||
public MutableLiveData<String> getNetworkName() {
|
||||
return networkName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the live data with the status for the network name.
|
||||
*
|
||||
* @return The live data with the status for the network name.
|
||||
*/
|
||||
public LiveData<FormStatus> getNetworkNameStatus() {
|
||||
return networkNameStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the network name.
|
||||
*/
|
||||
private void validateNetworkName() {
|
||||
String string = networkName.getValue();
|
||||
if (string == null || string.length() == 0) {
|
||||
networkNameStatus.setValue(new FormStatus(R.string.setup_error_wlan_name_too_short));
|
||||
} else {
|
||||
networkNameStatus.setValue(FormStatus.VALID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the live data with the network password.
|
||||
*
|
||||
* @return The live data with the network password.
|
||||
*/
|
||||
public MutableLiveData<String> getNetworkPassword() {
|
||||
return networkPassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the live data with the status for the network password.
|
||||
*
|
||||
* @return The live data with the status for the network password.
|
||||
*/
|
||||
public LiveData<FormStatus> getNetworkPasswordStatus() {
|
||||
return networkPasswordStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the network password.
|
||||
*/
|
||||
private void validateNetworkPassword() {
|
||||
String string = networkPassword.getValue();
|
||||
if (string == null || string.length() == 0) {
|
||||
networkPasswordStatus.setValue(new FormStatus(R.string.setup_error_wlan_password_none));
|
||||
} else if (string.length() < 8) {
|
||||
networkPasswordStatus.setValue(new FormStatus(R.string.setup_error_wlan_password_too_short));
|
||||
} else {
|
||||
networkPasswordStatus.setValue(FormStatus.VALID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the live data with the device name.
|
||||
*
|
||||
* @return The live data with the device name.
|
||||
*/
|
||||
public MutableLiveData<String> getDeviceName() {
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the live data with the status for the device name.
|
||||
*
|
||||
* @return The live data with the status for the device name.
|
||||
*/
|
||||
public LiveData<FormStatus> getDeviceNameStatus() {
|
||||
return deviceNameStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the device name.
|
||||
*/
|
||||
private void validateDeviceName() {
|
||||
String string = deviceName.getValue();
|
||||
if (string == null || string.length() == 0) {
|
||||
deviceNameStatus.setValue(new FormStatus(R.string.setup_error_device_name_too_short));
|
||||
} else {
|
||||
deviceNameStatus.setValue(FormStatus.VALID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The live data with the longitude.
|
||||
*
|
||||
* @return The live data with the longitude.
|
||||
*/
|
||||
public MutableLiveData<String> getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* The live data with the longitude status.
|
||||
*
|
||||
* @return The live data with the longitude status.
|
||||
*/
|
||||
public LiveData<FormStatus> getLongitudeStatus() {
|
||||
return longitudeStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the manual longitude input.
|
||||
*/
|
||||
private void validateLongitude() {
|
||||
Double lng = null;
|
||||
try {
|
||||
String string = longitude.getValue();
|
||||
if (string != null) {
|
||||
lng = parseValue(string);
|
||||
if (lng < -180 || lng > 180) {
|
||||
lng = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) { }
|
||||
if (lng != null) {
|
||||
longitudeStatus.setValue(FormStatus.VALID);
|
||||
} else if (!manualPosition.getValue()) {
|
||||
longitudeStatus.setValue(null);
|
||||
} else {
|
||||
longitudeStatus.setValue(new FormStatus(R.string.setup_error_longitude));
|
||||
}
|
||||
}
|
||||
|
||||
private String toString(double value) {
|
||||
LocaleListCompat c = ConfigurationCompat.getLocales(getApplication().getResources().getConfiguration());
|
||||
if (c.size() > 0) {
|
||||
Locale locale = c.get(0);
|
||||
DecimalFormat f = new DecimalFormat("0.000000", new DecimalFormatSymbols(locale));
|
||||
return f.format(value);
|
||||
}
|
||||
return "" + value;
|
||||
}
|
||||
|
||||
private Double parseValue(String value) {
|
||||
if (value == null) return null;
|
||||
LocaleListCompat c = ConfigurationCompat.getLocales(getApplication().getResources().getConfiguration());
|
||||
for (int i = 0; i < c.size(); i++) {
|
||||
Locale l = c.get(i);
|
||||
NumberFormat f = NumberFormat.getNumberInstance(l);
|
||||
try {
|
||||
return ((Number)f.parseObject(value.trim())).doubleValue();
|
||||
} catch (ParseException e) {
|
||||
Log.d(TAG, "Failed to parse double from: " + value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The live data with the latitude.
|
||||
*
|
||||
* @return The live data with the latitude.
|
||||
*/
|
||||
public MutableLiveData<String> getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* The live data with the latitude status.
|
||||
*
|
||||
* @return The live data with the latitude status.
|
||||
*/
|
||||
|
||||
public LiveData<FormStatus> getLatitudeStatus() {
|
||||
return latitudeStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a manually entered latitude.
|
||||
*/
|
||||
public void validateLatitude() {
|
||||
Double lat = null;
|
||||
try {
|
||||
String string = latitude.getValue();
|
||||
if (string != null) {
|
||||
lat = parseValue(string);
|
||||
if (lat < -90 || lat > 90) {
|
||||
lat = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) { }
|
||||
if (lat != null) {
|
||||
latitudeStatus.setValue(FormStatus.VALID);
|
||||
} else if (!manualPosition.getValue()) {
|
||||
latitudeStatus.setValue(null);
|
||||
} else {
|
||||
latitudeStatus.setValue(new FormStatus(R.string.setup_error_latitude));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The live data with the gps state.
|
||||
*
|
||||
* @return The live data with the gps state.
|
||||
*/
|
||||
public MutableLiveData<Boolean> getGpsRegistered() {
|
||||
return gpsRegistered;
|
||||
}
|
||||
|
||||
/**
|
||||
* The live data with the switch state.
|
||||
*
|
||||
* @return The live data with the switch state.
|
||||
*/
|
||||
public MutableLiveData<Boolean> getManualPosition() {
|
||||
return manualPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enabled state of the gps button.
|
||||
*
|
||||
* @return The enabled state of the gps button.
|
||||
*/
|
||||
public MutableLiveData<Boolean> getGpsEnabled() {
|
||||
return gpsEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the live data with the final validity
|
||||
* state of the form.
|
||||
*
|
||||
* @return The live data with the form validity.
|
||||
*/
|
||||
public MutableLiveData<Boolean> getValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the status of the animation flag.
|
||||
*
|
||||
* @return True to animate.
|
||||
*/
|
||||
public boolean isAnimate() {
|
||||
return animate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the animation flag.
|
||||
*
|
||||
* @param animate The animation flag.
|
||||
*/
|
||||
public void setAnimate(boolean animate) {
|
||||
this.animate = animate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the summary of all validation states.
|
||||
*/
|
||||
private void validate() {
|
||||
getValid().setValue(
|
||||
getLongitudeStatus().getValue() != null && ! getLongitudeStatus().getValue().isError() &&
|
||||
getLatitudeStatus().getValue() != null && ! getLatitudeStatus().getValue().isError() &&
|
||||
getDeviceNameStatus().getValue() != null && !getDeviceNameStatus().getValue().isError() &&
|
||||
getNetworkNameStatus().getValue() != null && !getNetworkNameStatus().getValue().isError() &&
|
||||
getNetworkPasswordStatus().getValue() != null && !getNetworkPasswordStatus().getValue().isError()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the gps receiver (if not running already) and returns the
|
||||
* status.
|
||||
*
|
||||
* @return The status of the registration.
|
||||
*/
|
||||
public GpsStatus registerGpsReceiver() {
|
||||
if (gpsRegistered.getValue()) {
|
||||
return GpsStatus.SUCCESS;
|
||||
} else {
|
||||
if (PermissionUtil.hasForegroundPermissions(getApplication())) {
|
||||
LocationManager manager = (LocationManager)getApplication().getSystemService(Context.LOCATION_SERVICE);
|
||||
if (manager != null && manager.getAllProviders().contains(LocationManager.GPS_PROVIDER) && manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||
try {
|
||||
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, locationListener);
|
||||
gpsRegistered.setValue(true);
|
||||
return GpsStatus.SUCCESS;
|
||||
} catch (SecurityException e) {
|
||||
return GpsStatus.PROHIBITED;
|
||||
}
|
||||
} else {
|
||||
return GpsStatus.DISABLED;
|
||||
}
|
||||
} else {
|
||||
return GpsStatus.PROHIBITED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the gps receiver.
|
||||
*/
|
||||
public void unregisterGpsReciever() {
|
||||
if (gpsRegistered.getValue()) {
|
||||
// cleanup the gps receiver
|
||||
LocationManager manager = (LocationManager)getApplication().getSystemService(Context.LOCATION_SERVICE);
|
||||
if (manager != null) {
|
||||
manager.removeUpdates(locationListener);
|
||||
gpsRegistered.setValue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the arguments to connect with.
|
||||
*
|
||||
* @return The arguments.
|
||||
*/
|
||||
public @Nullable ConnectFragment.Args getArgs() {
|
||||
Double latitude = parseValue(getLatitude().getValue());
|
||||
if (latitude == null) return null;
|
||||
Double longitude = parseValue(getLongitude().getValue());
|
||||
if (longitude == null) return null;
|
||||
return new ConnectFragment.Args(getDeviceName().getValue(),
|
||||
getNetworkName().getValue(), getNetworkPassword().getValue(),
|
||||
longitude, latitude);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCleared() {
|
||||
unregisterGpsReciever();
|
||||
super.onCleared();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -18,6 +18,19 @@ import com.mowesta.android.feign.model.WeatherCondition;
|
||||
*/
|
||||
public class SummaryViewModel extends CustomizeViewModel {
|
||||
|
||||
/**
|
||||
* A click listener for the summary view model.
|
||||
*/
|
||||
public interface OnSummarySelectedListener {
|
||||
/**
|
||||
* Called when the summary is selected.
|
||||
*
|
||||
* @param model The model with the summary.
|
||||
*/
|
||||
void onSummarySelected(SummaryViewModel model);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The minimum values.
|
||||
*/
|
||||
@@ -127,6 +140,29 @@ public class SummaryViewModel extends CustomizeViewModel {
|
||||
updateSubtitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first condition contained in the data or null.
|
||||
*
|
||||
* @return The first condition or null.
|
||||
*/
|
||||
@Nullable
|
||||
public WeatherCondition getFirstCondition() {
|
||||
if (conditions == null || conditions.length < 1) return null;
|
||||
return conditions[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last condition contained in the data or null.
|
||||
*
|
||||
* @return The last condition contained in the data.
|
||||
*/
|
||||
@Nullable
|
||||
public WeatherCondition getLastCondition() {
|
||||
if (conditions == null || conditions.length < 1) return null;
|
||||
return conditions[conditions.length - 1];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the min and max values are set.
|
||||
*
|
||||
|
||||
@@ -36,7 +36,8 @@ public class TermsViewModel extends AndroidViewModel {
|
||||
*/
|
||||
public TermsViewModel(@NonNull Application app) {
|
||||
super(app);
|
||||
interactive.setValue(! new MowestaSettings(app).isTermsAccepted());
|
||||
MowestaSettings settings = ((IApp)app).getSettings();
|
||||
interactive.setValue(! settings.isTermsAccepted());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,14 +2,13 @@ package com.mowesta.android.app.repository;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.security.keystore.KeyGenParameterSpec;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.security.crypto.EncryptedFile;
|
||||
import androidx.security.crypto.MasterKeys;
|
||||
import androidx.security.crypto.MasterKey;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -282,9 +281,9 @@ public class FileStoreObserver<T> implements Observer<T> {
|
||||
* be setup.
|
||||
*/
|
||||
@NonNull EncryptedFile getEncryptedFile() throws IOException, GeneralSecurityException {
|
||||
KeyGenParameterSpec keyGenParameterSpec = MasterKeys.AES256_GCM_SPEC;
|
||||
String masterKeyAlias = MasterKeys.getOrCreate(keyGenParameterSpec);
|
||||
return new EncryptedFile.Builder(getFile(), context, masterKeyAlias,
|
||||
MasterKey.Builder b = new MasterKey.Builder(context);
|
||||
b.setKeyScheme(MasterKey.KeyScheme.AES256_GCM);
|
||||
return new EncryptedFile.Builder(context, getFile(), b.build(),
|
||||
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -186,8 +186,10 @@ public class UserRepository extends Repository {
|
||||
switch (error) {
|
||||
case 403:
|
||||
state.setValue(State.INVALID);
|
||||
break;
|
||||
default:
|
||||
state.setValue(State.UNABLE);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mowesta.android.app.util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
@@ -38,8 +39,8 @@ public class DateFormatter {
|
||||
* @return The formatted date with time.
|
||||
*/
|
||||
public String asDateTime(long time, @Nullable String timezone) {
|
||||
Date date = getDate(time, timezone);
|
||||
return getDateFormat().format(date) + " " + getTimeFormat().format(date);
|
||||
Calendar date = getDate(time, timezone);
|
||||
return format(getDateFormat(), date) + " " + format(getTimeFormat(), date);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +51,7 @@ public class DateFormatter {
|
||||
* @return The formatted date.
|
||||
*/
|
||||
public String asDate(long time, @Nullable String timezone) {
|
||||
return getDateFormat().format(getDate(time, timezone));
|
||||
return format(getDateFormat(), getDate(time, timezone));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +62,7 @@ public class DateFormatter {
|
||||
* @return The formatted time.
|
||||
*/
|
||||
public String asTime(long time, @Nullable String timezone) {
|
||||
return getTimeFormat().format(getDate(time, timezone));
|
||||
return format(getTimeFormat(), getDate(time, timezone));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,13 +72,26 @@ public class DateFormatter {
|
||||
* @param timezone The timezone or null to use the host timezone.
|
||||
* @return The date.
|
||||
*/
|
||||
private Date getDate(long time, @Nullable String timezone) {
|
||||
private Calendar getDate(long time, @Nullable String timezone) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
if (timezone != null) {
|
||||
c.setTimeZone(TimeZone.getTimeZone(timezone));
|
||||
|
||||
}
|
||||
c.setTimeInMillis(time);
|
||||
return c.getTime();
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the time in the calendar using the format.
|
||||
*
|
||||
* @param format The format.
|
||||
* @param c The calendar.
|
||||
* @return The string.
|
||||
*/
|
||||
private String format(DateFormat format, Calendar c) {
|
||||
format.setCalendar(c);
|
||||
return format.format(c.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,9 +34,14 @@ import java.util.List;
|
||||
public class MapViewUtil {
|
||||
|
||||
/**
|
||||
* The url.
|
||||
* The url for a light mode tile map.
|
||||
*/
|
||||
private static final String URL = "https://cloud.locoslab.com/carta/get/{z}/{x}/{y}.png";
|
||||
private static final String URL_LIGHT = "https://www.mowesta.com/carta/tile/{z}/{x}/{y}.png";
|
||||
|
||||
/**
|
||||
* The url for a dark mode tile map.
|
||||
*/
|
||||
private static final String URL_DARK = "https://www.mowesta.com/carta/tile/dark/{z}/{x}/{y}.png";
|
||||
|
||||
|
||||
/**
|
||||
@@ -153,7 +158,7 @@ public class MapViewUtil {
|
||||
*/
|
||||
public static void setupNonInteractiveMap(MapView mapView) {
|
||||
setupInteraction(mapView, false);
|
||||
setupTileLayer(mapView);
|
||||
setupTileLayer(mapView, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,19 +181,21 @@ public class MapViewUtil {
|
||||
* Configures an interactive map view.
|
||||
*
|
||||
* @param mapView The map view.
|
||||
* @param darkMode True to enable dark mode, false otherwise
|
||||
*/
|
||||
public static void setupInteractiveMap(MapView mapView) {
|
||||
public static void setupInteractiveMap(MapView mapView, boolean darkMode) {
|
||||
setupInteraction(mapView, true);
|
||||
setupTileLayer(mapView);
|
||||
setupTileLayer(mapView, darkMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a tile layer to the map.
|
||||
*
|
||||
* @param mapView The map view.
|
||||
* @param darkMode True to use dark mode.
|
||||
*/
|
||||
private static void setupTileLayer(MapView mapView) {
|
||||
TileLayerOptions options = new TileLayerOptions(URL);
|
||||
private static void setupTileLayer(MapView mapView, boolean darkMode) {
|
||||
TileLayerOptions options = new TileLayerOptions(darkMode?URL_DARK:URL_LIGHT);
|
||||
options.minZoom = 4;
|
||||
options.maxZoom = 18;
|
||||
TileLayer layer = new TileLayer(options);
|
||||
|
||||
@@ -18,13 +18,35 @@ import java.util.List;
|
||||
public class PermissionUtil {
|
||||
|
||||
/**
|
||||
* Checks whether the location permissions are granted.
|
||||
* Checks whether the location permissions for background localization are granted.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return True if the permissions are granted.
|
||||
*/
|
||||
public static boolean hasPermissions(@NonNull Context context) {
|
||||
public static boolean hasBackgroundPermissions(@NonNull Context context) {
|
||||
return hasPermissions(context, getBackgroundPermissions(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the location permissions for foreground localization are granted.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return True if the permissions are granted.
|
||||
*/
|
||||
public static boolean hasForegroundPermissions(@NonNull Context context) {
|
||||
return hasPermissions(context, getForegroundPermissions(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the permssions have been granted.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param permissions The permissions to check.
|
||||
* @return True if all granted.
|
||||
*/
|
||||
public static boolean hasPermissions(@NonNull Context context, @NonNull String[] permissions) {
|
||||
boolean hasPermissions = true;
|
||||
for (String permission: getPermissions(context)) {
|
||||
for (String permission: permissions) {
|
||||
hasPermissions &= PermissionChecker.checkSelfPermission(context, permission) == PermissionChecker.PERMISSION_GRANTED;
|
||||
}
|
||||
return hasPermissions;
|
||||
@@ -36,9 +58,9 @@ public class PermissionUtil {
|
||||
* @param context The context.
|
||||
* @return The permissions that have not been granted yet.
|
||||
*/
|
||||
public static String[] getNonGrantedPermissions(@NonNull Context context) {
|
||||
public static String[] getNonGrantedBackgroundPermissions(@NonNull Context context) {
|
||||
List<String> nonGranted = new ArrayList<>();
|
||||
for (String permission: getPermissions(context)) {
|
||||
for (String permission: getBackgroundPermissions(context)) {
|
||||
if (PermissionChecker.checkSelfPermission(context, permission) != PermissionChecker.PERMISSION_GRANTED) {
|
||||
nonGranted.add(permission);
|
||||
}
|
||||
@@ -56,7 +78,7 @@ public class PermissionUtil {
|
||||
* @param context The context.
|
||||
* @return The permissions.
|
||||
*/
|
||||
public static String[] getPermissions(@NonNull Context context) {
|
||||
public static String[] getBackgroundPermissions(@NonNull Context context) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||
return new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION };
|
||||
} else {
|
||||
@@ -64,4 +86,14 @@ public class PermissionUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the foreground permissions.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return The permissions required for foreground localization.
|
||||
*/
|
||||
public static String[] getForegroundPermissions(@NonNull Context context) {
|
||||
return new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,11 @@ package com.mowesta.android.app.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Display;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Utility to detect tablets running in landscape mode.
|
||||
@@ -42,4 +47,25 @@ public class TabletUtil {
|
||||
return isLandscape(context) && isTablet(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the screen width in dp.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return The screen width in dp.
|
||||
*/
|
||||
public static float getScreenWidthDp(Context context) {
|
||||
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||
return displayMetrics.widthPixels / displayMetrics.density;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a grid layout such that the items have at least the configured size.
|
||||
*
|
||||
* @param view The view.
|
||||
* @param itemWidthDp The item width in dp.
|
||||
*/
|
||||
public static void setGridLayout(RecyclerView view, int itemWidthDp) {
|
||||
int cols = Math.max(1, (int)(getScreenWidthDp(view.getContext()) / itemWidthDp));
|
||||
view.setLayoutManager(new GridLayoutManager(view.getContext(), cols));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
package com.mowesta.android.app.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.feign.model.WeatherCondition;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@@ -49,20 +58,25 @@ public class TimeUtils {
|
||||
/**
|
||||
* Returns the resource id of the "special" day.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param time The time.
|
||||
* @return The day name.
|
||||
*/
|
||||
public int getDayName(long time) {
|
||||
public String getDayName(Context context, long time) {
|
||||
c.setTimeInMillis(time);
|
||||
update(temp1);
|
||||
if (equals(temp1, yesterday)) {
|
||||
return R.string.date_yesterday;
|
||||
return context.getString(R.string.date_yesterday);
|
||||
} else if (equals(temp1, today)) {
|
||||
return R.string.date_today;
|
||||
return context.getString(R.string.date_today);
|
||||
} else if (equals(temp1, tomorrow)) {
|
||||
return R.string.date_tomorrow;
|
||||
return context.getString(R.string.date_tomorrow);
|
||||
} else {
|
||||
return 0;
|
||||
c.setTimeInMillis(time);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("EEEE",
|
||||
ConfigurationCompat.getLocales(context.getResources().getConfiguration()).get(0));
|
||||
sdf.setCalendar(c);
|
||||
return sdf.format(new Date(time));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
package com.mowesta.android.app.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Spanned;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.text.HtmlCompat;
|
||||
|
||||
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.feign.model.Settings;
|
||||
|
||||
/**
|
||||
* Conversions for measurement units used in the application.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class UnitUtils {
|
||||
|
||||
/**
|
||||
* Converts a temperature from degree Celsius to degree
|
||||
* Fahrenheit.
|
||||
*
|
||||
* @param temperature The temperature in Celsius.
|
||||
* @return The temperature in Fahrenheit.
|
||||
*/
|
||||
public static double celsiusToFahrenheit(double temperature) {
|
||||
return temperature * 9 / 5 + 32;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a speed given in meter per second
|
||||
* into miles/h.
|
||||
*
|
||||
* @param speed The speed in mps.
|
||||
* @return The speed in mph.
|
||||
*/
|
||||
public static double mpsToMph(double speed) {
|
||||
return speed * 3.6 * 0.6213711922373339136;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a speed given in meter per second
|
||||
* into km/h.
|
||||
*
|
||||
* @param speed The speed in mps
|
||||
* @return The speed in km/h.
|
||||
*/
|
||||
public static double mpsToKmph(double speed) {
|
||||
return speed * 3.6;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class on the Beaufort scale for a wind speed
|
||||
* given in meter per second.
|
||||
*
|
||||
* @param value The wind speed.
|
||||
* @return The beaufort scale (0-12).
|
||||
*/
|
||||
public static int mpsToBFT(double value) {
|
||||
if (value < 0.5d)
|
||||
return 0;
|
||||
else if (value < 1.6d)
|
||||
return 1;
|
||||
else if (value < 3.4d)
|
||||
return 2;
|
||||
else if (value < 5.6d)
|
||||
return 3;
|
||||
else if (value < 8.0d)
|
||||
return 4;
|
||||
else if (value < 10.8d)
|
||||
return 5;
|
||||
else if (value < 13.9d)
|
||||
return 6;
|
||||
else if (value < 17.2d)
|
||||
return 7;
|
||||
else if (value < 20.8d)
|
||||
return 8;
|
||||
else if (value < 24.5d)
|
||||
return 9;
|
||||
else if (value < 28.5d)
|
||||
return 10;
|
||||
else if (value < 32.7d)
|
||||
return 11;
|
||||
else
|
||||
return 12;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the pressure given in hpa into
|
||||
* psi.
|
||||
*
|
||||
* @param pressure The pressure in hpa.
|
||||
* @return The pressure in psi.
|
||||
*/
|
||||
public static double hpaToPsi(double pressure) {
|
||||
return 0.0145037738 * pressure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the rain measured in mm into
|
||||
* inches.
|
||||
*
|
||||
* @param rain The rain measured in mm/h.
|
||||
* @return The rain measured in in/h.
|
||||
*/
|
||||
public static double mmToIn(double rain) {
|
||||
return rain / 25.4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the snow height given in meters
|
||||
* into feet.
|
||||
*
|
||||
* @param snow The height in meters.
|
||||
* @return The snow height in feet.
|
||||
*/
|
||||
public static double mToFt(double snow) {
|
||||
return snow * 3.280839895;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds the value to the nearest int.
|
||||
*
|
||||
* @param value The value as double.
|
||||
* @return The nearest int.
|
||||
*/
|
||||
public static int round(double value) {
|
||||
return (int)Math.round(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the settings for the context.
|
||||
*
|
||||
* @param context The context.
|
||||
* @return The settings for the context.
|
||||
*/
|
||||
private static MowestaSettings getSettings(@NonNull Context context) {
|
||||
return ((IApp)context.getApplicationContext()).getSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the html string and returns a spanned.
|
||||
*
|
||||
* @param string The String.
|
||||
* @return The spanned.
|
||||
*/
|
||||
public static Spanned toSpanned(String string) {
|
||||
return HtmlCompat.fromHtml(string, HtmlCompat.FROM_HTML_MODE_COMPACT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the temperature as string.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param celsisus The degree in celisus.
|
||||
* @return The formatted string as defined by the user's preferences.
|
||||
*/
|
||||
public static String getTemperature(@NonNull Context context, double celsisus) {
|
||||
MowestaSettings.TemperatureUnit unit = getSettings(context).getTemperatureUnit();
|
||||
if (unit == MowestaSettings.TemperatureUnit.CELSIUS) {
|
||||
return context.getString(R.string.format_temperature_celsius, celsisus);
|
||||
} else {
|
||||
double fahrenheit = celsiusToFahrenheit(celsisus);
|
||||
if (unit == MowestaSettings.TemperatureUnit.FAHRENHEIT) {
|
||||
return context.getString(R.string.format_temperature_fahrenheit, fahrenheit);
|
||||
} else {
|
||||
return context.getString(R.string.format_temperature_both, celsisus, fahrenheit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPressure(@NonNull Context context, double hpa) {
|
||||
MowestaSettings.UnitSystem system = getSettings(context).getUnitSystem();
|
||||
if (system == MowestaSettings.UnitSystem.STANDARD) {
|
||||
return context.getString(R.string.format_pressure_si, hpa);
|
||||
} else {
|
||||
double psi = hpaToPsi(hpa);
|
||||
if (system == MowestaSettings.UnitSystem.IMPERIAL) {
|
||||
return context.getString(R.string.format_pressure_im, psi);
|
||||
} else {
|
||||
return context.getString(R.string.format_pressure_both, hpa, psi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getWindSpeed(@NonNull Context context, double mps) {
|
||||
MowestaSettings.UnitSystem system = getSettings(context).getUnitSystem();
|
||||
mps = Math.abs(mps); // make sure this is a positive value
|
||||
if (system == MowestaSettings.UnitSystem.STANDARD) {
|
||||
return context.getString(R.string.format_wind_speed_si, round(mpsToKmph(mps)), mpsToBFT(mps));
|
||||
} else {
|
||||
double mph = mpsToMph(mps);
|
||||
if (system == MowestaSettings.UnitSystem.IMPERIAL) {
|
||||
return context.getString(R.string.format_wind_speed_im, round(mph), mpsToBFT(mps));
|
||||
} else {
|
||||
return context.getString(R.string.format_wind_speed_both, round(mpsToKmph(mps)), round(mph));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPrecipitation(@NonNull Context context, double mm) {
|
||||
MowestaSettings.UnitSystem system = getSettings(context).getUnitSystem();
|
||||
mm = Math.max(0, mm); // make sure this is positive
|
||||
if (system == MowestaSettings.UnitSystem.STANDARD) {
|
||||
return context.getString(R.string.format_precipitation_si, mm);
|
||||
} else {
|
||||
double in = mmToIn(mm);
|
||||
if (system == MowestaSettings.UnitSystem.IMPERIAL) {
|
||||
return context.getString(R.string.format_precipitation_im, in);
|
||||
} else {
|
||||
return context.getString(R.string.format_precipitation_both, mm, in);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSnowDepth(@NonNull Context context, double m) {
|
||||
MowestaSettings.UnitSystem system = getSettings(context).getUnitSystem();
|
||||
m = Math.max(0, m); // make sure this is positive
|
||||
if (system == MowestaSettings.UnitSystem.STANDARD) {
|
||||
return context.getString(R.string.format_snow_si, m);
|
||||
} else {
|
||||
double ft = mToFt(m);
|
||||
if (system == MowestaSettings.UnitSystem.IMPERIAL) {
|
||||
return context.getString(R.string.format_snow_im, ft);
|
||||
} else {
|
||||
return context.getString(R.string.format_snow_both, m, ft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getAltitude(@NonNull Context context, double m) {
|
||||
MowestaSettings.UnitSystem system = getSettings(context).getUnitSystem();
|
||||
if (system == MowestaSettings.UnitSystem.STANDARD) {
|
||||
return context.getString(R.string.format_altitude_si, m);
|
||||
} else {
|
||||
double ft = mToFt(m);
|
||||
if (system == MowestaSettings.UnitSystem.IMPERIAL) {
|
||||
return context.getString(R.string.format_altitude_im, ft);
|
||||
} else {
|
||||
return context.getString(R.string.format_altitude_both, m, ft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDiagramPressure(@NonNull Context context, double hpa) {
|
||||
double value = hpa;
|
||||
if (getSettings(context).getUnitSystem() == MowestaSettings.UnitSystem.IMPERIAL) {
|
||||
value = hpaToPsi(hpa);
|
||||
}
|
||||
return context.getString(R.string.format_compact, (float)value);
|
||||
}
|
||||
|
||||
public static String getDiagramTemperature(@NonNull Context context, double celsius) {
|
||||
double value = celsius;
|
||||
if (getSettings(context).getTemperatureUnit() == MowestaSettings.TemperatureUnit.FAHRENHEIT) {
|
||||
value = celsiusToFahrenheit(celsius);
|
||||
}
|
||||
return context.getString(R.string.format_compact, (float)value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
|
||||
/**
|
||||
* A base class for views that show data. Besides from storing the
|
||||
* values this view also contains some funky logic to create a
|
||||
* magnifier effect.
|
||||
*
|
||||
* @param <T> The type of data to display.
|
||||
*/
|
||||
public abstract class DataView<T> extends View {
|
||||
|
||||
|
||||
/** The drawing direction of the gradient. */
|
||||
public enum Direction {
|
||||
/** Draw from left to right. */
|
||||
HORIZONTAL,
|
||||
/** Draw from top to bottom. */
|
||||
VERTICAL;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The drawing direction.
|
||||
*/
|
||||
@NonNull
|
||||
protected Direction direction = Direction.VERTICAL;
|
||||
|
||||
/**
|
||||
* A bitmap to draw the magnifier effect.
|
||||
*/
|
||||
protected Bitmap bitmap;
|
||||
|
||||
/**
|
||||
* The bitmap size in dp.
|
||||
*/
|
||||
protected int bitmapSize;
|
||||
|
||||
/**
|
||||
* The data of the view.
|
||||
*/
|
||||
@Nullable
|
||||
protected T[] data;
|
||||
|
||||
/**
|
||||
* The current selection or null.
|
||||
*/
|
||||
@Nullable
|
||||
protected Float selection;
|
||||
|
||||
@NonNull
|
||||
protected Paint bitmapBorderPaint = new Paint();
|
||||
|
||||
/**
|
||||
* The color for the background.
|
||||
*/
|
||||
private int colorNormal;
|
||||
|
||||
/**
|
||||
* The canvas to draw on the bitmap.
|
||||
*/
|
||||
private Canvas bitmapCanvas;
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public DataView(Context context) {
|
||||
super(context);
|
||||
init(context, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
*/
|
||||
public DataView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The style attrs.
|
||||
*/
|
||||
public DataView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The style attrs.
|
||||
* @param defStyleRes The style res.
|
||||
*/
|
||||
@TargetApi(21)
|
||||
public DataView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attribute set.
|
||||
*/
|
||||
private void init(Context context, @Nullable AttributeSet attrs) {
|
||||
colorNormal = ResourcesCompat.getColor(context.getResources(), R.color.normal, null);
|
||||
DisplayMetrics m = getResources().getDisplayMetrics();
|
||||
bitmapSize = (int)(m.density * 48 + 0.5);
|
||||
bitmapBorderPaint.setColor(ResourcesCompat.getColor(context.getResources(), R.color.inverse, null));
|
||||
bitmapBorderPaint.setStyle(Paint.Style.STROKE);
|
||||
bitmapBorderPaint.setStrokeWidth(4);
|
||||
if (attrs != null) {
|
||||
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.DataView);
|
||||
int type = ta.getInt(R.styleable.DataView_direction,-1);
|
||||
if (type >= 0 && type < Direction.values().length) {
|
||||
this.direction = Direction.values()[type];
|
||||
}
|
||||
ta.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the drawing direction.
|
||||
*
|
||||
* @param direction The drawing direction.
|
||||
*/
|
||||
public void setDirection(@NonNull Direction direction) {
|
||||
this.direction = direction;
|
||||
updateBitmap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the drawing direction.
|
||||
*
|
||||
* @return The drawing direction.
|
||||
*/
|
||||
@NonNull
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current data.
|
||||
*
|
||||
* @param data The data.
|
||||
*/
|
||||
public void setData(@Nullable T[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current data.
|
||||
*
|
||||
* @return The current data.
|
||||
*/
|
||||
@Nullable
|
||||
public T[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data at the relative position.
|
||||
*
|
||||
* @param pos The relative position.
|
||||
* @return The data.
|
||||
*/
|
||||
@Nullable
|
||||
public T getDataAt(float pos) {
|
||||
if (data == null || data.length == 0) return null;
|
||||
int idx = (int)((data.length - 1) * pos);
|
||||
idx = Math.min(Math.max(0, idx), data.length - 1);
|
||||
return data[idx];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
long now = System.currentTimeMillis();
|
||||
super.onDraw(canvas);
|
||||
onDrawData(now, canvas);
|
||||
if (selection != null) {
|
||||
bitmap.eraseColor(colorNormal);
|
||||
if (getBackground() != null) {
|
||||
getBackground().draw(bitmapCanvas);
|
||||
}
|
||||
bitmapCanvas.save();
|
||||
if (direction == Direction.VERTICAL) {
|
||||
bitmapCanvas.scale(1, 3);
|
||||
bitmapCanvas.translate(0, -selection * getHeight() + bitmapSize / 6f);
|
||||
} else {
|
||||
bitmapCanvas.scale(3, 1);
|
||||
bitmapCanvas.translate(-selection * getWidth() + bitmapSize / 6f, 0);
|
||||
}
|
||||
onDrawData(now, bitmapCanvas);
|
||||
bitmapCanvas.restore();
|
||||
if (direction == Direction.VERTICAL) {
|
||||
bitmapCanvas.drawLine(0, 1, bitmap.getWidth(), 1, bitmapBorderPaint);
|
||||
bitmapCanvas.drawLine(0, bitmap.getHeight() - 2, bitmap.getWidth(), bitmap.getHeight() - 2, bitmapBorderPaint);
|
||||
canvas.drawBitmap(bitmap, 0, selection * getHeight() - bitmapSize / 2, null);
|
||||
} else {
|
||||
bitmapCanvas.drawLine( 1, 0, 1, bitmap.getHeight(), bitmapBorderPaint);
|
||||
bitmapCanvas.drawLine(bitmap.getWidth() - 2, 0, bitmap.getWidth() - 2, bitmap.getHeight(), bitmapBorderPaint);
|
||||
canvas.drawBitmap(bitmap, selection * getWidth() - bitmapSize / 2, 0, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelection(@Nullable Float selection) {
|
||||
this.selection = selection;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Float getSelection() {
|
||||
return selection;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
updateBitmap();
|
||||
}
|
||||
|
||||
protected abstract void onDrawData(long time, Canvas canvas);
|
||||
|
||||
/**
|
||||
* Recomputes the bitmap based on the size.
|
||||
*/
|
||||
private void updateBitmap() {
|
||||
if (bitmap != null) {
|
||||
bitmap.recycle();
|
||||
bitmap = null;
|
||||
bitmapCanvas = null;
|
||||
}
|
||||
if (direction == Direction.VERTICAL) {
|
||||
if (getWidth() > 0) {
|
||||
bitmap = Bitmap.createBitmap(getWidth(), bitmapSize, Bitmap.Config.ARGB_8888);
|
||||
bitmapCanvas = new Canvas(bitmap);
|
||||
}
|
||||
} else {
|
||||
if (getHeight() > 0) {
|
||||
bitmap = Bitmap.createBitmap(bitmapSize, getHeight(), Bitmap.Config.ARGB_8888);
|
||||
bitmapCanvas = new Canvas(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* A gradient view that shows rain drops. This is used for the
|
||||
* precipitation.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class DropView extends GradientView {
|
||||
|
||||
/**
|
||||
* The threshold for rain.
|
||||
*/
|
||||
private static final double DROP_THRESHOLD = 0.1;
|
||||
|
||||
/**
|
||||
* The maximum number of water drops to simulate.
|
||||
*/
|
||||
private static final int MAXIMUM_DROPS = 45;
|
||||
|
||||
/**
|
||||
* The speed of the drops in dp.
|
||||
*/
|
||||
private static final int DROP_SPEED = 20;
|
||||
|
||||
/**
|
||||
* The random number generator for drops.
|
||||
*/
|
||||
private Random random = new Random();
|
||||
|
||||
/**
|
||||
* The drawable for a water drop.
|
||||
*/
|
||||
private Drawable drawable;
|
||||
|
||||
/**
|
||||
* The sum of all rain used to skew the random
|
||||
* number generator.
|
||||
*/
|
||||
private double sqrtSum;
|
||||
|
||||
/**
|
||||
* The square roots of the data.
|
||||
*/
|
||||
private double[] sqrts;
|
||||
|
||||
/**
|
||||
* The water drops.
|
||||
*/
|
||||
private WaterDrop[] drops = null;
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public DropView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
*/
|
||||
public DropView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The style.
|
||||
*/
|
||||
public DropView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The style.
|
||||
* @param defStyleRes The style res.
|
||||
*/
|
||||
public DropView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
private void init(Context context) {
|
||||
drawable = AppCompatResources.getDrawable(context, R.drawable.fg_water_drop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Double[] data) {
|
||||
super.setData(data);
|
||||
sqrtSum = 0;
|
||||
if (data != null) {
|
||||
sqrts = new double[data.length];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
if (data[i] > DROP_THRESHOLD) {
|
||||
sqrts[i] = Math.sqrt(data[i]);
|
||||
sqrtSum += sqrts[i];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sqrts = null;
|
||||
}
|
||||
updateDrops();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(@NonNull Direction direction) {
|
||||
super.setDirection(direction);
|
||||
updateDrops();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
updateDrops();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the drops after the data or size has changed.
|
||||
*/
|
||||
private void updateDrops() {
|
||||
if (data != null && data.length > 0 && sqrtSum > 0) {
|
||||
int count = Math.min((int) sqrtSum + 5, MAXIMUM_DROPS);
|
||||
drops = new WaterDrop[count];
|
||||
float density = getResources().getDisplayMetrics().density;
|
||||
for (int i = 0; i < drops.length; i++) {
|
||||
drops[i] = new WaterDrop(density);
|
||||
}
|
||||
postInvalidateOnAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDrawData(long time, Canvas canvas) {
|
||||
super.onDrawData(time, canvas);
|
||||
if (drops != null) {
|
||||
for (int i = 0; i < drops.length; i++) {
|
||||
drops[i].animate(time);
|
||||
drops[i].draw(canvas);
|
||||
}
|
||||
postInvalidateOnAnimation();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to emulate a single water drop.
|
||||
*/
|
||||
private class WaterDrop {
|
||||
|
||||
/**
|
||||
* The current time.
|
||||
*/
|
||||
private long time;
|
||||
/**
|
||||
* The left corner.
|
||||
*/
|
||||
private float x;
|
||||
/**
|
||||
* The top corner.
|
||||
*/
|
||||
private float y;
|
||||
/**
|
||||
* The remaining distance that this drop will
|
||||
* travel (in y direction) before it fades out.
|
||||
*/
|
||||
private float distance;
|
||||
/**
|
||||
* The speed at which the drop moves down in
|
||||
* pixels per second.
|
||||
*/
|
||||
private int speed;
|
||||
/**
|
||||
* The size of the current drop in pixels.
|
||||
*/
|
||||
private float size;
|
||||
/**
|
||||
* The alpha value used for drawing.
|
||||
*/
|
||||
private float alpha;
|
||||
/**
|
||||
* The screen density to compute random sizes
|
||||
* in dp.
|
||||
*/
|
||||
private float density;
|
||||
|
||||
/**
|
||||
* Creates a new drop.
|
||||
*
|
||||
* @param density The screen density.
|
||||
*/
|
||||
private WaterDrop(float density) {
|
||||
this.density = density;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a new random starting location for the water drop
|
||||
* as well as the size, movement speed (larger drops are faster)
|
||||
* and the distance to travel.
|
||||
*/
|
||||
private void reset() {
|
||||
int value = random.nextInt(5);
|
||||
size = this.density * (value + 3);
|
||||
float speedFactor = 0.5f + (value + 1) / 10f;
|
||||
speed = (int)(speedFactor * density * DROP_SPEED);
|
||||
float percent = random.nextFloat();
|
||||
double position = percent * sqrtSum;
|
||||
double current = 0;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
if (data[i] > DROP_THRESHOLD) current += sqrts[i];
|
||||
if (current >= position) {
|
||||
int start = i;
|
||||
int end = i;
|
||||
for (int j = start - 1; j >= Math.max(0, i - 8); j--) {
|
||||
if (data[j] > data[i]) start = j;
|
||||
else break;
|
||||
}
|
||||
for (int j = end + i; j < Math.min(data.length, i + 8); j++) {
|
||||
if (data[j] > data[i]) end = j;
|
||||
else break;
|
||||
}
|
||||
|
||||
if (direction == Direction.VERTICAL) {
|
||||
float dh = getHeight() / (float)data.length;
|
||||
y = dh * (start - random.nextFloat());
|
||||
x = (getWidth() - size) * random.nextFloat();
|
||||
distance = dh * (end + random.nextFloat()) - y;
|
||||
} else {
|
||||
float dw = getWidth() / (float)data.length;
|
||||
y = getHeight() * random.nextFloat();
|
||||
x = dw * (i + random.nextFloat());
|
||||
distance = (getHeight() - y) * random.nextFloat();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
alpha = 0.5f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Animates the drop for the current time.
|
||||
*
|
||||
* @param time The current time.
|
||||
*/
|
||||
public void animate(long time) {
|
||||
if (this.time == 0) {
|
||||
reset();
|
||||
} else {
|
||||
moveBy(time - this.time);
|
||||
if (alpha <= 0) {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the animation forward by a delta t in millis.
|
||||
*
|
||||
* @param delta The delta t in millis.
|
||||
*/
|
||||
private void moveBy(long delta) {
|
||||
int shift = (int)(size * (random.nextFloat() - .5f));
|
||||
float dx = delta / 1000f;
|
||||
float newy = y + dx * speed;
|
||||
x = x + dx * shift;
|
||||
distance -= newy - y;
|
||||
alpha = (float)Math.min(1, Math.max(0, 1 + distance / (size / 2)));
|
||||
y = newy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the drop in its current state.
|
||||
*
|
||||
* @param canvas The canvas to draw onto.
|
||||
*/
|
||||
public void draw(Canvas canvas) {
|
||||
int a = (int)Math.max(0, Math.min(255, alpha * 255));
|
||||
drawable.setAlpha(a);
|
||||
int ix = (int)x;
|
||||
int iy = (int)y;
|
||||
int s = (int)(size * alpha);
|
||||
drawable.setBounds(ix, iy, ix + s, iy + s);
|
||||
drawable.draw(canvas);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.gms.common.SignInButton;
|
||||
import com.mowesta.android.app.view.color.IColorScheme;
|
||||
|
||||
/**
|
||||
* A gradient view that joins two data items to get a color.
|
||||
* This is required to join the cloud depth and coverage.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class DualGradientView extends GradientView {
|
||||
|
||||
/**
|
||||
* The secondary data.
|
||||
*/
|
||||
@Nullable
|
||||
private Double[] secondaryData;
|
||||
|
||||
/**
|
||||
* The secondary color scheme.
|
||||
*/
|
||||
@Nullable
|
||||
private IColorScheme secondaryColorScheme;
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public DualGradientView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
*/
|
||||
public DualGradientView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The default attributes.
|
||||
*/
|
||||
public DualGradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The default attributes.
|
||||
* @param defStyleRes The default res.
|
||||
*/
|
||||
public DualGradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the secondary color scheme.
|
||||
*
|
||||
* @param secondaryColorScheme The secondary color scheme.
|
||||
*/
|
||||
public void setSecondaryColorScheme(@Nullable IColorScheme secondaryColorScheme) {
|
||||
this.secondaryColorScheme = secondaryColorScheme;
|
||||
updateColors();
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the secondary data.
|
||||
*
|
||||
* @param secondaryData The secondary data.
|
||||
*/
|
||||
public void setSecondaryData(@Nullable Double[] secondaryData) {
|
||||
this.secondaryData = secondaryData;
|
||||
updateColors();
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateColors() {
|
||||
super.updateColors();
|
||||
if (colors != null && secondaryData != null && secondaryColorScheme != null && secondaryData.length == colors.length) {
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
int cover = colors[i];
|
||||
int other = secondaryColorScheme.getColor(secondaryData[i]);
|
||||
colors[i] = (cover & 0xFF000000) | (other & 0x00FFFFFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Shader;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mowesta.android.app.view.color.IColorScheme;
|
||||
|
||||
/**
|
||||
* A view to display weather information as a gradient that is
|
||||
* drawn efficiently using the graphics card of the device.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class GradientView extends DataView<Double> {
|
||||
|
||||
/**
|
||||
* The color scheme.
|
||||
*/
|
||||
@Nullable
|
||||
protected IColorScheme colorScheme;
|
||||
|
||||
/**
|
||||
* The colors for the data.
|
||||
*/
|
||||
@Nullable
|
||||
protected int[] colors;
|
||||
|
||||
/**
|
||||
* The positions for the data.
|
||||
*/
|
||||
@Nullable
|
||||
protected float[] positions;
|
||||
|
||||
/**
|
||||
* The gradient for the data.
|
||||
*/
|
||||
@Nullable
|
||||
protected LinearGradient gradient;
|
||||
|
||||
/**
|
||||
* The paint to draw the gradient.
|
||||
*/
|
||||
protected Paint paint = new Paint();
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public GradientView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
*/
|
||||
public GradientView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
* @param defStyleAttr The default style.
|
||||
*/
|
||||
public GradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
* @param defStyleAttr The default style.
|
||||
* @param defStyleRes The default res.
|
||||
*/
|
||||
@TargetApi(21)
|
||||
public GradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
private void init(Context context) {
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Double[] data) {
|
||||
this.data = data;
|
||||
updatePositions();
|
||||
updateColors();
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color scheme to render the data.
|
||||
*
|
||||
* @return The color scheme.
|
||||
*/
|
||||
@Nullable
|
||||
public IColorScheme getColorScheme() {
|
||||
return colorScheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color scheme to render the data.
|
||||
*
|
||||
* @param colorScheme The color scheme.
|
||||
*/
|
||||
public void setColorScheme(@Nullable IColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
updateColors();
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(@NonNull Direction direction) {
|
||||
this.direction = direction;
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDrawData(long time, Canvas canvas) {
|
||||
if (gradient != null) {
|
||||
paint.setShader(gradient);
|
||||
canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the gradient to draw the data.
|
||||
*/
|
||||
protected void updateGradient() {
|
||||
if (colors == null || positions == null) {
|
||||
gradient = null;
|
||||
} else {
|
||||
float x = direction == Direction.HORIZONTAL ? getWidth(): 0;
|
||||
float y = direction == Direction.HORIZONTAL ? 0 : getHeight();
|
||||
gradient = new LinearGradient(0, 0, x, y, colors, positions, Shader.TileMode.CLAMP);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the positions of the gradient.
|
||||
*/
|
||||
protected void updatePositions() {
|
||||
if (data == null) {
|
||||
positions = null;
|
||||
} else {
|
||||
positions = new float[data.length];
|
||||
for (int i = 0; i < positions.length; i++) {
|
||||
positions[i] = 0.5f/data.length + i/(float)data.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the colors of the gradient.
|
||||
*/
|
||||
protected void updateColors() {
|
||||
if (data == null || colorScheme == null) {
|
||||
colors = null;
|
||||
} else {
|
||||
colors = new int[data.length];
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
colors[i] = colorScheme.getColor(data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import com.locoslab.library.geometry.util.clipper.Clipper;
|
||||
import com.mowesta.android.app.R;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This data view generates particles moving at a data-dependent
|
||||
* speed. The particles are drawn as a linear gradient. The size
|
||||
* of the gradient also depends on the speed. This view is used
|
||||
* to draw the wind speed.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class ParticleView extends DataView<Double> {
|
||||
|
||||
/**
|
||||
* A random number generator to share across all
|
||||
* particles.
|
||||
*/
|
||||
@NonNull
|
||||
private Random random = new Random();
|
||||
|
||||
/**
|
||||
* The particles that store their current position.
|
||||
*/
|
||||
@Nullable
|
||||
private Particle[] particles;
|
||||
|
||||
/**
|
||||
* The paint to draw the particles.
|
||||
*/
|
||||
@NonNull
|
||||
private Paint paint = new Paint();
|
||||
|
||||
/**
|
||||
* A factor to speed up or slow down the motion. This
|
||||
* factor is multiplied by the speed in meter per second
|
||||
* to get the motion in pixels per second.
|
||||
*/
|
||||
private float speedFactor = 10;
|
||||
|
||||
/**
|
||||
* The relative length of the particle tails. This
|
||||
* is used to derive the maximum length.
|
||||
*/
|
||||
private float relativeLength = .5f;
|
||||
|
||||
/**
|
||||
* The relative height of the particle tails. This
|
||||
* is used to derive the stroke width.
|
||||
*/
|
||||
private float relativeHeight = .5f;
|
||||
|
||||
/**
|
||||
* The randomized start time.
|
||||
*/
|
||||
private int randomizeTime = 2000;
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public ParticleView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
*/
|
||||
public ParticleView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
* @param defStyleAttr The default style attrs.
|
||||
*/
|
||||
public ParticleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
* @param defStyleAttr The default style attrs.
|
||||
* @param defStyleRes The default style res.
|
||||
*/
|
||||
@TargetApi(21)
|
||||
public ParticleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
private void init(Context context) {
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setStrokeCap(Paint.Cap.ROUND);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDrawData(long time, Canvas canvas) {
|
||||
if (particles != null) {
|
||||
for (int i = particles.length - 1; i >= 0; i--) {
|
||||
particles[i].animate(time);
|
||||
particles[i].draw(canvas, paint);
|
||||
}
|
||||
postInvalidateOnAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(@Nullable Double[] data) {
|
||||
super.setData(data);
|
||||
updateParticles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(@NonNull Direction direction) {
|
||||
super.setDirection(direction);
|
||||
updateParticles();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
updateParticles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-computes the particle's based on the data and the direction.
|
||||
*/
|
||||
private void updateParticles() {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
if (data == null || data.length == 0 || width == 0 || height == 0) {
|
||||
particles = null;
|
||||
} else {
|
||||
Direction dir = direction==Direction.VERTICAL?Direction.HORIZONTAL:Direction.VERTICAL;
|
||||
int color = ResourcesCompat.getColor(getResources(), R.color.particle, null);
|
||||
double max = 0;
|
||||
for (int i = 0; i < data.length; i++)
|
||||
max = Math.max(max, data[i]);
|
||||
particles = new Particle[data.length];
|
||||
float cell = (direction == Direction.VERTICAL?height:width) / (float)data.length;
|
||||
float length = (direction == Direction.VERTICAL?width:height) * relativeLength;
|
||||
float size = direction == Direction.VERTICAL?width:height;
|
||||
paint.setStrokeWidth(cell * relativeHeight);
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
RectF rect = direction == Direction.VERTICAL ? new RectF(0, cell * i, size, cell * (i + 1)) :
|
||||
new RectF(cell * i, 0, cell * (i + 1), size);
|
||||
float speed = (float)(speedFactor * data[i]);
|
||||
float tail = (float)(max == 0 ? 0 : (data[i] / max)) * length;
|
||||
particles[i] = new Particle(random, rect, dir, color, speed, tail, randomizeTime);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A single particle that moves into horizontal or vertical direction.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
private static class Particle {
|
||||
|
||||
/** A random number generator to make the particle less predictable. */
|
||||
@NonNull
|
||||
private Random random;
|
||||
|
||||
/** The movement direction (horizontal: left to right, vertical: top to bottom). */
|
||||
@NonNull
|
||||
private Direction direction;
|
||||
|
||||
/** The rectangle in which we draw. */
|
||||
@NonNull
|
||||
private RectF rect;
|
||||
|
||||
/** The current x-position of the particle (head). */
|
||||
private float x;
|
||||
/** The current y-position of the particle (head). */
|
||||
private float y;
|
||||
/** The length of the particle's tail. */
|
||||
private float length;
|
||||
/** The movement speed in pixels per second. */
|
||||
private float speed;
|
||||
/** The time used to randomize restarts. */
|
||||
private int randomize;
|
||||
/** The time when the particle's position was last computed. */
|
||||
private long time;
|
||||
|
||||
/** A gradient to quickly draw the particle. */
|
||||
@NonNull
|
||||
private LinearGradient gradient;
|
||||
/** The translation matrix to avoid object allocations. */
|
||||
@NonNull
|
||||
private Matrix matrix = new Matrix();
|
||||
|
||||
/**
|
||||
* A single particle that moves either vertically or horizontally.
|
||||
*
|
||||
* @param random A random number generator.
|
||||
* @param rect The rectangle in which the particle moves.
|
||||
* @param direction The direction to move (left to right or top to bottom).
|
||||
* @param speed The movement speed in pixels per second.
|
||||
* @param length The length of the tail of the particle.
|
||||
* @param randomize The time used to randomize the restart when the particle moved off the screen.
|
||||
*/
|
||||
public Particle(@NonNull Random random, @NonNull RectF rect, @NonNull Direction direction, int color, float speed, float length, int randomize) {
|
||||
this.random = random;
|
||||
this.direction = direction;
|
||||
this.rect = rect;
|
||||
this.speed = speed;
|
||||
this.length = length;
|
||||
this.randomize = randomize;
|
||||
gradient = new LinearGradient(0, 0,
|
||||
direction == Direction.HORIZONTAL?length:0,
|
||||
direction == Direction.HORIZONTAL?0:length,
|
||||
new int[] { 0x00ffffff, color },
|
||||
new float[] { 0f, 1f}, Shader.TileMode.CLAMP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the particle onto the canvas.
|
||||
*
|
||||
* @param c The canvas.
|
||||
* @param paint The paint to draw with.
|
||||
*/
|
||||
public void draw(Canvas c, Paint paint) {
|
||||
float xs = (direction == Direction.HORIZONTAL)? x - length: x;
|
||||
float ys = (direction == Direction.HORIZONTAL)? y : y - length;
|
||||
matrix.setTranslate(xs, ys);
|
||||
gradient.setLocalMatrix(matrix);
|
||||
paint.setShader(gradient);
|
||||
c.drawLine(xs , ys, x, y, paint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the animation state based on the time.
|
||||
*
|
||||
* @param time The time.
|
||||
*/
|
||||
public void animate(long time) {
|
||||
if (this.time == 0 || isFinished()) {
|
||||
reset(this.time == 0);
|
||||
} else {
|
||||
moveBy(time - this.time);
|
||||
}
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the particle has moved out of sight.
|
||||
*
|
||||
* @return True if it has moved out of sight. False otherwise.
|
||||
*/
|
||||
private boolean isFinished() {
|
||||
if (direction == Direction.HORIZONTAL) {
|
||||
return x - length > rect.right;
|
||||
} else {
|
||||
return y - length > rect.bottom;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the particle to a new initial position.
|
||||
*
|
||||
* @param init True, if the positions shall be randomly distributed.
|
||||
*/
|
||||
private void reset(boolean init) {
|
||||
float movement = random.nextInt(randomize) / 1000f * speed;
|
||||
if (direction == Direction.HORIZONTAL) {
|
||||
x = rect.left - movement + (init?rect.width() * random.nextFloat():0);
|
||||
y = rect.top + (rect.bottom - rect.top) * 0.5f;
|
||||
} else {
|
||||
x = rect.left + (rect.right - rect.left) * 0.5f;
|
||||
y = rect.top - movement + (init?rect.height() * random.nextFloat():0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the particle depending on the time passed.
|
||||
*
|
||||
* @param delta The time passed in milliseconds.
|
||||
*/
|
||||
private void moveBy(long delta) {
|
||||
float movement = delta / 1000f * speed;
|
||||
if (direction == Direction.HORIZONTAL) {
|
||||
x += movement;
|
||||
} else {
|
||||
y += movement;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.util.TimeUtils;
|
||||
|
||||
/**
|
||||
* The view to display the time and to handle touch events.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class TimeView extends DataView<Long> {
|
||||
|
||||
/**
|
||||
* An interface for listeners that want to be
|
||||
* informed about touch events.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public interface OnSlideListener {
|
||||
|
||||
/**
|
||||
* Called when there is a slide event on the view at
|
||||
* the specified relative position.
|
||||
*
|
||||
* @param relative The relative position (0 to 1).
|
||||
*/
|
||||
void onSlide(float relative);
|
||||
|
||||
|
||||
void onSlideEnd();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A listener to handle the touch events on the view.
|
||||
*
|
||||
*/
|
||||
private static class TouchListener implements View.OnTouchListener {
|
||||
|
||||
/** The epsilon to ignore duplicate events. */
|
||||
private float EPSILON = 0.0001f;
|
||||
|
||||
/** The time view that is observed by this listener. */
|
||||
private TimeView view;
|
||||
|
||||
/** A cache for the view position.*/
|
||||
private int[] viewPosition = new int[2];
|
||||
|
||||
/**
|
||||
* If down, the id of the pointer that we are tracking.
|
||||
*/
|
||||
private int id = 0;
|
||||
|
||||
/**
|
||||
* A boolean to memorize whether we already saw a finger going down.
|
||||
*/
|
||||
private boolean down = false;
|
||||
|
||||
/**
|
||||
* The last relative position that we saw.
|
||||
*/
|
||||
private float position = 0;
|
||||
|
||||
@NonNull
|
||||
private OnSlideListener listener;
|
||||
|
||||
public TouchListener(@NonNull TimeView view, @NonNull OnSlideListener listener) {
|
||||
this.view = view;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
updateViewPosition();
|
||||
int index = event.getActionIndex();
|
||||
int mask = event.getActionMasked();
|
||||
boolean onView = isOnView(event);
|
||||
switch (mask) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
if (! down && onView) {
|
||||
down = true;
|
||||
id = event.getPointerId(index);
|
||||
position = getPosition(event);
|
||||
listener.onSlide(position);
|
||||
};
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (down && id == event.getPointerId(index)) {
|
||||
float np = getPosition(event);
|
||||
if (Math.abs(np - position) > EPSILON) {
|
||||
position = np;
|
||||
listener.onSlide(position);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (down && id == event.getPointerId(index)) {
|
||||
down = false;
|
||||
listener.onSlideEnd();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return down;
|
||||
}
|
||||
|
||||
private void updateViewPosition() {
|
||||
view.getLocationOnScreen(viewPosition);
|
||||
}
|
||||
|
||||
private float getPosition(MotionEvent event) {
|
||||
if (view.getDirection() == Direction.HORIZONTAL) {
|
||||
if (view.getWidth() == 0) return 0;
|
||||
float x = event.getRawX();
|
||||
return Math.min(1, Math.max(0, (x - viewPosition[0]) / view.getWidth()));
|
||||
} else {
|
||||
if (view.getHeight() == 0) return 0;
|
||||
float y = event.getRawY();
|
||||
return Math.min(1, Math.max(0, (y - viewPosition[1]) / view.getHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOnView(MotionEvent event) {
|
||||
float x = event.getRawX();
|
||||
float y = event.getRawY();
|
||||
return x >= viewPosition[0] && x < viewPosition[0] + view.getWidth()
|
||||
&& y >= viewPosition[1] && y < viewPosition[1] + view.getHeight();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The timezone.
|
||||
*/
|
||||
private String timezone;
|
||||
|
||||
/**
|
||||
* The positions to draw lines.
|
||||
*/
|
||||
private float[] positions;
|
||||
|
||||
/**
|
||||
* The lengths of the lines at the positions.
|
||||
*/
|
||||
private float[] lengths;
|
||||
|
||||
/**
|
||||
* The paint to draw the lines.
|
||||
*/
|
||||
private Paint paint = new Paint();
|
||||
|
||||
/**
|
||||
* The paint to draw the current time.
|
||||
*/
|
||||
private Paint paintNow = new Paint();
|
||||
|
||||
/**
|
||||
* The circle animation.
|
||||
*/
|
||||
private TouchCircleAnimation animation = new TouchCircleAnimation(this);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public TimeView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
*/
|
||||
public TimeView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The default attributes.
|
||||
*/
|
||||
public TimeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The default attributes.
|
||||
* @param defStyleRes The default style.
|
||||
*/
|
||||
@TargetApi(21)
|
||||
public TimeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
private void init(Context context) {
|
||||
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||
paint.setStrokeWidth((int)(1f * displayMetrics.density + .5f));
|
||||
paint.setColor(ResourcesCompat.getColor(context.getResources(), R.color.inverse, null));
|
||||
paint.setAntiAlias(true);
|
||||
paintNow.setStrokeWidth((int)(2f * displayMetrics.density + .5f));
|
||||
paintNow.setColor(ResourcesCompat.getColor(context.getResources(), R.color.primary, null));
|
||||
paintNow.setAntiAlias(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an touch listener for this view.
|
||||
*
|
||||
* @param listener The listener to keep track of events.
|
||||
* @return The touch listener.
|
||||
*/
|
||||
public View.OnTouchListener createOnTouchListener(@NonNull OnSlideListener listener) {
|
||||
return new TouchListener(this, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timezone to draw the hours.
|
||||
*
|
||||
* @param timezone The timezone.
|
||||
*/
|
||||
public void setTimezone(String timezone) {
|
||||
this.timezone = timezone;
|
||||
updateTimes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time zone.
|
||||
*
|
||||
* @return The timezone.
|
||||
*/
|
||||
public String getTimezone() {
|
||||
return timezone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(@Nullable Long[] data) {
|
||||
super.setData(data);
|
||||
updateTimes();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
updateTimes();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDrawData(long time, Canvas canvas) {
|
||||
animation.animate(time);
|
||||
animation.draw(canvas);
|
||||
if (positions != null) {
|
||||
// draw now
|
||||
for (int i = 1; i < data.length; i++) {
|
||||
if (time > data[i - 1] && time <= data[i]) {
|
||||
float fraction = (data[i] - time) / (data[i] - data[i - 1]);
|
||||
float pos = (direction == Direction.VERTICAL?getHeight():getWidth()) * (i + fraction) / data.length;
|
||||
float end = direction == Direction.VERTICAL?getWidth():getHeight();
|
||||
if (direction == Direction.VERTICAL) {
|
||||
canvas.drawLine(0, pos, end, pos, paintNow);
|
||||
} else {
|
||||
canvas.drawLine(pos, 0, pos, end, paintNow);
|
||||
}
|
||||
}
|
||||
}
|
||||
// draw grid
|
||||
float center = (direction == Direction.VERTICAL?getWidth():getHeight()) / 2f;
|
||||
for (int i = 0; i < positions.length; i++) {
|
||||
float xs = direction == Direction.VERTICAL?center - .5f * lengths[i]:positions[i];
|
||||
float xe = direction == Direction.VERTICAL?center + .5f * lengths[i]:positions[i];
|
||||
float ys = direction == Direction.HORIZONTAL?center - .5f * lengths[i]:positions[i];
|
||||
float ye = direction == Direction.HORIZONTAL?center + .5f * lengths[i]:positions[i];
|
||||
canvas.drawLine(xs, ys, xe, ye, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTimes() {
|
||||
if (data == null || data.length == 0) {
|
||||
lengths = null;
|
||||
positions = null;
|
||||
} else {
|
||||
int[] hours = new int[data.length];
|
||||
TimeUtils time = new TimeUtils(System.currentTimeMillis(), timezone);
|
||||
int ranges = 0;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
hours[i] = time.getHour(data[i]);
|
||||
if (hours[i] % 6 == 0) {
|
||||
ranges += 1;
|
||||
}
|
||||
}
|
||||
positions = new float[ranges];
|
||||
lengths = new float[ranges];
|
||||
int index = 0;
|
||||
int total = direction == Direction.VERTICAL?getHeight():getWidth();
|
||||
int max = direction == Direction.VERTICAL?getWidth():getHeight();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
if (hours[i] % 6 == 0) {
|
||||
positions[index] = ((float)total / data.length) * (i + .5f);
|
||||
lengths[index] = hours[i] == 0 ? (max * .75f): (max * 0.25f);
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class TouchCircleAnimation {
|
||||
|
||||
/** The center of the click. */
|
||||
float cx, cy;
|
||||
/** The animated radius. */
|
||||
float radius;
|
||||
/** The animated alpha value. */
|
||||
float alpha;
|
||||
/** The speed at which the circle expands. */
|
||||
float expand = 500;
|
||||
/**
|
||||
* The speed at which the alpha value decays.
|
||||
*/
|
||||
float fade = 2f;
|
||||
/** The Animation time. */
|
||||
long time = 0;
|
||||
/** The number of repeatitions. */
|
||||
int repeat = 0;
|
||||
/** A boolean to indicate when done. */
|
||||
boolean done = false;
|
||||
/** The paint to draw. */
|
||||
Paint paint = new Paint();
|
||||
/** The view. */
|
||||
DataView<?> view;
|
||||
/** The finger drawable. */
|
||||
Drawable touch;
|
||||
|
||||
public TouchCircleAnimation(DataView<?> view) {
|
||||
this.view = view;
|
||||
this.touch = AppCompatResources.getDrawable(view.getContext(), R.drawable.ic_touch_app_normal_24);
|
||||
paint.setColor(ResourcesCompat.getColor(view.getResources(), R.color.accent, null));
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
}
|
||||
|
||||
|
||||
public void animate(long now) {
|
||||
if (time == 0) {
|
||||
reset();
|
||||
} else {
|
||||
updateBy(now - time);
|
||||
if (alpha < 0) {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
time = now;
|
||||
done = repeat > 3;
|
||||
}
|
||||
|
||||
private void updateBy(long delta) {
|
||||
float dx = delta / 1000f;
|
||||
alpha -= dx * fade;
|
||||
radius += dx * expand;
|
||||
}
|
||||
|
||||
|
||||
public void draw(Canvas c) {
|
||||
if (!done) {
|
||||
if (repeat > 1) {
|
||||
int a = (int)Math.min(255, Math.max(0, 255 * alpha));
|
||||
paint.setAlpha(Math.min(255, a + 128));
|
||||
c.drawCircle(cx, cy, radius, paint);
|
||||
touch.setAlpha(a);
|
||||
touch.draw(c);
|
||||
}
|
||||
postInvalidateOnAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void reset() {
|
||||
cx = getWidth() / 2;
|
||||
cy = getHeight() / 2;
|
||||
if (view.direction == Direction.VERTICAL) {
|
||||
cy = cy / 2f;
|
||||
}
|
||||
int padding = (int)(Math.min(getWidth(), getHeight()) * 0.1f);
|
||||
int size = Math.min(getWidth(), getHeight()) / 2 - padding;
|
||||
touch.setBounds((int)cx - size, (int)cy - size, (int)cx + size, (int) cy + size);
|
||||
radius = 1;
|
||||
alpha = 1;
|
||||
repeat += 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,17 +2,21 @@ package com.mowesta.android.app.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.DrawFilter;
|
||||
import android.text.TextPaint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatTextView;
|
||||
|
||||
import com.google.android.material.textview.MaterialTextView;
|
||||
|
||||
/**
|
||||
* A text view that draws vertical text.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class VerticalTextView extends AppCompatTextView {
|
||||
public class VerticalTextView extends MaterialTextView {
|
||||
|
||||
/**
|
||||
* The drawing direction.
|
||||
@@ -73,14 +77,23 @@ public class VerticalTextView extends AppCompatTextView {
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
TextPaint textPaint = getPaint();
|
||||
textPaint.setColor( getCurrentTextColor() );
|
||||
textPaint.drawableState = getDrawableState();
|
||||
canvas.save();
|
||||
if (topDown) {
|
||||
canvas.translate(getWidth(), 0);
|
||||
canvas.rotate(90);
|
||||
} else {
|
||||
canvas.translate(0, getHeight());
|
||||
canvas.rotate(-90);
|
||||
canvas.translate( 0, getHeight() );
|
||||
canvas.rotate( -90 );
|
||||
}
|
||||
canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
|
||||
getLayout().draw(canvas);
|
||||
canvas.translate( getCompoundPaddingLeft(),
|
||||
getExtendedPaddingTop() );
|
||||
getLayout().draw( canvas );
|
||||
canvas.setDrawFilter(new DrawFilter() {
|
||||
|
||||
});
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A color scheme for the cloud depth.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class CloudDepthColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* The list of supports.
|
||||
*/
|
||||
private static List<ColorSupport> SUPPORT = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SUPPORT.add(new ColorSupport(0, 0x00FFFFFF));
|
||||
SUPPORT.add(new ColorSupport(1, 0xFF999999));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new color scheme to render the cloud depth.
|
||||
*/
|
||||
public CloudDepthColorScheme() {
|
||||
super(SUPPORT, new LinearInterpolation());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The color scheme for relative humidity.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class HumidityColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* The support vector with the temperature to color mapping.
|
||||
*/
|
||||
private static List<ColorSupport> SUPPORT = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SUPPORT.add(new ColorSupport(0, 0x0042BAD0));
|
||||
SUPPORT.add(new ColorSupport(100, 0xFF42BAD0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color scheme.
|
||||
*/
|
||||
public HumidityColorScheme() {
|
||||
super(SUPPORT, new LinearInterpolation());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
/**
|
||||
* A color scheme is responsible for mapping a data
|
||||
* value to an ARGB color.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public interface IColorScheme {
|
||||
|
||||
/**
|
||||
* Returns the color for the data value.
|
||||
*
|
||||
* @param value The data value.
|
||||
* @return The ARGB value with 8 bit resolution.
|
||||
*/
|
||||
int getColor(double value);
|
||||
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.IDataInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A color scheme for temperature given in degrees Kelvin.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class InterpolatedColorScheme implements IColorScheme {
|
||||
|
||||
/**
|
||||
* A support point that defines the color for a particular value.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public static class ColorSupport implements Comparable<ColorSupport> {
|
||||
|
||||
/**
|
||||
* The value.
|
||||
*/
|
||||
protected double value;
|
||||
/**
|
||||
* The red component.
|
||||
*/
|
||||
protected int red;
|
||||
/**
|
||||
* The green component (0 - 255).
|
||||
*/
|
||||
protected int green;
|
||||
/**
|
||||
* The blue component.
|
||||
*/
|
||||
protected int blue;
|
||||
/**
|
||||
* The alpha component.
|
||||
*/
|
||||
protected int alpha;
|
||||
|
||||
/**
|
||||
* Creates the support for the specified color.
|
||||
*
|
||||
* @param value The value that should exhibit the color.
|
||||
* @param argb The color value.
|
||||
*/
|
||||
public ColorSupport(double value, int argb) {
|
||||
this(value, (argb >> 24) & 0xff, (argb >> 16) & 0xff, (argb >> 8) & 0xff, argb & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new support at a particular value.
|
||||
*
|
||||
* @param value The data value that should exhibit the color.
|
||||
* @param a The alpha value.
|
||||
* @param r The red value.
|
||||
* @param g The green value.
|
||||
* @param b The blue value.
|
||||
*/
|
||||
public ColorSupport(double value, int a, int r, int g, int b) {
|
||||
this.value = value;
|
||||
this.alpha = a & 0xff;
|
||||
this.red = r & 0xff;
|
||||
this.green = g & 0xff;
|
||||
this.blue = b & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color as ARGB int.
|
||||
*
|
||||
* @return The color as ARGB int.
|
||||
*/
|
||||
public int getColor() {
|
||||
return alpha << 24 | red << 16 | green << 8 | blue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blue component (0-255).
|
||||
*
|
||||
* @return The blue component.
|
||||
*/
|
||||
public int getRed() {
|
||||
return red;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blue component (0-255).
|
||||
*
|
||||
* @return The blue component.
|
||||
*/
|
||||
public int getGreen() {
|
||||
return green;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blue component (0-255).
|
||||
*
|
||||
* @return The blue component.
|
||||
*/
|
||||
public int getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blue component (0-255).
|
||||
*
|
||||
* @return The blue component.
|
||||
*/
|
||||
public int getBlue() {
|
||||
return blue;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(ColorSupport o) {
|
||||
return Double.compare(value, o.value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The supporting points.
|
||||
*/
|
||||
protected List<ColorSupport> supports;
|
||||
/**
|
||||
* The interpolation strategy.
|
||||
*/
|
||||
protected IDataInterpolation interpolation;
|
||||
|
||||
/**
|
||||
* Creates an interpolated color scheme.
|
||||
*
|
||||
* @param supports The supports.
|
||||
* @param interpolation The interpolation strategy.
|
||||
*/
|
||||
public InterpolatedColorScheme(List<ColorSupport> supports, IDataInterpolation interpolation) {
|
||||
if (supports.isEmpty()) throw new IllegalArgumentException("At least one color support point must be specified.");
|
||||
this.supports = new ArrayList<>(supports);
|
||||
this.interpolation = interpolation;
|
||||
Collections.sort(supports);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getColor(double data) {
|
||||
// data is smaller than any support, return lowest support color
|
||||
if (data < supports.get(0).getValue()) return supports.get(0).getColor();
|
||||
for (int i = 1; i < supports.size(); i++) {
|
||||
if (supports.get(i).getValue() > data) {
|
||||
return getColor(supports.get(i - 1), supports.get(i), data);
|
||||
}
|
||||
}
|
||||
// data is larger than any support, return highest support color
|
||||
return supports.get(supports.size() - 1).getColor();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the interpolated color for the value.
|
||||
*
|
||||
* @param from The lower support.
|
||||
* @param to The higher support.
|
||||
* @param value The data value.
|
||||
* @return The interpolated color.
|
||||
*/
|
||||
private int getColor(ColorSupport from, ColorSupport to, double value) {
|
||||
double fraction = (value - from.getValue()) / (double)(to.getValue() - from.getValue());
|
||||
int alpha = getColor(from.getAlpha(), to.getAlpha(), fraction);
|
||||
int red = getColor(from.getRed(), to.getRed(), fraction);
|
||||
int green = getColor(from.getGreen(), to.getGreen(), fraction);
|
||||
int blue = getColor(from.getBlue(), to.getBlue(), fraction);
|
||||
return alpha << 24 | red << 16 | green << 8 | blue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the interpolated color value and ensures that it
|
||||
* lies within the target bounds.
|
||||
*
|
||||
* @param from The start color value.
|
||||
* @param to The to color value.
|
||||
* @param fraction The fraction between from and to.
|
||||
* @return The color value.
|
||||
*/
|
||||
private int getColor(int from, int to, double fraction) {
|
||||
double r = interpolation.interpolate(from, to, fraction);
|
||||
return Math.min(255, Math.max(0, (int)Math.round(r)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The color scheme for precipitation (rain, snow, etc.).
|
||||
* @author Marcus
|
||||
*
|
||||
*/
|
||||
public class PrecipitationColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* The support vector with the temperature to color mapping.
|
||||
*/
|
||||
private static List<ColorSupport> SUPPORT = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SUPPORT.add(new ColorSupport(0, 0x0000000));
|
||||
SUPPORT.add(new ColorSupport(0.1, 0x88008800));
|
||||
SUPPORT.add(new ColorSupport(1, 0xFF00FF00)); // Nieselregen (<1)
|
||||
SUPPORT.add(new ColorSupport(10, 0xFF00FFFF));
|
||||
SUPPORT.add(new ColorSupport(20, 0xFF0000FF)); // Starkregen (>20)
|
||||
SUPPORT.add(new ColorSupport(20, 0xFF880000));
|
||||
SUPPORT.add(new ColorSupport(35, 0xFFFF0000)); // Unwetter (>35)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color scheme.
|
||||
*/
|
||||
public PrecipitationColorScheme() {
|
||||
super(SUPPORT, new LinearInterpolation());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A color scheme that makes low pressure zones blue and high
|
||||
* pressure zones red.
|
||||
*
|
||||
* @author Marcus
|
||||
*
|
||||
*/
|
||||
public class PressureColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* Creates a pressure color scheme.
|
||||
*
|
||||
* @param avg The average value.
|
||||
* @param min The minimum value.
|
||||
* @param max The maximum value.
|
||||
*/
|
||||
public PressureColorScheme(double avg, double min, double max) {
|
||||
super(createSupport(avg, min, max), new LinearInterpolation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the support for the color scheme based on the average,
|
||||
* minimum and maximum values.
|
||||
*
|
||||
* @param avg The average.
|
||||
* @param min The minimum.
|
||||
* @param max The maximum.
|
||||
* @return The support for the scheme.
|
||||
*/
|
||||
private static List<ColorSupport> createSupport(double avg, double min, double max) {
|
||||
List<ColorSupport> result = new ArrayList<>();
|
||||
result.add(new ColorSupport(min, 255, 0, 0, 0));
|
||||
result.add(new ColorSupport(avg, 255, 0, 0, 255));
|
||||
result.add(new ColorSupport(max, 255, 255, 0, 255));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.IDataInterpolation;
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
import com.mowesta.android.app.view.interpolation.StepInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A color scheme that is extracted from the climate charts of DWD.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class ScientificTemperatureColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* The support vector with the temperature to color mapping.
|
||||
*/
|
||||
private static List<ColorSupport> SUPPORT = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SUPPORT.add(new ColorSupport(-35, 0xFF0000FB));
|
||||
SUPPORT.add(new ColorSupport(-30, 0xFF2E46FF));
|
||||
SUPPORT.add(new ColorSupport(-25, 0xFF3974FF));
|
||||
SUPPORT.add(new ColorSupport(-20, 0xFF39A9FF));
|
||||
SUPPORT.add(new ColorSupport(-15, 0xFF29DBFF));
|
||||
SUPPORT.add(new ColorSupport(-10, 0xFF30FFEF));
|
||||
SUPPORT.add(new ColorSupport(-5, 0xFF88FFBE));
|
||||
SUPPORT.add(new ColorSupport(0, 0xFFB6FE8E));
|
||||
SUPPORT.add(new ColorSupport(0, 0xFFFFFF00));
|
||||
SUPPORT.add(new ColorSupport(5, 0xFFDAFF61));
|
||||
SUPPORT.add(new ColorSupport(10, 0xFFF8FF26));
|
||||
SUPPORT.add(new ColorSupport(15, 0xFFFEE100));
|
||||
SUPPORT.add(new ColorSupport(20, 0xFFFFB200));
|
||||
SUPPORT.add(new ColorSupport(25, 0xFFFE8500));
|
||||
SUPPORT.add(new ColorSupport(30, 0xFFFF5100));
|
||||
SUPPORT.add(new ColorSupport(35, 0xFFB30000));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color scheme with linear interpolation.
|
||||
*/
|
||||
public ScientificTemperatureColorScheme() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color scheme with linear or step-wise interpolation.
|
||||
*
|
||||
* @param linearInterpolation If set to true, enables linear interpolation.
|
||||
*/
|
||||
public ScientificTemperatureColorScheme(boolean linearInterpolation) {
|
||||
super(SUPPORT, linearInterpolation?new LinearInterpolation():new StepInterpolation(1f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a colors scheme with the specified interpolation.
|
||||
*
|
||||
* @param interpolation The interpolation function.
|
||||
*/
|
||||
public ScientificTemperatureColorScheme(IDataInterpolation interpolation) {
|
||||
super(SUPPORT, interpolation);
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A color scheme for the cloud coverage provided as a value between 0 and 1.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class WhiteCloudColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* The support vector with the temperature to color mapping.
|
||||
*/
|
||||
private static List<ColorSupport> SUPPORT = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SUPPORT.add(new ColorSupport(0, 0x00FFFFFF));
|
||||
SUPPORT.add(new ColorSupport(1, 0xFFFFFFFF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color scheme with linear interpolation.
|
||||
*/
|
||||
public WhiteCloudColorScheme() {
|
||||
super(SUPPORT, new LinearInterpolation());
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.mowesta.android.app.view.interpolation;
|
||||
|
||||
/**
|
||||
* An interface to interpolate data.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public interface IDataInterpolation {
|
||||
|
||||
/**
|
||||
* Computes an interpolated value between x and y that
|
||||
* resides at the specified fraction.
|
||||
*
|
||||
* @param x The x value.
|
||||
* @param y The y value.
|
||||
* @param fraction The fraction (between 0 = x and 1 = y).
|
||||
* @return The interpolated value.
|
||||
*/
|
||||
double interpolate(double x, double y, double fraction);
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.mowesta.android.app.view.interpolation;
|
||||
|
||||
/**
|
||||
* A simple linear interpolation.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class LinearInterpolation implements IDataInterpolation {
|
||||
|
||||
@Override
|
||||
public double interpolate(double x, double y, double fraction) {
|
||||
return x + (y - x) * fraction;
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.mowesta.android.app.view.interpolation;
|
||||
|
||||
/**
|
||||
* An interpolation that does not compute intermediate values but
|
||||
* instead bases its decision on which value to return on the fraction,
|
||||
* creating a step function.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class StepInterpolation implements IDataInterpolation {
|
||||
|
||||
/**
|
||||
* The default threshold value that results in financial rounding.
|
||||
*/
|
||||
public static final double DEFAULT_THRESHOLD = 0.5;
|
||||
|
||||
/**
|
||||
* The threshold at which to switch.
|
||||
*/
|
||||
private double threshold;
|
||||
|
||||
/**
|
||||
* Creates an interpolation function with the default threshold.
|
||||
*/
|
||||
public StepInterpolation() {
|
||||
this(DEFAULT_THRESHOLD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new step interpolation with the specified
|
||||
* threshold.
|
||||
*
|
||||
* @param threshold The threshold that defines which
|
||||
* value to return.
|
||||
*/
|
||||
public StepInterpolation(double threshold) {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double interpolate(double x, double y, double fraction) {
|
||||
if (fraction < threshold) return x;
|
||||
else return y;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 7.0 KiB |
@@ -2,10 +2,10 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<gradient
|
||||
android:gradientRadius="150%p"
|
||||
android:centerX="0.8"
|
||||
android:centerY="1"
|
||||
android:centerX="0.2"
|
||||
android:centerY="0.5"
|
||||
android:endColor="#00695C"
|
||||
android:startColor="#CBCDD1"
|
||||
android:type="radial" />
|
||||
android:startColor="#CBCDD1"
|
||||
android:type="radial" />
|
||||
|
||||
</shape>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<gradient
|
||||
android:centerX="0.5"
|
||||
android:angle="270"
|
||||
android:endColor="#A0ffffff"
|
||||
android:centerColor="#40ffffff"
|
||||
android:startColor="#00ffffff"
|
||||
android:type="linear" />
|
||||
|
||||
</shape>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<gradient
|
||||
android:angle="0"
|
||||
android:endColor="#f8e9cf"
|
||||
android:centerColor="#ffffff"
|
||||
android:startColor="#f8e9cf"
|
||||
android:type="linear" />
|
||||
|
||||
</shape>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@android:color/white"/>
|
||||
<corners
|
||||
android:bottomRightRadius="4dp"
|
||||
android:bottomLeftRadius="4dp"
|
||||
android:topLeftRadius="4dp"
|
||||
android:topRightRadius="4dp"/>
|
||||
</shape>
|
||||
@@ -0,0 +1,18 @@
|
||||
<vector android:height="24dp" android:viewportHeight="1576.68"
|
||||
android:viewportWidth="1576.68" android:width="24dp"
|
||||
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:pathData="M788.34,788.34m-784.54,0a784.54,784.54 0,1 1,1569.08 0a784.54,784.54 0,1 1,-1569.08 0">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:startX="1577"
|
||||
android:startY="0"
|
||||
android:endX="0"
|
||||
android:endY="1577"
|
||||
android:startColor="#aaaaaaaa"
|
||||
android:endColor="#00ffffff"
|
||||
android:type="linear">
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path android:fillColor="#eeFFFFFF" android:pathData="M932.1,185.17c135.76,82 339.41,251.63 439.96,406.9 100.54,155.27 97.98,296.16 78.45,397.05 -19.53,100.88 -56.04,161.74 -83.9,133.57 -27.86,-28.18 -47.07,-145.4 -112.07,-279.53 -65,-134.13 -175.78,-285.17 -282.41,-409.44 -106.63,-124.27 -209.09,-221.77 -226.38,-273.33 -17.3,-51.57 50.59,-57.2 186.36,24.8z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,8 @@
|
||||
<vector android:height="24dp"
|
||||
android:viewportHeight="30"
|
||||
android:viewportWidth="30"
|
||||
android:width="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M7.69,13.2c0,-0.99 0.19,-1.94 0.58,-2.85c0.39,-0.91 0.91,-1.68 1.57,-2.33s1.44,-1.17 2.34,-1.56c0.9,-0.39 1.85,-0.58 2.84,-0.58c0.99,0 1.94,0.19 2.85,0.58c0.9,0.39 1.68,0.91 2.33,1.56c0.65,0.65 1.17,1.43 1.56,2.33s0.58,1.85 0.58,2.85c0,1.62 -0.48,3.06 -1.44,4.34c-0.96,1.27 -2.2,2.14 -3.71,2.61v3.29h-4.24v-3.25c-1.54,-0.45 -2.81,-1.32 -3.79,-2.61S7.69,14.83 7.69,13.2zM9.3,13.2c0,1.55 0.56,2.88 1.69,3.99c1.11,1.12 2.45,1.68 4.02,1.68c1.03,0 1.99,-0.25 2.86,-0.76c0.88,-0.51 1.57,-1.2 2.09,-2.07c0.51,-0.87 0.77,-1.82 0.77,-2.85c0,-0.77 -0.15,-1.5 -0.45,-2.21s-0.71,-1.31 -1.22,-1.82c-0.51,-0.51 -1.12,-0.92 -1.83,-1.22c-0.71,-0.3 -1.44,-0.45 -2.21,-0.45c-0.77,0 -1.5,0.15 -2.21,0.45s-1.31,0.71 -1.82,1.22c-0.51,0.51 -0.92,1.12 -1.22,1.82C9.45,11.7 9.3,12.43 9.3,13.2zM9.88,13.56v-0.72h2.17v0.72H9.88zM10.97,10.02l0.52,-0.52l1.52,1.52l-0.52,0.53L10.97,10.02zM13.5,14.95c0,-0.42 0.15,-0.78 0.44,-1.09c0.29,-0.31 0.65,-0.47 1.06,-0.48l2.73,-4.49l0.66,0.35l-2.02,4.83c0.18,0.25 0.26,0.54 0.26,0.88c0,0.44 -0.15,0.81 -0.46,1.11c-0.31,0.3 -0.68,0.45 -1.12,0.45c-0.43,0 -0.8,-0.15 -1.1,-0.45C13.65,15.76 13.5,15.39 13.5,14.95zM14.81,10.28V8.12h0.69v2.17H14.81zM17.75,13.55v-0.74h2.17v0.74H17.75z"/>
|
||||
</vector>
|
||||
@@ -1,15 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="56.7532dp"
|
||||
android:height="56.7532dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="1755.38"
|
||||
android:viewportHeight="1755.38">
|
||||
<path
|
||||
android:pathData="M181.92,586.9c0,-58.39 20.51,-108.21 61.54,-149.01 41.25,-40.8 90.84,-61.32 148.78,-61.32 57.94,0 107.53,20.51 148.78,61.54 41.03,41.25 61.54,90.84 61.54,148.78 0,57.93 -20.52,107.53 -61.54,148.78 -41.25,41.03 -90.84,61.54 -148.78,61.54 -57.94,0 -107.53,-20.51 -148.78,-61.54 -41.03,-41.25 -61.54,-90.85 -61.54,-148.78zM291.48,586.9c0,27.73 9.92,51.4 29.53,71.23 19.84,19.61 43.51,29.53 71.24,29.53 27.73,0 51.4,-9.92 71.24,-29.53 19.61,-19.84 29.53,-43.51 29.53,-71.23 0,-27.73 -9.92,-51.4 -29.53,-71.24 -19.84,-19.61 -43.51,-29.53 -71.24,-29.53 -27.73,0 -51.4,9.92 -71.24,29.53 -19.61,19.84 -29.53,43.51 -29.53,71.24z"
|
||||
android:fillColor="#000000"
|
||||
android:fillType="nonZero"/>
|
||||
<path
|
||||
android:pathData="M1384.11,1005.51l189.35,58.16c-29.08,106.63 -77.54,185.75 -145.17,237.6 -67.63,51.62 -153.29,77.54 -257.21,77.54 -128.72,0 -234.44,-43.95 -317.4,-131.87 -82.73,-87.92 -124.21,-208.07 -124.21,-360.68 0,-161.18 41.7,-286.51 124.88,-375.78 83.18,-89.27 192.74,-133.9 328.44,-133.9 118.57,0 214.83,35.16 288.77,105.27 44.18,41.48 77.09,100.99 99.19,178.76l-193.42,45.99c-11.5,-50.04 -35.39,-89.72 -71.68,-118.8 -36.52,-29.08 -80.7,-43.51 -132.55,-43.51 -71.91,0 -130.3,25.7 -174.93,77.32 -44.86,51.4 -67.18,134.81 -67.18,250.22 0,122.18 22.09,209.42 66.05,261.27 44.18,52.07 101.44,78 172,78 52.07,0 96.93,-16.45 134.35,-49.59 37.42,-33.14 64.47,-84.98 80.7,-155.99z"
|
||||
android:fillColor="#000000"
|
||||
android:fillType="nonZero"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:viewportHeight="30"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="30" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M4.61,16.88c0,-1.15 0.36,-2.17 1.08,-3.07c0.72,-0.9 1.63,-1.48 2.74,-1.73c0.31,-1.37 1.02,-2.49 2.11,-3.37s2.35,-1.32 3.76,-1.32c1.38,0 2.61,0.43 3.69,1.28s1.78,1.95 2.1,3.29h0.33c0.9,0 1.73,0.22 2.49,0.65s1.37,1.03 1.81,1.79c0.44,0.76 0.67,1.58 0.67,2.48c0,0.88 -0.21,1.7 -0.63,2.45s-1,1.35 -1.73,1.8c-0.73,0.45 -1.54,0.69 -2.41,0.72H9.41c-1.34,-0.06 -2.47,-0.57 -3.4,-1.53C5.08,19.37 4.61,18.22 4.61,16.88zM6.32,16.88c0,0.87 0.3,1.62 0.9,2.26s1.33,0.98 2.19,1.03h11.19c0.86,-0.04 1.59,-0.39 2.19,-1.03c0.61,-0.64 0.91,-1.4 0.91,-2.26c0,-0.88 -0.33,-1.63 -0.98,-2.27c-0.65,-0.64 -1.42,-0.96 -2.32,-0.96H18.8c-0.11,0 -0.17,-0.06 -0.17,-0.18l-0.07,-0.57c-0.11,-1.08 -0.58,-1.99 -1.4,-2.72c-0.82,-0.73 -1.77,-1.1 -2.86,-1.1c-1.09,0 -2.05,0.37 -2.85,1.1c-0.81,0.73 -1.27,1.64 -1.37,2.72l-0.08,0.57c0,0.12 -0.07,0.18 -0.2,0.18H9.27c-0.84,0.1 -1.54,0.46 -2.1,1.07S6.32,16.05 6.32,16.88z"/>
|
||||
</vector>
|
||||
@@ -1,15 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="56.7532dp"
|
||||
android:height="56.7532dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="27985.17"
|
||||
android:viewportHeight="27985.17">
|
||||
<path
|
||||
android:pathData="M4043.1,9485.9c0,-930.8 327,-1725.1 981.1,-2375.5 657.7,-650.5 1448.3,-977.5 2371.9,-977.5 923.6,0 1714.3,327 2371.9,981.1 654,657.7 981.1,1448.3 981.1,2371.9 0,923.6 -327.1,1714.2 -981.1,2371.9 -657.7,654 -1448.3,981.1 -2371.9,981.1 -923.6,0 -1714.3,-327 -2371.9,-981.1 -654.1,-657.7 -981.1,-1448.3 -981.1,-2371.9zM5789.7,9485.9c0,442 158.1,819.4 470.8,1135.6 316.3,312.7 693.7,470.8 1135.7,470.8 442,0 819.4,-158.1 1135.7,-470.8 312.6,-316.2 470.8,-693.6 470.8,-1135.6 0,-442.1 -158.1,-819.4 -470.8,-1135.7 -316.3,-312.7 -693.7,-470.8 -1135.7,-470.8 -442,0 -819.4,158.1 -1135.7,470.8 -312.6,316.3 -470.8,693.6 -470.8,1135.7z"
|
||||
android:fillColor="#000000"
|
||||
android:fillType="nonZero"/>
|
||||
<path
|
||||
android:pathData="M13333.1,21852.3l0,-15439.1l10609,0l0,2609.1l-7482.3,0l0,3665.7l6468.9,0l0,2609.2l-6468.9,0l0,6555.1z"
|
||||
android:fillColor="#000000"
|
||||
android:fillType="nonZero"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:viewportHeight="30"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="30" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M7.56,17.19c0,-0.88 0.24,-1.89 0.72,-3.03s1.1,-2.25 1.86,-3.31c1.56,-2.06 2.92,-3.62 4.06,-4.67l0.75,-0.72c0.25,0.26 0.53,0.5 0.83,0.72c0.41,0.42 1.04,1.11 1.88,2.09s1.57,1.85 2.17,2.65c0.71,1.01 1.32,2.1 1.81,3.25s0.74,2.16 0.74,3.03c0,1 -0.19,1.95 -0.58,2.86c-0.39,0.91 -0.91,1.7 -1.57,2.36c-0.66,0.66 -1.45,1.19 -2.37,1.58c-0.92,0.39 -1.89,0.59 -2.91,0.59c-1,0 -1.95,-0.19 -2.86,-0.57c-0.91,-0.38 -1.7,-0.89 -2.36,-1.55c-0.66,-0.65 -1.19,-1.44 -1.58,-2.35S7.56,18.23 7.56,17.19zM9.82,14.26c0,0.83 0.17,1.49 0.52,1.99c0.35,0.49 0.88,0.74 1.59,0.74c0.72,0 1.25,-0.25 1.61,-0.74c0.35,-0.49 0.53,-1.15 0.54,-1.99c-0.01,-0.84 -0.19,-1.5 -0.54,-2c-0.35,-0.49 -0.89,-0.74 -1.61,-0.74c-0.71,0 -1.24,0.25 -1.59,0.74C9.99,12.76 9.82,13.42 9.82,14.26zM11.39,14.26c0,-0.15 0,-0.27 0,-0.35s0.01,-0.19 0.02,-0.33c0.01,-0.14 0.02,-0.25 0.05,-0.32s0.05,-0.16 0.09,-0.24c0.04,-0.08 0.09,-0.15 0.15,-0.18c0.07,-0.04 0.14,-0.06 0.23,-0.06c0.14,0 0.25,0.04 0.33,0.12s0.14,0.21 0.17,0.38c0.03,0.18 0.05,0.32 0.06,0.45s0.01,0.3 0.01,0.52c0,0.23 0,0.4 -0.01,0.52c-0.01,0.12 -0.03,0.27 -0.06,0.45c-0.03,0.17 -0.09,0.3 -0.17,0.38s-0.19,0.12 -0.33,0.12c-0.09,0 -0.16,-0.02 -0.23,-0.06c-0.07,-0.04 -0.12,-0.1 -0.15,-0.18c-0.04,-0.08 -0.07,-0.17 -0.09,-0.24c-0.02,-0.08 -0.04,-0.19 -0.05,-0.32c-0.01,-0.14 -0.02,-0.25 -0.02,-0.32S11.39,14.41 11.39,14.26zM11.98,22.01h1.32l4.99,-10.74h-1.35L11.98,22.01zM16.28,19.02c0.01,0.84 0.2,1.5 0.55,2c0.35,0.49 0.89,0.74 1.6,0.74c0.72,0 1.25,-0.25 1.6,-0.74c0.35,-0.49 0.52,-1.16 0.53,-2c-0.01,-0.84 -0.18,-1.5 -0.53,-1.99c-0.35,-0.49 -0.88,-0.74 -1.6,-0.74c-0.71,0 -1.25,0.25 -1.6,0.74C16.47,17.52 16.29,18.18 16.28,19.02zM17.85,19.02c0,-0.23 0,-0.4 0.01,-0.52c0.01,-0.12 0.03,-0.27 0.06,-0.45s0.09,-0.3 0.17,-0.38s0.19,-0.12 0.33,-0.12c0.09,0 0.17,0.02 0.24,0.06c0.07,0.04 0.12,0.1 0.16,0.19c0.04,0.09 0.07,0.17 0.1,0.24s0.04,0.18 0.05,0.32l0.01,0.32l0,0.34c0,0.16 0,0.28 0,0.35l-0.01,0.32l-0.05,0.32l-0.1,0.24l-0.16,0.19l-0.24,0.06c-0.14,0 -0.25,-0.04 -0.33,-0.12s-0.14,-0.21 -0.17,-0.38c-0.03,-0.18 -0.05,-0.33 -0.06,-0.45S17.85,19.25 17.85,19.02z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:fromDegrees="90"
|
||||
android:toDegrees="90"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:drawable="@drawable/ic_longitude_normal_24">
|
||||
</rotate>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M7,11v2h10v-2L7,11zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
|
||||
</vector>
|
||||
+2
-1
@@ -2,7 +2,8 @@
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
android:viewportHeight="24.0"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M15,9L9,9v6h6L15,9zM13,13h-2v-2h2v2zM21,11L21,9h-2L19,7c0,-1.1 -0.9,-2 -2,-2h-2L15,3h-2v2h-2L11,3L9,3v2L7,5c-1.1,0 -2,0.9 -2,2v2L3,9v2h2v2L3,13v2h2v2c0,1.1 0.9,2 2,2h2v2h2v-2h2v2h2v-2h2c1.1,0 2,-0.9 2,-2v-2h2v-2h-2v-2h2zM17,17L7,17L7,7h10v10z"/>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:viewportHeight="30"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="30" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M11.01,12.23c0,-0.26 0.13,-0.59 0.38,-1.01c0.25,-0.42 0.5,-0.77 0.73,-1.04c0.06,-0.07 0.14,-0.17 0.23,-0.28s0.15,-0.17 0.16,-0.18l0.37,0.43c0.28,0.31 0.53,0.66 0.76,1.07c0.23,0.41 0.35,0.74 0.35,1.01c0,0.41 -0.14,0.77 -0.43,1.06c-0.28,0.29 -0.63,0.44 -1.05,0.44c-0.41,0 -0.77,-0.15 -1.06,-0.44C11.16,12.99 11.01,12.64 11.01,12.23zM14.13,16.38c0,-0.29 0.08,-0.62 0.24,-1.01c0.16,-0.38 0.36,-0.74 0.6,-1.06c0.46,-0.61 0.89,-1.12 1.31,-1.53c0.04,-0.03 0.13,-0.11 0.26,-0.24l0.25,0.24c0.39,0.37 0.83,0.88 1.32,1.52c0.26,0.34 0.46,0.7 0.62,1.08s0.24,0.71 0.24,1c0,0.69 -0.23,1.26 -0.7,1.73c-0.47,0.47 -1.05,0.7 -1.73,0.7c-0.68,0 -1.25,-0.24 -1.72,-0.71S14.13,17.05 14.13,16.38zM15.65,9.48c0,-0.43 0.33,-1 1,-1.7l0.25,0.28c0.19,0.22 0.36,0.46 0.51,0.74c0.15,0.27 0.23,0.5 0.23,0.68c0,0.28 -0.1,0.5 -0.29,0.69c-0.19,0.18 -0.42,0.28 -0.7,0.28c-0.29,0 -0.53,-0.09 -0.72,-0.28C15.75,9.98 15.65,9.75 15.65,9.48z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM17,13L7,13v-2h10v2z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M7,11v2h10v-2L7,11zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:viewportHeight="30"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="30" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M9.91,19.56c0,-0.85 0.2,-1.64 0.59,-2.38s0.94,-1.35 1.65,-1.84V5.42c0,-0.8 0.27,-1.48 0.82,-2.03S14.2,2.55 15,2.55c0.81,0 1.49,0.28 2.04,0.83c0.55,0.56 0.83,1.23 0.83,2.03v9.92c0.71,0.49 1.25,1.11 1.64,1.84s0.58,1.53 0.58,2.38c0,0.92 -0.23,1.78 -0.68,2.56s-1.07,1.4 -1.85,1.85s-1.63,0.68 -2.56,0.68c-0.92,0 -1.77,-0.23 -2.55,-0.68s-1.4,-1.07 -1.86,-1.85S9.91,20.48 9.91,19.56zM11.67,19.56c0,0.93 0.33,1.73 0.98,2.39c0.65,0.66 1.44,0.99 2.36,0.99c0.93,0 1.73,-0.33 2.4,-1s1.01,-1.46 1.01,-2.37c0,-0.62 -0.16,-1.2 -0.48,-1.73c-0.32,-0.53 -0.76,-0.94 -1.32,-1.23l-0.28,-0.14c-0.1,-0.04 -0.15,-0.14 -0.15,-0.29V5.42c0,-0.32 -0.11,-0.59 -0.34,-0.81C15.62,4.4 15.34,4.29 15,4.29c-0.32,0 -0.6,0.11 -0.83,0.32c-0.23,0.21 -0.34,0.48 -0.34,0.81v10.74c0,0.15 -0.05,0.25 -0.14,0.29l-0.27,0.14c-0.55,0.29 -0.98,0.7 -1.29,1.23C11.82,18.35 11.67,18.92 11.67,19.56zM12.45,19.56c0,0.71 0.24,1.32 0.73,1.82s1.07,0.75 1.76,0.75s1.28,-0.25 1.79,-0.75c0.51,-0.5 0.76,-1.11 0.76,-1.81c0,-0.63 -0.22,-1.19 -0.65,-1.67c-0.43,-0.48 -0.96,-0.77 -1.58,-0.85V9.69c0,-0.06 -0.03,-0.13 -0.1,-0.19c-0.07,-0.07 -0.14,-0.1 -0.22,-0.1c-0.09,0 -0.16,0.03 -0.21,0.08c-0.05,0.06 -0.08,0.12 -0.08,0.21v7.34c-0.61,0.09 -1.13,0.37 -1.56,0.85C12.66,18.37 12.45,18.92 12.45,19.56z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="@color/primary">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9,11.24V7.5C9,6.12 10.12,5 11.5,5S14,6.12 14,7.5v3.74c1.21,-0.81 2,-2.18 2,-3.74C16,5.01 13.99,3 11.5,3S7,5.01 7,7.5C7,9.06 7.79,10.43 9,11.24zM18.84,15.87l-4.54,-2.26c-0.17,-0.07 -0.35,-0.11 -0.54,-0.11H13v-6C13,6.67 12.33,6 11.5,6S10,6.67 10,7.5v10.74c-3.6,-0.76 -3.54,-0.75 -3.67,-0.75c-0.31,0 -0.59,0.13 -0.79,0.33l-0.79,0.8l4.94,4.94C9.96,23.83 10.34,24 10.75,24h6.79c0.75,0 1.33,-0.55 1.44,-1.28l0.75,-5.27c0.01,-0.07 0.02,-0.14 0.02,-0.2C19.75,16.63 19.37,16.09 18.84,15.87z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:viewportHeight="30"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="30" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M3.1,16.97c0,0.24 0.09,0.45 0.28,0.62c0.16,0.19 0.37,0.28 0.63,0.28H18.7c0.29,0 0.53,0.1 0.73,0.3c0.2,0.2 0.3,0.45 0.3,0.74c0,0.29 -0.1,0.53 -0.3,0.72c-0.2,0.19 -0.44,0.29 -0.74,0.29c-0.29,0 -0.54,-0.1 -0.73,-0.29c-0.16,-0.18 -0.36,-0.26 -0.6,-0.26c-0.25,0 -0.46,0.09 -0.64,0.26s-0.27,0.38 -0.27,0.61c0,0.25 0.09,0.46 0.28,0.63c0.56,0.55 1.22,0.83 1.96,0.83c0.78,0 1.45,-0.27 2.01,-0.81c0.56,-0.54 0.83,-1.19 0.83,-1.97s-0.28,-1.44 -0.84,-2c-0.56,-0.56 -1.23,-0.84 -2,-0.84H4.01c-0.25,0 -0.46,0.09 -0.64,0.26C3.19,16.51 3.1,16.72 3.1,16.97zM3.1,13.69c0,0.23 0.09,0.43 0.28,0.61c0.17,0.18 0.38,0.26 0.63,0.26h20.04c0.78,0 1.45,-0.27 2.01,-0.82c0.56,-0.54 0.84,-1.2 0.84,-1.97c0,-0.77 -0.28,-1.44 -0.84,-1.99s-1.23,-0.83 -2.01,-0.83c-0.77,0 -1.42,0.27 -1.95,0.8c-0.18,0.16 -0.27,0.38 -0.27,0.67c0,0.26 0.09,0.47 0.26,0.63c0.17,0.16 0.38,0.24 0.63,0.24c0.24,0 0.45,-0.08 0.63,-0.24c0.19,-0.21 0.42,-0.31 0.7,-0.31c0.29,0 0.53,0.1 0.73,0.3c0.2,0.2 0.3,0.44 0.3,0.73c0,0.29 -0.1,0.53 -0.3,0.72c-0.2,0.19 -0.44,0.29 -0.73,0.29H4.01c-0.25,0 -0.46,0.09 -0.64,0.26C3.19,13.23 3.1,13.44 3.1,13.69z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@android:id/background">
|
||||
<color android:color="#33363636" />
|
||||
</item>
|
||||
<item android:id="@android:id/progress">
|
||||
<clip
|
||||
android:clipOrientation="vertical"
|
||||
android:gravity="bottom">
|
||||
<shape>
|
||||
<gradient
|
||||
android:startColor="#f9a825"
|
||||
android:centerColor="#f9a825"
|
||||
android:endColor="#f9a825"
|
||||
android:angle="90" />
|
||||
</shape>
|
||||
</clip>
|
||||
</item>
|
||||
</layer-list>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user