Skip to content

Commit

Permalink
Added GetPrinterStatusTask function
Browse files Browse the repository at this point in the history
Removed unit tests folders as I won't create unit tests on this wrapper
  • Loading branch information
ltrudu committed Jun 25, 2024
1 parent 173acba commit fedcdc4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 82 deletions.
2 changes: 0 additions & 2 deletions PrintWrapper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ dependencies {
implementation files('libs/jackson-databind-2.2.3.jar')
implementation 'androidx.appcompat:appcompat:1.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.tom-roush:pdfbox-android:2.0.27.0'

}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.zebra.printwrapper;

import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.printer.PrinterStatus;
import com.zebra.sdk.printer.ZebraPrinter;
import com.zebra.sdk.printer.ZebraPrinterFactory;
import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;
import com.zebra.sdk.printer.discovery.DiscoveredPrinter;

public class GetPrinterStatusTask extends ExecutorTask<DiscoveredPrinter, Boolean, PrinterStatus>{
@Override
protected PrinterStatus doInBackground(DiscoveredPrinter... printerParams) {
DiscoveredPrinter selectedPrinter = printerParams[0];
PrinterStatus printerStatus = null;
if(selectedPrinter != null)
{
if(selectedPrinter.getConnection() != null ) {
Connection connection = selectedPrinter.getConnection();
if(connection.isConnected() == false) {
try {
connection.open();
ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);
if(printer != null)
{
printerStatus = printer.getCurrentStatus();
}
} catch (ConnectionException e) {
throw new RuntimeException(e);
} catch (ZebraPrinterLanguageUnknownException e) {
throw new RuntimeException(e);
}
finally {
try {
connection.close();
} catch (ConnectionException e) {
throw new RuntimeException(e);
}
}
}
}
}
return printerStatus;
}
}
37 changes: 0 additions & 37 deletions PrintWrapper/src/main/java/com/zebra/printwrapper/SGDHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,6 @@ public static Connection connectToPrinter(DiscoveredPrinter printer, SGDHelperCa
}

if (printer instanceof DiscoveredPrinterBluetooth) {
//class BluetoothConnectionQuickClose extends BluetoothConnection {
//
// public BluetoothConnectionQuickClose(String address) {
// super(address);
// }
//
// @Override
// public void close() throws ConnectionException {
// this.friendlyName = "";
// if (this.isConnected) {
// this.isConnected = false;
//
// try {
// this.inputStream.close();
// this.outputStream.close();
// this.commLink.close();
// } catch (IOException e) {
// // Ugly... don't even know if it will be helpful or not...
// throw new ConnectionException(e.getMessage());
// }
// }
// }
//}
if (callback != null) {
callback.onMessage("Connecting to bluetooth Printer: " + printer.address);
}
Expand Down Expand Up @@ -145,20 +122,6 @@ public static Connection connectToPrinter(DiscoveredPrinter printer, SGDHelperCa
throw new PrinterWrapperException(new Exception("SGDHelper.connectToPrinter: Could not establish connection with BluetoothPrinter."));
}
} else if (printer instanceof DiscoveredPrinterNetwork) {
//class MultiChannelQuickClose extends MultichannelTcpConnection {
//
// public MultiChannelQuickClose(DiscoveredPrinter printer) {
// super(printer);
// }
//
// @Override
// public void close() throws ConnectionException {
// if (this.isConnected()) {
// this.closePrintingChannel();
// this.closeStatusChannel();
// }
// }
//}
if (callback != null) {
callback.onMessage("Connecting to Network Printer: " + printer.address);
}
Expand Down

This file was deleted.

0 comments on commit fedcdc4

Please sign in to comment.