Release v0.5.1

This commit is contained in:
Sebastián Katzer 2013-12-15 11:16:18 +01:00
parent 61011c4275
commit 5ef59a69ed
4 changed files with 11 additions and 174 deletions

View File

@ -9,11 +9,7 @@ by Sebastián Katzer ([github.com/katzer](https://github.com/katzer))
- **iOS** *(Print from iOS devices to AirPrint compatible printers)*<br>
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:
```
<gap:plugin name="de.appplant.cordova.plugin.printer" />
```
or to use this exact version:
```
<gap:plugin name="de.appplant.cordova.plugin.printer" version="0.5.0" />
```
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<br>
@ -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' });

View File

@ -3,7 +3,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="de.appplant.cordova.plugin.printer"
version="0.5.0">
version="0.5.1">
<name>Printer</name>
@ -51,7 +51,6 @@
</config-file>
<source-file src="src/android/Printer.java" target-dir="src/de/appplant/cordova/plugin/printer" />
<source-file src="src/android/KitKatPrinter.java" target-dir="src/de/appplant/cordova/plugin/printer" />
</platform>
</plugin>

View File

@ -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, "<html></html>");
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());
}
});
}
}

View File

@ -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', []);
};
},
/**
@ -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]);
};
}
};