mirror of
https://github.com/woheller69/solxpect.git
synced 2025-09-22 00:40:46 +02:00
add button to show current sun position
This commit is contained in:
parent
fc7844f6f6
commit
555c17bdd1
7 changed files with 47 additions and 8 deletions
|
@ -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);
|
||||
|
|
9
app/src/main/res/drawable/ic_solar_power_24px.xml
Normal file
9
app/src/main/res/drawable/ic_solar_power_24px.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
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"/>
|
||||
</vector>
|
|
@ -4,6 +4,6 @@
|
|||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FFFFFFFF"
|
||||
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"/>
|
||||
</vector>
|
||||
|
|
|
@ -2,14 +2,12 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/menu_update_location"
|
||||
android:id="@+id/menu_sun_position"
|
||||
android:orderInCategory="80"
|
||||
android:visible="false"
|
||||
android:icon="@drawable/ic_location_on_white_24dp"
|
||||
app:actionViewClass="android.widget.ImageButton"
|
||||
android:visible="true"
|
||||
android:icon="@drawable/ic_wb_sunny_24px"
|
||||
app:showAsAction="always"
|
||||
style="@android:style/Widget.ActionButton"
|
||||
android:title="@string/action_position" />
|
||||
android:title="@string/action_sun_position" />
|
||||
<item
|
||||
android:id="@+id/menu_refresh"
|
||||
android:orderInCategory="90"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
android:checkableBehavior="all">
|
||||
<item
|
||||
android:id="@+id/nav_weather"
|
||||
android:icon="@drawable/ic_wb_sunny_24px"
|
||||
android:icon="@drawable/ic_solar_power_24px"
|
||||
android:title="@string/activity_weather" />
|
||||
<item
|
||||
android:id="@+id/nav_manage"
|
||||
|
|
|
@ -131,5 +131,7 @@
|
|||
<string name="edit_location_shading_opacity_heading">Abschattung unterhalb dieser Elevation [%]</string>
|
||||
<string name="edit_location_shading_heading">Abschattung</string>
|
||||
<string name="activity_help">Anleitung</string>
|
||||
<string name="action_sun_position">Sonnenposition</string>
|
||||
<string name="action_sun_elevation">Elevation [°]</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -133,4 +133,6 @@
|
|||
<string name="edit_location_shading_opacity_heading">Shading below this elevation [%]</string>
|
||||
<string name="edit_location_shading_heading">Shading</string>
|
||||
<string name="activity_help">Instructions</string>
|
||||
<string name="action_sun_position">Sun position</string>
|
||||
<string name="action_sun_elevation">Elevation [°]</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue