更新CameraX至v1.1.0-rc01
This commit is contained in:
@@ -2,13 +2,9 @@
|
||||
package="com.king.zxing">
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
<uses-permission android:name="android.permission.FLASHLIGHT"/>
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application>
|
||||
|
||||
</application>
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.google.zxing.Result;
|
||||
import com.king.zxing.util.LogUtils;
|
||||
import com.king.zxing.util.PermissionUtils;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@@ -45,9 +44,8 @@ public class CaptureActivity extends AppCompatActivity implements CameraScan.OnS
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
int layoutId = getLayoutId();
|
||||
if(isContentView(layoutId)){
|
||||
setContentView(layoutId);
|
||||
if(isContentView()){
|
||||
setContentView(getLayoutId());
|
||||
}
|
||||
initUI();
|
||||
}
|
||||
@@ -154,10 +152,9 @@ public class CaptureActivity extends AppCompatActivity implements CameraScan.OnS
|
||||
|
||||
/**
|
||||
* 返回true时会自动初始化{@link #setContentView(int)},返回为false是需自己去初始化{@link #setContentView(int)}
|
||||
* @param layoutId
|
||||
* @return 默认返回true
|
||||
*/
|
||||
public boolean isContentView(@LayoutRes int layoutId){
|
||||
public boolean isContentView(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.google.zxing.Result;
|
||||
import com.king.zxing.util.LogUtils;
|
||||
import com.king.zxing.util.PermissionUtils;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.camera.view.PreviewView;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -57,8 +56,7 @@ public class CaptureFragment extends Fragment implements CameraScan.OnScanResult
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
int layoutId = getLayoutId();
|
||||
if(isContentView(layoutId)){
|
||||
if(isContentView()){
|
||||
mRootView = createRootView(inflater,container);
|
||||
}
|
||||
initUI();
|
||||
@@ -165,10 +163,9 @@ public class CaptureFragment extends Fragment implements CameraScan.OnScanResult
|
||||
|
||||
/**
|
||||
* 返回true时会自动初始化{@link #createRootView(LayoutInflater, ViewGroup)},返回为false是需自己去初始化{@link #createRootView(LayoutInflater, ViewGroup)}
|
||||
* @param layoutId
|
||||
* @return 默认返回true
|
||||
*/
|
||||
public boolean isContentView(@LayoutRes int layoutId){
|
||||
public boolean isContentView(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.king.zxing;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ScaleGestureDetector;
|
||||
@@ -241,6 +242,7 @@ public class DefaultCameraScan extends CameraScan {
|
||||
|
||||
//图像分析
|
||||
ImageAnalysis imageAnalysis = mCameraConfig.options(new ImageAnalysis.Builder()
|
||||
.setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888)
|
||||
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST));
|
||||
imageAnalysis.setAnalyzer(Executors.newSingleThreadExecutor(), image -> {
|
||||
if(isAnalyze && !isAnalyzeResult && mAnalyzer != null){
|
||||
@@ -433,7 +435,7 @@ public class DefaultCameraScan extends CameraScan {
|
||||
if(mCamera != null){
|
||||
return mCamera.getCameraInfo().hasFlashUnit();
|
||||
}
|
||||
return false;
|
||||
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,8 +47,9 @@ public abstract class ImageAnalyzer implements Analyzer {
|
||||
return analyze(rotatedData,height,width);
|
||||
}
|
||||
return analyze(data,width,height);
|
||||
}else{
|
||||
LogUtils.w("imageFormat: " + image.getFormat());
|
||||
}
|
||||
LogUtils.w("imageFormat: " + image.getFormat());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,15 @@ import android.content.Context;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Build;
|
||||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
|
||||
import com.king.zxing.R;
|
||||
import com.king.zxing.util.LogUtils;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.lang.annotation.ElementType;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
@@ -67,8 +70,12 @@ public final class BeepManager implements MediaPlayer.OnErrorListener, Closeable
|
||||
if (playBeep && mediaPlayer != null) {
|
||||
mediaPlayer.start();
|
||||
}
|
||||
if (vibrate) {
|
||||
vibrator.vibrate(VIBRATE_DURATION);
|
||||
if (vibrate && vibrator.hasVibrator()) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
vibrator.vibrate(VibrationEffect.createOneShot(VIBRATE_DURATION, VibrationEffect.DEFAULT_AMPLITUDE));
|
||||
} else {
|
||||
vibrator.vibrate(VIBRATE_DURATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user