private void InjectAndroidManifest(string projectPath)
        {
            var manifestPath = string.Format("{0}/src/main/AndroidManifest.xml", projectPath);

            if (!File.Exists(manifestPath))
            {
                throw new FileNotFoundException(string.Format("'{0}' doesn't exist.", manifestPath));
            }

            XmlDocument manifestDoc = new XmlDocument();

            manifestDoc.Load(manifestPath);

            InjectReceivers(manifestPath, manifestDoc);

            var settings = UnityNotificationEditorManager.Initialize().AndroidNotificationEditorSettingsFlat;

            var useCustomActivity = (bool)settings.Find(i => i.key == "UnityNotificationAndroidUseCustomActivity").val;

            if (useCustomActivity)
            {
                var customActivity = (string)settings.Find(i => i.key == "UnityNotificationAndroidCustomActivityString").val;
                AppendAndroidMetadataField(manifestPath, manifestDoc, "custom_notification_android_activity", customActivity);
            }

            var enableRescheduleOnRestart = (bool)settings.Find(i => i.key == "UnityNotificationAndroidRescheduleOnDeviceRestart").val;

            if (enableRescheduleOnRestart)
            {
                AppendAndroidMetadataField(manifestPath, manifestDoc, "reschedule_notifications_on_restart", "true");
                AppendAndroidPermissionField(manifestPath, manifestDoc, "android.permission.RECEIVE_BOOT_COMPLETED");
            }

            manifestDoc.Save(manifestPath);
        }
        static SettingsProvider CreateMobileNotificationsSettingsProvider()
        {
            var provider = AssetSettingsProvider.CreateProviderFromObject("Project/Mobile Notification Settings",
                                                                          UnityNotificationEditorManager.Initialize());

            provider.label = "Mobile Notification Settings";
            return(provider);
        }
        void RemoveIcondDataElement(ReorderableList list)
        {
            var i = UnityNotificationEditorManager.Initialize();

            i.RemoveDrawableResource(list.index);

            OnChange(list);
        }
        void AddIconDataElement(ReorderableList list)
        {
            Undo.RegisterCompleteObjectUndo(target, "Add a new icon element.");
            var manager = UnityNotificationEditorManager.Initialize();

            manager.RegisterDrawableResource(string.Format("icon_{0}", manager.TrackedResourceAssets.Count), null, NotificationIconType.SmallIcon);

            OnChange(list);
        }
        DrawableResourceData GetElementData(int index)
        {
            var res = UnityNotificationEditorManager.Initialize().TrackedResourceAssets;

            if (index < res.Count)
            {
                return(res[index]);
            }
            return(null);
        }
Ejemplo n.º 6
0
        public void OnPostGenerateGradleAndroidProject(string projectPath)
        {
            var icons = UnityNotificationEditorManager.Initialize().GenerateDrawableResourcesForExport();

            var directories = Directory.GetDirectories(projectPath);

            foreach (var icon in icons)
            {
                // When exporting a gradle project projectPath points to the the parent folder of the project
                // instead of the actual project
                if (!Directory.Exists(Path.Combine(projectPath, "src")))
                {
                    projectPath = Path.Combine(projectPath, PlayerSettings.productName);
                }

                var fileInfo = new FileInfo(string.Format("{0}/src/main/res/{1}", projectPath, icon.Key));
                if (fileInfo.Directory != null)
                {
                    fileInfo.Directory.Create();
                    File.WriteAllBytes(fileInfo.FullName, icon.Value);
                }
            }

            var settings = UnityNotificationEditorManager.Initialize().AndroidNotificationEditorSettingsFlat;

            var enableRescheduleOnRestart = (bool)settings
                                            .Find(i => i.key == "UnityNotificationAndroidRescheduleOnDeviceRestart").val;

            var useCustomActivity = (bool)settings
                                    .Find(i => i.key == "UnityNotificationAndroidUseCustomActivity").val;

            var customActivity = (string)settings
                                 .Find(i => i.key == "UnityNotificationAndroidCustomActivityString").val;

            if (useCustomActivity | enableRescheduleOnRestart)
            {
                string      manifestPath = string.Format("{0}/src/main/AndroidManifest.xml", projectPath);
                XmlDocument manifestDoc  = new XmlDocument();
                manifestDoc.Load(manifestPath);

                if (useCustomActivity)
                {
                    manifestDoc = AppendAndroidMetadataField(manifestDoc, "custom_notification_android_activity",
                                                             customActivity);
                }

                if (enableRescheduleOnRestart)
                {
                    manifestDoc = AppendAndroidMetadataField(manifestDoc, "reschedule_notifications_on_restart", "true");
                    manifestDoc = AppendAndroidPermissionField(manifestDoc,
                                                               "android.permission.RECEIVE_BOOT_COMPLETED");
                }
                manifestDoc.Save(manifestPath);
            }
        }
        bool CanAddCallbackDelegate(ReorderableList list)
        {
            var trackedAssets = UnityNotificationEditorManager.Initialize().TrackedResourceAssets;

            if (trackedAssets.Count <= 0)
            {
                return(true);
            }

            return(!trackedAssets.Any(i => i.Initialized() == false));
        }
Ejemplo n.º 8
0
        private static void SetSettingValue <T>(BuildTargetGroup target, string key, T value)
        {
            var manager = UnityNotificationEditorManager.Initialize();

            NotificationEditorSetting setting = GetSetting(target, key);

            if (setting != null)
            {
                setting.val = value;
                manager.SaveSetting(setting, target);
            }
        }
Ejemplo n.º 9
0
        private static NotificationEditorSetting GetSetting(BuildTargetGroup target, string key)
        {
            var manager = UnityNotificationEditorManager.Initialize();

            NotificationEditorSetting setting = null;

            if (target == BuildTargetGroup.Android)
            {
                setting = manager.AndroidNotificationEditorSettingsFlat.Find(i => i.key == key);
            }
            else if (target == BuildTargetGroup.iOS)
            {
                setting = manager.iOSNotificationEditorSettingsFlat.Find(i => i.key == key);
            }

            return(setting);
        }
        private void CopyNotificationResources(string projectPath)
        {
            // The projectPath points to the the parent folder instead of the actual project path.
            if (!Directory.Exists(Path.Combine(projectPath, "src")))
            {
                projectPath = Path.Combine(projectPath, PlayerSettings.productName);
            }

            // Get the icons set in the UnityNotificationEditorManager and write them to the res folder, then we can use the icons as res.
            var icons = UnityNotificationEditorManager.Initialize().GenerateDrawableResourcesForExport();

            foreach (var icon in icons)
            {
                var fileInfo = new FileInfo(string.Format("{0}/src/main/res/{1}", projectPath, icon.Key));
                if (fileInfo.Directory != null)
                {
                    fileInfo.Directory.Create();
                    File.WriteAllBytes(fileInfo.FullName, icon.Value);
                }
            }
        }
        public void OnPostGenerateGradleAndroidProject(string projectPath)
        {
            var icons = UnityNotificationEditorManager.Initialize().GenerateDrawableResourcesForExport();

            var directories = Directory.GetDirectories(projectPath);

            foreach (var icon in icons)
            {
                // When exporting a gradle project projectPath points to the the parent folder of the project
                // instead of the actual project
                if (!Directory.Exists(Path.Combine(projectPath, "src")))
                {
                    projectPath = Path.Combine(projectPath, PlayerSettings.productName);
                }

                var fileInfo = new FileInfo(string.Format("{0}/src/main/res/{1}", projectPath, icon.Key));
                if (fileInfo.Directory != null)
                {
                    fileInfo.Directory.Create();
                    File.WriteAllBytes(fileInfo.FullName, icon.Value);
                }
            }
        }
        void OnEnable()
        {
            manager = UnityNotificationEditorManager.Initialize();
            manager.CustomEditor = this;

            if (target == null)
            {
                return;
            }


            m_Target = new SerializedObject(target);

            m_ResourceAssets = serializedObject.FindProperty("TrackedResourceAssets");


            serializedObject.FindProperty("iOSRequestAuthorizationOnAppLaunch");

            serializedObject.FindProperty("iOSRequestAuthorizationForRemoteNotificationsOnAppLaunch");
            serializedObject.FindProperty("iOSRemoteNotificationForegroundPresentationOptions");


            m_ReorderableList = new ReorderableList(serializedObject, m_ResourceAssets, false, true, true, true);
            m_ReorderableList.elementHeight = kSlotSize + kIconSpacing;

            m_ReorderableList.showDefaultBackground = false;

            m_ReorderableList.drawHeaderCallback = (rect) =>
            {
                if (Event.current.type == EventType.Repaint)
                {
                    var boxBackground    = new GUIStyle("RL Background");
                    var headerBackground = new GUIStyle("RL Header");

                    var paddedRect = GetContentRect(rect,
                                                    1f,
                                                    (ReorderableList.Defaults.padding + 2f) * -1);

                    headerBackground.Draw(
                        paddedRect,
                        false, false, false, false);

                    var labelRect = GetContentRect(paddedRect, 0f, 3f);

                    GUI.Label(labelRect, "Notification icons", EditorStyles.label);
                }
            };
            m_ReorderableList.onAddCallback = (list) =>
                                              AddIconDataElement(list);

            m_ReorderableList.onRemoveCallback = (list) =>
                                                 RemoveIcondDataElement(list);

            m_ReorderableList.onCanAddCallback = (list) =>
                                                 CanAddCallbackDelegate(list);

            m_ReorderableList.drawElementBackgroundCallback = (rect, index, active, focused) =>
            {
                if (!(Event.current.type == EventType.Repaint))
                {
                    return;
                }

                var evenRow = new GUIStyle("CN EntryBackEven");
                var oddRow  = new GUIStyle("CN EntryBackOdd");

                var bg = index % 2 == 0 ? evenRow : oddRow;
                bg.Draw(rect, false, false, false, false);
                ReorderableList.defaultBehaviours.DrawElementBackground(rect, index, active, focused, true);
            };


            m_ReorderableList.drawElementCallback = (rect, index, selected, focused) =>
                                                    DrawIconDataElement(rect, index, selected, focused);

            m_ReorderableList.elementHeightCallback = index =>
            {
                var data = GetElementData(index);
                if (data == null)
                {
                    return(kSlotSize);
                }
                if (data.showOtherSizes)
                {
                    return(m_ReorderableList.elementHeight * 6);
                }
                return(m_ReorderableList.elementHeight +
                       (data.Asset != null && !data.IsValid ? kSlotSize : 0));
            };

            Undo.undoRedoPerformed += UpdateEditorStateOnUndo;
        }