本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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]);
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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());
}
}
示例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;
}
示例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();
}
示例11: print
import android.print.PrintDocumentAdapter; //导入依赖的package包/类
@Override
public void print(String printJobName, PrintDocumentAdapter documentAdapter,
PrintAttributes attributes) {
dumpJobStatesForDebug();
mPrintManager.print(printJobName, documentAdapter, attributes);
}
示例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;
}
示例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());
}
示例14: PrintDocumentAdapterWrapper
import android.print.PrintDocumentAdapter; //导入依赖的package包/类
public PrintDocumentAdapterWrapper(Activity activity, PrintDocumentAdapter adapter) {
super();
this.activity = activity;
this.delegate = adapter;
}
示例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();
}
}