public override View GetView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = new ImageView(ContextProp); convertView.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); // set size initially to fill whole screen. otherwise because of no height PdfPageGenerationTask will attempt to load all pages IWindowManager windowManager = Context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>(); Display disp = windowManager?.DefaultDisplay; if (disp != null) { Android.Graphics.Point screenSize = new Android.Graphics.Point(); disp.GetSize(screenSize); Android.Graphics.Bitmap pdfPageStartBitmap = Android.Graphics.Bitmap.CreateBitmap((int)(screenSize.X - HorizontalMarginsForView), (int)(screenSize.Y - VerticalMarginsForView), Android.Graphics.Bitmap.Config.Argb4444); ((ImageView)convertView).SetImageDrawable(new BitmapDrawable(ContextProp.Resources, pdfPageStartBitmap)); } } // on zoom do not cancel previous tasks so zooming is visible and performed on all visible views // on scrolling lets just focus on newest task bool isZooming = false; int tasksHistoryRelevant = 1; if (parent is PdfListView) { isZooming = ((PdfListView)parent).ScalingStatus != PdfListView.ScalingStatusValues.Idle; tasksHistoryRelevant = ((PdfListView)parent).VisibleItemCount; } // on scrolling hide reused views untill shown again so they do not show old content if (!isZooming) { ((ImageView)convertView).Visibility = ViewStates.Invisible; } PdfPageGenerationTask newPdfViewTask = new PdfPageGenerationTask((ImageView)convertView, this); newPdfViewTask.TaskIndex = position; SetPageGenerationTaskMngr(newPdfViewTask, tasksHistoryRelevant); newPdfViewTask.Execute(_url, position.ToString(), _zoom.ToString()); return(convertView); }
void SetPageGenerationTaskMngr(PdfPageGenerationTask pdfGenerationTask, int tasksHistoryRelevant) { if (_pdfPageGenerationTasks.Count > 1) { int historyRelevantCounter = 0; for (int i = _pdfPageGenerationTasks.Count - 1; i >= 0; i--) { historyRelevantCounter++; if (historyRelevantCounter > tasksHistoryRelevant) { _pdfPageGenerationTasks[i].Value.Cancel(false); _pdfPageGenerationTasks.RemoveAt(i); } } } _pdfPageGenerationTasks.Add(new KeyValuePair <int, PdfPageGenerationTask>(pdfGenerationTask.TaskIndex, pdfGenerationTask)); }