public RemoteViews GetViewAt(int position)
        {
            stopView = new RemoteViews(context.PackageName, Resource.Layout.widget_stop_list_item);

            // Click handlers
            Intent clickIntent = new Intent();

            clickIntent.PutExtra(ReittiWidget.ItemPosition, position);
            stopView.SetOnClickFillInIntent(Resource.Id.lineItemsHolderWidget, clickIntent);
            stopView.SetOnClickFillInIntent(Resource.Id.stopNameTextViewWidget, clickIntent);

            // Set stop name
            Stop stop = stops[position];

            stopView.SetTextViewText(Resource.Id.stopNameTextViewWidget, stop.Name);

            // Reset line views
            stopView.RemoveAllViews(Resource.Id.lineItemsHolderWidget);

            // Set line name and departure times
            foreach (var line in stop.Lines)
            {
                RemoteViews lineView = new RemoteViews(context.PackageName, Resource.Layout.widget_line_list_item);
                lineView.SetTextViewText(Resource.Id.labelLineNameWidget, line.Number);

                if (line.HasDepartures)
                {
                    if (line.NextDeparture != null)
                    {
                        lineView.SetTextViewText(Resource.Id.labelNextDepartureWidget, line.NextDeparture);
                    }
                    else
                    {
                        lineView.SetTextViewText(Resource.Id.labelNextDepartureWidget, context.GetString(Resource.String.no_time));
                    }

                    if (line.FollowingDeparture != null)
                    {
                        lineView.SetTextViewText(Resource.Id.labelFollowingDepartureWidget, line.FollowingDeparture);
                    }
                    else
                    {
                        lineView.SetTextViewText(Resource.Id.labelFollowingDepartureWidget, context.GetString(Resource.String.no_time));
                    }
                }
                else
                {
                    lineView.SetTextViewText(Resource.Id.labelNextDepartureWidget, context.GetString(Resource.String.no_time));
                    lineView.SetTextViewText(Resource.Id.labelFollowingDepartureWidget, context.GetString(Resource.String.no_time));
                }

                stopView.AddView(Resource.Id.lineItemsHolderWidget, lineView);
            }

            return(stopView);
        }
Beispiel #2
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);
        }