Version avec integration slave master
This commit is contained in:
@@ -311,6 +311,11 @@ public class Printama {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public int checkPaperStatus(){
|
||||
return _util.checkPaperStatus();
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return _util.isConnected();
|
||||
}
|
||||
@@ -385,6 +390,29 @@ public class Printama {
|
||||
});
|
||||
}
|
||||
|
||||
public void printSold(Bitmap bitmap, String title, StringBuilder text){
|
||||
_printama.connect(printama -> {
|
||||
_util.resetPrinter();
|
||||
_util.setBold();
|
||||
_util.printImage(bitmap);
|
||||
_util.printText(lineSeparator());
|
||||
_util.setAlign(PA.CENTER);
|
||||
_util.setBold();
|
||||
_util.printText(title+"\n");
|
||||
_util.setNormalText();
|
||||
_util.printText(lineSeparator()+"\n");
|
||||
_util.setNormalText();
|
||||
_util.setAlign(PA.LEFT);
|
||||
_util.printText(text.toString());
|
||||
_util.printText(lineSeparator());
|
||||
_util.setAlign(PA.CENTER);
|
||||
_util.printText("Powered by PMU-MALI"+"\n");
|
||||
_util.printText(lineSeparator());
|
||||
printama.feedPaper();
|
||||
printama.close();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
// PRINTER COMMANDS
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.anggastudio.printama.constants.PW;
|
||||
import com.anggastudio.printama.util.StrUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
@@ -54,6 +55,7 @@ class PrinterUtil {
|
||||
private final BluetoothDevice printer;
|
||||
private BluetoothSocket btSocket = null;
|
||||
private OutputStream btOutputStream = null;
|
||||
private InputStream btInputStream = null;
|
||||
private boolean is3InchPrinter;
|
||||
|
||||
PrinterUtil(BluetoothDevice printer) {
|
||||
@@ -67,6 +69,7 @@ class PrinterUtil {
|
||||
btSocket = socket;
|
||||
try {
|
||||
btOutputStream = socket.getOutputStream();
|
||||
btInputStream = socket.getInputStream();
|
||||
successListener.onConnected();
|
||||
} catch (IOException e) {
|
||||
failedListener.onFailed();
|
||||
@@ -80,8 +83,27 @@ class PrinterUtil {
|
||||
}).execute(printer);
|
||||
}
|
||||
|
||||
boolean isConnected() {
|
||||
return btSocket != null && btSocket.isConnected();
|
||||
boolean isConnected() {
|
||||
if (btSocket == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// Tester la connexion en vérifiant le flux d'entrée
|
||||
if (btSocket.isConnected()) {
|
||||
// Vérifier si le flux est accessible
|
||||
InputStream inputStream = btSocket.getInputStream();
|
||||
// Tenter de lire avec un timeout très court
|
||||
if (inputStream.available() >= 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
// Exception signifie que la connexion est perdue
|
||||
Log.e("Bluetooth", "Socket non connecté: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void finish() {
|
||||
@@ -243,6 +265,40 @@ class PrinterUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public int checkPaperStatus() {
|
||||
try {
|
||||
// Certaines imprimantes doivent être en mode "real-time"
|
||||
// Commande GS a 1 pour activer le mode "real-time"
|
||||
byte[] realtimeMode = new byte[]{0x1D, 0x61, 0x01};
|
||||
btOutputStream.write(realtimeMode);
|
||||
btOutputStream.flush();
|
||||
|
||||
Thread.sleep(50);
|
||||
|
||||
// Ensuite la commande de statut
|
||||
byte[] statusCommand = new byte[]{0x1D, 0x72, 0x01};
|
||||
btOutputStream.write(statusCommand);
|
||||
btOutputStream.flush();
|
||||
|
||||
Thread.sleep(200);
|
||||
|
||||
// Lire la réponse
|
||||
byte[] response = new byte[4];
|
||||
int bytesRead = btInputStream.read(response);
|
||||
|
||||
if (bytesRead > 0) {
|
||||
// Traiter la réponse...
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
boolean printImage(Bitmap bitmap, int width) {
|
||||
return printImage(PA.CENTER, bitmap, width);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="20dp"
|
||||
android:text="Choose Printer"
|
||||
android:text="Choisir une imprimante"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
android:layout_margin="20dp"
|
||||
android:backgroundTint="@color/colorGray5"
|
||||
android:gravity="center"
|
||||
android:text="Test"
|
||||
android:text="Tester"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp" />
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
android:layout_marginBottom="20dp"
|
||||
android:backgroundTint="@color/colorGray5"
|
||||
android:gravity="center"
|
||||
android:text="Save"
|
||||
android:text="Valider"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp" />
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="20dp"
|
||||
android:text="Choose Printer"
|
||||
android:text="Choissez une imprimante"
|
||||
android:textColor="@color/colorBlack"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
@@ -36,7 +36,7 @@
|
||||
android:textColor="@color/colorBlack"
|
||||
android:textSize="14sp"
|
||||
android:visibility="gone"
|
||||
tools:text="No paired Bluetooth printers found.\n\nTap the button below to open Bluetooth settings and pair a printer."
|
||||
tools:text="Aucune imprimante Bluetooth jumelée trouvée.\n\nAppuyez sur le bouton ci-dessous pour ouvrir les paramètres Bluetooth et jumeler une imprimante."
|
||||
tools:visibility="visible" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
@@ -61,7 +61,7 @@
|
||||
android:layout_marginRight="2dp"
|
||||
android:backgroundTint="@color/colorGray5"
|
||||
android:gravity="center"
|
||||
android:text="Test"
|
||||
android:text="Tester"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp" />
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
android:layout_weight="1"
|
||||
android:backgroundTint="@color/colorGray5"
|
||||
android:gravity="center"
|
||||
android:text="Save"
|
||||
android:text="Valider"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user