diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..61a9130
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index d84fb97..a2d6f5e 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -16,6 +16,7 @@
+
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index eb2873e..936e1c8 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -26,5 +26,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index ffa0f59..6076773 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -44,7 +44,7 @@
-
+
diff --git a/app/build.gradle b/app/build.gradle
index caa056b..a35c13c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -16,9 +16,9 @@ android {
defaultConfig {
applicationId "com.android.NBZxing"
minSdkVersion 17
- targetSdkVersion 29
- versionCode 15
- versionName "1.15"
+ targetSdkVersion 27
+ versionCode 17
+ versionName "1.21"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.release
compileOptions {
@@ -46,6 +46,7 @@ dependencies {
api "androidx.appcompat:appcompat:1.1.0"
implementation 'com.zhihu.android:matisse:0.5.3-beta3'
api "com.github.bumptech.glide:glide:4.11.0"
+ api 'com.tencent.bugly:crashreport:3.2.3'
//
// implementation 'com.github.ailiwean:NBZxing-Scale:0.0.3'
// implementation 'com.github.ailiwean:NBZxing:0.0.25'
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
index 57fb851..1ee2372 100644
--- a/app/proguard-rules.pro
+++ b/app/proguard-rules.pro
@@ -1 +1,3 @@
--keep public class com.ailiwean.module_grayscale.GrayScaleDispatch
\ No newline at end of file
+-keep public class com.ailiwean.module_grayscale.GrayScaleDispatch
+-dontwarn com.tencent.bugly.**
+-keep public class com.tencent.bugly.**{*;}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 87dcffb..ec54547 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,22 +5,36 @@
+
+
+
+
+
+
+
+
+
-
+
+
diff --git a/app/src/main/java/com/android/NBZxing/App.java b/app/src/main/java/com/android/NBZxing/App.java
new file mode 100644
index 0000000..428725e
--- /dev/null
+++ b/app/src/main/java/com/android/NBZxing/App.java
@@ -0,0 +1,22 @@
+package com.android.NBZxing;
+
+import android.app.Application;
+
+import com.tencent.bugly.crashreport.CrashReport;
+
+
+/**
+ * @Package: com.android.NBZxing
+ * @ClassName: App
+ * @Description:
+ * @Author: SWY
+ * @CreateDate: 2020/10/1 9:22 PM
+ */
+public class App extends Application {
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ CrashReport.initCrashReport(getApplicationContext(), "99de934384", true);
+ }
+}
diff --git a/app/src/main/java/com/android/NBZxing/CusScanView.kt b/app/src/main/java/com/android/NBZxing/CusScanView.kt
index e3615a1..08ec9b0 100644
--- a/app/src/main/java/com/android/NBZxing/CusScanView.kt
+++ b/app/src/main/java/com/android/NBZxing/CusScanView.kt
@@ -17,10 +17,6 @@ import com.google.android.cameraview.AspectRatio
*/
class CusScanView @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, def: Int = 0) : NBZxingView(context, attributeSet, def) {
- init {
- setAspectRatio(AspectRatio.of(16, 9))
- }
-
override fun resultBack(content: String) {
Toast.makeText(context, content, Toast.LENGTH_SHORT).show()
}
diff --git a/app/src/main/java/com/android/NBZxing/MainActiviy.kt b/app/src/main/java/com/android/NBZxing/MainActiviy.kt
new file mode 100644
index 0000000..f7f06a5
--- /dev/null
+++ b/app/src/main/java/com/android/NBZxing/MainActiviy.kt
@@ -0,0 +1,25 @@
+package com.android.NBZxing
+
+import android.os.Bundle
+import android.view.View
+import androidx.appcompat.app.AppCompatActivity
+
+/**
+ * @Package: com.android.NBZxing
+ * @ClassName: MainActiviy
+ * @Description:
+ * @Author: SWY
+ * @CreateDate: 2020/10/18 7:26 PM
+ */
+class MainActiviy : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_select)
+ }
+
+ fun toClick(view: View) {
+ ScanActivity.startSelf(this)
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/android/NBZxing/MainActivity.kt b/app/src/main/java/com/android/NBZxing/ScanActivity.kt
similarity index 81%
rename from app/src/main/java/com/android/NBZxing/MainActivity.kt
rename to app/src/main/java/com/android/NBZxing/ScanActivity.kt
index 559cb40..5bc9bd1 100644
--- a/app/src/main/java/com/android/NBZxing/MainActivity.kt
+++ b/app/src/main/java/com/android/NBZxing/ScanActivity.kt
@@ -2,6 +2,7 @@ package com.android.NBZxing
import android.Manifest
import android.app.Activity
+import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.pm.PackageManager
@@ -9,15 +10,25 @@ import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
+import android.view.Window
+import android.view.WindowManager
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.zhihu.matisse.Matisse
import com.zhihu.matisse.MimeType
import com.zhihu.matisse.engine.impl.GlideEngine
-class MainActivity : AppCompatActivity() {
+class ScanActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+
+// requestWindowFeature(Window.FEATURE_NO_TITLE)
+// window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
+// WindowManager.LayoutParams.FLAG_FULLSCREEN);
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+// window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
+// WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
+// }
setContentView(R.layout.activity_main)
findViewById(R.id.zxingview)
.synchLifeStart(this)
@@ -28,10 +39,13 @@ class MainActivity : AppCompatActivity() {
// .commit();
}
- fun initView() {
+ companion object {
+ fun startSelf(context: Context) {
+ context.startActivity(Intent(context, ScanActivity::class.java))
+ }
+ }
- findViewById(R.id.vToolBar)
- .setBackgroundColor(Color.parseColor("#2f000000"))
+ fun initView() {
findViewById(R.id.vTitle).text = "扫一扫"
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 369b4f9..f55c41e 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -12,5 +12,4 @@
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_select.xml b/app/src/main/res/layout/activity_select.xml
new file mode 100644
index 0000000..de234d3
--- /dev/null
+++ b/app/src/main/res/layout/activity_select.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/tool_title.xml b/app/src/main/res/layout/tool_title.xml
index aa47dab..8c400dc 100644
--- a/app/src/main/res/layout/tool_title.xml
+++ b/app/src/main/res/layout/tool_title.xml
@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/vToolBar"
android:layout_width="match_parent"
- android:layout_height="match_parent"
+ android:layout_height="wrap_content"
android:layout_gravity="top"
tools:ignore="ResourceName">
diff --git a/build.gradle b/build.gradle
index 99ef93c..5dc0b1f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -23,6 +23,7 @@ allprojects {
google()
jcenter()
maven { url 'https://jitpack.io' }
+ maven { url "https://raw.githubusercontent.com/Pgyer/mvn_repo_pgyer/master" }
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 5f394b8..67c79b4 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,10 +1,6 @@
#Thu Apr 30 15:56:24 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-<<<<<<< HEAD
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip
-=======
->>>>>>> backTexture
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
diff --git a/module_camera/src/main/api14/com/google/android/cameraview/TextureViewPreview.java b/module_camera/src/main/api14/com/google/android/cameraview/TextureViewPreview.java
index 998fd70..a75632c 100644
--- a/module_camera/src/main/api14/com/google/android/cameraview/TextureViewPreview.java
+++ b/module_camera/src/main/api14/com/google/android/cameraview/TextureViewPreview.java
@@ -115,8 +115,9 @@ boolean isReady() {
void configureTransform() {
Matrix matrix = new Matrix();
- if (Utils.getContext().getResources().getConfiguration().orientation ==
- Configuration.ORIENTATION_LANDSCAPE && mDisplayOrientation == 0)
+ if (Utils.INSTANCE.getContext() != null &&
+ Utils.INSTANCE.getContext().getResources().getConfiguration().orientation ==
+ Configuration.ORIENTATION_LANDSCAPE && mDisplayOrientation == 0)
mDisplayOrientation = Config.displayOrientation;
if (mDisplayOrientation % 180 == 90) {
diff --git a/module_camera/src/main/api21/com/google/android/cameraview/Camera2.java b/module_camera/src/main/api21/com/google/android/cameraview/Camera2.java
index bc91df7..15a5331 100644
--- a/module_camera/src/main/api21/com/google/android/cameraview/Camera2.java
+++ b/module_camera/src/main/api21/com/google/android/cameraview/Camera2.java
@@ -96,14 +96,12 @@ public void onDisconnected(@NonNull CameraDevice camera) {
@Override
public void onError(@NonNull CameraDevice camera, int error) {
- restart();
mCamera = null;
+ restart();
}
};
- boolean isTrue;
-
private final CameraCaptureSession.StateCallback mSessionCallback
= new CameraCaptureSession.StateCallback() {
@@ -217,7 +215,6 @@ public void updatePreView(PreviewImpl preview) {
@Override
boolean start() {
synchronized (Camera2.class) {
-
if (isCameraOpened())
return true;
@@ -391,7 +388,6 @@ void setZoom(float percent) {
try {
Rect showRect = CameraHelper.getZoomRect(mCameraCharacteristics, percent);
mPreviewRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, showRect);
- mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, null);
rectMeteringWithFocus(showRect);
} catch (Exception e) {
restart();
@@ -500,7 +496,7 @@ private boolean collectCameraInfo() {
}
if (!mPreviewSizes.ratios().contains(mAspectRatio)) {
- //扫码没有16:9则取4:3
+ //扫码没有设置的则取4:3
mAspectRatio = Constants.DEFAULT_ASPECT_RATIO;
//没有4:3则取最接近的
if (!mPreviewSizes.ratios().contains(mAspectRatio)) {
diff --git a/module_camera/src/main/base/com/google/android/cameraview/PreviewImpl.java b/module_camera/src/main/base/com/google/android/cameraview/PreviewImpl.java
index 627d836..e20352e 100644
--- a/module_camera/src/main/base/com/google/android/cameraview/PreviewImpl.java
+++ b/module_camera/src/main/base/com/google/android/cameraview/PreviewImpl.java
@@ -35,9 +35,9 @@ interface Callback {
private Callback mCallback;
- private int mWidth;
+ private volatile int mWidth;
- private int mHeight;
+ private volatile int mHeight;
void setCallback(Callback callback) {
mCallback = callback;
@@ -86,7 +86,11 @@ void setSize(int width, int height) {
getView().setTranslationX((float) -(width - v.getMeasuredWidth()) / 2);
if (height > v.getMeasuredHeight())
getView().setTranslationY((float) -(height - v.getMeasuredHeight()) / 2);
- cameraHandler.getLooper().getThread().interrupt();
+
+ if (cameraHandler != null &&
+ cameraHandler.getLooper().getThread().getState() == Thread.State.TIMED_WAITING)
+ cameraHandler.getLooper().getThread().interrupt();
+
}
int getWidth() {
@@ -98,10 +102,12 @@ int getHeight() {
}
/***
- * 当相机测量出的不支持设定的, 则提供一个支持的参数
+ * 同步比例
* @param aspectRatio
*/
public void updateAspectRatio(AspectRatio aspectRatio) {
+ mWidth = 0;
+ mHeight = 0;
if (getView().getParent() instanceof CameraView) {
((CameraView) getView().getParent()).setAspectRatio(aspectRatio);
}
diff --git a/module_camera/src/main/java/com/ailiwean/core/Utils.java b/module_camera/src/main/java/com/ailiwean/core/Utils.java
deleted file mode 100644
index 4086e15..0000000
--- a/module_camera/src/main/java/com/ailiwean/core/Utils.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.ailiwean.core;
-
-import android.content.Context;
-import android.util.TypedValue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.lang.ref.WeakReference;
-
-/**
- * @Package: com.ailiwean.core
- * @ClassName: Uitls
- * @Description:
- * @Author: SWY
- * @CreateDate: 2020/4/26 11:10 AM
- */
-public class Utils {
-
- static WeakReference holder;
-
- public static void init(Context mContext) {
- holder = new WeakReference<>(mContext);
- }
-
- public static Context getContext() {
- return holder.get();
- }
-
- public static int dp2px(float dpValue) {
- return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, Utils.getContext().getResources().getDisplayMetrics());
- }
-
- public static byte[] readFile(String fileName) {
- int len;
- FileInputStream stream;
- ByteArrayOutputStream stream2 = null;
- try {
- stream = new FileInputStream(fileName);
- stream2 = new ByteArrayOutputStream();
- byte[] buffer = new byte[5];
- //先读后写,循环读写
- while ((len = stream.read(buffer)) != -1) {
- stream2.write(buffer, 0, len);
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (stream2 != null)
- return stream2.toByteArray();
- return null;
- }
-
-}
diff --git a/module_camera/src/main/java/com/ailiwean/core/Utils.kt b/module_camera/src/main/java/com/ailiwean/core/Utils.kt
new file mode 100644
index 0000000..6a8cfbe
--- /dev/null
+++ b/module_camera/src/main/java/com/ailiwean/core/Utils.kt
@@ -0,0 +1,114 @@
+package com.ailiwean.core
+
+import android.Manifest
+import android.app.Activity
+import android.content.ContentUris
+import android.content.Context
+import android.content.pm.PackageManager
+import android.database.Cursor
+import android.net.Uri
+import android.os.Build
+import android.provider.MediaStore
+import android.util.TypedValue
+import androidx.core.app.ActivityCompat.requestPermissions
+import java.io.ByteArrayOutputStream
+import java.io.FileInputStream
+import java.io.FileNotFoundException
+import java.io.IOException
+import java.lang.ref.WeakReference
+
+/**
+ * @Package: com.ailiwean.core
+ * @ClassName: Utils
+ * @Description:
+ * @Author: SWY
+ * @CreateDate: 2020/10/10 2:18 PM
+ */
+object Utils {
+
+ var holder: WeakReference? = null
+
+ fun init(mContext: Context) {
+ holder = WeakReference(mContext)
+ }
+
+ fun getContext(): Context? {
+ return holder!!.get()
+ }
+
+ fun dp2px(dpValue: Float): Int {
+ return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, getContext()?.resources?.displayMetrics).toInt()
+ }
+
+ fun readFile(fileName: String?): ByteArray? {
+ var len: Int
+ val stream: FileInputStream
+ var stream2: ByteArrayOutputStream? = null
+ try {
+ stream = FileInputStream(fileName)
+ stream2 = ByteArrayOutputStream()
+ val buffer = ByteArray(5)
+ //先读后写,循环读写
+ while (stream.read(buffer).also { len = it } != -1) {
+ stream2.write(buffer, 0, len)
+ }
+ } catch (e: FileNotFoundException) {
+ e.printStackTrace()
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ return stream2?.toByteArray()
+ }
+
+
+ fun checkPermissionRW(context: Context): Boolean {
+ return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ context.checkSelfPermission(
+ Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
+
+ context.checkSelfPermission(
+ Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
+
+ } else {
+ return true
+ }
+ }
+
+ fun requstPermission(context: Context) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ (context as? Activity)?.requestPermissions(arrayOf(Manifest.permission.CAMERA,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE,
+ Manifest.permission.READ_EXTERNAL_STORAGE
+ ), 200)
+ }
+ }
+
+ fun checkPermissionCamera(context: Context): Boolean {
+ return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ context.checkSelfPermission(
+ Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED
+ } else {
+ return true
+ }
+ }
+
+ /***
+ * path转Uri兼容Android10
+ */
+ fun getMediaUriFromPath(context: Context, path: String): Uri {
+ val mediaUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
+ val cursor: Cursor? = context.contentResolver.query(mediaUri,
+ null,
+ MediaStore.Images.Media.DISPLAY_NAME + "= ?", arrayOf(path.substring(path.lastIndexOf("/") + 1)),
+ null)
+ var uri: Uri? = null
+ cursor?.let {
+ it.moveToFirst()
+ uri = ContentUris.withAppendedId(mediaUri,
+ it.getLong(it.getColumnIndex(MediaStore.Images.Media._ID)))
+ }
+ cursor?.close()
+ return uri ?: Uri.EMPTY
+ }
+
+}
\ No newline at end of file
diff --git a/module_camera/src/main/java/com/ailiwean/core/able/AbleManager.kt b/module_camera/src/main/java/com/ailiwean/core/able/AbleManager.kt
index 819e401..f595b82 100644
--- a/module_camera/src/main/java/com/ailiwean/core/able/AbleManager.kt
+++ b/module_camera/src/main/java/com/ailiwean/core/able/AbleManager.kt
@@ -7,6 +7,7 @@ import com.ailiwean.core.TypeRunnable
import com.ailiwean.core.WorkThreadServer
import com.ailiwean.core.helper.ScanHelper
import com.ailiwean.core.zxing.core.PlanarYUVLuminanceSource
+import com.ailiwean.module_grayscale.Dispatch
import com.ailiwean.module_grayscale.GrayScaleDispatch
import java.util.concurrent.CopyOnWriteArrayList
@@ -23,8 +24,7 @@ class AbleManager private constructor(handler: Handler) : PixsValuesAble(handler
private var server: WorkThreadServer = WorkThreadServer.createInstance()
- private var processClz: Class? = null
- private var processDispatch: GrayScaleDispatch? = null
+ private var processDispatch: Dispatch? = null
private val grayProcessHandler by lazy {
Handler(HandlerThread("GrayProcessThread")
@@ -35,8 +35,7 @@ class AbleManager private constructor(handler: Handler) : PixsValuesAble(handler
init {
loadAbility()
if (Config.hasDepencidesScale()) {
- processClz = Class.forName(Config.GARY_SCALE_PATH)
- processDispatch = processClz?.newInstance() as GrayScaleDispatch?
+ processDispatch = GrayScaleDispatch
}
}
@@ -62,7 +61,7 @@ class AbleManager private constructor(handler: Handler) : PixsValuesAble(handler
}
private fun grayscaleProcess(data: ByteArray, dataWidth: Int, dataHeight: Int) {
- if (processClz == null)
+ if (processDispatch == null)
return
grayProcessHandler.removeCallbacksAndMessages(null)
grayProcessHandler.post {
@@ -98,7 +97,7 @@ class AbleManager private constructor(handler: Handler) : PixsValuesAble(handler
}
ableList.clear()
server.quit()
- if (processClz == null)
+ if (processDispatch == null)
return
grayProcessHandler.removeCallbacksAndMessages(null)
grayProcessHandler.looper.quit()
diff --git a/module_camera/src/main/java/com/ailiwean/core/helper/ImgparseHelper.kt b/module_camera/src/main/java/com/ailiwean/core/helper/ImgparseHelper.kt
new file mode 100644
index 0000000..0eff52e
--- /dev/null
+++ b/module_camera/src/main/java/com/ailiwean/core/helper/ImgparseHelper.kt
@@ -0,0 +1,70 @@
+package com.ailiwean.core.helper
+
+import android.graphics.Bitmap
+import android.graphics.BitmapFactory
+import android.graphics.ImageDecoder
+import android.os.Build
+import com.ailiwean.core.Utils
+import com.ailiwean.core.zxing.BitmapLuminanceSource
+import com.ailiwean.core.zxing.CustomMultiFormatReader
+import com.ailiwean.core.zxing.core.BinaryBitmap
+import com.ailiwean.core.zxing.core.Result
+import com.ailiwean.core.zxing.core.common.HybridBinarizer
+import java.io.File
+
+/**
+ * @Package: com.ailiwean.core.helper
+ * @ClassName: ImgparseHelper
+ * @Description:
+ * @Author: SWY
+ * @CreateDate: 2020/10/10 2:15 PM
+ */
+object ImgparseHelper {
+
+ fun parseFile(filePath: String): Result? {
+
+ val file = File(filePath)
+ if (!file.exists())
+ return null
+
+ val bitmap: Bitmap = (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+ Utils.getContext()?.let { it ->
+ it.contentResolver.let { reso ->
+ ImageDecoder.createSource(reso, Utils.getMediaUriFromPath(it, filePath))
+ }.let {
+ ImageDecoder.decodeBitmap(it)
+ .copy(Bitmap.Config.RGB_565, false)
+ }
+ }
+ } else
+ BitmapFactory.decodeFile(filePath))
+ ?: return null
+
+ return parseBitmap(bitmap)
+ }
+
+ fun parseBitmap(bitmap: Bitmap?): Result? {
+
+ if (bitmap == null)
+ return null
+
+ bitmap.apply {
+ if (config != Bitmap.Config.RGB_565
+ && config != Bitmap.Config.ARGB_8888) {
+ if (isMutable)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ config = Bitmap.Config.RGB_565
+ } else {
+ copy(Bitmap.Config.RGB_565, false)
+ }
+ else
+ copy(Bitmap.Config.RGB_565, false)
+ }
+ val source = BitmapLuminanceSource(this)
+ return CustomMultiFormatReader.getInstance()
+ .decode(BinaryBitmap(HybridBinarizer(source)))
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/module_camera/src/main/java/com/ailiwean/core/helper/VibrateHelper.java b/module_camera/src/main/java/com/ailiwean/core/helper/VibrateHelper.java
index 7932f67..349a576 100644
--- a/module_camera/src/main/java/com/ailiwean/core/helper/VibrateHelper.java
+++ b/module_camera/src/main/java/com/ailiwean/core/helper/VibrateHelper.java
@@ -57,11 +57,12 @@ public static void playInit() {
*/
soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
}
- voiceId = soundPool.load(Utils.getContext(), R.raw.scan, 1);
+ voiceId = soundPool.load(Utils.INSTANCE.getContext(), R.raw.scan, 1);
}
public static void playVibrate() {
- RxVibrateTool.vibrateOnce(Utils.getContext(), VIBRATE_DURATION);
+ if (Utils.INSTANCE.getContext() != null)
+ RxVibrateTool.vibrateOnce(Utils.INSTANCE.getContext(), VIBRATE_DURATION);
}
/**
diff --git a/module_camera/src/main/java/com/ailiwean/core/view/FreeZxingView.kt b/module_camera/src/main/java/com/ailiwean/core/view/FreeZxingView.kt
index 3626ff3..96a2dba 100644
--- a/module_camera/src/main/java/com/ailiwean/core/view/FreeZxingView.kt
+++ b/module_camera/src/main/java/com/ailiwean/core/view/FreeZxingView.kt
@@ -1,34 +1,26 @@
package com.ailiwean.core.view
-import android.content.ContentUris
import android.content.Context
-import android.database.Cursor
import android.graphics.Bitmap
-import android.graphics.BitmapFactory
-import android.graphics.ImageDecoder
import android.graphics.PointF
-import android.net.Uri
-import android.os.*
-import android.provider.MediaStore
+import android.os.Handler
+import android.os.HandlerThread
+import android.os.Looper
+import android.os.Message
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import com.ailiwean.core.Config.*
import com.ailiwean.core.Result
import com.ailiwean.core.able.AbleManager
+import com.ailiwean.core.helper.ImgparseHelper
import com.ailiwean.core.helper.VibrateHelper
-import com.ailiwean.core.zxing.BitmapLuminanceSource
-import com.ailiwean.core.zxing.CustomMultiFormatReader
import com.ailiwean.core.zxing.ScanTypeConfig
-import com.ailiwean.core.zxing.core.BinaryBitmap
-import com.ailiwean.core.zxing.core.common.GlobalHistogramBinarizer
-import com.ailiwean.core.zxing.core.common.HybridBinarizer
import com.google.android.cameraview.AspectRatio
import com.google.android.cameraview.BaseCameraView
import com.google.android.cameraview.CameraView
import com.google.android.cameraview.R
import kotlinx.android.synthetic.*
-import java.io.File
import java.lang.ref.WeakReference
/**
@@ -51,9 +43,6 @@ abstract class FreeZxingView @JvmOverloads constructor(context: Context, attribu
//使用后置相机
facing = FACING_BACK
- //设定相机数据选取比例
- this.setAspectRatio(AspectRatio.of(16, 9))
-
//配置扫码类型
initScanType()
}
@@ -85,6 +74,11 @@ abstract class FreeZxingView @JvmOverloads constructor(context: Context, attribu
BusHandler(this, thread.looper)
}
+ //设定相机数据选取比例
+ override fun provideAspectRatio(): AspectRatio {
+ return AspectRatio.of(16, 9)
+ }
+
/***
* Handler结果回调
*/
@@ -209,6 +203,7 @@ abstract class FreeZxingView @JvmOverloads constructor(context: Context, attribu
}, {
lightOperator(false)
})
+ lightOperator(false)
//扫码条开始播放动画
scanBarView?.startScanAnimator()
//重新装填AbleManager
@@ -258,28 +253,15 @@ abstract class FreeZxingView @JvmOverloads constructor(context: Context, attribu
}
/***
- * File转Bitmap详见{@link #parseBitmap}
+ * File转Bitmap
*/
protected fun parseFile(filePath: String) {
proscribeCamera()
- if (!checkPermissionRW())
- return
-
- val file = File(filePath)
- if (!file.exists())
- return
-
busHandle.removeCallbacksAndMessages(null)
busHandle.post {
- val bitmap: Bitmap = (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
- ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, getMediaUriFromPath(context, filePath)))
- .copy(Bitmap.Config.RGB_565, false)
- } else
- BitmapFactory.decodeFile(filePath))
- ?: return@post
- parseBitmap(bitmap)
+ onParseResult(ImgparseHelper.parseFile(filePath))
}
}
@@ -291,64 +273,27 @@ abstract class FreeZxingView @JvmOverloads constructor(context: Context, attribu
proscribeCamera()
- if (bitmap == null)
- return
-
busHandle.removeCallbacksAndMessages(null)
busHandle.post {
- bitmap.apply {
- if (config != Bitmap.Config.RGB_565
- && config != Bitmap.Config.ARGB_8888) {
- if (isMutable)
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- config = Bitmap.Config.RGB_565
- } else {
- copy(Bitmap.Config.RGB_565, false)
- }
- else
- copy(Bitmap.Config.RGB_565, false)
- }
- val source = BitmapLuminanceSource(this)
- var result = CustomMultiFormatReader.getInstance()
- .decode(BinaryBitmap(GlobalHistogramBinarizer(source)))
- if (result == null)
- result = CustomMultiFormatReader.getInstance()
- .decode(BinaryBitmap(HybridBinarizer(source)))
- if (result != null) {
- mainHand.post {
- resultBackFile(result.text)
- scanSucHelper()
- }
- } else {
- mainHand.post {
- resultBackFile("")
- unProscibeCamera()
- }
- }
- }
+ onParseResult(ImgparseHelper.parseBitmap(bitmap))
}
}
- /***
- * path转Uri兼容Android10
- */
- private fun getMediaUriFromPath(context: Context, path: String): Uri {
- val mediaUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI
- val cursor: Cursor? = context.contentResolver.query(mediaUri,
- null,
- MediaStore.Images.Media.DISPLAY_NAME + "= ?", arrayOf(path.substring(path.lastIndexOf("/") + 1)),
- null)
- var uri: Uri? = null
- cursor?.let {
- it.moveToFirst()
- uri = ContentUris.withAppendedId(mediaUri,
- it.getLong(it.getColumnIndex(MediaStore.Images.Media._ID)))
+ private fun onParseResult(result: com.ailiwean.core.zxing.core.Result?) {
+
+ if (result != null) {
+ mainHand.post {
+ resultBackFile(result.text)
+ scanSucHelper()
+ }
+ } else {
+ mainHand.post {
+ resultBackFile("")
+ unProscibeCamera()
+ }
}
- cursor?.close()
- return uri ?: Uri.EMPTY
}
-
/***
* 提供扫码类型
*/
@@ -359,7 +304,6 @@ abstract class FreeZxingView @JvmOverloads constructor(context: Context, attribu
/***
* 业务Handler
*/
-
class BusHandler constructor(view: Callback, loop: Looper) : Handler(loop) {
var hasResult = false
var viewReference: WeakReference? = null
diff --git a/module_camera/src/main/java/com/ailiwean/core/view/ScanLightView.java b/module_camera/src/main/java/com/ailiwean/core/view/ScanLightView.java
index 47f4084..7f4dee2 100644
--- a/module_camera/src/main/java/com/ailiwean/core/view/ScanLightView.java
+++ b/module_camera/src/main/java/com/ailiwean/core/view/ScanLightView.java
@@ -46,6 +46,7 @@ private void initView() {
tv = v.findViewById(R.id.light_text);
addView(v);
setOnClickListener(v1 -> toggle());
+ setVisibility(View.GONE);
}
public void toggle() {
@@ -71,7 +72,6 @@ private void close() {
}
-
@Override
public void lightBrighter() {
setVisibility(View.VISIBLE);
diff --git a/module_camera/src/main/java/com/ailiwean/core/zxing/BitmapLuminanceSource.java b/module_camera/src/main/java/com/ailiwean/core/zxing/BitmapLuminanceSource.java
index 3e1e93c..4c8b289 100644
--- a/module_camera/src/main/java/com/ailiwean/core/zxing/BitmapLuminanceSource.java
+++ b/module_camera/src/main/java/com/ailiwean/core/zxing/BitmapLuminanceSource.java
@@ -8,19 +8,13 @@
/***
* Created by SWY
- * DATE 2019/6/3
- *
- * author Vondear
- * 定义解析Bitmap LuminanceSource
- *
*/
public class BitmapLuminanceSource extends LuminanceSource {
- private byte bitmapPixels[];
+ private byte[] bitmapPixels;
public BitmapLuminanceSource(Bitmap bitmap) {
super(bitmap.getWidth(), bitmap.getHeight());
- // 首先,要取得该图片的像素数组内容
int[] data = new int[bitmap.getWidth() * bitmap.getHeight()];
this.bitmapPixels = new byte[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getPixels(data, 0, getWidth(), 0, 0, getWidth(), getHeight());
diff --git a/module_camera/src/main/java/com/ailiwean/core/zxing/ScanRect.java b/module_camera/src/main/java/com/ailiwean/core/zxing/ScanRect.java
index 42d46b1..ae496ac 100644
--- a/module_camera/src/main/java/com/ailiwean/core/zxing/ScanRect.java
+++ b/module_camera/src/main/java/com/ailiwean/core/zxing/ScanRect.java
@@ -34,7 +34,7 @@ public class ScanRect {
* @param r
*/
public void setRect(RectF r) {
- //默认适配的是90度,也就是手机垂直方向拿着
+ //默认适配的是0度,也就是手机垂直方向拿着
//朝左倾斜90
if (Config.is90() && r != null) {
r = ScanHelper.adapter90(r);
diff --git a/module_camera/src/main/java/com/google/android/cameraview/BaseCameraView.kt b/module_camera/src/main/java/com/google/android/cameraview/BaseCameraView.kt
index f4b00cf..c9296d7 100644
--- a/module_camera/src/main/java/com/google/android/cameraview/BaseCameraView.kt
+++ b/module_camera/src/main/java/com/google/android/cameraview/BaseCameraView.kt
@@ -1,10 +1,6 @@
package com.google.android.cameraview
-import android.Manifest
-import android.app.Activity
import android.content.Context
-import android.content.pm.PackageManager
-import android.os.Build
import android.os.Handler
import android.os.HandlerThread
import android.util.AttributeSet
@@ -36,7 +32,6 @@ abstract class BaseCameraView @JvmOverloads constructor(context: Context, attrib
Utils.init(context)
autoFocus = true
adjustViewBounds = false
- this.setAspectRatio(AspectRatio.of(4, 3))
this.addCallback(object : Callback() {
var hasFloorView = false
@@ -118,6 +113,7 @@ abstract class BaseCameraView @JvmOverloads constructor(context: Context, attrib
}
if (isShoudCreateOpen) {
onCreate()
+ onResume()
onCameraCreate()
} else {
onResume()
@@ -153,11 +149,11 @@ abstract class BaseCameraView @JvmOverloads constructor(context: Context, attrib
private fun onCameraCreate() {
if (!isShoudCreateOpen)
return
- if (checkPermissionCamera()) {
+ if (Utils.checkPermissionCamera(context)) {
openCameraBefore()
openCamera()
} else {
- requstPermission()
+ Utils.requstPermission(context)
}
}
@@ -165,7 +161,7 @@ abstract class BaseCameraView @JvmOverloads constructor(context: Context, attrib
if (isShoudCreateOpen) {
return
}
- if (checkPermissionCamera() && !isCameraOpened) {
+ if (Utils.checkPermissionCamera(context) && !isCameraOpened) {
openCameraBefore()
openCamera()
}
@@ -244,37 +240,6 @@ abstract class BaseCameraView @JvmOverloads constructor(context: Context, attrib
cameraHandler.looper.quit()
}
- fun checkPermissionCamera(): Boolean {
- return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- context.checkSelfPermission(
- Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED
- } else {
- return true
- }
- }
-
- fun checkPermissionRW(): Boolean {
- return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- context.checkSelfPermission(
- Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
-
- context.checkSelfPermission(
- Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
-
- } else {
- return true
- }
- }
-
- fun requstPermission() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- (context as? Activity)?.requestPermissions(arrayOf(Manifest.permission.CAMERA,
- Manifest.permission.WRITE_EXTERNAL_STORAGE,
- Manifest.permission.READ_EXTERNAL_STORAGE
- ), 200)
- }
- }
-
/***
* 禁止相机启用
*/
diff --git a/module_camera/src/main/java/com/google/android/cameraview/CameraView.java b/module_camera/src/main/java/com/google/android/cameraview/CameraView.java
index c952ae6..2bccc85 100644
--- a/module_camera/src/main/java/com/google/android/cameraview/CameraView.java
+++ b/module_camera/src/main/java/com/google/android/cameraview/CameraView.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
+import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Build;
@@ -124,6 +125,7 @@ public CameraView(Context context, AttributeSet attrs, int defStyleAttr) {
mDisplayOrientationDetector = null;
return;
}
+ setBackgroundColor(Color.BLACK);
// Internal setup
mCallbacks = new CallbackBridge();
if (Build.VERSION.SDK_INT < 21) {
@@ -137,12 +139,7 @@ public CameraView(Context context, AttributeSet attrs, int defStyleAttr) {
R.style.Widget_CameraView);
mAdjustViewBounds = a.getBoolean(R.styleable.CameraView_android_adjustViewBounds, false);
setFacing(a.getInt(R.styleable.CameraView_facing, FACING_BACK));
- String aspectRatio = a.getString(R.styleable.CameraView_aspectRatio);
- if (aspectRatio != null) {
- setAspectRatio(AspectRatio.parse(aspectRatio));
- } else {
- setAspectRatio(Constants.DEFAULT_ASPECT_RATIO);
- }
+ setAspectRatio(provideAspectRatio());
setAutoFocus(a.getBoolean(R.styleable.CameraView_autoFocus, true));
setFlash(a.getInt(R.styleable.CameraView_flash, Constants.FLASH_AUTO));
a.recycle();
@@ -453,6 +450,10 @@ public int getFacing() {
return mImpl.getFacing();
}
+ protected AspectRatio provideAspectRatio() {
+ return Constants.DEFAULT_ASPECT_RATIO;
+ }
+
/**
* Gets all the aspect ratios supported by the current camera.
*/
diff --git a/module_camera/src/main/res/layout/nbzxing_default_floorview.xml b/module_camera/src/main/res/layout/nbzxing_default_floorview.xml
index e90b270..f9c65d8 100644
--- a/module_camera/src/main/res/layout/nbzxing_default_floorview.xml
+++ b/module_camera/src/main/res/layout/nbzxing_default_floorview.xml
@@ -29,7 +29,7 @@
android:id="@+id/scanRectView"
android:layout_width="200dp"
android:layout_height="200dp"
- android:layout_gravity="center|top" />
+ android:layout_gravity="center" />
-
-
-
-
-
-
-
+
+
+
+
diff --git a/module_grayscale/src/main/java/com/ailiwean/module_grayscale/Dispatch.java b/module_grayscale/src/main/java/com/ailiwean/module_grayscale/Dispatch.java
index 259d1fd..521ad6c 100644
--- a/module_grayscale/src/main/java/com/ailiwean/module_grayscale/Dispatch.java
+++ b/module_grayscale/src/main/java/com/ailiwean/module_grayscale/Dispatch.java
@@ -9,7 +9,7 @@
* @Author: SWY
* @CreateDate: 2020/8/9 6:31 PM
*/
-interface Dispatch {
+public interface Dispatch {
byte[] dispatch(byte[] data, int width, int height);
diff --git a/module_grayscale/src/main/java/com/ailiwean/module_grayscale/GrayScaleDispatch.kt b/module_grayscale/src/main/java/com/ailiwean/module_grayscale/GrayScaleDispatch.kt
index a49516e..2bd9d31 100644
--- a/module_grayscale/src/main/java/com/ailiwean/module_grayscale/GrayScaleDispatch.kt
+++ b/module_grayscale/src/main/java/com/ailiwean/module_grayscale/GrayScaleDispatch.kt
@@ -12,7 +12,7 @@ import kotlin.collections.ArrayList
* @Author: SWY
* @CreateDate: 2020/8/9 6:33 PM
*/
-class GrayScaleDispatch : Dispatch {
+object GrayScaleDispatch : Dispatch {
private var grayScaleProcess = ArrayList()
@@ -28,6 +28,10 @@ class GrayScaleDispatch : Dispatch {
grayScaleProcess.add(ReductionAreaScale(this))
}
+ fun getScaleList(): List {
+ return grayScaleProcess
+ }
+
override fun dispatch(data: ByteArray?, width: Int, height: Int): ByteArray {
return grayScaleProcess[random.nextInt(grayScaleProcess.size)].dispatch(
data, width, height)