Пример #1
0
        /// <summary>
        /// Returns builder for notification created in editor by index(position in list in editor window)
        /// </summary>
        /// <param name="pos">index of notification in the editor list</param>
        /// <returns>Notification builder</returns>
        public static NotificationBuilder GetNotificationBuilderByIndex(int pos)
        {
            NotificationInstance item    = _dataHolder.notifications[pos];
            NotificationBuilder  builder = NotificationBuilder.FromInstance(item);

            return(builder);
        }
Пример #2
0
        public static NotificationBuilder FromInstance(NotificationInstance notif)
        {
            NotificationBuilder builder = new NotificationBuilder(notif.id, notif.title, notif.body);

            if (notif.smallIcon != null)
            {
                builder.setSmallIcon(notif.smallIcon.name);
            }
            if (notif.largeIcon != null)
            {
                builder.setLargeIcon(notif.largeIcon.name);
            }
            if ((notif.ticker != null) && (notif.ticker.Length > 0))
            {
                builder.setTicker(notif.ticker);
            }
            int defaultFlags = 0;

            if (notif.defaultSound)
            {
                defaultFlags |= 1;
            }
            else if (notif.soundFile != null)
            {
                builder.setSound(notif.soundFile.name);
            }
            if (notif.defaultVibrate)
            {
                defaultFlags |= 2;
            }
            else if (notif.vibroPattern != null)
            {
                long[] pattern = notif.vibroPattern.ToArray();
                builder.setVibrate(pattern);
            }
            if (defaultFlags > 0)
            {
                builder.setDefaults(defaultFlags);
            }
            if (notif.number > 0)
            {
                builder.setNumber(notif.number);
            }
            if ((notif.group != null) && (notif.group.Length > 0))
            {
                builder.setGroup(notif.group);
            }
            if ((notif.sortKey != null) && (notif.sortKey.Length > 0))
            {
                builder.setSortKey(notif.sortKey);
            }
            if (notif.hasColor)
            {
                builder.setColor("#" + ColorUtils.ToHtmlStringRGB(notif.color));
            }
            builder.setGroupId(notif.groupId);
            builder.setAutoCancel(notif.autoCancel);
            builder.setAlertOnlyOnce(notif.alertOnce);
            if (notif.isRepeating)
            {
                builder.setRepeating(true);
                long num2     = ((notif.intervalHours * 0xe10) + (notif.intervalMinutes * 60)) + notif.intervalSeconds;
                long interval = num2 * 0x3e8L;
                builder.setInterval(interval);
            }
            long num4 = ((notif.delayHours * 0xe10) + (notif.delayMinutes * 60)) + notif.delaySeconds;
            long delayMilliseconds = num4 * 0x3e8L;

            builder.setDelay(delayMilliseconds);
            return(builder);
        }
Пример #3
0
        /// <summary>
        /// Draws the notification editor ui
        /// </summary>
        /// <param name="notif">Notification to draw</param>
        public static void DrawNotification(NotificationInstance notif)
        {
            GUIStyle labelStyle = GUI.skin.GetStyle(EditorConstants.STYLE_TEXT_FIELD_LABEL);

            // draw headline
            EditorGUILayout.LabelField(EditorConstants.NOTIFICATION_HEADLINE, GUI.skin.label);


            DrawTextField(labelStyle, "Name", ref notif.name);

            DrawIntField(labelStyle, "ID", "Notification id", ref notif.id);

            HandleIconField(labelStyle, "Small icon", ref notif.smallIcon);
            HandleIconField(labelStyle, "Large icon", ref notif.largeIcon);


            DrawTextField(labelStyle, "Title", ref notif.title);
            if (notif.title == null || notif.title.Length == 0)
            {
                EditorGUILayout.HelpBox("Titile can't be empty", MessageType.Error);
            }
            DrawTextField(labelStyle, "Body", ref notif.body);
            if (notif.body == null || notif.body.Length == 0)
            {
                EditorGUILayout.HelpBox("Body can't be empty", MessageType.Error);
            }
            DrawTextField(labelStyle, "Ticker", ref notif.ticker);

            DrawTextField(labelStyle, "Group", ref notif.group);
            DrawTextField(labelStyle, "Sort key", ref notif.sortKey);

            DrawToggleField(labelStyle, "Auto Cancel", EditorConstants.TOOLTIP_AUTO_CANCEL, ref notif.autoCancel);
            DrawToggleField(labelStyle, "Is repeating?", EditorConstants.TOOLTIP_IS_REPEATING, ref notif.isRepeating);

            // If Repeating
            if (notif.isRepeating)
            {
                EditorGUILayout.LabelField(new GUIContent("Interval:", EditorConstants.TOOLTIP_INTERVAL), labelStyle, GUILayout.Width(100));

                EditorGUI.indentLevel += 2;;
                DrawIntField(labelStyle, "Hours", "", ref notif.intervalHours, GUILayout.Width(100));
                DrawIntField(labelStyle, "Minutes", "", ref notif.intervalMinutes, GUILayout.Width(100));
                DrawIntField(labelStyle, "Seconds", "", ref notif.intervalSeconds, GUILayout.Width(100));
                EditorGUI.indentLevel -= 2;
            }

            // Delay
            EditorGUILayout.LabelField(new GUIContent("Delay", EditorConstants.TOOLTIP_DELAY), labelStyle, GUILayout.Width(100));

            EditorGUI.indentLevel += 2;
            DrawIntField(labelStyle, "Hours", "Hours before the norification will be shown", ref notif.delayHours, GUILayout.Width(100));
            DrawIntField(labelStyle, "Minutes", "Minutes before the norification will be shown", ref notif.delayMinutes, GUILayout.Width(100));
            DrawIntField(labelStyle, "Seconds", "Seconds before the norification will be shown", ref notif.delaySeconds, GUILayout.Width(100));
            EditorGUI.indentLevel -= 2;

            //
            DrawToggleField(labelStyle, "Alert once", EditorConstants.TOOLTIP_ALERT_ONCE, ref notif.alertOnce);
            DrawToggleField(labelStyle, "Default Sound", EditorConstants.TOOLTIP_DEFAULT_SOUND, ref notif.defaultSound);

            if (!notif.defaultSound)
            {
                HandleAudioField(labelStyle, "Sound clp", ref notif.soundFile);
            }

            DrawToggleField(labelStyle, "Default Vibrate", EditorConstants.TOOLTIP_VIBRATE, ref notif.defaultVibrate);

            if (!notif.defaultVibrate)
            {
                EditorGUILayout.LabelField(new GUIContent("Vibro pattern", EditorConstants.TOOLTIP_VIBRO_PATTERN), labelStyle, GUILayout.Width(100));

                // vibration pattern list
                EditorGUI.indentLevel += 2;
                for (int i = 0; i < notif.vibroPattern.Count; ++i)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUIContent cont;
                    if (i % 2 == 0)
                    {
                        cont = new GUIContent("Pause", "Miliseconds before next vibration");
                    }
                    else
                    {
                        cont = new GUIContent("On", "Length of vebration in miliseconds");
                    }

                    EditorGUILayout.LabelField(cont, labelStyle, GUILayout.Width(100));
                    notif.vibroPattern[i] = EditorGUILayout.LongField(notif.vibroPattern[i], GUILayout.Width(100));
                    EditorGUILayout.EndHorizontal();
                }

                // Add/Remove buttons
                GUIStyle smallBtnStyle = EditorStyles.miniButtonLeft;
                smallBtnStyle.margin.left = 40;

                EditorGUILayout.Space();
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("+", smallBtnStyle, miniButtonWidth))
                {
                    notif.vibroPattern.Add(1000);
                }
                if (GUILayout.Button("-", EditorStyles.miniButtonRight, miniButtonWidth))
                {
                    // remove last if the list is not empty
                    int elemCount = notif.vibroPattern.Count;
                    if (elemCount > 0)
                    {
                        notif.vibroPattern.RemoveAt(elemCount - 1);
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();

                EditorGUI.indentLevel -= 2;
            }

            DrawIntField(labelStyle, "Number", EditorConstants.TOOLTIP_NUMBER, ref notif.number);
            DrawToggleField(labelStyle, "Has color?", "Color in the circle", ref notif.hasColor);
            if (notif.hasColor)
            {
                EditorGUI.indentLevel += 2;
                DrawColorField(labelStyle, "Color", ref notif.color, GUILayout.Width(100));
                EditorGUI.indentLevel -= 2;
            }
        }
        public static NotificationBuilder GetNotificationBuilderByIndex(int pos)
        {
            NotificationInstance notif = _dataHolder.notifications[pos];

            return(NotificationBuilder.FromInstance(notif));
        }
Пример #5
0
        /// <summary>
        /// Builds notification from NotificationInstance - created in editor
        /// </summary>
        /// <param name="notif">Instance created in Notifications Window</param>
        /// <returns>Notification buildder</returns>
        public static NotificationBuilder FromInstance(NotificationInstance notif)
        {
            NotificationBuilder builder = new NotificationBuilder(notif.id, notif.title, notif.body);

            if (notif.smallIcon != null)
            {
                builder.setSmallIcon(notif.smallIcon.name);
            }

            if (notif.largeIcon != null)
            {
                builder.setLargeIcon(notif.largeIcon.name);
            }

            if (notif.ticker != null && notif.ticker.Length > 0)
            {
                builder.setTicker(notif.ticker);
            }

            int defaults = 0;

            // Handle sound
            if (notif.defaultSound)
            {
                defaults |= NotificationBuilder.DEFAULT_SOUND;
            }
            else
            {
                if (notif.soundFile != null)
                {
                    builder.setSound(notif.soundFile.name);
                }
            }

            // Handle vibrate
            if (notif.defaultVibrate)
            {
                defaults |= NotificationBuilder.DEFAULT_VIBRATE;
            }
            else
            {
                if (notif.vibroPattern != null)
                {
                    long[] vibratePattern = notif.vibroPattern.ToArray();
                    builder.setVibrate(vibratePattern);
                }
            }

            if (defaults > 0)
            {
                builder.setDefaults(defaults);
            }

            if (notif.number > 0)
            {
                builder.setNumber(notif.number);
            }

            if (notif.group != null && notif.group.Length > 0)
            {
                builder.setGroup(notif.group);
            }

            if (notif.sortKey != null && notif.sortKey.Length > 0)
            {
                builder.setSortKey(notif.sortKey);
            }

            if (notif.hasColor)
            {
                builder.setColor("#" + ColorUtility.ToHtmlStringRGB(notif.color));
            }

            builder.setAutoCancel(notif.autoCancel);
            builder.setAlertOnlyOnce(notif.alertOnce);

            // Repeating and interval
            if (notif.isRepeating)
            {
                builder.setRepeating(true);

                long intervalSeconds = notif.intervalHours * 3600 + notif.intervalMinutes * 60 + notif.intervalSeconds;
                long milis           = intervalSeconds * 1000;

                builder.setInterval(milis);
            }

            // Delay
            long delaySeconds = notif.delayHours * 3600 + notif.delayMinutes * 60 + notif.delaySeconds;
            long delayMilis   = delaySeconds * 1000;

            builder.setDelay(delayMilis);

            return(builder);
        }