Settings.System.putInt(mContext.getContentResolver(), Settings.System.DARKNIGHT_MINUTES, setMinute);
Intent i = new Intent(ACTION_UPDATE_BACKLIGHT_MODE);
mContext.sendBroadcast(i);
}
}
private LocationListener mlocationListener = new LocationListener() {
// Called when the location has changed.
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
Log.d(TAG, "Location Changed : location = " + location.toString());
if (location != null) {
ChinaLocation china_lc = LocationUtils.wgtochina(location.getLongitude(), location.getLatitude());
mLongitude = china_lc.china_lng;
mLatitude = china_lc.china_lat;
// more
Log.d(TAG, "Location Changed : Latitude = " + mLatitude + ", Longitude = "
+ mLongitude);
// updateStat(mLatitude, mLongitude);
saveSunSetAanSunRiseTime();
}
}
// Called when the provider is disabled by the user.
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Log.d(TAG, "Location provider is disabled by the user");
}
// Called when the provider is enabled by the user.
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Log.d(TAG, "Location provider is disabled by the user");
}
// Called when the provider status changes.
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
Log.d(TAG, "Location provider status changes; provider = " + provider + ", status = "
+ status + ", extras =" + extras.toString());
}
};
public class SunRisesAndSetsTime {
private static final String TAG = "SunRisesAndSetsTime";
private int days_of_month_1[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
private int days_of_month_2[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
private static final double h = -0.833;
private static final double PI = 3.1415926;
private int latDegree = 0;
private int latDinute = 0;
private int latSecond = 0;
private double UTo = 180.0;
private int longDegree = 0;
private int longDinute = 0;
private int longSecond = 0;
private int year, month, date;
public void setDate(int mYear, int mMonth, int mDate) {
year = mYear;
month = mMonth;
date = mDate;
Log.d(TAG, "year=" + year + " month=" + month + " date=" + date);
}
public void setLat(double mLat) {
Log.d(TAG, "setLat");
latDegree = (int) mLat;
double num1 = (mLat % 1) * 60;
latDinute = (int) num1;
double num2 = (num1 % 1) * 60;
latSecond = (int) num2;
Log.d(TAG, "latDegree=" + latDegree + " latDinute=" + latDinute + " latSecond=" + latSecond);
}
public void setLong(double mLong) {
Log.d(TAG, "setLong");
longDegree = (int) mLong;
double num1 = (mLong % 1) * 60;
longDinute = (int) num1;
double num2 = (num1 % 1) * 60;
longSecond = (int) num2;
Log.d(TAG, "longDegree=" + longDegree + " longDinute=" + longDinute + " longSecond=" + longSecond);
}
boolean leap_year(int year) {
if (((year % 400 == 0) || (year % 100 != 0) && (year % 4 == 0)))
return true;
else
return false;
}
int days(int year, int month, int date) {
int i, a = 0;
for (i = 2000; i < year; i++) {
if (leap_year(i))
a = a + 366;
else
a = a + 365;
}
if (leap_year(year)) {
for (i = 0; i < month - 1; i++) {
a = a + days_of_month_2[i];
}
} else {
for (i = 0; i < month - 1; i++) {
a = a + days_of_month_1[i];
}
}
a = a + date;
return a;
}
double t_century(int days, double UTo) {
return ((double) days + UTo / 360) / 36525;
}
double L_sun(double t_century) {
return (280.460 + 36000.770 * t_century);
}
double G_sun(double t_century) {
return (357.528 + 35999.050 * t_century);
}
double ecliptic_longitude(double L_sun, double G_sun) {
return (L_sun + 1.915 * Math.sin(G_sun * PI / 180) + 0.02 * Math.sin(2 * G_sun * PI / 180));
}
double earth_tilt(double t_century) {
return (23.4393 - 0.0130 * t_century);
}
double sun_deviation(double earth_tilt, double ecliptic_longitude) {
return (180 / PI * Math.asin(Math.sin(PI / 180 * earth_tilt) * Math.sin(PI / 180 * ecliptic_longitude)));
}
double GHA(double UTo, double G_sun, double ecliptic_longitude) {
return (UTo - 180 - 1.915 * Math.sin(G_sun * PI / 180) - 0.02 * Math.sin(2 * G_sun * PI / 180) + 2.466
* Math.sin(2 * ecliptic_longitude * PI / 180) - 0.053 * Math.sin(4 * ecliptic_longitude * PI / 180));
}
double e(double h, double glat, double sun_deviation) {
return 180
/ PI
* Math.acos((Math.sin(h * PI / 180) - Math.sin(glat * PI / 180) * Math.sin(sun_deviation * PI / 180))
/ (Math.cos(glat * PI / 180) * Math.cos(sun_deviation * PI / 180)));
}
double UT_rise(double UTo, double GHA, double glong, double e) {
return (UTo - (GHA + glong + e));
}
double UT_set(double UTo, double GHA, double glong, double e) {
return (UTo - (GHA + glong - e));
}
double result_rise(double UT, double UTo, double glong, double glat, int year, int month, int date) {
double d;
if (UT >= UTo)
d = UT - UTo;
else
d = UTo - UT;
if (d >= 0.1) {
UTo = UT;
UT = UT_rise(
UTo,
GHA(UTo,
G_sun(t_century(days(year, month, date), UTo)),
ecliptic_longitude(L_sun(t_century(days(year, month, date), UTo)),
G_sun(t_century(days(year, month, date), UTo)))),
glong,
e(h,
glat,
sun_deviation(
earth_tilt(t_century(days(year, month, date), UTo)),
ecliptic_longitude(L_sun(t_century(days(year, month, date), UTo)),
G_sun(t_century(days(year, month, date), UTo))))));
result_rise(UT, UTo, glong, glat, year, month, date);
}
return UT;
}
double result_set(double UT, double UTo, double glong, double glat, int year, int month, int date) {
double d;
if (UT >= UTo)
d = UT - UTo;
else
d = UTo - UT;
if (d >= 0.1) {
UTo = UT;
UT = UT_set(
UTo,
GHA(UTo,
G_sun(t_century(days(year, month, date), UTo)),
ecliptic_longitude(L_sun(t_century(days(year, month, date), UTo)),
G_sun(t_century(days(year, month, date), UTo)))),
glong,
e(h,
glat,
sun_deviation(
earth_tilt(t_century(days(year, month, date), UTo)),
ecliptic_longitude(L_sun(t_century(days(year, month, date), UTo)),
G_sun(t_century(days(year, month, date), UTo))))));
result_set(UT, UTo, glong, glat, year, month, date);
}
return UT;
}
int Zone(double glong) {
if (glong >= 0)
return (int) ((int) (glong / 15.0) + 1);
else
return (int) ((int) (glong / 15.0) - 1);
}
private double glat, glong;
private double rise, set;
public void init() {
Log.d(TAG, "init");
glat = latDegree + latDinute / 60 + latSecond / 3600;
// dd.input_glong(c);
// c = new int[] { 118, 74, 0234 };
glong = longDegree + longDinute / 60 + longSecond / 3600;
rise = result_rise(
UT_rise(UTo,
GHA(UTo,
G_sun(t_century(days(year, month, date), UTo)),
ecliptic_longitude(L_sun(t_century(days(year, month, date), UTo)),
G_sun(t_century(days(year, month, date), UTo)))),
glong,
e(h,
glat,
sun_deviation(
earth_tilt(t_century(days(year, month, date), UTo)),
ecliptic_longitude(L_sun(t_century(days(year, month, date), UTo)),
G_sun(t_century(days(year, month, date), UTo)))))), UTo, glong, glat,
year, month, date);
set = result_set(
UT_set(UTo,
GHA(UTo,
G_sun(t_century(days(year, month, date), UTo)),
ecliptic_longitude(L_sun(t_century(days(year, month, date), UTo)),
G_sun(t_century(days(year, month, date), UTo)))),
glong,
e(h,
glat,
sun_deviation(
earth_tilt(t_century(days(year, month, date), UTo)),
ecliptic_longitude(L_sun(t_century(days(year, month, date), UTo)),
G_sun(t_century(days(year, month, date), UTo)))))), UTo, glong, glat,
year, month, date);
}
public int[] getRiseTime() {
// double times = 0;
int[] times = new int[2];
times[0] = (int) (rise / 15 + Zone(glong));
times[1] = (int) (60 * (rise / 15 + Zone(glong) - (int) (rise / 15 + Zone(glong))));
return times;
}
public int[] getSetTime() {
int[] times = new int[2];
times[0] = (int) (set / 15 + Zone(glong));
times[1] = (int) (60 * (set / 15 + Zone(glong) - (int) (set / 15 + Zone(glong))));
return times;