Example #1
0
        protected void DrawIcon(Graphics g, DrawableIcon icn, Rectangle btnRect)
        {
            try
            {
                switch (icn.DisplayMode)
                {
                case DisplayMode.Normal:
                    DrawImageNormal(g, icn.Image, btnRect);
                    break;

                case DisplayMode.Stretch:
                    g.DrawImage(icn.Image, btnRect);
                    break;

                case DisplayMode.Zoom:
                    DrawImageZoomed(g, icn.Image, btnRect);
                    break;

                default:
                    string msg = String.Format("Display mode '{0}' is not implemented!", icn.DisplayMode.ToString().ToLower());
                    throw new ApplicationException(msg);
                }
            }
            catch (ApplicationException e)
            {
                logger.Warn(e.Message);
            }
        }
Example #2
0
        private void RegisterNotification(Icon icon = null, PartLoad e = null)
        {
            try
            {
                using (NotificationManager notificationManager = (NotificationManager)GetSystemService(NotificationService))
                {
                    Notification.Builder notificationBuilder;

                    settings = Settings.Instance;

                    string freeRam  = System.String.Empty;
                    string loadRam  = System.String.Empty;
                    string totalRam = System.String.Empty;
                    string usageCpu = System.String.Empty;
                    string freeCpu  = System.String.Empty;
                    string cpuCores = System.String.Empty;

                    #region Layout notification
                    if (view == null ||
                        textView1 == null || textView2 == null || textView3 == null || textView4 == null || textView5 == null || textView6 == null || remoteViewsEmpty == null || remoteViews == null)
                    {
                        LayoutNotificationResourceInit();
                    }
                    #endregion

                    #region Notification Channel (Support ANDROID VERSION  <  Oreo)
                    if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
                    {
                        NotificationChannel channel = new NotificationChannel(Info.Chanlelid, Info.Name, NotificationImportance.Default)
                        {
                            Description = Info.Description
                        };

                        notificationManager.CreateNotificationChannel(channel);
                        notificationBuilder = new Notification.Builder(this, Info.Chanlelid);
                    }
                    else
                    {
                        notificationBuilder = new Notification.Builder(this);
                    }
                    #endregion



                    if (icon == null)
                    {
                        drawableIcon = new DrawableIcon <string>();
                        icon         = drawableIcon.GenerateIcon(System.String.Empty);
                    }

                    if (e != null)
                    {
                        freeRam  = System.String.Concat(new string[] { "Load", ":", " ", e.UsedRamMB.ToString(), "Mb" });;
                        loadRam  = System.String.Concat(new string[] { "Free", ":", " ", e.AvailableRamMB.ToString(), "Mb" });
                        totalRam = System.String.Concat(new string[] { "Total", ":", " ", e.TotalRamMB.ToString(), "Mb" });
                        usageCpu = System.String.Concat(new string[] { "Load", ":", " ", e.CpuUsage.ToString(), " ", "%" });
                        freeCpu  = System.String.Concat(new string[] { "Free", ":", " ", e.CpuFree.ToString(), " ", "%" });
                        cpuCores = System.String.Concat(new string[] { "Cpu", ":", " ", e.CpuCores.ToString(), " ", "cores" });
                    }

                    if (settings.LayoutNotificationEmpty == false)
                    {
                        #region Empty

                        Notification notificationEmpty = notificationBuilder
                                                         .SetCustomContentView(remoteViewsEmpty)
                                                         .SetSmallIcon(icon)
                                                         .SetOngoing(true)
                                                         .SetAutoCancel(false)
                                                         .Build();

                        #region Start Service (Support ANDROID VERSION  <  Oreo)
                        if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
                        {
                            StartForeground(Info.NotificationId, notificationEmpty);
                        }
                        else
                        {
                            notificationManager.Notify(Info.NotificationId, notificationEmpty);
                        }
                        #endregion

                        #endregion
                    }
                    else
                    {
                        #region Filling

                        remoteViews.SetTextViewText(textView1.Id, loadRam);
                        remoteViews.SetTextViewText(textView2.Id, freeRam);
                        remoteViews.SetTextViewText(textView3.Id, totalRam);
                        remoteViews.SetTextViewText(textView4.Id, usageCpu);
                        remoteViews.SetTextViewText(textView5.Id, freeCpu);
                        remoteViews.SetTextViewText(textView6.Id, cpuCores);

                        Notification notification = notificationBuilder
                                                    .SetCustomContentView(remoteViews)
                                                    .SetSmallIcon(icon)
                                                    .SetOngoing(true)
                                                    .SetAutoCancel(false)
                                                    .Build();

                        #region Start Service (Support ANDROID VERSION  <  Oreo)
                        if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
                        {
                            StartForeground(Info.NotificationId, notification);
                        }
                        else
                        {
                            notificationManager.Notify(Info.NotificationId, notification);
                        }
                        #endregion

                        #endregion
                    }
                }
            }
            catch (System.Exception ex)
            {
                #region Attempt restart
                AttemptRestart();
                #endregion

                #region Logging
                LogRuntimeAttribute.InLogFiles(typeof(NotifyService), ex);
                #endregion
            }

            finally { }
        }