コード例 #1
0
        private void UpdateNotification(bool firstNotification)
        {
            InitNotification();
            mNotificationBuilder.SetContentTitle(Resources.GetString(Resource.String.service_running));
            String secondLine = m_Network != null && m_Network.ClientConnected ?
                                String.Format(Resources.GetString(Resource.String.connected_with), m_Network.ClientName) :
                                Resources.GetString(Resource.String.not_connected);

            mNotificationBuilder.SetContentText(secondLine);
            var    style   = new Notification.BigTextStyle(mNotificationBuilder);
            String project = m_Project != null?
                             String.Format(Resources.GetString(Resource.String.loaded_project), m_Project.Title) :
                                 Resources.GetString(Resource.String.no_project);

            style.BigText(secondLine + "\n" + project);
            mNotificationBuilder.SetStyle(style);
            mNotificationBuilder.SetProgress(0, 0, false);
            if (firstNotification)
            {
                StartForeground(mNotificationId, mNotificationBuilder.Build());
            }
            else
            {
                var nMgr         = (NotificationManager)GetSystemService(NotificationService);
                var notification = mNotificationBuilder.Build();
                notification.Flags |= NotificationFlags.ForegroundService;
                nMgr.Notify(mNotificationId, notification);
            }
        }
コード例 #2
0
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            if (builder == null)
            {
                builder = new Notification.Builder(context);
            }

            builder.SetContentTitle(this.Title);
            if (this.TotalBytes > 0 && this.CurrentBytes != -1)
            {
                builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
            }
            else
            {
                builder.SetProgress(0, 0, true);
            }
            builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
            builder.SetContentInfo(context.GetString(Resource.String.time_remaining_notification, Helpers.GetTimeRemaining(this.TimeRemaining)));
            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return(builder.Notification);
        }
コード例 #3
0
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            var builder = new Notification.Builder(context);

            if (!string.IsNullOrEmpty(this.PausedText))
            {
                builder.SetContentTitle(this.PausedText);
                builder.SetContentText(string.Empty);
                builder.SetContentInfo(string.Empty);
            }
            else
            {
                builder.SetContentTitle(this.Title);
                if (this.TotalBytes > 0 && this.CurrentBytes != -1)
                {
                    builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
                }
                else
                {
                    builder.SetProgress(0, 0, true);
                }

                builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
                builder.SetContentInfo(string.Format("{0}s left", Helpers.GetTimeRemaining(this.TimeRemaining)));
            }

            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return(builder.Notification);
        }
コード例 #4
0
        private void RunNotificationProgressBar(List <Milestone> milestones, CancellationToken token)
        {
            SetProgressBuilder(milestones.First(), milestones.ElementAt(1));
            for (var i = 0; i < milestones.Count - 1; i++)
            {
                var milestone = milestones[i];
                ShowActionNotification(milestone, notificationManager, i);

                UpdateProgressBuilderText(milestone, milestones[i + 1]);
                while (milestone.EndTime.ToUniversalTime() > DateTime.UtcNow)
                {
                    var currentCookingTime = DateTime.Now - milestone.StartTime;
                    var percentage         = (currentCookingTime.TotalMilliseconds / milestone.CookingTime.TotalMilliseconds) *
                                             100;

                    progressBuilder.SetProgress(100, (int)percentage, false);

                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                    notificationManager.Notify(ForegroundNotificationId, progressBuilder.Build());

                    Thread.Sleep((milestone.EndTime - DateTime.Now).TotalMinutes <= OneMinuteAndFiveSeconds ? 1000 : 5000);
                }
            }

            ShowFinishedNotification(notificationManager);
            StopForeground(true);
        }
コード例 #5
0
        public void SendNotification(string title, string text, bool sound = false, bool progress = false, int total = 0, int partial = 0, int percentMax = 100)
        {
            // Instantiate the builder and set notification elements:
            Notification.Builder builder = new Notification.Builder(Application.Context)
                                           .SetContentTitle(title).SetContentText(text)
                                           .SetSmallIcon(Resource.Drawable.icon);//.SetTicker("");

            // Build the notification:
            //Notification notification = builder.Build();

            // Get the notification manager:
            NotificationManager notificationManager =
                Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;

            // Publish the notification:
            const int notificationId = 2468;

            if (progress)
            {
                builder.SetProgress(percentMax, percentMax * partial / total, false);
            }

            if (sound)
            {
                builder.SetSound(Android.Media.RingtoneManager.GetDefaultUri(Android.Media.RingtoneType.Notification));
            }

            notificationManager.Notify(notificationId, builder.Build());

            builder.SetWhen(DateTime.Now.Millisecond);
        }
コード例 #6
0
        private void NotifyUpdateStatus()
        {
            var contentText = Math.Round((Convert.ToDecimal(uploadedBytes) / (1024.0m * 1024.0m)), 2) + " MB of " + Math.Round((Convert.ToDecimal(totalBytes) / (1024.0m * 1024.0m)), 2) + " MB";

            //    Log.Debug("NotifyUpdateStatus", "uploadedBytes = " + uploadedBytes + "percentComplete = " + percentComplete);
            notificationBuilder.SetProgress(100, percentComplete, false)
            .SetContentText(contentText);
            notificationManager.Notify(notificationID, notificationBuilder.Build());
        }
コード例 #7
0
        IEnumerator UpdateProgressBar(Notification.Builder builder)
        {
            var         currentProgress = 0f;
            const float durationTime    = 5f;
            const int   maxProgress     = 100;

            while (currentProgress < durationTime)
            {
                var progress = Mathf.CeilToInt(currentProgress / 5f * maxProgress);
                currentProgress += Time.deltaTime;
                builder.SetProgress(maxProgress, progress, false);
                AGNotificationManager.Notify(_notificationId, builder.Build());
                yield return(null);
            }

            AGNotificationManager.Notify(_notificationId, builder.Build());
        }
コード例 #8
0
        /// <summary>
        /// //////////////////////////////////////////////////ignore
        /// </summary>
        /// <param name="path"></param>
        /// <param name="linkarchivo"></param>


        ///



        public void descargame(string nombrearchivo, string linkarchivo, string patharchivo)
        {
            int       notiide = rondon.Next(24, 100000);
            WebClient cliente = new WebClient();

            ///cliente.Encoding = Encoding.UTF8;
            // cliente.Credentials = new NetworkCredential("anonymous", "");



            string titulo  = "Descargando localmente: " + Path.GetFileNameWithoutExtension(nombrearchivo);
            string tituloo = "";

            NotificationManager notificationManager =
                GetSystemService(Context.NotificationService) as NotificationManager;

            if (nombrearchivo.Trim().Length > 40)
            {
                titulo = titulo.Remove(40);
            }
            tituloo = titulo;
#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
            var builder = new Notification.Builder(ApplicationContext);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
            builder.SetContentTitle(titulo);
            builder.SetContentText("Espere por favor");
            builder.SetSmallIcon(Resource.Drawable.downloadbutton);
            builder.SetProgress(100, progreso, true);
            notificationManager.Notify(notiide, builder.Build());



            RunOnUiThread(() => Toast.MakeText(this, "Descargando localmente: " + Path.GetFileNameWithoutExtension(nombrearchivo) + " se le notificara de su progreso", ToastLength.Long).Show());



            cliente.DownloadFileCompleted += (aa, aaa) =>
            {
                progreso = 100;
                WebClient cliente2 = new WebClient();
                cliente2.Encoding    = Encoding.UTF8;
                cliente2.Credentials = new NetworkCredential("anonymous", "");

                cliente2.DownloadFileCompleted += delegate
                {
                };
                if (pathimagenesdelotro.StartsWith("/"))
                {
                    cliente2.DownloadFile(new Uri(@"ftp://" + ipdelotro + ":" + puertoarchivosdelotro + pathimagenesdelotro + linkarchivo.Split('=')[1]), Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits/" + linkarchivo.Split('=')[1]);
                }
                else
                {
                    try {
                        cliente2.DownloadFile(new Uri(@"ftp://" + ipdelotro + ":" + puertoarchivosdelotro + "/" + getteardisco(pathimagenesdelotro) + linkarchivo.Split('=')[1] + ".jpg"), Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits/" + linkarchivo.Split('=')[1]);
                    }
                    catch (Exception)
                    {
                        try {
                            cliente2.DownloadFile("http://i.ytimg.com/vi/" + linkarchivo.Split('=')[1] + "/mqdefault.jpg", Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits/" + linkarchivo.Split('=')[1]);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                // string perruris = "ftp://" + ipdelotro + ":" + puertoarchivosdelotro + "/" + getteardisco(pathimagenesdelotro) + linkarchivo.Split('=')[1] + ".jpg";



                escribirenregistro(Path.Combine(SettingsHelper.GetSetting("rutadescarga"), nombrearchivo), linkarchivo);
                Intent intentssdd = new Intent(this, typeof(actividadadinfooffline));
                intentssdd.PutExtra("nombre", Path.GetFileName(nombrearchivo));
                intentssdd.PutExtra("link", linkarchivo);
                intentssdd.PutExtra("path", Path.Combine(SettingsHelper.GetSetting("rutadescarga"), nombrearchivo));



                PendingIntent intentosd = PendingIntent.GetActivity(this, rondon.Next(24, 100000), intentssdd, PendingIntentFlags.UpdateCurrent);
                string        titulo2   = "Descarga local completada de : " + Path.GetFileNameWithoutExtension(nombrearchivo);
                string        tituloo2  = "";

                if (nombrearchivo.Trim().Length > 40)
                {
                    titulo2 = titulo2.Remove(40);
                }
                tituloo2 = titulo2;

                builder.SetContentTitle(titulo2);
                builder.SetContentText("Toque para abrir");
                builder.SetSmallIcon(Resource.Drawable.downloadbutton);
                builder.SetContentIntent(intentosd);
                builder.SetProgress(1, 1, false);
                notificationManager.Notify(notiide, builder.Build());
                RunOnUiThread(() => Toast.MakeText(this, "Descarga local de: " + Path.GetFileNameWithoutExtension(nombrearchivo) + " completada", ToastLength.Long).Show());
                new Thread(() => {
                    if (selectedtab == "Audios")
                    {
                        playeroffline.gettearinstancia().cargarmp3();
                    }
                    else
                    {
                        playeroffline.gettearinstancia().cargarvideos();
                    }


                    var adaptadol2 = new adapterlistaoffline(this, playeroffline.gettearinstancia().nombreses.ToList(), playeroffline.gettearinstancia().linkeses, "", playeroffline.gettearinstancia().nombreses, playeroffline.gettearinstancia().diccionario, playeroffline.gettearinstancia().patheses);
                    RunOnUiThread(() => listaelementos.Adapter = adaptadol2);
                }).Start();
            };
            if (patharchivo.StartsWith("/"))
            {
                cliente.DownloadFileAsync(new Uri(@"ftp://" + ipdelotro + ":" + puertoarchivosdelotro + patharchivo), Path.Combine(SettingsHelper.GetSetting("rutadescarga"), nombrearchivo));
            }
            else
            {
                cliente.DownloadFileAsync(new Uri(@"ftp://" + ipdelotro + ":" + puertoarchivosdelotro + "/" + getteardisco(patharchivo)), Path.Combine(SettingsHelper.GetSetting("rutadescarga"), nombrearchivo));
            }
        }
コード例 #9
0
        public static async void ShowLocalNot(LocalNot not, Context context = null)
        {
            var cc      = context ?? Application.Context;
            var builder = new Notification.Builder(cc);

            builder.SetContentTitle(not.title);

            bool containsMultiLine = not.body.Contains("\n");

            if (Build.VERSION.SdkInt < BuildVersionCodes.O || !containsMultiLine)
            {
                builder.SetContentText(not.body);
            }
            builder.SetSmallIcon(not.smallIcon);
            builder.SetAutoCancel(not.autoCancel);
            builder.SetOngoing(not.onGoing);

            if (not.progress != -1)
            {
                builder.SetProgress(100, not.progress, false);
            }

            builder.SetVisibility(NotificationVisibility.Public);
            builder.SetOnlyAlertOnce(true);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                var channelId = $"{cc.PackageName}.general";
                var channel   = new NotificationChannel(channelId, "General", (NotificationImportance)not.notificationImportance);
                NotManager.CreateNotificationChannel(channel);

                builder.SetChannelId(channelId);

                if (not.bigIcon != null)
                {
                    if (not.bigIcon != "")
                    {
                        var bitmap = await GetImageBitmapFromUrl(not.bigIcon);

                        if (bitmap != null)
                        {
                            builder.SetLargeIcon(bitmap);
                            if (not.mediaStyle)
                            {
                                builder.SetStyle(new Notification.MediaStyle());                                 // NICER IMAGE
                            }
                        }
                    }
                }

                if (containsMultiLine)
                {
                    var b = new Notification.BigTextStyle();
                    b.BigText(not.body);
                    builder.SetStyle(b);
                }

                if (not.actions.Count > 0)
                {
                    List <Notification.Action> actions = new List <Notification.Action>();

                    for (int i = 0; i < not.actions.Count; i++)
                    {
                        var _resultIntent = new Intent(context, typeof(MainIntentService));
                        _resultIntent.PutExtra("data", not.actions[i].action);
                        var pending = PendingIntent.GetService(context, 3337 + i + not.id,
                                                               _resultIntent,
                                                               PendingIntentFlags.UpdateCurrent
                                                               );
                        actions.Add(new Notification.Action(not.actions[i].sprite, not.actions[i].name, pending));
                    }

                    builder.SetActions(actions.ToArray());
                }
            }

            builder.SetShowWhen(not.showWhen);
            if (not.when != null)
            {
                builder.SetWhen(CurrentTimeMillis((DateTime)not.when));
            }
            var stackBuilder = Android.Support.V4.App.TaskStackBuilder.Create(cc);

            var resultIntent = GetLauncherActivity(cc);

            if (not.data != "")
            {
                resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
                var _data = Android.Net.Uri.Parse(not.data);                //"cloudstreamforms:tt0371746Name=Iron man=EndAll");
                resultIntent.SetData(_data);
                stackBuilder.AddNextIntent(resultIntent);
                var resultPendingIntent =
                    stackBuilder.GetPendingIntent(not.id, (int)PendingIntentFlags.UpdateCurrent);
                builder.SetContentIntent(resultPendingIntent);
            }
            else
            {
                stackBuilder.AddNextIntent(resultIntent);

                builder.SetContentIntent(GetCurrentPending());
            }

            try {
                NotManager.Notify(not.id, builder.Build());
            }
            catch { }
        }
コード例 #10
0
        /// <summary>
        /// //////////////////////////////////////////////////ignore
        /// </summary>
        /// <param name="path"></param>
        /// <param name="linkarchivo"></param>


        ///
        public void descargame(string nombrearchivo, string linkarchivo, string patharchivo)
        {
            int       notiide = rondon.Next(24, 100000);
            WebClient cliente = new WebClient();

            cliente.Encoding    = Encoding.UTF8;
            cliente.Credentials = new NetworkCredential("anonymous", "");

            RunOnUiThread(() => Toast.MakeText(this, "Descargando localmente: " + Path.GetFileNameWithoutExtension(nombrearchivo) + " se le notificara de su progreso", ToastLength.Long).Show());
            cliente.DownloadProgressChanged += (aa, aaa) =>
            {
                string titulo  = "Descargando localmente: " + Path.GetFileNameWithoutExtension(nombrearchivo);
                string tituloo = "";
                NotificationManager notificationManager =
                    GetSystemService(Context.NotificationService) as NotificationManager;
                if (nombrearchivo.Trim().Length > 40)
                {
                    titulo = titulo.Remove(40);
                }
                tituloo = titulo;
                var builder = new Notification.Builder(ApplicationContext);
                builder.SetContentTitle(titulo);
                builder.SetContentText("Espere por favor");
                builder.SetProgress(100, aaa.ProgressPercentage, false);
                builder.SetSmallIcon(Resource.Drawable.downloadbutton);
                if (aaa.ProgressPercentage == 20 || aaa.ProgressPercentage == 40 || aaa.ProgressPercentage == 60 || aaa.ProgressPercentage == 80 || aaa.ProgressPercentage == 100)
                {
                    notificationManager.Notify(notiide, builder.Build());
                }
            };
            cliente.DownloadFileCompleted += (aa, aaa) =>
            {
                WebClient cliente2 = new WebClient();
                cliente2.Encoding    = Encoding.UTF8;
                cliente2.Credentials = new NetworkCredential("anonymous", "");
                try
                {
                    cliente2.DownloadFileAsync(new Uri(@"ftp://" + ipdelotro + ":" + puertoarchivosdelotro + pathimagenesdelotro + linkarchivo.Split('=')[1]), Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits/" + linkarchivo.Split('=')[1]);
                    cliente2.DownloadFileCompleted += delegate
                    {
                        RunOnUiThread(() => fondo.SetImageBitmap(clasesettings.CreateBlurredImageoffline(this, 20, linkarchivo)));
                    };
                }
                catch (Exception)
                {
                }
                escribirenregistro(Path.Combine(clasesettings.gettearvalor("rutadescarga"), nombrearchivo), linkarchivo);
                Intent intentssdd = new Intent(this, typeof(actividadadinfooffline));
                intentssdd.PutExtra("nombre", Path.GetFileName(nombrearchivo));
                intentssdd.PutExtra("link", linkarchivo);
                intentssdd.PutExtra("path", Path.Combine(clasesettings.gettearvalor("rutadescarga"), nombrearchivo));



                PendingIntent       intentosd           = PendingIntent.GetActivity(this, rondon.Next(24, 100000), intentssdd, PendingIntentFlags.UpdateCurrent);
                string              titulo              = "Descarga local completada de : " + Path.GetFileNameWithoutExtension(nombrearchivo);
                string              tituloo             = "";
                NotificationManager notificationManager =
                    GetSystemService(Context.NotificationService) as NotificationManager;
                if (nombrearchivo.Trim().Length > 40)
                {
                    titulo = titulo.Remove(40);
                }
                tituloo = titulo;
                var builder = new Notification.Builder(ApplicationContext);
                builder.SetContentTitle(titulo);
                builder.SetContentText("Toque para abrir");
                builder.SetSmallIcon(Resource.Drawable.downloadbutton);
                builder.SetContentIntent(intentosd);
                notificationManager.Notify(notiide, builder.Build());
                RunOnUiThread(() => Toast.MakeText(this, "Descarga local de: " + Path.GetFileNameWithoutExtension(nombrearchivo) + " completada", ToastLength.Long).Show());
            };

            cliente.DownloadFileAsync(new Uri(@"ftp://" + ipdelotro + ":" + puertoarchivosdelotro + patharchivo), Path.Combine(clasesettings.gettearvalor("rutadescarga"), nombrearchivo));
        }
        /// <summary>
        /// Update the notification.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The updated notification.
        /// </returns>
        public Notification UpdateNotification(Context context)
        {
            var builder = new Notification.Builder(context);
            if (!string.IsNullOrEmpty(this.PausedText))
            {
                builder.SetContentTitle(this.PausedText);
                builder.SetContentText(string.Empty);
                builder.SetContentInfo(string.Empty);
            }
            else
            {
                builder.SetContentTitle(this.Title);
                if (this.TotalBytes > 0 && this.CurrentBytes != -1)
                {
                    builder.SetProgress((int)(this.TotalBytes >> 8), (int)(this.CurrentBytes >> 8), false);
                }
                else
                {
                    builder.SetProgress(0, 0, true);
                }

                builder.SetContentText(Helpers.GetDownloadProgressString(this.CurrentBytes, this.TotalBytes));
                builder.SetContentInfo(string.Format("{0}s left", Helpers.GetTimeRemaining(this.TimeRemaining)));
            }

            builder.SetSmallIcon(this.Icon != 0 ? this.Icon : Android.Resource.Drawable.StatSysDownload);
            builder.SetOngoing(true);
            builder.SetTicker(this.Ticker);
            builder.SetContentIntent(this.PendingIntent);

            return builder.Notification;
        }