コード例 #1
0
                public MyOnLayoutAsyncTask(MyPrintDocumentAdapter self, PrintAttributes newAttributes,
                                           CancellationSignal cancellationSignal, LayoutResultCallback callback)
                {
                    this.self               = self;
                    this.newAttributes      = newAttributes;
                    this.cancellationSignal = cancellationSignal;
                    this.callback           = callback;

                    items = ((MotoGpStatAdapter)self.pcc.ListAdapter).CloneItems();
                }
コード例 #2
0
        public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
                                      CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
        {
            document = new PrintedPdfDocument(context, newAttributes);

            CalculateScale(newAttributes);

            var printInfo = new PrintDocumentInfo
                            .Builder("pdf-test.pdf")
                            .SetContentType(PrintContentType.Document)
                            .SetPageCount(1)
                            .Build();

            callback.OnLayoutFinished(printInfo, true);
        }
コード例 #3
0
        public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
                                       CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
        {
            document = new PrintedPdfDocument(context, newAttributes);

            CalculateScale(newAttributes);

            var printInfo = new PrintDocumentInfo
                .Builder("pdf-test.pdf")
                .SetContentType(PrintContentType.Document)
                .SetPageCount(1)
                .Build();

            callback.OnLayoutFinished(printInfo, true);
        }
コード例 #4
0
 public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
 {
     if (cancellationSignal.IsCanceled)
     {
         callback.OnLayoutCancelled();
         return;
     }
     callback.OnLayoutFinished(new PrintDocumentInfo.Builder(path)
                               .SetContentType(PrintContentType.Document)
                               .Build(), true);
 }
コード例 #5
0
ファイル: PrintPDFAdapter.cs プロジェクト: TinuMurani/WalkOut
 public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
 {
     if (cancellationSignal.IsCanceled)
     {
         callback.OnLayoutCancelled();
     }
     else
     {
         PrintDocumentInfo.Builder builder = new PrintDocumentInfo.Builder(_filePath);
         builder.SetContentType(PrintContentType.Document)
         .SetPageCount(PrintDocumentInfo.PageCountUnknown)
         .Build();
         callback.OnLayoutFinished(builder.Build(), !newAttributes.Equals(oldAttributes));
     }
 }
コード例 #6
0
 public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
                               CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
 {
     mWrappedInstance.OnLayout(oldAttributes, newAttributes,
                               cancellationSignal, callback, extras);
 }
コード例 #7
0
ファイル: CrossPrint.cs プロジェクト: DuarteGilbert/Punchando
            public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
            {
                mPdfDocument = new PrintedPdfDocument(CrossPrint.appcontext, newAttributes);

                if (cancellationSignal.IsCanceled)
                {
                    callback.OnLayoutCancelled();
                    return;
                }
                int pages = computePageCount(newAttributes);

                if (pages > 0)
                {
                    PrintDocumentInfo info = new PrintDocumentInfo
                                             .Builder("pdf.pdf")
                                             .SetContentType(PrintContentType.Document)
                                             .SetPageCount(pages).Build();
                    callback.OnLayoutFinished(info, true);
                }
                else
                {
                    callback.OnLayoutFailed("Page count calculation failed.");
                }
            }
コード例 #8
0
			public override void OnLayout (PrintAttributes oldAttributes, PrintAttributes newAttributes, 
				CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
			{
				mWrappedInstance.OnLayout(oldAttributes, newAttributes,
					cancellationSignal, callback, extras);
			}
コード例 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="oldAttributes"></param>
        /// <param name="newAttributes"></param>
        /// <param name="cancellationSignal"></param>
        /// <param name="callback"></param>
        /// <param name="extras"></param>
        public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
        {
            if (cancellationSignal.IsCanceled)
            {
                callback.OnLayoutCancelled();
                return;
            }

            using (PrintDocumentInfo.Builder builder = new PrintDocumentInfo.Builder(FileToPrint))
            {
                //using (
                PrintDocumentInfo pdi = builder.SetContentType(ContentType).Build(); //)
                {
                    callback.OnLayoutFinished(pdi, true);
                }
            }
        }
コード例 #10
0
            public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
                                          CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras)
            {
                // If we are already cancelled, don't do any work.
                if (cancellationSignal.IsCanceled)
                {
                    callback.OnLayoutCancelled();
                    return;
                }

                // Now we determined if the print attributes changed in a way that
                // would change the layout and if so we will do a layout pass.
                bool layoutNeeded = false;

                int density = System.Math.Max(newAttributes.GetResolution().HorizontalDpi,
                                              newAttributes.GetResolution().VerticalDpi);

                // Note that we are using the PrintedPdfDocument class which creates
                // a PDF generating canvas whose size is in points (1/72") not screen
                // pixels. Hence, this canvas is pretty small compared to the screen.
                // The recommended way is to layout the content in the desired size,
                // in this case as large as the printer can do, and set a translation
                // to the PDF canvas to shrink in. Note that PDF is a vector format
                // and you will not lose data during the transformation.

                // The content width is equal to the page width minus the margins times
                // the horizontal printer density. This way we get the maximal number
                // of pixels the printer can put horizontally.
                int marginLeft   = (int)(density * (float)newAttributes.MinMargins.LeftMils / MILS_IN_INCH);
                int marginRight  = (int)(density * (float)newAttributes.MinMargins.RightMils / MILS_IN_INCH);
                int contentWidth = (int)(density * (float)newAttributes.GetMediaSize()
                                         .WidthMils / MILS_IN_INCH) - marginLeft - marginRight;

                if (mRenderPageWidth != contentWidth)
                {
                    mRenderPageWidth = contentWidth;
                    layoutNeeded     = true;
                }

                // The content height is equal to the page height minus the margins times
                // the vertical printer resolution. This way we get the maximal number
                // of pixels the printer can put vertically.
                int marginTop     = (int)(density * (float)newAttributes.MinMargins.TopMils / MILS_IN_INCH);
                int marginBottom  = (int)(density * (float)newAttributes.MinMargins.BottomMils / MILS_IN_INCH);
                int contentHeight = (int)(density * (float)newAttributes.GetMediaSize()
                                          .HeightMils / MILS_IN_INCH) - marginTop - marginBottom;

                if (mRenderPageHeight != contentHeight)
                {
                    mRenderPageHeight = contentHeight;
                    layoutNeeded      = true;
                }

                // Create a context for resources at printer density. We will
                // be inflating views to render them and would like them to use
                // resources for a density the printer supports.
                if (mPrintContext == null || mPrintContext.Resources.Configuration.DensityDpi != density)
                {
                    var configuration = new Configuration();
                    configuration.DensityDpi = density;
                    mPrintContext            = pcc.CreateConfigurationContext(configuration);
                    mPrintContext.SetTheme(Android.Resource.Style.ThemeHoloLight);
                }

                // If no layout is needed that we did a layout at least once and
                // the document info is not null, also the second argument is false
                // to notify the system that the content did not change. This is
                // important as if the system has some pages and the content didn't
                // change the system will ask, the application to write them again.
                if (!layoutNeeded)
                {
                    callback.OnLayoutFinished(mDocumentInfo, false);
                    return;
                }

                // For demonstration purposes we will do the layout off the main
                // thread but for small content sizes like this one it is OK to do
                // that on the main thread.
                var asyncTask = new MyOnLayoutAsyncTask(this, newAttributes, cancellationSignal, callback);

                asyncTask.ExecuteOnExecutor(AsyncTask.ThreadPoolExecutor, (Java.Lang.Void[])null);
            }
コード例 #11
0
        public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, Android.OS.CancellationSignal cancellationSignal, LayoutResultCallback callback, Android.OS.Bundle extras)
        {
            if (cancellationSignal.IsCanceled)
            {
                callback.OnLayoutCancelled();
                return;
            }

            var pdi =
                new PrintDocumentInfo
                .Builder(_fileName)
                .SetContentType(Android.Print.PrintContentType.Document)
                .Build();

            callback.OnLayoutFinished(pdi, true);
        }