Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7514953a6 | ||
|
|
0483420af2 | ||
|
|
a72613aa58 | ||
|
|
b45311404c | ||
|
|
df19ff4b14 | ||
|
|
fa6f76ba7d | ||
|
|
5aee1eb084 |
@@ -88,7 +88,7 @@ android {
|
||||
applicationId "com.mowesta.android.app"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 29
|
||||
versionCode 7
|
||||
versionCode 8
|
||||
versionName "${version}"
|
||||
buildConfigField "long", "BUILD_TIME", System.currentTimeMillis() + "L"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
@@ -6,8 +6,6 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.util.Log;
|
||||
@@ -55,7 +53,7 @@ public class WifiTask extends NetworkTask {
|
||||
if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
|
||||
Log.d(TAG, "Received network state changed.");
|
||||
if (intent.hasExtra(WifiManager.EXTRA_NETWORK_INFO)) {
|
||||
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||
android.net.NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||
if (info != null) {
|
||||
Log.d(TAG, "Received network info: " + info);
|
||||
if (info.isConnected() && isWifiConnected()) {
|
||||
@@ -119,7 +117,7 @@ public class WifiTask extends NetworkTask {
|
||||
Log.d(TAG, "Wifi was disabled, turning it on.");
|
||||
didEnableWifi = manager.setWifiEnabled(true);
|
||||
}
|
||||
WifiConfiguration existing = findConfiguration();
|
||||
android.net.wifi.WifiConfiguration existing = findConfiguration();
|
||||
if (existing == null) {
|
||||
networkId = manager.addNetwork(createConfiguration());
|
||||
manager.saveConfiguration();
|
||||
@@ -171,8 +169,8 @@ public class WifiTask extends NetworkTask {
|
||||
*/
|
||||
private int getMaximumPriority() throws SecurityException {
|
||||
int result = 1;
|
||||
List<WifiConfiguration> configurations = manager.getConfiguredNetworks();
|
||||
for (WifiConfiguration configuration: configurations) {
|
||||
List<android.net.wifi.WifiConfiguration> configurations = manager.getConfiguredNetworks();
|
||||
for (android.net.wifi.WifiConfiguration configuration: configurations) {
|
||||
result = Math.max(result, configuration.priority);
|
||||
}
|
||||
return result;
|
||||
@@ -184,10 +182,10 @@ public class WifiTask extends NetworkTask {
|
||||
* @return The network configuration, if present already.
|
||||
* @throws SecurityException Thrown if we are missing a permission.
|
||||
*/
|
||||
private WifiConfiguration findConfiguration() throws SecurityException {
|
||||
private android.net.wifi.WifiConfiguration findConfiguration() throws SecurityException {
|
||||
String ssid = getSsid();
|
||||
List<WifiConfiguration> configurations = manager.getConfiguredNetworks();
|
||||
for (WifiConfiguration configuration: configurations) {
|
||||
List<android.net.wifi.WifiConfiguration> configurations = manager.getConfiguredNetworks();
|
||||
for (android.net.wifi.WifiConfiguration configuration: configurations) {
|
||||
if (ssid.equals(configuration.SSID)) {
|
||||
return configuration;
|
||||
}
|
||||
@@ -200,19 +198,19 @@ public class WifiTask extends NetworkTask {
|
||||
*
|
||||
* @return The network configuration.
|
||||
*/
|
||||
private WifiConfiguration createConfiguration() {
|
||||
WifiConfiguration result = new WifiConfiguration();
|
||||
private android.net.wifi.WifiConfiguration createConfiguration() {
|
||||
android.net.wifi.WifiConfiguration result = new android.net.wifi.WifiConfiguration();
|
||||
result.SSID = getSsid();
|
||||
result.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
|
||||
result.allowedProtocols.set(WifiConfiguration.Protocol.RSN); // For WPA2
|
||||
result.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
|
||||
result.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
|
||||
result.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
|
||||
result.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
|
||||
result.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
|
||||
result.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
|
||||
result.allowedAuthAlgorithms.set(android.net.wifi.WifiConfiguration.AuthAlgorithm.OPEN);
|
||||
result.allowedProtocols.set(android.net.wifi.WifiConfiguration.Protocol.RSN); // For WPA2
|
||||
result.allowedKeyManagement.set(android.net.wifi.WifiConfiguration.KeyMgmt.WPA_PSK);
|
||||
result.allowedKeyManagement.set(android.net.wifi.WifiConfiguration.KeyMgmt.WPA_EAP);
|
||||
result.allowedPairwiseCiphers.set(android.net.wifi.WifiConfiguration.PairwiseCipher.TKIP);
|
||||
result.allowedPairwiseCiphers.set(android.net.wifi.WifiConfiguration.PairwiseCipher.CCMP);
|
||||
result.allowedGroupCiphers.set(android.net.wifi.WifiConfiguration.GroupCipher.TKIP);
|
||||
result.allowedGroupCiphers.set(android.net.wifi.WifiConfiguration.GroupCipher.CCMP);
|
||||
result.preSharedKey = String.format("\"%s\"", ArduinoConfig.ARDUINO_PWD);
|
||||
result.status = WifiConfiguration.Status.ENABLED;
|
||||
result.status = android.net.wifi.WifiConfiguration.Status.ENABLED;
|
||||
try {
|
||||
int priority = getMaximumPriority() + 400;
|
||||
Log.d(TAG, "Setting maximum priority to " + priority + ".");
|
||||
|
||||
+19
-13
@@ -58,24 +58,27 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
if (request != null) {
|
||||
switch (request.getType()) {
|
||||
case DAY:
|
||||
pager.setCurrentItem(0, true);
|
||||
break;
|
||||
case TIME:
|
||||
pager.setCurrentItem(1, true);
|
||||
break;
|
||||
case HOUR:
|
||||
case TIME:
|
||||
pager.setCurrentItem(2, true);
|
||||
break;
|
||||
case HOUR:
|
||||
pager.setCurrentItem(3, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
TabLayout tabs = view.findViewById(R.id.tabs);
|
||||
TabLayout tabs = getActivity().findViewById(R.id.tabs);
|
||||
new TabLayoutMediator(tabs, pager, (tab, position) -> {
|
||||
switch (position) {
|
||||
case 0:
|
||||
tab.setText(R.string.city_info_day);
|
||||
tab.setText(R.string.city_info_gradient);
|
||||
break;
|
||||
case 1:
|
||||
tab.setText(R.string.city_info_day);
|
||||
break;
|
||||
case 2:
|
||||
tab.setText(R.string.city_info_time);
|
||||
break;
|
||||
default:
|
||||
@@ -100,16 +103,20 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
ForecastRecyclerFragment fragment = new ForecastRecyclerFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("page", position);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
if (position == 0) {
|
||||
return new CityGradientFragment();
|
||||
} else {
|
||||
ForecastRecyclerFragment fragment = new ForecastRecyclerFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("page", position - 1);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,5 +433,4 @@ public class CityForecastFragment extends CityFragment.ChildFragment {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
package com.mowesta.android.app.fragment;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.databinding.FragmentGradientBinding;
|
||||
import com.mowesta.android.app.model.CustomizeViewModel;
|
||||
import com.mowesta.android.app.util.DateFormatter;
|
||||
import com.mowesta.android.app.util.TimeUtils;
|
||||
import com.mowesta.android.app.view.DataView;
|
||||
import com.mowesta.android.app.view.TimeView;
|
||||
import com.mowesta.android.app.view.color.CloudDepthColorScheme;
|
||||
import com.mowesta.android.app.view.color.HumidityColorScheme;
|
||||
import com.mowesta.android.app.view.color.PrecipitationColorScheme;
|
||||
import com.mowesta.android.app.view.color.PressureColorScheme;
|
||||
import com.mowesta.android.app.view.color.ScientificTemperatureColorScheme;
|
||||
import com.mowesta.android.app.view.color.WhiteCloudColorScheme;
|
||||
import com.mowesta.android.feign.model.WeatherCondition;
|
||||
|
||||
/**
|
||||
* The fragment to show the overview as a bunch of gradients.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class CityGradientFragment extends CityFragment.ChildFragment {
|
||||
|
||||
/**
|
||||
* The timeout after which we reset the view.
|
||||
*/
|
||||
private static final int TIMEOUT_REMOVER = 10000;
|
||||
|
||||
/**
|
||||
* The view binding.
|
||||
*/
|
||||
private FragmentGradientBinding binding;
|
||||
|
||||
/**
|
||||
* The time utilities.
|
||||
*/
|
||||
private TimeUtils timeUtils = new TimeUtils(System.currentTimeMillis(), null);
|
||||
|
||||
/**
|
||||
* The view pager of the parent.
|
||||
*/
|
||||
private ViewPager2 pager;
|
||||
|
||||
/**
|
||||
* The date formatter.
|
||||
*/
|
||||
private DateFormatter dateFormatter;
|
||||
|
||||
/**
|
||||
* The handler to post the removal of
|
||||
*/
|
||||
private Handler handler = new Handler();
|
||||
|
||||
/**
|
||||
* The animator for the progress bar.
|
||||
*/
|
||||
private ValueAnimator animator;
|
||||
|
||||
/**
|
||||
* The weather condition to display as text.
|
||||
*/
|
||||
private WeatherCondition condition = new WeatherCondition();
|
||||
|
||||
private boolean closed = false;
|
||||
|
||||
private Runnable remover = () -> {
|
||||
updateSelection(null);
|
||||
animator.cancel();
|
||||
binding.gradientText.setVisibility(View.GONE);
|
||||
};
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
dateFormatter = new DateFormatter(getContext());
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_gradient, container, false);
|
||||
// this is quite ugly, but we need to disable the view pager and collapse the toolbar
|
||||
pager = getActivity().findViewById(R.id.pager);
|
||||
AppBarLayout layout = getActivity().findViewById(R.id.layout_appbar);
|
||||
binding.gradientProgress1.setMax(TIMEOUT_REMOVER);
|
||||
binding.gradientProgress2.setMax(TIMEOUT_REMOVER);
|
||||
animator = ValueAnimator.ofInt(TIMEOUT_REMOVER, 0);
|
||||
animator.setInterpolator(new LinearInterpolator());
|
||||
animator.setDuration(TIMEOUT_REMOVER);
|
||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation){
|
||||
int value = (Integer)animation.getAnimatedValue();
|
||||
binding.gradientProgress1.setProgress(value);
|
||||
binding.gradientProgress2.setProgress(value);
|
||||
binding.gradientText.setAlpha(Math.min(1, Math.max(0, value / 1000f)));
|
||||
}
|
||||
});
|
||||
binding.gradientScroll.setOnTouchListener(binding.gradientTouch.createOnTouchListener(new TimeView.OnSlideListener() {
|
||||
@Override
|
||||
public void onSlide(float relative) {
|
||||
if (!hasData()) return;
|
||||
animator.cancel();
|
||||
binding.gradientProgress1.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientProgress2.setProgress(TIMEOUT_REMOVER);
|
||||
binding.gradientText.setAlpha(1);
|
||||
handler.removeCallbacks(remover);
|
||||
if (!closed) {
|
||||
layout.setExpanded(false, true);
|
||||
closed = true;
|
||||
}
|
||||
pager.setUserInputEnabled(false);
|
||||
updateSelection(relative);
|
||||
updateCondition(relative);
|
||||
binding.gradientText.setVisibility(View.VISIBLE);
|
||||
updateGuide(relative);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlideEnd() {
|
||||
pager.setUserInputEnabled(true);
|
||||
closed = false;
|
||||
animator.start();
|
||||
handler.postDelayed(remover, TIMEOUT_REMOVER);
|
||||
}
|
||||
}));
|
||||
|
||||
binding.setLifecycleOwner(getViewLifecycleOwner());
|
||||
binding.gradientText.setVisibility(View.GONE);
|
||||
binding.gradientTemperature.setColorScheme(new ScientificTemperatureColorScheme());
|
||||
binding.gradientCloud.setColorScheme(new WhiteCloudColorScheme());
|
||||
binding.gradientCloud.setSecondaryColorScheme(new CloudDepthColorScheme());
|
||||
binding.gradientPreciptiation.setColorScheme(new PrecipitationColorScheme());
|
||||
binding.gradientHumidity.setColorScheme(new HumidityColorScheme());
|
||||
getCityViewModel().getHour().observe(getViewLifecycleOwner(), (list) -> {
|
||||
if (list == null) return;
|
||||
int housrs = 0;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
housrs += list.get(i).getCondition().getValue().getDuration();
|
||||
}
|
||||
Double[] temp = new Double[housrs];
|
||||
Double[] cloud = new Double[housrs];
|
||||
Double[] depth = new Double[housrs];
|
||||
Double[] prec = new Double[housrs];
|
||||
Double[] pres = new Double[housrs];
|
||||
Double[] wind = new Double[housrs];
|
||||
Double[] hum = new Double[housrs];
|
||||
Long[] hours = new Long[housrs];
|
||||
int index = 0;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
WeatherCondition wc = list.get(i).getCondition().getValue();
|
||||
for (int j = 0; j < wc.getDuration(); j++) {
|
||||
temp[index] = wc.getTemperature();
|
||||
cloud[index] = wc.getCloudCoverage();
|
||||
prec[index] = wc.getPrecipitation();
|
||||
pres[index] = wc.getPressure();
|
||||
depth[index] = wc.getCloudDepth();
|
||||
wind[index] = wc.getWindSpeed();
|
||||
hum[index] = wc.getHumidity();
|
||||
hours[index] = wc.getTime() + j * 3600000;
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
binding.gradientCloud.setSecondaryData(depth);
|
||||
binding.gradientTemperature.setData(temp);
|
||||
binding.gradientPressure.setData(pres);
|
||||
binding.gradientCloud.setData(cloud);
|
||||
binding.gradientPreciptiation.setData(prec);
|
||||
binding.gradientWindSpeed.setData(wind);
|
||||
binding.gradientHumidity.setData(hum);
|
||||
binding.gradientTouch.setData(hours);
|
||||
});
|
||||
getCityViewModel().getForecast().observe(getViewLifecycleOwner(), (forecast) -> {
|
||||
if (forecast != null) {
|
||||
// 1013,25 hPa * [ 1 − 6,5 * Höhe / (288150 m) ]5,255
|
||||
double avg = 1013.25 * Math.pow(1 - 6.5 * forecast.getSurfaceHeight() / 288150.0, 5.255);
|
||||
binding.gradientPressure.setColorScheme(new PressureColorScheme(avg, avg - 20, avg + 10));
|
||||
}
|
||||
});
|
||||
getCityViewModel().getCity().observe(getViewLifecycleOwner(), (city) -> {
|
||||
if (city != null) {
|
||||
binding.gradientTouch.setTimezone(city.getTimezone());
|
||||
timeUtils = new TimeUtils(System.currentTimeMillis(), city.getTimezone());
|
||||
}
|
||||
});
|
||||
// observe changes to the settings that affect us
|
||||
CustomizeViewModel customizeViewModel = new ViewModelProvider(this).get(CustomizeViewModel.class);
|
||||
customizeViewModel.getTemperatureUnit().observe(getViewLifecycleOwner(), (u)-> {
|
||||
Float selection = binding.gradientTouch.getSelection();
|
||||
if (selection != null) updateCondition(selection);
|
||||
});
|
||||
customizeViewModel.getUnitSystem().observe(getViewLifecycleOwner(), (s) -> {
|
||||
Float selection = binding.gradientTouch.getSelection();
|
||||
if (selection != null) updateCondition(selection);
|
||||
});
|
||||
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private boolean hasData() {
|
||||
return binding.gradientTouch.getData() != null && binding.gradientTouch.getData().length > 0;
|
||||
}
|
||||
|
||||
private void updateSelection(Float selection) {
|
||||
binding.gradientTemperature.setSelection(selection);
|
||||
binding.gradientWindSpeed.setSelection(selection);
|
||||
binding.gradientPreciptiation.setSelection(selection);
|
||||
binding.gradientHumidity.setSelection(selection);
|
||||
binding.gradientPressure.setSelection(selection);
|
||||
binding.gradientCloud.setSelection(selection);
|
||||
binding.gradientTouch.setSelection(selection);
|
||||
}
|
||||
|
||||
private void updateCondition(float selection) {
|
||||
long time = binding.gradientTouch.getDataAt(selection);
|
||||
condition.setTime(time);
|
||||
condition.setWindSpeed(binding.gradientWindSpeed.getDataAt(selection));
|
||||
condition.setPrecipitation(binding.gradientPreciptiation.getDataAt(selection));
|
||||
condition.setHumidity(binding.gradientHumidity.getDataAt(selection));
|
||||
condition.setPressure(binding.gradientPressure.getDataAt(selection));
|
||||
condition.setCloudCoverage(binding.gradientCloud.getDataAt(selection));
|
||||
condition.setTemperature(binding.gradientTemperature.getDataAt(selection));
|
||||
String day = timeUtils.getDayName(getContext(), time);
|
||||
String hour = dateFormatter.asTime(time, binding.gradientTouch.getTimezone());
|
||||
binding.gradientTime.setText(getString(R.string.format_two_parts, day, hour));
|
||||
binding.setModel(condition);
|
||||
}
|
||||
|
||||
private void updateGuide(float relative) {
|
||||
float px = 64 * getResources().getDisplayMetrics().density;
|
||||
float max = 128 * getResources().getDisplayMetrics().density;
|
||||
int size = binding.gradientTouch.getDirection() == DataView.Direction.HORIZONTAL ?
|
||||
binding.gradientConstraint.getWidth():binding.gradientConstraint.getHeight();
|
||||
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams)binding.gradientText.getLayoutParams();
|
||||
float percent = size == 0 ? 0 : px / size;
|
||||
float delta = size == 0 ? 0 : max / size;
|
||||
if (binding.gradientTouch.getDirection() == DataView.Direction.VERTICAL) {
|
||||
if (relative - delta < 0) {
|
||||
binding.guideGradient.setGuidelinePercent(relative + 2 * percent);
|
||||
params.bottomToTop = -1;
|
||||
params.topToBottom = R.id.guide_gradient;
|
||||
} else {
|
||||
binding.guideGradient.setGuidelinePercent(relative - percent);
|
||||
params.topToBottom = -1;
|
||||
params.bottomToTop = R.id.guide_gradient;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (relative > 0.5) {
|
||||
binding.guideGradient.setGuidelinePercent(relative - percent);
|
||||
params.leftToLeft = -1;
|
||||
params.rightToRight = R.id.guide_gradient;
|
||||
} else {
|
||||
binding.guideGradient.setGuidelinePercent(relative + percent);
|
||||
params.leftToLeft = R.id.guide_gradient;
|
||||
params.rightToRight = -1;
|
||||
}
|
||||
}
|
||||
binding.gradientText.setLayoutParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
handler.removeCallbacks(remover);
|
||||
remover.run();
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,7 @@ public class SetupViewModel extends AndroidViewModel {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) { }
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) { }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mowesta.android.app.util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
@@ -38,8 +39,8 @@ public class DateFormatter {
|
||||
* @return The formatted date with time.
|
||||
*/
|
||||
public String asDateTime(long time, @Nullable String timezone) {
|
||||
Date date = getDate(time, timezone);
|
||||
return getDateFormat().format(date) + " " + getTimeFormat().format(date);
|
||||
Calendar date = getDate(time, timezone);
|
||||
return format(getDateFormat(), date) + " " + format(getTimeFormat(), date);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +51,7 @@ public class DateFormatter {
|
||||
* @return The formatted date.
|
||||
*/
|
||||
public String asDate(long time, @Nullable String timezone) {
|
||||
return getDateFormat().format(getDate(time, timezone));
|
||||
return format(getDateFormat(), getDate(time, timezone));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +62,7 @@ public class DateFormatter {
|
||||
* @return The formatted time.
|
||||
*/
|
||||
public String asTime(long time, @Nullable String timezone) {
|
||||
return getTimeFormat().format(getDate(time, timezone));
|
||||
return format(getTimeFormat(), getDate(time, timezone));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,13 +72,26 @@ public class DateFormatter {
|
||||
* @param timezone The timezone or null to use the host timezone.
|
||||
* @return The date.
|
||||
*/
|
||||
private Date getDate(long time, @Nullable String timezone) {
|
||||
private Calendar getDate(long time, @Nullable String timezone) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
if (timezone != null) {
|
||||
c.setTimeZone(TimeZone.getTimeZone(timezone));
|
||||
|
||||
}
|
||||
c.setTimeInMillis(time);
|
||||
return c.getTime();
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the time in the calendar using the format.
|
||||
*
|
||||
* @param format The format.
|
||||
* @param c The calendar.
|
||||
* @return The string.
|
||||
*/
|
||||
private String format(DateFormat format, Calendar c) {
|
||||
format.setCalendar(c);
|
||||
return format.format(c.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
|
||||
/**
|
||||
* A base class for views that show data. Besides from storing the
|
||||
* values this view also contains some funky logic to create a
|
||||
* magnifier effect.
|
||||
*
|
||||
* @param <T> The type of data to display.
|
||||
*/
|
||||
public abstract class DataView<T> extends View {
|
||||
|
||||
|
||||
/** The drawing direction of the gradient. */
|
||||
public enum Direction {
|
||||
/** Draw from left to right. */
|
||||
HORIZONTAL,
|
||||
/** Draw from top to bottom. */
|
||||
VERTICAL;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The drawing direction.
|
||||
*/
|
||||
@NonNull
|
||||
protected Direction direction = Direction.VERTICAL;
|
||||
|
||||
/**
|
||||
* A bitmap to draw the magnifier effect.
|
||||
*/
|
||||
protected Bitmap bitmap;
|
||||
|
||||
/**
|
||||
* The bitmap size in dp.
|
||||
*/
|
||||
protected int bitmapSize;
|
||||
|
||||
/**
|
||||
* The data of the view.
|
||||
*/
|
||||
@Nullable
|
||||
protected T[] data;
|
||||
|
||||
/**
|
||||
* The current selection or null.
|
||||
*/
|
||||
@Nullable
|
||||
protected Float selection;
|
||||
|
||||
@NonNull
|
||||
protected Paint bitmapBorderPaint = new Paint();
|
||||
|
||||
/**
|
||||
* The color for the background.
|
||||
*/
|
||||
private int colorNormal;
|
||||
|
||||
/**
|
||||
* The canvas to draw on the bitmap.
|
||||
*/
|
||||
private Canvas bitmapCanvas;
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public DataView(Context context) {
|
||||
super(context);
|
||||
init(context, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
*/
|
||||
public DataView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The style attrs.
|
||||
*/
|
||||
public DataView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The style attrs.
|
||||
* @param defStyleRes The style res.
|
||||
*/
|
||||
@TargetApi(21)
|
||||
public DataView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attribute set.
|
||||
*/
|
||||
private void init(Context context, @Nullable AttributeSet attrs) {
|
||||
colorNormal = ResourcesCompat.getColor(context.getResources(), R.color.normal, null);
|
||||
DisplayMetrics m = getResources().getDisplayMetrics();
|
||||
bitmapSize = (int)(m.density * 48 + 0.5);
|
||||
bitmapBorderPaint.setColor(ResourcesCompat.getColor(context.getResources(), R.color.inverse, null));
|
||||
bitmapBorderPaint.setStyle(Paint.Style.STROKE);
|
||||
bitmapBorderPaint.setStrokeWidth(4);
|
||||
if (attrs != null) {
|
||||
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.DataView);
|
||||
int type = ta.getInt(R.styleable.DataView_direction,-1);
|
||||
if (type >= 0 && type < Direction.values().length) {
|
||||
this.direction = Direction.values()[type];
|
||||
}
|
||||
ta.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the drawing direction.
|
||||
*
|
||||
* @param direction The drawing direction.
|
||||
*/
|
||||
public void setDirection(@NonNull Direction direction) {
|
||||
this.direction = direction;
|
||||
updateBitmap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the drawing direction.
|
||||
*
|
||||
* @return The drawing direction.
|
||||
*/
|
||||
@NonNull
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current data.
|
||||
*
|
||||
* @param data The data.
|
||||
*/
|
||||
public void setData(@Nullable T[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current data.
|
||||
*
|
||||
* @return The current data.
|
||||
*/
|
||||
@Nullable
|
||||
public T[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data at the relative position.
|
||||
*
|
||||
* @param pos The relative position.
|
||||
* @return The data.
|
||||
*/
|
||||
@Nullable
|
||||
public T getDataAt(float pos) {
|
||||
if (data == null || data.length == 0) return null;
|
||||
int idx = (int)((data.length - 1) * pos);
|
||||
idx = Math.min(Math.max(0, idx), data.length - 1);
|
||||
return data[idx];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
long now = System.currentTimeMillis();
|
||||
super.onDraw(canvas);
|
||||
onDrawData(now, canvas);
|
||||
if (selection != null) {
|
||||
bitmap.eraseColor(colorNormal);
|
||||
if (getBackground() != null) {
|
||||
getBackground().draw(bitmapCanvas);
|
||||
}
|
||||
bitmapCanvas.save();
|
||||
if (direction == Direction.VERTICAL) {
|
||||
bitmapCanvas.scale(1, 3);
|
||||
bitmapCanvas.translate(0, -selection * getHeight() + bitmapSize / 6f);
|
||||
} else {
|
||||
bitmapCanvas.scale(3, 1);
|
||||
bitmapCanvas.translate(-selection * getWidth() + bitmapSize / 6f, 0);
|
||||
}
|
||||
onDrawData(now, bitmapCanvas);
|
||||
bitmapCanvas.restore();
|
||||
if (direction == Direction.VERTICAL) {
|
||||
bitmapCanvas.drawLine(0, 1, bitmap.getWidth(), 1, bitmapBorderPaint);
|
||||
bitmapCanvas.drawLine(0, bitmap.getHeight() - 2, bitmap.getWidth(), bitmap.getHeight() - 2, bitmapBorderPaint);
|
||||
canvas.drawBitmap(bitmap, 0, selection * getHeight() - bitmapSize / 2, null);
|
||||
} else {
|
||||
bitmapCanvas.drawLine( 1, 0, 1, bitmap.getHeight(), bitmapBorderPaint);
|
||||
bitmapCanvas.drawLine(bitmap.getWidth() - 2, 0, bitmap.getWidth() - 2, bitmap.getHeight(), bitmapBorderPaint);
|
||||
canvas.drawBitmap(bitmap, selection * getWidth() - bitmapSize / 2, 0, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelection(@Nullable Float selection) {
|
||||
this.selection = selection;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Float getSelection() {
|
||||
return selection;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
updateBitmap();
|
||||
}
|
||||
|
||||
protected abstract void onDrawData(long time, Canvas canvas);
|
||||
|
||||
/**
|
||||
* Recomputes the bitmap based on the size.
|
||||
*/
|
||||
private void updateBitmap() {
|
||||
if (bitmap != null) {
|
||||
bitmap.recycle();
|
||||
bitmap = null;
|
||||
bitmapCanvas = null;
|
||||
}
|
||||
if (direction == Direction.VERTICAL) {
|
||||
if (getWidth() > 0) {
|
||||
bitmap = Bitmap.createBitmap(getWidth(), bitmapSize, Bitmap.Config.ARGB_8888);
|
||||
bitmapCanvas = new Canvas(bitmap);
|
||||
}
|
||||
} else {
|
||||
if (getHeight() > 0) {
|
||||
bitmap = Bitmap.createBitmap(bitmapSize, getHeight(), Bitmap.Config.ARGB_8888);
|
||||
bitmapCanvas = new Canvas(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* A gradient view that shows rain drops. This is used for the
|
||||
* precipitation.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class DropView extends GradientView {
|
||||
|
||||
/**
|
||||
* The threshold for rain.
|
||||
*/
|
||||
private static final double DROP_THRESHOLD = 0.1;
|
||||
|
||||
/**
|
||||
* The maximum number of water drops to simulate.
|
||||
*/
|
||||
private static final int MAXIMUM_DROPS = 45;
|
||||
|
||||
/**
|
||||
* The speed of the drops in dp.
|
||||
*/
|
||||
private static final int DROP_SPEED = 20;
|
||||
|
||||
/**
|
||||
* The random number generator for drops.
|
||||
*/
|
||||
private Random random = new Random();
|
||||
|
||||
/**
|
||||
* The drawable for a water drop.
|
||||
*/
|
||||
private Drawable drawable;
|
||||
|
||||
/**
|
||||
* The sum of all rain used to skew the random
|
||||
* number generator.
|
||||
*/
|
||||
private double sqrtSum;
|
||||
|
||||
/**
|
||||
* The square roots of the data.
|
||||
*/
|
||||
private double[] sqrts;
|
||||
|
||||
/**
|
||||
* The water drops.
|
||||
*/
|
||||
private WaterDrop[] drops = null;
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public DropView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
*/
|
||||
public DropView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The style.
|
||||
*/
|
||||
public DropView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The style.
|
||||
* @param defStyleRes The style res.
|
||||
*/
|
||||
public DropView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
private void init(Context context) {
|
||||
drawable = AppCompatResources.getDrawable(context, R.drawable.fg_water_drop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Double[] data) {
|
||||
super.setData(data);
|
||||
sqrtSum = 0;
|
||||
if (data != null) {
|
||||
sqrts = new double[data.length];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
if (data[i] > DROP_THRESHOLD) {
|
||||
sqrts[i] = Math.sqrt(data[i]);
|
||||
sqrtSum += sqrts[i];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sqrts = null;
|
||||
}
|
||||
updateDrops();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(@NonNull Direction direction) {
|
||||
super.setDirection(direction);
|
||||
updateDrops();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
updateDrops();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the drops after the data or size has changed.
|
||||
*/
|
||||
private void updateDrops() {
|
||||
if (data != null && data.length > 0 && sqrtSum > 0) {
|
||||
int count = Math.min((int) sqrtSum + 5, MAXIMUM_DROPS);
|
||||
drops = new WaterDrop[count];
|
||||
float density = getResources().getDisplayMetrics().density;
|
||||
for (int i = 0; i < drops.length; i++) {
|
||||
drops[i] = new WaterDrop(density);
|
||||
}
|
||||
postInvalidateOnAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDrawData(long time, Canvas canvas) {
|
||||
super.onDrawData(time, canvas);
|
||||
if (drops != null) {
|
||||
for (int i = 0; i < drops.length; i++) {
|
||||
drops[i].animate(time);
|
||||
drops[i].draw(canvas);
|
||||
}
|
||||
postInvalidateOnAnimation();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A class to emulate a single water drop.
|
||||
*/
|
||||
private class WaterDrop {
|
||||
|
||||
/**
|
||||
* The current time.
|
||||
*/
|
||||
private long time;
|
||||
/**
|
||||
* The left corner.
|
||||
*/
|
||||
private float x;
|
||||
/**
|
||||
* The top corner.
|
||||
*/
|
||||
private float y;
|
||||
/**
|
||||
* The remaining distance that this drop will
|
||||
* travel (in y direction) before it fades out.
|
||||
*/
|
||||
private float distance;
|
||||
/**
|
||||
* The speed at which the drop moves down in
|
||||
* pixels per second.
|
||||
*/
|
||||
private int speed;
|
||||
/**
|
||||
* The size of the current drop in pixels.
|
||||
*/
|
||||
private float size;
|
||||
/**
|
||||
* The alpha value used for drawing.
|
||||
*/
|
||||
private float alpha;
|
||||
/**
|
||||
* The screen density to compute random sizes
|
||||
* in dp.
|
||||
*/
|
||||
private float density;
|
||||
|
||||
/**
|
||||
* Creates a new drop.
|
||||
*
|
||||
* @param density The screen density.
|
||||
*/
|
||||
private WaterDrop(float density) {
|
||||
this.density = density;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a new random starting location for the water drop
|
||||
* as well as the size, movement speed (larger drops are faster)
|
||||
* and the distance to travel.
|
||||
*/
|
||||
private void reset() {
|
||||
int value = random.nextInt(5);
|
||||
size = this.density * (value + 3);
|
||||
float speedFactor = 0.5f + (value + 1) / 10f;
|
||||
speed = (int)(speedFactor * density * DROP_SPEED);
|
||||
float percent = random.nextFloat();
|
||||
double position = percent * sqrtSum;
|
||||
double current = 0;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
if (data[i] > DROP_THRESHOLD) current += sqrts[i];
|
||||
if (current >= position) {
|
||||
int start = i;
|
||||
int end = i;
|
||||
for (int j = start - 1; j >= Math.max(0, i - 8); j--) {
|
||||
if (data[j] > data[i]) start = j;
|
||||
else break;
|
||||
}
|
||||
for (int j = end + i; j < Math.min(data.length, i + 8); j++) {
|
||||
if (data[j] > data[i]) end = j;
|
||||
else break;
|
||||
}
|
||||
|
||||
if (direction == Direction.VERTICAL) {
|
||||
float dh = getHeight() / (float)data.length;
|
||||
y = dh * (start - random.nextFloat());
|
||||
x = (getWidth() - size) * random.nextFloat();
|
||||
distance = dh * (end + random.nextFloat()) - y;
|
||||
} else {
|
||||
float dw = getWidth() / (float)data.length;
|
||||
y = getHeight() * random.nextFloat();
|
||||
x = dw * (i + random.nextFloat());
|
||||
distance = (getHeight() - y) * random.nextFloat();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
alpha = 0.5f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Animates the drop for the current time.
|
||||
*
|
||||
* @param time The current time.
|
||||
*/
|
||||
public void animate(long time) {
|
||||
if (this.time == 0) {
|
||||
reset();
|
||||
} else {
|
||||
moveBy(time - this.time);
|
||||
if (alpha <= 0) {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the animation forward by a delta t in millis.
|
||||
*
|
||||
* @param delta The delta t in millis.
|
||||
*/
|
||||
private void moveBy(long delta) {
|
||||
int shift = (int)(size * (random.nextFloat() - .5f));
|
||||
float dx = delta / 1000f;
|
||||
float newy = y + dx * speed;
|
||||
x = x + dx * shift;
|
||||
distance -= newy - y;
|
||||
alpha = (float)Math.min(1, Math.max(0, 1 + distance / (size / 2)));
|
||||
y = newy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the drop in its current state.
|
||||
*
|
||||
* @param canvas The canvas to draw onto.
|
||||
*/
|
||||
public void draw(Canvas canvas) {
|
||||
int a = (int)Math.max(0, Math.min(255, alpha * 255));
|
||||
drawable.setAlpha(a);
|
||||
int ix = (int)x;
|
||||
int iy = (int)y;
|
||||
int s = (int)(size * alpha);
|
||||
drawable.setBounds(ix, iy, ix + s, iy + s);
|
||||
drawable.draw(canvas);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.gms.common.SignInButton;
|
||||
import com.mowesta.android.app.view.color.IColorScheme;
|
||||
|
||||
/**
|
||||
* A gradient view that joins two data items to get a color.
|
||||
* This is required to join the cloud depth and coverage.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class DualGradientView extends GradientView {
|
||||
|
||||
/**
|
||||
* The secondary data.
|
||||
*/
|
||||
@Nullable
|
||||
private Double[] secondaryData;
|
||||
|
||||
/**
|
||||
* The secondary color scheme.
|
||||
*/
|
||||
@Nullable
|
||||
private IColorScheme secondaryColorScheme;
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public DualGradientView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
*/
|
||||
public DualGradientView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The default attributes.
|
||||
*/
|
||||
public DualGradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The default attributes.
|
||||
* @param defStyleRes The default res.
|
||||
*/
|
||||
public DualGradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the secondary color scheme.
|
||||
*
|
||||
* @param secondaryColorScheme The secondary color scheme.
|
||||
*/
|
||||
public void setSecondaryColorScheme(@Nullable IColorScheme secondaryColorScheme) {
|
||||
this.secondaryColorScheme = secondaryColorScheme;
|
||||
updateColors();
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the secondary data.
|
||||
*
|
||||
* @param secondaryData The secondary data.
|
||||
*/
|
||||
public void setSecondaryData(@Nullable Double[] secondaryData) {
|
||||
this.secondaryData = secondaryData;
|
||||
updateColors();
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateColors() {
|
||||
super.updateColors();
|
||||
if (colors != null && secondaryData != null && secondaryColorScheme != null && secondaryData.length == colors.length) {
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
int cover = colors[i];
|
||||
int other = secondaryColorScheme.getColor(secondaryData[i]);
|
||||
colors[i] = (cover & 0xFF000000) | (other & 0x00FFFFFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Shader;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mowesta.android.app.view.color.IColorScheme;
|
||||
|
||||
/**
|
||||
* A view to display weather information as a gradient that is
|
||||
* drawn efficiently using the graphics card of the device.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class GradientView extends DataView<Double> {
|
||||
|
||||
/**
|
||||
* The color scheme.
|
||||
*/
|
||||
@Nullable
|
||||
protected IColorScheme colorScheme;
|
||||
|
||||
/**
|
||||
* The colors for the data.
|
||||
*/
|
||||
@Nullable
|
||||
protected int[] colors;
|
||||
|
||||
/**
|
||||
* The positions for the data.
|
||||
*/
|
||||
@Nullable
|
||||
protected float[] positions;
|
||||
|
||||
/**
|
||||
* The gradient for the data.
|
||||
*/
|
||||
@Nullable
|
||||
protected LinearGradient gradient;
|
||||
|
||||
/**
|
||||
* The paint to draw the gradient.
|
||||
*/
|
||||
protected Paint paint = new Paint();
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public GradientView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
*/
|
||||
public GradientView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
* @param defStyleAttr The default style.
|
||||
*/
|
||||
public GradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
* @param defStyleAttr The default style.
|
||||
* @param defStyleRes The default res.
|
||||
*/
|
||||
@TargetApi(21)
|
||||
public GradientView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
private void init(Context context) {
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Double[] data) {
|
||||
this.data = data;
|
||||
updatePositions();
|
||||
updateColors();
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color scheme to render the data.
|
||||
*
|
||||
* @return The color scheme.
|
||||
*/
|
||||
@Nullable
|
||||
public IColorScheme getColorScheme() {
|
||||
return colorScheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color scheme to render the data.
|
||||
*
|
||||
* @param colorScheme The color scheme.
|
||||
*/
|
||||
public void setColorScheme(@Nullable IColorScheme colorScheme) {
|
||||
this.colorScheme = colorScheme;
|
||||
updateColors();
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(@NonNull Direction direction) {
|
||||
this.direction = direction;
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDrawData(long time, Canvas canvas) {
|
||||
if (gradient != null) {
|
||||
paint.setShader(gradient);
|
||||
canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the gradient to draw the data.
|
||||
*/
|
||||
protected void updateGradient() {
|
||||
if (colors == null || positions == null) {
|
||||
gradient = null;
|
||||
} else {
|
||||
float x = direction == Direction.HORIZONTAL ? getWidth(): 0;
|
||||
float y = direction == Direction.HORIZONTAL ? 0 : getHeight();
|
||||
gradient = new LinearGradient(0, 0, x, y, colors, positions, Shader.TileMode.CLAMP);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the positions of the gradient.
|
||||
*/
|
||||
protected void updatePositions() {
|
||||
if (data == null) {
|
||||
positions = null;
|
||||
} else {
|
||||
positions = new float[data.length];
|
||||
for (int i = 0; i < positions.length; i++) {
|
||||
positions[i] = 0.5f/data.length + i/(float)data.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the colors of the gradient.
|
||||
*/
|
||||
protected void updateColors() {
|
||||
if (data == null || colorScheme == null) {
|
||||
colors = null;
|
||||
} else {
|
||||
colors = new int[data.length];
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
colors[i] = colorScheme.getColor(data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import com.locoslab.library.geometry.util.clipper.Clipper;
|
||||
import com.mowesta.android.app.R;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This data view generates particles moving at a data-dependent
|
||||
* speed. The particles are drawn as a linear gradient. The size
|
||||
* of the gradient also depends on the speed. This view is used
|
||||
* to draw the wind speed.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class ParticleView extends DataView<Double> {
|
||||
|
||||
/**
|
||||
* A random number generator to share across all
|
||||
* particles.
|
||||
*/
|
||||
@NonNull
|
||||
private Random random = new Random();
|
||||
|
||||
/**
|
||||
* The particles that store their current position.
|
||||
*/
|
||||
@Nullable
|
||||
private Particle[] particles;
|
||||
|
||||
/**
|
||||
* The paint to draw the particles.
|
||||
*/
|
||||
@NonNull
|
||||
private Paint paint = new Paint();
|
||||
|
||||
/**
|
||||
* A factor to speed up or slow down the motion. This
|
||||
* factor is multiplied by the speed in meter per second
|
||||
* to get the motion in pixels per second.
|
||||
*/
|
||||
private float speedFactor = 10;
|
||||
|
||||
/**
|
||||
* The relative length of the particle tails. This
|
||||
* is used to derive the maximum length.
|
||||
*/
|
||||
private float relativeLength = .5f;
|
||||
|
||||
/**
|
||||
* The relative height of the particle tails. This
|
||||
* is used to derive the stroke width.
|
||||
*/
|
||||
private float relativeHeight = .5f;
|
||||
|
||||
/**
|
||||
* The randomized start time.
|
||||
*/
|
||||
private int randomizeTime = 2000;
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public ParticleView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
*/
|
||||
public ParticleView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
* @param defStyleAttr The default style attrs.
|
||||
*/
|
||||
public ParticleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attrs.
|
||||
* @param defStyleAttr The default style attrs.
|
||||
* @param defStyleRes The default style res.
|
||||
*/
|
||||
@TargetApi(21)
|
||||
public ParticleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
private void init(Context context) {
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setStrokeCap(Paint.Cap.ROUND);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDrawData(long time, Canvas canvas) {
|
||||
if (particles != null) {
|
||||
for (int i = particles.length - 1; i >= 0; i--) {
|
||||
particles[i].animate(time);
|
||||
particles[i].draw(canvas, paint);
|
||||
}
|
||||
postInvalidateOnAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(@Nullable Double[] data) {
|
||||
super.setData(data);
|
||||
updateParticles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(@NonNull Direction direction) {
|
||||
super.setDirection(direction);
|
||||
updateParticles();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
updateParticles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-computes the particle's based on the data and the direction.
|
||||
*/
|
||||
private void updateParticles() {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
if (data == null || data.length == 0 || width == 0 || height == 0) {
|
||||
particles = null;
|
||||
} else {
|
||||
Direction dir = direction==Direction.VERTICAL?Direction.HORIZONTAL:Direction.VERTICAL;
|
||||
int color = ResourcesCompat.getColor(getResources(), R.color.particle, null);
|
||||
double max = 0;
|
||||
for (int i = 0; i < data.length; i++)
|
||||
max = Math.max(max, data[i]);
|
||||
particles = new Particle[data.length];
|
||||
float cell = (direction == Direction.VERTICAL?height:width) / (float)data.length;
|
||||
float length = (direction == Direction.VERTICAL?width:height) * relativeLength;
|
||||
float size = direction == Direction.VERTICAL?width:height;
|
||||
paint.setStrokeWidth(cell * relativeHeight);
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
RectF rect = direction == Direction.VERTICAL ? new RectF(0, cell * i, size, cell * (i + 1)) :
|
||||
new RectF(cell * i, 0, cell * (i + 1), size);
|
||||
float speed = (float)(speedFactor * data[i]);
|
||||
float tail = (float)(max == 0 ? 0 : (data[i] / max)) * length;
|
||||
particles[i] = new Particle(random, rect, dir, color, speed, tail, randomizeTime);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A single particle that moves into horizontal or vertical direction.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
private static class Particle {
|
||||
|
||||
/** A random number generator to make the particle less predictable. */
|
||||
@NonNull
|
||||
private Random random;
|
||||
|
||||
/** The movement direction (horizontal: left to right, vertical: top to bottom). */
|
||||
@NonNull
|
||||
private Direction direction;
|
||||
|
||||
/** The rectangle in which we draw. */
|
||||
@NonNull
|
||||
private RectF rect;
|
||||
|
||||
/** The current x-position of the particle (head). */
|
||||
private float x;
|
||||
/** The current y-position of the particle (head). */
|
||||
private float y;
|
||||
/** The length of the particle's tail. */
|
||||
private float length;
|
||||
/** The movement speed in pixels per second. */
|
||||
private float speed;
|
||||
/** The time used to randomize restarts. */
|
||||
private int randomize;
|
||||
/** The time when the particle's position was last computed. */
|
||||
private long time;
|
||||
|
||||
/** A gradient to quickly draw the particle. */
|
||||
@NonNull
|
||||
private LinearGradient gradient;
|
||||
/** The translation matrix to avoid object allocations. */
|
||||
@NonNull
|
||||
private Matrix matrix = new Matrix();
|
||||
|
||||
/**
|
||||
* A single particle that moves either vertically or horizontally.
|
||||
*
|
||||
* @param random A random number generator.
|
||||
* @param rect The rectangle in which the particle moves.
|
||||
* @param direction The direction to move (left to right or top to bottom).
|
||||
* @param speed The movement speed in pixels per second.
|
||||
* @param length The length of the tail of the particle.
|
||||
* @param randomize The time used to randomize the restart when the particle moved off the screen.
|
||||
*/
|
||||
public Particle(@NonNull Random random, @NonNull RectF rect, @NonNull Direction direction, int color, float speed, float length, int randomize) {
|
||||
this.random = random;
|
||||
this.direction = direction;
|
||||
this.rect = rect;
|
||||
this.speed = speed;
|
||||
this.length = length;
|
||||
this.randomize = randomize;
|
||||
gradient = new LinearGradient(0, 0,
|
||||
direction == Direction.HORIZONTAL?length:0,
|
||||
direction == Direction.HORIZONTAL?0:length,
|
||||
new int[] { 0x00ffffff, color },
|
||||
new float[] { 0f, 1f}, Shader.TileMode.CLAMP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the particle onto the canvas.
|
||||
*
|
||||
* @param c The canvas.
|
||||
* @param paint The paint to draw with.
|
||||
*/
|
||||
public void draw(Canvas c, Paint paint) {
|
||||
float xs = (direction == Direction.HORIZONTAL)? x - length: x;
|
||||
float ys = (direction == Direction.HORIZONTAL)? y : y - length;
|
||||
matrix.setTranslate(xs, ys);
|
||||
gradient.setLocalMatrix(matrix);
|
||||
paint.setShader(gradient);
|
||||
c.drawLine(xs , ys, x, y, paint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the animation state based on the time.
|
||||
*
|
||||
* @param time The time.
|
||||
*/
|
||||
public void animate(long time) {
|
||||
if (this.time == 0 || isFinished()) {
|
||||
reset(this.time == 0);
|
||||
} else {
|
||||
moveBy(time - this.time);
|
||||
}
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the particle has moved out of sight.
|
||||
*
|
||||
* @return True if it has moved out of sight. False otherwise.
|
||||
*/
|
||||
private boolean isFinished() {
|
||||
if (direction == Direction.HORIZONTAL) {
|
||||
return x - length > rect.right;
|
||||
} else {
|
||||
return y - length > rect.bottom;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the particle to a new initial position.
|
||||
*
|
||||
* @param init True, if the positions shall be randomly distributed.
|
||||
*/
|
||||
private void reset(boolean init) {
|
||||
float movement = random.nextInt(randomize) / 1000f * speed;
|
||||
if (direction == Direction.HORIZONTAL) {
|
||||
x = rect.left - movement + (init?rect.width() * random.nextFloat():0);
|
||||
y = rect.top + (rect.bottom - rect.top) * 0.5f;
|
||||
} else {
|
||||
x = rect.left + (rect.right - rect.left) * 0.5f;
|
||||
y = rect.top - movement + (init?rect.height() * random.nextFloat():0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the particle depending on the time passed.
|
||||
*
|
||||
* @param delta The time passed in milliseconds.
|
||||
*/
|
||||
private void moveBy(long delta) {
|
||||
float movement = delta / 1000f * speed;
|
||||
if (direction == Direction.HORIZONTAL) {
|
||||
x += movement;
|
||||
} else {
|
||||
y += movement;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
package com.mowesta.android.app.view;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import com.mowesta.android.app.R;
|
||||
import com.mowesta.android.app.util.TimeUtils;
|
||||
|
||||
/**
|
||||
* The view to display the time and to handle touch events.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class TimeView extends DataView<Long> {
|
||||
|
||||
/**
|
||||
* An interface for listeners that want to be
|
||||
* informed about touch events.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public interface OnSlideListener {
|
||||
|
||||
/**
|
||||
* Called when there is a slide event on the view at
|
||||
* the specified relative position.
|
||||
*
|
||||
* @param relative The relative position (0 to 1).
|
||||
*/
|
||||
void onSlide(float relative);
|
||||
|
||||
|
||||
void onSlideEnd();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A listener to handle the touch events on the view.
|
||||
*
|
||||
*/
|
||||
private static class TouchListener implements View.OnTouchListener {
|
||||
|
||||
/** The epsilon to ignore duplicate events. */
|
||||
private float EPSILON = 0.0001f;
|
||||
|
||||
/** The time view that is observed by this listener. */
|
||||
private TimeView view;
|
||||
|
||||
/** A cache for the view position.*/
|
||||
private int[] viewPosition = new int[2];
|
||||
|
||||
/**
|
||||
* If down, the id of the pointer that we are tracking.
|
||||
*/
|
||||
private int id = 0;
|
||||
|
||||
/**
|
||||
* A boolean to memorize whether we already saw a finger going down.
|
||||
*/
|
||||
private boolean down = false;
|
||||
|
||||
/**
|
||||
* The last relative position that we saw.
|
||||
*/
|
||||
private float position = 0;
|
||||
|
||||
@NonNull
|
||||
private OnSlideListener listener;
|
||||
|
||||
public TouchListener(@NonNull TimeView view, @NonNull OnSlideListener listener) {
|
||||
this.view = view;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
updateViewPosition();
|
||||
int index = event.getActionIndex();
|
||||
int mask = event.getActionMasked();
|
||||
boolean onView = isOnView(event);
|
||||
switch (mask) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
if (! down && onView) {
|
||||
down = true;
|
||||
id = event.getPointerId(index);
|
||||
position = getPosition(event);
|
||||
listener.onSlide(position);
|
||||
};
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (down && id == event.getPointerId(index)) {
|
||||
float np = getPosition(event);
|
||||
if (Math.abs(np - position) > EPSILON) {
|
||||
position = np;
|
||||
listener.onSlide(position);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (down && id == event.getPointerId(index)) {
|
||||
down = false;
|
||||
listener.onSlideEnd();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return down;
|
||||
}
|
||||
|
||||
private void updateViewPosition() {
|
||||
view.getLocationOnScreen(viewPosition);
|
||||
}
|
||||
|
||||
private float getPosition(MotionEvent event) {
|
||||
if (view.getDirection() == Direction.HORIZONTAL) {
|
||||
if (view.getWidth() == 0) return 0;
|
||||
float x = event.getRawX();
|
||||
return Math.min(1, Math.max(0, (x - viewPosition[0]) / view.getWidth()));
|
||||
} else {
|
||||
if (view.getHeight() == 0) return 0;
|
||||
float y = event.getRawY();
|
||||
return Math.min(1, Math.max(0, (y - viewPosition[1]) / view.getHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOnView(MotionEvent event) {
|
||||
float x = event.getRawX();
|
||||
float y = event.getRawY();
|
||||
return x >= viewPosition[0] && x < viewPosition[0] + view.getWidth()
|
||||
&& y >= viewPosition[1] && y < viewPosition[1] + view.getHeight();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The timezone.
|
||||
*/
|
||||
private String timezone;
|
||||
|
||||
/**
|
||||
* The positions to draw lines.
|
||||
*/
|
||||
private float[] positions;
|
||||
|
||||
/**
|
||||
* The lengths of the lines at the positions.
|
||||
*/
|
||||
private float[] lengths;
|
||||
|
||||
/**
|
||||
* The paint to draw the lines.
|
||||
*/
|
||||
private Paint paint = new Paint();
|
||||
|
||||
/**
|
||||
* The paint to draw the current time.
|
||||
*/
|
||||
private Paint paintNow = new Paint();
|
||||
|
||||
/**
|
||||
* The circle animation.
|
||||
*/
|
||||
private TouchCircleAnimation animation = new TouchCircleAnimation(this);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public TimeView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
*/
|
||||
public TimeView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The default attributes.
|
||||
*/
|
||||
public TimeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new view.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param attrs The attributes.
|
||||
* @param defStyleAttr The default attributes.
|
||||
* @param defStyleRes The default style.
|
||||
*/
|
||||
@TargetApi(21)
|
||||
public TimeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the view.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
private void init(Context context) {
|
||||
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||
paint.setStrokeWidth((int)(1f * displayMetrics.density + .5f));
|
||||
paint.setColor(ResourcesCompat.getColor(context.getResources(), R.color.inverse, null));
|
||||
paint.setAntiAlias(true);
|
||||
paintNow.setStrokeWidth((int)(2f * displayMetrics.density + .5f));
|
||||
paintNow.setColor(ResourcesCompat.getColor(context.getResources(), R.color.primary, null));
|
||||
paintNow.setAntiAlias(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an touch listener for this view.
|
||||
*
|
||||
* @param listener The listener to keep track of events.
|
||||
* @return The touch listener.
|
||||
*/
|
||||
public View.OnTouchListener createOnTouchListener(@NonNull OnSlideListener listener) {
|
||||
return new TouchListener(this, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timezone to draw the hours.
|
||||
*
|
||||
* @param timezone The timezone.
|
||||
*/
|
||||
public void setTimezone(String timezone) {
|
||||
this.timezone = timezone;
|
||||
updateTimes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time zone.
|
||||
*
|
||||
* @return The timezone.
|
||||
*/
|
||||
public String getTimezone() {
|
||||
return timezone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(@Nullable Long[] data) {
|
||||
super.setData(data);
|
||||
updateTimes();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
updateTimes();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDrawData(long time, Canvas canvas) {
|
||||
animation.animate(time);
|
||||
animation.draw(canvas);
|
||||
if (positions != null) {
|
||||
// draw now
|
||||
for (int i = 1; i < data.length; i++) {
|
||||
if (time > data[i - 1] && time <= data[i]) {
|
||||
float fraction = (data[i] - time) / (data[i] - data[i - 1]);
|
||||
float pos = (direction == Direction.VERTICAL?getHeight():getWidth()) * (i + fraction) / data.length;
|
||||
float end = direction == Direction.VERTICAL?getWidth():getHeight();
|
||||
if (direction == Direction.VERTICAL) {
|
||||
canvas.drawLine(0, pos, end, pos, paintNow);
|
||||
} else {
|
||||
canvas.drawLine(pos, 0, pos, end, paintNow);
|
||||
}
|
||||
}
|
||||
}
|
||||
// draw grid
|
||||
float center = (direction == Direction.VERTICAL?getWidth():getHeight()) / 2f;
|
||||
for (int i = 0; i < positions.length; i++) {
|
||||
float xs = direction == Direction.VERTICAL?center - .5f * lengths[i]:positions[i];
|
||||
float xe = direction == Direction.VERTICAL?center + .5f * lengths[i]:positions[i];
|
||||
float ys = direction == Direction.HORIZONTAL?center - .5f * lengths[i]:positions[i];
|
||||
float ye = direction == Direction.HORIZONTAL?center + .5f * lengths[i]:positions[i];
|
||||
canvas.drawLine(xs, ys, xe, ye, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTimes() {
|
||||
if (data == null || data.length == 0) {
|
||||
lengths = null;
|
||||
positions = null;
|
||||
} else {
|
||||
int[] hours = new int[data.length];
|
||||
TimeUtils time = new TimeUtils(System.currentTimeMillis(), timezone);
|
||||
int ranges = 0;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
hours[i] = time.getHour(data[i]);
|
||||
if (hours[i] % 6 == 0) {
|
||||
ranges += 1;
|
||||
}
|
||||
}
|
||||
positions = new float[ranges];
|
||||
lengths = new float[ranges];
|
||||
int index = 0;
|
||||
int total = direction == Direction.VERTICAL?getHeight():getWidth();
|
||||
int max = direction == Direction.VERTICAL?getWidth():getHeight();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
if (hours[i] % 6 == 0) {
|
||||
positions[index] = ((float)total / data.length) * (i + .5f);
|
||||
lengths[index] = hours[i] == 0 ? (max * .75f): (max * 0.25f);
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class TouchCircleAnimation {
|
||||
|
||||
/** The center of the click. */
|
||||
float cx, cy;
|
||||
/** The animated radius. */
|
||||
float radius;
|
||||
/** The animated alpha value. */
|
||||
float alpha;
|
||||
/** The speed at which the circle expands. */
|
||||
float expand = 500;
|
||||
/**
|
||||
* The speed at which the alpha value decays.
|
||||
*/
|
||||
float fade = 2f;
|
||||
/** The Animation time. */
|
||||
long time = 0;
|
||||
/** The number of repeatitions. */
|
||||
int repeat = 0;
|
||||
/** A boolean to indicate when done. */
|
||||
boolean done = false;
|
||||
/** The paint to draw. */
|
||||
Paint paint = new Paint();
|
||||
/** The view. */
|
||||
DataView<?> view;
|
||||
/** The finger drawable. */
|
||||
Drawable touch;
|
||||
|
||||
public TouchCircleAnimation(DataView<?> view) {
|
||||
this.view = view;
|
||||
this.touch = AppCompatResources.getDrawable(view.getContext(), R.drawable.ic_touch_app_normal_24);
|
||||
paint.setColor(ResourcesCompat.getColor(view.getResources(), R.color.accent, null));
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
}
|
||||
|
||||
|
||||
public void animate(long now) {
|
||||
if (time == 0) {
|
||||
reset();
|
||||
} else {
|
||||
updateBy(now - time);
|
||||
if (alpha < 0) {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
time = now;
|
||||
done = repeat > 3;
|
||||
}
|
||||
|
||||
private void updateBy(long delta) {
|
||||
float dx = delta / 1000f;
|
||||
alpha -= dx * fade;
|
||||
radius += dx * expand;
|
||||
}
|
||||
|
||||
|
||||
public void draw(Canvas c) {
|
||||
if (!done) {
|
||||
if (repeat > 1) {
|
||||
int a = (int)Math.min(255, Math.max(0, 255 * alpha));
|
||||
paint.setAlpha(Math.min(255, a + 128));
|
||||
c.drawCircle(cx, cy, radius, paint);
|
||||
touch.setAlpha(a);
|
||||
touch.draw(c);
|
||||
}
|
||||
postInvalidateOnAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void reset() {
|
||||
cx = getWidth() / 2;
|
||||
cy = getHeight() / 2;
|
||||
if (view.direction == Direction.VERTICAL) {
|
||||
cy = cy / 2f;
|
||||
}
|
||||
int padding = (int)(Math.min(getWidth(), getHeight()) * 0.1f);
|
||||
int size = Math.min(getWidth(), getHeight()) / 2 - padding;
|
||||
touch.setBounds((int)cx - size, (int)cy - size, (int)cx + size, (int) cy + size);
|
||||
radius = 1;
|
||||
alpha = 1;
|
||||
repeat += 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A color scheme for the cloud depth.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class CloudDepthColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* The list of supports.
|
||||
*/
|
||||
private static List<ColorSupport> SUPPORT = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SUPPORT.add(new ColorSupport(0, 0x00FFFFFF));
|
||||
SUPPORT.add(new ColorSupport(1, 0xFF999999));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new color scheme to render the cloud depth.
|
||||
*/
|
||||
public CloudDepthColorScheme() {
|
||||
super(SUPPORT, new LinearInterpolation());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The color scheme for relative humidity.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class HumidityColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* The support vector with the temperature to color mapping.
|
||||
*/
|
||||
private static List<ColorSupport> SUPPORT = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SUPPORT.add(new ColorSupport(0, 0x0042BAD0));
|
||||
SUPPORT.add(new ColorSupport(100, 0xFF42BAD0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color scheme.
|
||||
*/
|
||||
public HumidityColorScheme() {
|
||||
super(SUPPORT, new LinearInterpolation());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
/**
|
||||
* A color scheme is responsible for mapping a data
|
||||
* value to an ARGB color.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public interface IColorScheme {
|
||||
|
||||
/**
|
||||
* Returns the color for the data value.
|
||||
*
|
||||
* @param value The data value.
|
||||
* @return The ARGB value with 8 bit resolution.
|
||||
*/
|
||||
int getColor(double value);
|
||||
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.IDataInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A color scheme for temperature given in degrees Kelvin.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class InterpolatedColorScheme implements IColorScheme {
|
||||
|
||||
/**
|
||||
* A support point that defines the color for a particular value.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public static class ColorSupport implements Comparable<ColorSupport> {
|
||||
|
||||
/**
|
||||
* The value.
|
||||
*/
|
||||
protected double value;
|
||||
/**
|
||||
* The red component.
|
||||
*/
|
||||
protected int red;
|
||||
/**
|
||||
* The green component (0 - 255).
|
||||
*/
|
||||
protected int green;
|
||||
/**
|
||||
* The blue component.
|
||||
*/
|
||||
protected int blue;
|
||||
/**
|
||||
* The alpha component.
|
||||
*/
|
||||
protected int alpha;
|
||||
|
||||
/**
|
||||
* Creates the support for the specified color.
|
||||
*
|
||||
* @param value The value that should exhibit the color.
|
||||
* @param argb The color value.
|
||||
*/
|
||||
public ColorSupport(double value, int argb) {
|
||||
this(value, (argb >> 24) & 0xff, (argb >> 16) & 0xff, (argb >> 8) & 0xff, argb & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new support at a particular value.
|
||||
*
|
||||
* @param value The data value that should exhibit the color.
|
||||
* @param a The alpha value.
|
||||
* @param r The red value.
|
||||
* @param g The green value.
|
||||
* @param b The blue value.
|
||||
*/
|
||||
public ColorSupport(double value, int a, int r, int g, int b) {
|
||||
this.value = value;
|
||||
this.alpha = a & 0xff;
|
||||
this.red = r & 0xff;
|
||||
this.green = g & 0xff;
|
||||
this.blue = b & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color as ARGB int.
|
||||
*
|
||||
* @return The color as ARGB int.
|
||||
*/
|
||||
public int getColor() {
|
||||
return alpha << 24 | red << 16 | green << 8 | blue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blue component (0-255).
|
||||
*
|
||||
* @return The blue component.
|
||||
*/
|
||||
public int getRed() {
|
||||
return red;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blue component (0-255).
|
||||
*
|
||||
* @return The blue component.
|
||||
*/
|
||||
public int getGreen() {
|
||||
return green;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blue component (0-255).
|
||||
*
|
||||
* @return The blue component.
|
||||
*/
|
||||
public int getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blue component (0-255).
|
||||
*
|
||||
* @return The blue component.
|
||||
*/
|
||||
public int getBlue() {
|
||||
return blue;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(ColorSupport o) {
|
||||
return Double.compare(value, o.value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The supporting points.
|
||||
*/
|
||||
protected List<ColorSupport> supports;
|
||||
/**
|
||||
* The interpolation strategy.
|
||||
*/
|
||||
protected IDataInterpolation interpolation;
|
||||
|
||||
/**
|
||||
* Creates an interpolated color scheme.
|
||||
*
|
||||
* @param supports The supports.
|
||||
* @param interpolation The interpolation strategy.
|
||||
*/
|
||||
public InterpolatedColorScheme(List<ColorSupport> supports, IDataInterpolation interpolation) {
|
||||
if (supports.isEmpty()) throw new IllegalArgumentException("At least one color support point must be specified.");
|
||||
this.supports = new ArrayList<>(supports);
|
||||
this.interpolation = interpolation;
|
||||
Collections.sort(supports);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getColor(double data) {
|
||||
// data is smaller than any support, return lowest support color
|
||||
if (data < supports.get(0).getValue()) return supports.get(0).getColor();
|
||||
for (int i = 1; i < supports.size(); i++) {
|
||||
if (supports.get(i).getValue() > data) {
|
||||
return getColor(supports.get(i - 1), supports.get(i), data);
|
||||
}
|
||||
}
|
||||
// data is larger than any support, return highest support color
|
||||
return supports.get(supports.size() - 1).getColor();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the interpolated color for the value.
|
||||
*
|
||||
* @param from The lower support.
|
||||
* @param to The higher support.
|
||||
* @param value The data value.
|
||||
* @return The interpolated color.
|
||||
*/
|
||||
private int getColor(ColorSupport from, ColorSupport to, double value) {
|
||||
double fraction = (value - from.getValue()) / (double)(to.getValue() - from.getValue());
|
||||
int alpha = getColor(from.getAlpha(), to.getAlpha(), fraction);
|
||||
int red = getColor(from.getRed(), to.getRed(), fraction);
|
||||
int green = getColor(from.getGreen(), to.getGreen(), fraction);
|
||||
int blue = getColor(from.getBlue(), to.getBlue(), fraction);
|
||||
return alpha << 24 | red << 16 | green << 8 | blue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the interpolated color value and ensures that it
|
||||
* lies within the target bounds.
|
||||
*
|
||||
* @param from The start color value.
|
||||
* @param to The to color value.
|
||||
* @param fraction The fraction between from and to.
|
||||
* @return The color value.
|
||||
*/
|
||||
private int getColor(int from, int to, double fraction) {
|
||||
double r = interpolation.interpolate(from, to, fraction);
|
||||
return Math.min(255, Math.max(0, (int)Math.round(r)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The color scheme for precipitation (rain, snow, etc.).
|
||||
* @author Marcus
|
||||
*
|
||||
*/
|
||||
public class PrecipitationColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* The support vector with the temperature to color mapping.
|
||||
*/
|
||||
private static List<ColorSupport> SUPPORT = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SUPPORT.add(new ColorSupport(0, 0x0000000));
|
||||
SUPPORT.add(new ColorSupport(0.1, 0x88008800));
|
||||
SUPPORT.add(new ColorSupport(1, 0xFF00FF00)); // Nieselregen (<1)
|
||||
SUPPORT.add(new ColorSupport(10, 0xFF00FFFF));
|
||||
SUPPORT.add(new ColorSupport(20, 0xFF0000FF)); // Starkregen (>20)
|
||||
SUPPORT.add(new ColorSupport(20, 0xFF880000));
|
||||
SUPPORT.add(new ColorSupport(35, 0xFFFF0000)); // Unwetter (>35)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color scheme.
|
||||
*/
|
||||
public PrecipitationColorScheme() {
|
||||
super(SUPPORT, new LinearInterpolation());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A color scheme that makes low pressure zones blue and high
|
||||
* pressure zones red.
|
||||
*
|
||||
* @author Marcus
|
||||
*
|
||||
*/
|
||||
public class PressureColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* Creates a pressure color scheme.
|
||||
*
|
||||
* @param avg The average value.
|
||||
* @param min The minimum value.
|
||||
* @param max The maximum value.
|
||||
*/
|
||||
public PressureColorScheme(double avg, double min, double max) {
|
||||
super(createSupport(avg, min, max), new LinearInterpolation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the support for the color scheme based on the average,
|
||||
* minimum and maximum values.
|
||||
*
|
||||
* @param avg The average.
|
||||
* @param min The minimum.
|
||||
* @param max The maximum.
|
||||
* @return The support for the scheme.
|
||||
*/
|
||||
private static List<ColorSupport> createSupport(double avg, double min, double max) {
|
||||
List<ColorSupport> result = new ArrayList<>();
|
||||
result.add(new ColorSupport(min, 255, 0, 0, 0));
|
||||
result.add(new ColorSupport(avg, 255, 0, 0, 255));
|
||||
result.add(new ColorSupport(max, 255, 255, 0, 255));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.IDataInterpolation;
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
import com.mowesta.android.app.view.interpolation.StepInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A color scheme that is extracted from the climate charts of DWD.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class ScientificTemperatureColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* The support vector with the temperature to color mapping.
|
||||
*/
|
||||
private static List<ColorSupport> SUPPORT = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SUPPORT.add(new ColorSupport(-35, 0xFF0000FB));
|
||||
SUPPORT.add(new ColorSupport(-30, 0xFF2E46FF));
|
||||
SUPPORT.add(new ColorSupport(-25, 0xFF3974FF));
|
||||
SUPPORT.add(new ColorSupport(-20, 0xFF39A9FF));
|
||||
SUPPORT.add(new ColorSupport(-15, 0xFF29DBFF));
|
||||
SUPPORT.add(new ColorSupport(-10, 0xFF30FFEF));
|
||||
SUPPORT.add(new ColorSupport(-5, 0xFF88FFBE));
|
||||
SUPPORT.add(new ColorSupport(0, 0xFFB6FE8E));
|
||||
SUPPORT.add(new ColorSupport(0, 0xFFFFFF00));
|
||||
SUPPORT.add(new ColorSupport(5, 0xFFDAFF61));
|
||||
SUPPORT.add(new ColorSupport(10, 0xFFF8FF26));
|
||||
SUPPORT.add(new ColorSupport(15, 0xFFFEE100));
|
||||
SUPPORT.add(new ColorSupport(20, 0xFFFFB200));
|
||||
SUPPORT.add(new ColorSupport(25, 0xFFFE8500));
|
||||
SUPPORT.add(new ColorSupport(30, 0xFFFF5100));
|
||||
SUPPORT.add(new ColorSupport(35, 0xFFB30000));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color scheme with linear interpolation.
|
||||
*/
|
||||
public ScientificTemperatureColorScheme() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color scheme with linear or step-wise interpolation.
|
||||
*
|
||||
* @param linearInterpolation If set to true, enables linear interpolation.
|
||||
*/
|
||||
public ScientificTemperatureColorScheme(boolean linearInterpolation) {
|
||||
super(SUPPORT, linearInterpolation?new LinearInterpolation():new StepInterpolation(1f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a colors scheme with the specified interpolation.
|
||||
*
|
||||
* @param interpolation The interpolation function.
|
||||
*/
|
||||
public ScientificTemperatureColorScheme(IDataInterpolation interpolation) {
|
||||
super(SUPPORT, interpolation);
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.mowesta.android.app.view.color;
|
||||
|
||||
import com.mowesta.android.app.view.interpolation.LinearInterpolation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A color scheme for the cloud coverage provided as a value between 0 and 1.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class WhiteCloudColorScheme extends InterpolatedColorScheme {
|
||||
|
||||
/**
|
||||
* The support vector with the temperature to color mapping.
|
||||
*/
|
||||
private static List<ColorSupport> SUPPORT = new ArrayList<>();
|
||||
|
||||
static {
|
||||
SUPPORT.add(new ColorSupport(0, 0x00FFFFFF));
|
||||
SUPPORT.add(new ColorSupport(1, 0xFFFFFFFF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a color scheme with linear interpolation.
|
||||
*/
|
||||
public WhiteCloudColorScheme() {
|
||||
super(SUPPORT, new LinearInterpolation());
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.mowesta.android.app.view.interpolation;
|
||||
|
||||
/**
|
||||
* An interface to interpolate data.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public interface IDataInterpolation {
|
||||
|
||||
/**
|
||||
* Computes an interpolated value between x and y that
|
||||
* resides at the specified fraction.
|
||||
*
|
||||
* @param x The x value.
|
||||
* @param y The y value.
|
||||
* @param fraction The fraction (between 0 = x and 1 = y).
|
||||
* @return The interpolated value.
|
||||
*/
|
||||
double interpolate(double x, double y, double fraction);
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.mowesta.android.app.view.interpolation;
|
||||
|
||||
/**
|
||||
* A simple linear interpolation.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class LinearInterpolation implements IDataInterpolation {
|
||||
|
||||
@Override
|
||||
public double interpolate(double x, double y, double fraction) {
|
||||
return x + (y - x) * fraction;
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.mowesta.android.app.view.interpolation;
|
||||
|
||||
/**
|
||||
* An interpolation that does not compute intermediate values but
|
||||
* instead bases its decision on which value to return on the fraction,
|
||||
* creating a step function.
|
||||
*
|
||||
* @author Marcus
|
||||
*/
|
||||
public class StepInterpolation implements IDataInterpolation {
|
||||
|
||||
/**
|
||||
* The default threshold value that results in financial rounding.
|
||||
*/
|
||||
public static final double DEFAULT_THRESHOLD = 0.5;
|
||||
|
||||
/**
|
||||
* The threshold at which to switch.
|
||||
*/
|
||||
private double threshold;
|
||||
|
||||
/**
|
||||
* Creates an interpolation function with the default threshold.
|
||||
*/
|
||||
public StepInterpolation() {
|
||||
this(DEFAULT_THRESHOLD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new step interpolation with the specified
|
||||
* threshold.
|
||||
*
|
||||
* @param threshold The threshold that defines which
|
||||
* value to return.
|
||||
*/
|
||||
public StepInterpolation(double threshold) {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double interpolate(double x, double y, double fraction) {
|
||||
if (fraction < threshold) return x;
|
||||
else return y;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<gradient
|
||||
android:angle="0"
|
||||
android:endColor="#f8e9cf"
|
||||
android:centerColor="#ffffff"
|
||||
android:startColor="#f8e9cf"
|
||||
android:type="linear" />
|
||||
|
||||
</shape>
|
||||
@@ -0,0 +1,18 @@
|
||||
<vector android:height="24dp" android:viewportHeight="1576.68"
|
||||
android:viewportWidth="1576.68" android:width="24dp"
|
||||
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:pathData="M788.34,788.34m-784.54,0a784.54,784.54 0,1 1,1569.08 0a784.54,784.54 0,1 1,-1569.08 0">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:startX="1577"
|
||||
android:startY="0"
|
||||
android:endX="0"
|
||||
android:endY="1577"
|
||||
android:startColor="#aaaaaaaa"
|
||||
android:endColor="#00ffffff"
|
||||
android:type="linear">
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path android:fillColor="#eeFFFFFF" android:pathData="M932.1,185.17c135.76,82 339.41,251.63 439.96,406.9 100.54,155.27 97.98,296.16 78.45,397.05 -19.53,100.88 -56.04,161.74 -83.9,133.57 -27.86,-28.18 -47.07,-145.4 -112.07,-279.53 -65,-134.13 -175.78,-285.17 -282.41,-409.44 -106.63,-124.27 -209.09,-221.77 -226.38,-273.33 -17.3,-51.57 50.59,-57.2 186.36,24.8z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:viewportHeight="30"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="30" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M4.61,16.88c0,-1.15 0.36,-2.17 1.08,-3.07c0.72,-0.9 1.63,-1.48 2.74,-1.73c0.31,-1.37 1.02,-2.49 2.11,-3.37s2.35,-1.32 3.76,-1.32c1.38,0 2.61,0.43 3.69,1.28s1.78,1.95 2.1,3.29h0.33c0.9,0 1.73,0.22 2.49,0.65s1.37,1.03 1.81,1.79c0.44,0.76 0.67,1.58 0.67,2.48c0,0.88 -0.21,1.7 -0.63,2.45s-1,1.35 -1.73,1.8c-0.73,0.45 -1.54,0.69 -2.41,0.72H9.41c-1.34,-0.06 -2.47,-0.57 -3.4,-1.53C5.08,19.37 4.61,18.22 4.61,16.88zM6.32,16.88c0,0.87 0.3,1.62 0.9,2.26s1.33,0.98 2.19,1.03h11.19c0.86,-0.04 1.59,-0.39 2.19,-1.03c0.61,-0.64 0.91,-1.4 0.91,-2.26c0,-0.88 -0.33,-1.63 -0.98,-2.27c-0.65,-0.64 -1.42,-0.96 -2.32,-0.96H18.8c-0.11,0 -0.17,-0.06 -0.17,-0.18l-0.07,-0.57c-0.11,-1.08 -0.58,-1.99 -1.4,-2.72c-0.82,-0.73 -1.77,-1.1 -2.86,-1.1c-1.09,0 -2.05,0.37 -2.85,1.1c-0.81,0.73 -1.27,1.64 -1.37,2.72l-0.08,0.57c0,0.12 -0.07,0.18 -0.2,0.18H9.27c-0.84,0.1 -1.54,0.46 -2.1,1.07S6.32,16.05 6.32,16.88z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:viewportHeight="30"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="30" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M7.56,17.19c0,-0.88 0.24,-1.89 0.72,-3.03s1.1,-2.25 1.86,-3.31c1.56,-2.06 2.92,-3.62 4.06,-4.67l0.75,-0.72c0.25,0.26 0.53,0.5 0.83,0.72c0.41,0.42 1.04,1.11 1.88,2.09s1.57,1.85 2.17,2.65c0.71,1.01 1.32,2.1 1.81,3.25s0.74,2.16 0.74,3.03c0,1 -0.19,1.95 -0.58,2.86c-0.39,0.91 -0.91,1.7 -1.57,2.36c-0.66,0.66 -1.45,1.19 -2.37,1.58c-0.92,0.39 -1.89,0.59 -2.91,0.59c-1,0 -1.95,-0.19 -2.86,-0.57c-0.91,-0.38 -1.7,-0.89 -2.36,-1.55c-0.66,-0.65 -1.19,-1.44 -1.58,-2.35S7.56,18.23 7.56,17.19zM9.82,14.26c0,0.83 0.17,1.49 0.52,1.99c0.35,0.49 0.88,0.74 1.59,0.74c0.72,0 1.25,-0.25 1.61,-0.74c0.35,-0.49 0.53,-1.15 0.54,-1.99c-0.01,-0.84 -0.19,-1.5 -0.54,-2c-0.35,-0.49 -0.89,-0.74 -1.61,-0.74c-0.71,0 -1.24,0.25 -1.59,0.74C9.99,12.76 9.82,13.42 9.82,14.26zM11.39,14.26c0,-0.15 0,-0.27 0,-0.35s0.01,-0.19 0.02,-0.33c0.01,-0.14 0.02,-0.25 0.05,-0.32s0.05,-0.16 0.09,-0.24c0.04,-0.08 0.09,-0.15 0.15,-0.18c0.07,-0.04 0.14,-0.06 0.23,-0.06c0.14,0 0.25,0.04 0.33,0.12s0.14,0.21 0.17,0.38c0.03,0.18 0.05,0.32 0.06,0.45s0.01,0.3 0.01,0.52c0,0.23 0,0.4 -0.01,0.52c-0.01,0.12 -0.03,0.27 -0.06,0.45c-0.03,0.17 -0.09,0.3 -0.17,0.38s-0.19,0.12 -0.33,0.12c-0.09,0 -0.16,-0.02 -0.23,-0.06c-0.07,-0.04 -0.12,-0.1 -0.15,-0.18c-0.04,-0.08 -0.07,-0.17 -0.09,-0.24c-0.02,-0.08 -0.04,-0.19 -0.05,-0.32c-0.01,-0.14 -0.02,-0.25 -0.02,-0.32S11.39,14.41 11.39,14.26zM11.98,22.01h1.32l4.99,-10.74h-1.35L11.98,22.01zM16.28,19.02c0.01,0.84 0.2,1.5 0.55,2c0.35,0.49 0.89,0.74 1.6,0.74c0.72,0 1.25,-0.25 1.6,-0.74c0.35,-0.49 0.52,-1.16 0.53,-2c-0.01,-0.84 -0.18,-1.5 -0.53,-1.99c-0.35,-0.49 -0.88,-0.74 -1.6,-0.74c-0.71,0 -1.25,0.25 -1.6,0.74C16.47,17.52 16.29,18.18 16.28,19.02zM17.85,19.02c0,-0.23 0,-0.4 0.01,-0.52c0.01,-0.12 0.03,-0.27 0.06,-0.45s0.09,-0.3 0.17,-0.38s0.19,-0.12 0.33,-0.12c0.09,0 0.17,0.02 0.24,0.06c0.07,0.04 0.12,0.1 0.16,0.19c0.04,0.09 0.07,0.17 0.1,0.24s0.04,0.18 0.05,0.32l0.01,0.32l0,0.34c0,0.16 0,0.28 0,0.35l-0.01,0.32l-0.05,0.32l-0.1,0.24l-0.16,0.19l-0.24,0.06c-0.14,0 -0.25,-0.04 -0.33,-0.12s-0.14,-0.21 -0.17,-0.38c-0.03,-0.18 -0.05,-0.33 -0.06,-0.45S17.85,19.25 17.85,19.02z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:viewportHeight="30"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="30" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M11.01,12.23c0,-0.26 0.13,-0.59 0.38,-1.01c0.25,-0.42 0.5,-0.77 0.73,-1.04c0.06,-0.07 0.14,-0.17 0.23,-0.28s0.15,-0.17 0.16,-0.18l0.37,0.43c0.28,0.31 0.53,0.66 0.76,1.07c0.23,0.41 0.35,0.74 0.35,1.01c0,0.41 -0.14,0.77 -0.43,1.06c-0.28,0.29 -0.63,0.44 -1.05,0.44c-0.41,0 -0.77,-0.15 -1.06,-0.44C11.16,12.99 11.01,12.64 11.01,12.23zM14.13,16.38c0,-0.29 0.08,-0.62 0.24,-1.01c0.16,-0.38 0.36,-0.74 0.6,-1.06c0.46,-0.61 0.89,-1.12 1.31,-1.53c0.04,-0.03 0.13,-0.11 0.26,-0.24l0.25,0.24c0.39,0.37 0.83,0.88 1.32,1.52c0.26,0.34 0.46,0.7 0.62,1.08s0.24,0.71 0.24,1c0,0.69 -0.23,1.26 -0.7,1.73c-0.47,0.47 -1.05,0.7 -1.73,0.7c-0.68,0 -1.25,-0.24 -1.72,-0.71S14.13,17.05 14.13,16.38zM15.65,9.48c0,-0.43 0.33,-1 1,-1.7l0.25,0.28c0.19,0.22 0.36,0.46 0.51,0.74c0.15,0.27 0.23,0.5 0.23,0.68c0,0.28 -0.1,0.5 -0.29,0.69c-0.19,0.18 -0.42,0.28 -0.7,0.28c-0.29,0 -0.53,-0.09 -0.72,-0.28C15.75,9.98 15.65,9.75 15.65,9.48z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="@color/primary">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M9,11.24V7.5C9,6.12 10.12,5 11.5,5S14,6.12 14,7.5v3.74c1.21,-0.81 2,-2.18 2,-3.74C16,5.01 13.99,3 11.5,3S7,5.01 7,7.5C7,9.06 7.79,10.43 9,11.24zM18.84,15.87l-4.54,-2.26c-0.17,-0.07 -0.35,-0.11 -0.54,-0.11H13v-6C13,6.67 12.33,6 11.5,6S10,6.67 10,7.5v10.74c-3.6,-0.76 -3.54,-0.75 -3.67,-0.75c-0.31,0 -0.59,0.13 -0.79,0.33l-0.79,0.8l4.94,4.94C9.96,23.83 10.34,24 10.75,24h6.79c0.75,0 1.33,-0.55 1.44,-1.28l0.75,-5.27c0.01,-0.07 0.02,-0.14 0.02,-0.2C19.75,16.63 19.37,16.09 18.84,15.87z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:viewportHeight="30"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="30" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M3.1,16.97c0,0.24 0.09,0.45 0.28,0.62c0.16,0.19 0.37,0.28 0.63,0.28H18.7c0.29,0 0.53,0.1 0.73,0.3c0.2,0.2 0.3,0.45 0.3,0.74c0,0.29 -0.1,0.53 -0.3,0.72c-0.2,0.19 -0.44,0.29 -0.74,0.29c-0.29,0 -0.54,-0.1 -0.73,-0.29c-0.16,-0.18 -0.36,-0.26 -0.6,-0.26c-0.25,0 -0.46,0.09 -0.64,0.26s-0.27,0.38 -0.27,0.61c0,0.25 0.09,0.46 0.28,0.63c0.56,0.55 1.22,0.83 1.96,0.83c0.78,0 1.45,-0.27 2.01,-0.81c0.56,-0.54 0.83,-1.19 0.83,-1.97s-0.28,-1.44 -0.84,-2c-0.56,-0.56 -1.23,-0.84 -2,-0.84H4.01c-0.25,0 -0.46,0.09 -0.64,0.26C3.19,16.51 3.1,16.72 3.1,16.97zM3.1,13.69c0,0.23 0.09,0.43 0.28,0.61c0.17,0.18 0.38,0.26 0.63,0.26h20.04c0.78,0 1.45,-0.27 2.01,-0.82c0.56,-0.54 0.84,-1.2 0.84,-1.97c0,-0.77 -0.28,-1.44 -0.84,-1.99s-1.23,-0.83 -2.01,-0.83c-0.77,0 -1.42,0.27 -1.95,0.8c-0.18,0.16 -0.27,0.38 -0.27,0.67c0,0.26 0.09,0.47 0.26,0.63c0.17,0.16 0.38,0.24 0.63,0.24c0.24,0 0.45,-0.08 0.63,-0.24c0.19,-0.21 0.42,-0.31 0.7,-0.31c0.29,0 0.53,0.1 0.73,0.3c0.2,0.2 0.3,0.44 0.3,0.73c0,0.29 -0.1,0.53 -0.3,0.72c-0.2,0.19 -0.44,0.29 -0.73,0.29H4.01c-0.25,0 -0.46,0.09 -0.64,0.26C3.19,13.23 3.1,13.44 3.1,13.69z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@android:id/background">
|
||||
<color android:color="#33363636" />
|
||||
</item>
|
||||
<item android:id="@android:id/progress">
|
||||
<clip
|
||||
android:clipOrientation="vertical"
|
||||
android:gravity="bottom">
|
||||
<shape>
|
||||
<gradient
|
||||
android:startColor="#f9a825"
|
||||
android:centerColor="#f9a825"
|
||||
android:endColor="#f9a825"
|
||||
android:angle="90" />
|
||||
</shape>
|
||||
</clip>
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -0,0 +1,285 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<data>
|
||||
<variable
|
||||
name="model"
|
||||
type="com.mowesta.android.feign.model.WeatherCondition" />
|
||||
</data>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:fillViewport="true"
|
||||
android:id="@+id/gradient_scroll"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:baselineAligned="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent">
|
||||
<ImageView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="0dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:contentDescription="@string/label_temperature"
|
||||
app:srcCompat="@drawable/ic_thermometer_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="22dp"
|
||||
android:layout_height="0dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:contentDescription="@string/label_precipitation"
|
||||
app:srcCompat="@drawable/ic_raindrops_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="0dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:contentDescription="@string/label_cloud_coverage"
|
||||
app:srcCompat="@drawable/ic_cloud_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="0dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:padding="4dp"
|
||||
android:contentDescription="@string/label_local_time"
|
||||
app:srcCompat="@drawable/ic_alarm_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="0dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:padding="2dp"
|
||||
android:contentDescription="@string/label_humidity"
|
||||
app:srcCompat="@drawable/ic_humidity_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="0dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:contentDescription="@string/label_wind_speed"
|
||||
app:srcCompat="@drawable/ic_wind_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="0dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:contentDescription="@string/label_pressure"
|
||||
app:srcCompat="@drawable/ic_barometer_normal_24"/>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/gradient_constraint"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.mowesta.android.app.view.GradientView
|
||||
app:direction="HORIZONTAL"
|
||||
android:id="@+id/gradient_temperature"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<com.mowesta.android.app.view.DropView
|
||||
app:direction="HORIZONTAL"
|
||||
android:id="@+id/gradient_preciptiation"
|
||||
android:background="@drawable/bg_precipitation"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<com.mowesta.android.app.view.DualGradientView
|
||||
app:direction="HORIZONTAL"
|
||||
android:id="@+id/gradient_cloud"
|
||||
android:background="@color/bg_cloud"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
|
||||
<com.mowesta.android.app.view.TimeView
|
||||
app:direction="HORIZONTAL"
|
||||
android:id="@+id/gradient_touch"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
|
||||
<com.mowesta.android.app.view.GradientView
|
||||
app:direction="HORIZONTAL"
|
||||
android:id="@+id/gradient_humidity"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<com.mowesta.android.app.view.ParticleView
|
||||
app:direction="HORIZONTAL"
|
||||
android:id="@+id/gradient_wind_speed"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<com.mowesta.android.app.view.GradientView
|
||||
app:direction="HORIZONTAL"
|
||||
android:id="@+id/gradient_pressure"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/guide_gradient"
|
||||
app:layout_constraintGuide_percent="0.5"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/gradient_text"
|
||||
app:layout_constraintLeft_toLeftOf="@id/guide_gradient"
|
||||
android:background="@color/normal"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/gradient_progress_1"
|
||||
android:layout_width="2dp"
|
||||
android:background="@color/normal"
|
||||
android:layout_height="match_parent"
|
||||
android:progressDrawable="@drawable/progress_vertical"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:indeterminate="false" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingStart="@dimen/space_medium"
|
||||
android:paddingEnd="@dimen/space_medium"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="7°C"
|
||||
temperature="@{model}"
|
||||
android:textStyle="bold"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="11mm/h"
|
||||
precipitation="@{model}"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="99%"
|
||||
cloudCoverage="@{model}"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="1.1.2000 11:00"
|
||||
android:id="@+id/gradient_time"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="99%"
|
||||
humidity="@{model}"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="4km/h"
|
||||
windSpeed="@{model}"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="1000.3hPa"
|
||||
pressure="@{model}"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/gradient_progress_2"
|
||||
android:layout_width="2dp"
|
||||
android:background="@color/normal"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleY="-1"
|
||||
android:progressDrawable="@drawable/progress_vertical"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:indeterminate="false" />
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</layout>
|
||||
@@ -38,7 +38,7 @@
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@color/primary"
|
||||
app:itemIconTint="@drawable/selector_navigation"
|
||||
|
||||
@@ -0,0 +1,295 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<data>
|
||||
<variable
|
||||
name="model"
|
||||
type="com.mowesta.android.feign.model.WeatherCondition" />
|
||||
</data>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:fillViewport="true"
|
||||
android:id="@+id/gradient_scroll"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageView
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="24dp"
|
||||
android:contentDescription="@string/label_temperature"
|
||||
app:srcCompat="@drawable/ic_thermometer_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="24dp"
|
||||
android:contentDescription="@string/label_precipitation"
|
||||
app:srcCompat="@drawable/ic_raindrops_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="24dp"
|
||||
android:contentDescription="@string/label_cloud_coverage"
|
||||
app:srcCompat="@drawable/ic_cloud_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="24dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:padding="4dp"
|
||||
android:contentDescription="@string/label_local_time"
|
||||
app:srcCompat="@drawable/ic_alarm_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="24dp"
|
||||
android:padding="2dp"
|
||||
android:contentDescription="@string/label_humidity"
|
||||
app:srcCompat="@drawable/ic_humidity_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="24dp"
|
||||
android:contentDescription="@string/label_wind_speed"
|
||||
app:srcCompat="@drawable/ic_wind_normal_24"/>
|
||||
<ImageView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="24dp"
|
||||
android:contentDescription="@string/label_pressure"
|
||||
app:srcCompat="@drawable/ic_barometer_normal_24"/>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/gradient_constraint"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.mowesta.android.app.view.GradientView
|
||||
android:id="@+id/gradient_temperature"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<com.mowesta.android.app.view.DropView
|
||||
android:id="@+id/gradient_preciptiation"
|
||||
android:background="@drawable/bg_precipitation"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<com.mowesta.android.app.view.DualGradientView
|
||||
android:id="@+id/gradient_cloud"
|
||||
android:background="@color/bg_cloud"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
|
||||
<com.mowesta.android.app.view.TimeView
|
||||
android:id="@+id/gradient_touch"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
|
||||
<com.mowesta.android.app.view.GradientView
|
||||
android:id="@+id/gradient_humidity"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<com.mowesta.android.app.view.ParticleView
|
||||
android:id="@+id/gradient_wind_speed"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<com.mowesta.android.app.view.GradientView
|
||||
android:id="@+id/gradient_pressure"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/guide_gradient"
|
||||
app:layout_constraintGuide_percent="0.5"
|
||||
android:orientation="horizontal"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/gradient_text"
|
||||
app:layout_constraintBottom_toTopOf="@id/guide_gradient"
|
||||
android:background="@color/normal"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/gradient_progress_1"
|
||||
android:layout_width="match_parent"
|
||||
android:background="@color/normal"
|
||||
android:foregroundGravity="center_vertical"
|
||||
android:layout_height="2dp"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:indeterminate="false" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Space
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="11mm/h"
|
||||
precipitation="@{model}"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:gravity="center_horizontal|bottom"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="1.1.2000 11:00"
|
||||
android:id="@+id/gradient_time"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_horizontal|bottom"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="4km/h"
|
||||
windSpeed="@{model}"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_horizontal|bottom"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="0dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
||||
<Space
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="7°C"
|
||||
temperature="@{model}"
|
||||
android:textStyle="bold"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:gravity="start|bottom"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:layout_weight="1.5"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="99%"
|
||||
cloudCoverage="@{model}"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:gravity="end|bottom"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="99%"
|
||||
humidity="@{model}"
|
||||
android:gravity="start|bottom"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
tools:text="1000.3hPa"
|
||||
pressure="@{model}"
|
||||
android:gravity="end|bottom"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:layout_weight="1.5"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/gradient_progress_2"
|
||||
android:layout_width="match_parent"
|
||||
android:background="@color/normal"
|
||||
android:foregroundGravity="center_vertical"
|
||||
android:layout_height="2dp"
|
||||
android:scaleX="-1"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:indeterminate="false" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</layout>
|
||||
@@ -2,6 +2,7 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
@@ -11,6 +12,7 @@
|
||||
app:tabMaxWidth="0dp"
|
||||
app:tabGravity="fill"
|
||||
app:tabMode="fixed"
|
||||
app:tabTextAppearance="@style/TextAppearance.Mowesta.TabLayout"
|
||||
tools:targetApi="21"
|
||||
android:elevation="4dp"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:padding="8dp"
|
||||
app:srcCompat="@drawable/icon_launch_sun"
|
||||
android:fitsSystemWindows="true"
|
||||
android:scaleType="fitEnd"
|
||||
app:layout_collapseMode="parallax" />
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:theme="@style/ThemeOverlay.MaterialComponents.Dark"
|
||||
android:id="@+id/layout_appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="128dp">
|
||||
|
||||
@@ -44,5 +46,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:layout_collapseMode="pin" />
|
||||
|
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
@@ -10,15 +10,10 @@
|
||||
type="com.mowesta.android.app.model.VideoViewModel.OnVideoSelectedListener" />
|
||||
</data>
|
||||
<LinearLayout
|
||||
android:layout_margin="8dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:layout_margin="8dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -41,7 +36,6 @@
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?attr/textAppearanceCaption" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</layout>
|
||||
|
||||
@@ -228,8 +228,9 @@
|
||||
<string name="city_video">Videos</string>
|
||||
<string name="city_info">Informationen</string>
|
||||
<string name="city_info_title">Aktuelles Wetter</string>
|
||||
<string name="city_info_gradient">Visuell</string>
|
||||
<string name="city_info_day">Tag</string>
|
||||
<string name="city_info_time">Tageszeit</string>
|
||||
<string name="city_info_time">Zeitraum</string>
|
||||
<string name="city_info_hour">Stunde</string>
|
||||
<string name="label_station">Wetterstation</string>
|
||||
<string name="label_full_day">Gesamter Tag</string>
|
||||
|
||||
@@ -3,4 +3,7 @@
|
||||
<color name="separator">#555555</color>
|
||||
<color name="bg_search">#333333</color>
|
||||
<color name="inverse">#a0ffffff</color>
|
||||
<color name="normal">#ff000000</color>
|
||||
<color name="particle">#ff4444ff</color>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<declare-styleable name="DataView">
|
||||
<attr name="direction" format="enum">
|
||||
<enum name="HORIZONTAL" value="0" />
|
||||
<enum name="VERTICAL" value="1" />
|
||||
</attr>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="WeatherView">
|
||||
<attr name="weather" format="enum">
|
||||
<enum name="DAY_SUNNY" value="0"/>
|
||||
|
||||
@@ -10,5 +10,21 @@
|
||||
<color name="separator">#eeeeee</color>
|
||||
<color name="bg_search">#fefefe</color>
|
||||
<color name="inverse">#a0000000</color>
|
||||
<color name="normal">#ffffffff</color>
|
||||
<color name="particle">#ff0000ff</color>
|
||||
<color name="fg_accent">#c0000000</color>
|
||||
|
||||
<color name="bg_cloud">#5c99e9</color>
|
||||
|
||||
<!--
|
||||
0xFFEFF8FD, // 1 ice
|
||||
0xFF989278, // 2 rock
|
||||
0xFFD1B281, // 3 sand
|
||||
0xFFE3CCAB, // 4 sandyloam
|
||||
0xFFCD9160, // 5 loam
|
||||
0xFFB65941, // 6 clayloam
|
||||
0xFFAC753B, // 7 clay
|
||||
0xFF987E6F, // 8 peat
|
||||
0xFF47859c, // 9 sea water
|
||||
-->
|
||||
</resources>
|
||||
|
||||
@@ -231,6 +231,7 @@
|
||||
<string name="city_video">Video</string>
|
||||
<string name="city_info">Information</string>
|
||||
<string name="city_info_title">Current Weather</string>
|
||||
<string name="city_info_gradient">Visual</string>
|
||||
<string name="city_info_day">Day</string>
|
||||
<string name="city_info_time">Time</string>
|
||||
<string name="city_info_hour">Hour</string>
|
||||
|
||||
@@ -29,4 +29,9 @@
|
||||
|
||||
<style name="ThemeOverlay.Mowesta.MaterialComponents" parent="Theme.MaterialComponents.Light" />
|
||||
|
||||
|
||||
<style name="TextAppearance.Mowesta.TabLayout" parent="TextAppearance.MaterialComponents.Button">
|
||||
<item name="android:letterSpacing" tools:targetApi="21">0</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ allprojects {
|
||||
|
||||
// set version for our project
|
||||
group = 'com.mowesta'
|
||||
version = '1.0.7'
|
||||
version = '1.0.8'
|
||||
|
||||
// set versions for our libraries
|
||||
ext {
|
||||
|
||||
@@ -125,6 +125,22 @@ export class ConditionMapComponent implements OnInit, AfterViewInit {
|
||||
*/
|
||||
private currZoom = MapComponent.DEFAULT_ZOOM;
|
||||
|
||||
/**
|
||||
* The position on which the mouse went down on a tooltip.
|
||||
*/
|
||||
private tooltipDownPosition: number[] = [0, 0];
|
||||
/**
|
||||
* The tooltip on which the mouse went down.
|
||||
*/
|
||||
private tooltipDownElement: L.Tooltip = null;
|
||||
/**
|
||||
* The slop which we allow until we start ignoring touch events.
|
||||
* This is a number of pixels squared (i.e. 400 = 20px).
|
||||
*/
|
||||
private readonly tooltipDownSlop = 400;
|
||||
|
||||
|
||||
|
||||
constructor(
|
||||
private readonly res: ResourceService,
|
||||
private readonly defaultService: DefaultService,
|
||||
@@ -331,7 +347,7 @@ export class ConditionMapComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the whole line of tiles is at least 75% within the viewport.
|
||||
* Checks if the whole line of tiles is at least 10% within the viewport.
|
||||
* Only the outer tiles of the map are checked.
|
||||
*
|
||||
* @param boundary The boundary to check. (North, East, South, West)
|
||||
@@ -339,7 +355,7 @@ export class ConditionMapComponent implements OnInit, AfterViewInit {
|
||||
* @param cornerOutVp The corner of the tile not within the viewport.
|
||||
*/
|
||||
private isTileLineInViewPort(boundary: number, cornerOnVp: number, cornerOutVp: number): number {
|
||||
return ((Math.abs(cornerOnVp - boundary) / Math.abs(cornerOnVp - cornerOutVp)) >= 0.75) ? 0 : 1;
|
||||
return ((Math.abs(cornerOnVp - boundary) / Math.abs(cornerOnVp - cornerOutVp)) >= 0.10) ? 0 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -433,8 +449,25 @@ export class ConditionMapComponent implements OnInit, AfterViewInit {
|
||||
.setContent(content)
|
||||
.setLatLng(new L.LatLng(cityData.city.coordinate.latitude, cityData.city.coordinate.longitude))
|
||||
.addTo(this.appMap.map);
|
||||
cityData.tooltip.getElement().addEventListener('click', ev => {
|
||||
this.router.navigateByUrl(`/${this.res.getLanguage()}/weather/cities/${cityData.city.id}`);
|
||||
// this used to be a click handler, but unfortunately, the click
|
||||
// will also be issued if the map is dragged which creates a user
|
||||
// experience that really stinks, so we need to run our own click
|
||||
// detection code that ignores clicks where up and down are not
|
||||
// on the same location (because the user dragged the map)
|
||||
cityData.tooltip.getElement().addEventListener('mousedown', ev => {
|
||||
this.tooltipDownElement = cityData.tooltip;
|
||||
this.tooltipDownPosition = [ev.clientX, ev.clientY ];
|
||||
});
|
||||
cityData.tooltip.getElement().addEventListener('mouseup', ev => {
|
||||
if (this.tooltipDownElement === cityData.tooltip) {
|
||||
const dx = this.tooltipDownPosition[0] - ev.clientX;
|
||||
const dy = this.tooltipDownPosition[1] - ev.clientY;
|
||||
if (dx * dx + dy * dy < 400) {
|
||||
this.router.navigateByUrl(`/${this.res.getLanguage()}/weather/cities/${cityData.city.id}`);
|
||||
}
|
||||
}
|
||||
this.tooltipDownElement = null;
|
||||
this.tooltipDownPosition = [0, 0];
|
||||
});
|
||||
cityData.tooltip.getElement().style.pointerEvents = 'auto';
|
||||
cityData.tooltip.getElement().style.cursor = 'pointer';
|
||||
|
||||
Reference in New Issue
Block a user