66 lines
1.7 KiB
Java
66 lines
1.7 KiB
Java
|
|
package chaoran.business.adapter;
|
||
|
|
|
||
|
|
/*
|
||
|
|
**********************************************
|
||
|
|
* DATE PERSON REASON
|
||
|
|
* 2021-02-03 FXY Created
|
||
|
|
**********************************************
|
||
|
|
*/
|
||
|
|
|
||
|
|
import android.content.BroadcastReceiver;
|
||
|
|
import android.content.Context;
|
||
|
|
import android.content.Intent;
|
||
|
|
import android.content.IntentFilter;
|
||
|
|
import android.media.AudioManager;
|
||
|
|
import android.media.SoundPool;
|
||
|
|
import android.os.Vibrator;
|
||
|
|
import chaoran.business.R;
|
||
|
|
import chaoran.business.activity.ResultListener;
|
||
|
|
import chaoran.business.strategy.Strategy;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 阿尔卑斯适配器
|
||
|
|
* CR-5W适用
|
||
|
|
*/
|
||
|
|
public class AlpsAdapter implements Adapter {
|
||
|
|
private Context context;
|
||
|
|
private Strategy strategy;
|
||
|
|
private ResultListener resultListener;
|
||
|
|
|
||
|
|
public AlpsAdapter(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("BARCODE"));
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void executeStrategy(ResultListener resultListener) {
|
||
|
|
IntentFilter filter = new IntentFilter();
|
||
|
|
filter.addAction("com.barcode.sendBroadcast");
|
||
|
|
context.registerReceiver(this, filter);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void exclusiveStrategy() {
|
||
|
|
context.unregisterReceiver(this);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|