Skip to content

Interfaces

Forrest Guice edited this page Jan 31, 2019 · 43 revisions

Public Interfaces

Intent

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); since v0.10.0.

See the CalculatorProviderContract for more information.

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