Example #1
0
        public override void save(string directory, string javaClass, CodeExtension codeExtension)
        {
            this.CopyNodes(directory, codeExtension.GetAllUsedNodes());
            this.CopyLibs(directory);
            this.CopyJavaFile(directory, javaClass, codeExtension);

            //TODO create text:
            string readMeText =
                "Please do the following steps to use " + codeExtension.ClassName + ":\n" +
                "  1: Add the Classes in the folders to your IDE. \n" +
                "  2: Add the Libs in the 'libs' folder to your IDE and include it to the Project.\n" +
                "  3: Include the permissions below to your Manifest.\n" +
                "  4: Create a new " + codeExtension.ClassName + " in your code.\n" +
                "  5: Populate all Setters in the class according to what they need to be set.\n" +
                "  6: Call .start(); on " + codeExtension.ClassName + " to start it.\n" +
                "\n\n Permission Needed:\n" +
                codeExtension.GetExtras()
                .Select(e => e as NeedsPermission)
                .NonNull()
                .Select(p => p.Permission)
                .StringJoin("\n")
            ;


            File.WriteAllText(Path.Combine(directory, "README.txt"), readMeText);
        }
Example #2
0
        public override void save(string directory, string javaClass, CodeExtension codeExtension)
        {
            //Check if we have a Android studio Folder:
            string manifestPath = SearchManifest(directory);

            if (manifestPath == null)
            {
                return;
            }

            //We have a manifest!
            //Now navigate to the Source-Path:
            DirectoryInfo eclipseProjectPath = Directory.GetParent(manifestPath);

            string projectName = eclipseProjectPath.Name;
            string projectPath = eclipseProjectPath.FullName;

            //Add the permissions:
            AddExtrasToManifest(manifestPath, codeExtension.GetExtras());

            //Copy classes:
            string srcDirPath = Path.Combine(projectPath, "src");

            CopyJavaFile(srcDirPath, javaClass, codeExtension);
            CopyNodes(srcDirPath, codeExtension.GetAllUsedNodes());

            //Copy lib:
            string libPath = Path.Combine(projectPath, "libs");

            Directory.CreateDirectory(libPath);
            CopyLibs(libPath);

            //Add Lib to Eclipse File:
            //Since Eclipse does not support AAR files, we need to copy them manually:
            DirectoryInfo libDir = new DirectoryInfo(Path.Combine(WorkSpace.DIR, WorkSpace.LIBS_DIR));

            foreach (var file in libDir.GetFiles())
            {
                //Extract the classes file from the AAR files:
                if (file.Name.EndsWith(".aar"))
                {
                    using (ZipArchive zip = ZipFile.Open(file.FullName, ZipArchiveMode.Read))
                    {
                        zip.Entries
                        .Where(e => e.Name == "classes.jar")
                        .ForEachTryIgnore(e => e.ExtractToFile(Path.Combine(libPath, file.Name)));
                    }
                }

                if (file.Name.EndsWith(".jar"))
                {
                    file.CopyTo(Path.Combine(libPath, file.Name));
                }
            }

            //TODO Add libs to project file?!? No clue where! :(
        }
Example #3
0
        public override void save(string directory, string javaClass, CodeExtension codeExtension)
        {
            //Check if we have a Android studio Folder:
            string manifestPath = SearchManifest(directory);

            if (manifestPath == null)
            {
                return;
            }

            //We have a manifest!
            //Now navigate to the Source-Path:
            DirectoryInfo androidStudioProjectPath   = Directory.GetParent(manifestPath).Parent.Parent;
            DirectoryInfo androidStudioWorkspacePath = androidStudioProjectPath.Parent;

            string projectName   = androidStudioProjectPath.Name;
            string workspacePath = androidStudioWorkspacePath.FullName;

            //Add the Extras:
            AddExtrasToManifest(manifestPath, codeExtension.GetExtras());

            //Copy classes:
            string javaDirPath = Directory.GetParent(manifestPath).FullName;

            javaDirPath = Path.Combine(javaDirPath, "java");
            Directory.CreateDirectory(javaDirPath);

            CopyJavaFile(javaDirPath, javaClass, codeExtension);
            CopyNodes(javaDirPath, codeExtension.GetAllUsedNodes());

            //Copy lib:
            string libPath = Path.Combine(androidStudioProjectPath.FullName, "libs");

            Directory.CreateDirectory(libPath);
            CopyLibs(libPath);

            //Add lib to Gradle file:
            string gradlePath = Path.Combine(androidStudioProjectPath.FullName, "build.gradle");

            if (File.Exists(gradlePath))
            {
                string gradleFile = File.ReadAllText(gradlePath);
                if (!gradleFile.Contains("dirs 'libs'"))
                {
                    //Check if we have an easy go:
                    if (gradleFile.Contains("mavenCentral()"))
                    {
                        gradleFile = gradleFile.Replace("mavenCentral()", "mavenCentral()\n  flatDir {\n    dirs 'libs'\n  }\n");
                    }
                    else
                    {
                        gradleFile +=
                            "\n" +
                            "repositories {\n" +
                            "  mavenCentral()\n" +
                            "  flatDir {\n" +
                            "    dirs 'libs'\n" +
                            "  }\n" +
                            "}\n";
                    }

                    //Add Lib dependencies:
                    gradleFile = gradleFile.ReplaceFirst("dependencies {",
                                                         "dependencies {\n" +
                                                         "    compile 'de.tu_darmstadt.smastra.base:SmaSTraBase:1.0@aar'"
                                                         );

                    //Finally rewrite:
                    File.WriteAllText(gradlePath, gradleFile);
                }
            }
            else
            {
                MessageBox.Show("Did not find the build.gradle, please edit it by hand!", "File not found: build.gradle");
            }
        }