<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title><![CDATA[DIMPLE.IO Developers]]></title>
    <link href="http://dimple.io/developers/atom.xml" rel="self"/>
    <link href="http://dimple.io/developers/"/>
    <updated>2014-05-04T03:23:58+03:00</updated>
    <id>http://dimple.io/developers/</id>
        <generator uri="http://sculpin.io/">Sculpin</generator>
            <entry>
            <title type="html"><![CDATA[Dimple Plugin SDK]]></title>
            <link href="http://dimple.io/developers/2014/05/03/dimple_plugin_sdk.html"/>
            <updated>2014-05-03T00:00:00+03:00</updated>
            <id>http://dimple.io/developers/2014/05/03/dimple_plugin_sdk.html</id>
            <content type="html"><![CDATA[<p>Dimple Plugin SDK is set of files that can be included in your application to ease creation of plugins. It's available for download <a href="https://github.com/DIMPLE-INC/Plugin-SDK">here</a>. JavaDoc is available <a href="http://dimple.io/developers/sdk-doc/">here</a></p>

<h2>What's included</h2>

<ul>
<li>DimpleConst - Constants used for Dimple plugin intents.</li>
<li>DimplePluginActivity - abstract activity that can be extended for setup of plugins and execution of simple plugin.</li>
<li>DimplePluginBroadcastReceiver - abstract receiver that can be extended to receive long-press plugin events.</li>
</ul>

<h2>Usage</h2>

<h3>Copy all 3 java files into your project</h3>

<p>Files can be found in src folder.</p>

<p>Package of files is not important - files can be placed anywhere in project source directory.</p>

<h3>Create activity that will be used to setup plugin.</h3>

<p>In AndroidManifest.xml file you need to include</p>

<pre><code>&lt;activity android:name="ActivityName"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="io.dimple.action.PLUGIN"/&gt;
        &lt;category android:name="android.intent.category.DEFAULT"/&gt;
    &lt;/intent-filter&gt;
&lt;/activity&gt;
</code></pre>

<p>to list this activity as simple plugin or</p>

<pre><code>&lt;activity android:name="ActivityName"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="io.dimple.action.PLUGIN_LONGPRESS"/&gt;
        &lt;category android:name="android.intent.category.DEFAULT"/&gt;
    &lt;/intent-filter&gt;
&lt;/activity&gt;
</code></pre>

<p>to list this activity as long-press plugin in Dimple (replacing ActivityName with your activity).</p>

<p>In code your activity should extend DimplePluginActivity and implement createPlugin method:</p>

<pre><code>public class ActivityName extends extends DimplePluginActivity
{
    @Override
    public void createPlugin(boolean longPress, int memorySize)
    {
    }
}
</code></pre>

<h3>Send data back to Dimple</h3>

<p>When you have prepared plugin data (it can be in createPlugin method or from user interaction) - you need to send data back to Dimple to add plugin to Dimple button. To do it, you can use method finishCreatingPlugin. If you want to cancel plugin creation, call cancelCreatingPlugin.</p>

<p>Sending back data does not guarantee that plugin will be written to Dimple as user can cancel writing later or remove configured plugin from button list.</p>

<h3>Execute</h3>

<h4>Simple plugin</h4>

<p>Simple plugin execution happens in same activity as setup. Override execute method to react on plugin execution.</p>

<pre><code>@Override
public void execute(byte[] data)
{
}
</code></pre>

<h4>Long-press plugin</h4>

<p>For long-press plugin you need to implement DimplePluginBroadcastReceiver class and make broadcast receiver.</p>

<p>In AndroidManifest.xml file you need to include</p>

<pre><code>&lt;receiver android:name="ReceiverName"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="io.dimple.action.PLUGIN_LONGPRESS"/&gt;
    &lt;/intent-filter&gt;
&lt;/receiver&gt;
</code></pre>

<p>(replacing ReceiverName with your receiver) and in code</p>

<pre><code>public class ReceiverName extends DimplePluginBroadcastReceiver
{
    @Override
    public void onDimpleDown(Context context, byte[] data)
    {
    }

    @Override
    public void onDimpleHold(Context context, long holdLength, byte[] data, long timeSinceLastHoldEvent)
    {
    }

    @Override
    public void onDimpleUp(Context context, long holdLength, byte[] data)
    {
    }
}
</code></pre>
]]></content>
        </entry>
            <entry>
            <title type="html"><![CDATA[How to integrate your plugin into Dimple app]]></title>
            <link href="http://dimple.io/developers/2014/04/30/how_to_write_plugins.html"/>
            <updated>2014-04-30T00:00:00+03:00</updated>
            <id>http://dimple.io/developers/2014/04/30/how_to_write_plugins.html</id>
            <content type="html"><![CDATA[<h2>What is Dimple plugin</h2>

<p>Dimple plugin is activity (both for setup and execution) with <code>io.dimple.action.PLUGIN</code> as action in Intent filter (for just press) or activity (for setup) and broadcast receiver (for execution) with <code>io.dimple.action.PLUGIN_LONGPRESS</code> as action (for long press).  Dimple will list all activities with those actions in "Third party plugins" list. One application can contain multiple plugins.</p>

<p>All communication with Dimple app happens thorugh standart Android appliaction lifecycle and methods.</p>

<h2>Types of Dimple plugins</h2>

<h3>Simple plugin</h3>

<p>Simple plugin is activity that can be started by pressing Dimple. Activity is started with Intent containing data that was set up during set-up phase of plugin. For this plugin setup activity and plugin executor activity is the same.</p>

<h3>Long-press plugin</h3>

<p>Long-press plugin is broadcast listener that can receive three type of events - on Dimple button down, on Dimple hold (interval can be set up during setup) and on Dimple button up. Setup happens through activity that is provided in <code>AndroidManifest.xml</code> file.</p>

<p>Long-press plugins are not compatible with "popup window" feature and using one will disable this feature in UI.</p>

<h2>How to interact with Dimple</h2>

<h3>Preparing activity to be listed as Dimple plugin</h3>

<p>In <code>AndroidManifest.xml</code> file each activity that will be used as plugin  need to have intent filter defined like this:</p>

<pre><code>&lt;activity android:name="PluginActivity"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="io.dimple.action.PLUGIN"/&gt;
          &lt;category android:name="android.intent.category.DEFAULT"/&gt;
      &lt;/intent-filter&gt;
&lt;/activity&gt;
</code></pre>

<p>(Replace <code>"io.dimple.action.PLUGIN"</code> with <code>"io.dimple.action.PLUGIN_LONGPRESS"</code> for long press plugins).</p>

<p>Activity should be able to return result so that activity shouldn't have limitations on how it can be used (f.e. activity can't have <code>launchMode="singleInstance"</code>).</p>

<h3>Plugin start</h3>

<p>When user chooses plugin from plugin list in Dimple app, plugin activity is started with extras. String extra <code>"type"</code> contains value <code>"create"</code> if plugin is started from plugin chooser in Dimple app or <code>"execute"</code>(only if simple plugin) if plugin is started from Dimple press.</p>

<h3>Setting up action</h3>

<p>When plugin is started from Dimple app chooser, Dimple app is waiting for plugin data passed back as activity result. Integer extra <code>"memory"</code> contains maximum array size that can be sent back and still fit Dimple (can vary from launch to launch). To send data back to Dimple app, create Intent with byte[] extra <code>"data"</code> that contains byte array with plugin data and set it as result intent with <code>Activity.RESULT_OK</code> result code afterwards finishing your activity.</p>

<h3>Executing plugin</h3>

<h4>Simple plugin</h4>

<p>When plugin is started from Dimple press, plugin is started in new task and data previously set is passed as byte array extra <code>"data"</code>.</p>

<h4>Long-press plugins</h4>

<p>Dimple press will send broadcast events to application. To get events you need to set up broadcast listener like this</p>

<pre><code>    &lt;receiver android:name=".PluginLongPressBroadcastReceiver"&gt;
        &lt;intent-filter&gt;
            &lt;action android:name="io.dimple.action.PLUGIN_LONGPRESS"/&gt;
        &lt;/intent-filter&gt;
    &lt;/receiver&gt;
</code></pre>

<p>We suggest to have one receiver per app and identify functionality by using data array.</p>

<h3>Show me the code (sample)</h3>

<p>This is plugin that saves String into Dimple and shows it when executed.</p>

<pre><code>@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    final Bundle extras = getIntent().getExtras();
    if (extras != null &amp;&amp; extras.containsKey("type"))
    {
        //Dimple app plugin chooser
        if ("create".equals(extras.getString("type")))
        {
            int bytesLeft = extras.getInt("memory");
            create(bytesLeft);
        }
        //Dimple press
        else if ("execute".equals(extras.getString("type")))
        {
            execute(extras.getByteArray("data"));
        }
        else
        {
            finish();
        }

    }
    else
    {
        finish();
    }
}

public void create(int bytesLeft)
{
    //Preparing data
    String dataString = "Hello world, " + System.currentTimeMillis();
    //Converting data to byte array
    byte[] data = dataString.getBytes(Charset.forName("UTF-8"));

    //Checking if Dimple have enough space
    if (bytesLeft &lt; data.length)
    {
        Toast.makeText(this, "Not enough space",Toast.LENGTH_SHORT).show();
        setResult(RESULT_CANCELED);
        finish();
        return;
    }

    //Sending data back to Dimple
    Intent result = new Intent();
    result.putExtra("data", data);
    setResult(RESULT_OK, result);
    finish();
}

public void execute(byte[] data)
{
    //Setting layout (containing TextView with ID text_output
    setContentView(R.layout.main);

    //Getting back String from data
    String message = new String(data, Charset.forName("UTF-8"));
    //Displaying result to user
    ((TextView) findViewById(R.id.text_output)).setText(message);
}
</code></pre>

<h2>Plugin styling</h2>

<p>Dimple use icon and label information from activitiy record in <code>AndroidManifest.xml</code>. If some of information is missing Dimple falls back to application record. To use distinct icon and label for plugin, set those like in this sample:</p>

<pre><code>    &lt;activity android:name="PluginActivity"
              android:label="@string/plugin_name"
              android:icon="@drawable/ic_plugin"&gt;
</code></pre>

<h2>Tips</h2>

<ul>
<li>If you don't need to save data for plugin, send back <code>new byte[0]</code> as data.</li>
<li>You don't need to send result back immediatly, you can ask user for input, run other activities and do other things Android task lifecycle permits before returning result. [Documentation](http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)) on method used by Dimple.</li>
<li>To optimize for space, choose short activity class names (and package names if possible) and place activity in root of package when creating plugins. Package name and path to activity are saved into Dimple to execute plugin.</li>
</ul>
]]></content>
        </entry>
    </feed>