Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1710e031 authored by Svetoslav's avatar Svetoslav Committed by Svetoslav Ganov
Browse files

Fix print preview rendered page preloading.

After the preview list is scrolled we are preloading the
pages around the ones that are shown, so now if the user
does a slight adjustment (expected after a scroll) the
pages around are rendered. There was an off by one error
and one of the bitmaps of the shown pages was reused and
as a result the wrong content was shown.

Change-Id: If04aebf46bcc637491221c6218005ecc1a7253d2
parent 53912d07
Loading
Loading
Loading
Loading
+2 −3
Original line number Original line Diff line number Diff line
@@ -26,7 +26,6 @@ import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.pdf.PdfRenderer;
import android.graphics.pdf.PdfRenderer;
import android.os.AsyncTask;
import android.os.AsyncTask;
import android.os.Debug;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.print.PrintAttributes.MediaSize;
import android.print.PrintAttributes.MediaSize;
import android.print.PrintAttributes.Margins;
import android.print.PrintAttributes.Margins;
@@ -69,7 +68,6 @@ public final class PageContentRepository {
    private RenderSpec mLastRenderSpec;
    private RenderSpec mLastRenderSpec;


    private int mScheduledPreloadFirstShownPage = INVALID_PAGE_INDEX;
    private int mScheduledPreloadFirstShownPage = INVALID_PAGE_INDEX;

    private int mScheduledPreloadLastShownPage = INVALID_PAGE_INDEX;
    private int mScheduledPreloadLastShownPage = INVALID_PAGE_INDEX;


    private int mState;
    private int mState;
@@ -525,7 +523,8 @@ public final class PageContentRepository {
                    * BYTES_PER_PIXEL;
                    * BYTES_PER_PIXEL;
            final int maxCachedPageCount = mPageContentCache.getMaxSizeInBytes()
            final int maxCachedPageCount = mPageContentCache.getMaxSizeInBytes()
                    / bitmapSizeInBytes;
                    / bitmapSizeInBytes;
            final int halfPreloadCount = (maxCachedPageCount - (lastShownPage - firstShownPage)) /2;
            final int halfPreloadCount = (maxCachedPageCount
                    - (lastShownPage - firstShownPage)) / 2 - 1;


            final int excessFromStart;
            final int excessFromStart;
            if (firstShownPage - halfPreloadCount < 0) {
            if (firstShownPage - halfPreloadCount < 0) {
+8 −8
Original line number Original line Diff line number Diff line
@@ -708,17 +708,17 @@ public final class PageAdapter extends Adapter {
    }
    }


    public void startPreloadContent(PageRange pageRangeInAdapter) {
    public void startPreloadContent(PageRange pageRangeInAdapter) {
//        final int startPageInDocument = computePageIndexInDocument(pageRangeInAdapter.getStart());
        final int startPageInDocument = computePageIndexInDocument(pageRangeInAdapter.getStart());
//        final int startPageInFile = computePageIndexInFile(startPageInDocument);
        final int startPageInFile = computePageIndexInFile(startPageInDocument);
//        final int endPageInDocument = computePageIndexInDocument(pageRangeInAdapter.getEnd());
        final int endPageInDocument = computePageIndexInDocument(pageRangeInAdapter.getEnd());
//        final int endPageInFile = computePageIndexInFile(endPageInDocument);
        final int endPageInFile = computePageIndexInFile(endPageInDocument);
//        if (startPageInDocument != INVALID_PAGE_INDEX && endPageInDocument != INVALID_PAGE_INDEX) {
        if (startPageInDocument != INVALID_PAGE_INDEX && endPageInDocument != INVALID_PAGE_INDEX) {
//            mPageContentRepository.startPreload(startPageInFile, endPageInFile);
            mPageContentRepository.startPreload(startPageInFile, endPageInFile);
//        }
        }
    }
    }


    public void stopPreloadContent() {
    public void stopPreloadContent() {
//        mPageContentRepository.stopPreload();
        mPageContentRepository.stopPreload();
    }
    }


    private void doDestroy() {
    private void doDestroy() {