Exemple #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);
        }
Exemple #2
0
 void Refresh()
 {
     if (input == null)
     {
         // Normal dialog
         // TODO: HTML
         textDescription.Text    = messageBox.Text;              // Html.FromHtml(messageBox.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);
         if (messageBox.Image != null)
         {
             imageView.SetImageBitmap(null);
             using (Bitmap bm = ctrl.ConvertMediaToBitmap(messageBox.Image)) {
                 imageView.SetImageBitmap(null);
                 imageView.SetImageBitmap(bm);
             }
             imageView.Visibility = ViewStates.Visible;
         }
         else
         {
             imageView.Visibility = ViewStates.Gone;
         }
         if (!String.IsNullOrEmpty(messageBox.FirstButtonLabel))
         {
             btnView1.Visibility    = ViewStates.Visible;
             btnView1.Text          = messageBox.FirstButtonLabel;
             btnView1.LayoutChange += (object sender, View.LayoutChangeEventArgs e) => SetTextScale(btnView1);
         }
         else
         {
             btnView1.Visibility = ViewStates.Gone;
         }
         if (!String.IsNullOrEmpty(messageBox.SecondButtonLabel))
         {
             btnView2.Visibility    = ViewStates.Visible;
             btnView2.Text          = messageBox.SecondButtonLabel;
             btnView2.LayoutChange += (object sender, View.LayoutChangeEventArgs e) => SetTextScale(btnView2);
         }
         else
         {
             btnView2.Visibility = ViewStates.Gone;
         }
     }
     else
     {
         // TODO: HTML
         textDescription.Text    = input.Text;              // Html.FromHtml(input.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);
         if (input.Image != null)
         {
             using (Bitmap bm = ctrl.ConvertMediaToBitmap(input.Image)) {
                 imageView.SetImageBitmap(bm);
             }
             imageView.Visibility = ViewStates.Visible;
         }
         else
         {
             imageView.Visibility = ViewStates.Gone;
         }
         if (input.InputType == InputType.MultipleChoice)
         {
             // Multiple choice dialog
             Spinner spinner = ctrl.FindViewById <Spinner> (Resource.Id.spinnerMulti);
             spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs> (OnSpinnerItemSelected);
             ArrayAdapter <string> adapter = new ArrayAdapter <string>(this.Activity, Android.Resource.Layout.SimpleSpinnerItem, input.Choices.ToArray());
             adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
             spinner.Adapter = adapter;
         }
         else
         {
             // Input dialog
             // ToDo: Clear text field editInput
             if (Main.Prefs.InputFocus)
             {
                 editInput.RequestFocus();
                 ((InputMethodManager)ctrl.GetSystemService(Context.InputMethodService)).ShowSoftInput(editInput, ShowFlags.Implicit);
             }
         }
     }
 }