新大陆 pda 广播模式兼容
This commit is contained in:
@ -10,6 +10,7 @@ package chaoran.business;
|
||||
|
||||
public enum BrandEnum {
|
||||
//枚举名即为valueOf()
|
||||
NEW_LAND("新大陆", "newland"),
|
||||
HISENSE("海信", "hisense"),
|
||||
UROVO("DT50 Lite", "urovo"),
|
||||
LACHESIS("联新", "lachesis"),
|
||||
|
||||
@ -135,6 +135,9 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
case HKWS:
|
||||
adapter = new HkwsAdapter(this, this);
|
||||
break;
|
||||
case NEW_LAND:
|
||||
adapter = new NewlandAdapter(this, this);
|
||||
break;
|
||||
}
|
||||
if (null != adapter) {
|
||||
adapter.start();
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
public class NewlandAdapter implements Adapter {
|
||||
private Context context;
|
||||
private ResultListener resultListener;
|
||||
private Strategy strategy;
|
||||
|
||||
|
||||
public NewlandAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
}
|
||||
|
||||
@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("SCAN_BARCODE1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("nlscan.action.SCANNER_RESULT");
|
||||
filter.setPriority(2);
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user