Page content sometimes disappears when scrolling a long doc in print preview.
The operations of the remote renderer have to be performed in order, open,
render some pages, close. One of the tasks was executed on the wrong executor
resuling in a race and an occassional bad state.
Also fixed a NPE if the preview list is flinged and then the user presses
back.
bug:17537922
Change-Id: I5048078ba2b875a2a8335f3a4324afaa34d014a2
diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java b/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java
index 14c41da..0bec217 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java
@@ -526,7 +526,7 @@
callback.run();
}
}
- }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void[]) null);
+ }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
public void close(final Runnable callback) {
@@ -552,7 +552,7 @@
callback.run();
}
}
- }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
+ }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
public void destroy() {
@@ -571,7 +571,7 @@
mPageContentCache.invalidate();
mPageContentCache.clear();
}
- }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void[]) null);
+ }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
public void startPreload(int firstShownPage, int lastShownPage, RenderSpec renderSpec) {
@@ -687,7 +687,7 @@
// Oh well, we will have work to do...
renderTask = new RenderPageTask(pageIndex, renderSpec, callback);
mPageToRenderTaskMap.put(pageIndex, renderTask);
- renderTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void[]) null);
+ renderTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
public void cancelRendering(int pageIndex) {
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PageAdapter.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PageAdapter.java
index 369c453..84bbc27 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/ui/PageAdapter.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PageAdapter.java
@@ -275,7 +275,6 @@
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View page = mLayoutInflater.inflate(R.layout.preview_page, parent, false);
ViewHolder holder = new MyViewHolder(page);
- holder.setIsRecyclable(true);
return holder;
}
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
index 389988a..d169319 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
@@ -953,7 +953,7 @@
// When the update is done we update the print preview.
mProgressMessageController.post();
return true;
- } else {
+ } else if (!willUpdate) {
// Update preview.
updatePrintPreviewController(false);
}
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintPreviewController.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintPreviewController.java
index b999866..0d45352 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintPreviewController.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintPreviewController.java
@@ -77,6 +77,7 @@
mRecyclerView = (RecyclerView) activity.findViewById(R.id.preview_content);
mRecyclerView.setLayoutManager(mLayoutManger);
mRecyclerView.setAdapter(mPageAdapter);
+ mRecyclerView.setItemViewCacheSize(0);
mPreloadController = new PreloadController(mRecyclerView);
mRecyclerView.setOnScrollListener(mPreloadController);
@@ -348,8 +349,7 @@
public void startPreloadContent() {
PageAdapter pageAdapter = (PageAdapter) mRecyclerView.getAdapter();
-
- if (pageAdapter.isOpened()) {
+ if (pageAdapter != null && pageAdapter.isOpened()) {
PageRange shownPages = computeShownPages();
if (shownPages != null) {
pageAdapter.startPreloadContent(shownPages);
@@ -359,8 +359,7 @@
public void stopPreloadContent() {
PageAdapter pageAdapter = (PageAdapter) mRecyclerView.getAdapter();
-
- if (pageAdapter.isOpened()) {
+ if (pageAdapter != null && pageAdapter.isOpened()) {
pageAdapter.stopPreloadContent();
}
}
diff --git a/packages/PrintSpooler/src/com/android/printspooler/widget/PageContentView.java b/packages/PrintSpooler/src/com/android/printspooler/widget/PageContentView.java
index 1000117..b792789 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/widget/PageContentView.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/widget/PageContentView.java
@@ -52,12 +52,12 @@
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ mContentRequested = false;
requestPageContentIfNeeded();
}
@Override
public void onPageContentAvailable(BitmapDrawable content) {
- assert (getBackground() != content);
setBackground(content);
}
@@ -70,7 +70,7 @@
final boolean providerChanged = (mProvider == null)
? provider != null : !mProvider.equals(provider);
final boolean loadingDrawableChanged = (mEmptyState == null)
- ? mEmptyState != null : !mEmptyState.equals(emptyState);
+ ? emptyState != null : !mEmptyState.equals(emptyState);
final boolean mediaSizeChanged = (mMediaSize == null)
? mediaSize != null : !mMediaSize.equals(mediaSize);
final boolean marginsChanged = (mMinMargins == null)