예제 #1
0
        public static Notification GetNotification(Context context, MedicationDosage medication, DateTime occurrenceDate, Intent notificationIntent)
        {
            var builder = new NotificationCompat.Builder(context);

            builder.SetContentTitle(medication.Name);
            builder.SetTicker($"[PILLER] {medication.Name}");
            builder.SetSmallIcon(Resource.Drawable.pill64x64);


            builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Alarm));
            builder.SetPriority((int)NotificationPriority.High);
            builder.SetVisibility((int)NotificationVisibility.Public); // visible on locked screen

            RemoteViews contentView = new RemoteViews(context.PackageName, Resource.Layout.customNotification);

            contentView.SetTextViewText(Resource.Id.titleTextView, medication.Name);
            contentView.SetTextViewText(Resource.Id.descTextView, medication.Dosage + " - " + FormatOccurrence(occurrenceDate));

            if (medication?.ThumbnailName == null)
            {
                contentView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64));
            }
            else
            {
                ImageLoaderService imageLoader = Mvx.Resolve <ImageLoaderService>();
                byte[]             array       = imageLoader.LoadImage(medication.ThumbnailName);
                contentView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length));
            }

            RemoteViews contentBigView = new RemoteViews(context.PackageName, Resource.Layout.customBigNotification);

            contentBigView.SetTextViewText(Resource.Id.titleTextView, medication.Name);
            contentBigView.SetTextViewText(Resource.Id.descTextView, medication.Dosage + " - " + FormatOccurrence(occurrenceDate));

            PendingIntent intent = PendingIntent.GetActivity(context, 0, notificationIntent, 0);

            contentBigView.SetOnClickPendingIntent(Resource.Id.okButton, intent);

            intent = PendingIntent.GetActivity(context, 0, notificationIntent, 0);
            contentBigView.SetOnClickPendingIntent(Resource.Id.noButton, intent);

            intent = PendingIntent.GetActivity(context, 0, notificationIntent, 0);
            contentBigView.SetOnClickPendingIntent(Resource.Id.laterButton, intent);

            if (medication?.ThumbnailName == null)
            {
                contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64));
            }
            else
            {
                ImageLoaderService imageLoader = Mvx.Resolve <ImageLoaderService>();
                byte[]             array       = imageLoader.LoadImage(medication.ThumbnailName);
                contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length));
            }

            builder.SetCustomContentView(contentView);
            builder.SetCustomBigContentView(contentBigView);

            return(builder.Build());
        }
예제 #2
0
        // Build a widget update to show the current Wiktionary
        // "Word of the day." Will block until the online API returns.
        public RemoteViews buildUpdate(Context context)
        {
            // Build an update that holds the updated widget contents
            var updateViews = new RemoteViews(context.PackageName, Resource.Layout.widget_logo);

            Log.Debug("WIDGET", "Loading OTA");

            var ota = Arasoft.ClassicPhone.OTABitmap.FromUserData("00 48 1C 01 7F FF EF FF EF FF FB FF FE 40 3F E8 38 2F FF FB FF FE 48 3F A8 38 2F 9F FB FF FE 4C FF A9 FF 2F 8F FA DA DA 4E FF 29 01 2F 80 FA 52 52 5E 7F 69 31 2F BF 7B 07 06 4F FF 69 79 2F BE FB 77 76 47 FF 69 79 2F BE 7B 07 06 47 FE EF 7D EF BE 7B FF FE 47 FC EF 7D E7 BC F1 FF FC 40 F0 EF 7D E7 7C F1 ED BC 21 E7 C9 79 27 98 F1 E5 3C 21 E7 C9 39 27 C8 F1 F0 7C 16 6F 89 39 23 E6 E0 F7 78 15 2F 88 82 23 F3 E0 F0 78 08 3F 04 44 43 D7 E0 FF F8 04 3E 02 28 81 EF C0 7F F0 02 3C 01 39 00 FF 80 3F E0 01 38 00 BA 00 7F 00 1F C0 00 F0 00 7C 00 3E 00 0F 80 FF C0 00 38 00 1C 00 07 FF 55 FF FF FF FF FF FF FF AA 2A F3 87 87 3F 1E 67 0F 54 15 F3 93 9F 3E 4E 27 27 A8 2A F3 87 8F 3E 4E 07 27 54 55 F3 93 9F 3E 0E 47 27 AA FF F3 9B 87 0E 4E 67 0F FF 00 FF FF FF FF FF FF FF 00".Replace(" ", ""));

            var bmp = Bitmap.CreateBitmap(10 + ota.Width * 4, 10 + ota.Height * 4, Bitmap.Config.Argb8888);
            var cnv = new Canvas(bmp);
            var white = new Paint(PaintFlags.AntiAlias) { Color = Color.White };
            var dropshadow = new Paint(PaintFlags.AntiAlias) { Color = Color.Argb(127, 0, 0, 0) };

            Log.Debug("WIDGET", "Drawing bitmap");

            DrawOTA(ota, cnv, dropshadow, 6, 6);
            DrawOTA(ota, cnv, white, 5, 5);

            Log.Debug("WIDGET", "Bitmap generated");

            updateViews.SetImageViewBitmap(Resource.Id.logo, bmp);

            Log.Debug("WIDGET", "View bitmap set");

            return updateViews;
        }
예제 #3
0
        public static void Update(Context context, AppWidgetManager appWidgetManager, params int[] appWidgetIds)
        {
            foreach (int appWidgetId in appWidgetIds)
            {
                Step step;
                if (!TramUrWayApplication.Config.StepWidgets.TryGetValue(appWidgetId, out step))
                {
                    return;
                }

                RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.StepWidget);

                Intent intent = new Intent(context, typeof(StopActivity));
                intent.PutExtra("Stop", step.Stop.Id);
                intent.PutExtra("Route", step.Route.Id);

                int code = Util.Hash(step.Stop.Id, step.Route.Id);

                PendingIntent pendingIntent = PendingIntent.GetActivity(context, code, intent, 0);
                remoteViews.SetOnClickPendingIntent(Resource.Id.StepWidget_Button, pendingIntent);

                // Update widget UI
                remoteViews.SetTextViewText(Resource.Id.StepWidget_Name, step.Stop.Name);
                remoteViews.SetViewVisibility(Resource.Id.StepWidget_Description, TramUrWayApplication.Config.EnableWidgetRefresh ? ViewStates.Visible : ViewStates.Gone);

                Bitmap bitmap = Utils.GetTransportIconForLine(context, step.Route.Line, 48);
                remoteViews.SetImageViewBitmap(Resource.Id.StepWidget_Icon, bitmap);

                // Get step information
                if (TramUrWayApplication.Config.EnableWidgetRefresh)
                {
                    DateTime   now       = DateTime.Now;
                    TimeStep[] timeSteps = null;

                    try
                    {
                        timeSteps = TramUrWayApplication.Service.GetLiveTimeSteps(step.Route.Line).Where(t => t.Step.Stop == step.Stop).OrderBy(t => t.Date).Take(2).ToArray();
                    }
                    catch (Exception e)
                    {
                        timeSteps = TramUrWayApplication.Lines.SelectMany(l => l.Routes)
                                    .SelectMany(r => r.Steps.Where(s => s.Stop.Name == step.Stop.Name))
                                    .SelectMany(s => s.Route.TimeTable?.GetStepsFromStep(s, now)?.Take(3) ?? Enumerable.Empty <TimeStep>())
                                    .Take(2)
                                    .ToArray();
                    }

                    remoteViews.SetTextViewText(Resource.Id.StepWidget_Description, timeSteps == null ? "???" : Utils.GetReadableTimes(timeSteps, now, false));
                }

                try
                {
                    appWidgetManager.UpdateAppWidget(appWidgetId, remoteViews);
                }
                catch (Exception e)
                {
                    Toast.MakeText(context, "Exception while updating widget: " + e, ToastLength.Long).Show();
                }
            }
        }
예제 #4
0
        private async void UpdateDataNotification()
        {
            while (true)
            {
                if (info_radio != null && info_radio.track != current_name_track)
                {
                    contentView.SetImageViewBitmap(Resource.Id.notification_image, GetImageBitmapFromUrl(info_radio.image));
                    contentView.SetTextViewText(Resource.Id.notification_text_title, info_radio.track);
                    contentView.SetTextViewText(Resource.Id.notification_text_artist, info_radio.artist);

                    mNotifyManager.Notify(Id_Notification, notification);
                    current_name_track = info_radio.track;
                }
                await Task.Delay(3000);
            }
        }
예제 #5
0
        public static void BuildNotification(String songId)
        {
            MediaMetadataRetriever metadata = SongMetadata.GetMetadata(songId);

            string title   = metadata.ExtractMetadata(MetadataKey.Title);
            string content = metadata.ExtractMetadata(MetadataKey.Artist);

            if (title == null || content == null)
            {
                title   = "TubeLoad";
                content = AndroidSongsManager.Instance.GetSong(songId).Name.Replace(".mp3", "");
            }

            builder.SetSmallIcon(Resource.Drawable.icon);
            Drawable drawable = SongMetadata.GetSongPicture(songId);
            Bitmap   bitmap;

            if (drawable != null)
            {
                bitmap = ((BitmapDrawable)SongMetadata.GetSongPicture(songId)).Bitmap;
            }
            else
            {
                bitmap = BitmapFactory.DecodeResource(Application.Context.Resources, Resource.Drawable.default_song_image);
            }

            if (Android.OS.Build.VERSION.SdkInt > Android.OS.BuildVersionCodes.M)
            {
                RemoteViews notificationLayoutExpanded = new RemoteViews(Application.Context.PackageName, Resource.Layout.view_notification_actions);
                notificationLayoutExpanded.SetTextViewText(Resource.Id.notificationTitle, title);
                notificationLayoutExpanded.SetTextViewText(Resource.Id.notificationContent, content);
                notificationLayoutExpanded.SetImageViewBitmap(Resource.Id.songImg, bitmap);
                CreateNotificationMediaActions(notificationLayoutExpanded);
                builder.SetCustomBigContentView(notificationLayoutExpanded);
                builder.SetContentTitle(title);
            }
            else
            {
                builder.SetLargeIcon(bitmap);
                builder.SetContentTitle(title);
                builder.SetContentText(content);
            }

            songNotification = builder.Build();

            notificationManager.Notify(SONG_NOTIFICATION_ID, songNotification);
        }
예제 #6
0
        public RemoteViews GetViewAt(int position)
        {
            if (_source.Count == 0)
            {
                return(null);
            }

            var book = _source[position];

            var remoteViews = new RemoteViews(_context.PackageName, Resource.Layout.WidgetCell);

            remoteViews.SetTextViewText(Resource.Id.widgetcell_title, book.Title);

            var data  = _webApi.GetThumbnail(book.Thumbnail).Result;
            var image = BitmapFactory.DecodeByteArray(data, 0, data.Length);

            remoteViews.SetImageViewBitmap(Resource.Id.widgetcell_image, image);

            var intent = new Intent(); // TODO: セルごとにアクションを変えたい場合などはこのIntendにデータをセットする

            remoteViews.SetOnClickFillInIntent(Resource.Id.widgetcell_container, intent);

            return(remoteViews);
        }
        public void mostrarnotificacion()
        {
            var listapending = listapendingintents();


            RemoteViews contentView = new RemoteViews(PackageName, Resource.Layout.layoutminiplayeronline);

            if (linkactual.Trim().Length > 1)
            {
                try
                {
                    contentView.SetImageViewBitmap(Resource.Id.imageView1, ImageHelper.GetRoundedShape(GetImageBitmapFromUrl(linkactual)));
                    contentView.SetImageViewBitmap(Resource.Id.fondo1, ImageHelper.CreateBlurredImageFromUrl(this, 20, linkactual));
                }
                catch (Exception)
                {
                }
            }
            contentView.SetOnClickPendingIntent(Resource.Id.imageView1, listapending[5]);
            contentView.SetTextViewText(Resource.Id.textView1, tituloactual);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView2, listapending[0]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView4, listapending[1]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView3, listapending[2]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView6, listapending[3]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView5, listapending[4]);


            /*
             *
             * 1-playpause
             * 2-siguiente
             * 3-anterior
             * 4-adelantar
             * 5-atrazar
             *
             */

            Notification.Action accion1 = new Notification.Action(Resource.Drawable.playpause, "Playpause", listapending[0]);
            Notification.Action accion2 = new Notification.Action(Resource.Drawable.skipnext, "Siguiente", listapending[1]);
            Notification.Action accion3 = new Notification.Action(Resource.Drawable.skipprevious, "Anterior", listapending[2]);
            Notification.Action accion4 = new Notification.Action(Resource.Drawable.skipforward, "adelantar", listapending[3]);
            Notification.Action accion5 = new Notification.Action(Resource.Drawable.skipbackward, "atrazar", listapending[4]);

#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
            var nBuilder = new Notification.Builder(this);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
            Notification.MediaStyle estilo = new Notification.MediaStyle();
            if (Mainmenu.gettearinstancia() != null)
            {
                //  estilo.SetMediaSession(mainmenu.gettearinstancia().mSession.SessionToken);

                estilo.SetShowActionsInCompactView(1, 2, 3);
            }
            if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
#pragma warning disable 414
                try {
#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
                    nBuilder.SetContent(contentView);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
                }
                catch (Exception) {
                }

#pragma warning restore 414
            }
            else
            {
                nBuilder.SetStyle(estilo);
                nBuilder.SetLargeIcon(ImageHelper.GetImageBitmapFromUrl(linkactual));
                nBuilder.SetContentTitle(tituloactual);
                nBuilder.SetContentText("Desde: " + Mainmenu.gettearinstancia().devicename);
                nBuilder.AddAction(accion5);
                nBuilder.AddAction(accion3);
                nBuilder.AddAction(accion1);
                nBuilder.AddAction(accion2);
                nBuilder.AddAction(accion4);
                nBuilder.SetContentIntent(listapending[5]);
                nBuilder.SetColor(Android.Graphics.Color.ParseColor("#ce2c2b"));
            }
            nBuilder.SetOngoing(true);

            nBuilder.SetSmallIcon(Resource.Drawable.play);

            Notification notification = nBuilder.Build();
            StartForeground(19248736, notification);
        }
예제 #8
0
        private Notification BuildNotification()
        {
            _notificationBuilder = new NotificationCompat.Builder(ApplicationContext);
            _notificationBuilder.SetOngoing(true);
            _notificationBuilder.SetAutoCancel(false);
            _notificationBuilder.SetSmallIcon(Resource.Drawable.NotifIcon);
            //Open up the player screen when the user taps on the notification.
            var launchNowPlayingIntent = new Intent();

            launchNowPlayingIntent.SetAction(LaunchNowPlayingAction);
            var launchNowPlayingPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, launchNowPlayingIntent,
                                                                           0);

            _notificationBuilder.SetContentIntent(launchNowPlayingPendingIntent);

            //Grab the notification layouts.
            var notificationView = new RemoteViews(ApplicationContext.PackageName,
                                                   Resource.Layout.notification_custom_layout);
            var expNotificationView = new RemoteViews(ApplicationContext.PackageName,
                                                      Resource.Layout.notification_custom_expanded_layout);

            //Initialize the notification layout buttons.
            var previousTrackIntent = new Intent();

            previousTrackIntent.SetAction(PrevAction);
            var previousTrackPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0,
                                                                        previousTrackIntent, 0);

            var playPauseTrackIntent = new Intent();

            playPauseTrackIntent.SetAction(PlayPauseAction);
            var playPauseTrackPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0,
                                                                         playPauseTrackIntent, 0);

            var nextTrackIntent = new Intent();

            nextTrackIntent.SetAction(NextAction);
            var nextTrackPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, nextTrackIntent, 0);

            var stopServiceIntent = new Intent();

            stopServiceIntent.SetAction(StopAction);
            var stopServicePendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, stopServiceIntent,
                                                                      0);

            //Check if audio is playing and set the appropriate play/pause button.
            if (App.Current.AudioServiceConnection.GetPlaybackService().IsPlayingMusic)
            {
                notificationView.SetImageViewResource(Resource.Id.notification_base_play,
                                                      Resource.Drawable.btn_playback_pause_light);
                expNotificationView.SetImageViewResource(Resource.Id.notification_expanded_base_play,
                                                         Resource.Drawable.btn_playback_pause_light);
            }
            else
            {
                notificationView.SetImageViewResource(Resource.Id.notification_base_play,
                                                      Resource.Drawable.btn_playback_play_light);
                expNotificationView.SetImageViewResource(Resource.Id.notification_expanded_base_play,
                                                         Resource.Drawable.btn_playback_play_light);
            }

            var song = AudioPlayerHelper.CurrentQueueSong.Song;

            //Set the notification content.
            expNotificationView.SetTextViewText(Resource.Id.notification_expanded_base_line_one, song.Name);
            expNotificationView.SetTextViewText(Resource.Id.notification_expanded_base_line_two, song.ArtistName);
            expNotificationView.SetTextViewText(Resource.Id.notification_expanded_base_line_three, song.Album.Name);

            notificationView.SetTextViewText(Resource.Id.notification_base_line_one, song.Name);
            notificationView.SetTextViewText(Resource.Id.notification_base_line_two, song.ArtistName);

            //the previous and next buttons, always enabled.
            expNotificationView.SetViewVisibility(Resource.Id.notification_expanded_base_previous, ViewStates.Visible);
            expNotificationView.SetViewVisibility(Resource.Id.notification_expanded_base_next, ViewStates.Visible);
            expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_play,
                                                        playPauseTrackPendingIntent);
            expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_next,
                                                        nextTrackPendingIntent);
            expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_previous,
                                                        previousTrackPendingIntent);

            notificationView.SetViewVisibility(Resource.Id.notification_base_previous, ViewStates.Visible);
            notificationView.SetViewVisibility(Resource.Id.notification_base_next, ViewStates.Visible);
            notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_play, playPauseTrackPendingIntent);
            notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_next, nextTrackPendingIntent);
            notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_previous, previousTrackPendingIntent);

            //Set the "Stop Service" pending intents.
            expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_collapse,
                                                        stopServicePendingIntent);
            notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_collapse, stopServicePendingIntent);

            //Set the album art.
            if (song.Album.Artwork != null)
            {
                if (song.Album.Artwork.Image != null)
                {
                    expNotificationView.SetImageViewBitmap(Resource.Id.notification_expanded_base_image,
                                                           song.Album.Artwork.Image as Bitmap);
                    notificationView.SetImageViewBitmap(Resource.Id.notification_base_image,
                                                        song.Album.Artwork.Image as Bitmap);
                }
                else
                {
                    ((PclBitmapImage)song.Album.Artwork).PropertyChanged += OnPropertyChanged;
                }
            }
            else
            {
                song.Album.PropertyChanged += OnPropertyChanged;
            }

            //Attach the shrunken layout to the notification.
            _notificationBuilder.SetContent(notificationView);

            //Build the notification object.
            var notification = _notificationBuilder.Build();

            //Attach the expanded layout to the notification and set its flags.
            notification.BigContentView = expNotificationView;
            notification.Flags          = NotificationFlags.ForegroundService |
                                          NotificationFlags.NoClear |
                                          NotificationFlags.OngoingEvent;
            return(notification);
        }
        private void UpdateNowPlayingNotification()
        {
            Application.SynchronizationContext.Post(_ =>
            {
                try
                {
                    if (isNotifyPlayerActive)
                    {
                        var nm            = GetNotifyManager();
                        var remoteViewExp = new RemoteViews(PackageName, Resource.Layout.layout_notifi_player_exp);

                        remoteViewExp.SetImageViewResource(Resource.Id.ibNotifiAction3,
                                                           netStatus.StatusPlay == CmdHelper.NetStatus.Status.PAUSE
                                ? Resource.Drawable.play_100_black
                                : Resource.Drawable.pause_100_black);

                        Intent itAction = new Intent(BROAD_NOTIFY_PLAYER);
                        itAction.PutExtra("ACT", 0);
                        PendingIntent piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0);
                        remoteViewExp.SetOnClickPendingIntent(Resource.Id.ibNotifiAction1, piAction);

                        itAction = new Intent(BROAD_NOTIFY_PLAYER);
                        itAction.PutExtra("ACT", 1);
                        piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0);
                        remoteViewExp.SetOnClickPendingIntent(Resource.Id.ibNotifiAction2, piAction);

                        itAction = new Intent(BROAD_NOTIFY_PLAYER);
                        itAction.PutExtra("ACT", 2);
                        piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0);
                        remoteViewExp.SetOnClickPendingIntent(Resource.Id.ibNotifiAction3, piAction);

                        itAction = new Intent(BROAD_NOTIFY_PLAYER);
                        itAction.PutExtra("ACT", 3);
                        piAction = PendingIntent.GetBroadcast(this, IntentHelper.GetId(), itAction, 0);
                        remoteViewExp.SetOnClickPendingIntent(Resource.Id.ibNotifiAction4, piAction);

                        var titleName  = netTitleName?.TitleName;
                        var artistName = netArtistName?.ArtistName;

                        if (cmdInputState?.Parameter == "2E")
                        {
                            artistName = netTitleName?.TitleName;
                            titleName  = "Bluetooth";
                        }

                        if (titleName != null)
                        {
                            remoteViewExp.SetTextViewText(Resource.Id.tvNotifiTitle1, titleName);
                            remoteViewExp.SetViewVisibility(Resource.Id.tvNotifiTitle1, ViewStates.Visible);
                        }

                        if (artistName != null)
                        {
                            remoteViewExp.SetTextViewText(Resource.Id.tvNotifiTitle2, artistName);
                            remoteViewExp.SetViewVisibility(Resource.Id.tvNotifiTitle2, ViewStates.Visible);
                        }

                        if (netAlbumName?.AlbumName != null)
                        {
                            remoteViewExp.SetTextViewText(Resource.Id.tvNotifiTitle3, netAlbumName.AlbumName);
                            remoteViewExp.SetViewVisibility(Resource.Id.tvNotifiTitle3, ViewStates.Visible);
                        }

                        if (netArt?.bmArt != null)
                        {
                            remoteViewExp.SetImageViewBitmap(Resource.Id.ivNotifiCover, netArt.bmArt);
                            remoteViewExp.SetViewVisibility(Resource.Id.ivNotifiCover, ViewStates.Visible);
                        }
                        else
                        {
                            remoteViewExp.SetImageViewResource(Resource.Id.ivNotifiCover, Resource.Drawable.app_icon);
                            remoteViewExp.SetViewVisibility(Resource.Id.ivNotifiCover, ViewStates.Visible);
                        }

                        NotificationCompat.Builder nb = new NotificationCompat.Builder(ApplicationContext);


                        Intent intent = new Intent(this, typeof(HomeActivity));
                        intent.PutExtra(INTENT_HOME_TAB, 0);
                        intent.AddFlags(ActivityFlags.ClearTop);
                        intent.AddFlags(ActivityFlags.SingleTop);
                        PendingIntent pendingIntent = PendingIntent.GetActivity(this, IntentHelper.GetId(), intent, 0);
                        nb.SetContentIntent(pendingIntent);

                        nb.SetCustomBigContentView(remoteViewExp);
                        var x = remoteViewExp.Clone();
                        x.SetViewVisibility(Resource.Id.llNotifyExp, ViewStates.Gone);
                        nb.SetCustomContentView(x);

                        nb.SetSmallIcon(Resource.Drawable.av_receiver_100_black);
                        nb.SetOngoing(true);


                        nm.Notify(notifyIdPlayer, nb.Build());
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }, null);
        }
        public void mostrarnotificacion()
        {
            List <PendingIntent> listapending = listapendingintents();

            RemoteViews contentView = new RemoteViews(PackageName, Resource.Layout.layoutminiplayer);

            if (linkactual.Trim().Length > 1)
            {
                try
                {
                    // contentView.SetImageViewBitmap(Resource.Id.imageView1, playeroffline.gettearinstancia().imageneses.First(info => info.GenerationId == playeroffline.gettearinstancia().diccionario[tituloactual]));
                    contentView.SetImageViewBitmap(Resource.Id.fondo1, ImageHelper.CreateBlurredImageFromPortrait(this, 20, linkactual));
                }
                catch (Exception) {
                }

                ///   contentView.SetImageViewBitmap(Resource.Id.fondo1, clasesettings.CreateBlurredImageoffline(this, 20, linkactual));
            }
            contentView.SetTextViewText(Resource.Id.textView1, tituloactual);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView1, listapending[5]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView2, listapending[0]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView4, listapending[1]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView3, listapending[2]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView6, listapending[3]);
            contentView.SetOnClickPendingIntent(Resource.Id.imageView5, listapending[4]);



            Notification.Action accion1 = new Notification.Action(Resource.Drawable.playpause, "Playpause", listapending[0]);
            Notification.Action accion2 = new Notification.Action(Resource.Drawable.skipnext, "Siguiente", listapending[1]);
            Notification.Action accion3 = new Notification.Action(Resource.Drawable.skipprevious, "Anterior", listapending[2]);
            Notification.Action accion4 = new Notification.Action(Resource.Drawable.skipforward, "adelantar", listapending[3]);
            Notification.Action accion5 = new Notification.Action(Resource.Drawable.skipbackward, "atrazar", listapending[4]);

            /*
             *
             * 1-playpause
             * 2-siguiente
             * 3-anterior
             * 4-adelantar
             * 5-atrazar
             *
             */



            Notification.MediaStyle estilo = new Notification.MediaStyle();
            if (playeroffline.gettearinstancia() != null)
            {
                estilo.SetMediaSession(playeroffline.gettearinstancia().mSession.SessionToken);

                estilo.SetShowActionsInCompactView(1, 2, 3);
            }


#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
            var nBuilder = new Notification.Builder(this);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos

            if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
#pragma warning disable 414
                try
                {
#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
                    nBuilder.SetContent(contentView);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
                }
                catch (Exception) {
                }

#pragma warning restore 414
            }
            else
            {
                nBuilder.SetStyle(estilo);
                nBuilder.SetLargeIcon(GetImageBitmapFromUrl(Android.OS.Environment.ExternalStorageDirectory + "/.gr3cache/portraits/" + playeroffline.gettearinstancia().linkeses[playeroffline.gettearinstancia().nombreses.IndexOf(tituloactual)].Split('=')[1]));
                nBuilder.SetContentTitle(tituloactual);

                nBuilder.SetContentText(playeroffline.gettearinstancia().linkeses[playeroffline.gettearinstancia().nombreses.IndexOf(tituloactual)]);
                nBuilder.AddAction(accion5);
                nBuilder.AddAction(accion3);
                nBuilder.AddAction(accion1);
                nBuilder.AddAction(accion2);
                nBuilder.AddAction(accion4);
                nBuilder.SetContentIntent(listapending[5]);
                nBuilder.SetColor(Android.Graphics.Color.ParseColor("#ce2c2b"));

                //  nBuilder.AddAction()
            }

            nBuilder.SetOngoing(true);
            nBuilder.SetSmallIcon(Resource.Drawable.play);
            Notification notification = nBuilder.Build();
            StartForeground(19248736, notification);
            listapending.Clear();
        }
예제 #11
0
        private Notification BuildNotification()
        {
            _notificationBuilder = new NotificationCompat.Builder(ApplicationContext);
            _notificationBuilder.SetOngoing(true);
            _notificationBuilder.SetAutoCancel(false);
            _notificationBuilder.SetSmallIcon(Resource.Drawable.NotifIcon);
            //Open up the player screen when the user taps on the notification.
            var launchNowPlayingIntent = new Intent();
            launchNowPlayingIntent.SetAction(LaunchNowPlayingAction);
            var launchNowPlayingPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, launchNowPlayingIntent,
                0);
            _notificationBuilder.SetContentIntent(launchNowPlayingPendingIntent);

            //Grab the notification layouts.
            var notificationView = new RemoteViews(ApplicationContext.PackageName,
                Resource.Layout.notification_custom_layout);
            var expNotificationView = new RemoteViews(ApplicationContext.PackageName,
                Resource.Layout.notification_custom_expanded_layout);

            //Initialize the notification layout buttons.
            var previousTrackIntent = new Intent();
            previousTrackIntent.SetAction(PrevAction);
            var previousTrackPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0,
                previousTrackIntent, 0);

            var playPauseTrackIntent = new Intent();
            playPauseTrackIntent.SetAction(PlayPauseAction);
            var playPauseTrackPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0,
                playPauseTrackIntent, 0);

            var nextTrackIntent = new Intent();
            nextTrackIntent.SetAction(NextAction);
            var nextTrackPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, nextTrackIntent, 0);

            var stopServiceIntent = new Intent();
            stopServiceIntent.SetAction(StopAction);
            var stopServicePendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, stopServiceIntent,
                0);

            //Check if audio is playing and set the appropriate play/pause button.
            if (App.Current.AudioServiceConnection.GetPlaybackService().IsPlayingMusic)
            {
                notificationView.SetImageViewResource(Resource.Id.notification_base_play,
                    Resource.Drawable.btn_playback_pause_light);
                expNotificationView.SetImageViewResource(Resource.Id.notification_expanded_base_play,
                    Resource.Drawable.btn_playback_pause_light);
            }
            else
            {
                notificationView.SetImageViewResource(Resource.Id.notification_base_play,
                    Resource.Drawable.btn_playback_play_light);
                expNotificationView.SetImageViewResource(Resource.Id.notification_expanded_base_play,
                    Resource.Drawable.btn_playback_play_light);
            }

            var song = AudioPlayerHelper.CurrentQueueSong.Song;

            //Set the notification content.
            expNotificationView.SetTextViewText(Resource.Id.notification_expanded_base_line_one, song.Name);
            expNotificationView.SetTextViewText(Resource.Id.notification_expanded_base_line_two, song.ArtistName);
            expNotificationView.SetTextViewText(Resource.Id.notification_expanded_base_line_three, song.Album.Name);

            notificationView.SetTextViewText(Resource.Id.notification_base_line_one, song.Name);
            notificationView.SetTextViewText(Resource.Id.notification_base_line_two, song.ArtistName);

            //the previous and next buttons, always enabled.
            expNotificationView.SetViewVisibility(Resource.Id.notification_expanded_base_previous, ViewStates.Visible);
            expNotificationView.SetViewVisibility(Resource.Id.notification_expanded_base_next, ViewStates.Visible);
            expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_play,
                playPauseTrackPendingIntent);
            expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_next,
                nextTrackPendingIntent);
            expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_previous,
                previousTrackPendingIntent);

            notificationView.SetViewVisibility(Resource.Id.notification_base_previous, ViewStates.Visible);
            notificationView.SetViewVisibility(Resource.Id.notification_base_next, ViewStates.Visible);
            notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_play, playPauseTrackPendingIntent);
            notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_next, nextTrackPendingIntent);
            notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_previous, previousTrackPendingIntent);

            //Set the "Stop Service" pending intents.
            expNotificationView.SetOnClickPendingIntent(Resource.Id.notification_expanded_base_collapse,
                stopServicePendingIntent);
            notificationView.SetOnClickPendingIntent(Resource.Id.notification_base_collapse, stopServicePendingIntent);

            //Set the album art.
            if (song.Album.Artwork != null)
            {
                if (song.Album.Artwork.Image != null)
                {
                    expNotificationView.SetImageViewBitmap(Resource.Id.notification_expanded_base_image,
                        song.Album.Artwork.Image as Bitmap);
                    notificationView.SetImageViewBitmap(Resource.Id.notification_base_image,
                        song.Album.Artwork.Image as Bitmap);
                }
                else
                    ((PclBitmapImage) song.Album.Artwork).PropertyChanged += OnPropertyChanged;
            }
            else
                song.Album.PropertyChanged += OnPropertyChanged;

            //Attach the shrunken layout to the notification.
            _notificationBuilder.SetContent(notificationView);

            //Build the notification object.
            var notification = _notificationBuilder.Build();

            //Attach the expanded layout to the notification and set its flags.
            notification.BigContentView = expNotificationView;
            notification.Flags = NotificationFlags.ForegroundService |
                                 NotificationFlags.NoClear |
                                 NotificationFlags.OngoingEvent;
            return notification;
        }
        public static void SendLocalEdisonNotification(Context ctx, string notificationChannelId, string title, int smallIconResId, Color smallIconColor, string notificationCatagory,
                                                       int notificationVisibility, int notificationId, string notificationTag, PendingIntent pendingIntent, bool autoCancel, string summaryTitle,
                                                       string messageText, int contentIconResId, Color contentIconBackgroundColor,
                                                       int collapsedLayoutResId, int expandedLayoutResId, int headsupLayoutResId,
                                                       int largeIconResId, int titleResId, int responseTitleResId, int messageTextResId, int emergencyButtonResId, int activityButtonResId, int safeButtonResId,
                                                       PendingIntent emergencyIntent, PendingIntent activityIntent, PendingIntent safeIntent, string groupKey = null)
        {
            var notificationManager = NotificationManager.FromContext(ctx);
            var channel             = notificationManager.GetNotificationChannel(notificationChannelId);

            if (channel == null)
            {
                return;
            }

            //Map channel importance (Android 8+) to notification importance (android 7)
            int priority = MapToPriority(channel.Importance);

            // ensure visibility is valid
            if (notificationVisibility > NotificationCompat.VisibilityPublic || notificationVisibility < NotificationCompat.VisibilitySecret)
            {
                notificationVisibility = NotificationCompat.VisibilityPrivate;
            }

            var notificationBuilder = new NotificationCompat.Builder(ctx, notificationChannelId)
                                      .SetContentTitle(title)
                                      .SetSmallIcon(smallIconResId)
                                      .SetColor(smallIconColor)
                                      .SetPriority(priority)
                                      .SetCategory(notificationCatagory)
                                      .SetVisibility(notificationVisibility)
                                      .SetAutoCancel(autoCancel);

            SpannableStringBuilder sb = null;

            if (!string.IsNullOrWhiteSpace(summaryTitle))
            {
                sb = new SpannableStringBuilder(summaryTitle);
                sb.SetSpan(new StyleSpan(TypefaceStyle.Bold), 0, summaryTitle.Length, SpanTypes.ExclusiveExclusive);
                notificationBuilder.SetContentText(sb);
                if (!string.IsNullOrWhiteSpace(messageText))
                {
                    sb = new SpannableStringBuilder(summaryTitle);
                    sb.Append("\n");
                    sb.Append(messageText);
                    sb.SetSpan(new StyleSpan(TypefaceStyle.Bold), 0, summaryTitle.Length, SpanTypes.ExclusiveExclusive);
                    notificationBuilder.SetStyle(new NotificationCompat.BigTextStyle().BigText(sb));
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(messageText))
                {
                    notificationBuilder.SetContentText(messageText);
                    if (!string.IsNullOrWhiteSpace(messageText))
                    {
                        notificationBuilder.SetStyle(new NotificationCompat.BigTextStyle().BigText(messageText));
                    }
                }
            }


            if (pendingIntent != null)
            {
                notificationBuilder.SetContentIntent(pendingIntent);
            }

            Bitmap icon = null;

            if (contentIconResId != 0)
            {
                // build circular icon
                Drawable iconDrawable = Drawables.CircularIcon(ctx, contentIconResId, Color.White, contentIconBackgroundColor, PixelSizeConverter.DpToPx(15), PixelSizeConverter.DpToPx(140));
                // try to get bitmap
                icon = iconDrawable.ToBitmap();
                // Don't set the large icon otherwise it takes up the right hand side of the entire notification. Instead will set in the custom view
                //             if (icon != null)
                //                 notificationBuilder.SetLargeIcon(icon);
            }


            if (Build.VERSION.SdkInt >= BuildVersionCodes.N && !string.IsNullOrWhiteSpace(groupKey))
            {
                notificationBuilder.SetGroup(groupKey);
            }


            notificationBuilder.SetStyle(new NotificationCompat.DecoratedCustomViewStyle());

            RemoteViews collapsedContent = new RemoteViews(ctx.PackageName, collapsedLayoutResId);

            if (!string.IsNullOrWhiteSpace(title))
            {
                var titleText = title;
                if (!string.IsNullOrWhiteSpace(summaryTitle))
                {
                    titleText = titleText + ": " + summaryTitle;
                }
                collapsedContent.SetTextViewText(titleResId, titleText);
            }
            else if (!string.IsNullOrWhiteSpace(summaryTitle))
            {
                collapsedContent.SetTextViewText(titleResId, summaryTitle);
            }
            if (icon != null)
            {
                collapsedContent.SetImageViewBitmap(largeIconResId, icon);
            }
            collapsedContent.SetOnClickPendingIntent(emergencyButtonResId, emergencyIntent);
            collapsedContent.SetOnClickPendingIntent(activityButtonResId, activityIntent);
            collapsedContent.SetOnClickPendingIntent(safeButtonResId, safeIntent);
            notificationBuilder.SetCustomContentView(collapsedContent);

            RemoteViews headsupContent = new RemoteViews(ctx.PackageName, headsupLayoutResId);

            if (!string.IsNullOrWhiteSpace(title))
            {
                var titleText = title;
                if (!string.IsNullOrWhiteSpace(summaryTitle))
                {
                    titleText = titleText + ": " + summaryTitle;
                }
                headsupContent.SetTextViewText(titleResId, titleText);
            }
            else if (!string.IsNullOrWhiteSpace(summaryTitle))
            {
                headsupContent.SetTextViewText(titleResId, summaryTitle);
            }
            if (icon != null)
            {
                headsupContent.SetImageViewBitmap(largeIconResId, icon);
            }
            headsupContent.SetOnClickPendingIntent(emergencyButtonResId, emergencyIntent);
            headsupContent.SetOnClickPendingIntent(activityButtonResId, activityIntent);
            headsupContent.SetOnClickPendingIntent(safeButtonResId, safeIntent);
            notificationBuilder.SetCustomHeadsUpContentView(headsupContent);


            RemoteViews expandedContent = new RemoteViews(ctx.PackageName, expandedLayoutResId);

            if (!string.IsNullOrWhiteSpace(title))
            {
                expandedContent.SetTextViewText(titleResId, title);
            }
            if (!string.IsNullOrWhiteSpace(summaryTitle))
            {
                expandedContent.SetTextViewText(responseTitleResId, summaryTitle);
            }
            if (icon != null)
            {
                expandedContent.SetImageViewBitmap(largeIconResId, icon);
            }
            if (messageText != null)
            {
                expandedContent.SetTextViewText(messageTextResId, messageText);
            }
            expandedContent.SetOnClickPendingIntent(emergencyButtonResId, emergencyIntent);
            expandedContent.SetOnClickPendingIntent(activityButtonResId, activityIntent);
            expandedContent.SetOnClickPendingIntent(safeButtonResId, safeIntent);
            notificationBuilder.SetCustomBigContentView(expandedContent);

            notificationManager.Notify(notificationTag, notificationId, notificationBuilder.Build());
            icon?.Dispose();
        }
 public override void OnLoadingComplete(string imageUri, View view, Bitmap loadedImage)
 {
     mRemoteViews.SetImageViewBitmap(mImageResId, loadedImage);
     mAppWidgetManager.UpdateAppWidget(mAppWidgetId, mRemoteViews);
 }
예제 #14
0
            private void Loadimage(AnimeItemViewModel vm, RemoteViews views)
            {
                var bitmap = ImageService.Instance.LoadUrl(vm.ImgUrl).AsBitmapDrawableAsync().Result;

                views.SetImageViewBitmap(Resource.Id.Image, bitmap.Bitmap);
            }
예제 #15
0
        public static void Update(Context context, NextAlarm nextAlarm, int[] appWidgetIds = null)
        {
            AppWidgetManager appWidgetManager = AppWidgetManager.GetInstance(context);
            ComponentName    thisWidget       = new ComponentName(context, Class.FromType(typeof(Widget)).Name);

            if (appWidgetIds == null)
            {
                appWidgetIds = appWidgetManager.GetAppWidgetIds(thisWidget);
            }
            var prefs = PrefsKeys.GetPrefs(context);

            foreach (var appWidgetId in appWidgetIds)
            {
                var timeOffset = prefs.GetInt(PrefsKeys.TimeOffset + appWidgetId, 0);
                nextAlarm.RefreshDisplay(context, timeOffset);

                RemoteViews updateViews = new RemoteViews(context.PackageName, Resource.Layout.widget);
                var         useTodDom   = prefs.GetBoolean(PrefsKeys.DateUseTodTom + appWidgetId, true);
                if (useTodDom)
                {
                    updateViews.SetTextViewText(Resource.Id.alarm_date, nextAlarm.DayAbbreviated);
                }
                else
                {
                    updateViews.SetTextViewText(Resource.Id.alarm_date, nextAlarm.Day);
                }
                if (nextAlarm.Time.Length > 5)
                {
                    updateViews.SetTextViewText(Resource.Id.alarm_time_12, nextAlarm.Time);
                    updateViews.SetViewVisibility(Resource.Id.alarm_time_12, ViewStates.Visible);
                    updateViews.SetViewVisibility(Resource.Id.alarm_time_24, ViewStates.Gone);
                }
                else
                {
                    updateViews.SetTextViewText(Resource.Id.alarm_time_24, nextAlarm.Time);
                    updateViews.SetViewVisibility(Resource.Id.alarm_time_24, ViewStates.Visible);
                    updateViews.SetViewVisibility(Resource.Id.alarm_time_12, ViewStates.Gone);
                }

                var dateColor = new Color(prefs.GetInt(PrefsKeys.DateColor + appWidgetId, context.GetCompatColor(Resource.Color.date)));
                updateViews.SetTextColor(Resource.Id.alarm_date, dateColor);
                var dateTextSize = prefs.GetInt(PrefsKeys.DateTextSize + appWidgetId, -1);
                if (dateTextSize != -1)
                {
                    updateViews.SetTextViewTextSize(Resource.Id.alarm_date, (int)ComplexUnitType.Dip, dateTextSize);
                }


                var timeColor = new Color(prefs.GetInt(PrefsKeys.TimeColor + appWidgetId, context.GetCompatColor(Resource.Color.time)));
                updateViews.SetTextColor(Resource.Id.alarm_time_24, timeColor);
                updateViews.SetTextColor(Resource.Id.alarm_time_12, timeColor);

                var timeTextSize = prefs.GetInt(PrefsKeys.TimeTextSize + appWidgetId, -1);
                if (timeTextSize != -1)
                {
                    updateViews.SetTextViewTextSize(Resource.Id.alarm_time_24, (int)ComplexUnitType.Dip, timeTextSize);
                    updateViews.SetTextViewTextSize(Resource.Id.alarm_time_12, (int)ComplexUnitType.Dip, timeTextSize);
                }

                var         iconColor    = new Color(prefs.GetInt(PrefsKeys.IconColor + appWidgetId, context.GetCompatColor(Resource.Color.icon)));
                Bitmap      sourceBitmap = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ic_alarm_white_18dp);
                Bitmap      resultBitmap = Bitmap.CreateBitmap(sourceBitmap.Width, sourceBitmap.Height, Bitmap.Config.Argb8888);
                Paint       p            = new Paint();
                float[]     matrix       = { 0, 0, 0, iconColor.R / 255f, 0,
                                             0,           0, 0, iconColor.G / 255f, 0,
                                             0,           0, 0, iconColor.B / 255f, 0,
                                             0,           0, 0, iconColor.A / 255f, 0 };
                ColorFilter filter = new ColorMatrixColorFilter(matrix);
                p.SetColorFilter(filter);
                Canvas canvas = new Canvas(resultBitmap);
                canvas.DrawBitmap(sourceBitmap, 0, 0, p);
                updateViews.SetImageViewBitmap(Resource.Id.alarm_icon, resultBitmap);

                var backgroundColor = new Color(prefs.GetInt(PrefsKeys.BackgroundColor + appWidgetId, context.GetCompatColor(Resource.Color.background)));
                updateViews.SetInt(Resource.Id.background, "setColorFilter", backgroundColor.ToArgb());
                updateViews.SetInt(Resource.Id.background, "setAlpha", backgroundColor.A);

                updateViews.SetOnClickPendingIntent(Resource.Id.widget_root, nextAlarm.RelayIntent);
                appWidgetManager.UpdateAppWidget(appWidgetId, updateViews);
            }

            ScheduleMidnightUpdate(context);
        }
예제 #16
0
            public void OnCompleted(int task, int splitLineIndex, string pastedText, List <List <object> > tempLines, int curPos, long tempStartPos, long tempEndPos, bool isRemaining, List <Bookmark> foundBookmarks)
            {
                StringBuilder pinyin = new StringBuilder("");

                RemoteViews smallView = null;

                if (Build.VERSION.SdkInt < BuildVersionCodes.JellyBean)
                {
                    foreach (List <object> line in tempLines)
                    {
                        object lastWord = null;

                        foreach (object word in line)
                        {
                            if (lastWord != null && (lastWord is int? || lastWord.GetType() != word.GetType()))
                            {
                                pinyin.Append(" ");
                            }

                            if (word is string)
                            {
                                pinyin.Append((string)word);
                            }
                            else
                            {
                                pinyin.Append(Dict.PinyinToTones(Dict.GetPinyin((int)word)));
                            }

                            lastWord = word;
                        }
                    }

                    smallView = new RemoteViews(Service.PackageName, Resource.Layout.Notification_Small);
                    smallView.SetTextViewText(Resource.Id.notifsmall_text, pinyin);
                }
                else
                {
                    smallView = new RemoteViews(Service.PackageName, Resource.Layout.Notification_Big);
                }

                Service.dict = null;

                NotificationCompat.Builder mBuilder = (new NotificationCompat.Builder(Service.ApplicationContext))
                                                      .SetSmallIcon(Resource.Drawable.notification)
                                                      .SetContentTitle("ChineseReader")
                                                      .SetContentText(pinyin)
                                                      .SetContent(smallView)
                                                      .SetPriority(NotificationCompat.PriorityMax)
                                                      .SetVibrate(new long[0]);


                Intent resultIntent = new Intent(Service.Application, typeof(MainActivity));

                resultIntent.SetAction(Intent.ActionSend);
                resultIntent.SetType("text/plain");
                resultIntent.PutExtra(Intent.ExtraText, pastedText);

                // The stack builder object will contain an artificial back stack for the
                // started Activity.
                // This ensures that navigating backward from the Activity leads out of
                // your application to the Home screen.
                global::Android.Support.V4.App.TaskStackBuilder stackBuilder = global::Android.Support.V4.App.TaskStackBuilder.Create(Service.ApplicationContext);

                // Adds the back stack for the Intent (but not the Intent itself)
                stackBuilder.AddParentStack(Class.FromType(typeof(MainActivity)));

                // Adds the Intent that starts the Activity to the top of the stack
                stackBuilder.AddNextIntent(resultIntent);
                PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

                mBuilder.SetContentIntent(resultPendingIntent);
                NotificationManager mNotificationManager = (NotificationManager)Service.GetSystemService(Context.NotificationService);

                mNotificationManager.CancelAll();

                // mId allows you to update the notification_big later on.
                Notification notif = mBuilder.Build();

                if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean)
                {
                    LineView lv = new LineView(Service.context);
                    lv.line         = tempLines[0];
                    lv.lines        = tempLines;
                    lv.hlIndex      = new Point(-1, -1);
                    lv.top          = new List <string>();
                    lv.bottom       = new List <string>();
                    lv.tones        = new List <int>();
                    lv.charTypeface = Typeface.Default;

                    int wordHeight = (int)(lv.WordHeight);
                    int lineCount  = (int)System.Math.Min(tempLines.Count, System.Math.Floor(256 * lv.scale / wordHeight) + 1);
                    int width      = (int)System.Math.Round((double)AnnTask.screenWidth);
                    lv.Measure(width, wordHeight);
                    lv.Layout(0, 0, width, wordHeight);
                    Bitmap bitmap  = Bitmap.CreateBitmap(width, (int)System.Math.Min(System.Math.Max(64 * lv.scale, wordHeight * lineCount), 256 * lv.scale), Bitmap.Config.Argb8888);
                    Canvas canvas  = new Canvas(bitmap);
                    Paint  whiteBg = new Paint();
                    whiteBg.Color = Color.ParseColor("FFFFFFFF");
                    canvas.DrawRect(0, 0, canvas.Width, canvas.Height, whiteBg);

                    for (int i = 0; i < lineCount; i++)
                    {
                        lv.lines = tempLines;
                        lv.line  = tempLines[i];
                        lv.bottom.Clear();
                        lv.top.Clear();
                        lv.tones.Clear();
                        int count = lv.lines[i].Count;

                        if (count == 0 || lv.line[count - 1] is string && ((string)lv.line[count - 1]).Length == 0 || tempEndPos >= pastedText.Length && i == tempLines.Count - 1)
                        {
                            lv.lastLine = true;
                        }
                        else
                        {
                            lv.lastLine = false;
                        }

                        for (int j = 0; j < count; j++)
                        {
                            object word = lv.lines[i][j];

                            if (word is string)
                            {
                                lv.bottom.Add((string)word);
                                lv.top.Add("");
                                lv.tones.Add(0);
                            }
                            else
                            {
                                int    entry = (int)word;
                                string key   = Dict.GetCh(entry);
                                lv.bottom.Add(key);
                                if (Service.sharedPrefs.GetString("pref_pinyinType", "marks").Equals("none"))
                                {
                                    lv.top.Add("");
                                }
                                else
                                {
                                    lv.top.Add(Dict.PinyinToTones(Dict.GetPinyin(entry)));
                                }

                                if (Service.sharedPrefs.GetString("pref_toneColors", "none").Equals("none"))
                                {
                                    lv.tones.Add(0);
                                }
                                else
                                {
                                    int tones        = int.Parse(Regex.Replace(Dict.GetPinyin(entry), @"[\\D]", ""));
                                    int reverseTones = 0;
                                    while (tones != 0)
                                    {
                                        reverseTones = reverseTones * 10 + tones % 10;
                                        tones        = tones / 10;
                                    }
                                    lv.tones.Add(reverseTones);
                                }
                            }
                        }

                        lv.Draw(canvas);
                        canvas.Translate(0, wordHeight);
                    }

                    RemoteViews bigView = new RemoteViews(Service.PackageName, Resource.Layout.Notification_Big);
                    bigView.SetImageViewBitmap(Resource.Id.notif_img, bitmap);
                    smallView.SetImageViewBitmap(Resource.Id.notif_img, Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, (int)(64 * lv.scale)));
                    notif.BigContentView = bigView;
                }

                mNotificationManager.Notify(NOTIFICATION_ID, notif);
            }
예제 #17
0
        private void UpdateWidgetView()
        {
            if (_isShutDowning)
                return;

            Console.WriteLine("WidgetService - UpdateWidgetView");

            try
            {
                // Update widget
                Console.WriteLine("WidgetService - UpdateWidgetView - Getting widgets (0)...");
                RemoteViews viewWidget = new RemoteViews(PackageName, Resource.Layout.WidgetPlayer);
                Console.WriteLine("WidgetService - UpdateWidgetView - Getting widgets (1)...");
                AppWidgetManager manager = AppWidgetManager.GetInstance(this);
                Console.WriteLine("WidgetService - UpdateWidgetView - Getting widgets (2) - appWidgetIds count: {0}", _widgetIds.Length);

                // Update metadata on widget
                if (_audioFile != null)
                {
                    viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblArtistName, _audioFile.ArtistName);
                    viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblAlbumTitle, _audioFile.AlbumTitle);
                    viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblSongTitle, _audioFile.Title);
                }
                else
                {
                    viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblArtistName, "");
                    viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblAlbumTitle, "");
                    viewWidget.SetTextViewText(Resource.Id.widgetPlayer_lblSongTitle, "");                                    
                }

                if (_status == PlayerStatusType.Initialized ||
                    _status == PlayerStatusType.Paused ||
                    _status == PlayerStatusType.Stopped)
                {
                    viewWidget.SetImageViewResource(Resource.Id.widgetPlayer_btnPlayPause, Resource.Drawable.player_play);
                }
                else
                {
                    viewWidget.SetImageViewResource(Resource.Id.widgetPlayer_btnPlayPause, Resource.Drawable.player_pause);
                }

                // Update album art on widget
                if (_bitmapAlbumArt == null)
                    viewWidget.SetImageViewResource(Resource.Id.widgetPlayer_imageAlbum, 0);
                else
                    viewWidget.SetImageViewBitmap(Resource.Id.widgetPlayer_imageAlbum, _bitmapAlbumArt);

                Console.WriteLine("WidgetService - UpdateWidgetView - Getting widgets (3) - appWidgetIds count: {0}", _widgetIds.Length);

                foreach (int id in _widgetIds)
                {
                    Console.WriteLine("WidgetService - UpdateWidgetView - Updating widgets - id: {0}", id);
                    manager.UpdateAppWidget(id, viewWidget);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("WidgetService - UpdateWidgetView - Widget exception: {0}", ex);
            }
        }
예제 #18
0
        private void StartForeground(bool flag)
        {
            Intent        resultIntent        = new Intent(this, typeof(MainActivity));
            PendingIntent resultPendingIntent = PendingIntent.GetActivity(this, 0, resultIntent, PendingIntentFlags.UpdateCurrent);

            PendingIntent play_pauseAction   = null;
            int           notificationAction = Android.Resource.Drawable.IcMediaPause;

            var intent_receiver = new Intent(Receiver.ButtonPlayNotificationReceiver.ReceiverPlay);

            if (flag)
            {
                notificationAction = Android.Resource.Drawable.IcMediaPause;
                play_pauseAction   = ActionsInNotification(0);
                intent_receiver.PutExtra("buttonflag", false);
            }
            else
            {
                notificationAction = Android.Resource.Drawable.IcMediaPlay;
                play_pauseAction   = ActionsInNotification(1);
                intent_receiver.PutExtra("buttonflag", true);
            }
            SendBroadcast(intent_receiver);

            contentView = new RemoteViews(ApplicationContext.PackageName, Resource.Layout.notification);

            if (info_radio != null)
            {
                contentView.SetImageViewBitmap(Resource.Id.notification_image, GetImageBitmapFromUrl(info_radio.image));
                contentView.SetTextViewText(Resource.Id.notification_text_title, info_radio.track);
                contentView.SetTextViewText(Resource.Id.notification_text_artist, info_radio.artist);
            }
            else
            {
                contentView.SetImageViewBitmap(Resource.Id.notification_image, GetImageBitmapFromUrl("http://medianau.top/images/logo.png"));
                contentView.SetTextViewText(Resource.Id.notification_text_title, "Подключение...");
                contentView.SetTextViewText(Resource.Id.notification_text_artist, "");
            }

            contentView.SetImageViewResource(Resource.Id.notification_button_play, notificationAction);
            contentView.SetOnClickPendingIntent(Resource.Id.notification_button_play, play_pauseAction);
            contentView.SetOnClickPendingIntent(Resource.Id.notification_button_cancel, ActionsInNotification(2));

            NotifyBuilder = new NotificationCompat.Builder(this, Id_Channel);

            notification = NotifyBuilder.SetContentTitle("Radio NAU started!")
                           .SetTicker("Radio NAU started!")
                           .SetContentText("Radio NAU started!")
                           .SetSmallIcon(Resource.Mipmap.logo_min)
                           .SetContentIntent(resultPendingIntent)
                           .SetPriority(Android.Support.V4.App.NotificationCompat.PriorityDefault)
                           .SetSound(null)
                           .SetOngoing(true)
                           .SetAutoCancel(false)
                           .SetVisibility(NotificationCompat.VisibilityPublic)
                           .Build();

            notification.BigContentView = contentView;

            mNotifyManager = (NotificationManager)GetSystemService(Context.NotificationService);
            if (Build.VERSION.SdkInt >= Build.VERSION_CODES.O)
            {
                NotificationChannel channel = new NotificationChannel(Id_Channel, GetString(Resource.String.noti_channel_default), NotificationImportance.High);
                channel.SetShowBadge(false);
                mNotifyManager.CreateNotificationChannel(channel);
            }
            //mNotifyManager.Notify(Id_Notification, notification);
            StartForeground(Id_Notification, notification);
        }
예제 #19
0
        public static Notification GetNotification(Context context, MedicationDosage medication, NotificationOccurrence notificationOccurrence, Intent notificationIntent)
        {
            var builder = new NotificationCompat.Builder(context);

            builder.SetContentTitle(medication.Name);
            builder.SetTicker($"[PILLER] {medication.Name}");
            builder.SetSmallIcon(Resource.Drawable.pill64x64);

            var data = JsonConvert.DeserializeObject <SettingsData>(Mvx.Resolve <ISettings>().GetValue <string>(SettingsData.Key));

            Android.Net.Uri ring = Android.Net.Uri.Parse(data.RingUri);
            builder.SetSound(ring);

            builder.SetPriority((int)NotificationPriority.High);
            builder.SetVisibility((int)NotificationVisibility.Public); // visible on locked screen

            RemoteViews contentView = new RemoteViews(context.PackageName, Resource.Layout.customNotification);

            contentView.SetTextViewText(Resource.Id.titleTextView, medication.Name + " " + medication.Dosage);
            contentView.SetTextViewText(Resource.Id.descTextView, FormatOccurrence(notificationOccurrence.OccurrenceDateTime));
            //contentView.SetImageViewBitmap(Resource.Id.iconView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64));

            RemoteViews contentBigView = new RemoteViews(context.PackageName, Resource.Layout.customBigNotification);

            contentBigView.SetTextViewText(Resource.Id.titleTextView, medication.Name + " " + medication.Dosage);
            contentBigView.SetTextViewText(Resource.Id.descTextView, FormatOccurrence(notificationOccurrence.OccurrenceDateTime));

            if (medication?.ThumbnailName == null)
            {
                var roundedImage = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64);
                contentView.SetImageViewBitmap(Resource.Id.imageView, roundedImage);
                contentBigView.SetImageViewBitmap(Resource.Id.iconView, roundedImage);
            }
            else
            {
                var    imageLoader = Mvx.Resolve <ImageLoaderService>();
                byte[] array       = imageLoader.LoadImage(medication.ThumbnailName);
                contentView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length));
                contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length));
            }

            var medicationId   = medication.Id.Value;
            var notificationId = notificationOccurrence.Id.Value;

            System.Diagnostics.Debug.Write(notificationId);

            Intent okIntent    = new Intent(notificationIntent);
            Intent noIntent    = new Intent(notificationIntent);
            Intent laterIntent = new Intent(notificationIntent);

            notificationIntent.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId);
            okIntent.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId);
            noIntent.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId);
            laterIntent.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId);
            notificationIntent.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId);
            okIntent.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId);
            noIntent.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId);
            laterIntent.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId);

            okIntent.SetAction("OK");
            noIntent.SetAction("LATER");
            //laterIntent.SetAction("LATER");

            PendingIntent ok_intent = PendingIntent.GetBroadcast(context, Environment.TickCount, okIntent, 0);

            contentBigView.SetOnClickPendingIntent(Resource.Id.okButton, ok_intent);

            PendingIntent no_intent = PendingIntent.GetBroadcast(context, Environment.TickCount, noIntent, 0);

            contentBigView.SetOnClickPendingIntent(Resource.Id.noButton, no_intent);

            //PendingIntent later_intent = PendingIntent.GetBroadcast(context, Environment.TickCount, laterIntent, 0);
            //contentBigView.SetOnClickPendingIntent(Resource.Id.laterButton, later_intent);
            //contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64));

            if (medication?.ThumbnailName == null)
            {
                contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.pill64x64));
            }
            else
            {
                ImageLoaderService imageLoader = Mvx.Resolve <ImageLoaderService>();
                byte[]             array       = imageLoader.LoadImage(medication.ThumbnailName);
                contentBigView.SetImageViewBitmap(Resource.Id.imageView, BitmapFactory.DecodeByteArray(array, 0, array.Length));
            }

            builder.SetCustomContentView(contentView);
            builder.SetCustomBigContentView(contentBigView);

            var notification = builder.Build();
            // action upon notification click
            var notificationMainAction = new Intent(context, typeof(NotificationPublisher));

            notificationMainAction.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId);
            notificationMainAction.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId);
            notificationMainAction.SetAction("GO_TO_MEDICATION");
            var flags = (PendingIntentFlags)((int)PendingIntentFlags.CancelCurrent | (int)NotificationFlags.AutoCancel);

            notification.ContentIntent = PendingIntent.GetBroadcast(context, notificationId, notificationMainAction, flags);

            // action upon notification dismiss
            var notificationDismissAction = new Intent(context, typeof(NotificationPublisher));

            notificationDismissAction.PutExtra(NotificationPublisher.MEDICATION_ID, medicationId);
            notificationDismissAction.PutExtra(NotificationPublisher.NOTIFICATION_ID, notificationId);
            notificationDismissAction.SetAction("NOTIFCATION_DISMISS");
            //var flags = (PendingIntentFlags)((int)PendingIntentFlags.CancelCurrent | (int)NotificationFlags.AutoCancel);
            notification.DeleteIntent = PendingIntent.GetBroadcast(context, notificationId, notificationDismissAction, flags);

            return(notification);
        }