diff options
Diffstat (limited to 'eclipse')
9 files changed, 229 insertions, 66 deletions
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 @@ <wizard canFinishEarly="false" category="com.android.ide.eclipse.wizards.category" - class="com.android.ide.eclipse.adt.internal.wizards.templates.NewTemplateWizard$NewActivityWizard" + class="com.android.ide.eclipse.adt.internal.wizards.templates.NewActivityWizard" finalPerspective="org.eclipse.jdt.ui.JavaPerspective" hasPages="true" icon="icons/new_adt_project.png" - id="com.android.ide.eclipse.editors.wizards.NewTemplateWizard.Activity" - name="Blank Activity" - preferredPerspectives="org.eclipse.jdt.ui.JavaPerspective" - project="false" /> - <wizard - canFinishEarly="false" - category="com.android.ide.eclipse.wizards.category" - class="com.android.ide.eclipse.adt.internal.wizards.templates.NewTemplateWizard$MasterDetailWizard" - finalPerspective="org.eclipse.jdt.ui.JavaPerspective" - hasPages="true" - icon="icons/new_adt_project.png" - id="com.android.ide.eclipse.editors.wizards.NewTemplateWizard.MasterDetail" - name="Master Detail Flow" + id="com.android.ide.eclipse.editors.wizards.NewActivityWizard" + name="Android Activity" preferredPerspectives="org.eclipse.jdt.ui.JavaPerspective" project="false" /> <wizard diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ImportProjectWizard.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ImportProjectWizard.java index 969537a..9aaf574 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ImportProjectWizard.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/ImportProjectWizard.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 The Android Open Source Project + * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Eclipse Public License, Version 1.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java index 542ffc6..41c88d7 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java @@ -1215,7 +1215,7 @@ public class NewProjectCreator { * @throws FileNotFoundException * @throws CoreException */ - private void addLocalFile(IProject project, File source, String destName, + public static void addLocalFile(IProject project, File source, String destName, IProgressMonitor monitor) throws FileNotFoundException, CoreException { IFile dest = project.getFile(destName); if (dest.exists() == 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 new file mode 100644 index 0000000..a2e3518 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/templates/NewActivityWizard.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.eclipse.org/org/documents/epl-v10.php + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.ide.eclipse.adt.internal.wizards.templates; + +import static com.android.ide.eclipse.adt.internal.wizards.templates.NewProjectWizard.ATTR_MIN_API; +import static com.android.ide.eclipse.adt.internal.wizards.templates.NewProjectWizard.ATTR_MIN_API_LEVEL; +import static com.android.ide.eclipse.adt.internal.wizards.templates.NewProjectWizard.ATTR_PACKAGE_NAME; +import static com.android.ide.eclipse.adt.internal.wizards.templates.NewProjectWizard.ATTR_TARGET_API; +import static org.eclipse.core.resources.IResource.DEPTH_INFINITE; + +import com.android.ide.eclipse.adt.AdtPlugin; +import com.android.ide.eclipse.adt.AdtUtils; +import com.android.ide.eclipse.adt.internal.editors.IconFactory; +import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; + +import java.io.File; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Wizard for creating new activities. This is a hybrid between a New Project + * Wizard and a New Template Wizard: it has the "Activity selector" page from + * the New Project Wizard, which is used to dynamically select a wizard for the + * second page, but beyond that it runs the normal template wizard when it comes + * time to create the template. + */ +public class NewActivityWizard extends Wizard implements INewWizard { + private static final String PROJECT_LOGO_LARGE = "android-64"; //$NON-NLS-1$ + + private IWorkbench mWorkbench; + private UpdateToolsPage mUpdatePage; + private NewProjectPage mMainPage; + private NewTemplatePage mTemplatePage; + private ActivityPage mActivityPage; + private NewProjectWizardState mValues; + private NewTemplateWizardState mActivityValues; + + /** Creates a new {@link NewActivityWizard} */ + public NewActivityWizard() { + } + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + mWorkbench = workbench; + + setWindowTitle("New Activity"); + setHelpAvailable(false); + ImageDescriptor desc = IconFactory.getInstance().getImageDescriptor(PROJECT_LOGO_LARGE); + setDefaultPageImageDescriptor(desc); + + if (!UpdateToolsPage.isUpToDate()) { + mUpdatePage = new UpdateToolsPage(); + } + + mValues = new NewProjectWizardState(); + mActivityPage = new ActivityPage(mValues); + + mActivityValues = mValues.activityValues; + List<IProject> 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<String> 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<String, Object> 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<String> 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<String, Object> paramMap = new HashMap<String, Object>(); 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; } } |