diff options
author | Xavier Ducrohet <xav@android.com> | 2012-06-21 18:27:33 -0700 |
---|---|---|
committer | android code review <noreply-gerritcodereview@google.com> | 2012-06-21 18:27:34 -0700 |
commit | aec21574e51cc4b8588c7260bcbb478e300a65b5 (patch) | |
tree | f10d34b2d14646612a9981b94aac90e60f624abd | |
parent | e0002cfd9ab930b9c855f970132c8b7dfad2a483 (diff) | |
parent | a85ff38b62bbeb35ace582729a0cf07088d3905a (diff) | |
download | sdk-aec21574e51cc4b8588c7260bcbb478e300a65b5.zip sdk-aec21574e51cc4b8588c7260bcbb478e300a65b5.tar.gz sdk-aec21574e51cc4b8588c7260bcbb478e300a65b5.tar.bz2 |
Merge "More template tweaks"
21 files changed, 328 insertions, 19 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml b/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml index 3ca6d03..5979f74 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml +++ b/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml @@ -290,6 +290,22 @@ <wizard canFinishEarly="false" category="com.android.ide.eclipse.wizards.category" + class="com.android.ide.eclipse.adt.internal.wizards.templates.NewActivityWizard$OtherWizard" + finalPerspective="org.eclipse.jdt.ui.JavaPerspective" + hasPages="true" + icon="icons/newCustomView.png" + id="com.android.ide.eclipse.editors.wizards.NewActivityWizard.OtherWizard" + name="Android Object" + preferredPerspectives="org.eclipse.jdt.ui.JavaPerspective" + project="false" > + <description> + Create an Android object such as a Service, an Activity, a Broadcast Receiver, etc. + </description> + </wizard> + <!-- Available through generic object list above + <wizard + canFinishEarly="false" + category="com.android.ide.eclipse.wizards.category" class="com.android.ide.eclipse.adt.internal.wizards.templates.NewTemplateWizard$NewCustomViewWizard" finalPerspective="org.eclipse.jdt.ui.JavaPerspective" hasPages="true" @@ -302,6 +318,7 @@ Create an Android custom view </description> </wizard> + --> <wizard canFinishEarly="false" category="com.android.ide.eclipse.wizards.category" diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/ActivityPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/ActivityPage.java index 47ed771..7f67a0d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/ActivityPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/ActivityPage.java @@ -16,6 +16,7 @@ package com.android.ide.eclipse.adt.internal.wizards.templates; import static com.android.ide.eclipse.adt.internal.wizards.templates.NewProjectWizard.CATEGORY_ACTIVITIES; +import static com.android.ide.eclipse.adt.internal.wizards.templates.NewProjectWizard.CATEGORY_OTHER; import static com.android.ide.eclipse.adt.internal.wizards.templates.TemplateHandler.PREVIEW_PADDING; import static com.android.ide.eclipse.adt.internal.wizards.templates.TemplateHandler.PREVIEW_WIDTH; @@ -57,16 +58,29 @@ class ActivityPage extends WizardPage implements SelectionListener { private Image mPreviewImage; private Label mHeading; private Label mDescription; + private boolean mOnlyActivities; + private boolean mAskCreate; /** * Create the wizard. */ - ActivityPage(NewProjectWizardState values) { + ActivityPage(NewProjectWizardState values, boolean onlyActivities, boolean askCreate) { super("activityPage"); //$NON-NLS-1$ mValues = values; + mOnlyActivities = onlyActivities; + mAskCreate = askCreate; - setTitle("Create Activity"); - setDescription("Select whether to create an activity, and if so, what kind of activity."); + if (onlyActivities) { + setTitle("Create Activity"); + } else { + setTitle("Create Android Object"); + } + if (onlyActivities && askCreate) { + setDescription( + "Select whether to create an activity, and if so, what kind of activity."); + } else { + setDescription("Select which template to use"); + } } @Override @@ -80,17 +94,23 @@ class ActivityPage extends WizardPage implements SelectionListener { Composite container = (Composite) getControl(); container.setLayout(new GridLayout(3, false)); - mCreateToggle = new Button(container, SWT.CHECK); - mCreateToggle.setSelection(true); - mCreateToggle.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1)); - mCreateToggle.setText("Create Activity"); - mCreateToggle.addSelectionListener(this); + if (mAskCreate) { + mCreateToggle = new Button(container, SWT.CHECK); + mCreateToggle.setSelection(true); + mCreateToggle.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1)); + mCreateToggle.setText("Create Activity"); + mCreateToggle.addSelectionListener(this); + } mList = new List(container, SWT.BORDER | SWT.V_SCROLL); mList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - mTemplates = mValues.template.getManager().getTemplates(CATEGORY_ACTIVITIES); + TemplateManager manager = mValues.template.getManager(); + mTemplates = manager.getTemplates(CATEGORY_ACTIVITIES); + if (!mOnlyActivities) { + mTemplates.addAll(manager.getTemplates(CATEGORY_OTHER)); + } java.util.List<String> names = new ArrayList<String>(mTemplates.size()); File current = mValues.activityValues.getTemplateLocation(); int index = -1; @@ -196,11 +216,13 @@ class ActivityPage extends WizardPage implements SelectionListener { if (visible) { mShown = true; - try { - mIgnore = true; - mCreateToggle.setSelection(mValues.createActivity); - } finally { - mIgnore = false; + if (mAskCreate) { + try { + mIgnore = true; + mCreateToggle.setSelection(mValues.createActivity); + } finally { + mIgnore = false; + } } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewActivityWizard.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewActivityWizard.java index d3099bc..85afe77 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewActivityWizard.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewActivityWizard.java @@ -45,19 +45,21 @@ public class NewActivityWizard extends TemplateWizard { private ActivityPage mActivityPage; private NewProjectWizardState mValues; private NewTemplateWizardState mActivityValues; + protected boolean mOnlyActivities; /** Creates a new {@link NewActivityWizard} */ public NewActivityWizard() { + mOnlyActivities = true; } @Override public void init(IWorkbench workbench, IStructuredSelection selection) { super.init(workbench, selection); - setWindowTitle("New Activity"); + setWindowTitle(mOnlyActivities ? "New Activity" : "New Android Object"); mValues = new NewProjectWizardState(); - mActivityPage = new ActivityPage(mValues); + mActivityPage = new ActivityPage(mValues, mOnlyActivities, false); mActivityValues = mValues.activityValues; List<IProject> projects = AdtUtils.getSelectedProjects(selection); @@ -134,4 +136,12 @@ public class NewActivityWizard extends TemplateWizard { protected List<Change> computeChanges() { return mActivityValues.computeChanges(); } + + /** Wizard for creating other Android components */ + public static class OtherWizard extends NewActivityWizard { + /** Create new {@link OtherWizard} */ + public OtherWizard() { + mOnlyActivities = false; + } + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectWizard.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectWizard.java index 8903495..2da1fb5 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectWizard.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectWizard.java @@ -72,6 +72,7 @@ public class NewProjectWizard extends TemplateWizard { static final String ATTR_APP_TITLE = "appTitle"; //$NON-NLS-1$ static final String CATEGORY_PROJECTS = "projects"; //$NON-NLS-1$ static final String CATEGORY_ACTIVITIES = "activities"; //$NON-NLS-1$ + static final String CATEGORY_OTHER = "other"; //$NON-NLS-1$ private NewProjectPage mMainPage; private ActivityPage mActivityPage; @@ -89,7 +90,7 @@ public class NewProjectWizard extends TemplateWizard { mValues = new NewProjectWizardState(); mMainPage = new NewProjectPage(mValues); - mActivityPage = new ActivityPage(mValues); + mActivityPage = new ActivityPage(mValues, true, true); } @Override diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplatePage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplatePage.java index 815be68..aa35bda 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplatePage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplatePage.java @@ -115,6 +115,8 @@ public class NewTemplatePage extends WizardPage private List<Parameter> mParameters; private StringEvaluator mEvaluator; + private TemplateMetadata mShowingTemplate; + /** * Creates a new {@link NewTemplatePage} * @@ -158,6 +160,12 @@ public class NewTemplatePage extends WizardPage @SuppressWarnings("unused") // SWT constructors have side effects and aren't unused private void onEnter() { + TemplateMetadata template = mValues.getTemplateHandler().getTemplate(); + if (template == mShowingTemplate) { + return; + } + mShowingTemplate = template; + Composite parent = (Composite) getControl(); Control[] children = parent.getChildren(); @@ -198,7 +206,6 @@ public class NewTemplatePage extends WizardPage // Add parameters mFirst = null; - TemplateMetadata template = mValues.getTemplateHandler().getTemplate(); String thumb = null; if (template != null) { thumb = template.getThumbnailPath(); diff --git a/templates/activities/BlankActivity/root/src/app_package/include_onOptionsItemSelected.java.ftl b/templates/activities/BlankActivity/root/src/app_package/include_onOptionsItemSelected.java.ftl index c77fdee..001e08f 100644 --- a/templates/activities/BlankActivity/root/src/app_package/include_onOptionsItemSelected.java.ftl +++ b/templates/activities/BlankActivity/root/src/app_package/include_onOptionsItemSelected.java.ftl @@ -10,4 +10,5 @@ } return super.onOptionsItemSelected(item); } - </#if>
\ No newline at end of file + </#if> + diff --git a/templates/other/BroadcastReceiver/globals.xml.ftl b/templates/other/BroadcastReceiver/globals.xml.ftl new file mode 100644 index 0000000..bfc27eb --- /dev/null +++ b/templates/other/BroadcastReceiver/globals.xml.ftl @@ -0,0 +1,4 @@ +<?xml version="1.0"?> +<globals> + <global id="srcOut" value="src/${slashedPackageName(packageName)}" /> +</globals> diff --git a/templates/other/BroadcastReceiver/recipe.xml.ftl b/templates/other/BroadcastReceiver/recipe.xml.ftl new file mode 100644 index 0000000..a9d2623 --- /dev/null +++ b/templates/other/BroadcastReceiver/recipe.xml.ftl @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<recipe> + <merge from="AndroidManifest.xml.ftl" /> + <instantiate from="src/app_package/BroadcastReceiver.java.ftl" + to="${srcOut}/${className}.java" /> + <open file="${srcOut}/${className}.java" /> +</recipe> diff --git a/templates/other/BroadcastReceiver/root/AndroidManifest.xml.ftl b/templates/other/BroadcastReceiver/root/AndroidManifest.xml.ftl new file mode 100644 index 0000000..d107f00 --- /dev/null +++ b/templates/other/BroadcastReceiver/root/AndroidManifest.xml.ftl @@ -0,0 +1,10 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" > + + <receiver> + <service android:name=".${className}" + android:exported="${isExported?string}" + android:enabled="${isEnabled?string}" > + </service> + </receiver> + +</manifest> diff --git a/templates/other/BroadcastReceiver/root/src/app_package/BroadcastReceiver.java.ftl b/templates/other/BroadcastReceiver/root/src/app_package/BroadcastReceiver.java.ftl new file mode 100644 index 0000000..560c132 --- /dev/null +++ b/templates/other/BroadcastReceiver/root/src/app_package/BroadcastReceiver.java.ftl @@ -0,0 +1,17 @@ +package ${packageName}; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +public class ${className} extends BroadcastReceiver { + public ${className}() { + } + + @Override + public void onReceive(Context context, Intent intent) { + // TODO: This method is called when the BroadcastReceiver is receiving + // an Intent broadcast. + throw new UnsupportedOperationException("Not yet implemented"); + } +} diff --git a/templates/other/BroadcastReceiver/template.xml b/templates/other/BroadcastReceiver/template.xml new file mode 100644 index 0000000..09869ff --- /dev/null +++ b/templates/other/BroadcastReceiver/template.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<template + format="1" + revision="1" + name="New Broadcast Receiver" + description="Creates a new broadcast receiver class"> + + <parameter + id="className" + name="Class Name" + type="string" + constraints="class|unique" + default="MyReceiver" /> + + <parameter + id="isExported" + name="Exported" + type="boolean" + default="true" + help="Whether or not the broadcast receiver can receive messages from sources outside its application" /> + + <parameter + id="isEnabled" + name="Enabled" + type="boolean" + default="true" + help="Whether or not the broadcast receiver can be instantiated by the system" /> + + <globals file="globals.xml.ftl" /> + <execute file="recipe.xml.ftl" /> + +</template> diff --git a/templates/other/ContentProvider/globals.xml.ftl b/templates/other/ContentProvider/globals.xml.ftl new file mode 100644 index 0000000..bfc27eb --- /dev/null +++ b/templates/other/ContentProvider/globals.xml.ftl @@ -0,0 +1,4 @@ +<?xml version="1.0"?> +<globals> + <global id="srcOut" value="src/${slashedPackageName(packageName)}" /> +</globals> diff --git a/templates/other/ContentProvider/recipe.xml.ftl b/templates/other/ContentProvider/recipe.xml.ftl new file mode 100644 index 0000000..6cdad82 --- /dev/null +++ b/templates/other/ContentProvider/recipe.xml.ftl @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<recipe> + <merge from="AndroidManifest.xml.ftl" /> + <instantiate from="src/app_package/ContentProvider.java.ftl" + to="${srcOut}/${className}.java" /> + <open file="${srcOut}/${className}.java" /> +</recipe> diff --git a/templates/other/ContentProvider/root/AndroidManifest.xml.ftl b/templates/other/ContentProvider/root/AndroidManifest.xml.ftl new file mode 100644 index 0000000..6fa4afc --- /dev/null +++ b/templates/other/ContentProvider/root/AndroidManifest.xml.ftl @@ -0,0 +1,11 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" > + + <application> + <provider android:name=".${className}" + android:authorities="${authorities}" + android:exported="${isExported?string}" + android:enabled="${isEnabled?string}" > + </provider> + </application> + +</manifest> diff --git a/templates/other/ContentProvider/root/src/app_package/ContentProvider.java.ftl b/templates/other/ContentProvider/root/src/app_package/ContentProvider.java.ftl new file mode 100644 index 0000000..e5b43b5 --- /dev/null +++ b/templates/other/ContentProvider/root/src/app_package/ContentProvider.java.ftl @@ -0,0 +1,50 @@ +package ${packageName}; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; + +public class ${className} extends ContentProvider { + public ${className}() { + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + // Implement this to handle requests to delete one or more rows. + throw new UnsupportedOperationException("Not yet implemented"); + } + + @Override + public String getType(Uri uri) { + // TODO: Implement this to handle requests for the MIME type of the data + // at the given URI. + throw new UnsupportedOperationException("Not yet implemented"); + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + // TODO: Implement this to handle requests to insert a new row. + throw new UnsupportedOperationException("Not yet implemented"); + } + + @Override + public boolean onCreate() { + // TODO: Implement this to initialize your content provider on startup. + return false; + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, + String[] selectionArgs, String sortOrder) { + // TODO: Implement this to handle query requests from clients. + throw new UnsupportedOperationException("Not yet implemented"); + } + + @Override + public int update(Uri uri, ContentValues values, String selection, + String[] selectionArgs) { + // TODO: Implement this to handle requests to update one or more rows. + throw new UnsupportedOperationException("Not yet implemented"); + } +} diff --git a/templates/other/ContentProvider/template.xml b/templates/other/ContentProvider/template.xml new file mode 100644 index 0000000..c6730d8 --- /dev/null +++ b/templates/other/ContentProvider/template.xml @@ -0,0 +1,40 @@ +<?xml version="1.0"?> +<template + format="1" + revision="1" + name="New Content Provider" + description="Creates a new content provider class"> + + <parameter + id="className" + name="Class Name" + type="string" + constraints="class|unique" + default="MyContentProvider" /> + + <parameter + id="authorities" + name="URI Authorities" + type="string" + constraints="nonempty" + default="" + help="A list of one or more URI authorities that identify data under the purview of the content provider. " /> + + <parameter + id="isExported" + name="Exported" + type="boolean" + default="true" + help="Whether or not the content provider can be used by components of other applications " /> + + <parameter + id="isEnabled" + name="Enabled" + type="boolean" + default="true" + help="Whether or not the content provider can be instantiated by the system " /> + + <globals file="globals.xml.ftl" /> + <execute file="recipe.xml.ftl" /> + +</template> diff --git a/templates/other/Service/globals.xml.ftl b/templates/other/Service/globals.xml.ftl new file mode 100644 index 0000000..bfc27eb --- /dev/null +++ b/templates/other/Service/globals.xml.ftl @@ -0,0 +1,4 @@ +<?xml version="1.0"?> +<globals> + <global id="srcOut" value="src/${slashedPackageName(packageName)}" /> +</globals> diff --git a/templates/other/Service/recipe.xml.ftl b/templates/other/Service/recipe.xml.ftl new file mode 100644 index 0000000..6e4bd57 --- /dev/null +++ b/templates/other/Service/recipe.xml.ftl @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<recipe> + <merge from="AndroidManifest.xml.ftl" /> + <instantiate from="src/app_package/Service.java.ftl" + to="${srcOut}/${className}.java" /> + <open file="${srcOut}/${className}.java" /> +</recipe> diff --git a/templates/other/Service/root/AndroidManifest.xml.ftl b/templates/other/Service/root/AndroidManifest.xml.ftl new file mode 100644 index 0000000..14b0bce --- /dev/null +++ b/templates/other/Service/root/AndroidManifest.xml.ftl @@ -0,0 +1,10 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" > + + <application> + <service android:name=".${className}" + android:exported="${isExported?string}" + android:enabled="${isEnabled?string}" > + </service> + </application> + +</manifest> diff --git a/templates/other/Service/root/src/app_package/Service.java.ftl b/templates/other/Service/root/src/app_package/Service.java.ftl new file mode 100644 index 0000000..571d2b8 --- /dev/null +++ b/templates/other/Service/root/src/app_package/Service.java.ftl @@ -0,0 +1,16 @@ +package ${packageName}; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; + +public class ${className} extends Service { + public ${className}() { + } + + @Override + public IBinder onBind(Intent intent) { + // TODO: Return the communication channel to the service. + throw new UnsupportedOperationException("Not yet implemented"); + } +} diff --git a/templates/other/Service/template.xml b/templates/other/Service/template.xml new file mode 100644 index 0000000..3ce6e6a --- /dev/null +++ b/templates/other/Service/template.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<template + format="1" + revision="1" + name="New Service" + description="Creates a new service class"> + + <parameter + id="className" + name="Class Name" + type="string" + constraints="class|unique" + default="MyService" /> + + <parameter + id="isExported" + name="Exported" + type="boolean" + default="true" + help="Whether or not components of other applications can invoke the service or interact with it" /> + + <parameter + id="isEnabled" + name="Enabled" + type="boolean" + default="true" + help="Whether or not the service can be instantiated by the system" /> + + <globals file="globals.xml.ftl" /> + <execute file="recipe.xml.ftl" /> + +</template> |