1、支持连续扫码
2、支持横屏扫码(主要为了支持Pad)
This commit is contained in:
@@ -20,6 +20,7 @@ import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.king.zxing.CaptureActivity;
|
||||
@@ -30,6 +31,7 @@ import com.king.zxing.app.util.StatusBarUtils;
|
||||
*/
|
||||
public class CustomCaptureActivity extends CaptureActivity {
|
||||
|
||||
private boolean isContinuousScan;
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.custom_capture_activity;
|
||||
@@ -43,6 +45,8 @@ public class CustomCaptureActivity extends CaptureActivity {
|
||||
TextView tvTitle = findViewById(R.id.tvTitle);
|
||||
tvTitle.setText(getIntent().getStringExtra(MainActivity.KEY_TITLE));
|
||||
|
||||
isContinuousScan = getIntent().getBooleanExtra(MainActivity.KEY_IS_CONTINUOUS,false);
|
||||
|
||||
getBeepManager().setPlayBeep(true);
|
||||
getBeepManager().setVibrate(true);
|
||||
}
|
||||
@@ -76,6 +80,9 @@ public class CustomCaptureActivity extends CaptureActivity {
|
||||
@Override
|
||||
public void onResult(Result result) {
|
||||
super.onResult(result);
|
||||
if(isContinuousScan){//连续扫码时,直接弹出结果
|
||||
Toast.makeText(this,result.getText(),Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +91,7 @@ public class CustomCaptureActivity extends CaptureActivity {
|
||||
*/
|
||||
@Override
|
||||
public boolean isContinuousScan() {
|
||||
return super.isContinuousScan();
|
||||
return isContinuousScan;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,6 +46,7 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
|
||||
public static final String KEY_TITLE = "key_title";
|
||||
public static final String KEY_IS_QR_CODE = "key_code";
|
||||
public static final String KEY_IS_CONTINUOUS = "key_continuous_scan";
|
||||
|
||||
public static final int REQUEST_CODE_SCAN = 0X01;
|
||||
public static final int REQUEST_CODE_PHOTO = 0X02;
|
||||
@@ -56,6 +57,7 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
|
||||
private Class<?> cls;
|
||||
private String title;
|
||||
private boolean isContinuousScan;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -156,6 +158,7 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeCustomAnimation(this,R.anim.in,R.anim.out);
|
||||
Intent intent = new Intent(this, cls);
|
||||
intent.putExtra(KEY_TITLE,title);
|
||||
intent.putExtra(KEY_IS_CONTINUOUS,isContinuousScan);
|
||||
ActivityCompat.startActivityForResult(this,intent,REQUEST_CODE_SCAN,optionsCompat.toBundle());
|
||||
}
|
||||
|
||||
@@ -189,7 +192,14 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
}
|
||||
|
||||
public void OnClick(View v){
|
||||
isContinuousScan = false;
|
||||
switch (v.getId()){
|
||||
case R.id.btn0:
|
||||
this.cls = CustomCaptureActivity.class;
|
||||
this.title = ((Button)v).getText().toString();
|
||||
isContinuousScan = true;
|
||||
checkCameraPermissions();
|
||||
break;
|
||||
case R.id.btn1:
|
||||
this.cls = CaptureActivity.class;
|
||||
this.title = ((Button)v).getText().toString();
|
||||
|
||||
@@ -33,6 +33,19 @@
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@+id/toolbar"
|
||||
app:layout_constraintGuide_percent="0.2"/>
|
||||
<Button
|
||||
android:id="@+id/btn0"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="连续扫码"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/line"
|
||||
style="@style/OnClick"/>
|
||||
<Button
|
||||
android:id="@+id/btn1"
|
||||
android:layout_width="match_parent"
|
||||
@@ -44,7 +57,7 @@
|
||||
android:text="默认扫码"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/line"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn0"
|
||||
style="@style/OnClick"/>
|
||||
<Button
|
||||
android:id="@+id/btn2"
|
||||
|
||||
Reference in New Issue
Block a user