123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- package epson.print.service;
- import android.util.Log;
- import java.util.concurrent.SynchronousQueue;
- import java.util.concurrent.TimeUnit;
- import epson.print.EPImageList;
- public class CreatePrintImageThread extends Thread {
- private static final String TAG = "CreatePrintImageThread";
- private Exception mException;
- private EPImageList mImageList;
- private int mImagePerPage;
- private LocalImageCreator mLocalImageCreator;
- private boolean mLoopEnd;
- private PrintService mPrintService;
- private SynchronousQueue<Integer> mQueue = new SynchronousQueue<>();
- private RenderingController mRenderingController;
- private int mTotalPage;
- public CreatePrintImageThread(RenderingController renderingController, PrintService printService, LocalImageCreator localImageCreator, EPImageList ePImageList, int i, int i2) {
- super(TAG);
- mRenderingController = renderingController;
- mPrintService = printService;
- mLocalImageCreator = localImageCreator;
- mImageList = ePImageList;
- mImagePerPage = i;
- mTotalPage = i2;
- }
- public void run() {
- mLoopEnd = false;
- createImageLoop();
- mLoopEnd = true;
- Log.v(TAG, "run() end");
- }
- private void createImageLoop() {
- mException = null;
- int size = mImageList.size();
- int i = 0;
- int i2 = 0;
- while (i < mTotalPage) {
- try {
- int i3 = mImagePerPage + i2;
- if (i3 > size) {
- i3 = size;
- }
- mRenderingController.waitPage(i2, i3);
- if (mPrintService.getCancelPrinting()) {
- throw new LocalInterrupt();
- } else if (localCreateImage(mImageList, i) != null) {
- if (!mPrintService.getCancelPrinting()) {
- putSheet(i);
- i++;
- i2 = i3;
- } else {
- throw new LocalInterrupt();
- }
- } else {
- return;
- }
- } catch (Exception e) {
- mException = e;
- e.printStackTrace();
- return;
- }
- }
- }
- private String localCreateImage(EPImageList ePImageList, int i) {
- return mLocalImageCreator.createImage(mPrintService, ePImageList, i);
- }
- private void putSheet(int i) throws InterruptedException {
- Log.v(TAG, "queue.put " + i);
- mQueue.put(Integer.valueOf(i));
- }
- public int waitePrintImage() throws Exception {
- Exception exc = mException;
- if (exc != null) {
- throw exc;
- } else if (mLoopEnd) {
- return -1;
- } else {
- Log.v(TAG, "next take");
- Integer poll = mQueue.poll(180, TimeUnit.MINUTES);
- Log.v(TAG, "queue.take " + poll);
- if (poll == null) {
- return -1;
- }
- return poll.intValue();
- }
- }
- static class LocalImageCreator {
- int mColor;
- int mDate;
- int mDuplex;
- int mLayout;
- int mLayoutMulti;
- int mPaperSize;
- int mQuality;
- public LocalImageCreator(int i, int i2, int i3, int i4, int i5, int i6, int i7) {
- mPaperSize = i;
- mColor = i2;
- mDuplex = i3;
- mLayout = i4;
- mLayoutMulti = i5;
- mQuality = i6;
- mDate = i7;
- }
- public String createImage(PrintService printService, EPImageList ePImageList, int i) {
- return printService.createPrintImage(ePImageList, i, mPaperSize, mColor, mDuplex, mLayout, mLayoutMulti, mQuality, mDate);
- }
- }
- }
|