From 419015cfd365a3b2a2763207d3f42ba24e2a3ea1 Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Mon, 11 Jun 2012 15:58:12 -0700 Subject: Add Activity Wizard The "Android Application" wizard has an embedded "activity chooser" page, and based on your selection the next page shows the configuration page for that activity. This changeset removes the two top level wizards for creating activities ("New Blank Activity" and "New Master/Detail"), with a single "New Activity" wizard whose first page is the activity chooser, and second page is the same as it was under the two individual wizards. Other than making the menu simpler this also has the advantage that it will pull in additional activities we register in the activities folder (updated separately from ADT). Change-Id: Iceef00178c4a0ceecc112db39f350285b7a223f7 --- .../plugins/com.android.ide.eclipse.adt/plugin.xml | 17 +- .../wizards/newproject/ImportProjectWizard.java | 2 +- .../wizards/newproject/NewProjectCreator.java | 2 +- .../wizards/templates/NewActivityWizard.java | 174 +++++++++++++++++++++ .../internal/wizards/templates/NewProjectPage.java | 11 +- .../wizards/templates/NewProjectWizard.java | 17 ++ .../wizards/templates/NewTemplateWizard.java | 42 +---- .../wizards/templates/NewTemplateWizardState.java | 2 - .../wizards/templates/TemplateHandler.java | 28 +++- 9 files changed, 229 insertions(+), 66 deletions(-) create mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewActivityWizard.java diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml b/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml index 0f9830c..c2e65ea 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml +++ b/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml @@ -268,23 +268,12 @@ - projects = AdtUtils.getSelectedProjects(selection); + if (projects.size() == 1) { + mActivityValues.project = projects.get(0); + } + } + + @Override + public void addPages() { + if (mUpdatePage != null) { + addPage(mUpdatePage); + } + + addPage(mActivityPage); + } + + @Override + public IWizardPage getStartingPage() { + if (mUpdatePage != null && mUpdatePage.isPageComplete()) { + return mMainPage; + } + return super.getStartingPage(); + } + + @Override + public IWizardPage getNextPage(IWizardPage page) { + if (page == mActivityPage) { + if (mTemplatePage == null) { + Set hidden = mActivityValues.hidden; + hidden.add(ATTR_PACKAGE_NAME); + hidden.add(ATTR_MIN_API); + hidden.add(ATTR_MIN_API_LEVEL); + hidden.add(ATTR_TARGET_API); + + mTemplatePage = new NewTemplatePage(mActivityValues, true); + addPage(mTemplatePage); + } + return mTemplatePage; + } + + return super.getNextPage(page); + } + + @Override + public boolean canFinish() { + // Deal with lazy creation of some pages: these may not be in the page-list yet + // since they are constructed lazily, so consider that option here. + if (mTemplatePage == null || !mTemplatePage.isPageComplete()) { + return false; + } + + return super.canFinish(); + } + + @Override + public boolean performFinish() { + try { + Shell shell = getShell(); + if (shell != null) { + shell.setVisible(false); + } + IProject project = mActivityValues.project; + File outputPath = AdtUtils.getAbsolutePath(project).toFile(); + assert mValues.createActivity; + NewTemplateWizardState activityValues = mValues.activityValues; + Map parameters = activityValues.parameters; + ManifestInfo manifest = ManifestInfo.get(project); + parameters.put(ATTR_PACKAGE_NAME, manifest.getPackage()); + parameters.put(ATTR_MIN_API, manifest.getMinSdkVersion()); + parameters.put(ATTR_MIN_API_LEVEL, manifest.getMinSdkName()); + parameters.put(ATTR_TARGET_API, manifest.getTargetSdkVersion()); + TemplateHandler activityTemplate = activityValues.getTemplateHandler(); + activityTemplate.setBackupMergedFiles(false); + activityTemplate.render(outputPath, parameters); + List filesToOpen = activityTemplate.getFilesToOpen(); + + try { + project.refreshLocal(DEPTH_INFINITE, new NullProgressMonitor()); + } catch (CoreException e) { + AdtPlugin.log(e, null); + } + + // Open the primary file/files + NewTemplateWizard.openFiles(project, filesToOpen, mWorkbench); + + return true; + } catch (Exception ioe) { + AdtPlugin.log(ioe, null); + return false; + } + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java index 869fc2f..b6993c7 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewProjectPage.java @@ -18,7 +18,6 @@ package com.android.ide.eclipse.adt.internal.wizards.templates; import static com.android.ide.eclipse.adt.AdtUtils.extractClassName; import static com.android.ide.eclipse.adt.internal.wizards.templates.NewTemplatePage.WIZARD_PAGE_WIDTH; -import static com.android.tools.lint.detector.api.LintUtils.assertionsEnabled; import com.android.annotations.Nullable; import com.android.ide.eclipse.adt.AdtPlugin; @@ -309,11 +308,11 @@ public class NewProjectPage extends WizardPage super.setVisible(visible); // DURING DEVELOPMENT ONLY - if (assertionsEnabled()) { - String uniqueProjectName = AdtUtils.getUniqueProjectName("Test", ""); - mProjectText.setText(uniqueProjectName); - mPackageText.setText("test.pkg"); - } + //if (assertionsEnabled()) { + // String uniqueProjectName = AdtUtils.getUniqueProjectName("Test", ""); + // mProjectText.setText(uniqueProjectName); + // mPackageText.setText("test.pkg"); + //} validatePage(); } 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 9147063..1de4b2c 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 @@ -27,6 +27,7 @@ import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.wizards.newproject.NewProjectCreator; import com.android.ide.eclipse.adt.internal.wizards.newproject.NewProjectCreator.ProjectPopulator; import com.android.ide.eclipse.adt.internal.wizards.newxmlfile.NewXmlFileWizard; +import com.android.sdklib.SdkConstants; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -232,6 +233,22 @@ public class NewProjectWizard extends Wizard implements INewWizard { ProjectPopulator projectPopulator = new ProjectPopulator() { @Override public void populate(IProject project) { + // Copy in the proguard file; templates don't provide this one. + // add the default proguard config + File libFolder = new File(AdtPlugin.getOsSdkToolsFolder(), + SdkConstants.FD_LIB); + try { + assert project == newProject; + NewProjectCreator.addLocalFile(project, + new File(libFolder, SdkConstants.FN_PROJECT_PROGUARD_FILE), + // Write ProGuard config files with the extension .pro which + // is what is used in the ProGuard documentation and samples + SdkConstants.FN_PROJECT_PROGUARD_FILE, + new NullProgressMonitor()); + } catch (Exception e) { + AdtPlugin.log(e, null); + } + // Generate basic output skeleton Map paramMap = new HashMap(); paramMap.put(ATTR_PACKAGE_NAME, mValues.packageName); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizard.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizard.java index 143db78..28f5ca6 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizard.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizard.java @@ -50,11 +50,9 @@ import java.util.Set; * Template wizard which creates parameterized templates */ public class NewTemplateWizard extends Wizard implements INewWizard { - /** Template name and location under /templates in the plugin */ + /** Template name and location under $sdk/templates for the default activity */ static final String BLANK_ACTIVITY = "activities/BlankActivity"; //$NON-NLS-1$ - /** Template name and location under /templates in the plugin */ - static final String MASTER_DETAIL_FLOW = "activities/MasterDetailFlow"; //$NON-NLS-1$ - /** Template name and location under /templates in the plugin */ + /** Template name and location under $sdk/templates for the custom view template */ static final String CUSTOM_VIEW = "other/CustomView"; //$NON-NLS-1$ private static final String PROJECT_LOGO_LARGE = "android-64"; //$NON-NLS-1$ @@ -209,42 +207,6 @@ public class NewTemplateWizard extends Wizard implements INewWizard { } /** - * Specific New Master Detail Flow wizard - */ - public static class MasterDetailWizard extends NewTemplateWizard { - /** Creates a new {@link MasterDetailWizard} */ - public MasterDetailWizard() { - super(MASTER_DETAIL_FLOW); - } - - @Override - public void init(IWorkbench workbench, IStructuredSelection selection) { - super.init(workbench, selection); - setWindowTitle("New Master Detail Flow"); - super.mMainPage.setTitle("New Master Detail Flow"); - super.mMainPage.setDescription("Creates a new Master Detail Flow"); - } - } - - /** - * Specific New Blank Activity wizard - */ - public static class NewActivityWizard extends NewTemplateWizard { - /** Creates a new {@link NewActivityWizard} */ - public NewActivityWizard() { - super(BLANK_ACTIVITY); - } - - @Override - public void init(IWorkbench workbench, IStructuredSelection selection) { - super.init(workbench, selection); - setWindowTitle("New Blank Activity"); - super.mMainPage.setTitle("New Blank Activity"); - super.mMainPage.setDescription("Creates a new blank activity"); - } - } - - /** * Specific New Custom View wizard */ public static class NewCustomViewWizard extends NewTemplateWizard { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizardState.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizardState.java index 1fb73d8..aaf1a6a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizardState.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewTemplateWizardState.java @@ -89,6 +89,4 @@ public class NewTemplateWizardState { File getTemplateLocation() { return mTemplateLocation; } - - } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java index f22a742..ee6115f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/TemplateHandler.java @@ -17,6 +17,7 @@ package com.android.ide.eclipse.adt.internal.wizards.templates; import static com.android.ide.eclipse.adt.AdtConstants.DOT_FTL; import static com.android.ide.eclipse.adt.AdtConstants.DOT_XML; +import static com.android.sdklib.SdkConstants.FD_EXTRAS; import static com.android.sdklib.SdkConstants.FD_TEMPLATES; import static com.android.sdklib.SdkConstants.FD_TOOLS; @@ -277,7 +278,20 @@ class TemplateHandler { public static File getTemplateRootFolder() { String location = AdtPrefs.getPrefs().getOsSdkFolder(); if (location != null) { - File folder = new File(location, FD_TOOLS + File.separator + FD_TEMPLATES); + File folder = new File(location, FD_TOOLS + File.separator + FD_TEMPLATES); + if (folder.isDirectory()) { + return folder; + } + } + + return null; + } + + @Nullable + public static File getExtraTemplateRootFolder() { + String location = AdtPrefs.getPrefs().getOsSdkFolder(); + if (location != null) { + File folder = new File(location, FD_EXTRAS + File.separator + FD_TEMPLATES); if (folder.isDirectory()) { return folder; } @@ -300,7 +314,6 @@ class TemplateHandler { } return null; - } @Nullable @@ -941,6 +954,17 @@ class TemplateHandler { } } + // Add in templates from extras/ as well. + root = getExtraTemplateRootFolder(); + if (root != null) { + File[] files = new File(root, folder).listFiles(); + if (files != null) { + for (File file : files) { + templates.add(file); + } + } + } + return templates; } } -- cgit v1.1