Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
e72afae503 | ||
|
|
a83314e997 | ||
|
|
8179510ea8 |
@@ -14,12 +14,12 @@ ext {
|
||||
versionAndroidXCard = '1.0.0'
|
||||
versionAndroidXCoordinator = '1.1.0'
|
||||
versionAndroidXConstraint = '1.1.3'
|
||||
versionAndroidXNavigation = '2.3.0-beta01'
|
||||
versionAndroidXNavigation = '2.3.0'
|
||||
versionAndroidXLifecycle = '2.2.0'
|
||||
versionAndroidXSecurity = '1.0.0-rc02'
|
||||
versionAndroidXSecurity = '1.1.0-alpha01'
|
||||
versionAndroidXViewpager = '1.0.0'
|
||||
versionGoogleMaterial = '1.1.0'
|
||||
versionAndroidXSwipeRefresh = '1.0.0'
|
||||
versionAndroidXSwipeRefresh = '1.1.0'
|
||||
versionExoPlayer = '2.11.5'
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ android {
|
||||
applicationId "com.mowesta.android.app"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 29
|
||||
versionCode 6
|
||||
versionCode 7
|
||||
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,27 +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.navigation.NavDeepLinkBuilder;
|
||||
import androidx.navigation.NavDirections;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
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;
|
||||
@@ -97,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);
|
||||
@@ -111,7 +103,7 @@ 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();
|
||||
}
|
||||
@@ -170,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,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);
|
||||
}
|
||||
@@ -221,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.
|
||||
*/
|
||||
@@ -77,6 +88,16 @@ public class MowestaSettings extends SdkSettings {
|
||||
*/
|
||||
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.
|
||||
*
|
||||
@@ -171,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.
|
||||
*
|
||||
@@ -334,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,287 @@
|
||||
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.NetworkInfo;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
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)) {
|
||||
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);
|
||||
}
|
||||
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<WifiConfiguration> configurations = manager.getConfiguredNetworks();
|
||||
for (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 WifiConfiguration findConfiguration() throws SecurityException {
|
||||
String ssid = getSsid();
|
||||
List<WifiConfiguration> configurations = manager.getConfiguredNetworks();
|
||||
for (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 WifiConfiguration createConfiguration() {
|
||||
WifiConfiguration result = new WifiConfiguration();
|
||||
result.SSID = getSsid();
|
||||
result.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
|
||||
result.allowedProtocols.set(WifiConfiguration.Protocol.RSN); // For WPA2
|
||||
result.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
|
||||
result.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
|
||||
result.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
|
||||
result.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
|
||||
result.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
|
||||
result.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
|
||||
result.preSharedKey = String.format("\"%s\"", ArduinoConfig.ARDUINO_PWD);
|
||||
result.status = 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -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,27 +61,24 @@ 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);
|
||||
case R.id.action_unit_system:
|
||||
UnitSystemDialogFragment system = new UnitSystemDialogFragment();
|
||||
system.show(getChildFragmentManager(), "system");
|
||||
return true;
|
||||
case R.id.unit_celsius:
|
||||
settings.setTemperatureCelsius(false);
|
||||
case R.id.action_temperature_unit:
|
||||
TemperatureUnitDialogFragment unit = new TemperatureUnitDialogFragment();
|
||||
unit.show(getChildFragmentManager(), "unit");
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
||||
@@ -12,6 +12,7 @@ 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;
|
||||
@@ -24,6 +25,7 @@ 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;
|
||||
@@ -212,6 +214,17 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -83,6 +83,8 @@ public class CityInfoFragment extends CityFragment.ChildFragment {
|
||||
model.getBoundary().observe(getViewLifecycleOwner(), (b) -> updateMap.run());
|
||||
binding.setModel(model);
|
||||
binding.setCondition(condition);
|
||||
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
|
||||
|
||||
@@ -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
|
||||
@@ -109,7 +110,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));
|
||||
}
|
||||
}
|
||||
}
|
||||
+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();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ 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;
|
||||
@@ -78,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)-> {
|
||||
@@ -90,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
|
||||
@@ -99,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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -420,7 +420,7 @@ public class VideoFragment extends AbstractNetworkFragment {
|
||||
*/
|
||||
public ExoPlayerViewModel(Application application) {
|
||||
super(application);
|
||||
MowestaSettings s = new MowestaSettings(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));
|
||||
|
||||
@@ -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())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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());
|
||||
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.
|
||||
@@ -336,7 +318,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 +355,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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,31 +1,158 @@
|
||||
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 java.text.Normalizer;
|
||||
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
|
||||
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.
|
||||
*
|
||||
@@ -35,9 +162,52 @@ public class SetupViewModel extends AndroidViewModel {
|
||||
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.
|
||||
*
|
||||
@@ -52,10 +222,23 @@ public class SetupViewModel extends AndroidViewModel {
|
||||
*
|
||||
* @return The live data with the status for the network name.
|
||||
*/
|
||||
public MutableLiveData<FormStatus> getNetworkNameStatus() {
|
||||
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.
|
||||
*
|
||||
@@ -70,10 +253,25 @@ public class SetupViewModel extends AndroidViewModel {
|
||||
*
|
||||
* @return The live data with the status for the network password.
|
||||
*/
|
||||
public MutableLiveData<FormStatus> getNetworkPasswordStatus() {
|
||||
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.
|
||||
*
|
||||
@@ -88,10 +286,22 @@ public class SetupViewModel extends AndroidViewModel {
|
||||
*
|
||||
* @return The live data with the status for the device name.
|
||||
*/
|
||||
public MutableLiveData<FormStatus> getDeviceNameStatus() {
|
||||
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.
|
||||
*
|
||||
@@ -106,10 +316,58 @@ public class SetupViewModel extends AndroidViewModel {
|
||||
*
|
||||
* @return The live data with the longitude status.
|
||||
*/
|
||||
public MutableLiveData<FormStatus> getLongitudeStatus() {
|
||||
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.
|
||||
*
|
||||
@@ -125,10 +383,33 @@ public class SetupViewModel extends AndroidViewModel {
|
||||
* @return The live data with the latitude status.
|
||||
*/
|
||||
|
||||
public MutableLiveData<FormStatus> getLatitudeStatus() {
|
||||
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.
|
||||
*
|
||||
@@ -165,4 +446,103 @@ public class SetupViewModel extends AndroidViewModel {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, round(celsisus));
|
||||
} else {
|
||||
int fahrenheit = round(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, round(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();
|
||||
if (system == MowestaSettings.UnitSystem.STANDARD) {
|
||||
return context.getString(R.string.format_wind_speed_si, round(mpsToKmph(mps)));
|
||||
} else {
|
||||
double mph = mpsToMph(mps);
|
||||
if (system == MowestaSettings.UnitSystem.IMPERIAL) {
|
||||
return context.getString(R.string.format_wind_speed_im, round(mph));
|
||||
} 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();
|
||||
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();
|
||||
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,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>
|
||||
@@ -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,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="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>
|
||||
@@ -29,6 +29,7 @@
|
||||
android:layout_width="48dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_height="wrap_content"
|
||||
android:tint="@color/fg_accent"
|
||||
app:srcCompat="@drawable/ic_view_headline_normal_24"/>
|
||||
<TextView
|
||||
android:layout_weight="1"
|
||||
@@ -37,6 +38,7 @@
|
||||
android:layout_gravity="center_vertical"
|
||||
style="@style/TextAppearance.MaterialComponents.Subtitle1"
|
||||
android:text="@string/action_customize"
|
||||
android:textColor="@color/fg_accent"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="end"
|
||||
android:layout_width="0dp"
|
||||
@@ -44,6 +46,7 @@
|
||||
<ImageButton
|
||||
android:contentDescription="@string/button_close"
|
||||
android:layout_width="48dp"
|
||||
android:tint="@color/fg_accent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="@{ () -> closeListener.run() }"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
|
||||
@@ -52,15 +55,66 @@
|
||||
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_height="270dp"
|
||||
android:layout_height="320dp"
|
||||
android:layout_width="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/space_medium"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:labelFor="@id/customize_temperature"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:hint="@string/customize_hint_temperature">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/customize_temperature"
|
||||
android:inputType="none|textNoSuggestions"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:cursorVisible="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="@dimen/space_medium"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:labelFor="@id/customize_system"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:hint="@string/customize_hint_system">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/customize_system"
|
||||
android:inputType="none|textNoSuggestions"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:cursorVisible="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -42,8 +42,12 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
app:autoSizeTextType="uniform"
|
||||
app:autoSizeMaxTextSize="@dimen/max_font_headline"
|
||||
app:autoSizeMinTextSize="@dimen/min_font_headline"
|
||||
android:layout_margin="@dimen/space_medium"
|
||||
android:text="@string/collection_title"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline4" />
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<data>
|
||||
<import type="android.view.View"/>
|
||||
<import type="com.mowesta.android.app.model.ConnectViewModel.State" />
|
||||
<variable
|
||||
name="model"
|
||||
type="com.mowesta.android.app.model.ConnectViewModel" />
|
||||
<variable
|
||||
name="retryListener"
|
||||
type="Runnable" />
|
||||
</data>
|
||||
<RelativeLayout
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/connect_sun"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="150dp"
|
||||
app:srcCompat="@drawable/icon_launch_sun"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_above="@id/connect_content"
|
||||
android:contentDescription="@null" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/connect_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:id="@+id/connect_device"
|
||||
android:contentDescription="@null"
|
||||
android:layout_margin="@dimen/space_medium"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
app:srcCompat="@drawable/ic_devices_normal_24" />
|
||||
<ImageView
|
||||
android:id="@+id/connect_network"
|
||||
android:contentDescription="@null"
|
||||
android:layout_margin="@dimen/space_medium"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
app:srcCompat="@drawable/ic_wifi_normal_24" />
|
||||
<ImageView
|
||||
android:id="@+id/connect_configure"
|
||||
android:contentDescription="@null"
|
||||
android:layout_margin="@dimen/space_medium"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
app:srcCompat="@drawable/ic_toys_normal_24" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_margin="@dimen/space_large"
|
||||
style="@style/TextAppearance.MaterialComponents.Body1"
|
||||
tools:text="@{ model.messageText }"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/connect_button"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_margin="@dimen/space_medium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="@{ model.retryVisible ? View.VISIBLE: View.GONE }"
|
||||
android:onClick="@{ () -> retryListener.run() }"
|
||||
android:text="@string/connect_button_try_again" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</layout>
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout>
|
||||
<data>
|
||||
<variable
|
||||
name="addButtonListener"
|
||||
type="Runnable" />
|
||||
|
||||
</data>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
@@ -22,7 +28,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_gravity="end|top"
|
||||
android:visibility="gone"
|
||||
android:visibility="visible"
|
||||
android:onClick="@{ () -> addButtonListener.run() }"
|
||||
app:tint="@color/black"
|
||||
app:backgroundTint="@color/accent"
|
||||
android:contentDescription="@string/action_device_add"
|
||||
|
||||
@@ -29,7 +29,11 @@
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/login_title"
|
||||
android:layout_width="wrap_content"
|
||||
app:autoSizeTextType="uniform"
|
||||
app:autoSizeMaxTextSize="@dimen/max_font_headline"
|
||||
app:autoSizeMinTextSize="@dimen/min_font_headline"
|
||||
android:layout_width="match_parent"
|
||||
android:maxLines="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/space_medium"
|
||||
android:text="@string/login_title"
|
||||
@@ -63,6 +67,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/login_hint_user"
|
||||
android:maxLength="32"
|
||||
android:enabled="@{ model.loginEnabled }"
|
||||
android:inputType="text"
|
||||
android:text="@={model.login}" />
|
||||
|
||||
@@ -23,16 +23,41 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_gravity="center_horizontal"
|
||||
style="@style/match_parent_limit"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/setup_icon"
|
||||
android:layout_width="72dp"
|
||||
android:layout_height="72dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:padding="@dimen/space_medium"
|
||||
android:contentDescription="@null"
|
||||
app:srcCompat="@drawable/ic_toys_normal_24"
|
||||
android:tint="@color/accent" />
|
||||
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/setup_layout"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/setup_title"
|
||||
android:layout_width="wrap_content"
|
||||
app:autoSizeTextType="uniform"
|
||||
app:autoSizeMaxTextSize="@dimen/max_font_headline"
|
||||
app:autoSizeMinTextSize="@dimen/min_font_headline"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:paddingEnd="56dp"
|
||||
android:layout_margin="@dimen/space_medium"
|
||||
android:text="@string/setup_title"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline4" />
|
||||
@@ -72,34 +97,41 @@
|
||||
android:id="@+id/setup_button_gps"
|
||||
android:enabled="@{ model.gpsEnabled }"
|
||||
android:onClick="@{ () -> gpsButtonListener.run() }"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/setup_button_gps" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
android:layout_width="@dimen/space_medium"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<Switch
|
||||
android:id="@+id/setup_switch_manual"
|
||||
android:checked="@={ model.manualPosition }"
|
||||
android:layout_width="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/setup_button_manual" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_margin="@dimen/space_medium">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/setup_longitude"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/space_medium"
|
||||
android:layout_marginEnd="@dimen/space_medium"
|
||||
app:err="@{ model.longitudeStatus }"
|
||||
app:errorEnabled="true"
|
||||
app:startIconDrawable="@drawable/ic_gps_fixed_normal_24">
|
||||
app:startIconDrawable="@drawable/ic_longitude_normal_24">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
@@ -110,17 +142,19 @@
|
||||
android:text="@={model.longitude}" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="@dimen/space_medium"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/setup_latitude"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/space_medium"
|
||||
android:layout_marginEnd="@dimen/space_medium"
|
||||
app:err="@{ model.latitudeStatus }"
|
||||
app:errorEnabled="true"
|
||||
app:startIconDrawable="@drawable/ic_gps_fixed_normal_24">
|
||||
app:startIconDrawable="@drawable/ic_latitude_normal_24">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
@@ -131,6 +165,8 @@
|
||||
android:text="@={model.latitude}" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/space_medium"/>
|
||||
@@ -151,6 +187,7 @@
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLength="32"
|
||||
android:hint="@string/setup_hint_wlan_name"
|
||||
android:inputType="text"
|
||||
android:text="@={model.networkName}" />
|
||||
@@ -193,11 +230,12 @@
|
||||
app:counterMaxLength="32"
|
||||
app:err="@{ model.deviceNameStatus }"
|
||||
app:errorEnabled="true"
|
||||
app:startIconDrawable="@drawable/ic_memory_black_24dp">
|
||||
app:startIconDrawable="@drawable/ic_memory_normal_24dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLength="32"
|
||||
android:hint="@string/setup_hint_device_name"
|
||||
android:inputType="text"
|
||||
android:text="@={model.deviceName}" />
|
||||
@@ -228,6 +266,9 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</layout>
|
||||
@@ -26,12 +26,16 @@
|
||||
app:boxBackgroundColor="@color/accent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:hintTextColor="?attr/colorControlNormal"
|
||||
android:textColorHint="@color/fg_accent"
|
||||
app:hintTextColor="@color/fg_accent"
|
||||
app:endIconMode="clear_text"
|
||||
app:startIconTint="@color/fg_accent"
|
||||
app:endIconTint="@color/fg_accent"
|
||||
app:startIconDrawable="@drawable/ic_search_normal_24">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/fg_accent"
|
||||
android:hint="@string/stations_search_hint"
|
||||
android:inputType="text"
|
||||
android:text="@={model.term}" />
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
android:minWidth="140dp"
|
||||
android:padding="8dp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/fg_accent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:tint="@color/fg_accent"
|
||||
android:contentDescription="@null"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center_vertical" />
|
||||
@@ -34,6 +35,7 @@
|
||||
countryName="@{model.country}"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
android:textColor="@color/fg_accent"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:layout_width="0dp"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="?attr/textAppearanceBody1"/>
|
||||
@@ -35,6 +35,9 @@
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="36dp"
|
||||
android:clipToPadding="false"
|
||||
android:paddingTop="18dp"
|
||||
android:paddingBottom="18dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="0dp">
|
||||
|
||||
@@ -42,6 +45,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/guide_center"
|
||||
android:layout_margin="36dp"
|
||||
app:layout_constraintGuide_percent="0.5"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:tint="@color/fg_accent"
|
||||
android:contentDescription="@null"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center_vertical" />
|
||||
@@ -39,6 +40,7 @@
|
||||
tools:text="Nordrhein-Westfalen"
|
||||
stateName="@{model.state}"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
android:textColor="@color/fg_accent"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:layout_width="match_parent"
|
||||
@@ -46,6 +48,7 @@
|
||||
<TextView
|
||||
tools:text="Deutschland"
|
||||
stateCountry="@{model.state}"
|
||||
android:textColor="@color/fg_accent"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:contentDescription="@null"
|
||||
android:tint="@color/fg_accent"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center_vertical" />
|
||||
<LinearLayout
|
||||
@@ -44,6 +45,7 @@
|
||||
tools:text="Essen-Bredeney"
|
||||
stationName="@{model.station}"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
android:textColor="@color/fg_accent"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:layout_weight="1"
|
||||
@@ -53,16 +55,19 @@
|
||||
<TextView
|
||||
stationAltitude="@{model.station}"
|
||||
tools:text="3000 m"
|
||||
android:textColor="@color/fg_accent"
|
||||
android:textAppearance="?attr/textAppearanceCaption"
|
||||
android:textAlignment="textEnd"
|
||||
android:layout_width="60dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="20dp"
|
||||
android:padding="1dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_gravity="bottom"
|
||||
android:gravity="bottom"
|
||||
android:contentDescription="@string/label_altitude"
|
||||
android:tint="@color/fg_accent"
|
||||
tools:targetApi="O"
|
||||
android:tooltipText="@string/label_altitude"
|
||||
app:srcCompat="@drawable/ic_landscape_normal_24" />
|
||||
@@ -72,6 +77,7 @@
|
||||
<TextView
|
||||
tools:text="Deutscher Wetterdienst"
|
||||
stationOperator="@{model.station}"
|
||||
android:textColor="@color/fg_accent"
|
||||
android:textAppearance="?attr/textAppearanceBody2"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
|
||||
@@ -44,16 +44,17 @@
|
||||
|
||||
<TextView
|
||||
stationAltitude="@{model}"
|
||||
tools:text="100 m"
|
||||
tools:text="1100 m / 1250 ft"
|
||||
android:textAppearance="?attr/textAppearanceCaption"
|
||||
android:textAlignment="textEnd"
|
||||
android:layout_width="60dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="20dp"
|
||||
android:padding="1dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_gravity="bottom"
|
||||
android:gravity="bottom"
|
||||
android:contentDescription="@string/label_altitude"
|
||||
tools:targetApi="O"
|
||||
android:tooltipText="@string/label_altitude"
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
app:weather="THERMOMETER"/>
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:layout_marginEnd="16dp"
|
||||
@@ -112,7 +112,7 @@
|
||||
tools:text="10 °C / 20 °F" />
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textStyle="bold"
|
||||
@@ -137,7 +137,7 @@
|
||||
app:weather="RAINDROPS"/>
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:layout_marginEnd="16dp"
|
||||
@@ -146,7 +146,7 @@
|
||||
tools:text="0.0 kg/m²h" />
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
@@ -167,7 +167,7 @@
|
||||
directionIcon="@{model.max}"/>
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:gravity="end"
|
||||
@@ -176,7 +176,7 @@
|
||||
tools:text="22 km/h / 7 mph" />
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
@@ -200,7 +200,7 @@
|
||||
app:weather="CLOUD"/>
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:gravity="end"
|
||||
@@ -209,7 +209,7 @@
|
||||
tools:text="62.54 %" />
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
@@ -233,7 +233,7 @@
|
||||
app:weather="HUMIDITY"/>
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:layout_marginEnd="16dp"
|
||||
@@ -242,7 +242,7 @@
|
||||
tools:text="0.00 %" />
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
@@ -266,7 +266,7 @@
|
||||
app:weather="SNOWFLAKE_COLD"/>
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:gravity="end"
|
||||
@@ -275,7 +275,7 @@
|
||||
tools:text="1.12 m" />
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
@@ -299,7 +299,7 @@
|
||||
app:weather="BAROMETER"/>
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:layout_marginEnd="16dp"
|
||||
@@ -308,7 +308,7 @@
|
||||
tools:text="1012.12 hPA" />
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textAppearance="?attr/textAppearanceBody1"
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
<menu
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:title="@string/action_switch_to_fahrenheit"
|
||||
<item android:title="@string/action_temperature"
|
||||
app:showAsAction="ifRoom"
|
||||
android:id="@+id/unit_celsius"
|
||||
android:icon="@drawable/ic_celsius_normal_24"/>
|
||||
<item android:title="@string/action_switch_to_celsius"
|
||||
android:id="@+id/action_temperature_unit"
|
||||
android:icon="@drawable/ic_thermometer_normal_24"/>
|
||||
<item android:title="@string/action_system"
|
||||
app:showAsAction="ifRoom"
|
||||
android:id="@+id/unit_fahrenheit"
|
||||
android:icon="@drawable/ic_fahrenheit_normal_24"/>
|
||||
android:id="@+id/action_unit_system"
|
||||
android:icon="@drawable/ic_barometer_normal_24"/>
|
||||
</menu>
|
||||
@@ -144,9 +144,15 @@
|
||||
android:id="@+id/destination_video"
|
||||
tools:layout="@layout/fragment_video"
|
||||
android:name="com.mowesta.android.app.fragment.VideoFragment" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/destination_setup"
|
||||
tools:layout="@layout/fragment_setup"
|
||||
android:name="com.mowesta.android.app.fragment.SetupFragment" />
|
||||
<fragment
|
||||
android:id="@+id/destination_connect"
|
||||
tools:layout="@layout/fragment_connect"
|
||||
android:name="com.mowesta.android.app.fragment.ConnectFragment" />
|
||||
<include app:graph="@navigation/navigation_drawer" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_drawer"
|
||||
app:popUpTo="@id/destination_drawer"
|
||||
|
||||
@@ -30,23 +30,30 @@
|
||||
<string name="setup_hint_wlan_name">Netzwerkname</string>
|
||||
<string name="setup_hint_wlan_password">Netzwerkpasswort</string>
|
||||
<string name="setup_hint_device_name">Gerätename</string>
|
||||
<string name="setup_device_manufacturer">MoWeSta</string>
|
||||
<string name="setup_device_name_default">Arduino</string>
|
||||
<string name="setup_hint_longitude">Längengrad</string>
|
||||
<string name="setup_hint_latitude">Breitengrad</string>
|
||||
<string name="setup_button_manual">Manuelle Standorteingabe</string>
|
||||
<string name="setup_button_gps">GPS-Standort bestimmen</string>
|
||||
<string name="setup_message_wait_gps">Bestimme GPS-Standort</string>
|
||||
<string name="setup_message_no_gps">Bitte schalte Deinen GPS-Empfänger ein</string>
|
||||
<string name="setup_error_longitude">Ungültiger Längengrad, der Wert muss zwischen -180 und +180 Grad liegen.</string>
|
||||
<string name="setup_error_latitude">Ungültiger Breitengrad, der Wert muss zwischen -90 und +90 Grad liegen.</string>
|
||||
<string name="setup_message_creating">Erstelle MoWeSta Gerät</string>
|
||||
<string name="setup_message_searching">Suche nach WiFi Netzwerken</string>
|
||||
<string name="setup_message_connecting">Verbindung wird hergestellt</string>
|
||||
<string name="setup_message_transfering">Wetterstation wird eingerichtet</string>
|
||||
<string name="setup_message_success">Einrichtung abgeschlossen</string>
|
||||
<string name="setup_message_failed">Einrichtung fehlgeschlagen</string>
|
||||
<string name="setup_button_try_again">Nochmal versuchen</string>
|
||||
<string name="setup_button_manual">Manuelle Eingabe</string>
|
||||
<string name="setup_button_gps">Standort bestimmen</string>
|
||||
<string name="setup_error_longitude">Ungültiger Längengrad.</string>
|
||||
<string name="setup_error_latitude">Ungültiger Breitengrad.</string>
|
||||
<string name="setup_button_ready">Fortfahren</string>
|
||||
<string name="setup_error_wlan_name_too_short">Der Netzwerkname ist erforderlich.</string>
|
||||
<string name="setup_error_wlan_password_none">Das Netzwerkpasswort ist erforderlich.</string>
|
||||
<string name="setup_error_wlan_password_too_short">Das Netzwerkpasswort ist zu kurz.</string>
|
||||
<string name="setup_error_device_name_too_short">Ein Gerätename ist erforderlich.</string>
|
||||
<string name="setup_error_gps_disabled">GPS ist derzeit deaktiviert.</string>
|
||||
|
||||
<string name="connect_message_creating">Erstelle MoWeSta Gerät</string>
|
||||
<string name="connect_message_create_failed">Das Gerät konnte nicht erstellt werden. Stell sicher, dass Du mit dem Internet verbunden bist und versuch\'s nochmal.</string>
|
||||
<string name="connect_message_searching">Suche nach WiFi Netzwerken</string>
|
||||
<string name="connect_message_search_failed">Die Verbindung mit dem Netzwerk ist fehlgeschlagen. Stell sicher, dass sich Dein Arduino im Einrichtungsmodus befindet und versuch\'s nochmal.</string>
|
||||
<string name="connect_message_transfering">Wetterstation wird eingerichtet</string>
|
||||
<string name="connect_message_transfer_failed">Die Einrichtung ist fehlgeschlagen. Stell sicher, dass sich Dein Arduino im Einrichtungsmodus befindet und versuch\'s nochmal.</string>
|
||||
|
||||
<string name="connect_message_success">Einrichtung erfolgreich</string>
|
||||
<string name="connect_button_try_again">Nochmal versuchen</string>
|
||||
|
||||
<!-- login and register -->
|
||||
<string name="login_url_register">https://www.mowesta.com/app/de/register</string>
|
||||
@@ -176,6 +183,9 @@
|
||||
<string name="city_type_capital">Hauptstadt</string>
|
||||
<string name="city_type_city">Stadt</string>
|
||||
<string name="city_type_town">Kleinstadt</string>
|
||||
<string name="city_type_suburb">Vorort</string>
|
||||
<string name="city_type_village">Dorf</string>
|
||||
|
||||
|
||||
|
||||
<string name="label_city">Stadt</string>
|
||||
@@ -242,9 +252,21 @@
|
||||
<string name="action_wikipedia">Bei Wikipedia anzeigen</string>
|
||||
<string name="action_refresh">Aktualisieren</string>
|
||||
<string name="action_device_add">Gerät hinzufügen</string>
|
||||
<string name="action_switch_to_fahrenheit">In Fahrenheit anzeigen</string>
|
||||
<string name="action_switch_to_celsius">In Celsius anzeigen</string>
|
||||
<string name="action_customize">Ansicht anpassen</string>
|
||||
<string name="action_temperature">Temperaturskala auswählen</string>
|
||||
<string name="action_system">Einheitensystem auswählen</string>
|
||||
|
||||
|
||||
<string name="customize_hint_temperature">Temperaturskala</string>
|
||||
<string name="customize_hint_system">Einheitensystem</string>
|
||||
|
||||
<string name="customize_temperature_both">°C / °F</string>
|
||||
<string name="customize_temperature_celsius">°C</string>
|
||||
<string name="customize_temperature_fahrenheit">°F</string>
|
||||
|
||||
<string name="customize_system_both">SI / Britisch</string>
|
||||
<string name="customize_system_standard">SI</string>
|
||||
<string name="customize_system_imperial">Britisch</string>
|
||||
|
||||
<string name="snackbar_error">Fehler beim Laden der Daten.</string>
|
||||
<string name="snackbar_reload">Neu\nladen</string>
|
||||
|
||||
@@ -10,4 +10,5 @@
|
||||
<color name="separator">#eeeeee</color>
|
||||
<color name="bg_search">#fefefe</color>
|
||||
<color name="inverse">#a0000000</color>
|
||||
<color name="fg_accent">#c0000000</color>
|
||||
</resources>
|
||||
|
||||
@@ -4,5 +4,7 @@
|
||||
<dimen name="margin_default">16dp</dimen>
|
||||
<dimen name="space_large">16dp</dimen>
|
||||
<dimen name="space_medium">8dp</dimen>
|
||||
<dimen name="max_font_headline">34sp</dimen>
|
||||
<dimen name="min_font_headline">18sp</dimen>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -4,32 +4,44 @@
|
||||
<string name="ude_url" translatable="false">https://www.mowesta.com</string>
|
||||
<string name="fair_url" translatable="false">https://www.fair-opendata.de</string>
|
||||
<string name="news_url" translatable="false">https://www.mowesta.com/category/news</string>
|
||||
<string name="setup_url" translatable="false">https://www.mowesta.com/weatherstation/</string>
|
||||
|
||||
<string tools:ignore="UnusedResources" name="mowesta_sdk_notification_activity_class_name" translatable="false">com.mowesta.android.app.MowestaActivity</string>
|
||||
|
||||
|
||||
<string name="format_temperature" translatable="false">%d °C / %d °F</string>
|
||||
<string name="format_humidity" translatable="false">%.2f %%</string>
|
||||
<string name="format_cloud_coverage" translatable="false">%.2f %%</string>
|
||||
<string name="format_pressure" translatable="false">%.2f hPA</string>
|
||||
<string name="format_frequency" translatable="false">%.0f Hz</string>
|
||||
<string name="format_voltage" translatable="false">%.2f V</string>
|
||||
<string name="format_wind_speed" translatable="false">%d km/h / %d mph</string>
|
||||
<string name="format_precipitation" translatable="false">%.1f kg/hm²</string>
|
||||
<string name="format_snow" translatable="false">%.2f m</string>
|
||||
<string name="format_altitude" translatable="false">%.0f m</string>
|
||||
<string name="format_temperature_both" translatable="false">%d<small>\u00A0°C</small> / %d<small>\u00A0°F</small></string>
|
||||
<string name="format_temperature_celsius" translatable="false">%d<small> °C</small></string>
|
||||
<string name="format_temperature_fahrenheit" translatable="false">%d<small> °F</small></string>
|
||||
<string name="format_pressure_both" translatable="false"><span>%.1f<small>\u00A0hPa</small></span> / <span>%.3f<small>\u00A0psi</small></span></string>
|
||||
<string name="format_pressure_si" translatable="false">%.1f<small> hPa</small></string>
|
||||
<string name="format_pressure_im" translatable="false">%.3f<small> psi</small></string>
|
||||
<string name="format_wind_speed_both" translatable="false">%d<small>\u00A0km\u2215h</small> / %d<small>\u00A0mph</small></string>
|
||||
<string name="format_wind_speed_si" translatable="false">%d<small> km\u2215h</small></string>
|
||||
<string name="format_wind_speed_im" translatable="false">%d<small> mph</small></string>
|
||||
<string name="format_precipitation_both" translatable="false">%.1f<small>\u00A0mm\u2215h</small> / %.2f<small>\u00A0in\u2215h</small></string>
|
||||
<string name="format_precipitation_si" translatable="false">%.1f<small> mm\u2215h</small></string>
|
||||
<string name="format_precipitation_im" translatable="false">%.2f<small> in\u2215h</small></string>
|
||||
<string name="format_snow_both" translatable="false">%.2f<small>\u00A0m</small> / %.2f<small>\u00A0ft</small></string>
|
||||
<string name="format_snow_si" translatable="false">%.2f<small> m</small></string>
|
||||
<string name="format_snow_im" translatable="false">%.2f<small> ft</small></string>
|
||||
<string name="format_altitude_both" translatable="false">%.0f<small>\u00A0m</small> / %.0f<small>\u00A0ft</small></string>
|
||||
<string name="format_altitude_si" translatable="false">%.0f<small> m</small></string>
|
||||
<string name="format_altitude_im" translatable="false">%.0f<small> ft</small></string>
|
||||
|
||||
<string name="format_humidity" translatable="false">%.2f<small> %%</small></string>
|
||||
<string name="format_cloud_coverage" translatable="false">%.2f<small> %%</small></string>
|
||||
<string name="format_frequency" translatable="false">%.0f<small> Hz</small></string>
|
||||
<string name="format_voltage" translatable="false">%.2f<small> V</small></string>
|
||||
<string name="format_compact" translatable="false">%.0f</string>
|
||||
<string name="format_integer" translatable="false">%d</string>
|
||||
<string name="format_two_lines" translatable="false">%s\n%s</string>
|
||||
<string name="format_two_names" translatable="false">%s, %s</string>
|
||||
<string name="format_two_parts" translatable="false">%s | %s</string>
|
||||
|
||||
|
||||
<integer name="terms_version_current">1</integer>
|
||||
<bool name="development_mode_default">false</bool>
|
||||
<bool name="privacy_measure_default">false</bool>
|
||||
<bool name="collection_shown_default">false</bool>
|
||||
<bool name="temperature_celsius_default">true</bool>
|
||||
<bool name="show_precipitation_default">true</bool>
|
||||
<bool name="show_wind_default">true</bool>
|
||||
<bool name="show_cloud_default">true</bool>
|
||||
|
||||
@@ -30,23 +30,32 @@
|
||||
<string name="setup_hint_wlan_name">Network name</string>
|
||||
<string name="setup_hint_wlan_password">Network password</string>
|
||||
<string name="setup_hint_device_name">Device name</string>
|
||||
<string name="setup_device_manufacturer">MoWeSta</string>
|
||||
<string name="setup_device_name_default">Arduino</string>
|
||||
<string name="setup_hint_longitude">Longitude</string>
|
||||
<string name="setup_hint_latitude">Latitude</string>
|
||||
<string name="setup_button_manual">Use manual position</string>
|
||||
<string name="setup_button_manual">Enter manually</string>
|
||||
<string name="setup_button_gps">Get GPS position</string>
|
||||
<string name="setup_message_wait_gps">Acquiring position from GPS</string>
|
||||
<string name="setup_message_no_gps">Please enable your GPS receiver</string>
|
||||
<string name="setup_error_longitude">Invalid longitude, must range from -180 to +180 degrees.</string>
|
||||
<string name="setup_error_latitude">Invalid latitude, must range from -90 to +90 degrees.</string>
|
||||
<string name="setup_message_creating">Creating MoWeSta device</string>
|
||||
<string name="setup_message_searching">Searching for WiFi networks</string>
|
||||
<string name="setup_message_connecting">Connecting to WiFi network</string>
|
||||
<string name="setup_message_transfering">Configuring weather station</string>
|
||||
<string name="setup_message_success">Setup complete</string>
|
||||
<string name="setup_message_failed">Setup failed</string>
|
||||
<string name="setup_button_try_again">Try again</string>
|
||||
<string name="setup_error_longitude">Invalid longitude.</string>
|
||||
<string name="setup_error_latitude">Invalid latitude.</string>
|
||||
<string name="setup_button_ready">Ready</string>
|
||||
<string name="setup_error_wlan_name_too_short">The network name is required.</string>
|
||||
<string name="setup_error_wlan_password_none">The network password is required.</string>
|
||||
<string name="setup_error_wlan_password_too_short">The network password is too short.</string>
|
||||
<string name="setup_error_device_name_too_short">A device name is required.</string>
|
||||
<string name="setup_error_gps_disabled">GPS is currently disabled.</string>
|
||||
|
||||
|
||||
<string name="connect_message_creating">Creating MoWeSta device</string>
|
||||
<string name="connect_message_create_failed">Failed to create the device. Please make sure that you are connected to the Internet and try again.</string>
|
||||
<string name="connect_message_searching">Searching for WiFi networks</string>
|
||||
<string name="connect_message_search_failed">Unable to connect to WiFi network. Please make sure that your Arduino is in setup mode and try again.</string>
|
||||
<string name="connect_message_transfering">Configuring weather station</string>
|
||||
<string name="connect_message_transfer_failed">Failed to configure the device. Please make sure that your Arduino is in setup mode and try again.</string>
|
||||
|
||||
<string name="connect_message_success">Setup complete</string>
|
||||
<string name="connect_button_try_again">Try again</string>
|
||||
|
||||
|
||||
|
||||
<!-- login and register -->
|
||||
@@ -177,6 +186,8 @@
|
||||
<string name="city_type_capital">Capital</string>
|
||||
<string name="city_type_city">City</string>
|
||||
<string name="city_type_town">Town</string>
|
||||
<string name="city_type_suburb">Suburb</string>
|
||||
<string name="city_type_village">Village</string>
|
||||
|
||||
<string name="label_city">City</string>
|
||||
<string name="label_country">Country</string>
|
||||
@@ -225,10 +236,10 @@
|
||||
<string name="city_info_hour">Hour</string>
|
||||
<string name="label_station">Weather station</string>
|
||||
<string name="label_full_day">Whole day</string>
|
||||
<string name="label_morning">6 – 12 a.m</string>
|
||||
<string name="label_afternoon">0 – 6 p.m.</string>
|
||||
<string name="label_evening">6 – 12 p.m.</string>
|
||||
<string name="label_night">0 – 6 a.m.</string>
|
||||
<string name="label_morning">6 – 12 AM</string>
|
||||
<string name="label_afternoon">0 – 6 PM</string>
|
||||
<string name="label_evening">6 – 12 PM</string>
|
||||
<string name="label_night">0 – 6 AM</string>
|
||||
<string name="date_today">Today</string>
|
||||
<string name="date_tomorrow">Tomorrow</string>
|
||||
<string name="date_yesterday">Yesterday</string>
|
||||
@@ -244,9 +255,23 @@
|
||||
<string name="action_wikipedia">Open in Wikipedia </string>
|
||||
<string name="action_refresh">Refresh</string>
|
||||
<string name="action_device_add">Add device</string>
|
||||
<string name="action_switch_to_fahrenheit">Show as Fahrenheit</string>
|
||||
<string name="action_switch_to_celsius">Show as Celsius</string>
|
||||
<string name="action_customize">Customize view</string>
|
||||
<string name="action_temperature">Set temperature scale</string>
|
||||
<string name="action_system">Set unit system</string>
|
||||
|
||||
|
||||
|
||||
|
||||
<string name="customize_hint_temperature">Temperature scale</string>
|
||||
<string name="customize_hint_system">Unit system</string>
|
||||
<string name="customize_temperature_both">°C / °F</string>
|
||||
<string name="customize_temperature_celsius">°C</string>
|
||||
<string name="customize_temperature_fahrenheit">°F</string>
|
||||
|
||||
<string name="customize_system_both">SI / Imperial</string>
|
||||
<string name="customize_system_standard">SI</string>
|
||||
<string name="customize_system_imperial">Imperial</string>
|
||||
|
||||
|
||||
<string name="snackbar_error">Failed to load data.</string>
|
||||
<string name="snackbar_reload">Reload</string>
|
||||
|
||||
@@ -3,4 +3,7 @@
|
||||
<domain-config cleartextTrafficPermitted="false">
|
||||
<domain includeSubdomains="true">mowesta.com</domain>
|
||||
</domain-config>
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="false">192.168.4.1</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user