Some small cleanup

This commit is contained in:
Sebastián Katzer 2014-10-02 16:01:12 +02:00
parent 7d29d01ff3
commit fb77141140

View File

@ -59,16 +59,16 @@ public class Printer extends CordovaPlugin {
* To run on the UI thread, use: * To run on the UI thread, use:
* cordova.getActivity().runOnUiThread(runnable); * cordova.getActivity().runOnUiThread(runnable);
* *
* @param action The action to execute. * @param action The action to execute.
* @param rawArgs The exec() arguments in JSON form. * @param args The exec() arguments in JSON form.
* @param callbackContext The callback context used when calling back into JavaScript. * @param callback The callback context used when calling back into JavaScript.
* @return Whether the action was valid. * @return Whether the action was valid.
*/ */
@Override @Override
public boolean execute (String action, JSONArray args, public boolean execute (String action, JSONArray args,
CallbackContext callbackContext) throws JSONException { CallbackContext callback) throws JSONException {
command = callbackContext; command = callback;
if (action.equalsIgnoreCase("isAvailable")) { if (action.equalsIgnoreCase("isAvailable")) {
isAvailable(); isAvailable();
@ -105,12 +105,12 @@ public class Printer extends CordovaPlugin {
*/ */
private void print (final JSONArray args) { private void print (final JSONArray args) {
final String content = args.optString(0, "<html></html>"); final String content = args.optString(0, "<html></html>");
final JSONObject props = args.optJSONObject(1);; final JSONObject props = args.optJSONObject(1);
cordova.getActivity().runOnUiThread( new Runnable() { cordova.getActivity().runOnUiThread( new Runnable() {
@Override @Override
public void run() { public void run() {
initWebView(content, props); initWebView(props);
loadContent(content); loadContent(content);
} }
}); });
@ -138,29 +138,25 @@ public class Printer extends CordovaPlugin {
* Configures the WebView components which will call the Google Cloud Print * Configures the WebView components which will call the Google Cloud Print
* Service. * Service.
* *
* @param content
* HTML encoded string
* @param props * @param props
* The JSON object with the containing page properties * The JSON object with the containing page properties
*/ */
private void initWebView (String content, JSONObject props) { private void initWebView (JSONObject props) {
Activity ctx = cordova.getActivity(); Activity ctx = cordova.getActivity();
view = new WebView(ctx); view = new WebView(ctx);
view.getSettings().setDatabaseEnabled(true); view.getSettings().setDatabaseEnabled(true);
setWebViewClient(content, props); setWebViewClient(props);
} }
/** /**
* Creates the web view client which sets the print document. * Creates the web view client which sets the print document.
* *
* @param content
* HTML encoded string
* @param props * @param props
* The JSON object with the containing page properties * The JSON object with the containing page properties
*/ */
private void setWebViewClient (final String content, JSONObject props) { private void setWebViewClient (JSONObject props) {
final String docName = props.optString("name", DEFAULT_DOC_NAME); final String docName = props.optString("name", DEFAULT_DOC_NAME);
final boolean landscape = props.optBoolean("landscape", false); final boolean landscape = props.optBoolean("landscape", false);
final boolean graystyle = props.optBoolean("graystyle", false); final boolean graystyle = props.optBoolean("graystyle", false);
@ -212,8 +208,6 @@ public class Printer extends CordovaPlugin {
cordova.getThreadPool().execute(new Runnable() { cordova.getThreadPool().execute(new Runnable() {
@Override @Override
public void run() { public void run() {
Looper.prepare();
for (;;) { for (;;) {
if (job.isCancelled() || job.isCompleted() || job.isFailed()) { if (job.isCancelled() || job.isCompleted() || job.isFailed()) {
command.success(); command.success();