@@ -16,11 +16,28 @@ public class MuPDFPageAdapter extends BaseAdapter {
1616 private final FilePicker .FilePickerSupport mFilePickerSupport ;
1717 private final MuPDFCore mCore ;
1818 private final SparseArray <PointF > mPageSizes = new SparseArray <PointF >();
19+ private AsyncTask <MuPDFCore ,Void ,Void > getPageSizesTask ;
1920
2021 public MuPDFPageAdapter (Context c , FilePicker .FilePickerSupport filePickerSupport , MuPDFCore core ) {
2122 mContext = c ;
2223 mFilePickerSupport = filePickerSupport ;
2324 mCore = core ;
25+
26+ if (mCore !=null )
27+ {
28+ getPageSizesTask = new AsyncTask <MuPDFCore ,Void ,Void >(){
29+ @ Override
30+ protected Void doInBackground (MuPDFCore ... core ) {
31+ int numPages = getCount ();
32+ for (int position = 0 ; position < numPages ; position ++) {
33+ PointF size = core [0 ].getPageSize (position );
34+ mPageSizes .put (position , size );
35+ }
36+ return null ;
37+ }
38+ };
39+ getPageSizesTask .execute (mCore );
40+ }
2441 }
2542
2643 @ Override
@@ -57,9 +74,10 @@ public View getView(final int position, View convertView, ViewGroup parent) {
5774 // Page size as yet unknown so find it out
5875 PointF size = mCore .getPageSize (position );
5976 mPageSizes .put (position , size );
60- pageView .setPage (position , size );
77+ pageView .setPage (position , size );
6178 // Warning: Page size must be known for measuring so
62- // we can't do this in background!!!
79+ // we can't do this in background, but we try to fetch
80+ // all page sizes in the background when the adapter is created
6381 }
6482 return pageView ;
6583 }
0 commit comments