Java Code Examples for com.android.builder.model.AndroidProject#getBuildToolsVersion()

The following examples show how to use com.android.builder.model.AndroidProject#getBuildToolsVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TvActivityWizardIterator.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(WizardDescriptor wizard) {
    this.wizard = wizard;
    index = 0;
    panels = createPanels();
    // Make sure list of steps is accurate.
    steps = createSteps();
    wizard.putProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0);
    for (int i = 0; i < panels.size(); i++) {
        Component c = panels.get(i).getComponent();
        if (c instanceof JComponent) { // assume Swing components
            JComponent jc = (JComponent) c;
            // Step #.
            // TODO if using org.openide.dialogs >= 7.8, can use WizardDescriptor.PROP_*:
            jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i));
            // Step name (actually the whole list for reference).
            jc.putClientProperty("WizardPanel_contentData", steps.toArray(new String[steps.size()]));
        }
    }
    NewFileWizard fileWizard = (NewFileWizard) wizard;
    try {
        Project project = (Project) wizard.getProperty("project");
        if (AndroidProjects.isAndroidMavenProject(project) && (project instanceof NbAndroidProjectImpl)) {
            NbAndroidProjectImpl gradleProject = (NbAndroidProjectImpl) project;
            File projectDirectory = gradleProject.getProjectDirectoryAsFile();
            DataFolder targetFolder = fileWizard.getTargetFolder();
            String targetPath = targetFolder.getPrimaryFile().getPath();
            BuildVariant buildVariant = project.getLookup().lookup(BuildVariant.class);
            AndroidSources androidSources = project.getLookup().lookup(AndroidSources.class);
            SourceGroup[] sourceGroups = androidSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
            FileObject srcRootFolder = null;
            for (SourceGroup sourceGroup : sourceGroups) {
                if (sourceGroup.contains(targetFolder.getPrimaryFile())) {
                    srcRootFolder = sourceGroup.getRootFolder();
                }
            }
            sourceGroups = androidSources.getSourceGroups(AndroidConstants.ANDROID_MANIFEST_XML);
            FileObject manifestRootFolder = null;
            if (sourceGroups.length == 1) {
                manifestRootFolder = sourceGroups[0].getRootFolder();
            }
            wizard.putProperty(MANIFEST_ROOT_FOLDER, FileUtil.toFile(manifestRootFolder));
            Variant variant = buildVariant.getCurrentVariant();
            wizard.putProperty(BUILD_VARIANT, variant);
            if (srcRootFolder != null) {
                String packageName = targetPath.replace(srcRootFolder.getPath(), "");
                packageName = packageName.replace("/", ".").replace("\\", ".");
                packageName = packageName.substring(1);
                wizard.putProperty(PROP_PROJECT_PACKAGE, packageName);
            }
            AndroidPlatformInfo projectPlatform = AndroidProjects.projectPlatform(project);
            if (projectPlatform != null) {
                AndroidSdk sdk = projectPlatform.getSdk();
                wizard.putProperty(PROP_PROJECT_SDK, sdk);
                wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_TV_PLATFORM, new PlatformDecorator(projectPlatform));
                wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_TV_ENABLED, true);
            }
            Project rootProject = AndroidProjects.findRootProject(project);
            if (rootProject != null) {
                wizard.putProperty(AndroidProjectTemplatePanelVisualBasicSettings.PROP_PROJECT_DIR, FileUtil.toFile(rootProject.getProjectDirectory()));
                String folderName = project.getProjectDirectory().getPath().replace(rootProject.getProjectDirectory().getPath(), "").substring(1);
                if (!folderName.contains("/") && !folderName.contains("\\")) {
                    wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_TV_FOLDER, folderName);
                }
            }
            AndroidProject aPrj = project.getLookup().lookup(AndroidProject.class);
            if (aPrj != null) {
                String buildToolsVersion = aPrj.getBuildToolsVersion();
                wizard.putProperty(BUILD_TOOL_VERSION, buildToolsVersion);
            }
            wizard.putProperty(ERROR_NO_ANDROID, false);
        } else {
            wizard.putProperty(ERROR_NO_ANDROID, true);
        }

    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 2
Source File: WearActivityWizardIterator.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(WizardDescriptor wizard) {
    this.wizard = wizard;
    index = 0;
    panels = createPanels();
    // Make sure list of steps is accurate.
    steps = createSteps();
    wizard.putProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0);
    for (int i = 0; i < panels.size(); i++) {
        Component c = panels.get(i).getComponent();
        if (c instanceof JComponent) { // assume Swing components
            JComponent jc = (JComponent) c;
            // Step #.
            // TODO if using org.openide.dialogs >= 7.8, can use WizardDescriptor.PROP_*:
            jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i));
            // Step name (actually the whole list for reference).
            jc.putClientProperty("WizardPanel_contentData", steps.toArray(new String[steps.size()]));
        }
    }
    NewFileWizard fileWizard = (NewFileWizard) wizard;
    try {
        Project project = (Project) wizard.getProperty("project");
        if (AndroidProjects.isAndroidMavenProject(project) && (project instanceof NbAndroidProjectImpl)) {
            NbAndroidProjectImpl gradleProject = (NbAndroidProjectImpl) project;
            File projectDirectory = gradleProject.getProjectDirectoryAsFile();
            DataFolder targetFolder = fileWizard.getTargetFolder();
            String targetPath = targetFolder.getPrimaryFile().getPath();
            BuildVariant buildVariant = project.getLookup().lookup(BuildVariant.class);
            AndroidSources androidSources = project.getLookup().lookup(AndroidSources.class);
            SourceGroup[] sourceGroups = androidSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
            FileObject srcRootFolder = null;
            for (SourceGroup sourceGroup : sourceGroups) {
                if (sourceGroup.contains(targetFolder.getPrimaryFile())) {
                    srcRootFolder = sourceGroup.getRootFolder();
                }
            }
            sourceGroups = androidSources.getSourceGroups(AndroidConstants.ANDROID_MANIFEST_XML);
            FileObject manifestRootFolder = null;
            if (sourceGroups.length == 1) {
                manifestRootFolder = sourceGroups[0].getRootFolder();
            }
            wizard.putProperty(MANIFEST_ROOT_FOLDER, FileUtil.toFile(manifestRootFolder));
            Variant variant = buildVariant.getCurrentVariant();
            wizard.putProperty(BUILD_VARIANT, variant);
            if (srcRootFolder != null) {
                String packageName = targetPath.replace(srcRootFolder.getPath(), "");
                packageName = packageName.replace("/", ".").replace("\\", ".");
                packageName = packageName.substring(1);
                wizard.putProperty(PROP_PROJECT_PACKAGE, packageName);
            }
            AndroidPlatformInfo projectPlatform = AndroidProjects.projectPlatform(project);
            if (projectPlatform != null) {
                AndroidSdk sdk = projectPlatform.getSdk();
                wizard.putProperty(PROP_PROJECT_SDK, sdk);
                wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_WEAR_PLATFORM, new PlatformDecorator(projectPlatform));
                wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_WEAR_ENABLED, true);
            }
            Project rootProject = AndroidProjects.findRootProject(project);
            if (rootProject != null) {
                wizard.putProperty(AndroidProjectTemplatePanelVisualBasicSettings.PROP_PROJECT_DIR, FileUtil.toFile(rootProject.getProjectDirectory()));
                String folderName = project.getProjectDirectory().getPath().replace(rootProject.getProjectDirectory().getPath(), "").substring(1);
                if (!folderName.contains("/") && !folderName.contains("\\")) {
                    wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_WEAR_FOLDER, folderName);
                }
            }
            AndroidProject aPrj = project.getLookup().lookup(AndroidProject.class);
            if (aPrj != null) {
                String buildToolsVersion = aPrj.getBuildToolsVersion();
                wizard.putProperty(BUILD_TOOL_VERSION, buildToolsVersion);
            }
            wizard.putProperty(ERROR_NO_ANDROID, false);
        } else {
            wizard.putProperty(ERROR_NO_ANDROID, true);
        }

    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 3
Source File: MobileActivityWizardIterator.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(WizardDescriptor wizard) {
    this.wizard = wizard;
    index = 0;
    panels = createPanels();
    // Make sure list of steps is accurate.
    steps = createSteps();
    wizard.putProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0);
    for (int i = 0; i < panels.size(); i++) {
        Component c = panels.get(i).getComponent();
        if (c instanceof JComponent) { // assume Swing components
            JComponent jc = (JComponent) c;
            // Step #.
            // TODO if using org.openide.dialogs >= 7.8, can use WizardDescriptor.PROP_*:
            jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i));
            // Step name (actually the whole list for reference).
            jc.putClientProperty("WizardPanel_contentData", steps.toArray(new String[steps.size()]));
        }
    }
    NewFileWizard fileWizard = (NewFileWizard) wizard;
    try {
        Project project = (Project) wizard.getProperty("project");
        if (AndroidProjects.isAndroidMavenProject(project) && (project instanceof NbAndroidProjectImpl)) {
            NbAndroidProjectImpl gradleProject = (NbAndroidProjectImpl) project;
            File projectDirectory = gradleProject.getProjectDirectoryAsFile();
            DataFolder targetFolder = fileWizard.getTargetFolder();
            String targetPath = targetFolder.getPrimaryFile().getPath();
            BuildVariant buildVariant = project.getLookup().lookup(BuildVariant.class);
            AndroidSources androidSources = project.getLookup().lookup(AndroidSources.class);
            SourceGroup[] sourceGroups = androidSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
            FileObject srcRootFolder = null;
            for (SourceGroup sourceGroup : sourceGroups) {
                if (sourceGroup.contains(targetFolder.getPrimaryFile())) {
                    srcRootFolder = sourceGroup.getRootFolder();
                }
            }
            sourceGroups = androidSources.getSourceGroups(AndroidConstants.ANDROID_MANIFEST_XML);
            FileObject manifestRootFolder = null;
            if (sourceGroups.length == 1) {
                manifestRootFolder = sourceGroups[0].getRootFolder();
            }
            wizard.putProperty(MANIFEST_ROOT_FOLDER, FileUtil.toFile(manifestRootFolder));
            Variant variant = buildVariant.getCurrentVariant();
            wizard.putProperty(BUILD_VARIANT, variant);
            if (srcRootFolder != null) {
                try {
                    String packageName = targetPath.replace(srcRootFolder.getPath(), "");
                    packageName = packageName.replace("/", ".").replace("\\", ".");
                    packageName = packageName.substring(1);
                    wizard.putProperty(PROP_PROJECT_PACKAGE, packageName);
                } catch (Exception e) {
                }
            }
            PlatformDecorator projectPlatform = new PlatformDecorator(AndroidProjects.projectPlatform(project));
            if (projectPlatform != null) {
                AndroidSdk sdk = projectPlatform.getSdk();
                wizard.putProperty(PROP_PROJECT_SDK, sdk);
                wizard.putProperty(PROP_PHONE_TABLET_PLATFORM, projectPlatform);
                wizard.putProperty(PROP_PHONE_TABLET_ENABLED, true);
            }
            Project rootProject = AndroidProjects.findRootProject(project);
            if (rootProject != null) {
                wizard.putProperty(AndroidProjectTemplatePanelVisualBasicSettings.PROP_PROJECT_DIR, FileUtil.toFile(rootProject.getProjectDirectory()));
                String folderName = project.getProjectDirectory().getPath().replace(rootProject.getProjectDirectory().getPath(), "").substring(1);
                if (!folderName.contains("/") && !folderName.contains("\\")) {
                    wizard.putProperty(PROP_PHONE_TABLET_FOLDER, folderName);
                }
            }
            AndroidProject aPrj = project.getLookup().lookup(AndroidProject.class);
            if (aPrj != null) {
                String buildToolsVersion = aPrj.getBuildToolsVersion();
                wizard.putProperty(BUILD_TOOL_VERSION, buildToolsVersion);
            }
            wizard.putProperty(ERROR_NO_ANDROID, false);
        } else {
            wizard.putProperty(ERROR_NO_ANDROID, true);
        }

    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 4
Source File: FileWizardIterator.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(WizardDescriptor wizard) {
    this.wizard = wizard;
    String displayName = (String) wizard.getProperty("NewFileWizard_Title");
    type = Type.find(displayName);
    index = 0;
    panels = createPanels();
    // Make sure list of steps is accurate.
    steps = createSteps();
    wizard.putProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0);
    for (int i = 0; i < panels.size(); i++) {
        Component c = panels.get(i).getComponent();
        if (c instanceof JComponent) { // assume Swing components
            JComponent jc = (JComponent) c;
            // Step #.
            // TODO if using org.openide.dialogs >= 7.8, can use WizardDescriptor.PROP_*:
            jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i));
            // Step name (actually the whole list for reference).
            jc.putClientProperty("WizardPanel_contentData", steps.toArray(new String[steps.size()]));
        }
    }
    NewFileWizard fileWizard = (NewFileWizard) wizard;
    try {
        Project project = (Project) wizard.getProperty("project");
        if (AndroidProjects.isAndroidMavenProject(project) && (project instanceof NbAndroidProjectImpl)) {
            NbAndroidProjectImpl gradleProject = (NbAndroidProjectImpl) project;
            File projectDirectory = gradleProject.getProjectDirectoryAsFile();
            DataFolder targetFolder = fileWizard.getTargetFolder();
            String targetPath = targetFolder.getPrimaryFile().getPath();
            BuildVariant buildVariant = project.getLookup().lookup(BuildVariant.class);
            AndroidSources androidSources = project.getLookup().lookup(AndroidSources.class);
            SourceGroup[] sourceGroups = androidSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
            FileObject srcRootFolder = null;
            for (SourceGroup sourceGroup : sourceGroups) {
                if (sourceGroup.contains(targetFolder.getPrimaryFile())) {
                    srcRootFolder = sourceGroup.getRootFolder();
                }
            }
            sourceGroups = androidSources.getSourceGroups(AndroidConstants.ANDROID_MANIFEST_XML);
            FileObject manifestRootFolder = null;
            if (sourceGroups.length == 1) {
                manifestRootFolder = sourceGroups[0].getRootFolder();
            }
            wizard.putProperty(MANIFEST_ROOT_FOLDER, FileUtil.toFile(manifestRootFolder));
            Variant variant = buildVariant.getCurrentVariant();
            wizard.putProperty(BUILD_VARIANT, variant);
            if (srcRootFolder != null) {
                String packageName = targetPath.replace(srcRootFolder.getPath(), "");
                packageName = packageName.replace("/", ".").replace("\\", ".");
                packageName = packageName.substring(1);
                wizard.putProperty(PROP_PROJECT_PACKAGE, packageName);
            }
            AndroidPlatformInfo projectPlatform = AndroidProjects.projectPlatform(project);
            if (projectPlatform != null) {
                AndroidSdk sdk = projectPlatform.getSdk();
                wizard.putProperty(PROP_PROJECT_SDK, sdk);
                wizard.putProperty(PROP_PLATFORM, new PlatformDecorator(projectPlatform));
            }
            Project rootProject = AndroidProjects.findRootProject(project);
            if (rootProject != null) {
                wizard.putProperty(AndroidProjectTemplatePanelVisualBasicSettings.PROP_PROJECT_DIR, FileUtil.toFile(rootProject.getProjectDirectory()));
                String folderName = project.getProjectDirectory().getPath().replace(rootProject.getProjectDirectory().getPath(), "").substring(1);
                if (!folderName.contains("/") && !folderName.contains("\\")) {
                    wizard.putProperty(PROP_SUB_PROJECT_FOLDER, folderName);
                }
            }
            AndroidProject aPrj = project.getLookup().lookup(AndroidProject.class);
            if (aPrj != null) {
                String buildToolsVersion = aPrj.getBuildToolsVersion();
                wizard.putProperty(BUILD_TOOL_VERSION, buildToolsVersion);
            }
            wizard.putProperty(ERROR_NO_ANDROID, false);
        } else {
            wizard.putProperty(ERROR_NO_ANDROID, true);
        }

    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}