From 5ef59a69ed461eadd22a202d9218a72e9f0453ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 15 Dec 2013 11:16:18 +0100 Subject: [PATCH] Release v0.5.1 --- README.md | 26 ++---- plugin.xml | 5 +- src/android/KitKatPrinter.java | 142 --------------------------------- www/printer.js | 12 +-- 4 files changed, 11 insertions(+), 174 deletions(-) delete mode 100644 src/android/KitKatPrinter.java diff --git a/README.md b/README.md index 33679b4..aa7248c 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,7 @@ by Sebastián Katzer ([github.com/katzer](https://github.com/katzer)) - **iOS** *(Print from iOS devices to AirPrint compatible printers)*
See [Drawing and Printing Guide for iOS](http://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/Printing/Printing.html) for detailed informations and screenshots. -- **Android** *(Print through 3rd party printing apps on SDK <= 18)* - -## Dependencies -Cordova will check all dependencies and install them if they are missing. -- [org.apache.cordova.device](https://github.com/apache/cordova-plugin-device) *(since v0.5.0)* +- **Android** *(Print through 3rd party printing apps)* ## Adding the Plugin to your project Through the [Command-line Interface](http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface): @@ -28,19 +24,11 @@ Through the [Command-line Interface](http://cordova.apache.org/docs/en/3.0.0/gui cordova plugin rm de.appplant.cordova.plugin.printer ``` -## PhoneGap Build -Add the following xml to your config.xml to always use the latest version of this plugin: -``` - -``` -or to use this exact version: -``` - -``` -More informations can be found [here](https://build.phonegap.com/plugins/352). - ## Release Notes -#### Version 0.5.0 (11.12.2013) +#### Version 0.5.1 (15.12.2013) +- Removed Android KitKat support *(See kitkat branch)* + +#### Version 0.5.0 (yanked) - Release under the Apache 2.0 license. - [***change:***] Removed the `callback` property from the `print` interface. - [enhancement:] Added Android KitKat support
@@ -92,7 +80,7 @@ window.plugin.printer.print(page); ## Platform specifics -### Get all available printing apps on Android <= 4.3 +### Get all available printing apps on Android The callback function will be called with a second argument which is an array, indicating which printer apps are available for printing. ```javascript window.plugin.printer.isServiceAvailable( @@ -102,7 +90,7 @@ window.plugin.printer.isServiceAvailable( ); ``` -### Specify printing app on Android <= 4.3 +### Specify printing app on Android An App-ID can be assigned as a platform configuration to indicate which 3rd party printing app shall be used. Otherwise the first found application will be used. ```javascript window.plugin.printer.print(page, { appId: 'epson.print' }); diff --git a/plugin.xml b/plugin.xml index fbe0ca3..88284e8 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,7 +3,7 @@ + version="0.5.1"> Printer @@ -50,8 +50,7 @@ - - + diff --git a/src/android/KitKatPrinter.java b/src/android/KitKatPrinter.java deleted file mode 100644 index 75805d5..0000000 --- a/src/android/KitKatPrinter.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - Copyright 2013 appPlant UG - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -package de.appplant.cordova.plugin.printer; - -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.PluginResult; - -import org.json.JSONArray; -import org.json.JSONException; - -import android.annotation.TargetApi; -import android.content.Context; -import android.os.Build; -import android.print.PrintAttributes; -import android.print.PrintDocumentAdapter; -import android.print.PrintManager; -import android.view.View; -import android.webkit.WebView; -import android.webkit.WebViewClient; - -@TargetApi(19) -public class KitKatPrinter extends CordovaPlugin { - - @Override - public boolean execute (String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - // Es soll überprüft werden, ob ein Dienst zum Ausdrucken von Inhalten zur Verfügung steht - if (action.equalsIgnoreCase("isServiceAvailable")) { - isServiceAvailable(callbackContext); - - return true; - } - - // Etwas soll ausgedruckt werden - if (action.equalsIgnoreCase("print")) { - print(args, callbackContext); - - return true; - } - - // Returning false results in a "MethodNotFound" error. - return false; - } - - /** - * Überprüft, ob ein Drucker zur Verfügung steht. - */ - private void isServiceAvailable (CallbackContext ctx) { - Boolean supported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; - PluginResult result = new PluginResult(PluginResult.Status.OK, supported); - - ctx.sendPluginResult(result); - } - - /** - * Druckt den HTML Content aus. - */ - private void print (final JSONArray args, CallbackContext ctx) { - final KitKatPrinter self = this; - - cordova.getActivity().runOnUiThread( new Runnable() { - public void run() { - String content = args.optString(0, ""); - WebView controller = self.getPrintController(); - - self.loadContentIntoPrintController(content, controller); - - self.startPrinterApp(controller); - } - }); - } - - /** - * Erstellt den Print-View. - */ - private WebView getPrintController () { - WebView webview = new WebView(cordova.getActivity()); - - webview.setVisibility(View.INVISIBLE); - webview.getSettings().setJavaScriptEnabled(false); - - return webview; - } - - /** - * Lädt den zu druckenden Content in ein WebView, welcher vom Drucker ausgedruckt werden soll. - */ - private void loadContentIntoPrintController (String content, WebView webview) { - //Set base URI to the assets/www folder - String baseURL = webView.getUrl(); - baseURL = baseURL.substring(0, baseURL.lastIndexOf('/') + 1); - - webview.loadDataWithBaseURL(baseURL, content, "text/html", "UTF-8", null); - } - - /** - * Öffnet die Printer App, damit der Content ausgedruckt werden kann. - */ - private void startPrinterApp (WebView webview) { - webview.setWebViewClient (new WebViewClient() { - public boolean shouldOverrideUrlLoading (WebView view, String url) { - return false; - } - - public void onPageFinished (WebView webview, String url) { - // Get a PrintManager instance - PrintManager printManager = (PrintManager) cordova.getActivity() - .getSystemService(Context.PRINT_SERVICE); - - // Get a print adapter instance - PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter(); - - // Get a print builder instance - PrintAttributes.Builder builder = new PrintAttributes.Builder(); - - builder.setMinMargins(PrintAttributes.Margins.NO_MARGINS); - - // Create a print job with name and adapter instance - printManager.print("Print Document", printAdapter, builder.build()); - } - }); - } -} diff --git a/www/printer.js b/www/printer.js index 0df05dd..7b8d6e9 100755 --- a/www/printer.js +++ b/www/printer.js @@ -39,11 +39,7 @@ Printer.prototype = { callback.apply(scope || window, args); }; - if (device.platform == 'Android' && device.version >= '4.4') { - cordova.exec(callbackFn, null, 'KitKatPrinter', 'isServiceAvailable', []); - } else { - cordova.exec(callbackFn, null, 'Printer', 'isServiceAvailable', []); - }; + cordova.exec(callbackFn, null, 'Printer', 'isServiceAvailable', []); }, /** @@ -61,11 +57,7 @@ Printer.prototype = { return; } - if (device.platform == 'Android' && device.version >= '4.4') { - cordova.exec(null, null, 'KitKatPrinter', 'print', [page, options]); - } else { - cordova.exec(null, null, 'Printer', 'print', [page, options]); - }; + cordova.exec(null, null, 'Printer', 'print', [page, options]); } };