コード例 #1
0
        private void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, WidgetDimensions dimensions)
        {
            var widgetInfo  = TimeEntryWidgetInfo.FromSharedPreferences();
            var remoteViews = TimeEntryWidgetFactory.Create(dimensions).Setup(context, widgetInfo);

            appWidgetManager.UpdateAppWidget(appWidgetId, remoteViews);
        }
コード例 #2
0
        public override RemoteViews Setup(Context context, TimeEntryWidgetInfo widgetInfo)
        {
            var view = new RemoteViews(context.PackageName, Resource.Layout.TimeEntryWidgetSmall);

            SetupActionsForStartAndStopButtons(context, view);

            view.SetViewVisibility(Resource.Id.StartButton, (!widgetInfo.IsRunning).ToVisibility());
            view.SetViewVisibility(Resource.Id.StopButton, widgetInfo.IsRunning.ToVisibility());

            return(view);
        }
コード例 #3
0
        public static TimeEntryWidgetInfo FromSharedPreferences()
        {
            var sharedPreferences = Application.Context.GetSharedPreferences(WidgetInfoSharedPreferencesName, FileCreationMode.Private);

            var info = new TimeEntryWidgetInfo();

            info.IsRunning    = sharedPreferences.GetBoolean(IsRunningKey, false);
            info.StartTime    = DateTimeOffset.FromUnixTimeSeconds(sharedPreferences.GetLong(StartTimeKey, default));
            info.Description  = sharedPreferences.GetString(DescriptionKey, "");
            info.HasProject   = sharedPreferences.GetBoolean(HasProjectKey, false);
            info.ProjectName  = sharedPreferences.GetString(ProjectNameKey, "");
            info.ProjectColor = sharedPreferences.GetString(ProjectColorKey, "");
            info.HasClient    = sharedPreferences.GetBoolean(HasClientKey, false);
            info.ClientName   = sharedPreferences.GetString(ClientNameKey, "");

            return(info);
        }
コード例 #4
0
        public override RemoteViews Setup(Context context, TimeEntryWidgetInfo widgetInfo)
        {
            var view = new RemoteViews(context.PackageName, Resource.Layout.TimeEntryWidget);

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

            if (widgetInfo.IsRunning)
            {
                view.SetViewVisibility(Resource.Id.StartButton, Gone);
                view.SetViewVisibility(Resource.Id.StopButton, Visible);

                var duration = (DateTimeOffset.Now - widgetInfo.StartTime).TotalMilliseconds;
                view.SetChronometer(Resource.Id.DurationTextView, SystemClock.ElapsedRealtime() - (long)duration, "%s", true);

                if (string.IsNullOrEmpty(widgetInfo.Description))
                {
                    view.SetTextViewText(Resource.Id.DescriptionTextView, Resources.NoDescription);
                    view.SetTextColor(Resource.Id.DescriptionTextView, context.SafeGetColor(Resource.Color.secondaryText));
                }
                else
                {
                    view.SetTextViewText(Resource.Id.DescriptionTextView, widgetInfo.Description);
                    view.SetTextColor(Resource.Id.DescriptionTextView, context.SafeGetColor(Resource.Color.primaryText));
                }

                view.SetViewVisibility(Resource.Id.DotView, widgetInfo.HasProject.ToVisibility());
                view.SetViewVisibility(Resource.Id.ProjectTextView, widgetInfo.HasProject.ToVisibility());
                if (widgetInfo.HasProject)
                {
                    // Project
                    var projectColor = widgetInfo.ProjectColor != null
                        ? Color.ParseColor(widgetInfo.ProjectColor)
                        : Color.Black;
                    view.SetInt(Resource.Id.DotView, "setBackgroundColor", projectColor);
                    view.SetTextViewText(Resource.Id.ProjectTextView, widgetInfo.ProjectName ?? "");
                    view.SetTextColor(Resource.Id.ProjectTextView, projectColor);

                    // Client
                    view.SetViewVisibility(Resource.Id.ClientTextView, widgetInfo.HasClient.ToVisibility());
                    if (widgetInfo.HasClient)
                        view.SetTextViewText(Resource.Id.ClientTextView, widgetInfo.ClientName);
                }
            }
            else
            {
                view.SetViewVisibility(Resource.Id.StartButton, Visible);
                view.SetViewVisibility(Resource.Id.StopButton, Gone);

                view.SetChronometer(Resource.Id.DurationTextView, SystemClock.ElapsedRealtime(), "%s", false);

                view.SetTextViewText(Resource.Id.DescriptionTextView, Resources.NoDescription);
                view.SetTextColor(Resource.Id.DescriptionTextView, context.SafeGetColor(Resource.Color.secondaryText));

                view.SetViewVisibility(Resource.Id.DotView, false.ToVisibility());
                view.SetViewVisibility(Resource.Id.ProjectTextView, false.ToVisibility());
                view.SetViewVisibility(Resource.Id.ClientTextView, false.ToVisibility());
            }

            return view;
        }
コード例 #5
0
 public abstract RemoteViews Setup(Context context, TimeEntryWidgetInfo widgetInfo);
コード例 #6
0
 public RemoteViews Setup(Context context, TimeEntryWidgetInfo widgetInfo)
 => Setup(context);