更新CameraX至v1.2.1
This commit is contained in:
@@ -44,7 +44,7 @@
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
|
||||
<activity
|
||||
android:name=".CustomActivity"
|
||||
android:name=".CustomFullScanActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.king.zxing.CameraScan;
|
||||
import com.king.zxing.config.CameraConfig;
|
||||
import com.king.zxing.CaptureActivity;
|
||||
import com.king.zxing.DecodeConfig;
|
||||
import com.king.zxing.DecodeFormatManager;
|
||||
@@ -121,8 +120,8 @@ public class CustomCaptureActivity extends CaptureActivity {
|
||||
if(toast == null){
|
||||
toast = Toast.makeText(this,text,Toast.LENGTH_SHORT);
|
||||
}else{
|
||||
toast.setDuration(Toast.LENGTH_SHORT);
|
||||
toast.setText(text);
|
||||
toast.setDuration(Toast.LENGTH_SHORT);
|
||||
}
|
||||
toast.show();
|
||||
}
|
||||
|
||||
@@ -8,9 +8,13 @@ import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.king.zxing.CameraScan;
|
||||
import com.king.zxing.DecodeConfig;
|
||||
import com.king.zxing.DecodeFormatManager;
|
||||
import com.king.zxing.DefaultCameraScan;
|
||||
import com.king.zxing.ViewfinderView;
|
||||
import com.king.zxing.analyze.MultiFormatAnalyzer;
|
||||
import com.king.zxing.app.util.StatusBarUtils;
|
||||
import com.king.zxing.config.ResolutionCameraConfig;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
@@ -22,7 +26,7 @@ import androidx.fragment.app.Fragment;
|
||||
* 自定义扫码,切记自定义扫码需在{@link Activity}或者{@link Fragment}相对应的生命周期里面调用{@link #mCameraScan}对应的生命周期
|
||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public class CustomActivity extends AppCompatActivity implements CameraScan.OnScanResultCallback {
|
||||
public class CustomFullScanActivity extends AppCompatActivity implements CameraScan.OnScanResultCallback {
|
||||
|
||||
private boolean isContinuousScan;
|
||||
|
||||
@@ -59,9 +63,16 @@ public class CustomActivity extends AppCompatActivity implements CameraScan.OnSc
|
||||
|
||||
isContinuousScan = getIntent().getBooleanExtra(MainActivity.KEY_IS_CONTINUOUS,false);
|
||||
|
||||
//初始化解码配置
|
||||
DecodeConfig decodeConfig = new DecodeConfig();
|
||||
decodeConfig.setHints(DecodeFormatManager.QR_CODE_HINTS)//如果只有识别二维码的需求,这样设置效率会更高,不设置默认为DecodeFormatManager.DEFAULT_HINTS
|
||||
.setFullAreaScan(true);//设置是否全区域识别,默认false
|
||||
|
||||
mCameraScan = new DefaultCameraScan(this,previewView);
|
||||
mCameraScan.setOnScanResultCallback(this)
|
||||
.setAnalyzer(new MultiFormatAnalyzer(decodeConfig))
|
||||
.setVibrate(true)
|
||||
.setCameraConfig(new ResolutionCameraConfig(this, ResolutionCameraConfig.IMAGE_QUALITY_720P))
|
||||
.startCamera();
|
||||
|
||||
}
|
||||
@@ -31,7 +31,6 @@ import com.king.zxing.util.CodeUtils;
|
||||
import com.king.zxing.util.LogUtils;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@@ -43,9 +42,9 @@ import pub.devrel.easypermissions.EasyPermissions;
|
||||
/**
|
||||
* 扫码Demo示例说明
|
||||
*
|
||||
* 快速实现扫码有以下几种方式:
|
||||
* 快速实现扫码识别有以下几种方式:
|
||||
*
|
||||
* 1、直接使用CaptureActivity或者CaptureFragment。(纯洁的扫码,无任何添加剂)
|
||||
* 1、直接使用CaptureActivity或者CaptureFragment。(默认的扫码实现)
|
||||
*
|
||||
* 2、通过继承CaptureActivity或者CaptureFragment并自定义布局。(适用于大多场景,并无需关心扫码相关逻辑,自定义布局时需覆写getLayoutId方法)
|
||||
*
|
||||
@@ -108,13 +107,6 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
}
|
||||
|
||||
private void parsePhoto(Intent data){
|
||||
|
||||
// final String path = UriUtils.getImagePath(this,data);
|
||||
// LogUtils.d("path:" + path);
|
||||
// if(TextUtils.isEmpty(path)){
|
||||
// return;
|
||||
// }
|
||||
|
||||
try {
|
||||
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),data.getData());
|
||||
//异步解析
|
||||
@@ -243,7 +235,7 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
checkCameraPermissions();
|
||||
break;
|
||||
case R.id.btn4:
|
||||
this.cls = CustomActivity.class;
|
||||
this.cls = CustomFullScanActivity.class;
|
||||
this.title = ((Button)v).getText().toString();
|
||||
checkCameraPermissions();
|
||||
break;
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.king.zxing.DecodeConfig;
|
||||
import com.king.zxing.DecodeFormatManager;
|
||||
import com.king.zxing.analyze.MultiFormatAnalyzer;
|
||||
import com.king.zxing.app.util.StatusBarUtils;
|
||||
import com.king.zxing.config.AspectRatioCameraConfig;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
@@ -50,8 +51,8 @@ public class QRCodeActivity extends CaptureActivity {
|
||||
|
||||
//在启动预览之前,设置分析器,只识别二维码
|
||||
getCameraScan()
|
||||
.setCameraConfig(new AspectRatioCameraConfig(this))//设置相机配置,使用 AspectRatioCameraConfig
|
||||
.setVibrate(true)//设置是否震动,默认为false
|
||||
.setNeedAutoZoom(true)//二维码太小时可自动缩放,默认为false
|
||||
.setAnalyzer(new MultiFormatAnalyzer(decodeConfig));//设置分析器,如果内置实现的一些分析器不满足您的需求,你也可以自定义去实现
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB |
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_selected="true" android:drawable="@drawable/flash_on"/>
|
||||
<item android:state_selected="false" android:drawable="@drawable/flash_off"/>
|
||||
</selector>
|
||||
@@ -87,7 +87,7 @@
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="自定义扫码"
|
||||
android:text="自定义全屏扫二维码"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btn3"
|
||||
|
||||
@@ -13,24 +13,16 @@
|
||||
android:id="@+id/viewfinderView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:labelTextWidth="180dp"
|
||||
app:labelText="@string/tips_scan_code"
|
||||
app:labelTextSize="@dimen/size_14sp"
|
||||
app:laserColor="@color/colorAccent"
|
||||
app:frameColor="@color/colorPrimary"
|
||||
app:cornerColor="@color/colorPrimary"
|
||||
app:labelTextLocation="bottom"
|
||||
app:laserStyle="grid"
|
||||
app:gridHeight="0dp"/>
|
||||
app:viewfinderStyle="popular"/>
|
||||
<ImageView
|
||||
android:id="@+id/ivFlash"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/flash_selected_selector"
|
||||
android:src="@drawable/zxl_flashlight_selector"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginTop="160dp" />
|
||||
android:layout_marginTop="170dp" />
|
||||
<include layout="@layout/toolbar_capture"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -24,11 +24,11 @@
|
||||
android:id="@+id/ivFlashlight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/flash_selected_selector"
|
||||
android:src="@drawable/zxl_flashlight_selector"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginTop="160dp" />
|
||||
android:layout_marginTop="170dp" />
|
||||
<include layout="@layout/toolbar_capture"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -24,11 +24,11 @@
|
||||
android:id="@+id/ivFlashlight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/flash_selected_selector"
|
||||
android:src="@drawable/zxl_flashlight_selector"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginTop="160dp" />
|
||||
android:layout_marginTop="170dp" />
|
||||
<include layout="@layout/toolbar_capture"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="status_bar_height">25dp</dimen>
|
||||
</resources>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="status_bar_height">0dp</dimen>
|
||||
<dimen name="status_bar_height">25dp</dimen>
|
||||
|
||||
<dimen name="title_height">50dp</dimen>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user