28 Commits

Author SHA1 Message Date
Jenly
9b0635a4d4 Update README 2020-12-29 15:26:43 +08:00
Jenly
2771733a9b Update README 2020-12-24 18:16:16 +08:00
Jenly
4d607cf849 fix #86 2020-04-28 22:29:44 +08:00
Jenly
282c3dc39e 优化细节 2020-04-28 22:27:59 +08:00
Jenly
4b8b4e8723 优化细节 2020-04-28 21:08:50 +08:00
Jenly
078d31b2ad 统一日志管理 2020-04-27 21:44:01 +08:00
Jenly
86dac6216b fix#81 2020-03-29 17:21:43 +08:00
jenly1314
d3d98a3e90 Update README 2019-12-30 09:18:31 +08:00
jenly1314
30bc3e3708 发布v1.1.6-androidx 2019-12-27 18:50:44 +08:00
jenly1314
42a5cc926a 支持识别反色码(#66,#69,#72) 2019-12-27 18:11:44 +08:00
jenly1314
0a136a686b 生成条形码/二维码支持自定义颜色 (#73) 2019-12-27 18:10:42 +08:00
jenly1314
6952061597 Update README 2019-12-17 09:10:31 +08:00
jenly1314
1f1f379a6d - 2019-12-16 13:56:19 +08:00
jenly1314
2f4379cd7a 优化Camera初始化相关策略,减少出现卡顿的可能性(#64,#65) 2019-12-16 11:52:28 +08:00
jenly1314
c36ea8eb58 优化细节 2019-12-05 10:46:24 +08:00
jenly1314
b1eecb27e6 增加混淆规则 2019-11-28 16:01:24 +08:00
jenly1314
6054dcccf6 Update README 2019-11-28 16:00:24 +08:00
jenly1314
c74ad11a19 增加混淆规则 2019-11-28 16:00:10 +08:00
jenly1314
22ec947508 增加混淆规则 2019-11-25 10:57:35 +08:00
jenly1314
f528805859 Update README 2019-11-25 10:57:08 +08:00
jenly1314
26d60ae141 Update README 2019-11-18 11:09:21 +08:00
jenly1314
b830b89b5f * 内置手电筒按钮,当光线太暗时,自动显示手电筒 fix(#58)
*  生成二维码时Logo支持自定义大小 fix(#62)
2019-11-15 17:29:37 +08:00
jenly1314
004bd683a1 1、支持真实识别区域比例和识别区域偏移量可配置
2、对外暴露更多可配置参数
2019-09-24 11:49:13 +08:00
jenly1314
db340b3f4d CI 2019-09-24 11:48:56 +08:00
jenly1314
7dab96d448 CI 2019-08-23 09:41:34 +08:00
jenly1314
eb409a37fb CI 2019-08-23 09:38:17 +08:00
jenly1314
61a40d70e7 支持AndroidX对应版本 2019-06-27 18:09:12 +08:00
jenly1314
d85da52e84 支持AndroidX对应版本 2019-06-27 14:03:57 +08:00
44 changed files with 191 additions and 167 deletions

View File

@@ -1,3 +1,4 @@
version: 2 version: 2
jobs: jobs:
build: build:

View File

@@ -16,8 +16,6 @@ ZXingLite for Android 是ZXing的精简版基于ZXing库优化扫码和生成
>简单如斯,你不试试? Come on~ >简单如斯,你不试试? Come on~
### [AndroidX version](https://github.com/jenly1314/ZXingLite/tree/androidx)
## Gif 展示 ## Gif 展示
![Image](GIF.gif) ![Image](GIF.gif)
@@ -167,6 +165,7 @@ api 'com.google.zxing:core:3.3.3'
> 4、参照CaptureHelper写一个自定义的扫码帮助类其它步骤同方式3。扩展高级用法谨慎使用 > 4、参照CaptureHelper写一个自定义的扫码帮助类其它步骤同方式3。扩展高级用法谨慎使用
### 其他 ### 其他
需使用JDK8+编译在你项目中的build.gradle的android{}中添加配置: 需使用JDK8+编译在你项目中的build.gradle的android{}中添加配置:

View File

@@ -9,7 +9,7 @@ android {
targetSdkVersion build_versions.targetSdk targetSdkVersion build_versions.targetSdk
versionCode app_version.versionCode versionCode app_version.versionCode
versionName app_version.versionName versionName app_version.versionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
release { release {

Binary file not shown.

View File

@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":25,"versionName":"1.1.9","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":26,"versionName":"1.1.9-androidx","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

View File

@@ -1,13 +1,14 @@
package com.king.zxing.app; package com.king.zxing.app;
import android.content.Context; import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import static org.junit.Assert.*; import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import static org.junit.Assert.assertEquals;
/** /**
* Instrumented test, which will execute on an Android device. * Instrumented test, which will execute on an Android device.

View File

@@ -16,7 +16,7 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".MainActivity" <activity android:name=".MainActivity"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

View File

@@ -1,17 +1,18 @@
package com.king.zxing.app; package com.king.zxing.app;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import com.king.zxing.CaptureFragment; import com.king.zxing.CaptureFragment;
import com.king.zxing.app.util.StatusBarUtils; import com.king.zxing.app.util.StatusBarUtils;
import androidx.annotation.IdRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
/** /**
* Fragment扫码 * Fragment扫码
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a> * @author <a href="mailto:jenly1314@gmail.com">Jenly</a>

View File

@@ -18,8 +18,6 @@ package com.king.zxing.app;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@@ -27,6 +25,9 @@ import android.widget.TextView;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.king.zxing.util.CodeUtils; import com.king.zxing.util.CodeUtils;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
/** /**
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a> * @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/ */
@@ -92,4 +93,4 @@ public class CodeActivity extends AppCompatActivity {
break; break;
} }
} }
} }

View File

@@ -1,11 +1,7 @@
package com.king.zxing.app; package com.king.zxing.app;
import android.app.Activity; import android.app.Activity;
import android.hardware.Camera;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
@@ -17,6 +13,10 @@ import com.king.zxing.OnCaptureCallback;
import com.king.zxing.ViewfinderView; import com.king.zxing.ViewfinderView;
import com.king.zxing.app.util.StatusBarUtils; import com.king.zxing.app.util.StatusBarUtils;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
/** /**
* 自定义扫码当直接使用CaptureActivity * 自定义扫码当直接使用CaptureActivity
* 自定义扫码,切记自定义扫码需在{@link Activity}或者{@link Fragment}相对应的生命周期里面调用{@link #mCaptureHelper}对应的生命周期 * 自定义扫码,切记自定义扫码需在{@link Activity}或者{@link Fragment}相对应的生命周期里面调用{@link #mCaptureHelper}对应的生命周期

View File

@@ -16,7 +16,6 @@
package com.king.zxing.app; package com.king.zxing.app;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@@ -25,6 +24,8 @@ import com.king.zxing.CaptureActivity;
import com.king.zxing.app.util.StatusBarUtils; import com.king.zxing.app.util.StatusBarUtils;
import com.king.zxing.camera.FrontLightMode; import com.king.zxing.camera.FrontLightMode;
import androidx.appcompat.widget.Toolbar;
/** /**
* 自定义继承CaptureActivity * 自定义继承CaptureActivity
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a> * @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>

View File

@@ -16,14 +16,14 @@
package com.king.zxing.app; package com.king.zxing.app;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import com.king.zxing.CaptureActivity; import com.king.zxing.CaptureActivity;
import com.king.zxing.DecodeFormatManager;
import com.king.zxing.app.util.StatusBarUtils; import com.king.zxing.app.util.StatusBarUtils;
import androidx.appcompat.widget.Toolbar;
/** /**
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a> * @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/ */

View File

@@ -19,9 +19,6 @@ import android.Manifest;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@@ -36,6 +33,9 @@ import com.king.zxing.util.CodeUtils;
import java.util.List; import java.util.List;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import pub.devrel.easypermissions.AfterPermissionGranted; import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions; import pub.devrel.easypermissions.EasyPermissions;
@@ -243,4 +243,4 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
} }
} }
} }

View File

@@ -19,8 +19,6 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.support.annotation.FloatRange;
import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
@@ -29,6 +27,9 @@ import android.widget.LinearLayout;
import com.king.zxing.app.R; import com.king.zxing.app.R;
import androidx.annotation.FloatRange;
import androidx.appcompat.widget.Toolbar;
/** /**
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a> * @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/ */

View File

@@ -68,4 +68,4 @@ public final class UriUtils {
return path; return path;
} }
} }

View File

@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
<android.support.v7.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:background="@color/colorPrimary" android:background="@color/colorPrimary"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -27,7 +25,7 @@
android:textColor="@color/white" android:textColor="@color/white"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:text="@string/app_name"/> android:text="@string/app_name"/>
</android.support.v7.widget.Toolbar> </androidx.appcompat.widget.Toolbar>
<Button <Button
android:id="@+id/btn0" android:id="@+id/btn0"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -133,4 +131,4 @@
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn6" app:layout_constraintTop_toBottomOf="@+id/btn6"
style="@style/OnClick"/> style="@style/OnClick"/>
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@@ -15,4 +15,4 @@
app:layout_constraintTop_toBottomOf="@+id/toolbar" app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintBottom_toBottomOf="parent"/> app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -33,4 +33,4 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="160dp" /> android:layout_marginTop="160dp" />
<include layout="@layout/toolbar_capture"/> <include layout="@layout/toolbar_capture"/>
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -32,4 +32,4 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="160dp" /> android:layout_marginTop="160dp" />
<include layout="@layout/toolbar_capture"/> <include layout="@layout/toolbar_capture"/>
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<include layout="@layout/zxl_capture"/> <include layout="@layout/zxl_capture"/>
<include layout="@layout/toolbar_capture"/> <include layout="@layout/toolbar_capture"/>
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
@@ -9,4 +9,4 @@
app:contentInsetLeft="0dp" app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"> app:contentInsetStart="0dp">
<include layout="@layout/top_title_back_bar"/> <include layout="@layout/top_title_back_bar"/>
</android.support.v7.widget.Toolbar> </androidx.appcompat.widget.Toolbar>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
@@ -8,4 +8,4 @@
app:contentInsetLeft="0dp" app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"> app:contentInsetStart="0dp">
<include layout="@layout/top_title_back_bar"/> <include layout="@layout/top_title_back_bar"/>
</android.support.v7.widget.Toolbar> </androidx.appcompat.widget.Toolbar>

View File

@@ -4,6 +4,7 @@ buildscript {
apply from: 'versions.gradle' apply from: 'versions.gradle'
addRepos(repositories) addRepos(repositories)
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.novoda:bintray-release:0.9' classpath 'com.novoda:bintray-release:0.9'

View File

@@ -11,3 +11,5 @@ org.gradle.jvmargs = -Xmx1536m
# This option should only be used with decoupled projects. More details, visit # This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true # org.gradle.parallel=true
android.useAndroidX=true
android.enableJetifier=true

View File

@@ -10,7 +10,7 @@ android {
versionCode app_version.versionCode versionCode app_version.versionCode
versionName app_version.versionName versionName app_version.versionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {

View File

@@ -31,4 +31,4 @@
#ZXing #ZXing
-dontwarn com.google.zxing.** -dontwarn com.google.zxing.**
-keep class com.google.zxing.**{ *;} -keep class com.google.zxing.**{ *;}

View File

@@ -1,12 +1,13 @@
package com.king.zxing; package com.king.zxing;
import android.content.Context; import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**

View File

@@ -37,6 +37,8 @@ import java.io.IOException;
*/ */
public final class BeepManager implements MediaPlayer.OnErrorListener, Closeable { public final class BeepManager implements MediaPlayer.OnErrorListener, Closeable {
private static final String TAG = BeepManager.class.getSimpleName();
private static final float BEEP_VOLUME = 0.10f; private static final float BEEP_VOLUME = 0.10f;
private static final long VIBRATE_DURATION = 200L; private static final long VIBRATE_DURATION = 200L;
@@ -105,7 +107,7 @@ public final class BeepManager implements MediaPlayer.OnErrorListener, Closeable
mediaPlayer.prepare(); mediaPlayer.prepare();
return mediaPlayer; return mediaPlayer;
} catch (IOException ioe) { } catch (IOException ioe) {
LogUtils.w( ioe); LogUtils.w(ioe);
mediaPlayer.release(); mediaPlayer.release();
return null; return null;
} }

View File

@@ -16,16 +16,19 @@
package com.king.zxing; package com.king.zxing;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
import com.king.zxing.camera.CameraManager; import com.king.zxing.camera.CameraManager;
import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
/**
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/
public class CaptureActivity extends AppCompatActivity implements OnCaptureCallback{ public class CaptureActivity extends AppCompatActivity implements OnCaptureCallback{
public static final String KEY_RESULT = Intents.Scan.RESULT; public static final String KEY_RESULT = Intents.Scan.RESULT;

View File

@@ -16,9 +16,6 @@
package com.king.zxing; package com.king.zxing;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
@@ -26,6 +23,10 @@ import android.view.ViewGroup;
import com.king.zxing.camera.CameraManager; import com.king.zxing.camera.CameraManager;
import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
/** /**
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a> * @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/ */
@@ -188,4 +189,4 @@ public class CaptureFragment extends Fragment implements OnCaptureCallback {
return false; return false;
} }
} }

View File

@@ -211,4 +211,4 @@ public class CaptureHandler extends Handler implements ResultPointCallback {
public void setSupportLuminanceInvert(boolean supportLuminanceInvert) { public void setSupportLuminanceInvert(boolean supportLuminanceInvert) {
isSupportLuminanceInvert = supportLuminanceInvert; isSupportLuminanceInvert = supportLuminanceInvert;
} }
} }

View File

@@ -22,8 +22,6 @@ import android.graphics.Bitmap;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.RectF; import android.graphics.RectF;
import android.hardware.Camera; import android.hardware.Camera;
import android.support.annotation.FloatRange;
import android.support.v4.app.Fragment;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
@@ -43,6 +41,12 @@ import java.util.EnumMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import androidx.annotation.FloatRange;
import androidx.fragment.app.Fragment;
/**
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/
/** /**
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a> * @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/ */
@@ -345,7 +349,7 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
captureHandler.setSupportLuminanceInvert(isSupportLuminanceInvert); captureHandler.setSupportLuminanceInvert(isSupportLuminanceInvert);
} }
} catch (IOException ioe) { } catch (IOException ioe) {
LogUtils.w( ioe); LogUtils.w(ioe);
} catch (RuntimeException e) { } catch (RuntimeException e) {
// Barcode Scanner has seen crashes in the wild of this variety: // Barcode Scanner has seen crashes in the wild of this variety:
// java.?lang.?RuntimeException: Fail to connect to camera service // java.?lang.?RuntimeException: Fail to connect to camera service
@@ -532,6 +536,7 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
activity.setResult(Activity.RESULT_OK,intent); activity.setResult(Activity.RESULT_OK,intent);
activity.finish(); activity.finish();
},100); },100);
return; return;
} }

View File

@@ -146,7 +146,7 @@ final class DecodeHandler extends Handler {
if (rawResult != null) { if (rawResult != null) {
// Don't log the barcode contents for security. // Don't log the barcode contents for security.
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
LogUtils.d( "Found barcode in " + (end - start) + " ms"); LogUtils.d("Found barcode in " + (end - start) + " ms");
BarcodeFormat barcodeFormat = rawResult.getBarcodeFormat(); BarcodeFormat barcodeFormat = rawResult.getBarcodeFormat();
if(handler!=null && handler.isSupportAutoZoom() && barcodeFormat == BarcodeFormat.QR_CODE){ if(handler!=null && handler.isSupportAutoZoom() && barcodeFormat == BarcodeFormat.QR_CODE){
@@ -237,7 +237,7 @@ final class DecodeHandler extends Handler {
lastZoomTime = System.currentTimeMillis(); lastZoomTime = System.currentTimeMillis();
return true; return true;
} else { } else {
LogUtils.i( "Zoom not supported"); LogUtils.d("Zoom not supported");
} }
} }

View File

@@ -98,7 +98,7 @@ final class DecodeThread extends Thread {
hints.put(DecodeHintType.CHARACTER_SET, characterSet); hints.put(DecodeHintType.CHARACTER_SET, characterSet);
} }
hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback); hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
LogUtils.i( "Hints: " + hints); LogUtils.i("Hints: " + hints);
} }
Handler getHandler() { Handler getHandler() {

View File

@@ -35,6 +35,8 @@ import java.util.concurrent.RejectedExecutionException;
*/ */
final class InactivityTimer { final class InactivityTimer {
private static final String TAG = InactivityTimer.class.getSimpleName();
private static final long INACTIVITY_DELAY_MS = 5 * 60 * 1000L; private static final long INACTIVITY_DELAY_MS = 5 * 60 * 1000L;
private final Activity activity; private final Activity activity;
@@ -55,7 +57,7 @@ final class InactivityTimer {
try { try {
inactivityTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); inactivityTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (RejectedExecutionException ree) { } catch (RejectedExecutionException ree) {
LogUtils.w( "Couldn't schedule inactivity task; ignoring"); LogUtils.w( "Couldn't schedule inactivity task; ignoring");
} }
} }
@@ -65,13 +67,13 @@ final class InactivityTimer {
activity.unregisterReceiver(powerStatusReceiver); activity.unregisterReceiver(powerStatusReceiver);
registered = false; registered = false;
} else { } else {
LogUtils.w( "PowerStatusReceiver was never registered?"); LogUtils.w( "PowerStatusReceiver was never registered?");
} }
} }
void onResume() { void onResume() {
if (registered) { if (registered) {
LogUtils.w( "PowerStatusReceiver was already registered?"); LogUtils.w( "PowerStatusReceiver was already registered?");
} else { } else {
activity.registerReceiver(powerStatusReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); activity.registerReceiver(powerStatusReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
registered = true; registered = true;
@@ -129,7 +131,7 @@ final class InactivityTimer {
protected Object doInBackground(Object... objects) { protected Object doInBackground(Object... objects) {
try { try {
Thread.sleep(INACTIVITY_DELAY_MS); Thread.sleep(INACTIVITY_DELAY_MS);
LogUtils.i( "Finishing activity due to inactivity"); LogUtils.i("Finishing activity due to inactivity");
Activity activity = weakReference.get(); Activity activity = weakReference.get();
if(activity!=null){ if(activity!=null){
activity.finish(); activity.finish();

View File

@@ -1,5 +1,4 @@
package com.king.zxing; package com.king.zxing;
/* /*
* Copyright (C) 2008 ZXing authors * Copyright (C) 2008 ZXing authors
* *
@@ -16,7 +15,6 @@ package com.king.zxing;
* limitations under the License. * limitations under the License.
*/ */
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Canvas; import android.graphics.Canvas;
@@ -25,10 +23,6 @@ import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.RectF; import android.graphics.RectF;
import android.graphics.Shader; import android.graphics.Shader;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.Layout; import android.text.Layout;
import android.text.StaticLayout; import android.text.StaticLayout;
import android.text.TextPaint; import android.text.TextPaint;
@@ -43,6 +37,11 @@ import com.google.zxing.ResultPoint;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
/** /**
* This view is overlaid on top of the camera preview. It adds the viewfinder rectangle and partial * This view is overlaid on top of the camera preview. It adds the viewfinder rectangle and partial
* transparency outside it, as well as the laser scanner animation and result points. * transparency outside it, as well as the laser scanner animation and result points.

View File

@@ -29,7 +29,6 @@ import java.util.concurrent.RejectedExecutionException;
import com.king.zxing.Preferences; import com.king.zxing.Preferences;
import com.king.zxing.util.LogUtils; import com.king.zxing.util.LogUtils;
@SuppressWarnings("deprecation") // camera APIs
final class AutoFocusManager implements Camera.AutoFocusCallback { final class AutoFocusManager implements Camera.AutoFocusCallback {
private static final long AUTO_FOCUS_INTERVAL_MS = 1200L; private static final long AUTO_FOCUS_INTERVAL_MS = 1200L;
@@ -53,7 +52,7 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
useAutoFocus = useAutoFocus =
sharedPrefs.getBoolean(Preferences.KEY_AUTO_FOCUS, true) && sharedPrefs.getBoolean(Preferences.KEY_AUTO_FOCUS, true) &&
FOCUS_MODES_CALLING_AF.contains(currentFocusMode); FOCUS_MODES_CALLING_AF.contains(currentFocusMode);
LogUtils.i( "Current focus mode '" + currentFocusMode + "'; use auto focus? " + useAutoFocus); LogUtils.i("Current focus mode '" + currentFocusMode + "'; use auto focus? " + useAutoFocus);
start(); start();
} }
@@ -70,7 +69,7 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
newTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); newTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
outstandingTask = newTask; outstandingTask = newTask;
} catch (RejectedExecutionException ree) { } catch (RejectedExecutionException ree) {
LogUtils.w( "Could not request auto focus", ree); LogUtils.w("Could not request auto focus", ree);
} }
} }
} }
@@ -84,7 +83,7 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
focusing = true; focusing = true;
} catch (RuntimeException re) { } catch (RuntimeException re) {
// Have heard RuntimeException reported in Android 4.0.x+; continue? // Have heard RuntimeException reported in Android 4.0.x+; continue?
LogUtils.w( "Unexpected exception while focusing", re); LogUtils.w("Unexpected exception while focusing", re);
// Try again later to keep cycle going // Try again later to keep cycle going
autoFocusAgainLater(); autoFocusAgainLater();
} }
@@ -110,7 +109,7 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
camera.cancelAutoFocus(); camera.cancelAutoFocus();
} catch (RuntimeException re) { } catch (RuntimeException re) {
// Have heard RuntimeException reported in Android 4.0.x+; continue? // Have heard RuntimeException reported in Android 4.0.x+; continue?
LogUtils.w( "Unexpected exception while cancelling focusing", re); LogUtils.w("Unexpected exception while cancelling focusing", re);
} }
} }
} }

View File

@@ -81,15 +81,15 @@ final class CameraConfigurationManager {
throw new IllegalArgumentException("Bad rotation: " + displayRotation); throw new IllegalArgumentException("Bad rotation: " + displayRotation);
} }
} }
LogUtils.i( "Display at: " + cwRotationFromNaturalToDisplay); LogUtils.i("Display at: " + cwRotationFromNaturalToDisplay);
int cwRotationFromNaturalToCamera = camera.getOrientation(); int cwRotationFromNaturalToCamera = camera.getOrientation();
LogUtils.i( "Camera at: " + cwRotationFromNaturalToCamera); LogUtils.i("Camera at: " + cwRotationFromNaturalToCamera);
// Still not 100% sure about this. But acts like we need to flip this: // Still not 100% sure about this. But acts like we need to flip this:
if (camera.getFacing() == CameraFacing.FRONT) { if (camera.getFacing() == CameraFacing.FRONT) {
cwRotationFromNaturalToCamera = (360 - cwRotationFromNaturalToCamera) % 360; cwRotationFromNaturalToCamera = (360 - cwRotationFromNaturalToCamera) % 360;
LogUtils.i( "Front camera overriden to: " + cwRotationFromNaturalToCamera); LogUtils.i("Front camera overriden to: " + cwRotationFromNaturalToCamera);
} }
/* /*
@@ -101,30 +101,30 @@ final class CameraConfigurationManager {
overrideRotationString = prefs.getString(PreferencesActivity.KEY_FORCE_CAMERA_ORIENTATION, null); overrideRotationString = prefs.getString(PreferencesActivity.KEY_FORCE_CAMERA_ORIENTATION, null);
} }
if (overrideRotationString != null && !"-".equals(overrideRotationString)) { if (overrideRotationString != null && !"-".equals(overrideRotationString)) {
LogUtils.i( "Overriding camera manually to " + overrideRotationString); LogUtils.i("Overriding camera manually to " + overrideRotationString);
cwRotationFromNaturalToCamera = Integer.parseInt(overrideRotationString); cwRotationFromNaturalToCamera = Integer.parseInt(overrideRotationString);
} }
*/ */
cwRotationFromDisplayToCamera = (360 + cwRotationFromNaturalToCamera - cwRotationFromNaturalToDisplay) % 360; cwRotationFromDisplayToCamera = (360 + cwRotationFromNaturalToCamera - cwRotationFromNaturalToDisplay) % 360;
LogUtils.i( "Final display orientation: " + cwRotationFromDisplayToCamera); LogUtils.i("Final display orientation: " + cwRotationFromDisplayToCamera);
if (camera.getFacing() == CameraFacing.FRONT) { if (camera.getFacing() == CameraFacing.FRONT) {
LogUtils.i( "Compensating rotation for front camera"); LogUtils.i("Compensating rotation for front camera");
cwNeededRotation = (360 - cwRotationFromDisplayToCamera) % 360; cwNeededRotation = (360 - cwRotationFromDisplayToCamera) % 360;
} else { } else {
cwNeededRotation = cwRotationFromDisplayToCamera; cwNeededRotation = cwRotationFromDisplayToCamera;
} }
LogUtils.i( "Clockwise rotation from display to camera: " + cwNeededRotation); LogUtils.i("Clockwise rotation from display to camera: " + cwNeededRotation);
Point theScreenResolution = new Point(); Point theScreenResolution = new Point();
display.getSize(theScreenResolution); display.getSize(theScreenResolution);
screenResolution = theScreenResolution; screenResolution = theScreenResolution;
LogUtils.i( "Screen resolution in current orientation: " + screenResolution); LogUtils.i("Screen resolution in current orientation: " + screenResolution);
cameraResolution = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution); cameraResolution = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution);
LogUtils.i( "Camera resolution: " + cameraResolution); LogUtils.i("Camera resolution: " + cameraResolution);
bestPreviewSize = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution); bestPreviewSize = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution);
LogUtils.i( "Best available preview size: " + bestPreviewSize); LogUtils.i("Best available preview size: " + bestPreviewSize);
boolean isScreenPortrait = screenResolution.x < screenResolution.y; boolean isScreenPortrait = screenResolution.x < screenResolution.y;
boolean isPreviewSizePortrait = bestPreviewSize.x < bestPreviewSize.y; boolean isPreviewSizePortrait = bestPreviewSize.x < bestPreviewSize.y;
@@ -134,7 +134,7 @@ final class CameraConfigurationManager {
} else { } else {
previewSizeOnScreen = new Point(bestPreviewSize.y, bestPreviewSize.x); previewSizeOnScreen = new Point(bestPreviewSize.y, bestPreviewSize.x);
} }
LogUtils.i( "Preview size on screen: " + previewSizeOnScreen); LogUtils.i("Preview size on screen: " + previewSizeOnScreen);
} }
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) { void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {
@@ -143,14 +143,14 @@ final class CameraConfigurationManager {
Camera.Parameters parameters = theCamera.getParameters(); Camera.Parameters parameters = theCamera.getParameters();
if (parameters == null) { if (parameters == null) {
LogUtils.w( "Device error: no camera parameters are available. Proceeding without configuration."); LogUtils.w("Device error: no camera parameters are available. Proceeding without configuration.");
return; return;
} }
LogUtils.i( "Initial camera parameters: " + parameters.flatten()); LogUtils.i("Initial camera parameters: " + parameters.flatten());
if (safeMode) { if (safeMode) {
LogUtils.w( "In camera config safe mode -- most settings will not be honored"); LogUtils.w("In camera config safe mode -- most settings will not be honored");
} }
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@@ -197,7 +197,7 @@ final class CameraConfigurationManager {
Camera.Parameters afterParameters = theCamera.getParameters(); Camera.Parameters afterParameters = theCamera.getParameters();
Camera.Size afterSize = afterParameters.getPreviewSize(); Camera.Size afterSize = afterParameters.getPreviewSize();
if (afterSize != null && (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) { if (afterSize != null && (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) {
LogUtils.w( "Camera said it supported preview size " + bestPreviewSize.x + 'x' + bestPreviewSize.y + LogUtils.w("Camera said it supported preview size " + bestPreviewSize.x + 'x' + bestPreviewSize.y +
", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height); ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
bestPreviewSize.x = afterSize.width; bestPreviewSize.x = afterSize.width;
bestPreviewSize.y = afterSize.height; bestPreviewSize.y = afterSize.height;

View File

@@ -79,7 +79,7 @@ public final class CameraConfigurationUtils {
} }
if (focusMode != null) { if (focusMode != null) {
if (focusMode.equals(parameters.getFocusMode())) { if (focusMode.equals(parameters.getFocusMode())) {
LogUtils.d( "Focus mode already set to " + focusMode); LogUtils.d( "Focus mode already set to " + focusMode);
} else { } else {
parameters.setFocusMode(focusMode); parameters.setFocusMode(focusMode);
} }
@@ -101,9 +101,9 @@ public final class CameraConfigurationUtils {
} }
if (flashMode != null) { if (flashMode != null) {
if (flashMode.equals(parameters.getFlashMode())) { if (flashMode.equals(parameters.getFlashMode())) {
LogUtils.d( "Flash mode already set to " + flashMode); LogUtils.d( "Flash mode already set to " + flashMode);
} else { } else {
LogUtils.d( "Setting flash mode to " + flashMode); LogUtils.d( "Setting flash mode to " + flashMode);
parameters.setFlashMode(flashMode); parameters.setFlashMode(flashMode);
} }
} }
@@ -121,13 +121,13 @@ public final class CameraConfigurationUtils {
// Clamp value: // Clamp value:
compensationSteps = Math.max(Math.min(compensationSteps, maxExposure), minExposure); compensationSteps = Math.max(Math.min(compensationSteps, maxExposure), minExposure);
if (parameters.getExposureCompensation() == compensationSteps) { if (parameters.getExposureCompensation() == compensationSteps) {
LogUtils.d( "Exposure compensation already set to " + compensationSteps + " / " + actualCompensation); LogUtils.d( "Exposure compensation already set to " + compensationSteps + " / " + actualCompensation);
} else { } else {
LogUtils.d( "Setting exposure compensation to " + compensationSteps + " / " + actualCompensation); LogUtils.d( "Setting exposure compensation to " + compensationSteps + " / " + actualCompensation);
parameters.setExposureCompensation(compensationSteps); parameters.setExposureCompensation(compensationSteps);
} }
} else { } else {
LogUtils.d( "Camera does not support exposure compensation"); LogUtils.d( "Camera does not support exposure compensation");
} }
} }
@@ -137,7 +137,7 @@ public final class CameraConfigurationUtils {
public static void setBestPreviewFPS(Camera.Parameters parameters, int minFPS, int maxFPS) { public static void setBestPreviewFPS(Camera.Parameters parameters, int minFPS, int maxFPS) {
List<int[]> supportedPreviewFpsRanges = parameters.getSupportedPreviewFpsRange(); List<int[]> supportedPreviewFpsRanges = parameters.getSupportedPreviewFpsRange();
LogUtils.d( "Supported FPS ranges: " + toString(supportedPreviewFpsRanges)); LogUtils.d( "Supported FPS ranges: " + toString(supportedPreviewFpsRanges));
if (supportedPreviewFpsRanges != null && !supportedPreviewFpsRanges.isEmpty()) { if (supportedPreviewFpsRanges != null && !supportedPreviewFpsRanges.isEmpty()) {
int[] suitableFPSRange = null; int[] suitableFPSRange = null;
for (int[] fpsRange : supportedPreviewFpsRanges) { for (int[] fpsRange : supportedPreviewFpsRanges) {
@@ -149,14 +149,14 @@ public final class CameraConfigurationUtils {
} }
} }
if (suitableFPSRange == null) { if (suitableFPSRange == null) {
LogUtils.d( "No suitable FPS range?"); LogUtils.d( "No suitable FPS range?");
} else { } else {
int[] currentFpsRange = new int[2]; int[] currentFpsRange = new int[2];
parameters.getPreviewFpsRange(currentFpsRange); parameters.getPreviewFpsRange(currentFpsRange);
if (Arrays.equals(currentFpsRange, suitableFPSRange)) { if (Arrays.equals(currentFpsRange, suitableFPSRange)) {
LogUtils.d( "FPS range already set to " + Arrays.toString(suitableFPSRange)); LogUtils.d( "FPS range already set to " + Arrays.toString(suitableFPSRange));
} else { } else {
LogUtils.d( "Setting FPS range to " + Arrays.toString(suitableFPSRange)); LogUtils.d( "Setting FPS range to " + Arrays.toString(suitableFPSRange));
parameters.setPreviewFpsRange(suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], parameters.setPreviewFpsRange(suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); suitableFPSRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
} }
@@ -166,23 +166,23 @@ public final class CameraConfigurationUtils {
public static void setFocusArea(Camera.Parameters parameters) { public static void setFocusArea(Camera.Parameters parameters) {
if (parameters.getMaxNumFocusAreas() > 0) { if (parameters.getMaxNumFocusAreas() > 0) {
LogUtils.d( "Old focus areas: " + toString(parameters.getFocusAreas())); LogUtils.d( "Old focus areas: " + toString(parameters.getFocusAreas()));
List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000); List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000);
LogUtils.d( "Setting focus area to : " + toString(middleArea)); LogUtils.d( "Setting focus area to : " + toString(middleArea));
parameters.setFocusAreas(middleArea); parameters.setFocusAreas(middleArea);
} else { } else {
LogUtils.d( "Device does not support focus areas"); LogUtils.d( "Device does not support focus areas");
} }
} }
public static void setMetering(Camera.Parameters parameters) { public static void setMetering(Camera.Parameters parameters) {
if (parameters.getMaxNumMeteringAreas() > 0) { if (parameters.getMaxNumMeteringAreas() > 0) {
LogUtils.d( "Old metering areas: " + parameters.getMeteringAreas()); LogUtils.d( "Old metering areas: " + parameters.getMeteringAreas());
List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000); List<Camera.Area> middleArea = buildMiddleArea(AREA_PER_1000);
LogUtils.d( "Setting metering area to : " + toString(middleArea)); LogUtils.d( "Setting metering area to : " + toString(middleArea));
parameters.setMeteringAreas(middleArea); parameters.setMeteringAreas(middleArea);
} else { } else {
LogUtils.d( "Device does not support metering areas"); LogUtils.d( "Device does not support metering areas");
} }
} }
@@ -194,19 +194,19 @@ public final class CameraConfigurationUtils {
public static void setVideoStabilization(Camera.Parameters parameters) { public static void setVideoStabilization(Camera.Parameters parameters) {
if (parameters.isVideoStabilizationSupported()) { if (parameters.isVideoStabilizationSupported()) {
if (parameters.getVideoStabilization()) { if (parameters.getVideoStabilization()) {
LogUtils.d( "Video stabilization already enabled"); LogUtils.d( "Video stabilization already enabled");
} else { } else {
LogUtils.d( "Enabling video stabilization..."); LogUtils.d( "Enabling video stabilization...");
parameters.setVideoStabilization(true); parameters.setVideoStabilization(true);
} }
} else { } else {
LogUtils.d( "This device does not support video stabilization"); LogUtils.d( "This device does not support video stabilization");
} }
} }
public static void setBarcodeSceneMode(Camera.Parameters parameters) { public static void setBarcodeSceneMode(Camera.Parameters parameters) {
if (Camera.Parameters.SCENE_MODE_BARCODE.equals(parameters.getSceneMode())) { if (Camera.Parameters.SCENE_MODE_BARCODE.equals(parameters.getSceneMode())) {
LogUtils.d( "Barcode scene mode already set"); LogUtils.d( "Barcode scene mode already set");
return; return;
} }
String sceneMode = findSettableValue("scene mode", String sceneMode = findSettableValue("scene mode",
@@ -224,22 +224,22 @@ public final class CameraConfigurationUtils {
return; return;
} }
if (parameters.getZoom() == zoom) { if (parameters.getZoom() == zoom) {
LogUtils.d( "Zoom is already set to " + zoom); LogUtils.d( "Zoom is already set to " + zoom);
} else { } else {
LogUtils.d( "Setting zoom to " + zoom); LogUtils.d( "Setting zoom to " + zoom);
parameters.setZoom(zoom); parameters.setZoom(zoom);
} }
} else { } else {
LogUtils.d( "Zoom is not supported"); LogUtils.d( "Zoom is not supported");
} }
} }
private static Integer indexOfClosestZoom(Camera.Parameters parameters, double targetZoomRatio) { private static Integer indexOfClosestZoom(Camera.Parameters parameters, double targetZoomRatio) {
List<Integer> ratios = parameters.getZoomRatios(); List<Integer> ratios = parameters.getZoomRatios();
LogUtils.d( "Zoom ratios: " + ratios); LogUtils.d( "Zoom ratios: " + ratios);
int maxZoom = parameters.getMaxZoom(); int maxZoom = parameters.getMaxZoom();
if (ratios == null || ratios.isEmpty() || ratios.size() != maxZoom + 1) { if (ratios == null || ratios.isEmpty() || ratios.size() != maxZoom + 1) {
LogUtils.w( "Invalid zoom ratios!"); LogUtils.w( "Invalid zoom ratios!");
return null; return null;
} }
double target100 = 100.0 * targetZoomRatio; double target100 = 100.0 * targetZoomRatio;
@@ -252,13 +252,13 @@ public final class CameraConfigurationUtils {
closestIndex = i; closestIndex = i;
} }
} }
LogUtils.d( "Chose zoom ratio of " + (ratios.get(closestIndex) / 100.0)); LogUtils.d( "Chose zoom ratio of " + (ratios.get(closestIndex) / 100.0));
return closestIndex; return closestIndex;
} }
public static void setInvertColor(Camera.Parameters parameters) { public static void setInvertColor(Camera.Parameters parameters) {
if (Camera.Parameters.EFFECT_NEGATIVE.equals(parameters.getColorEffect())) { if (Camera.Parameters.EFFECT_NEGATIVE.equals(parameters.getColorEffect())) {
LogUtils.d( "Negative effect already set"); LogUtils.d( "Negative effect already set");
return; return;
} }
String colorMode = findSettableValue("color effect", String colorMode = findSettableValue("color effect",
@@ -273,7 +273,7 @@ public final class CameraConfigurationUtils {
List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes(); List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes();
if (rawSupportedSizes == null) { if (rawSupportedSizes == null) {
LogUtils.w( "Device returned no supported preview sizes; using default"); LogUtils.w( "Device returned no supported preview sizes; using default");
Camera.Size defaultSize = parameters.getPreviewSize(); Camera.Size defaultSize = parameters.getPreviewSize();
if (defaultSize == null) { if (defaultSize == null) {
throw new IllegalStateException("Parameters contained no preview size!"); throw new IllegalStateException("Parameters contained no preview size!");
@@ -287,7 +287,7 @@ public final class CameraConfigurationUtils {
for (Camera.Size size : rawSupportedSizes) { for (Camera.Size size : rawSupportedSizes) {
previewSizesString.append(size.width).append('x').append(size.height).append(' '); previewSizesString.append(size.width).append('x').append(size.height).append(' ');
} }
LogUtils.d( "Supported preview sizes: " + previewSizesString); LogUtils.d( "Supported preview sizes: " + previewSizesString);
} }
double screenAspectRatio; double screenAspectRatio;
@@ -296,7 +296,7 @@ public final class CameraConfigurationUtils {
}else{ }else{
screenAspectRatio = screenResolution.y / (double) screenResolution.x; screenAspectRatio = screenResolution.y / (double) screenResolution.x;
} }
LogUtils.d( "screenAspectRatio: " + screenAspectRatio); LogUtils.d( "screenAspectRatio: " + screenAspectRatio);
// Find a suitable size, with max resolution // Find a suitable size, with max resolution
int maxResolution = 0; int maxResolution = 0;
@@ -312,19 +312,19 @@ public final class CameraConfigurationUtils {
boolean isCandidatePortrait = realWidth < realHeight; boolean isCandidatePortrait = realWidth < realHeight;
int maybeFlippedWidth = isCandidatePortrait ? realWidth: realHeight ; int maybeFlippedWidth = isCandidatePortrait ? realWidth: realHeight ;
int maybeFlippedHeight = isCandidatePortrait ? realHeight : realWidth; int maybeFlippedHeight = isCandidatePortrait ? realHeight : realWidth;
LogUtils.d( String.format("maybeFlipped:%d * %d",maybeFlippedWidth,maybeFlippedHeight)); LogUtils.d( String.format("maybeFlipped:%d * %d",maybeFlippedWidth,maybeFlippedHeight));
double aspectRatio = maybeFlippedWidth / (double) maybeFlippedHeight; double aspectRatio = maybeFlippedWidth / (double) maybeFlippedHeight;
LogUtils.d( "aspectRatio: " + aspectRatio); LogUtils.d( "aspectRatio: " + aspectRatio);
double distortion = Math.abs(aspectRatio - screenAspectRatio); double distortion = Math.abs(aspectRatio - screenAspectRatio);
LogUtils.d( "distortion: " + distortion); LogUtils.d( "distortion: " + distortion);
if (distortion > MAX_ASPECT_DISTORTION) { if (distortion > MAX_ASPECT_DISTORTION) {
continue; continue;
} }
if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) { if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) {
Point exactPoint = new Point(realWidth, realHeight); Point exactPoint = new Point(realWidth, realHeight);
LogUtils.d( "Found preview size exactly matching screen size: " + exactPoint); LogUtils.d( "Found preview size exactly matching screen size: " + exactPoint);
return exactPoint; return exactPoint;
} }
@@ -340,7 +340,7 @@ public final class CameraConfigurationUtils {
// the CPU is much more powerful. // the CPU is much more powerful.
if (maxResPreviewSize != null) { if (maxResPreviewSize != null) {
Point largestSize = new Point(maxResPreviewSize.width, maxResPreviewSize.height); Point largestSize = new Point(maxResPreviewSize.width, maxResPreviewSize.height);
LogUtils.d( "Using largest suitable preview size: " + largestSize); LogUtils.d( "Using largest suitable preview size: " + largestSize);
return largestSize; return largestSize;
} }
@@ -350,24 +350,24 @@ public final class CameraConfigurationUtils {
throw new IllegalStateException("Parameters contained no preview size!"); throw new IllegalStateException("Parameters contained no preview size!");
} }
Point defaultSize = new Point(defaultPreview.width, defaultPreview.height); Point defaultSize = new Point(defaultPreview.width, defaultPreview.height);
LogUtils.d( "No suitable preview sizes, using default: " + defaultSize); LogUtils.d( "No suitable preview sizes, using default: " + defaultSize);
return defaultSize; return defaultSize;
} }
private static String findSettableValue(String name, private static String findSettableValue(String name,
Collection<String> supportedValues, Collection<String> supportedValues,
String... desiredValues) { String... desiredValues) {
LogUtils.d( "Requesting " + name + " value from among: " + Arrays.toString(desiredValues)); LogUtils.d( "Requesting " + name + " value from among: " + Arrays.toString(desiredValues));
LogUtils.d( "Supported " + name + " values: " + supportedValues); LogUtils.d( "Supported " + name + " values: " + supportedValues);
if (supportedValues != null) { if (supportedValues != null) {
for (String desiredValue : desiredValues) { for (String desiredValue : desiredValues) {
if (supportedValues.contains(desiredValue)) { if (supportedValues.contains(desiredValue)) {
LogUtils.d( "Can set " + name + " to: " + desiredValue); LogUtils.d( "Can set " + name + " to: " + desiredValue);
return desiredValue; return desiredValue;
} }
} }
} }
LogUtils.d( "No supported values match"); LogUtils.d( "No supported values match");
return null; return null;
} }

View File

@@ -22,7 +22,6 @@ import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.hardware.Camera; import android.hardware.Camera;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.FloatRange;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import com.google.zxing.PlanarYUVLuminanceSource; import com.google.zxing.PlanarYUVLuminanceSource;
@@ -32,6 +31,8 @@ import com.king.zxing.util.LogUtils;
import java.io.IOException; import java.io.IOException;
import androidx.annotation.FloatRange;
/** /**
* This object wraps the Camera service object and expects to be the only one talking to it. The * This object wraps the Camera service object and expects to be the only one talking to it. The
* implementation encapsulates the steps needed to take preview-sized images, which are used for * implementation encapsulates the steps needed to take preview-sized images, which are used for
@@ -114,8 +115,8 @@ public final class CameraManager {
configManager.setDesiredCameraParameters(theCamera, false); configManager.setDesiredCameraParameters(theCamera, false);
} catch (RuntimeException re) { } catch (RuntimeException re) {
// Driver failed // Driver failed
LogUtils.w( "Camera rejected parameters. Setting only minimal safe-mode parameters"); LogUtils.w("Camera rejected parameters. Setting only minimal safe-mode parameters");
LogUtils.i( "Resetting to saved camera params: " + parametersFlattened); LogUtils.i( "Resetting to saved camera params: " + parametersFlattened);
// Reset: // Reset:
if (parametersFlattened != null) { if (parametersFlattened != null) {
parameters = cameraObject.getParameters(); parameters = cameraObject.getParameters();
@@ -125,7 +126,7 @@ public final class CameraManager {
configManager.setDesiredCameraParameters(theCamera, true); configManager.setDesiredCameraParameters(theCamera, true);
} catch (RuntimeException re2) { } catch (RuntimeException re2) {
// Well, darn. Give up // Well, darn. Give up
LogUtils.w( "Camera rejected even safe-mode parameters! No configuration"); LogUtils.w("Camera rejected even safe-mode parameters! No configuration");
} }
} }
} }
@@ -184,7 +185,6 @@ public final class CameraManager {
previewCallback.setHandler(null, 0); previewCallback.setHandler(null, 0);
previewing = false; previewing = false;
} }
} }
/** /**
@@ -358,7 +358,7 @@ public final class CameraManager {
int leftOffset = (screenResolution.x - width) / 2; int leftOffset = (screenResolution.x - width) / 2;
int topOffset = (screenResolution.y - height) / 2; int topOffset = (screenResolution.y - height) / 2;
framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height); framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
LogUtils.d( "Calculated manual framing rect: " + framingRect); LogUtils.d( "Calculated manual framing rect: " + framingRect);
framingRectInPreview = null; framingRectInPreview = null;
} else { } else {
requestedFramingRectWidth = width; requestedFramingRectWidth = width;

View File

@@ -27,6 +27,8 @@ import com.king.zxing.util.LogUtils;
@SuppressWarnings("deprecation") // camera APIs @SuppressWarnings("deprecation") // camera APIs
final class PreviewCallback implements Camera.PreviewCallback { final class PreviewCallback implements Camera.PreviewCallback {
private static final String TAG = PreviewCallback.class.getSimpleName();
private final CameraConfigurationManager configManager; private final CameraConfigurationManager configManager;
private Handler previewHandler; private Handler previewHandler;
private int previewMessage; private int previewMessage;
@@ -50,7 +52,7 @@ final class PreviewCallback implements Camera.PreviewCallback {
message.sendToTarget(); message.sendToTarget();
previewHandler = null; previewHandler = null;
} else { } else {
LogUtils.d( "Got preview callback, but no handler or resolution available"); LogUtils.d("Got preview callback, but no handler or resolution available");
} }
} }

View File

@@ -47,11 +47,11 @@ public final class OpenCameraInterface {
int numCameras = Camera.getNumberOfCameras(); int numCameras = Camera.getNumberOfCameras();
if (numCameras == 0) { if (numCameras == 0) {
LogUtils.w( "No cameras!"); LogUtils.w("No cameras!");
return null; return null;
} }
if (cameraId >= numCameras) { if (cameraId >= numCameras) {
LogUtils.w( "Requested camera does not exist: " + cameraId); LogUtils.w("Requested camera does not exist: " + cameraId);
return null; return null;
} }

View File

@@ -20,12 +20,14 @@ import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.support.annotation.ColorInt;
import android.support.annotation.FloatRange;
import android.support.annotation.NonNull;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.ColorInt;
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap; import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType; import com.google.zxing.DecodeHintType;
@@ -648,7 +650,7 @@ public final class CodeUtils {
* @param textColor * @param textColor
* @return * @return
*/ */
private static Bitmap addCode(Bitmap src,String code,int textSize,@ColorInt int textColor,int offset) { private static Bitmap addCode(Bitmap src, String code, int textSize, @ColorInt int textColor, int offset) {
if (src == null) { if (src == null) {
return null; return null;
} }

View File

@@ -1,7 +1,7 @@
//App //App
def app_version = [:] def app_version = [:]
app_version.versionCode = 25 //androidx 26 app_version.versionCode = 26
app_version.versionName = "1.1.9" app_version.versionName = "1.1.9-androidx"
ext.app_version = app_version ext.app_version = app_version
//build version //build version
@@ -16,35 +16,37 @@ ext.deps = [:]
// App dependencies // App dependencies
def versions = [:] def versions = [:]
//support //AndroidX
versions.supportLibrary = "28.0.0" versions.material = "1.2.0-alpha01"
versions.appcompat = "1.1.0"
versions.constraintLayout = "1.1.3" versions.constraintLayout = "1.1.3"
//test //test
versions.junit = "4.12" versions.junit = "1.1.0"
versions.runner = "1.0.2" versions.test = "1.2.0"
versions.rules = "1.0.2" versions.runner = "1.2.0"
versions.espresso = "3.0.2" versions.espresso = "3.2.0"
//zxing //zxing
versions.zxing = "3.3.3" versions.zxing = "3.3.3"
versions.easypermissions = "2.0.1" versions.easypermissions = "3.0.0"
ext.versions = versions
//support //support
def support = [:] def support = [:]
support.design = "com.android.support:design:$versions.supportLibrary" support.design = "com.google.android.material:material:$versions.material"
support.appcompat = "com.android.support:appcompat-v7:$versions.supportLibrary" support.appcompat = "androidx.appcompat:appcompat:$versions.appcompat"
support.constraintlayout = "com.android.support.constraint:constraint-layout:$versions.constraintLayout" support.constraintlayout = "androidx.constraintlayout:constraintlayout:$versions.constraintLayout"
deps.support = support deps.support = support
//test //test
def test = [:] def test = [:]
test.junit = "junit:junit:$versions.junit" test.junit = "androidx.test.ext:junit:$versions.junit"
test.runner = "com.android.support.test:runner:$versions.runner" test.test = "androidx.test:core:$versions.test"
test.espresso = "com.android.support.test.espresso:espresso-core:$versions.espresso" test.runner = "androidx.test:runner:$versions.runner"
test.espresso = "androidx.test.espresso:espresso-core:$versions.espresso"
deps.test = test deps.test = test
//zxing //zxing