SunriseSunsetView
SunriseSunsetView is a lightweight Android view used for displaying and/or editing sunrise and sunset times. This is a part of my efforts to modularize some of the things that I write; it was originally a part of Alarmio, and has been separated into its own library.
A Screenshot |
---|
Usage
Setup
This project is published on JitPack, which you can add to your project by copying the following to your root build.gradle at the end of "repositories".
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
To add the dependency, copy this line into your app module's build.gradle file.
implementation 'me.jfenn:SunriseSunsetView:0.0.1'
Basic Use
Adding the SlideActionView somewhere in your layout is fairly simple. Here is an example:
<me.jfenn.sunrisesunsetview.SunriseSunsetView
android:id="@+id/sunView"
android:layout_width="match_parent"
android:layout_height="240dp" />
Note the layout_height="240dp"
. The view does not have a minimum size, and will scale according to its width and height inside of the layout that it is placed in, so you must define a width and height for it to use.
You can specify an interface to recieve updates from the view by calling .setListener(SunriseListener)
...
sunView.setListener(new SunriseSunsetView.SunriseListener() {
@Override
public void onSunriseChanged(SunriseSunsetView view, long sunriseMillis) {
// do something
}
@Override
public void onSunsetChanged(SunriseSunsetView view, long sunsetMillis) {
// do something else
}
});
The sunrise and sunset times are passed as milliseconds ranging from 0 to "24 hours", or 86400000. Note that these values are not dependent on your current time zone - they start at 0, representing "0:00", and end at 864399999, representing "23:59".
You can set these values by calling .setDayStart(millis)
and .setDayEnd(millis)
.