当前位置: 首页>>代码示例>>Java>>正文


Java PrintDocumentAdapter类代码示例

本文整理汇总了Java中android.print.PrintDocumentAdapter的典型用法代码示例。如果您正苦于以下问题:Java PrintDocumentAdapter类的具体用法?Java PrintDocumentAdapter怎么用?Java PrintDocumentAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PrintDocumentAdapter类属于android.print包,在下文中一共展示了PrintDocumentAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printOrCreatePdfFromWebview

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@SuppressWarnings("deprecation")
public PrintJob printOrCreatePdfFromWebview(WebView webview, String jobName) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Context c = webview.getContext();
        PrintDocumentAdapter printAdapter;
        PrintManager printManager = (PrintManager) c.getSystemService(Context.PRINT_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            printAdapter = webview.createPrintDocumentAdapter(jobName);
        } else {
            printAdapter = webview.createPrintDocumentAdapter();
        }
        if (printManager != null) {
            return printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
        }
    } else {
        Log.e(getClass().getName(), "ERROR: Method called on too low Android API version");
    }
    return null;
}
 
开发者ID:gsantner,项目名称:markor,代码行数:21,代码来源:ShareUtilBase.java

示例2: genPdfFile

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
private void genPdfFile() {
    PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);

    // Get a print adapter instance
    PrintDocumentAdapter printAdapter;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        printAdapter = mWebView.createPrintDocumentAdapter("my.pdf");
    } else {
        printAdapter = mWebView.createPrintDocumentAdapter();
    }

    // Create a print job with name and adapter instance
    String jobName = getString(R.string.app_name) + " Document";

    PrintAttributes attributes = new PrintAttributes.Builder()
            .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
            .setResolution(new PrintAttributes.Resolution("id", Context.PRINT_SERVICE, 200, 200))
            .setColorMode(PrintAttributes.COLOR_MODE_COLOR)
            .setMinMargins(PrintAttributes.Margins.NO_MARGINS)
            .build();

    printManager.print(jobName, printAdapter, attributes);


}
 
开发者ID:REBOOTERS,项目名称:AndroidAnimationExercise,代码行数:26,代码来源:PdfActivity.java

示例3: onOptionsItemSelected

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	Intent intent;
	switch (item.getItemId()) {
	case android.R.id.home:
		intent = new Intent(this, AboutActivity.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(intent);
		return true;
	case R.id.menu_print:
		PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
		PrintDocumentAdapter adapter = webView.createPrintDocumentAdapter();
		printManager.print(getString(R.string.app_name), adapter, null);
		return true;
	}
	return false;
}
 
开发者ID:lookwhatlook,项目名称:WeiboWeiBaTong,代码行数:18,代码来源:LicenseActivity.java

示例4: onLayout

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
public final void onLayout(PrintAttributes paramPrintAttributes1, PrintAttributes paramPrintAttributes2, CancellationSignal paramCancellationSignal, PrintDocumentAdapter.LayoutResultCallback paramLayoutResultCallback, Bundle paramBundle)
{
  int i = 1;
  this.f = paramPrintAttributes2;
  if (paramCancellationSignal.isCanceled())
  {
    paramLayoutResultCallback.onLayoutCancelled();
    return;
  }
  if (this.b != null)
  {
    PrintDocumentInfo localPrintDocumentInfo = new PrintDocumentInfo.Builder(this.c).setContentType(i).setPageCount(i).build();
    if (!paramPrintAttributes2.equals(paramPrintAttributes1)) {}
    for (;;)
    {
      paramLayoutResultCallback.onLayoutFinished(localPrintDocumentInfo, i);
      return;
      int j = 0;
    }
  }
  this.a = new jo(this, paramCancellationSignal, paramPrintAttributes2, paramPrintAttributes1, paramLayoutResultCallback).execute(new Uri[0]);
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:23,代码来源:jn.java

示例5: onLayout

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
public void onLayout(final PrintAttributes oldPrintAttributes, final PrintAttributes newPrintAttributes, final CancellationSignal cancellationSignal, android.print.PrintDocumentAdapter.LayoutResultCallback layoutresultcallback, Bundle bundle)
{
    boolean flag = true;
    mAttributes = newPrintAttributes;
    if (cancellationSignal.isCanceled())
    {
        layoutresultcallback.onLayoutCancelled();
        return;
    }
    if (mBitmap != null)
    {
        cancellationSignal = (new android.print.PrintDocumentInfo.Builder(jobName)).setContentType(1).setPageCount(1).build();
        if (newPrintAttributes.equals(oldPrintAttributes))
        {
            flag = false;
        }
        layoutresultcallback.onLayoutFinished(cancellationSignal, flag);
        return;
    } else
    {
        mLoadBitmap = (layoutresultcallback. new PrintHelperKitkat._cls2._cls1()).execute(new Uri[0]);
        return;
    }
}
 
开发者ID:Hamz-a,项目名称:MyCTFWriteUps,代码行数:25,代码来源:PrintHelperKitkat$2$1.java

示例6: onLayout

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
public final void onLayout(PrintAttributes paramPrintAttributes1, PrintAttributes paramPrintAttributes2, CancellationSignal paramCancellationSignal, PrintDocumentAdapter.LayoutResultCallback paramLayoutResultCallback, Bundle paramBundle)
{
  int i = 1;
  this.a = paramPrintAttributes2;
  PrintDocumentInfo localPrintDocumentInfo = new PrintDocumentInfo.Builder(this.b).setContentType(i).setPageCount(i).build();
  if (!paramPrintAttributes2.equals(paramPrintAttributes1)) {}
  for (;;)
  {
    paramLayoutResultCallback.onLayoutFinished(localPrintDocumentInfo, i);
    return;
    int j = 0;
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:14,代码来源:jm.java

示例7: onOptionsItemSelected

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;
    int itemId = item.getItemId();
    if (itemId == android.R.id.home) {
        intent = new Intent(this, AboutActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return true;
    } else if (itemId == R.id.menu_print) {
        PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
        PrintDocumentAdapter adapter = webView.createPrintDocumentAdapter();
        printManager.print(getString(R.string.app_name), adapter, null);
        return true;
    }
    return false;
}
 
开发者ID:andforce,项目名称:iBeebo,代码行数:18,代码来源:LicenseActivity.java

示例8: createWebPrintJob

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
private void createWebPrintJob(WebView webView) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        new UIHelper(this).showToast(R.string.min_19);
        return;
    } else {
        // Get a PrintManager instance
        PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);

        // Get a print adapter instance
        PrintDocumentAdapter printAdapter;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            printAdapter = webView.createPrintDocumentAdapter(getString(R.string.asset_allocation));
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
            printAdapter = webView.createPrintDocumentAdapter();
        } else {
            // to satisfy lint.
            return;
        }

        // Create a print job with name and adapter instance
        String jobName = getString(R.string.app_name) + " Document";
        // PrintJob printJob =
        printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
    }
}
 
开发者ID:moneymanagerex,项目名称:android-money-manager-ex,代码行数:26,代码来源:AssetAllocationReportActivity.java

示例9: onOptionsItemSelected

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;
    switch (item.getItemId()) {
        case android.R.id.home:
            intent = new Intent(this, AboutActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            return true;
        case R.id.menu_print:
            PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
            PrintDocumentAdapter adapter = webView.createPrintDocumentAdapter();
            printManager.print(getString(R.string.app_name), adapter, null);
            return true;
    }
    return false;
}
 
开发者ID:shawnlinboy,项目名称:siciyuan,代码行数:18,代码来源:LicenseActivity.java

示例10: print

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
static void print(final Context context, final long poemId) {
    new AsyncTask<Void, Void, PoemCursor>() {

        @Override
        protected PoemCursor doInBackground(Void... params) {
            final PoemSelection poemSelection = new PoemSelection().id(poemId);
            PoemCursor cursor = poemSelection.query(context.getContentResolver());
            if (cursor.moveToFirst()) {
                return cursor;
            }
            return null;
        }

        @Override
        protected void onPostExecute(final PoemCursor poemCursor) {
            if (poemCursor == null) return;
            final WebView webView = new WebView(context);
            final String title = poemCursor.getTitle();
            webView.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                    @SuppressWarnings("deprecation")
                    PrintDocumentAdapter printDocumentAdapter =
                            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? webView.createPrintDocumentAdapter(title)
                                    : webView.createPrintDocumentAdapter();
                    PrintAttributes printAttributes = new PrintAttributes.Builder().build();
                    PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
                    printManager.print(title, printDocumentAdapter, printAttributes);
                }
            });
            try {
                String preContent = poemCursor.getPreContent();
                if (preContent == null) preContent = "";
                String formattedText = context.getString(R.string.print_preview_html,
                        poemCursor.getTitle(),
                        preContent,
                        poemCursor.getContent(),
                        Poems.getPoemNumberString(context, poemCursor),
                        Poems.getLocationDateString(context, poemCursor));
                webView.loadDataWithBaseURL(null, formattedText, "text/html", "UTF-8", null);
            } finally {
                poemCursor.close();
            }
        }
    }.execute();

}
 
开发者ID:caarmen,项目名称:PalidaMuerte,代码行数:49,代码来源:PoemPrinter.java

示例11: print

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
@Override
public void print(String printJobName, PrintDocumentAdapter documentAdapter,
        PrintAttributes attributes) {
    dumpJobStatesForDebug();
    mPrintManager.print(printJobName, documentAdapter, attributes);
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:7,代码来源:PrintManagerDelegateImpl.java

示例12: onWrite

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
public void onWrite(PageRange apagerange[], ParcelFileDescriptor parcelfiledescriptor, CancellationSignal cancellationsignal, android.print.PrintDocumentAdapter.WriteResultCallback writeresultcallback)
        {
            cancellationsignal = new PrintedPdfDocument(mContext, mAttributes);
            apagerange = PrintHelperKitkat.access$000(PrintHelperKitkat.this, mBitmap, mAttributes.getColorMode());
            android.graphics.pdf.PdfDocument.Page page = cancellationsignal.startPage(1);
            Object obj = new RectF(page.getInfo().getContentRect());
            obj = PrintHelperKitkat.access$100(PrintHelperKitkat.this, mBitmap.getWidth(), mBitmap.getHeight(), ((RectF) (obj)), fittingMode);
            page.getCanvas().drawBitmap(apagerange, ((android.graphics.Matrix) (obj)), null);
            cancellationsignal.finishPage(page);
            cancellationsignal.writeTo(new FileOutputStream(parcelfiledescriptor.getFileDescriptor()));
            writeresultcallback.onWriteFinished(new PageRange[] {
                PageRange.ALL_PAGES
            });
_L1:
            if (cancellationsignal != null)
            {
                cancellationsignal.close();
            }
            IOException ioexception;
            if (parcelfiledescriptor != null)
            {
                try
                {
                    parcelfiledescriptor.close();
                }
                // Misplaced declaration of an exception variable
                catch (ParcelFileDescriptor parcelfiledescriptor) { }
            }
            if (apagerange != mBitmap)
            {
                apagerange.recycle();
            }
            return;
            ioexception;
            Log.e("PrintHelperKitkat", "Error writing printed content", ioexception);
            writeresultcallback.onWriteFailed(null);
              goto _L1
            writeresultcallback;
            if (cancellationsignal != null)
            {
                cancellationsignal.close();
            }
            if (parcelfiledescriptor != null)
            {
                try
                {
                    parcelfiledescriptor.close();
                }
                // Misplaced declaration of an exception variable
                catch (ParcelFileDescriptor parcelfiledescriptor) { }
            }
            if (apagerange != mBitmap)
            {
                apagerange.recycle();
            }
            throw writeresultcallback;
        }
 
开发者ID:Hamz-a,项目名称:MyCTFWriteUps,代码行数:58,代码来源:PrintHelperKitkat$2$1.java

示例13: createWebPrintJob

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
/**
 * Starts a print job for the given WebView
 *
 * Source: https://developer.android.com/training/printing/html-docs.html
 *
 * @param v the WebView to be printed
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
private void createWebPrintJob(WebView v) {
    // Get a PrintManager instance
    PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);

    // Get a print adapter instance
    PrintDocumentAdapter printAdapter = new PrintDocumentAdapterWrapper(this, v.createPrintDocumentAdapter());

    // Create a print job with name and adapter instance
    printJob = printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
}
 
开发者ID:dimagi,项目名称:commcare-android,代码行数:19,代码来源:TemplatePrinterActivity.java

示例14: PrintDocumentAdapterWrapper

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
public PrintDocumentAdapterWrapper(Activity activity, PrintDocumentAdapter adapter) {
    super();
    this.activity = activity;
    this.delegate = adapter;
}
 
开发者ID:dimagi,项目名称:commcare-android,代码行数:6,代码来源:TemplatePrinterActivity.java

示例15: printWithAdapter

import android.print.PrintDocumentAdapter; //导入依赖的package包/类
private void printWithAdapter(String jobName, PrintDocumentAdapter adapter) {
    if (PrintHelper.systemSupportsPrint()) {
        PrintManager printManager = 
          (PrintManager) getSystemService(Context.PRINT_SERVICE);
        printManager.print(jobName, adapter, null);
    } else {
        Toast.makeText(this,
          "この端末では印刷をサポートしていません",
          Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:sys1yagi,项目名称:PrintingFrameworkSample,代码行数:12,代码来源:CustomPrintActivity.java


注:本文中的android.print.PrintDocumentAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。