Пример #1
0
        void SetHead(RemoteViews rv, Lesson lesson, bool prevEqual)
        {
            if (prevEqual)
            {
                //viewHolder.LessonOrder.Visibility = ViewStates.Gone;
                //viewHolder.LessonTime.Visibility = ViewStates.Gone;
                //viewHolder.Divider.Visibility = ViewStates.Visible;
                //viewHolder.Indicator.Visibility = ViewStates.Gone;
                rv.SetInt(Resource.Id.layout_schedule, "setBackgroundResource", Resource.Color.mtrl_btn_transparent_bg_color);
            }
            else
            {
                //if (this.currLessonOrder == lesson.Order)
                //{
                //    viewHolder.Indicator.Visibility = ViewStates.Visible;
                //    viewHolder.LessonTime.SetTextColor(this.headCurrentColor);
                //}
                //else
                //{
                //    viewHolder.Indicator.Visibility = ViewStates.Gone;
                //    viewHolder.LessonTime.SetTextColor(this.headColor);
                //}

                //viewHolder.LessonOrder.Visibility = ViewStates.Visible;
                //viewHolder.LessonTime.Visibility = ViewStates.Visible;
                //viewHolder.Divider.Visibility = ViewStates.Visible;
                rv.SetInt(Resource.Id.layout_schedule, "setBackgroundResource", Resource.Drawable.top_stroke);
                var(StartTime, EndTime) = lesson.GetTime();
                rv.SetTextViewText(Resource.Id.text_schedule_time, StartTime + " - " + EndTime);
                rv.SetTextViewText(Resource.Id.text_schedule_order, "#" + (lesson.Order + 1));
            }
        }
Пример #2
0
 void SetImages(RemoteViews widgetView, bool enabled)
 {
     if (enabled)
     {
         widgetView.SetInt(Resource.Id.SwitchButton, "setBackgroundResource", Resource.Drawable.five_g_switch_enable);
     }
     else
     {
         widgetView.SetInt(Resource.Id.SwitchButton, "setBackgroundResource", Resource.Drawable.five_g_switch_disable);
     }
 }
Пример #3
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");
            }
        }
Пример #4
0
        public RemoteViews GetViewAt(int position)
        {
            RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.task_item);
            var         item        = TaskWidget.Items[position];
            var         imageName   = item.IconPath.Split('/')[1].Split('.')[0];
            var         background  = Resource.Drawable.task_item_background_false;

            if (item.Status)
            {
                background = Resource.Drawable.task_item_background_true;
            }

            var extras = new Bundle();

            extras.PutInt("ItemNo", item.No);

            var fiIntent = new Intent();

            fiIntent.PutExtras(extras);

            remoteViews.SetOnClickFillInIntent(Resource.Id.task_layout, fiIntent);
            remoteViews.SetInt(Resource.Id.task_layout, "setBackgroundResource", background);
            remoteViews.SetImageViewResource(Resource.Id.task_icon, context.Resources.GetIdentifier(imageName, "drawable", context.PackageName));
            remoteViews.SetTextViewText(Resource.Id.task_content, item.Content);

            return(remoteViews);
        }
Пример #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);
            }
            else
            {
                remoteView.SetImageViewResource(Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetPlay);
            }

            // 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);

            return(remoteView);
        }
Пример #6
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);
            } else {
                remoteView.SetImageViewResource (Resource.Id.WidgetContinueImageButton, Resource.Drawable.IcWidgetPlay);
            }

            // 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);

            return remoteView;
        }
Пример #7
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);
        }
Пример #8
0
        public override void OnUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
        {
            base.OnUpdate(context, appWidgetManager, appWidgetIds);
            var defconStatus = GetApplicationDefconStatus().ToString();

            for (int i = 0; i < appWidgetIds.Length; i++)
            {
                int           appWidgetId   = appWidgetIds[i];
                Intent        intent        = new Intent(context, typeof(MainActivity));
                PendingIntent pendingIntent = PendingIntent.GetActivity(context, 0, intent, 0);
                RemoteViews   remoteViews   = new RemoteViews(context.PackageName, Resource.Layout.mydefcon_widget);
                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(appWidgetId, remoteViews);
            }
        }
            public RemoteViews GetViewAt(int position)
            {
                try
                {
                    object item = _items[position];

                    if (item is DateTime)
                    {
                        var dateHeaderView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetAgendaDateListItem);
                        dateHeaderView.SetTextViewText(Resource.Id.WidgetAgendaDateHeaderTextView, ToFriendlyDate((DateTime)item, _now));

                        return(dateHeaderView);
                    }

                    if (item is string)
                    {
                        // String represents "Nothing due!", etc
                        var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetAgendaEmptyListItem);
                        emptyView.SetTextViewText(Resource.Id.WidgetAgendaEmptyListItemTextView, item as string);

                        return(emptyView);
                    }

                    var task = item as BaseViewItemHomeworkExam;
                    var c    = task.GetClassOrNull();
                    if (c == null)
                    {
                        var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetAgendaEmptyListItem);
                        return(emptyView);
                    }

                    RemoteViews taskView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetAgendaTaskListItem);
                    taskView.SetTextViewText(Resource.Id.WidgetAgendaTaskTextView, task.Name);
                    taskView.SetInt(Resource.Id.WidgetAgendaTaskColorBar, "setBackgroundColor", ColorTools.GetColor(c.Color));

                    Intent taskIntent = new Intent()
                                        .SetAction(Intent.ActionView)
                                        .SetData(Android.Net.Uri.Parse("powerplanner:?" + ArgumentsHelper.CreateArgumentsForView(task, _localAccountId).SerializeToString()));
                    taskView.SetOnClickFillInIntent(Resource.Id.WidgetAgendaTaskListItem, taskIntent);

                    return(taskView);
                }
                catch (Exception ex)
                {
                    // Out of range exception can be expected since the items list can change while we're working
                    if (!(ex is ArgumentOutOfRangeException))
                    {
                        TelemetryExtension.Current?.TrackException(ex);
                    }

                    var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetAgendaEmptyListItem);
                    return(emptyView);
                }
            }
Пример #10
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);
        }
Пример #11
0
            public RemoteViews GetViewAt(int position)
            {
                Realm other = Realm.GetInstance(DB.RealmConfiguration);

                if (!RealmInstance.IsSameInstance(other))
                {
                    RealmInstance.Dispose();
                    RealmInstance = other;
                }

                RemoteViews page = new RemoteViews(context.PackageName, ItemLayout);

                Book book = RealmInstance.Find <Book>(position);

                if (book == null)
                {
                    return(page);
                }

                page.SetTextViewText(Resource.Id.book_title, book.Title);

                Intent bookClick = new Intent();

                bookClick.SetAction(SelectBook);
                bookClick.PutExtra(AppWidgetManager.ExtraAppwidgetId, WidgetId);
                bookClick.PutExtra(ExtraBookId, book.ID);
                page.SetOnClickFillInIntent(Resource.Id.root, bookClick);

                if (book.ID == BookId)
                {
                    page.SetInt(Resource.Id.root, "setBackgroundColor", Color.ParseColor("#d0d0d0"));
                }
                else
                {
                    page.SetInt(Resource.Id.root, "setBackgroundColor", Color.ParseColor("#f0f0f0"));
                }

                return(page);
            }
Пример #12
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;
        }
Пример #13
0
        private void UpdateDisplay(string message, Android.Graphics.Color color)
        {
            //Uncomment if you want to hear a success sound on every screenupdate
            //			AudioManager audio = (AudioManager) GetSystemService(Context.AudioService);
            //			audio.PlaySoundEffect((SoundEffect)Sounds.Success);

            if (color == Android.Graphics.Color.Yellow)
            {
                remoteViews.SetTextColor(Resource.Id.LivecardContent, Android.Graphics.Color.Black);
            }
            else
            {
                remoteViews.SetTextColor(Resource.Id.LivecardContent, Android.Graphics.Color.White);
            }
            remoteViews.SetInt(Resource.Id.Framelayout1, "setBackgroundColor", color);

            remoteViews.SetTextViewText(Resource.Id.LivecardContent, message);

            livecard.SetViews(remoteViews);
        }
Пример #14
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;
        }
Пример #15
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)
            {
                try
                {
                    object item = _items[position];

                    if (item is DateTime)
                    {
                        var dateHeaderView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetScheduleDateListItem);
                        dateHeaderView.SetTextViewText(Resource.Id.WidgetScheduleDateHeaderTextView, WidgetAgendaService.WidgetAgendaFactory.ToFriendlyDate((DateTime)item, _now));

                        return(dateHeaderView);
                    }

                    if (item is string)
                    {
                        // String represents "Nothing due!", etc
                        var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetScheduleEmptyListItem);
                        emptyView.SetTextViewText(Resource.Id.WidgetScheduleEmptyListItemTextView, item as string);

                        return(emptyView);
                    }

                    if (item is ViewItemHoliday)
                    {
                        var holiday = item as ViewItemHoliday;

                        RemoteViews holidayView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetScheduleHolidayListItem);
                        holidayView.SetTextViewText(Resource.Id.WidgetScheduleHolidayNameTextView, holiday.Name.Trim());
                        holidayView.SetInt(Resource.Id.WidgetScheduleHolidayListItem, "setBackgroundColor", Views.DayScheduleSnapshotView.HolidayColor);

                        Intent holidayIntent = new Intent()
                                               .SetAction(Intent.ActionView)
                                               .SetData(Android.Net.Uri.Parse("powerplanner:?" + new ViewHolidayArguments()
                        {
                            ItemId         = holiday.Identifier,
                            LaunchSurface  = LaunchSurface.SecondaryTile,
                            LocalAccountId = _localAccountId
                        }.SerializeToString()));
                        holidayView.SetOnClickFillInIntent(Resource.Id.WidgetScheduleHolidayListItem, holidayIntent);

                        return(holidayView);
                    }

                    var schedule = item as ViewItemSchedule;
                    var c        = schedule.Class;
                    if (c == null)
                    {
                        var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetScheduleEmptyListItem);
                        return(emptyView);
                    }

                    bool hasRoom = !string.IsNullOrWhiteSpace(schedule.Room);

                    RemoteViews classView = new RemoteViews(_context.PackageName, hasRoom ? Resource.Layout.WidgetScheduleClassWithRoomListItem : Resource.Layout.WidgetScheduleClassListItem);
                    classView.SetTextViewText(Resource.Id.WidgetScheduleClassNameTextView, c.Name.Trim());
                    classView.SetTextViewText(Resource.Id.WidgetScheduleClassTimeTextView, Views.ListItems.MyScheduleItemView.GetStringTimeToTime(schedule));
                    if (hasRoom)
                    {
                        classView.SetTextViewText(Resource.Id.WidgetScheduleClassRoomTextView, schedule.Room.Trim());
                    }
                    classView.SetInt(Resource.Id.WidgetScheduleClassListItem, "setBackgroundColor", ColorTools.GetColor(c.Color));

                    Intent classIntent = new Intent()
                                         .SetAction(Intent.ActionView)
                                         .SetData(Android.Net.Uri.Parse("powerplanner:?" + new ViewClassArguments()
                    {
                        ItemId         = c.Identifier,
                        LaunchSurface  = LaunchSurface.SecondaryTile,
                        LocalAccountId = _localAccountId
                    }.SerializeToString()));
                    classView.SetOnClickFillInIntent(Resource.Id.WidgetScheduleClassListItem, classIntent);

                    return(classView);
                }
                catch (Exception ex)
                {
                    // Out of range exception can be expected since the items list can change while we're working
                    if (!(ex is ArgumentOutOfRangeException))
                    {
                        TelemetryExtension.Current?.TrackException(ex);
                    }

                    var emptyView = new RemoteViews(_context.PackageName, Resource.Layout.WidgetScheduleEmptyListItem);
                    return(emptyView);
                }
            }
Пример #17
0
        private RemoteViews UpdateWidgetListView(Context context, int appWidgetId)
        {
            RemoteViews ClassIndex  = new RemoteViews(context.PackageName, Resource.Layout.classindex);
            RemoteViews Framework   = new RemoteViews(context.PackageName, Resource.Layout.classtableframe);
            RemoteViews remoteViews = new RemoteViews(context.PackageName, Resource.Layout.classtablewidget);

            remoteViews.RemoveAllViews(Resource.Id.ClassGrid);
            Framework.RemoveAllViews(Resource.Id.classgridframe);
            remoteViews.AddView(Resource.Id.ClassGrid, ClassIndex);

            if (!Core.Initialized)
            {
                Framework.SetTextViewText(Resource.Id.lastrefreshtime, "请进入程序初次设置后点击刷新");
                Framework.AddView(Resource.Id.classgridframe, remoteViews);
                return(Framework);
            }

            RenderItems();

            for (int i = 0; i < 7; i++)
            {
                RemoteViews SingleLine        = new RemoteViews(context.PackageName, Resource.Layout.SingleLine);
                int         AlreadyFillBlanks = 0;

                for (int j = 0; j < 11; j++)
                {
                    if (items[i, j] == null)
                    {
                        if (AlreadyFillBlanks == 11)
                        {
                            continue;
                        }
                        int Period = 11 - AlreadyFillBlanks;

                        int         LayoutId = (int)typeof(Resource.Layout).GetField("singleclassitem_" + Period.ToString()).GetRawConstantValue();
                        RemoteViews AddView  = new RemoteViews(context.PackageName, LayoutId);
                        SingleLine.AddView(Resource.Id.singleline, AddView);
                        AlreadyFillBlanks += Period;
                    }
                    else if (items[i, j].Name == "")
                    {
                        int Period   = items[i, j].DayEnd - items[i, j].DayBegin + 1;
                        int LayoutId = (int)typeof(Resource.Layout).GetField("singleclassitem_" + Period.ToString()).GetRawConstantValue();
                        AlreadyFillBlanks += Period;
                        RemoteViews AddView = new RemoteViews(context.PackageName, LayoutId);
                        SingleLine.AddView(Resource.Id.singleline, AddView);
                    }
                    else
                    {
                        int         Period   = items[i, j].DayEnd - items[i, j].DayBegin + 1;
                        int         LayoutId = (int)typeof(Resource.Layout).GetField("singleclassitem_" + Period.ToString()).GetRawConstantValue();
                        int         ViewId   = (int)typeof(Resource.Id).GetField("class" + Period.ToString()).GetRawConstantValue();
                        RemoteViews AddView  = new RemoteViews(context.PackageName, LayoutId);
                        AddView.SetTextViewText(ViewId, items[i, j].Name + "\n" + items[i, j].Classroom);
                        Color color = ClassColors[items[i, j].Name[0] % 10];
                        //color.A = 95;
                        AlreadyFillBlanks += Period;
                        AddView.SetInt(ViewId, "setBackgroundColor", color);
                        SingleLine.AddView(Resource.Id.singleline, AddView);
                    }
                }

                AlreadyFillBlanks = 0;
                remoteViews.AddView(Resource.Id.ClassGrid, SingleLine);
            }

            DateTime currentTime     = DateTime.Now;
            var      WeekDays        = new string[] { "星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
            var      LastRefreshTime = $"{currentTime.ToString("m")} {WeekDays[(int)currentTime.DayOfWeek]} 第{Core.App.Service.CurrentWeek}周 点击刷新";

            Framework.SetTextViewText(Resource.Id.lastrefreshtime, LastRefreshTime);
            Framework.AddView(Resource.Id.classgridframe, remoteViews);
            return(Framework);
        }
Пример #18
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);
        }
Пример #19
0
        public static void Update(Context context, NextAlarm nextAlarm, int[] appWidgetIds = null)
        {
            AppWidgetManager appWidgetManager = AppWidgetManager.GetInstance(context);
            ComponentName    thisWidget       = new ComponentName(context, Class.FromType(typeof(Widget)).Name);

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

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

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

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


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

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

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

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

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

            ScheduleMidnightUpdate(context);
        }