修改eclipse项目为as项目
This commit is contained in:
64
app/src/main/java/com/lianxin/nr510/Engine.java
Normal file
64
app/src/main/java/com/lianxin/nr510/Engine.java
Normal file
@ -0,0 +1,64 @@
|
||||
package com.lianxin.nr510;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class Engine {
|
||||
|
||||
private NR510Running runEngine = null;
|
||||
|
||||
public void start(Context context) {
|
||||
if (runEngine == null) {
|
||||
runEngine = new NR510Running(context);
|
||||
new Thread(runEngine).start();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(Context context) {
|
||||
if (runEngine != null) {
|
||||
Intent intent = new Intent("com.lachesis.barcode.STOP_BARCODE");
|
||||
context.sendBroadcast(intent);
|
||||
runEngine.closeRunning();
|
||||
runEngine = null;
|
||||
}
|
||||
}
|
||||
|
||||
private class NR510Running implements Runnable {
|
||||
|
||||
private boolean scanRunning = true;
|
||||
private Context context;
|
||||
|
||||
public NR510Running(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void closeRunning() {
|
||||
scanRunning = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
if (scanRunning) {
|
||||
Intent intent = new Intent("com.lachesis.barcode.START_BARCODE");
|
||||
context.sendBroadcast(intent);
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
intent = new Intent("com.lachesis.barcode.STOP_BARCODE");
|
||||
context.sendBroadcast(intent);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user