Example #1
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            // Try to reuse convertView if it's not  null, otherwise inflate it from our item layout
            // This gives us some performance gains by not always inflating a new view
            // This will sound familiar to MonoTouch developers with UITableViewCell.DequeueReusableCell()
            var view = (convertView ?? ctrl.LayoutInflater.Inflate(Resource.Layout.GameListScreenItem, parent, false)) as RelativeLayout;

            var layout     = view.FindViewById <LinearLayout>(Resource.Id.linearLayoutItemText);
            var imageIcon  = view.FindViewById <ImageView>(Resource.Id.imageIcon);
            var textHeader = view.FindViewById <TextView>(Resource.Id.textHeader);

            if (!owner.ShowDirections)
            {
                var layoutParams = (RelativeLayout.LayoutParams)layout.LayoutParameters;
                layoutParams.RightMargin = 0;
                layout.LayoutParameters  = layoutParams;
            }

            Bitmap bm = null;

            try {
                if (owner.ShowIcons)
                {
                    //					imageIcon.SetImageBitmap(null);
                    if (owner.Items[position].Icon != null)
                    {
                        bm = ctrl.ConvertMediaToBitmap(owner.Items[position].Icon, 32);
                    }
                    else
                    {
                        bm = Images.IconEmpty;
                    }
                    imageIcon.SetImageBitmap(bm);
                    imageIcon.Visibility = ViewStates.Visible;
                }
                else
                {
                    imageIcon.Visibility = ViewStates.Gone;
                }
            } finally {
                if (bm != null)
                {
                    bm.Dispose();
                    bm = null;
                }
            }

            string name = owner.Items[position].Name == null ? "" : owner.Items[position].Name;

            if (owner.Items[position] is Task)
            {
                textHeader.Text = (((Task)owner.Items[position]).Complete ? (((Task)owner.Items[position]).CorrectState == TaskCorrectness.NotCorrect ? Strings.TaskNotCorrect : Strings.TaskCorrect) + " " : "") + name;
            }
            else
            {
                textHeader.Text = name;
            }

            using (var textDistance = view.FindViewById <TextView> (Resource.Id.textDistance)) {
                using (var imageDirection = view.FindViewById <ImageView> (Resource.Id.imageDirection)) {
                    if (screen == ScreenTypes.Locations || screen == ScreenTypes.Items)
                    {
                        if (((Thing)owner.Items[position]).VectorFromPlayer != null)
                        {
                            textDistance.Visibility   = ViewStates.Visible;
                            imageDirection.Visibility = ViewStates.Visible;
                            textDistance.Text         = ((Thing)owner.Items[position]).VectorFromPlayer.Distance.BestMeasureAs(DistanceUnit.Meters);
                            if (((Thing)owner.Items[position]).VectorFromPlayer.Distance.Value == 0)
                            {
                                imageDirection.SetImageBitmap(BitmapFactory.DecodeResource(owner.Activity.Resources, Resource.Drawable.ic_direction_position));
                            }
                            else
                            {
                                imageDirection.SetImageBitmap(BitmapArrow.Draw(_directionSize, ((Thing)owner.Items[position]).VectorFromPlayer.Bearing.Value + Main.GPS.Bearing));
//								AsyncImageFromDirection.LoadBitmap(imageDirection, ((Thing)owner.Items[position]).VectorFromPlayer.Bearing.Value + Main.GPS.Bearing, imageDirection.Width, imageDirection.Height);
                            }
                        }
                        else
                        {
                            textDistance.Visibility   = ViewStates.Gone;
                            imageDirection.Visibility = ViewStates.Gone;
                        }
                    }
                    else
                    {
                        textDistance.Visibility   = ViewStates.Gone;
                        imageDirection.Visibility = ViewStates.Gone;
                    }
                }
            }

            // Finally return the view
            return(view);
        }
Example #2
0
        void Refresh(object o = null)
        {
            string what = o == null ? "" : (string)o;

            if (activeObject == null || this.Activity == null)
            {
                return;
            }

            Activity.RunOnUiThread(() => {
                if (Activity == null)
                {
                    return;
                }

                // Assign this item's values to the various subviews
                ctrl.SupportActionBar.SetDisplayShowHomeEnabled(true);

                string name = activeObject.Name == null ? "" : activeObject.Name;

                if (what.Equals("") || what.Equals("Name"))
                {
                    if (activeObject is Task)
                    {
                        ctrl.SupportActionBar.Title = (((Task)activeObject).Complete ? (((Task)activeObject).CorrectState == TaskCorrectness.NotCorrect ? Strings.TaskNotCorrect : Strings.TaskCorrect) + " " : "") + name;
                    }
                    else
                    {
                        ctrl.SupportActionBar.Title = name;
                    }
                }

                if (what.Equals("") || what.Equals("Media"))
                {
                    if (activeObject.Image != null)
                    {
                        using (Bitmap bm = ctrl.ConvertMediaToBitmap(activeObject.Image)) {
                            _imageView.SetImageBitmap(null);
                            _imageView.SetImageBitmap(bm);
                        }
                        _imageView.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        _imageView.Visibility = ViewStates.Gone;
                    }
                }

                if (what.Equals("") || what.Equals("Description"))
                {
                    if (!String.IsNullOrWhiteSpace(activeObject.Description))
                    {
                        _textDescription.Visibility = ViewStates.Visible;
                        _textDescription.Text       = activeObject.Description;                   // Html.FromHtml(activeObject.HTML.Replace("&lt;BR&gt;", "<br>").Replace("<br>\n", "<br>").Replace("\n", "<br>"));
                        _textDescription.Gravity    = Main.Prefs.TextAlignment.ToSystem();
                        _textDescription.SetTextSize(global::Android.Util.ComplexUnitType.Sp, (float)Main.Prefs.TextSize);
                    }
                    else
                    {
                        _textDescription.Visibility = ViewStates.Visible;
                        _textDescription.Text       = "";
                        _textDescription.Gravity    = Main.Prefs.TextAlignment.ToSystem();
                        _textDescription.SetTextSize(global::Android.Util.ComplexUnitType.Sp, (float)Main.Prefs.TextSize);
                    }
                }
                // Tasks don't have any command button or direction
                if (activeObject is Task)
                {
                    _layoutBottom.Visibility = ViewStates.Gone;
                    return;
                }

                // Check, if the bottom should be displayed or not
                _layoutButtons.Visibility   = ((Thing)activeObject).ActiveCommands.Count == 0 ? ViewStates.Invisible : ViewStates.Visible;
                _layoutDirection.Visibility = ctrl.Engine.Player.Inventory.Contains(activeObject) ? ViewStates.Gone : (((Thing)activeObject).VectorFromPlayer == null ? ViewStates.Gone : ViewStates.Visible);
                _layoutBottom.Visibility    = (_layoutButtons.Visibility == ViewStates.Visible || _layoutDirection.Visibility == ViewStates.Visible) ? ViewStates.Visible : ViewStates.Gone;

                if (_layoutButtons.Visibility == ViewStates.Visible)
                {
                    _layoutButtons.RemoveAllViews();
                    commands = ((Thing)activeObject).ActiveCommands;
                    _layoutButtons.WeightSum = 1;
                    if (commands.Count > 0)
                    {
                        Button btnView = new Button(Activity.ApplicationContext);
                        btnView.Text   = commands.Count == 1 ? commands[0].Text : GetString(Resource.String.screen_detail_commands);
                        btnView.SetTextColor(Color.White);
                        btnView.SetHighlightColor(Color.White);
                        btnView.SetBackgroundResource(Resource.Drawable.apptheme_btn_default_holo_light);
                        btnView.LayoutChange += (object sender, View.LayoutChangeEventArgs e) => SetTextScale(btnView);
                        btnView.Click        += OnButtonClicked;
                        // Set size of button
                        Android.Views.ViewGroup.LayoutParams lp = new Android.Views.ViewGroup.LayoutParams(Android.Views.ViewGroup.LayoutParams.FillParent, Android.Views.ViewGroup.LayoutParams.FillParent);
                        // Add button to view
                        _layoutButtons.AddView(btnView, lp);
                    }
                }

                if (_layoutDirection.Visibility == ViewStates.Visible)
                {
                    // Draw direction content
                    var direction = ((Thing)activeObject).VectorFromPlayer;
                    if (direction != null)
                    {
                        _textDirection.Visibility  = ViewStates.Visible;
                        _imageDirection.Visibility = ViewStates.Visible;
                        _textDirection.Text        = direction.Distance.BestMeasureAs(DistanceUnit.Meters);
                        Bitmap bm;
                        _imageDirection.SetImageBitmap(null);
                        if (direction.Distance.Value == 0)
                        {
                            _imageDirection.SetImageBitmap(BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_direction_position));
                        }
                        else
                        {
                            _imageDirection.SetImageBitmap(BitmapArrow.Draw(Math.Min(_imageDirection.Width, _imageDirection.Height), direction.Bearing.Value + Main.GPS.Bearing));
                            //							AsyncImageFromDirection.LoadBitmap(_imageDirection, direction.Bearing.Value + Main.GPS.Bearing, 48, 48);
                            // TODO:
                            // Remove
                            //							bm = ctrl.DrawArrow (direction.Bearing.Value + Main.GPS.Bearing);
                            //							_imageDirection.SetImageBitmap (bm);
                            //							bm = null;
                        }
                    }
                }

                // Resize scrollview
                _layoutDefault.Invalidate();
            });
        }