-
-
Notifications
You must be signed in to change notification settings - Fork 61
Interfaces
com.forrestguice.suntimeswidget.SuntimesActivity
To open the main activity and highlight the time of the next sunset.
Intent intent = new Intent();
intent.setComponent("com.forrestguice.suntimeswidget", "com.forrestguice.suntimeswidget.SuntimesActivity");
intent.setAction("suntimes.action.SEEK_NOTE");
intent.putExtra("solarevent", "SUNSET");
startActivity(intent);
The following solarevent
identifiers are recognized:
MORNING_ASTRONOMICAL
, MORNING_NAUTICAL
, MORNING_BLUE8
, MORNING_CIVIL
, MORNING_BLUE4
, SUNRISE
, MORNING_GOLDEN
, NOON
, EVENING_GOLDEN
, SUNSET
, EVENING_BLUE4
, EVENING_CIVIL
, EVENING_BLUE8
, EVENING_NAUTICAL
, EVENING_ASTRONOMICAL
, MOONRISE
, MOONSET
.
com.forrestguice.suntimeswidget.alarmclock.ui.AlarmClockActivity
To schedule an alarm create an Intent with the ACTION_SET_ALARM
action.
Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
intent.putExtra(AlarmClock.EXTRA_MESSAGE, "My Alarm");
intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
intent.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
startActivity(intent);
This is the same as scheduling using the Android Alarm Clock, where EXTRA_MESSAGE
, EXTRA_HOUR
, and EXTRA_MINUTES
are expected parameters. Other standard extras include; AlarmClock.EXTRA_VIBRATE
, AlarmClock.EXTRA_RINGTONE
, AlarmClock.EXTRA_SKIP_UI
, and AlarmClock.EXTRA_DAYS
.
See https://developer.android.com/reference/android/provider/AlarmClock.
The alarmtype
extra is a Suntimes Alarms feature that overrides the alarm type. The following values are recognized:
ALARM
(default), NOTIFICATION
.
The timezone
extra is a Suntimes Alarms features indicating a timezoneID should be applied to the hour and minute values. Use special values Local Mean Time
or Apparent Solar Time
to specify hours and minutes in solar time.
The solarevent
extra is a Suntimes Alarms feature that overrides the hour and minute using the specified solar event.
The following solar event identifiers are recognized:
MORNING_ASTRONOMICAL
, MORNING_NAUTICAL
, MORNING_BLUE8
, MORNING_CIVIL
, MORNING_BLUE4
, SUNRISE
, MORNING_GOLDEN
, NOON
, EVENING_GOLDEN
, SUNSET
, EVENING_BLUE4
, EVENING_CIVIL
, EVENING_BLUE8
, EVENING_NAUTICAL
, EVENING_ASTRONOMICAL
, MOONRISE
, MOONSET
.
Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
intent.putExtra("solarevent", "SUNRISE");
startActivity(intent);
The latitude
, longitude
, and altitude
extras allow overriding the event location (defaults to the app location). If these extras are supplied, the location_label
extra can also be supplied to set the place name.
Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
intent.putExtra("alarmtype", "notification");
intent.putExtra("solarevent", "SUNSET");
intent.putExtra("latitude", 35.0); // dd (double)
intent.putExtra("longitude", -112.0); // dd (double)
intent.putExtra("altitude", 1000); // meters (double)
intent.putExtra("location_label", "The Place"); // label (String; may be null)
startActivity(intent);
com.forrestguice.suntimeswidget.settings.colors.ColorActivity
To use the color picker create an Intent (either implicit or explicit) with the Intent.ACTION_PICK
action and a color://
data uri.
ArrayList<Integer> recentColors = new ArrayList<>();
recentColors.add(Color.RED);
int color = Color.GREEN;
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setData(Uri.parse("color://" + String.format("#%08X", color))); // selected color as uri fragment; color://#hexColor
//intent.putExtra("color", color); // selected color as an int (another way to do same as above)
// may be necessary to make Intent explicit depending on Android version
//intent.setComponent("com.forrestguice.suntimeswidget", "com.forrestguice.suntimeswidget.settings.colors.ColorActivity");
intent.putExtra("showAlpha", false); // show alpha slider
intent.putExtra("recentColors", recentColors); // show "recent" palette of colors
startActivityForResult(intent, REQUEST_CODE);
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK && resultCode == REQUEST_CODE)
{
int color;
Uri uri = data.getData();
if (uri != null)
{
try {
color = Color.parseColor("#" + uri.getFragment());
// color = color data.getIntExtra("color", 0); // another way to do the same as above
onColorPicked(color); // do something with returned value
} catch (IllegalArgumentException e) {
Log.e("onActivityResult", "bad color uri; " + e);
}
}
}
}
com.forrestguice.suntimeswidget.actions.ActionListActivity
Requires permission suntimes.permission.READ_CALCULATOR
.
com.forrestguice.suntimeswidget.getfix.PlacesActivity
Requires permission suntimes.permission.READ_CALCULATOR
.
com.forrestguice.suntimeswidget.themes.WidgetThemeListActivity
Requires permission suntimes.permission.READ_CALCULATOR
.
com.forrestguice.suntimeswidget.SuntimesWidgetListActivity
Requires permission suntimes.permission.READ_CALCULATOR
.
com.forrestguice.suntimeswidget.SuntimesSettingsActivity
Settings Fragments | |
---|---|
General Prefs | com.forrestguice.suntimeswidget.SuntimesSettingsActivity$GeneralPrefsFragment |
Alarm Prefs | com.forrestguice.suntimeswidget.SuntimesSettingsActivity$AlarmPrefsFragment |
Calendar Prefs | com.forrestguice.suntimeswidget.SuntimesSettingsActivity$CalendarPrefsFragment |
Locale Prefs | com.forrestguice.suntimeswidget.SuntimesSettingsActivity$LocalePrefsFragment |
Places Prefs | com.forrestguice.suntimeswidget.SuntimesSettingsActivity$PlacesPrefsFragment |
UI Prefs | com.forrestguice.suntimeswidget.SuntimesSettingsActivity$UIPrefsFragment |
Requires permission suntimes.permission.READ_CALCULATOR
.
Bundle extras = new Bundle(); // show general preference fragment
extras.putString(PreferenceActivity.EXTRA_SHOW_FRAGMENT, "com.forrestguice.suntimeswidget.SuntimesSettingsActivity$GeneralPrefsFragment");
extras.putBoolean(PreferenceActivity.EXTRA_NO_HEADERS, true);
Intent intent = new Intent();
intent.setComponent("com.forrestguice.suntimeswidget", "com.forrestguice.suntimeswidget.SuntimesSettingsActivity");
intent.putExtras(extras);
startActivity(intent);
TODO: (Re)configure activity intent & extras. TODO: widget list, theme list
A set of content providers allow add-on apps to access information managed by the main app.
See CalculatorProviderContract
This provider permits third-party access to implementations of the SuntimesCalculator interface (and supporting configuration data).
Calculator Provider |
---|
URI: content://suntimeswidget.calculator.provider
|
Requires: suntimes.permission.READ_CALCULATOR
|
Since: v0.10.0 |
This provider can be used to retrieve user defined colors. It can be used in conjunction with the Theme List activity.
Theme Provider |
---|
URI: content://suntimeswidget.theme.provider
|
Requires: suntimes.permission.READ_CALCULATOR
|
Since: v0.12.8 |
// Gets the time of all full moons occurring between `startDate` to `endDate`:
String[] projection = new String[] { COLUMN_MOON_FULL };
Uri uri = Uri.parse("content://" + AUTHORITY + "/" + QUERY_MOONPHASE + "/"
+ startDate.getTimeInMillis() + "-" + endDate.getTimeInMillis());
ContentResolver resolver = context.getContentResolver();
Cursor cursor = resolver.query(uri, projection, null, null, null);
if (cursor != null
{
cursor.moveToFirst();
while (!cursor.isAfterLast())
{
Long fullMoonTimeMillis = cursor.getLong(cursor.getColumnIndex(COLUMN_MOON_FULL));
if (fullMoonTimeMillis != null) {
// ...
}
cursor.moveToNext();
}
cursor.close();
}
A set of interfaces allow tighter addon integration with the main app. These interfaces are content-provider-contracts defined by Suntimes, and implemented by each addon.
Addons can supply custom alarms to SuntimesAlarms; TBD in v0.14.0
.
See CalendarHelper
Addons can supply custom calendars to SuntimesCalendar.
Addons need to declare the availability of their calendar provider(s) in the manifest with an intent-filter and with meta-data (containing a | delimited list of provider's URI).
<meta-data android:name="SuntimesCalendarReference" android:value="content://calendar.provider1|content://calendar.provider2|..." />
<intent-filter>
<action android:name="suntimes.action.ADD_CALENDAR" />
<category android:name="suntimes.SUNTIMES_CALENDAR" />
</intent-filter>
The app uses an interface to perform all calculations. To add a new calculator you must first implement SuntimesCalculator
, and then publish a SuntimesCalculatorDescriptor
.
TODO
The default calculators are defined in SuntimesCalculatorDescriptor.initCalculators()
. Add a call to addValue
that initializes your descriptor with the rest of the defaults, then recompile the app.
It is also possible to dynamically add calculators without recompiling by publishing the descriptor from the AndroidManifest.xml
.
Create a new project with a single Activity and an implementation of the interface. Supposing our calculator implementation is MySuntimesCalculator.java
, the project manifest might look like...
<activity android:name="com.example.MyCalculatorPlugin">
<meta-data android:name="CalculatorName" android:value="mycalculatorname" />
<meta-data android:name="CalculatorDisplayString" android:value="My Calculator" />
<meta-data android:name="CalculatorReference" android:value="com.example.MySuntimesCalculator" />
<meta-data android:name="CalculatorFeatures" android:value="0,30" />
<intent-filter>
<action android:name="android.intent.action.RUN" />
<category android:name="com.forrestguice.suntimeswidget.SUNTIMES_CALCULATOR" />
</intent-filter>
</activity>
...where CalculatorName
, CalculatorDisplayString
, CalculatorReference
, and CalculatorFeatures
match the values defined by our implementation. The MyCalculatorPlugin
activity itself can be empty (or optionally shown by the launcher to display "about" info).
Compile the new project and install the resulting apk.
When the data source plugins
option is enabled, Suntimes will automatically scan for activities that provide the RUN
action and attempt to load a descriptor.