FileDocCategorySizeDatePackage
PrintPreviewController.javaAPI DocAndroid 5.1 API13948Thu Mar 12 22:22:42 GMT 2015com.android.printspooler.ui

PrintPreviewController

public class PrintPreviewController extends Object implements MutexFileProvider.OnReleaseRequestCallback, EmbeddedContentContainer.OnSizeChangeListener, PageAdapter.PreviewArea

Fields Summary
private final PrintActivity
mActivity
private final com.android.printspooler.model.MutexFileProvider
mFileProvider
private final MyHandler
mHandler
private final PageAdapter
mPageAdapter
private final android.support.v7.widget.GridLayoutManager
mLayoutManger
private final com.android.printspooler.widget.PrintOptionsLayout
mPrintOptionsLayout
private final android.support.v7.widget.RecyclerView
mRecyclerView
private final com.android.printspooler.widget.PrintContentView
mContentView
private final com.android.printspooler.widget.EmbeddedContentContainer
mEmbeddedContentContainer
private final PreloadController
mPreloadController
private int
mDocumentPageCount
Constructors Summary
public PrintPreviewController(PrintActivity activity, com.android.printspooler.model.MutexFileProvider fileProvider)

        mActivity = activity;
        mHandler = new MyHandler(activity.getMainLooper());
        mFileProvider = fileProvider;

        mPrintOptionsLayout = (PrintOptionsLayout) activity.findViewById(R.id.options_container);
        mPageAdapter = new PageAdapter(activity, activity, this);

        final int columnCount = mActivity.getResources().getInteger(
                R.integer.preview_page_per_row_count);

        mLayoutManger = new GridLayoutManager(mActivity, columnCount);

        mRecyclerView = (RecyclerView) activity.findViewById(R.id.preview_content);
        mRecyclerView.setLayoutManager(mLayoutManger);
        mRecyclerView.setAdapter(mPageAdapter);
        mRecyclerView.setItemViewCacheSize(0);
        mPreloadController = new PreloadController(mRecyclerView);
        mRecyclerView.setOnScrollListener(mPreloadController);

        mContentView = (PrintContentView) activity.findViewById(R.id.options_content);
        mEmbeddedContentContainer = (EmbeddedContentContainer) activity.findViewById(
                R.id.embedded_content_container);
        mEmbeddedContentContainer.setOnSizeChangeListener(this);
    
Methods Summary
public voidcloseOptions()

        mContentView.closeOptions();
    
public voiddestroy(java.lang.Runnable callback)

        mHandler.cancelQueuedOperations();
        mRecyclerView.setAdapter(null);
        mPageAdapter.destroy(callback);
    
public intgetFilePageCount()

        return mPageAdapter.getFilePageCount();
    
public intgetHeight()

        return mEmbeddedContentContainer.getHeight();
    
public android.print.PageRange[]getRequestedPages()

        return mPageAdapter.getRequestedPages();
    
public android.print.PageRange[]getSelectedPages()

        return mPageAdapter.getSelectedPages();
    
public intgetWidth()

        return mEmbeddedContentContainer.getWidth();
    
public booleanisOptionsOpened()

        return mContentView.isOptionsOpened();
    
public voidonContentUpdated(boolean documentChanged, int documentPageCount, android.print.PageRange[] writtenPages, android.print.PageRange[] selectedPages, android.print.PrintAttributes.MediaSize mediaSize, android.print.PrintAttributes.Margins minMargins)

        boolean contentChanged = false;

        if (documentChanged) {
            contentChanged = true;
        }

        if (documentPageCount != mDocumentPageCount) {
            mDocumentPageCount = documentPageCount;
            contentChanged = true;
        }

        if (contentChanged) {
            // If not closed, close as we start over.
            if (mPageAdapter.isOpened()) {
                Message operation = mHandler.obtainMessage(MyHandler.MSG_CLOSE);
                mHandler.enqueueOperation(operation);
            }
        }

        // The content changed. In this case we have to invalidate
        // all rendered pages and reopen the file...
        if ((contentChanged || !mPageAdapter.isOpened()) && writtenPages != null) {
            Message operation = mHandler.obtainMessage(MyHandler.MSG_OPEN);
            mHandler.enqueueOperation(operation);
        }

        // Update the attributes before after closed to avoid flicker.
        SomeArgs args = SomeArgs.obtain();
        args.arg1 = writtenPages;
        args.arg2 = selectedPages;
        args.arg3 = mediaSize;
        args.arg4 = minMargins;
        args.argi1 = documentPageCount;

        Message operation = mHandler.obtainMessage(MyHandler.MSG_UPDATE, args);
        mHandler.enqueueOperation(operation);

        // If document changed and has pages we want to start preloading.
        if (contentChanged && writtenPages != null) {
            operation = mHandler.obtainMessage(MyHandler.MSG_START_PRELOAD);
            mHandler.enqueueOperation(operation);
        }
    
public voidonOrientationChanged()

        // Adjust the print option column count.
        final int optionColumnCount = mActivity.getResources().getInteger(
                R.integer.print_option_column_count);
        mPrintOptionsLayout.setColumnCount(optionColumnCount);
        mPageAdapter.onOrientationChanged();
    
public voidonReleaseRequested(java.io.File file)

        // This is called from the async task's single threaded executor
        // thread, i.e. not on the main thread - so post a message.
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                // At this point the other end will write to the file, hence
                // we have to close it and reopen after the write completes.
                if (mPageAdapter.isOpened()) {
                    Message operation = mHandler.obtainMessage(MyHandler.MSG_CLOSE);
                    mHandler.enqueueOperation(operation);
                }
            }
        });
    
public voidonSizeChanged(int width, int height)

        mPageAdapter.onPreviewAreaSizeChanged();
    
public voidsetColumnCount(int columnCount)

        mLayoutManger.setSpanCount(columnCount);
    
public voidsetPadding(int left, int top, int right, int bottom)

        mRecyclerView.setPadding(left, top, right, bottom);
    
public voidsetUiShown(boolean shown)

        if (shown) {
            mRecyclerView.setVisibility(View.VISIBLE);
        } else {
            mRecyclerView.setVisibility(View.GONE);
        }