>
+ }else if( GpCom.ERROR_CODE.values()[code]!= GpCom.ERROR_CODE.SUCCESS){
+ view.showToast( GpCom.getErrorText(GpCom.ERROR_CODE.values()[code]));
}
}
@@ -197,17 +141,14 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter
@Override
public void connectPrinter(BluetoothDevice device) {
- if(mGpService==null){
+ if(printerService==null){
view.showToast(context.getString(R.string.printer_service_boot_fail));
return;
}
- try {
- int code = mGpService.openPort(0, PortParameters.BLUETOOTH, device.getAddress(), 0);
- if(code==0){
- Preferences.getInstance().setPrinterMac(device.getAddress());
- }
- LogHelper.d(TAG,"open port return code ="+code);
- } catch (Exception e) {
+ int code = printerService.connectPrinter(device);
+ if(code==0){
+ Preferences.getInstance().setPrinterMac(device.getAddress());
+ }else{
view.showToast(context.getString(R.string.printer_port_open_fail));
}
@@ -223,12 +164,6 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter
}
}
- 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
private final BroadcastReceiver mFindBlueToothReceiver = new BroadcastReceiver() {
@@ -264,12 +199,11 @@ public class PrinterSettingPresenter implements PrinterSettingContract.Presenter
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(TAG, "connect status " + type);
if (type == GpDevice.STATE_CONNECTING) {
view.onPrinterStatusFetched(context.getString(R.string.connecting));
} else if (type == GpDevice.STATE_NONE) {
-
+ view.onPrinterStatusFetched(context.getString(R.string.connecting));
} else if (type == GpDevice.STATE_VALID_PRINTER) {
view.onPrinterStatusFetched(context.getString(R.string.printer_is_connected));
} else if (type == GpDevice.STATE_INVALID_PRINTER) {