Esempio n. 1
0
        private void SetupRunningBtn(Context ctx, RemoteViews views)
        {
            var entry     = new WidgetSyncManager.WidgetEntryData();
            var isRunning = false;

            // Check if an entry is running.
            foreach (var item in UpdateService.LastEntries)
            {
                if (item.IsRunning)
                {
                    entry     = item;
                    isRunning = true;
                }
            }

            var baseTime = SystemClock.ElapsedRealtime();

            if (isRunning)
            {
                views.SetInt(Resource.Id.WidgetActionButton, "setBackgroundColor", ctx.Resources.GetColor(Resource.Color.bright_red));
                views.SetInt(Resource.Id.WidgetActionButton, "setText", Resource.String.TimerStopButtonText);
                views.SetInt(Resource.Id.WidgetColorView, "setColorFilter", Color.ParseColor(entry.Color));
                views.SetViewVisibility(Resource.Id.WidgetRunningEntry, ViewStates.Visible);
                views.SetTextViewText(
                    Resource.Id.WidgetRunningDescriptionTextView,
                    String.IsNullOrWhiteSpace(entry.Description) ? ctx.Resources.GetString(Resource.String.RunningWidgetNoDescription) : entry.Description);

                var time = (long)entry.Duration.TotalMilliseconds;

                // Format chronometer correctly.
                string format = "00:%s";
                if (time >= 3600000 && time < 36000000)
                {
                    format = "0%s";
                }
                else if (time >= 36000000)
                {
                    format = "%s";
                }

                views.SetChronometer(Resource.Id.Chronometer, baseTime - (long)entry.Duration.TotalMilliseconds, format, true);
            }
            else
            {
                views.SetInt(Resource.Id.WidgetActionButton, "setBackgroundColor", ctx.Resources.GetColor(Resource.Color.bright_green));
                views.SetInt(Resource.Id.WidgetActionButton, "setText", Resource.String.TimerStartButtonText);
                views.SetViewVisibility(Resource.Id.WidgetRunningEntry, ViewStates.Invisible);
                views.SetChronometer(Resource.Id.Chronometer, baseTime, "00:%s", false);
                views.SetTextViewText(Resource.Id.Chronometer, "00:00:00");
            }
        }
        public RemoteViews GetViewAt(int position)
        {
            var remoteView = new RemoteViews(context.PackageName, Resource.Layout.widget_list_item);
            var rowData    = itemList [position];

            // set if is running
            if (rowData.IsRunning)
            {
                remoteView.SetImageViewResource(Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetStop);
                remoteView.SetViewVisibility(Resource.Id.DurationChronometer, Android.Views.ViewStates.Visible);
                remoteView.SetViewVisibility(Resource.Id.DurationTextView, Android.Views.ViewStates.Gone);
            }
            else
            {
                remoteView.SetImageViewResource(Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetPlay);
                remoteView.SetViewVisibility(Resource.Id.DurationChronometer, Android.Views.ViewStates.Gone);
                remoteView.SetViewVisibility(Resource.Id.DurationTextView, Android.Views.ViewStates.Visible);
            }

            // set color
            remoteView.SetInt(Resource.Id.WidgetColorView, "setColorFilter", Color.ParseColor(rowData.Color));
            remoteView.SetOnClickFillInIntent(Resource.Id.WidgetContinueImageButton, ConstructFillIntent(rowData));

            // set content
            remoteView.SetTextViewText(
                Resource.Id.DescriptionTextView,
                String.IsNullOrWhiteSpace(rowData.Description) ? context.Resources.GetString(Resource.String.RunningWidgetNoDescription) : rowData.Description);
            remoteView.SetTextViewText(
                Resource.Id.ProjectTextView,
                String.IsNullOrWhiteSpace(rowData.ProjectName) ? context.Resources.GetString(Resource.String.RunningWidgetNoProject) : rowData.ProjectName);
            remoteView.SetTextViewText(Resource.Id.DurationTextView, rowData.TimeValue);

            var time = (long)rowData.Duration.TotalMilliseconds;

            // Format chronometer correctly.
            string format = "00:%s";

            if (time >= 3600000 && time < 36000000)
            {
                format = "0%s";
            }
            else if (time >= 36000000)
            {
                format = "%s";
            }
            var baseTime = SystemClock.ElapsedRealtime();

            remoteView.SetChronometer(Resource.Id.DurationChronometer, baseTime - (long)rowData.Duration.TotalMilliseconds, format, true);


            return(remoteView);
        }
Esempio n. 3
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;
        }
Esempio n. 4
0
        private void SetupRunningBtn (Context ctx, RemoteViews views)
        {
            var entry = new WidgetSyncManager.WidgetEntryData();
            var isRunning = false;

            // Check if an entry is running.
            foreach (var item in UpdateService.LastEntries)
                if (item.IsRunning) {
                    entry = item;
                    isRunning = true;
                }

            var baseTime = SystemClock.ElapsedRealtime ();

            if (isRunning) {
                views.SetInt (Resource.Id.WidgetActionButton, "setBackgroundColor", ctx.Resources.GetColor (Resource.Color.bright_red));
                views.SetInt (Resource.Id.WidgetActionButton, "setText", Resource.String.TimerStopButtonText);
                views.SetInt (Resource.Id.WidgetColorView, "setColorFilter", Color.ParseColor (entry.Color));
                views.SetViewVisibility (Resource.Id.WidgetRunningEntry, ViewStates.Visible);
                views.SetTextViewText (
                    Resource.Id.WidgetRunningDescriptionTextView,
                    String.IsNullOrWhiteSpace (entry.Description) ? ctx.Resources.GetString (Resource.String.RunningWidgetNoDescription) : entry.Description);

                var time = (long)entry.Duration.TotalMilliseconds;

                // Format chronometer correctly.
                string format = "00:%s";
                if (time >= 3600000 && time < 36000000) {
                    format = "0%s";
                } else if (time >= 36000000) {
                    format = "%s";
                }

                views.SetChronometer (Resource.Id.Chronometer, baseTime - (long)entry.Duration.TotalMilliseconds, format, true);
            } else {
                views.SetInt (Resource.Id.WidgetActionButton, "setBackgroundColor", ctx.Resources.GetColor (Resource.Color.bright_green));
                views.SetInt (Resource.Id.WidgetActionButton, "setText", Resource.String.TimerStartButtonText);
                views.SetViewVisibility (Resource.Id.WidgetRunningEntry, ViewStates.Invisible);
                views.SetChronometer (Resource.Id.Chronometer, baseTime, "00:%s", false);
                views.SetTextViewText (Resource.Id.Chronometer, "00:00:00");
            }
        }
Esempio n. 5
0
        public RemoteViews GetViewAt (int position)
        {
            var remoteView = new RemoteViews (context.PackageName, Resource.Layout.widget_list_item);
            var rowData = itemList [position];

            // set if is running
            if (rowData.IsRunning) {
                remoteView.SetImageViewResource (Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetStop);
                remoteView.SetViewVisibility (Resource.Id.DurationChronometer, Android.Views.ViewStates.Visible);
                remoteView.SetViewVisibility (Resource.Id.DurationTextView, Android.Views.ViewStates.Gone);
            } else {
                remoteView.SetImageViewResource (Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetPlay);
                remoteView.SetViewVisibility (Resource.Id.DurationChronometer, Android.Views.ViewStates.Gone);
                remoteView.SetViewVisibility (Resource.Id.DurationTextView, Android.Views.ViewStates.Visible);
            }

            // set color
            remoteView.SetInt (Resource.Id.WidgetColorView, "setColorFilter", Color.ParseColor (rowData.Color));
            remoteView.SetOnClickFillInIntent (Resource.Id.WidgetContinueImageButton, ConstructFillIntent (rowData));

            // set content
            remoteView.SetTextViewText (
                Resource.Id.DescriptionTextView,
                String.IsNullOrWhiteSpace (rowData.Description) ? context.Resources.GetString (Resource.String.RunningWidgetNoDescription) : rowData.Description);
            remoteView.SetTextViewText (
                Resource.Id.ProjectTextView,
                String.IsNullOrWhiteSpace (rowData.ProjectName) ? context.Resources.GetString (Resource.String.RunningWidgetNoProject) : rowData.ProjectName);
            remoteView.SetTextViewText (Resource.Id.DurationTextView, rowData.TimeValue);

            var time = (long)rowData.Duration.TotalMilliseconds;

            // Format chronometer correctly.
            string format = "00:%s";
            if (time >= 3600000 && time < 36000000) {
                format = "0%s";
            } else if (time >= 36000000) {
                format = "%s";
            }
            var baseTime = SystemClock.ElapsedRealtime ();
            remoteView.SetChronometer (Resource.Id.DurationChronometer, baseTime - (long)rowData.Duration.TotalMilliseconds, format, true);


            return remoteView;
        }