diff --git a/app/src/main/java/org/woheller69/weather/activities/ForecastCityActivity.java b/app/src/main/java/org/woheller69/weather/activities/ForecastCityActivity.java index 10082f4..6ac27bb 100644 --- a/app/src/main/java/org/woheller69/weather/activities/ForecastCityActivity.java +++ b/app/src/main/java/org/woheller69/weather/activities/ForecastCityActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import androidx.appcompat.app.AlertDialog; import androidx.preference.PreferenceManager; import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayoutMediator; @@ -19,17 +20,24 @@ import android.view.animation.Animation; import android.view.animation.LinearInterpolator; import android.view.animation.RotateAnimation; import android.widget.TextView; +import net.e175.klaus.solarpositioning.AzimuthZenithAngle; +import net.e175.klaus.solarpositioning.DeltaT; +import net.e175.klaus.solarpositioning.Grena3; import org.woheller69.weather.R; import org.woheller69.weather.database.GeneralData; import org.woheller69.weather.database.HourlyForecast; import org.woheller69.weather.database.SQLiteHelper; import org.woheller69.weather.database.WeekForecast; +import org.woheller69.weather.ui.Help.StringFormatUtils; import org.woheller69.weather.ui.updater.IUpdateableCityUI; import org.woheller69.weather.ui.updater.ViewUpdater; import org.woheller69.weather.ui.viewPager.WeatherPagerAdapter; import java.lang.reflect.Field; +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.List; public class ForecastCityActivity extends NavigationActivity implements IUpdateableCityUI { @@ -179,6 +187,26 @@ public class ForecastCityActivity extends NavigationActivity implements IUpdatea WeatherPagerAdapter.refreshSingleData(getApplicationContext(),true, pagerAdapter.getCityIDForPos(viewPager2.getCurrentItem())); ForecastCityActivity.startRefreshAnimation(); } + } else if (id==R.id.menu_sun_position){ + Long time = System.currentTimeMillis()/1000; + Instant i = Instant.ofEpochSecond(time); //currentTimeMillis is in GMT + ZonedDateTime dateTime = ZonedDateTime.ofInstant(i, ZoneId.of("GMT")); + AzimuthZenithAngle position = Grena3.calculateSolarPosition( + dateTime, + db.getCityToWatch(cityId).getLatitude(), + db.getCityToWatch(cityId).getLongitude(), + DeltaT.estimate(dateTime.toLocalDate())); // delta T (s) + + String solarAzimuth = StringFormatUtils.formatDecimal((float) position.getAzimuth(),""); + String solarElevation = StringFormatUtils.formatDecimal((float) (90 - position.getZenithAngle()),""); + + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); + alertDialogBuilder.setTitle(R.string.action_sun_position); + + alertDialogBuilder.setMessage(getString(R.string.edit_location_hint_azimuth)+": "+solarAzimuth + " \n" + getString(R.string.action_sun_elevation) + ": " + solarElevation); + alertDialogBuilder.setPositiveButton(getString(android.R.string.ok), (dialog, which) -> { }); + AlertDialog alertDialog = alertDialogBuilder.create(); + alertDialog.show(); } return super.onOptionsItemSelected(item); diff --git a/app/src/main/res/drawable/ic_solar_power_24px.xml b/app/src/main/res/drawable/ic_solar_power_24px.xml new file mode 100644 index 0000000..f328add --- /dev/null +++ b/app/src/main/res/drawable/ic_solar_power_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_wb_sunny_24px.xml b/app/src/main/res/drawable/ic_wb_sunny_24px.xml index 4f7c019..36167d1 100644 --- a/app/src/main/res/drawable/ic_wb_sunny_24px.xml +++ b/app/src/main/res/drawable/ic_wb_sunny_24px.xml @@ -4,6 +4,6 @@ android:viewportWidth="24" android:viewportHeight="24"> diff --git a/app/src/main/res/menu/activity_forecast_city.xml b/app/src/main/res/menu/activity_forecast_city.xml index 0cc6a61..1403670 100644 --- a/app/src/main/res/menu/activity_forecast_city.xml +++ b/app/src/main/res/menu/activity_forecast_city.xml @@ -2,14 +2,12 @@ + android:title="@string/action_sun_position" /> Abschattung unterhalb dieser Elevation [%] Abschattung Anleitung + Sonnenposition + Elevation [°] diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 34818f7..15f1ffc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -133,4 +133,6 @@ Shading below this elevation [%] Shading Instructions + Sun position + Elevation [°]