Skip to content

Interfaces

Forrest Guice edited this page Oct 26, 2020 · 43 revisions

Public Interfaces

Intent

Alarm Clock

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);

Color Picker

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);
            }
        }
    }
}

Action List

com.forrestguice.suntimeswidget.actions.ActionListActivity

Requires permission suntimes.permission.READ_CALCULATOR.

Places List

com.forrestguice.suntimeswidget.getfix.PlacesActivity

Requires permission suntimes.permission.READ_CALCULATOR.

Theme List

com.forrestguice.suntimeswidget.themes.WidgetThemeListActivity

Requires permission suntimes.permission.READ_CALCULATOR.

Widget List

com.forrestguice.suntimeswidget.SuntimesWidgetListActivity

Requires permission suntimes.permission.READ_CALCULATOR.

Settings

com.forrestguice.suntimeswidget.SuntimesSettingsActivity

Requires permission suntimes.permission.READ_CALCULATOR.

Others

TODO: (Re)configure activity intent & extras. TODO: widget list, theme list

Content Provider

A ContentProvider permits third-party access to implementations of the SuntimesCalculator interface (and supporting configuration data).

Calculator Provider

See CalculatorProviderContract

Calculator Provider
URI: content://suntimeswidget.calculator.provider
Requires: suntimes.permission.READ_CALCULATOR
Added: v0.10.0

Theme Provider

See SuntimesThemeContract

Theme Provider
URI: content://suntimeswidget.theme.provider
Requires: suntimes.permission.READ_CALCULATOR
Added: v0.12.8

An Example

// 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();
}       

SuntimesCalculator

The app uses an interface to perform all calculations. To add a new calculator you must first implement SuntimesCalculator, and then publish a SuntimesCalculatorDescriptor.

Implementing the Interface

TODO

Publishing a Descriptor

A) Publish as a default

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.

B) Publish as a plugin

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.

Clone this wiki locally