DDRefactoringPluginDemo

This is an example illustration DroidDevelop plugins creation.

This is open source project which avail on http://code.google.com/p/dd-refactoring-plugin-demo/.

You also can download it on the Android Market: https://market.android.com/details?id=com.assoft.DDRefactoringPluginDemo


To create your self plugin you need makes next steps:

1. Add next strings in your activity declaration in the AndroidManifest.xml file:

       <intent-filter>          
         
<action android:name="com.assoft.DroidDevelop.getRefactCommandsNames" />
         
<category android:name="android.intent.category.DEFAULT" />
       
</intent-filter>       <intent-filter>          
         
<action android:name="com.assoft.DroidDevelop.processRefactCommand" />
         
<category android:name="android.intent.category.DEFAULT" />
       
</intent-filter>

2. In your main activity your need to programming reaction to "com.assoft.DroidDevelop.getRefactCommandsNames" intent action.

For this you need set your command names separated by "|" as intent data.

For example:

     Intent I = getIntent();
     
if (I == null)
     
{
        finishActivity
(RESULT_CANCELED);
       
return;
     
}
     
if (I.getAction().contentEquals("com.assoft.DroidDevelop.getRefactCommandsNames"))
     
{
        I
.setData("Command1|Command2|Command3");
        setResult
(RESULT_OK, I);
     
}
 

3. At last your need to programming reaction to "com.assoft.DroidDevelop.processRefactCommand" intent action.

In this case you can access to next variables:

- command name

- current DroidDevelop editor content

- current DroidDevelop editor selection start

- current DroidDevelop editor selection end

You can access to this variables by next code:

         Intent intent = getIntent();
         
if (intent == null)
           
return;
         
String name = intent.getStringExtra("android.intent.extra.Name");
         
String text = intent.getStringExtra("android.intent.extra.Text");
         
int start = intent.getIntExtra("android.intent.extra.SelectionStart", 0);
         
int end = intent.getIntExtra("android.intent.extra.SelectionEnd", 0);
 

After process your command you need to set your result text and selection back to intent.

For example:

         if (name == "Clear Text")
         
{
            intent
.putExtra("android.intent.extra.SelectionStart", 0);
            intent
.putExtra("android.intent.extra.SelectionEnd", 0);
            intent
.setData(Uri.parse(""));        
            setResult
(RESULT_OK, intent);
         
}

Comments