private void changePackage() { defaultAndroidProjectPath = settings.getProjectPath(); // File androidPhonegapFolder = new File(installDirectory + // "/PhonegapSDK/Default/android/src/com/phonegap"); File androidPhonegapFolder = new File(defaultAndroidProjectPath + "/src/com/phonegap"); System.out.println("Folder: " + androidPhonegapFolder.getPath()); File[] files = androidPhonegapFolder.listFiles( new FileFilter() { public boolean accept(File pathname) { fireModelChanged(new Event(null, (progress++) % 100, 0, action, PLATFORM)); if (pathname.getPath().endsWith("java")) { return true; } return false; } }); System.out.println("Package: " + getPackageName()); for (int i = 0; files != null && i < files.length; i++) { File file = files[i]; fileHandler.changePackage(phonegapPackage, getPackageName(), new File(tempSrcPath), file); } File manifestXml = new File(tempManifestPath); fileHandler.changeStringInFile(phonegapPackage, getPackageName(), manifestXml); }
private void changeIcon() { try { File icon = new File(getIconpath()); fileHandler.copyFileToDir(icon, new File(tempDrawableFolder)); System.out.println("icon name: " + icon.getPath()); fileHandler.changeStringInFile( "@drawable/icon", "@drawable/" + removePrefix(icon.getName()), new File(tempManifestPath)); } catch (IOException ex) { java.util.logging.Logger.getLogger(AndroidApplicationModel.class.getName()) .log(Level.SEVERE, null, ex); } }
private void copyProject() { Logger.print(this, "copyProject"); try { defaultAndroidProjectPath = settings.getProjectPath(); fileHandler.copyDirectory( new File(defaultAndroidProjectPath), new File(tempAndroidProjectPath), new FileFilter() { public boolean accept(File pathname) { fireModelChanged(new Event(null, (progress++) % 100, 0, action, PLATFORM)); Logger.print(this, pathname.getPath()); if (pathname.getPath().contains("src")) { return false; } if (pathname.getPath().contains("assets")) { return false; } return true; } }); } catch (IOException ex) { java.util.logging.Logger.getLogger(AndroidApplicationModel.class.getName()) .log(Level.SEVERE, null, ex); } }
private void prepare() { String jdkPath = RegistryHandler.getJDKPath(); if (!isToolsJarInWebSDK()) { copyJdkTools(jdkPath); } File tools_jar = new File(jdkPath + "\\lib\\tools.jar"); current.addPathComponent(tools_jar); try { fileHandler.deleteFolder(new File(tempAndroidProjectPath)); copyAssets(); copyProject(); changeIcon(); changePackage(); changeName(); createBuildProperties(); targetId = RegistryHandler.getAndroidTarget() + 1; // Update R.java and some properties. cmdHelper.updateAndroidProject(targetId, tempAndroidProjectPath, getNameForFile()); } catch (IOException ex) { java.util.logging.Logger.getLogger(AndroidApplicationModel.class.getName()) .log(Level.SEVERE, null, ex); } }
/** * generate Android application * * @param debug flag for using debug keys for signing */ public void generate(boolean debug) { action = "Generating"; progress = 0; prepare(); String target; if (debug) { target = "debug"; } else { target = "release"; } antHelper.runAnt(tempBuildFile, target, current); try { fileHandler.copyDirectory( new File(tempAndroidProjectPath + "/bin"), getDestinationDir(), new FileFilter() { public boolean accept(File pathname) { final String fileName = pathname.getName().toLowerCase(); return fileName.endsWith(".apk") || fileName.equalsIgnoreCase("bin"); } }); } catch (IOException ex) { java.util.logging.Logger.getLogger(AndroidApplicationModel.class.getName()) .log(Level.SEVERE, null, ex); } fireModelChanged(new Event(null, 100, 0, "Created", PLATFORM)); }
private void changeName() { // The file in which the AppName is stored. File stringsXml = new File(tempStringsPath); fireModelChanged(new Event(null, (progress++) % 100, 0, action, PLATFORM)); String stringToInstert = "\"" + getName() + "\""; String firstString = "<string name=\"app_name\">"; String endString = "</string>"; fileHandler.insertStringInToAFile(firstString, endString, stringToInstert, stringsXml); }
private void copyAssets() throws IOException { fireModelChanged(new Event(null, (progress++) % 100, 0, action, PLATFORM)); File targetAssetsFolder = new File(tempWwwPath); // Delete assets/www folder and recreate it. // Copy assets to assets/www fileHandler.copyDirectory( new File(getSelectedFolder()), targetAssetsFolder, new FileFilter() { public boolean accept(File pathname) { fireModelChanged(new Event(null, (progress++) % 100, 0, action, PLATFORM)); return !pathname.getPath().toLowerCase().contains("phonegap.js"); } }); }
/** clean up temporary folder */ public void finish() { fileHandler.deleteFolder(new File(tempAndroidProjectPath)); fireModelChanged(new Event(null, 100, 0, "Finished", PLATFORM)); }