Esempio n. 1
0
        public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            Console.WriteLine("PlayerWidgetProvider - OnUpdate - appWidgetIds.length: {0}", appWidgetIds.Length);
            AlarmManager alarmManager = (AlarmManager)context.GetSystemService(Context.AlarmService);

            Intent intentAlarm = new Intent(context, typeof(WidgetService));
            intentAlarm.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intentAlarm.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);
            if (_pendingIntentWidgetService == null)
                _pendingIntentWidgetService = PendingIntent.GetService(context, 0, intentAlarm, PendingIntentFlags.CancelCurrent);

            Calendar time = Calendar.Instance;
            time.Set(CalendarField.Minute, 0);
            time.Set(CalendarField.Second, 0);
            time.Set(CalendarField.Millisecond, 0);
            alarmManager.SetRepeating(AlarmType.Rtc, time.Time.Time, 1000 * 10, _pendingIntentWidgetService);
            //alarmManager.SetRepeating(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime(), 1000, _pendingIntentWidgetService);

            for (int a = 0; a < appWidgetIds.Length; a++)
            {
                int appWidgetId = appWidgetIds[a];
                RemoteViews views = new RemoteViews(context.PackageName, Resource.Layout.WidgetPlayer);

                //var intentBackground = new Intent(context, typeof (WidgetService));
                //intentBackground.SetAction(SessionsWidgetActions.op.ToString());
                //intentBackground.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);
                //var pendingIntentBackgroundClick = PendingIntent.GetService(context, appWidgetId, intentBackground, PendingIntentFlags.UpdateCurrent);
                //views.SetOnClickPendingIntent(Resource.Id.widgetPlayer, pendingIntentBackgroundClick);

                var intentPrevious = new Intent(context, typeof(WidgetService));
                intentPrevious.SetAction(SessionsWidgetActions.SessionsWidgetPrevious.ToString());
                intentPrevious.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);
                var pendingIntentPreviousClick = PendingIntent.GetService(context, appWidgetId, intentPrevious, PendingIntentFlags.UpdateCurrent);
                views.SetOnClickPendingIntent(Resource.Id.widgetPlayer_btnPrevious, pendingIntentPreviousClick);

                var intentPlayPause = new Intent(context, typeof(WidgetService));
                intentPlayPause.SetAction(SessionsWidgetActions.SessionsWidgetPlayPause.ToString());
                intentPlayPause.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);
                var pendingIntentPlayPauseClick = PendingIntent.GetService(context, appWidgetId, intentPlayPause, PendingIntentFlags.UpdateCurrent);
                views.SetOnClickPendingIntent(Resource.Id.widgetPlayer_btnPlayPause, pendingIntentPlayPauseClick);

                var intentNext = new Intent(context, typeof(WidgetService));
                intentNext.SetAction(SessionsWidgetActions.SessionsWidgetNext.ToString());
                intentNext.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);
                var pendingIntentNextClick = PendingIntent.GetService(context, appWidgetId, intentNext, PendingIntentFlags.UpdateCurrent);
                views.SetOnClickPendingIntent(Resource.Id.widgetPlayer_btnNext, pendingIntentNextClick);

                appWidgetManager.UpdateAppWidget(appWidgetId, views);
            }
        }
        private void RegisterClicks(Context context, int[] appWidgetIds, RemoteViews widgetView)
        {
            var intent = new Intent(context, typeof(ButtonWidget));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);

            // Register click event for the Background
            var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            widgetView.SetOnClickPendingIntent(Resource.Id.btn_scan_qr, piBackground);

            widgetView.SetOnClickPendingIntent(Resource.Id.btn_scan_qr,
                                               GetPendingSelfIntent(context, AnnouncementClick));
        }
Esempio n. 3
0
        private void RegisterClicks(Context context, int[] appWidgetIds, RemoteViews widgetView)
        {
            var intent = new Intent(context, typeof(ClassTableWidget));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);

            // Register click event for the Background
            var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            widgetView.SetOnClickPendingIntent(Resource.Id.lastrefreshtime, piBackground);
            widgetView.SetOnClickPendingIntent(Resource.Id.ClassGrid, piBackground);

            // Register click event for the Announcement-icon
        }
Esempio n. 4
0
        public void UpdateWidgets(Context context, AppWidgetManager appWidgetManager,
                                  int[] appWidgetIds, string updateMessage, string totalVal, string profitVal, Color profCol, bool updating, bool setIntents = false)
        {
            for (int i = 0; i < appWidgetIds.Length; i++)
            {
                int         widgetId    = appWidgetIds[i];
                RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.Widget);
                remoteViews.SetViewVisibility(Resource.Id.widgetButton, (updating)?
                                              Android.Views.ViewStates.Gone : Android.Views.ViewStates.Visible);
                remoteViews.SetViewVisibility(Resource.Id.widgetLoading, (updating)?
                                              Android.Views.ViewStates.Visible : Android.Views.ViewStates.Gone);

                if (!string.IsNullOrWhiteSpace(profitVal))
                {
                    remoteViews.SetTextViewText(Resource.Id.widgetProfit, profitVal);
                    remoteViews.SetTextColor(Resource.Id.widgetProfit, profCol);
                }

                if (!string.IsNullOrWhiteSpace(totalVal))
                {
                    remoteViews.SetTextViewText(Resource.Id.widgetTotal, totalVal);
                }

                if (!string.IsNullOrWhiteSpace(updateMessage))
                {
                    remoteViews.SetTextViewText(Resource.Id.widgetTime, updateMessage);
                }

                if (setIntents)
                {
                    Intent intent = new Intent(context, typeof(HodlrWidgetProvider));
                    intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
                    intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);

                    PendingIntent pendingIntent = PendingIntent.GetBroadcast(
                        context, 0, intent, PendingIntentFlags.UpdateCurrent);

                    remoteViews.SetOnClickPendingIntent(Resource.Id.widgetButton, pendingIntent);


                    Intent        activityIntent = new Intent(context, typeof(MainActivity));
                    PendingIntent pendingAct     = PendingIntent.GetActivity(context, 0, activityIntent, 0);
                    remoteViews.SetOnClickPendingIntent(Resource.Id.widgetImage, pendingAct);
                }

                appWidgetManager.UpdateAppWidget(widgetId, remoteViews);
            }
        }
Esempio n. 5
0
        private void CreateClickIntent(Context context, int[] ids, RemoteViews remoteViews)
        {
            var intent = new Intent(context, typeof(ResinWidgetSimple));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, ids);
            intent.PutExtra(KEY_CLICKUPDATE, VALUE_CLICKUPDATE);

            var runIntent = new Intent(context, typeof(ResinWidget));

            runIntent.SetAction(Intent.ActionMain);
            runIntent.PutExtra(KEY_RUNAPP, VALUE_RUNAPP);

            remoteViews.SetOnClickPendingIntent(Resource.Id.ResinWidgetSimpleRootLayout, PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable));
            remoteViews.SetOnClickPendingIntent(Resource.Id.ResinWidgetSimpleIcon, PendingIntent.GetBroadcast(context, 0, runIntent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable));
        }
Esempio n. 6
0
        public static void UpdateWidget(Context context, AppWidgetManager appWidgetManager, int widgetID)
        {
            RemoteViews widgetView = new RemoteViews(context.PackageName, Resource.Layout.layout1);

            _SecondsLeft -= 5;
            TimeSpan differ = (DateTime.Now.AddSeconds(_SecondsLeft) - DateTime.Now);

            widgetView.SetTextViewText(2131296412, "Осталось целых дней: " + Math.Floor((DateTime.Now.AddSeconds(_SecondsLeft) - DateTime.Now).TotalDays) + "\nОсталось минут: " + (int)differ.TotalMinutes);

            if (_SecondsLeft < 0)
            {
                notificationEventStarted(context, widgetID);
            }


            Intent configIntent = new Intent(context, Java.Lang.Class.FromType(typeof(CalendarActivity)));

            configIntent.SetAction(AppWidgetManager.ActionAppwidgetConfigure);
            configIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, widgetID);
            PendingIntent pIntent = PendingIntent.GetActivity(context, widgetID, configIntent, 0);


            widgetView.SetOnClickPendingIntent(2131296411, pIntent);
            appWidgetManager.UpdateAppWidget(widgetID, widgetView);
        }
Esempio n. 7
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();
                }
            }
        }
        public void SetListeners(RemoteViews view)
        {
            //radio listener
            ////Intent radio = new Intent(context, typeof(HelperActivity));
            ////radio.PutExtra("DO", "radio");
            ////PendingIntent pRadio = PendingIntent.GetActivity(context, 0, radio, 0);
            ////view.SetOnClickPendingIntent(Resource.Id.radio, pRadio);

            //////volume listener
            ////Intent volume = new Intent(context, typeof(HelperActivity));
            ////volume.PutExtra("DO", "volume");
            ////PendingIntent pVolume = PendingIntent.GetActivity(context, 1, volume, 0);
            ////view.SetOnClickPendingIntent(Resource.Id.volume, pVolume);

            //////reboot listener
            ////Intent reboot = new Intent(context, typeof(HelperActivity));
            ////reboot.PutExtra("DO", "reboot");
            ////PendingIntent pReboot = PendingIntent.GetActivity(context, 5, reboot, 0);
            ////view.SetOnClickPendingIntent(Resource.Id.reboot, pReboot);

            //////top listener
            ////Intent top = new Intent(context, typeof(HelperActivity));
            ////top.PutExtra("DO", "top");
            ////PendingIntent pTop = PendingIntent.GetActivity(context, 3, top, 0);
            ////view.SetOnClickPendingIntent(Resource.Id.top, pTop);

            //app listener
            Intent app = new Intent(context, typeof(HelperActivity));

            app.PutExtra("DO", "app");
            PendingIntent pApp = PendingIntent.GetActivity(context, 4, app, 0);

            view.SetOnClickPendingIntent(Resource.Id.btn1, pApp);
        }
Esempio n. 9
0
        /// <summary>
        /// This method is called when clicks are registered.
        /// </summary>
        public override void OnReceive(Context context, Intent intent)
        {
            base.OnReceive(context, intent);

            // Check if the click is from the "Announcement" button
            if (RefreshClick.Equals(intent.Action))
            {
                // Retrieve the widget layout. This is a RemoteViews, so we can't use 'FindViewById'
                var widgetView = new RemoteViews(context.PackageName, Resource.Layout.Widget);
                SetTextViewText(widgetView);
                Toast.MakeText(context, "Namaz vakitleri yenilandi", ToastLength.Short);
                UserDialogs.Instance.Toast("Namaz vakitleri yenilandi", TimeSpan.FromSeconds(3));
                ComponentName componentName = new ComponentName(context, Java.Lang.Class.FromType(typeof(AppWidget)).Name);
                AppWidgetManager.GetInstance(context)?.UpdateAppWidget(componentName, widgetView);
                widgetView.SetOnClickPendingIntent(Resource.Id.widgetRefreshIcon, GetPendingSelfIntent(context, RefreshClick));
                //var pm = context.PackageManager;
                //try
                //{
                //    var packageName = "com.suleymaniyetakvimi";
                //    var launchIntent = pm.GetLaunchIntentForPackage(packageName);
                //    context.StartActivity(launchIntent);
                //}
                //catch
                //{
                //    // Something went wrong :)
                //}
            }
        }
Esempio n. 10
0
        //Only one updatePeriodMillis is used for all instances of the widget
        public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            base.OnUpdate(context, appWidgetManager, appWidgetIds);

            Setup(context);

            int numOfIds = appWidgetIds.Length;

            for (int i = 0; i < numOfIds; i++)
            {
                int appWidgetId = appWidgetIds[i];

                //Get the layout for the App Widget using RemoteViews and attach a clicking listener to the widget
                RemoteViews widgetUI = new RemoteViews(context.PackageName, Resource.Layout.activity_main);

                // Create an Intent to update the widget
                Intent intent = new Intent(context, typeof(AppWidget));

                intent.PutExtra("widgetUI", widgetUI);

                PendingIntent pendingIntent = PendingIntent.GetBroadcast(context, 0, intent, 0);

                widgetUI.SetOnClickPendingIntent(Resource.Id.widgetBackground, pendingIntent);

                UpdateTextAndImage(context, widgetUI);

                //Update the current app widget (attaches UI to widget?)
                appWidgetManager.UpdateAppWidget(appWidgetId, BuildRemoteViews(context, appWidgetIds));
            }
        }
        public RemoteViews Setup(Context context, int widgetId)
        {
            var view = new RemoteViews(context.PackageName, Resource.Layout.SuggestionsWidget);

            var intent = new Intent(context, JavaUtils.ToClass <SuggestionsWidgetService>());

            intent.PutExtra(AppWidgetManager.ExtraAppwidgetId, widgetId);

            view.SetRemoteAdapter(Resource.Id.SuggestionsList, intent);
            view.SetEmptyView(Resource.Id.SuggestionsList, Resource.Id.NoData);

            var tapIntent = new Intent(context, JavaUtils.ToClass <WidgetsForegroundService>());

            tapIntent.SetAction(SuggestionTapped);
            tapIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, widgetId);
            var tapPendingIntent = context.SafeGetForegroundService(0, tapIntent, UpdateCurrent);

            view.SetPendingIntentTemplate(Resource.Id.SuggestionsList, tapPendingIntent);

            view.SetTextViewText(Resource.Id.Title, Resources.WorkingOnThese);
            view.SetTextViewText(Resource.Id.NoData, Resources.NoSuggestionsAvailable);
            view.SetTextViewText(Resource.Id.ShowAllTimeEntriesLabel, Resources.ShowAllTimEntries);

            var openAppIntent        = new Intent(context, typeof(SplashScreen)).SetFlags(TaskOnHome);
            var openAppPendingIntent = PendingIntent.GetActivity(context, 0, openAppIntent, UpdateCurrent);

            view.SetOnClickPendingIntent(Resource.Id.ShowAllTimeEntriesLabel, openAppPendingIntent);

            return(view);
        }
Esempio n. 12
0
        public override async void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            var            me         = new ComponentName(context, Java.Lang.Class.FromType(typeof(AppWidget)).Name);
            var            widgetView = new RemoteViews(context.PackageName, Resource.Layout.Widget);
            InternetStatus status     = new InternetStatus();
            NetCredential  credential = new NetCredential();

            credential.State = await status.SuggestAsync();

            var helper = credential.GetHelper();

            if (helper != null)
            {
                FluxUser user = await helper.GetFluxAsync();

                widgetView.SetTextViewText(Resource.Id.widgetTitle, user.Username);
                widgetView.SetTextViewText(Resource.Id.widgetFlux, $"流量:{user.Flux}");
                widgetView.SetTextViewText(Resource.Id.widgetBalance, string.Format(CultureInfo.GetCultureInfo("zh-CN"), "余额:{0:C2}", user.Balance));
            }
            var intent = new Intent(context, typeof(AppWidget));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetIds);
            var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            widgetView.SetOnClickPendingIntent(Resource.Id.widgetBackground, piBackground);
            appWidgetManager.UpdateAppWidget(me, widgetView);
        }
Esempio n. 13
0
        public RemoteViews BuildUpdate(Intent intent)
        {
            RemoteViews updateViews = new RemoteViews(this.PackageName, Resource.Layout.widget_app_layout2);

            System.DateTime time = System.DateTime.Now;
            string          text = $"{time}";   // string.Format("now time : {0}", time);

            updateViews.SetTextViewText(Resource.Id.Text2, text);

            // ウィジェットのUI処理の登録なんかは一度やったら必要なさそうに感じるが、
            // AppWidgetProvider::OnEnabled()なんかでやろうとすると、ウィジェットを2つ立ち上げると、
            // OnEnabled()は一番最初に起動したウィジェットでしか呼ばれないので、あとに立ち上げたほうのボタンなんかをクリックしても反応しなくなる。
            // Update処理(要はここ)で通すようにしたほうがいいのかも。
#if true
            // ボタンクリックでActivityの起動
            Intent        WidgetIntent = new Intent(this, typeof(MainActivity));
            PendingIntent appIntent    = PendingIntent.GetActivity(this, 0, WidgetIntent, 0);
            updateViews.SetOnClickPendingIntent(Resource.Id.TestButton2, appIntent);
            // これでボタンのイメージ変えることもできる
//			updateViews.SetImageViewResource(Resource.Id.TestButton2, Resource.Drawable.widget_button_focused);
            // Intentに設定されたAction見てみる
            System.Diagnostics.Debug.WriteLine("WidgetIntent.Action = " + WidgetIntent.Action);

            // 時間書いたメッセージ部分のクリックでもActivity起動できるようにしてみる
            updateViews.SetOnClickPendingIntent(Resource.Id.Text2, appIntent);

            // ボタン押したら時計が更新されるようにする
            Intent UpdateClockIntent = new Intent();
            // ボタンを押したときにこのIntentがブロードキャストされて、それをこのクラスが直接受け取り、OnStartCommandが呼ばれる。
            UpdateClockIntent.SetAction("Update_Time");
            PendingIntent updateTimeIntent = PendingIntent.GetService(this, 0, UpdateClockIntent, 0);                   // サービスクラスへ投げるインテント作成
            updateViews.SetOnClickPendingIntent(Resource.Id.TestButton3, updateTimeIntent);
#endif
            if (!string.IsNullOrEmpty(intent.Action))
            {
                if (intent.Action.Equals("Update_Time"))
                {
                    time = System.DateTime.Now;
                    text = $"{time}";                    // string.Format("now time : {0}", time);
                    updateViews.SetTextViewText(Resource.Id.Text2, text);
//					Toast.MakeText(this, "ClockUpdate.", ToastLength.Short).Show();
                }
            }

            return(updateViews);
        }
Esempio n. 14
0
        public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            try
            {
                foreach (var appWidgetId in appWidgetIds)
                {
                    // Set up the intent that starts the widget schedule items service, which will provide the views for the collection
                    Intent intent = new Intent(context, typeof(WidgetScheduleService));
                    intent.SetPackage(context.PackageName);

                    // Add the app widget ID to the intent extras
                    intent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetId);
                    intent.SetData(Android.Net.Uri.Parse(intent.ToUri(Android.Content.IntentUriType.AndroidAppScheme)));

                    // Instantiate the widget layout
                    var views = new RemoteViews(context.PackageName, Resource.Layout.WidgetSchedule);

                    // Localize header text
                    views.SetTextViewText(Resource.Id.WidgetScheduleHeaderText, PowerPlannerResources.GetString("MainMenuItem_Schedule"));

                    // This is displayed while the list view loads.
                    // My list view will always have items, so this will act as loading text.
                    views.SetEmptyView(Resource.Id.WidgetScheduleListView, Resource.Id.WidgetScheduleEmptyView);

                    // Wire the header click
                    Intent openIntent = new Intent(context, typeof(MainActivity))
                                        .SetAction(Intent.ActionView)
                                        .SetData(Android.Net.Uri.Parse("powerplanner:?" + new ViewScheduleArguments()
                    {
                        LaunchSurface = LaunchSurface.SecondaryTile
                    }.SerializeToString()));
                    PendingIntent pendingOpenIntent = PendingIntent.GetActivity(context, 0, openIntent, 0);
                    views.SetOnClickPendingIntent(Resource.Id.WidgetScheduleHeader, pendingOpenIntent);

                    // Set up the list adapter to use our service that generates the items
                    views.SetRemoteAdapter(Resource.Id.WidgetScheduleListView, intent);

                    // Add click handlers to each individual item
                    Intent itemClickIntent = new Intent(context, typeof(MainActivity));
                    itemClickIntent.SetAction(Intent.ActionView);
                    itemClickIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetId);
                    PendingIntent pendingItemClickIntent = PendingIntent.GetActivity(context, 0, itemClickIntent, 0);
                    views.SetPendingIntentTemplate(Resource.Id.WidgetScheduleListView, pendingItemClickIntent);

                    // Update the widget
                    appWidgetManager.UpdateAppWidget(appWidgetId, views);
                }
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current.TrackException(ex);
            }

            TelemetryExtension.Current?.TrackEvent("Widget_Schedule_OnUpdate");
            base.OnUpdate(context, appWidgetManager, appWidgetIds);
        }
Esempio n. 15
0
        private void CreateWAIconClickIntent(Context context, RemoteViews remoteViews, int id, string itemName, Locations location)
        {
            Intent runIntent = new Intent(context, typeof(WAWidget));

            runIntent.SetAction(Intent.ActionMain);
            runIntent.PutExtra(KEY_RUNAPP, VALUE_RUNAPP);
            runIntent.PutStringArrayListExtra(KEY_WAITEM_LIST, CreateWAList(itemName, location));

            remoteViews.SetOnClickPendingIntent(id, PendingIntent.GetBroadcast(context, id, runIntent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable));
        }
Esempio n. 16
0
        private void RegisterClicks(Context context, int[] appWidgetIds, RemoteViews widgetView)
        {
            var intent = new Intent(context, typeof(DataWidget));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);

            var pendingIntent = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            widgetView.SetOnClickPendingIntent(Resource.Id.widget, pendingIntent);
        }
Esempio n. 17
0
        private RemoteViews BuildUpdate(Context context, int[] appWidgetIds)
        {
            RemoteViews updateViews = new RemoteViews(context.PackageName, Resource.Layout.widget);

            Intent i = new Intent(context, typeof(AppWidget));

            i.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            i.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);

            PendingIntent pi = PendingIntent.GetBroadcast(context, 0, i, PendingIntentFlags.UpdateCurrent);

            updateViews.SetImageViewResource(Resource.Id.left_die, IMAGES[(int)(Math.Random() * 6)]);
            updateViews.SetOnClickPendingIntent(Resource.Id.left_die, pi);

            updateViews.SetImageViewResource(Resource.Id.right_die, IMAGES[(int)(Math.Random() * 6)]);
            updateViews.SetOnClickPendingIntent(Resource.Id.right_die, pi);

            updateViews.SetOnClickPendingIntent(Resource.Id.background, pi);

            return(updateViews);
        }
Esempio n. 18
0
        private void RegisterClicks(Context context, RemoteViews widgetView, int[] appWidgetIds)
        {
            var intent = new Intent(context, typeof(MySessionsWidget));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);

            // Register click event for the Background view of the widget
            var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            widgetView.SetOnClickPendingIntent(Resource.Id.widgetBackground, piBackground);
        }
Esempio n. 19
0
        private void CreateClickIntent(Context context, int[] ids, int id, RemoteViews remoteViews)
        {
            var intent = new Intent(context, typeof(WAWidget));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, ids);
            intent.PutExtra(KEY_CLICKUPDATE, VALUE_CLICKUPDATE);

            var prevIntent = new Intent(context, typeof(WAWidget));

            prevIntent.SetAction(ACTION_PREVIOUS);
            prevIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, id);

            var nextIntent = new Intent(context, typeof(WAWidget));

            nextIntent.SetAction(ACTION_NEXT);
            nextIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, id);

            remoteViews.SetOnClickPendingIntent(Resource.Id.WAWidgetRootLayout, PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable));
            remoteViews.SetOnClickPendingIntent(Resource.Id.WAWidgetPreviousButton, PendingIntent.GetBroadcast(context, 1, prevIntent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable));
            remoteViews.SetOnClickPendingIntent(Resource.Id.WAWidgetNextButton, PendingIntent.GetBroadcast(context, 2, nextIntent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable));
        }
Esempio n. 20
0
        public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            Log.Info(App.Tag, "In MainWidget.OnUpdate()");

            var remoteViews = new RemoteViews(context.PackageName, Resource.Layout.mainWidget);
            var thisWidget = new ComponentName(context, this.Class);

            Intent intent = new Intent(context, typeof(WidgetService));
            PendingIntent pendingIntent = PendingIntent.GetService(context, 0, intent, PendingIntentFlags.UpdateCurrent);
            remoteViews.SetOnClickPendingIntent(Resource.Id.MyButton, pendingIntent);

            appWidgetManager.UpdateAppWidget(thisWidget, remoteViews);
        }
Esempio n. 21
0
        private void RegisterClicks(Context context, int[] appWidgetIds, RemoteViews widgetView)
        {
            var intent = new Intent(context, typeof(AppWidget));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);

            // Register click event for the Background
            var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            widgetView.SetOnClickPendingIntent(Resource.Id.standingUpdate, piBackground);
            //Console.Out.WriteLine("Something happened");
        }
Esempio n. 22
0
        private void RegisterClicks(Context context, int[] appWidgetIds, RemoteViews widgetView)
        {
            //var intent = new Intent(context, typeof(AppWidget));
            //intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            //intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);

            // Register click event for the Background
            //var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);
            //widgetView.SetOnClickPendingIntent(Resource.Id.widgetBackground, piBackground);

            // Register click event for the Logo-icon
            widgetView.SetOnClickPendingIntent(Resource.Id.widgetRefreshIcon, GetPendingSelfIntent(context, RefreshClick));
        }
Esempio n. 23
0
        public void SetListeners(RemoteViews view)
        {
            //listener 1
            ////Intent volume = new Intent(parent, NotificationReturnSlot.class);
            ////volume.putExtra("DO", "volume");
            ////PendingIntent btn1 = PendingIntent.getActivity(parent, 0, volume, 0);
            ////    view.setOnClickPendingIntent(R.id.btn1, btn1);

            //listener 2
            Intent stop = new Intent(parent, typeof(NotificationReturnSlot));

            stop.PutExtra("DO", "stopNotification");
            PendingIntent btn1 = PendingIntent.GetActivity(parent, 0, stop, 0);

            view.SetOnClickPendingIntent(Resource.Id.btn1, btn1);

            Intent frederik = new Intent(parent, typeof(NotificationReturnSlot));

            stop.PutExtra("DO", "frederik");
            PendingIntent btn2 = PendingIntent.GetActivity(parent, 1, stop, 0);

            view.SetOnClickPendingIntent(Resource.Id.btn2, btn2);
        }
Esempio n. 24
0
        public override async void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            var            me         = new ComponentName(context, Java.Lang.Class.FromType(typeof(AppWidget)).Name);
            var            widgetView = new RemoteViews(context.PackageName, Resource.Layout.Widget);
            InternetStatus status     = new InternetStatus();
            NetCredential  credential = new NetCredential();

            (credential.Username, credential.Password) = await CredentialStore.LoadCredentialAsync();

            credential.State = await status.SuggestAsync();

            NetXFSettings settings = new NetXFSettings();

            settings.LoadSettings();
            var helper = credential.GetHelper(settings);

            if (helper != null)
            {
                if (settings.BackgroundAutoLogin && !string.IsNullOrEmpty(credential.Username))
                {
                    if (settings.EnableRelogin)
                    {
                        await helper.LogoutAsync();
                    }
                    await helper.LoginAsync();
                }
                FluxUser user = await helper.GetFluxAsync();

                var remainFlux = FluxHelper.GetMaxFlux(user.Flux, user.Balance) - user.Flux;
                widgetView.SetTextViewText(Resource.Id.widgetTitle, $"用户:{user.Username}");
                widgetView.SetTextViewText(Resource.Id.widgetFlux, $"流量:{user.Flux}");
                widgetView.SetTextViewText(Resource.Id.widgetRemain, $"剩余:{remainFlux}");
                widgetView.SetTextViewText(Resource.Id.widgetBalance, string.Format(CultureInfo.GetCultureInfo("zh-CN"), "余额:{0:C2}", user.Balance));
            }
            else
            {
                widgetView.SetTextViewText(Resource.Id.widgetTitle, "暂无流量信息");
                widgetView.SetTextViewText(Resource.Id.widgetFlux, string.Empty);
                widgetView.SetTextViewText(Resource.Id.widgetRemain, string.Empty);
                widgetView.SetTextViewText(Resource.Id.widgetBalance, string.Empty);
            }
            var intent = new Intent(context, typeof(AppWidget));

            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);
            var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            widgetView.SetOnClickPendingIntent(Resource.Id.widgetBackground, piBackground);
            appWidgetManager.UpdateAppWidget(me, widgetView);
        }
        //Click listener for root widget area
        private void SetWidgetClick(RemoteViews remoteViews, Context context, int appWidgetId)
        {
            Intent updateIntent = new Intent(context, typeof(ReittiWidget));

            // Means we want to update widget
            updateIntent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);
            // Means we want to update this particular widget
            updateIntent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, new int[] { appWidgetId });
            // Package into pending intent
            PendingIntent pIntent = PendingIntent.GetBroadcast(context, appWidgetId, updateIntent, 0);

            // Set control on which we want click listener to be - here ROOT layout
            remoteViews.SetOnClickPendingIntent(Resource.Id.widgetRootLayout, pIntent);
        }
Esempio n. 26
0
        private static RemoteViews CreateSmallLayout(Context context, int appWidgetId)
        {
            RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.panic_button);

            // Update the header for the current unread message count
            int    count  = 10;
            String header = context.GetString(Resource.String.panic_button_header);

            remoteViews.SetTextViewText(Resource.Id.panic_button_header, header);

            // Add a click pending intent to launch the inbox
            remoteViews.SetOnClickPendingIntent(Resource.Id.panic_button, CreateInboxActivityPendingIntent(context));

            return(remoteViews);
        }
Esempio n. 27
0
        public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            //base.OnUpdate(context, appWidgetManager, appWidgetIds);
            foreach (var appWidgetId in appWidgetIds)
            {
                Intent        intent        = new Intent(context, typeof(MainActivity));
                PendingIntent pendingIntent = PendingIntent.GetActivity(context, 0, intent, 0);

                RemoteViews views = new RemoteViews(context.PackageName, Resource.Layout.example_widget);

                views.SetOnClickPendingIntent(Resource.Id.btnWidgetPressMe, pendingIntent);

                appWidgetManager.UpdateAppWidget(appWidgetId, views);
            }
        }
Esempio n. 28
0
        protected RemoteViews Setup(Context context)
        {
            var view = new RemoteViews(context.PackageName, Resource.Layout.WidgetNotLoggedIn);

            view.SetOnClickPendingIntent(Resource.Id.RootLayout, getOpenAppToLoginPendingIntent(context));

            view.SetTextViewText(Resource.Id.NotLoggedInLabel, LabelText);

            view.SetViewVisibility(Resource.Id.NotLoggedInLabel, isFullView.ToVisibility());
            view.SetViewVisibility(Resource.Id.TogglLogo, isFullView.ToVisibility());
            view.SetViewVisibility(Resource.Id.PadLock, isFullView.ToVisibility());
            view.SetViewVisibility(Resource.Id.PadLockBig, (!isFullView).ToVisibility());

            return(view);
        }
        /**
         * Creates a small layout for the app widget
         *
         *
         * @param context Application context
         * @param appWidgetId id of the widget
         * @return RemoteViews for the small layout
         */
        private static RemoteViews CreateSmallLayout(Context context, int appWidgetId)
        {
            RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.widget_layout_small);

            // Update the header for the current unread message count
            int    count     = RichPushManager.Shared().RichPushUser.Inbox.UnreadCount;
            String inboxName = context.GetString(Resource.String.inbox_name);
            String header    = context.GetString(Resource.String.header_format_string, count, inboxName);

            remoteViews.SetTextViewText(Resource.Id.widget_header_text, header);

            // Add a click pending intent to launch the inbox
            remoteViews.SetOnClickPendingIntent(Resource.Id.widget_header, CreateInboxActivityPendingIntent(context));

            return(remoteViews);
        }
Esempio n. 30
0
        void SetRefreshPendingIntent(Context ctx, RemoteViews rv, int[] appWidgetIds)
        {
            var refreshIntent = new Intent(ctx, typeof(AppWidget));

            refreshIntent.SetAction(ACTION_REFRESH);
            refreshIntent.PutExtra(ACTION_REFRESH, appWidgetIds);

            PendingIntent btnClickPendingIntent = PendingIntent.GetBroadcast(
                ctx,
                0,
                refreshIntent,
                PendingIntentFlags.UpdateCurrent
                );

            rv.SetOnClickPendingIntent(Resource.Id.widget_refresh, btnClickPendingIntent);
        }
Esempio n. 31
0
        private void RegisterClicks(Context context, int[] appWidgetIds, RemoteViews widgetUI)
        {
            var intent = new Intent(context, typeof(AppWidget));

            //this intent will call OnUpdate
            intent.SetAction(AppWidgetManager.ActionAppwidgetUpdate);

            //... for all app widget instances?
            intent.PutExtra(AppWidgetManager.ExtraAppwidgetIds, appWidgetIds);

            //setup a broadcast-sending pending intent
            var pendingIntent = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);

            //when the background is clicked send the pending intent
            widgetUI.SetOnClickPendingIntent(Resource.Id.widgetBackground, pendingIntent);
        }
Esempio n. 32
0
        public override void OnAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions)
        {
            var           defconStatus  = GetApplicationDefconStatus().ToString();
            var           widgetHeight  = newOptions.GetInt(AppWidgetManager.OptionAppwidgetMinHeight);
            Intent        intent        = new Intent(context, typeof(MainActivity));
            PendingIntent pendingIntent = PendingIntent.GetActivity(context, 0, intent, 0);
            ComponentName componentName = new ComponentName(context, Java.Lang.Class.FromType(typeof(MyDefconWidget)).Name);
            RemoteViews   remoteViews   = new RemoteViews(context.PackageName, Resource.Layout.mydefcon_widget);

            remoteViews.SetTextViewTextSize(Resource.Id.mydefconWidgetTextView, 2, widgetHeight * (float)0.5);
            remoteViews.SetTextViewText(Resource.Id.mydefconWidgetTextView, defconStatus);
            remoteViews.SetTextColor(Resource.Id.mydefconWidgetTextView, GetLightColor(defconStatus));
            remoteViews.SetInt(Resource.Id.mydefconWidgetLinearLayout, "setBackgroundColor", GetDarkColor(defconStatus));
            remoteViews.SetInt(Resource.Id.mydefconFrameLayout, "setBackgroundColor", GetLightColor(defconStatus));
            remoteViews.SetOnClickPendingIntent(Resource.Id.mydefconWidgetLinearLayout, pendingIntent);
            appWidgetManager.UpdateAppWidget(componentName, remoteViews);
        }
Esempio n. 33
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)
		{
			var entry = BlogPost.GetBlogPost ();

			// Build an update that holds the updated widget contents
			var updateViews = new RemoteViews (context.PackageName, Resource.Layout.widget_word);

			updateViews.SetTextViewText (Resource.Id.blog_title, entry.Title);
			updateViews.SetTextViewText (Resource.Id.creator, entry.Creator);

			// When user clicks on widget, launch to Wiktionary definition page
			if (!string.IsNullOrEmpty (entry.Link)) {
				Intent defineIntent = new Intent (Intent.ActionView, Android.Net.Uri.Parse (entry.Link));
			
				PendingIntent pendingIntent = PendingIntent.GetActivity (context, 0, defineIntent, 0);
				updateViews.SetOnClickPendingIntent (Resource.Id.widget, pendingIntent);
			}

			return updateViews;
		}
Esempio n. 34
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)
        {
            // var entry = WordEntry.GetWordOfTheDay();

            // Build an update that holds the updated widget contents
            var updateViews = new RemoteViews(context.PackageName, Resource.Layout.taskwidget);

            try
            {

                var launchAppIntent = new Intent(this, typeof (MainActivity));
                launchAppIntent.AddFlags(ActivityFlags.SingleTop);
                launchAppIntent.AddFlags(ActivityFlags.ClearTop);
                launchAppIntent.PutExtra("CameFromWidget", true);
                var pendingIntent = PendingIntent.GetActivity(context, 0, launchAppIntent, 0);
                updateViews.SetOnClickPendingIntent(Resource.Id.widget_top_action_bar, pendingIntent);

                var launchAppIntent2 = new Intent(this, typeof(MainActivity));
                launchAppIntent2.AddFlags(ActivityFlags.SingleTop);
                launchAppIntent2.AddFlags(ActivityFlags.ClearTop);
                var pendingIntent2 = PendingIntent.GetActivity(context, 0, launchAppIntent, 0);
                updateViews.SetOnClickPendingIntent(Resource.Id.widget_main_area, pendingIntent2);

                var newTasks = new List<string>();
                var newTasksChecked = new List<bool>();
                var lineVisibility = new List<ViewStates>();
                for(int i = 0; i < 15; i++)
                {
                    newTasks.Add(string.Empty);
                    newTasksChecked.Add(false);
                    lineVisibility.Add(ViewStates.Gone);
                }

                var tasks = DataManager.GetTasks(SortOption.Newest);
                var count = tasks.Count();
                count = count > m_TextViews.Length ? m_TextViews.Length : count;

                for (int i = 0; i < count; i++)
                {
                    var task = tasks.ElementAt(i);
                    newTasks[i] = task.Task;
                    newTasksChecked[i] = task.Checked;

                    if (i != 0)
                        lineVisibility[i - 1] = ViewStates.Visible;
                }

                if (newTasks[0] == string.Empty)
                        newTasks[0] = "No Tasks Added.";

                for(int i = 0; i < m_TextViews.Length; i++)
                {
                    updateViews.SetTextViewText(m_TextViews[i], newTasks[i]);
                    updateViews.SetTextColor(m_TextViews[i], newTasksChecked[i] ? Android.Graphics.Color.DarkGray : Android.Graphics.Color.Black );

                }

                for(int i = 0; i < m_TextViewsLines.Length; i++)
                    updateViews.SetViewVisibility(m_TextViewsLines[i], lineVisibility[i]);

            }
            catch (Exception ex)
            {

                updateViews.SetTextViewText(Resource.Id.widget_task_1, "Error loading widget");
            }

            return updateViews;
        }
		/**
     * Creates a small layout for the app widget
     * 
     * 
     * @param context Application context
     * @param appWidgetId id of the widget
     * @return RemoteViews for the small layout
     */
		private static RemoteViews CreateSmallLayout(Context context, int appWidgetId) {
			RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.widget_layout_small);

			// Update the header for the current unread message count
			int count = RichPushManager.Shared().RichPushUser.Inbox.UnreadCount;
			String inboxName = context.GetString(Resource.String.inbox_name);
			String header = context.GetString(Resource.String.header_format_string, count, inboxName);

			remoteViews.SetTextViewText(Resource.Id.widget_header_text, header);

			// Add a click pending intent to launch the inbox
			remoteViews.SetOnClickPendingIntent(Resource.Id.widget_header, CreateInboxActivityPendingIntent(context));

			return remoteViews;
		}
		/**
     * Creates a large layout for the app widget
     * 
     * This layout is only supported in SDK >= 11 (Honeycomb)
     * 
     * @param context Application context
     * @param appWidgetId id of the widget
     * @return RemoteViews for the large layout
     */
		private static RemoteViews CreateLargeLayout(Context context, int appWidgetId) {
			RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.widget_layout);

			// Specify the service to provide data for the collection widget.  Note that we need to
			// embed the appWidgetId via the data otherwise it will be ignored.
			Intent intent = new Intent(context, typeof (RichPushWidgetService));
			intent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetId);
			remoteViews.SetRemoteAdapter(appWidgetId, Resource.Id.message_list, intent);

			// Set the empty view to be displayed if the collection is empty.  It must be a sibling
			// view of the collection view.
			remoteViews.SetEmptyView(Resource.Id.message_list, Resource.Id.empty_view);

			// Bind a click listener template for the contents of the message list
			remoteViews.SetPendingIntentTemplate(Resource.Id.message_list, CreateMessageTemplateIntent(context, appWidgetId));

			// Add a click pending intent to launch the inbox
			remoteViews.SetOnClickPendingIntent(Resource.Id.widget_header, CreateInboxActivityPendingIntent(context));

			return remoteViews;
		}
Esempio n. 37
0
        private void SetupWidget (Context ctx)
        {
            RemoteViews views;

            var wm = AppWidgetManager.GetInstance (ctx);
            var cn = new ComponentName (ctx, Java.Lang.Class.FromType (typeof (WidgetProvider)));
            var ids = wm.GetAppWidgetIds (cn);

            if (UpdateService.IsUserLogged) {

                views = new RemoteViews (ctx.PackageName, Resource.Layout.keyguard_widget);

                SetupRunningBtn (ctx, views);

                var adapterServiceIntent = new Intent (ctx, typeof (RemotesViewsFactoryService));
                adapterServiceIntent.PutExtra (AppWidgetManager.ExtraAppwidgetIds, ids);
                adapterServiceIntent.SetData (Android.Net.Uri.Parse (adapterServiceIntent.ToUri (IntentUriType.Scheme)));

                for (int i = 0; i < ids.Length; i++) {
                    views.SetRemoteAdapter (ids[i], Resource.Id.WidgetRecentEntriesListView, adapterServiceIntent);
                }

                var listItemIntent = new Intent (ctx, typeof (WidgetStartStopService.Receiver));
                listItemIntent.SetData (Android.Net.Uri.Parse (listItemIntent.ToUri (IntentUriType.Scheme)));
                var pendingIntent = PendingIntent.GetBroadcast (ctx, 0, listItemIntent, PendingIntentFlags.UpdateCurrent);
                views.SetPendingIntentTemplate (Resource.Id.WidgetRecentEntriesListView, pendingIntent);
                views.SetOnClickPendingIntent (Resource.Id.WidgetActionButton, StartStopButtonIntent (ctx));

            } else {
                views = new RemoteViews (ctx.PackageName, Resource.Layout.widget_login);
                views.SetOnClickPendingIntent (Resource.Id.WidgetLoginButton, LogInButtonIntent (ctx));
            }

            // Update widget view.
            wm.UpdateAppWidget (ids, views);
        }
Esempio n. 38
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;
        }
        void ShowNotification(bool custom)
        {
            Resources res = Resources;
            NotificationManager notificationManager = (NotificationManager) GetSystemService (
                NotificationService);

            Notification.Builder builder = new Notification.Builder (this)
                .SetSmallIcon (Resource.Drawable.ic_stat_notify_example)
                .SetAutoCancel (true)
                .SetTicker (GetString(Resource.String.notification_text))
                .SetContentIntent (GetDialogPendingIntent ("Tapped the notification entry."));

            if (custom) {
                // Sets a custom content view for the notification, including an image button.
                RemoteViews layout = new RemoteViews (PackageName, Resource.Layout.notification);
                layout.SetTextViewText (Resource.Id.notification_title, GetString (Resource.String.app_name));
                layout.SetOnClickPendingIntent (Resource.Id.notification_button,
                    GetDialogPendingIntent ("Tapped the 'dialog' button in the notification."));
                builder.SetContent (layout);

                // Notifications in Android 3.0 now have a standard mechanism for displaying large
                // bitmaps such as contact avatars. Here, we load an example image and resize it to the
                // appropriate size for large bitmaps in notifications.
                Bitmap largeIconTemp = BitmapFactory.DecodeResource (res,
                    Resource.Drawable.notification_default_largeicon);
                Bitmap largeIcon = Bitmap.CreateScaledBitmap (
                    largeIconTemp,
                    res.GetDimensionPixelSize (Android.Resource.Dimension.NotificationLargeIconWidth),
                    res.GetDimensionPixelSize (Android.Resource.Dimension.NotificationLargeIconHeight),
                    false);
                largeIconTemp.Recycle ();

                builder.SetLargeIcon (largeIcon);

            } else {
                builder
                .SetNumber (7) // An example number.
                .SetContentTitle (GetString (Resource.String.app_name))
                .SetContentText (GetString (Resource.String.notification_text));
            }

            notificationManager.Notify (NotificationDefault, builder.Notification);
        }