2023-04-10 10:51:36 +08:00
|
|
|
package chaoran.business.adapter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
|
|
|
|
|
import chaoran.business.activity.ResultListener;
|
|
|
|
|
import chaoran.business.service.ScanServiceEDA50P;
|
|
|
|
|
import chaoran.business.service.ScanServiceZEBRA;
|
|
|
|
|
import chaoran.business.strategy.Strategy;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class HoneywellAdapter implements Adapter {
|
|
|
|
|
private Context context;
|
|
|
|
|
private Strategy strategy;
|
|
|
|
|
private ResultListener resultListener;
|
|
|
|
|
private Intent intent = null;
|
|
|
|
|
|
|
|
|
|
public HoneywellAdapter(Context context, ResultListener resultListener) {
|
|
|
|
|
this.context = context;
|
|
|
|
|
this.resultListener = resultListener;
|
|
|
|
|
strategy = new Receiver();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void start() {
|
|
|
|
|
strategy.executeStrategy(resultListener);
|
|
|
|
|
openContinueScan();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void stop() {
|
|
|
|
|
strategy.exclusiveStrategy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Receiver extends BroadcastReceiver implements Strategy {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
resultListener.result(intent.getStringExtra("data"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void executeStrategy(ResultListener resultListener) {
|
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
|
filter.addAction("com.honeywell.scan.broadcast");
|
|
|
|
|
context.registerReceiver(this, filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exclusiveStrategy() {
|
|
|
|
|
context.unregisterReceiver(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-10 15:37:18 +08:00
|
|
|
|
2023-04-10 10:51:36 +08:00
|
|
|
public void openContinueScan(){
|
2023-04-10 16:17:49 +08:00
|
|
|
|
|
|
|
|
if("eda50p".equals(Build.MODEL.toLowerCase())){ // 扫描正常
|
|
|
|
|
intent = new Intent(context, ScanServiceEDA50P.class);
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
context.getApplicationContext().startForegroundService(intent);
|
|
|
|
|
}else {
|
|
|
|
|
context.getApplicationContext().startService(intent);
|
|
|
|
|
}
|
|
|
|
|
}else if("eda51".equals(Build.MODEL.toLowerCase())){ // 扫描正常
|
2023-04-10 10:51:36 +08:00
|
|
|
intent = new Intent(context, ScanServiceEDA50P.class);
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
context.getApplicationContext().startForegroundService(intent);
|
|
|
|
|
}else {
|
|
|
|
|
context.getApplicationContext().startService(intent);
|
|
|
|
|
}
|
2023-04-10 15:37:18 +08:00
|
|
|
}
|
|
|
|
|
else if("tc26".equals(Build.MODEL.toLowerCase())){
|
2023-04-10 10:51:36 +08:00
|
|
|
intent = new Intent(context, ScanServiceZEBRA.class);
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
|
context.getApplicationContext().startForegroundService(intent);
|
|
|
|
|
}else {
|
|
|
|
|
context.getApplicationContext().startService(intent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|