}
+ if ((byte) (status & GpCom.STATE_TIMES_OUT) > 0) {
+ str += "查询超时";
+ }
+ }
+ view.showToast( "打印机:" + " 状态:" + str);
+ view.onPrinterError(str);
+ } catch (RemoteException e1) {
+ e1.printStackTrace();
+ }
}
@Override
public void printTestPage() {
-
+ try {
+ int rel = mGpService.printeTestPage(0); //
+ Log.i("ServiceConnection", "rel " + rel);
+ GpCom.ERROR_CODE r = GpCom.ERROR_CODE.values()[rel];
+ if (r != GpCom.ERROR_CODE.SUCCESS) {
+ view.showToast( GpCom.getErrorText(r));
+ }
+ } catch (RemoteException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
}
@Override
@@ -89,8 +165,13 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter
}
@Override
- public void connectPrinter() {
-
+ public void connectPrinter(BluetoothDevice device) {
+ try {
+ int code = mGpService.openPort(0, PortParameters.BLUETOOTH, device.getAddress(), 0);
+ LogHelper.d("czy","open port return code ="+code);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
}
@Override
@@ -103,9 +184,11 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter
}
}
- @Override
- public void connectBluetooth(BluetoothDevice device) {
-
+ private void startAndBindPrintService() {
+ Intent intent = new Intent(App.getAppContext(), GpPrintService.class);
+ App.getAppContext().startService(intent);
+ conn = new PrinterServiceConnection();
+ App.getAppContext().bindService(intent, conn, Context.BIND_AUTO_CREATE);
}
// changes the title when discovery is finished
@@ -131,6 +214,30 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter
}
};
+ private void registerPrinterBroadcast() {
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(GpCom.ACTION_CONNECT_STATUS);
+ context.registerReceiver(PrinterStatusBroadcastReceiver, filter);
+ }
+
+ private BroadcastReceiver PrinterStatusBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (GpCom.ACTION_CONNECT_STATUS.equals(intent.getAction())) {
+ int type = intent.getIntExtra(GpPrintService.CONNECT_STATUS, 0);
+ int id = intent.getIntExtra(GpPrintService.PRINTER_ID, 0);
+ Log.d("czy", "connect status " + type);
+ if (type == GpDevice.STATE_CONNECTING) {
+
+ } else if (type == GpDevice.STATE_NONE) {
+
+ } else if (type == GpDevice.STATE_VALID_PRINTER) {
+
+ } else if (type == GpDevice.STATE_INVALID_PRINTER) {
+ }
+ }
+ }
+ };
}