优化细节
This commit is contained in:
@@ -8,6 +8,7 @@ import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.king.zxing.CaptureHelper;
|
||||
import com.king.zxing.OnCaptureCallback;
|
||||
import com.king.zxing.ViewfinderView;
|
||||
@@ -34,6 +35,7 @@ public class CustomActivity extends AppCompatActivity implements OnCaptureCallba
|
||||
|
||||
private View ivTorch;
|
||||
|
||||
private Toast toast;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
@@ -100,13 +102,23 @@ public class CustomActivity extends AppCompatActivity implements OnCaptureCallba
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onResultCallback(String result) {
|
||||
public boolean onResultCallback(Result result) {
|
||||
if(isContinuousScan){
|
||||
Toast.makeText(this,result,Toast.LENGTH_SHORT).show();
|
||||
showToast(result.getText());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void showToast(String text){
|
||||
if(toast == null){
|
||||
toast = Toast.makeText(this,text,Toast.LENGTH_SHORT);
|
||||
}else{
|
||||
toast.setDuration(Toast.LENGTH_SHORT);
|
||||
toast.setText(text);
|
||||
}
|
||||
toast.show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onClick(View v){
|
||||
|
||||
@@ -20,9 +20,10 @@ import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.king.zxing.CaptureActivity;
|
||||
import com.king.zxing.app.util.StatusBarUtils;
|
||||
import com.king.zxing.camera.FrontLightMode;
|
||||
|
||||
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
@@ -33,6 +34,9 @@ import androidx.appcompat.widget.Toolbar;
|
||||
public class CustomCaptureActivity extends CaptureActivity {
|
||||
|
||||
private boolean isContinuousScan;
|
||||
|
||||
private Toast toast;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.custom_capture_activity;
|
||||
@@ -51,12 +55,12 @@ public class CustomCaptureActivity extends CaptureActivity {
|
||||
//获取CaptureHelper,里面有扫码相关的配置设置
|
||||
getCaptureHelper().playBeep(false)//播放音效
|
||||
.vibrate(true)//震动
|
||||
.fullScreenScan(true)
|
||||
.supportVerticalCode(true)//支持扫垂直条码,建议有此需求时才使用。
|
||||
// .decodeFormats(DecodeFormatManager.QR_CODE_FORMATS)//设置只识别二维码会提升速度
|
||||
// .framingRectRatio(0.9f)//设置识别区域比例,范围建议在0.625 ~ 1.0之间。非全屏识别时才有效
|
||||
// .framingRectVerticalOffset(0)//设置识别区域垂直方向偏移量,非全屏识别时才有效
|
||||
// .framingRectHorizontalOffset(0)//设置识别区域水平方向偏移量,非全屏识别时才有效
|
||||
.frontLightMode(FrontLightMode.AUTO)//设置闪光灯模式
|
||||
.tooDarkLux(45f)//设置光线太暗时,自动触发开启闪光灯的照度值
|
||||
.brightEnoughLux(100f)//设置光线足够明亮时,自动触发关闭闪光灯的照度值
|
||||
.continuousScan(isContinuousScan)//是否连扫
|
||||
@@ -70,14 +74,24 @@ public class CustomCaptureActivity extends CaptureActivity {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onResultCallback(String result) {
|
||||
public boolean onResultCallback(Result result) {
|
||||
if(isContinuousScan){//连续扫码时,直接弹出结果
|
||||
Toast.makeText(this,result,Toast.LENGTH_SHORT).show();
|
||||
showToast(result.getText());
|
||||
}
|
||||
|
||||
return super.onResultCallback(result);
|
||||
}
|
||||
|
||||
private void showToast(String text){
|
||||
if(toast == null){
|
||||
toast = Toast.makeText(this,text,Toast.LENGTH_SHORT);
|
||||
}else{
|
||||
toast.setDuration(Toast.LENGTH_SHORT);
|
||||
toast.setText(text);
|
||||
}
|
||||
toast.show();
|
||||
}
|
||||
|
||||
public void onClick(View v){
|
||||
switch (v.getId()){
|
||||
case R.id.ivLeft:
|
||||
|
||||
@@ -31,6 +31,8 @@ import com.king.zxing.Intents;
|
||||
import com.king.zxing.app.util.UriUtils;
|
||||
import com.king.zxing.util.CodeUtils;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@@ -70,6 +72,8 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
private String title;
|
||||
private boolean isContinuousScan;
|
||||
|
||||
private Toast toast;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -83,7 +87,7 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
switch (requestCode){
|
||||
case REQUEST_CODE_SCAN:
|
||||
String result = data.getStringExtra(Intents.Scan.RESULT);
|
||||
Toast.makeText(this,result,Toast.LENGTH_SHORT).show();
|
||||
showToast(result);
|
||||
break;
|
||||
case REQUEST_CODE_PHOTO:
|
||||
parsePhoto(data);
|
||||
@@ -93,6 +97,16 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
}
|
||||
}
|
||||
|
||||
private void showToast(String text){
|
||||
if(toast == null){
|
||||
toast = Toast.makeText(this,text,Toast.LENGTH_SHORT);
|
||||
}else{
|
||||
toast.setDuration(Toast.LENGTH_SHORT);
|
||||
toast.setText(text);
|
||||
}
|
||||
toast.show();
|
||||
}
|
||||
|
||||
private void parsePhoto(Intent data){
|
||||
final String path = UriUtils.getImagePath(this,data);
|
||||
Log.d("Jenly","path:" + path);
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
app:cornerColor="@color/colorPrimary"
|
||||
app:resultPointColor="@color/colorAccent"
|
||||
app:labelTextLocation="bottom"
|
||||
app:laserStyle="grid"/>
|
||||
app:laserStyle="grid"
|
||||
app:showResultPoint="true"/>
|
||||
<ImageView
|
||||
android:id="@+id/ivTorch"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user