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);
        }
        public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            try
            {
                foreach (var appWidgetId in appWidgetIds)
                {
                    // Set up the intent that starts the widget agenda items service, which will provide the views for the collection
                    Intent intent = new Intent(context, typeof(WidgetAgendaService));
                    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.WidgetAgenda);

                    // 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.WidgetAgendaListView, Resource.Id.WidgetAgendaEmptyView);

                    // Wire the header click
                    Intent openIntent = new Intent(context, typeof(MainActivity))
                                        .SetAction(Intent.ActionView);
                    PendingIntent pendingOpenIntent = PendingIntent.GetActivity(context, 0, openIntent, 0);
                    views.SetOnClickPendingIntent(Resource.Id.WidgetAgendaHeaderBranding, pendingOpenIntent);

                    // Wire the "+" click
                    Intent addIntent = new Intent(context, typeof(MainActivity))
                                       .SetAction(Intent.ActionView)
                                       .SetData(Android.Net.Uri.Parse("powerplanner:?" + new QuickAddToCurrentAccountArguments().SerializeToString()));
                    PendingIntent pendingAddIntent = PendingIntent.GetActivity(context, 0, addIntent, 0);
                    views.SetOnClickPendingIntent(Resource.Id.WidgetAgendaHeaderAddButton, pendingAddIntent);

                    // Set up the list adapter to use our service that generates the items
                    views.SetRemoteAdapter(Resource.Id.WidgetAgendaListView, 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.WidgetAgendaListView, pendingItemClickIntent);

                    // Update the widget
                    appWidgetManager.UpdateAppWidget(appWidgetId, views);
                    Android.Util.Log.Debug("WidgetAgendaProvider", "Updated Widget");
                }
            }

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

            TelemetryExtension.Current?.TrackEvent("Widget_Agenda_OnUpdate");
            base.OnUpdate(context, appWidgetManager, appWidgetIds);
        }
Ejemplo n.º 3
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);
        }
		/**
     * 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;
		}
Ejemplo n.º 5
0
        public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            currentAppWidgetManager = appWidgetManager;
            for (int i = 0; i < appWidgetIds.Length; i++)
            {
                //the service intent which will provide the views for the listview
                Intent intent = new Intent(context, typeof(CollectionWidgetService));
                //adding the widget id to the intent extras
                intent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetIds[i]);
                intent.SetData(Uri.Parse(intent.ToUri(IntentUriType.Scheme)));

                // Gets the remote object of the app widget
                RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.widget_layout);
                //provide the listView with the needed adapter through the service
                remoteViews.SetRemoteAdapter(Resource.Id.list_view, intent);
                //Set the empty view in case the collection is empty
                remoteViews.SetEmptyView(Resource.Id.list_view, Resource.Id.empty_view);

                //setting up the pending intent template to be filled by each list item on click
                Intent navigationIntent = new Intent(context, typeof(AppWidget));
                navigationIntent.SetAction(NavigationAction);
                navigationIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetIds[i]);
                navigationIntent.SetData(Uri.Parse(intent.ToUri(IntentUriType.Scheme)));

                //Pending intent to be used as a template
                PendingIntent navigationPendingIntent = PendingIntent.GetBroadcast(context, 0, navigationIntent, PendingIntentFlags.UpdateCurrent);
                remoteViews.SetPendingIntentTemplate(Resource.Id.list_view, navigationPendingIntent);

                //refresh button click action
                Intent refreshIntent = new Intent(context, typeof(AppWidget));
                refreshIntent.SetAction(RefreshAction);
                refreshIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetIds[i]);
                refreshIntent.SetData(Uri.Parse(intent.ToUri(IntentUriType.Scheme)));
                remoteViews.SetOnClickPendingIntent(Resource.Id.refreshBTN, PendingIntent.GetBroadcast(context, 0, refreshIntent, 0));

                appWidgetManager.UpdateAppWidget(appWidgetIds[i], remoteViews);
            }

            base.OnUpdate(context, appWidgetManager, appWidgetIds);
        }
        /**
         * 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);
        }
Ejemplo n.º 7
0
        public static RemoteViews UpdateWidget(Context context, int appWidgetId, int[] appWidgetIds)
        {
            var remoteViews = new RemoteViews(context.PackageName, Resource.Layout.task_widget);

            var intent = new Intent(Intent.ActionMain);

            intent.AddCategory(Intent.CategoryLauncher);
            intent.SetComponent(new ComponentName(context, Java.Lang.Class.FromType(typeof(MainActivity))));

            var pending = PendingIntent.GetActivity(context, 0, intent, 0);

            remoteViews.SetOnClickPendingIntent(Resource.Id.widget_layout, pending);
            remoteViews.SetOnClickPendingIntent(Resource.Id.previous_button, GetPendingSelfIntent(context, ACTION_WIDGET_PREVIOUS));
            remoteViews.SetOnClickPendingIntent(Resource.Id.forward_button, GetPendingSelfIntent(context, ACTION_WIDGET_FORWARD));
            remoteViews.SetOnClickPendingIntent(Resource.Id.refresh_button, GetPendingSelfIntent(context, ACTION_WIDGET_REFRESH));

            var svcIntent = new Intent(context, typeof(TaskWidgetService));

            svcIntent.SetPackage(context.PackageName);
            svcIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetId);
            svcIntent.SetData(Android.Net.Uri.Parse(svcIntent.ToUri(IntentUriType.AndroidAppScheme)));

            var itemIntent = new Intent(context, typeof(TaskWidget));

            itemIntent.PutExtra(AppWidgetManager.ExtraAppwidgetId, appWidgetIds);
            itemIntent.SetData(Android.Net.Uri.Parse(svcIntent.ToUri(IntentUriType.AndroidAppScheme)));
            itemIntent.SetAction(ACTION_WIDGET_LIST_ITEM);

            var itemPending = PendingIntent.GetBroadcast(context, 0, itemIntent, 0);

            remoteViews.SetPendingIntentTemplate(Resource.Id.task_listview, itemPending);

            var task = "";

            switch (CurrentTask)
            {
            case 0:
                task = context.GetText(Resource.String.daily_task);
                break;

            case 1:
                task = context.GetText(Resource.String.weekly_task);
                break;

            case 2:
                task = context.GetText(Resource.String.one_time_task);
                break;
            }

            remoteViews.SetInt(Resource.Id.widget_layout, "setBackgroundColor", (int)(Opacity * 0xFF) << 24 | Theme);
            // 어두운 테마
            if (Theme == Convert.ToInt32(0x000000))
            {
                remoteViews.SetTextColor(Resource.Id.task, Android.Graphics.Color.White);
                remoteViews.SetInt(Resource.Id.divider, "setBackgroundColor", Android.Graphics.Color.White);
            }
            // 밝은 테마
            else
            {
                remoteViews.SetTextColor(Resource.Id.task, Android.Graphics.Color.Black);
                remoteViews.SetInt(Resource.Id.divider, "setBackgroundColor", Android.Graphics.Color.Black);
            }
            remoteViews.SetTextViewText(Resource.Id.task, task);
            remoteViews.SetEmptyView(Resource.Id.task_listview, Resource.Id.empty_view);
            remoteViews.SetRemoteAdapter(Resource.Id.task_listview, svcIntent);
            if (Progress)
            {
                remoteViews.SetViewVisibility(Resource.Id.progress_layout, Android.Views.ViewStates.Visible);
            }
            else
            {
                remoteViews.SetViewVisibility(Resource.Id.progress_layout, Android.Views.ViewStates.Gone);
            }

            return(remoteViews);
        }