From fedcdc47ea41f0b10a38630270afaa1717b3a931 Mon Sep 17 00:00:00 2001 From: Trudu Laurent Date: Tue, 25 Jun 2024 17:15:26 +0200 Subject: [PATCH] Added GetPrinterStatusTask function Removed unit tests folders as I won't create unit tests on this wrapper --- PrintWrapper/build.gradle | 2 - .../printwrapper/ExampleInstrumentedTest.java | 26 ----------- .../printwrapper/GetPrinterStatusTask.java | 45 +++++++++++++++++++ .../com/zebra/printwrapper/SGDHelper.java | 37 --------------- .../zebra/printwrapper/ExampleUnitTest.java | 17 ------- 5 files changed, 45 insertions(+), 82 deletions(-) delete mode 100644 PrintWrapper/src/androidTest/java/com/zebra/printwrapper/ExampleInstrumentedTest.java create mode 100644 PrintWrapper/src/main/java/com/zebra/printwrapper/GetPrinterStatusTask.java delete mode 100644 PrintWrapper/src/test/java/com/zebra/printwrapper/ExampleUnitTest.java diff --git a/PrintWrapper/build.gradle b/PrintWrapper/build.gradle index 72f90e5..f4abeef 100644 --- a/PrintWrapper/build.gradle +++ b/PrintWrapper/build.gradle @@ -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' } diff --git a/PrintWrapper/src/androidTest/java/com/zebra/printwrapper/ExampleInstrumentedTest.java b/PrintWrapper/src/androidTest/java/com/zebra/printwrapper/ExampleInstrumentedTest.java deleted file mode 100644 index 023098b..0000000 --- a/PrintWrapper/src/androidTest/java/com/zebra/printwrapper/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.zebra.printwrapper; - -import android.content.Context; - -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.zebra.printwrapper.test", appContext.getPackageName()); - } -} \ No newline at end of file diff --git a/PrintWrapper/src/main/java/com/zebra/printwrapper/GetPrinterStatusTask.java b/PrintWrapper/src/main/java/com/zebra/printwrapper/GetPrinterStatusTask.java new file mode 100644 index 0000000..5dfb355 --- /dev/null +++ b/PrintWrapper/src/main/java/com/zebra/printwrapper/GetPrinterStatusTask.java @@ -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{ + @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; + } +} diff --git a/PrintWrapper/src/main/java/com/zebra/printwrapper/SGDHelper.java b/PrintWrapper/src/main/java/com/zebra/printwrapper/SGDHelper.java index 4609b4d..340ca8a 100644 --- a/PrintWrapper/src/main/java/com/zebra/printwrapper/SGDHelper.java +++ b/PrintWrapper/src/main/java/com/zebra/printwrapper/SGDHelper.java @@ -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); } @@ -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); } diff --git a/PrintWrapper/src/test/java/com/zebra/printwrapper/ExampleUnitTest.java b/PrintWrapper/src/test/java/com/zebra/printwrapper/ExampleUnitTest.java deleted file mode 100644 index cb710ff..0000000 --- a/PrintWrapper/src/test/java/com/zebra/printwrapper/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.zebra.printwrapper; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file