FORUMS
Remove All Ads from XDA

[GUIDE] AutomateIt Plug-in Development

381 posts
Thanks Meter: 232
 
By Muzikant, Inactive Recognized Developer on 26th March 2014, 02:08 PM
Post Reply Email Thread
Prerequisite
Don't know what is AutomateIt ? Read more on this thread.

What is AutomateIt Plugin ?
Plugins are applications that by installing them, you add new actions and triggers that you can use within AutomateIt. Sounds easy, right ?
Each plugin can provide additional triggers and actions that extend the capabilities of AutomateIt, so you can focus on the functionality and take advantage of the AutomateIt platform to connect each trigger or action with existing capabilities of AutomateIt or with other plugins.

More details and a list of available plugins are available on the app website.

Getting started
Although developing a plugin is super-easy and requires only several simple steps, you are deeply encouraged to read the full documentation on the app website.
To summarize it for you, here are the steps you need to follow when developing a new plugin:Setting up your environment after downloading the plugin SDK is done by adding a single dependency needs to be added to your build.gradle file:
Code:
compile 'com.automateitapp:automateit.plugin.sdk:1.0.3'
Creating a new plugin action or trigger is done by implementing a class that extends either PluginAction or PluginTrigger in your plugin project that references the AutomateItPluginLibrary.

Each of these abstract classes requires a set of simple functions to be implemented that provide metadata for the action or trigger (such as title, description, icons and parameters) and the functionality of the action or trigger. See sample code below for an action that shows a Toast message.

a complete sample app is available as a git repo that can be cloned from here.

When the plugin app is installed on a user device, it communicates with AutomateIt so that the plugin actions and triggers become available within AutomateIt.

Additional Documentation
Looking forward to seeing some awesome plugins !

Sample Action Code
Code:
package com.smarterapps.demoplugin.actions;

import java.util.List;

import android.content.Context;
import android.widget.Toast;

import com.smarterapps.automateitplugin.sdk.PluginDataFieldCollection;
import com.smarterapps.automateitplugin.sdk.PluginValidationResult;
import com.smarterapps.automateitplugin.sdk.RequiredApp;
import com.smarterapps.automateitplugin.sdk.fields.PluginDataFieldBoolean;
import com.smarterapps.automateitplugin.sdk.fields.PluginDataFieldString;
import com.smarterapps.demoplugin.R;

public class Action1 extends com.smarterapps.automateitplugin.sdk.PluginAction
{
	private static final int FIELD_ID_TEXT_TO_SHOW = 1;
	private static final int FIELD_ID_DURATION_LONG = 2;

	@Override
	public String getActionTitle(Context context)
	{
		return context.getString(R.string.action1_title);
	}

	@Override
	public String getActionDescription(Context context)
	{
		return context.getString(R.string.action1_default_description);
	}

	@Override
	public String getActionDescription(Context context, PluginDataFieldCollection data)
	{
		if (null != data)
		{
			String msgText = (String) data.getFieldById(FIELD_ID_TEXT_TO_SHOW).getValue();
			boolean durationLong = (Boolean) data.getFieldById(FIELD_ID_DURATION_LONG).getValue();

			int toastDurationStringId = durationLong ? R.string.duration_long: R.string.duration_short;

			return context.getString(R.string.action1_description,
					context.getString(toastDurationStringId),
					msgText);
		}

		return getActionDescription(context);
	}

	@Override
	public int getActionIconResourceId()
	{
		return R.drawable.ic_action1;
	}

	@Override
	public int getActionSmallIconResourceId()
	{
		return R.drawable.ic_action1_small;
	}

	@Override
	public PluginDataFieldCollection getActionFields(Context context)
	{
		PluginDataFieldCollection retval = new PluginDataFieldCollection();

		retval.add(new PluginDataFieldBoolean(
				FIELD_ID_DURATION_LONG, 
				context.getString(R.string.action1_field_duration_title), 
				context.getString(R.string.action1_field_duration_description),
				true));

		retval.add(new PluginDataFieldString(
				FIELD_ID_TEXT_TO_SHOW,
				context.getString(R.string.action1_field_msg_title),
				context.getString(R.string.action1_field_msg_description),
				""));

		return retval;
	}

	@Override
	public void doAction(Context context, PluginDataFieldCollection data)
	{
		boolean durationLong = (Boolean) data.getFieldById(FIELD_ID_DURATION_LONG).getValue();
		int toastDuration = durationLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;

		String toastMsg = (String) data.getFieldById(FIELD_ID_TEXT_TO_SHOW).getValue();
		Toast.makeText(context, toastMsg, toastDuration).show();
	}

	@Override
	public PluginValidationResult validateData(Context context, PluginDataFieldCollection data)
	{
		// Validate action1
		String toastMsg = (String) data.getFieldById(FIELD_ID_TEXT_TO_SHOW).getValue();

		if (null == toastMsg || toastMsg.trim().length() == 0)
		{
			return new PluginValidationResult(false, "Toast message can't be empty");
		}

		return PluginValidationResult.getValidResult();
	}

	@Override
	public List<RequiredApp> getRequiredApps()
	{
		return null;
	}
}
 
 
10th February 2015, 11:07 AM |#2  
Muzikant's Avatar
OP Inactive Recognized Developer
Thanks Meter: 232
 
More
AutomateIt Plugin SDK has been updated so it is now even easier to integrate actions and triggers into your apps, or build a brand new plugin.
It requires a single dependency in your build.gradle file and the rest is up to you!

Sample app is available as a git repo on bitbucket.org:
https://bitbucket.org/AutomateIt/automateit-plugin-demo

(Instructions were updated on the developer website and this post).
Post Reply Subscribe to Thread

Tags
automateit, automation, extension, plugin
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes