private void OnAddActivityClick(string activityName) { AMM_ActivityTemplate newActivity = new AMM_ActivityTemplate(false, activityName); newActivity.SetValue("android:name", activityName); newActivity.IsOpen = true; AMM_Manager.GetManifest().ApplicationTemplate.AddActivity(newActivity); }
private void ReadManifest(string manifestPath) { m_template = new AMM_Template(); if (!SA_AssetDatabase.IsFileExists(manifestPath)) { return; } #if !(UNITY_WP8 || UNITY_METRO) //Read XML file XmlDocument doc = new XmlDocument(); doc.Load(SA_PathUtil.ConvertRelativeToAbsolutePath(manifestPath)); XmlNode rootNode = doc.DocumentElement; foreach (XmlAttribute attr in rootNode.Attributes) { m_template.SetValue(attr.Name, attr.Value); } foreach (XmlNode childNode in rootNode.ChildNodes) { if (!childNode.Name.Equals("application") && !childNode.Name.Equals("uses-permission") && !childNode.Name.Equals("#comment")) { m_template.AddProperty(childNode.Name, AMM_Manager.ParseProperty(childNode)); } } XmlNode applicationNode = null; foreach (XmlNode childNode in rootNode.ChildNodes) { if (childNode.Name.Equals("application")) { applicationNode = childNode; break; } } foreach (XmlAttribute attr in applicationNode.Attributes) { m_template.ApplicationTemplate.SetValue(attr.Name, attr.Value); } foreach (XmlNode childNode in applicationNode.ChildNodes) { if (!childNode.Name.Equals("#comment") && !childNode.Name.Equals("activity")) { m_template.ApplicationTemplate.AddProperty(childNode.Name, AMM_Manager.ParseProperty(childNode)); } } foreach (XmlNode childNode in applicationNode.ChildNodes) { if (childNode.Name.Equals("activity") && !childNode.Name.Equals("#comment")) { string activityName = ""; if (childNode.Attributes["android:name"] != null) { activityName = childNode.Attributes["android:name"].Value; } else { Debug.LogWarning("Android Manifest contains activity tag without android:name attribute."); } XmlNode launcher = null; bool isLauncher = false; foreach (XmlNode actNode in childNode.ChildNodes) { if (actNode.Name.Equals("intent-filter")) { foreach (XmlNode intentNode in actNode.ChildNodes) { if (intentNode.Name.Equals("category")) { if (intentNode.Attributes["android:name"].Value.Equals("android.intent.category.LAUNCHER")) { isLauncher = true; launcher = actNode; } } } } } AMM_ActivityTemplate activity = new AMM_ActivityTemplate(isLauncher, activityName); foreach (XmlAttribute attr in childNode.Attributes) { activity.SetValue(attr.Name, attr.Value); } foreach (XmlNode actNode in childNode.ChildNodes) { if (!actNode.Name.Equals("#comment")) { if (actNode != launcher) { activity.AddProperty(actNode.Name, AMM_Manager.ParseProperty(actNode)); } } } m_template.ApplicationTemplate.AddActivity(activity); } } //Load Manifest Permissions foreach (XmlNode node in rootNode.ChildNodes) { if (node.Name.Equals("uses-permission")) { AMM_PropertyTemplate permission = new AMM_PropertyTemplate("uses-permission"); permission.SetValue("android:name", node.Attributes["android:name"].Value); m_template.AddPermission(permission); } } #endif }
private void Activities() { int launcherActivities = 0; foreach (int id in AMM_Manager.GetManifest().ApplicationTemplate.Activities.Keys) { AMM_ActivityTemplate activity = AMM_Manager.GetManifest().ApplicationTemplate.Activities[id]; if (activity.IsLauncher) { launcherActivities++; } EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.BeginHorizontal(); activity.IsOpen = EditorGUILayout.Foldout(activity.IsOpen, activity.Name); if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20.0f))) { AMM_Manager.GetManifest().ApplicationTemplate.RemoveActivity(activity); return; } EditorGUILayout.EndHorizontal(); if (activity.IsOpen) { EditorGUILayout.BeginVertical(); bool isLauncher = activity.IsLauncher; EditorGUI.BeginChangeCheck(); isLauncher = EditorGUILayout.Toggle("Is Launcher", activity.IsLauncher); if (EditorGUI.EndChangeCheck()) { activity.SetAsLauncher(isLauncher); } foreach (string k in activity.Values.Keys) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(k); EditorGUILayout.Space(); string input = activity.Values[k]; EditorGUI.BeginChangeCheck(); if (k.Equals("android:name")) { input = EditorGUILayout.TextField(activity.Values[k]); } else { input = EditorGUILayout.TextField(activity.Values[k]); } if (EditorGUI.EndChangeCheck()) { activity.SetValue(k, input); return; } if (!k.Equals("android:name")) { if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20.0f))) { activity.RemoveValue(k); return; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } AMM_SettingsWindow.DrawProperties(activity); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("Add Value", GUILayout.Width(100.0f))) { AMM_SettingsWindow.AddValueDialog(activity); } if (GUILayout.Button("Add Property", GUILayout.Width(100.0f))) { AMM_SettingsWindow.AddPropertyDialog(activity); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); } EditorGUILayout.EndVertical(); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("Add Activity", GUILayout.Width(100.0f))) { AMM_AddPermissionDialog dlg = EditorWindow.CreateInstance <AMM_AddPermissionDialog>(); dlg.onAddClick += OnAddActivityClick; dlg.titleContent.text = "Add Activity"; dlg.ShowAuxWindow(); } EditorGUILayout.EndHorizontal(); if (launcherActivities > 1) { EditorGUILayout.HelpBox("There is MORE THAN ONE Launcher Activity in Manifest", MessageType.Warning); } else if (launcherActivities < 1) { EditorGUILayout.HelpBox("There is NO Launcher Activities in Manifest", MessageType.Warning); } }