From 670c95ad1413d9617243c91ba749a1d5ad3f09d0 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Thu, 1 Dec 2011 02:21:30 +0000 Subject: [PATCH] SDK: - set application name correctly for android application git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8834 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/gde/android/AndroidSdkTool.java | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/sdk/jme3-android/src/com/jme3/gde/android/AndroidSdkTool.java b/sdk/jme3-android/src/com/jme3/gde/android/AndroidSdkTool.java index 6f5eb84d7..bf4702b52 100644 --- a/sdk/jme3-android/src/com/jme3/gde/android/AndroidSdkTool.java +++ b/sdk/jme3-android/src/com/jme3/gde/android/AndroidSdkTool.java @@ -13,6 +13,7 @@ import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.List; import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectInformation; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.NotifyDescriptor.Message; @@ -239,6 +240,7 @@ public class AndroidSdkTool { Exceptions.printStackTrace(ex); } updateAndroidManifest(project); + updateAndroidApplicationName(project, name); } public static void updateProject(Project project, String target, String name) { @@ -267,6 +269,7 @@ public class AndroidSdkTool { } catch (IOException ex) { Exceptions.printStackTrace(ex); } + updateAndroidApplicationName(project, name); } private static void updateAndroidManifest(Project project) { @@ -318,8 +321,58 @@ public class AndroidSdkTool { } } + private static void updateAndroidApplicationName(Project project, String name) { + FileObject manifest = project.getProjectDirectory().getFileObject("mobile/res/values/strings.xml"); + if (manifest == null) { + return; + } + InputStream in = null; + FileLock lock = null; + OutputStream out = null; + try { + in = manifest.getInputStream(); + Document configuration = XMLUtil.parse(new InputSource(in), false, false, null, null); + in.close(); + in = null; + Element sdkElement = XmlHelper.findChildElementWithAttribute(configuration.getDocumentElement(), "string", "name", "app_name"); + if (sdkElement == null) { + sdkElement = configuration.createElement("string"); + sdkElement.setAttribute("name", "app_name"); + configuration.getDocumentElement().appendChild(sdkElement); + } + if (!sdkElement.getTextContent().trim().equals(name)) { + sdkElement.setTextContent(name); + lock = manifest.lock(); + out = manifest.getOutputStream(lock); + XMLUtil.write(configuration, out, "UTF-8"); + out.close(); + out = null; + lock.releaseLock(); + lock = null; + } + } catch (SAXException ex) { + Exceptions.printStackTrace(ex); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } finally { + if (lock != null) { + lock.releaseLock(); + } + try { + if (in != null) { + in.close(); + } + if (out != null) { + out.close(); + } + } catch (IOException ex1) { + Exceptions.printStackTrace(ex1); + } + } + } + private static String mainActivityString(String mainClass, String packag) { - String str = + String str = "package " + packag + ";\n" + " \n" + "import com.jme3.app.AndroidHarness;\n"