Skip to content

Commit

Permalink
Improvements from omWeather development:
Browse files Browse the repository at this point in the history
Add wind icons
Use Rainviewer clouds layer in rain radar
Fix white lines in rain radar
Use violet for max uv level
Layout improvements
  • Loading branch information
woheller69 committed Mar 3, 2023
1 parent eb8017c commit ce4d6ad
Show file tree
Hide file tree
Showing 31 changed files with 224 additions and 129 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ For subscriptions later than Aug 15, 2022 you need a free subscription and OneCa

Please register for free account at: https://home.openweathermap.org/users/sign_up

Use [omWeather](https://github.com/woheller69/omweather) instead if you do not yet have an API key.

[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" height="75">](https://f-droid.org/de/packages/org.woheller69.weather/)


Expand Down
4 changes: 4 additions & 0 deletions app/src/main/assets/leaflet.css
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,7 @@ svg.leaflet-image-layer.leaflet-interactive path {
margin-left: -12px;
border-right-color: #fff;
}
.leaflet-tile-container img {
width: 257px !important;
height: 257px !important;
}
48 changes: 32 additions & 16 deletions app/src/main/assets/rainviewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<div id="mapid" style="position: absolute; top: 45px; left: 0; bottom: 0; right: 0;"></div>

<script>
//call: rainviewer.html?lat={latitude}&lon={longitude}&appid={API_KEY}&nightmode={mode} Takes latitude/longitude and OWM API_Key from request and shows rainviewer rain radar and OWM clouds layer on openstreetmap for requested position and zoom
//call: rainviewer.html?lat={latitude}&lon={longitude}&nightmode={mode} Takes latitude/longitude and nightmode from request and shows rainviewer rain radar and clouds on openstreetmap for requested position and zoom


var getUrlParameter = function getUrlParameter(sParam) {
Expand All @@ -60,18 +60,18 @@
}).setView([getUrlParameter('lat'), getUrlParameter('lon')], 8); //zoom factor 8

let myFilterClouds = [
'contrast:1000%',
'contrast:200%',
'invert:100%',
'opacity:60%'
'opacity:40%'
];

let myFilterCloudsNight = [
'contrast:1000%',
'contrast:200%',
'opacity:60%'
];

let myFilterMap = [
'saturate:200%'
'saturate:300%'
];

let myFilterMapNight = [
Expand All @@ -83,18 +83,12 @@
if (getUrlParameter('nightmode')==0){
L.tileLayer.colorFilter('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
filter: myFilterMap,
attribution: 'Map data ©<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors <br> Weather data <a href="https://www.rainviewer.com/api.html"> RainViewer </a>& <a href="https://openweathermap.org/api"> OpenWeatherMap </a>'
}).addTo(map);
L.tileLayer.colorFilter('https://tile.openweathermap.org/map/clouds_new/{z}/{x}/{y}.png?appid=' + getUrlParameter('appid'),{
filter: myFilterClouds
attribution: 'Map data ©<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors <br> Weather data <a href="https://www.rainviewer.com/api.html"> RainViewer </a>'
}).addTo(map);
}else{
L.tileLayer.colorFilter('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
filter: myFilterMapNight,
attribution: 'Map data ©<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors <br> Weather data <a href="https://www.rainviewer.com/api.html"> RainViewer </a>& <a href="https://openweathermap.org/api"> OpenWeatherMap </a>'
}).addTo(map);
L.tileLayer.colorFilter('https://tile.openweathermap.org/map/clouds_new/{z}/{x}/{y}.png?appid=' + getUrlParameter('appid'),{
filter: myFilterCloudsNight
attribution: 'Map data ©<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors <br> Weather data <a href="https://www.rainviewer.com/api.html"> RainViewer </a>'
}).addTo(map);
}

Expand All @@ -108,6 +102,7 @@
var mapFrames = [];
var lastPastFramePosition = -1;
var radarLayers = [];
var infraredLayer;

var animationPosition = 0;
var animationTimer = false;
Expand All @@ -121,15 +116,22 @@

// Save the API response
apiData = JSON.parse(apiRequest.response);

// Rebuild frames to show

//add current infrared frame
if (apiData.satellite && apiData.satellite.infrared) {
mapFrames = apiData.satellite.infrared;
lastPastFramePosition = apiData.satellite.infrared.length - 1;
addInfraredLayer(mapFrames[lastPastFramePosition]);
}

//Rebuild frames to show
if (apiData && apiData.radar && apiData.radar.past) {
mapFrames = apiData.radar.past;
if (apiData.radar.nowcast) {
mapFrames = mapFrames.concat(apiData.radar.nowcast);
}

// show the last "past" frame
//show the last "past" frame
lastPastFramePosition = apiData.radar.past.length - 1;
showFrame(lastPastFramePosition);
}
Expand All @@ -152,6 +154,20 @@
map.addLayer(radarLayers[frame.path]);
}
}

function addInfraredLayer(frame) {

if (getUrlParameter('nightmode')==0){
L.tileLayer.colorFilter(apiData.host + frame.path + '/256/{z}/{x}/{y}/0/0_0.png', {
filter: myFilterClouds
}).addTo(map);
} else {
L.tileLayer.colorFilter(apiData.host + frame.path + '/256/{z}/{x}/{y}/0/0_0.png', {
filter: myFilterCloudsNight
}).addTo(map);
}
console.log(apiData.host + frame.path + '/256/{z}/{x}/{y}/0/0_0.png');
}

/**
* Display particular frame of animation for the @position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ protected void onPause() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rain_viewer);
AppPreferencesManager prefManager =
new AppPreferencesManager(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));
String API_KEY = prefManager.getOWMApiKey(getApplicationContext());
float latitude = getIntent().getFloatExtra("latitude", -1);
float longitude = getIntent().getFloatExtra("longitude", -1);
int timezoneseconds = getIntent().getIntExtra("timezoneseconds",0);
Expand All @@ -61,7 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
webView = findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUserAgentString(BuildConfig.APPLICATION_ID+"/"+BuildConfig.VERSION_NAME);
webView.loadUrl("file:///android_asset/rainviewer.html?lat=" + latitude + "&lon=" + longitude + "&appid=" + API_KEY + "&nightmode=" + nightmode + "&hour12=" + hour12 + "&tz="+timezoneseconds);
webView.loadUrl("file:///android_asset/rainviewer.html?lat=" + latitude + "&lon=" + longitude + "&nightmode=" + nightmode + "&hour12=" + hour12 + "&tz="+timezoneseconds);

webView.setWebViewClient(new WebViewClient() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public class PFASQLiteHelper extends SQLiteAssetHelper {
COLUMN_TIME_SUNRISE + " VARCHAR(50) NOT NULL," +
COLUMN_TIME_SUNSET + " VARCHAR(50) NOT NULL," +
COLUMN_TIMEZONE_SECONDS + " INTEGER," +
COLUMN_RAIN60MIN + " VARCHAR(25 NOT NULL)," +
COLUMN_RAIN60MIN + " VARCHAR(25) NOT NULL," +
" FOREIGN KEY (" + CURRENT_WEATHER_CITY_ID + ") REFERENCES " + TABLE_CITIES + "(" + CITIES_ID + "));";

private static final String CREATE_TABLE_CITIES = "CREATE TABLE " + TABLE_CITIES +
Expand Down Expand Up @@ -487,10 +487,10 @@ public synchronized CityToWatch getCityToWatch(int id) {
Cursor cursor = database.rawQuery(
"SELECT " + CITIES_TO_WATCH_ID +
", " + CITIES_TO_WATCH_CITY_ID +
", " + CITIES_NAME +
", " + CITIES_COUNTRY_CODE +
", " + CITIES_LONGITUDE +
", " + CITIES_LATITUDE +
", " + CITIES_TO_WATCH_NAME +
", " + CITIES_TO_WATCH_COUNTRY_CODE +
", " + CITIES_TO_WATCH_LONGITUDE +
", " + CITIES_TO_WATCH_LATITUDE +
", " + CITIES_TO_WATCH_COLUMN_RANK +
" FROM " + TABLE_CITIES_TO_WATCH +
" WHERE " + CITIES_TO_WATCH_CITY_ID + " = ?", arguments);
Expand Down Expand Up @@ -522,10 +522,10 @@ public synchronized List<CityToWatch> getAllCitiesToWatch() {
Cursor cursor = database.rawQuery(
"SELECT " + CITIES_TO_WATCH_ID +
", " + CITIES_TO_WATCH_CITY_ID +
", " + CITIES_NAME +
", " + CITIES_COUNTRY_CODE +
", " + CITIES_LONGITUDE +
", " + CITIES_LATITUDE +
", " + CITIES_TO_WATCH_NAME +
", " + CITIES_TO_WATCH_COUNTRY_CODE +
", " + CITIES_TO_WATCH_LONGITUDE +
", " + CITIES_TO_WATCH_LATITUDE +
", " + CITIES_TO_WATCH_COLUMN_RANK +
" FROM " + TABLE_CITIES_TO_WATCH
, new String[]{});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.Looper;
import android.os.Message;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -114,6 +115,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
autoSuggestAdapter = new AutoSuggestAdapter(requireContext(),
R.layout.list_item_autocomplete);
autoCompleteTextView.setThreshold(2);
autoCompleteTextView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
autoCompleteTextView.setAdapter(autoSuggestAdapter);

autoCompleteTextView.setOnItemClickListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ private void handleUpdateForecastAction(Intent intent, int cityId, float lat, fl

// Update if update forced or if a certain time has passed
if (skipUpdateInterval || timestamp + updateInterval - systemTime <= 0) {
//if forecastChoice = 1 (3h) perform both else only one call API
int choice = Integer.parseInt(prefManager.getString("forecastChoice","1"));
if (choice==1) {
IHttpRequestForForecast forecastRequest = new OwmHttpRequestForForecast(getApplicationContext());
forecastRequest.perform(lat, lon, cityId);
}
//if forecastChoice = 1 (3h) perform both else only one call API
// int choice = Integer.parseInt(prefManager.getString("forecastChoice","1"));
// if (choice==1) {
// IHttpRequestForForecast forecastRequest = new OwmHttpRequestForForecast(getApplicationContext());
// forecastRequest.perform(lat, lon, cityId);
// }
IHttpRequestForOneCallAPI forecastOneCallRequest = new OwmHttpRequestForOneCallAPI(getApplicationContext());
forecastOneCallRequest.perform(lat,lon, cityId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ public static Drawable colorWindSpeed(Context context, float wind_speed) {

public static int colorWindSpeedWidget(float wind_speed) {
if (wind_speed < 0.3) {
return R.drawable.transparent_no_margin;
return R.drawable.ic_wind_empty;
} else if (wind_speed < 1.5) {
return R.drawable.transparent_no_margin;
return R.drawable.ic_wind_empty;
} else if (wind_speed < 3.3) {
return R.drawable.transparent_no_margin;
return R.drawable.ic_wind_empty;
} else if (wind_speed < 5.5) {
return R.drawable.transparent_no_margin;
return R.drawable.ic_wind_empty;
} else if (wind_speed < 7.9) {
return R.drawable.transparent_no_margin;
return R.drawable.ic_wind_empty;
} else if (wind_speed < 10.7) {
return R.drawable.ic_wind_yellow;
} else if (wind_speed < 13.8) {
Expand Down Expand Up @@ -175,7 +175,7 @@ public static Drawable colorUVindex(Context context, int uvindex) {
} else if (uvindex <= 10) {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_lightred,null);
} else {
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_red,null);
return ResourcesCompat.getDrawable(context.getResources(),R.drawable.rounded_violet,null);
}
}

Expand Down Expand Up @@ -219,7 +219,7 @@ public static Integer widgetColorUVindex(Context context, int uvindex) {
} else if (uvindex <= 10) {
return R.drawable.rounded_lightred;
} else {
return R.drawable.rounded_red;
return R.drawable.rounded_violet;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -162,12 +164,14 @@ public class OverViewHolder extends ViewHolder {
TextView temperature;
ImageView weather;
TextView sun;
ImageView windicon;

OverViewHolder(View v) {
super(v);
this.temperature = v.findViewById(R.id.card_overview_temperature);
this.weather = v.findViewById(R.id.card_overview_weather_image);
this.sun=v.findViewById(R.id.card_overview_sunrise_sunset);
this.sun = v.findViewById(R.id.card_overview_sunrise_sunset);
this.windicon = v.findViewById(R.id.card_overview_windicon);
}
}

Expand Down Expand Up @@ -289,7 +293,7 @@ public void onBindViewHolder(ViewHolder viewHolder, final int position) {
}

setImage(currentWeatherDataList.getWeatherID(), holder.weather, isDay);

holder.windicon.setImageResource(StringFormatUtils.colorWindSpeedWidget(currentWeatherDataList.getWindSpeed()));
holder.temperature.setText(StringFormatUtils.formatTemperature(context, currentWeatherDataList.getTemperatureCurrent()));

} else if (viewHolder.getItemViewType() == DETAILS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void onBindViewHolder(CourseOfDayViewHolder holder, int position) {

updateRecyclerViewHeader(); //update header according to date in first visible item on the left

holder.windicon.setImageResource(StringFormatUtils.colorWindSpeedWidget(courseOfDayList.get(position).getWindSpeed()));
setIcon(courseOfDayList.get(position).getWeatherID(), holder.weather, isDay);
holder.humidity.setText(StringFormatUtils.formatInt(courseOfDayList.get(position).getHumidity(), context.getString(R.string.units_rh)));

Expand Down Expand Up @@ -153,6 +154,7 @@ class CourseOfDayViewHolder extends RecyclerView.ViewHolder {
TextView precipitation;
TextView wind_speed;
ImageView wind_direction;
ImageView windicon;

CourseOfDayViewHolder(View itemView) {
super(itemView);
Expand All @@ -165,6 +167,7 @@ class CourseOfDayViewHolder extends RecyclerView.ViewHolder {
precipitation = itemView.findViewById(R.id.course_of_day_precipitation);
wind_speed = itemView.findViewById(R.id.course_of_day_wind_speed);
wind_direction = itemView.findViewById(R.id.course_of_day_wind_direction);
windicon = itemView.findViewById(R.id.course_of_day_wind_icon);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void onBindViewHolder(WeekForecastViewHolder holder, int position) {
}

setIcon((int) dayValues[9], holder.weather, isDay);
holder.windicon.setImageResource(StringFormatUtils.colorWindSpeedWidget(dayValues[5]));
holder.humidity.setText(StringFormatUtils.formatInt(dayValues[2],context.getString(R.string.units_rh)));

SharedPreferences prefManager = PreferenceManager.getDefaultSharedPreferences(context);
Expand Down Expand Up @@ -146,6 +147,7 @@ class WeekForecastViewHolder extends RecyclerView.ViewHolder {
TextView wind_speed;
TextView precipitation;
TextView uv_index;
ImageView windicon;

WeekForecastViewHolder(View itemView) {
super(itemView);
Expand All @@ -161,6 +163,7 @@ class WeekForecastViewHolder extends RecyclerView.ViewHolder {
wind_speed = itemView.findViewById(R.id.week_forecast_wind_speed);
precipitation = itemView.findViewById(R.id.week_forecast_precipitation);
uv_index = itemView.findViewById(R.id.week_forecast_uv_index);
windicon = itemView.findViewById(R.id.week_forecast_wind_icon);
}
}

Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/ic_wind_empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="12.01dp"
android:height="17.51dp"
android:viewportWidth="1201"
android:viewportHeight="1751">
<path
android:pathData="M125,1750L0,1750 0,0 250,0 250,1750 125,1750Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="#00000000"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
<path
android:pathData="M1200,575L249,1001 249,150 1200,575Z"
android:strokeLineJoin="round"
android:strokeWidth="28.222"
android:fillColor="#00000000"
android:strokeColor="#00000000"
android:fillType="evenOdd"/>
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/rounded_highlight.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:color="@color/backgroundHighlight"
/>
<padding
android:bottom="-3dp"
android:bottom="3dp"
android:top="-3dp"
android:left="5dp"
android:right="5dp" />
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/rounded_violet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/violet" />
<stroke android:width="0dp"
android:color="@color/violet"
/>
<padding
android:bottom="-3dp"
android:top="-3dp"
android:left="5dp"
android:right="5dp" />

<corners android:radius="7dp" />
</shape>
Loading

0 comments on commit ce4d6ad

Please sign in to comment.