Skip to content

Commit 555c17b

Browse files
committed
add button to show current sun position
1 parent fc7844f commit 555c17b

File tree

7 files changed

+47
-8
lines changed

7 files changed

+47
-8
lines changed

app/src/main/java/org/woheller69/weather/activities/ForecastCityActivity.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.content.SharedPreferences;
66
import android.os.Bundle;
77

8+
import androidx.appcompat.app.AlertDialog;
89
import androidx.preference.PreferenceManager;
910
import com.google.android.material.tabs.TabLayout;
1011
import com.google.android.material.tabs.TabLayoutMediator;
@@ -19,17 +20,24 @@
1920
import android.view.animation.LinearInterpolator;
2021
import android.view.animation.RotateAnimation;
2122
import android.widget.TextView;
23+
import net.e175.klaus.solarpositioning.AzimuthZenithAngle;
24+
import net.e175.klaus.solarpositioning.DeltaT;
25+
import net.e175.klaus.solarpositioning.Grena3;
2226

2327
import org.woheller69.weather.R;
2428
import org.woheller69.weather.database.GeneralData;
2529
import org.woheller69.weather.database.HourlyForecast;
2630
import org.woheller69.weather.database.SQLiteHelper;
2731
import org.woheller69.weather.database.WeekForecast;
32+
import org.woheller69.weather.ui.Help.StringFormatUtils;
2833
import org.woheller69.weather.ui.updater.IUpdateableCityUI;
2934
import org.woheller69.weather.ui.updater.ViewUpdater;
3035
import org.woheller69.weather.ui.viewPager.WeatherPagerAdapter;
3136

3237
import java.lang.reflect.Field;
38+
import java.time.Instant;
39+
import java.time.ZoneId;
40+
import java.time.ZonedDateTime;
3341
import java.util.List;
3442

3543
public class ForecastCityActivity extends NavigationActivity implements IUpdateableCityUI {
@@ -179,6 +187,26 @@ public boolean onOptionsItemSelected(final MenuItem item) {
179187
WeatherPagerAdapter.refreshSingleData(getApplicationContext(),true, pagerAdapter.getCityIDForPos(viewPager2.getCurrentItem()));
180188
ForecastCityActivity.startRefreshAnimation();
181189
}
190+
} else if (id==R.id.menu_sun_position){
191+
Long time = System.currentTimeMillis()/1000;
192+
Instant i = Instant.ofEpochSecond(time); //currentTimeMillis is in GMT
193+
ZonedDateTime dateTime = ZonedDateTime.ofInstant(i, ZoneId.of("GMT"));
194+
AzimuthZenithAngle position = Grena3.calculateSolarPosition(
195+
dateTime,
196+
db.getCityToWatch(cityId).getLatitude(),
197+
db.getCityToWatch(cityId).getLongitude(),
198+
DeltaT.estimate(dateTime.toLocalDate())); // delta T (s)
199+
200+
String solarAzimuth = StringFormatUtils.formatDecimal((float) position.getAzimuth(),"");
201+
String solarElevation = StringFormatUtils.formatDecimal((float) (90 - position.getZenithAngle()),"");
202+
203+
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
204+
alertDialogBuilder.setTitle(R.string.action_sun_position);
205+
206+
alertDialogBuilder.setMessage(getString(R.string.edit_location_hint_azimuth)+": "+solarAzimuth + " \n" + getString(R.string.action_sun_elevation) + ": " + solarElevation);
207+
alertDialogBuilder.setPositiveButton(getString(android.R.string.ok), (dialog, which) -> { });
208+
AlertDialog alertDialog = alertDialogBuilder.create();
209+
alertDialog.show();
182210
}
183211

184212
return super.onOptionsItemSelected(item);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="m80,880 l80,-400h640l80,400L80,880ZM120,160v-80h120v80L120,160ZM178,800h262v-80L194,720l-16,80ZM245,373 L188,317 273,232 330,288 245,373ZM210,640h230v-80L226,560l-16,80ZM480,280q-83,0 -141.5,-58.5T280,80h80q0,50 35,85t85,35q50,0 85,-35t35,-85h80q0,83 -58.5,141.5T480,280ZM480,80ZM440,440L440,320h80v120h-80ZM520,800h262l-16,-80L520,720v80ZM520,640h230l-16,-80L520,560v80ZM715,373 L631,288 687,232 772,316 715,373ZM720,160v-80h120v80L720,160Z"/>
9+
</vector>

app/src/main/res/drawable/ic_wb_sunny_24px.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
android:viewportWidth="24"
55
android:viewportHeight="24">
66
<path
7-
android:fillColor="#FF000000"
7+
android:fillColor="#FFFFFFFF"
88
android:pathData="M6.76,4.84l-1.8,-1.79 -1.41,1.41 1.79,1.79 1.42,-1.41zM4,10.5L1,10.5v2h3v-2zM13,0.55h-2L11,3.5h2L13,0.55zM20.45,4.46l-1.41,-1.41 -1.79,1.79 1.41,1.41 1.79,-1.79zM17.24,18.16l1.79,1.8 1.41,-1.41 -1.8,-1.79 -1.4,1.4zM20,10.5v2h3v-2h-3zM12,5.5c-3.31,0 -6,2.69 -6,6s2.69,6 6,6 6,-2.69 6,-6 -2.69,-6 -6,-6zM11,22.45h2L13,19.5h-2v2.95zM3.55,18.54l1.41,1.41 1.79,-1.8 -1.41,-1.41 -1.79,1.8z"/>
99
</vector>

app/src/main/res/menu/activity_forecast_city.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
<menu xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto">
44
<item
5-
android:id="@+id/menu_update_location"
5+
android:id="@+id/menu_sun_position"
66
android:orderInCategory="80"
7-
android:visible="false"
8-
android:icon="@drawable/ic_location_on_white_24dp"
9-
app:actionViewClass="android.widget.ImageButton"
7+
android:visible="true"
8+
android:icon="@drawable/ic_wb_sunny_24px"
109
app:showAsAction="always"
11-
style="@android:style/Widget.ActionButton"
12-
android:title="@string/action_position" />
10+
android:title="@string/action_sun_position" />
1311
<item
1412
android:id="@+id/menu_refresh"
1513
android:orderInCategory="90"

app/src/main/res/menu/activity_main_drawer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
android:checkableBehavior="all">
77
<item
88
android:id="@+id/nav_weather"
9-
android:icon="@drawable/ic_wb_sunny_24px"
9+
android:icon="@drawable/ic_solar_power_24px"
1010
android:title="@string/activity_weather" />
1111
<item
1212
android:id="@+id/nav_manage"

app/src/main/res/values-de/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,7 @@
131131
<string name="edit_location_shading_opacity_heading">Abschattung unterhalb dieser Elevation [%]</string>
132132
<string name="edit_location_shading_heading">Abschattung</string>
133133
<string name="activity_help">Anleitung</string>
134+
<string name="action_sun_position">Sonnenposition</string>
135+
<string name="action_sun_elevation">Elevation [°]</string>
134136

135137
</resources>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,6 @@
133133
<string name="edit_location_shading_opacity_heading">Shading below this elevation [%]</string>
134134
<string name="edit_location_shading_heading">Shading</string>
135135
<string name="activity_help">Instructions</string>
136+
<string name="action_sun_position">Sun position</string>
137+
<string name="action_sun_elevation">Elevation [°]</string>
136138
</resources>

0 commit comments

Comments
 (0)