diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml
index a47148a..e1bb4cf 100644
--- a/.idea/assetWizardSettings.xml
+++ b/.idea/assetWizardSettings.xml
@@ -25,6 +25,7 @@
@@ -62,11 +63,24 @@
@@ -278,6 +294,11 @@
+
@@ -291,6 +312,29 @@
+
+
+
+
+
+
+
diff --git a/app/build.gradle b/app/build.gradle
index a35c13c..793842d 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -17,8 +17,8 @@ android {
applicationId "com.android.NBZxing"
minSdkVersion 17
targetSdkVersion 27
- versionCode 17
- versionName "1.21"
+ versionCode 20
+ versionName "1.25"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.release
compileOptions {
diff --git a/app/seeds_txt b/app/seeds_txt
index 4448bfc..27978c2 100644
--- a/app/seeds_txt
+++ b/app/seeds_txt
@@ -90,7 +90,7 @@ androidx.appcompat.R$id: int accessibility_custom_action_10
com.google.android.cameraview.R$styleable: int AppCompatTheme_listChoiceIndicatorSingleAnimated
androidx.appcompat.R$layout: int select_dialog_multichoice_material
com.ailiwean.core.view.FreeZxingView: com.ailiwean.core.view.ScanLightViewCallBack getLightView()
-com.ailiwean.core.view.ScanBarView
+com.ailiwean.core.view.style1.ScanBarView
androidx.appcompat.R$color: int abc_color_highlight_material
com.zhihu.matisse.R$style: int Widget_AppCompat_SearchView
com.google.android.cameraview.R$styleable: int SearchView_queryBackground
@@ -331,7 +331,7 @@ com.google.android.cameraview.R$styleable: int AppCompatTextView_drawableTopComp
com.google.android.cameraview.R$style: int RtlOverlay_Widget_AppCompat_SearchView_MagIcon
com.zhihu.matisse.internal.ui.widget.RoundedRectangleImageView: RoundedRectangleImageView(android.content.Context,android.util.AttributeSet,int)
androidx.appcompat.R$styleable: int MenuItem_android_icon
-com.ailiwean.core.view.ScanBarView: android.widget.ImageView getBarView()
+com.ailiwean.core.view.style1.ScanBarView: android.widget.ImageView getBarView()
androidx.appcompat.R$styleable: int SearchView_submitBackground
com.google.android.cameraview.R$style: int ThemeOverlay_AppCompat
com.google.android.cameraview.R$style: int Widget_AppCompat_PopupWindow
@@ -650,7 +650,7 @@ androidx.appcompat.R$dimen: int abc_action_bar_default_padding_start_material
androidx.appcompat.resources.R$styleable: int FontFamilyFont_android_font
com.zhihu.matisse.R$color: int dracula_album_dropdown_count_text
androidx.appcompat.R$attr: int ttcIndex
-com.ailiwean.core.view.ScanBarView: ScanBarView(android.content.Context,android.util.AttributeSet)
+com.ailiwean.core.view.style1.ScanBarView: ScanBarView(android.content.Context,android.util.AttributeSet)
androidx.viewpager.widget.ViewPager: ViewPager(android.content.Context,android.util.AttributeSet)
androidx.appcompat.R$styleable: int AppCompatTheme_windowFixedHeightMinor
androidx.appcompat.R$styleable: int[] Toolbar
@@ -710,7 +710,7 @@ android.support.v4.app.RemoteActionCompatParcelizer: androidx.core.app.RemoteAct
androidx.core.R$attr: int fontProviderFetchTimeout
androidx.appcompat.R$styleable: int AnimatedStateListDrawableItem_android_id
com.google.android.cameraview.R$styleable: int Toolbar_collapseContentDescription
-com.ailiwean.core.view.LocationView
+com.ailiwean.core.view.style1.LocationView
androidx.appcompat.R$drawable: int abc_vector_test
androidx.appcompat.R$id: int parentPanel
androidx.appcompat.widget.ActionBarContextView: ActionBarContextView(android.content.Context,android.util.AttributeSet)
@@ -1049,7 +1049,7 @@ androidx.appcompat.R$styleable: int DrawerArrowToggle_color
androidx.appcompat.R$id: int accessibility_custom_action_22
com.zhihu.matisse.R$style: int Widget_AppCompat_ImageButton
androidx.recyclerview.R$styleable: int CoordinatorLayout_Layout_layout_keyline
-com.ailiwean.core.view.MaskView: void setMaskingColor(int)
+com.ailiwean.core.view.style1.MaskView: void setMaskingColor(int)
androidx.recyclerview.R$styleable: int FontFamilyFont_font
com.google.android.cameraview.R$style: int Widget_AppCompat_RatingBar
com.google.android.cameraview.R$layout: int abc_activity_chooser_view
@@ -1119,7 +1119,7 @@ com.zhihu.matisse.R$id: int accessibility_custom_action_29
com.zhihu.matisse.R$style: int Base_V21_Theme_AppCompat
androidx.core.R$id: int dialog_button
com.google.android.cameraview.R$drawable: int abc_seekbar_thumb_material
-com.ailiwean.core.view.ScanBarView: ScanBarView(android.content.Context,android.util.AttributeSet,int,int,kotlin.jvm.internal.DefaultConstructorMarker)
+com.ailiwean.core.view.style1.ScanBarView: ScanBarView(android.content.Context,android.util.AttributeSet,int,int,kotlin.jvm.internal.DefaultConstructorMarker)
com.google.android.cameraview.R$styleable: int AppCompatTheme_actionModeCloseButtonStyle
androidx.appcompat.R$styleable: int AppCompatImageView_android_src
com.zhihu.matisse.R$style: int Theme_AppCompat_DayNight_Dialog_MinWidth
@@ -1569,7 +1569,7 @@ com.zhihu.matisse.R$style: int Base_V26_Theme_AppCompat
androidx.appcompat.widget.ViewStubCompat: void setOnInflateListener(androidx.appcompat.widget.ViewStubCompat$OnInflateListener)
androidx.appcompat.R$styleable: int SwitchCompat_android_textOff
androidx.activity.ComponentActivity$2
-com.ailiwean.core.view.MaskView: void setClearRect(android.graphics.Rect)
+com.ailiwean.core.view.style1.MaskView: void setClearRect(android.graphics.Rect)
com.google.android.cameraview.R$style: int TextAppearance_AppCompat_Tooltip
com.google.android.cameraview.R$style: int Base_Widget_AppCompat_Button
com.google.android.cameraview.R$style: int Widget_AppCompat_Light_ListView_DropDown
@@ -1604,7 +1604,7 @@ com.zhihu.matisse.R$style: int Widget_AppCompat_Light_ActionMode_Inverse
androidx.appcompat.R$attr: int textAppearanceListItemSmall
androidx.appcompat.R$id: int custom
com.google.android.cameraview.R$id: int action_bar_spinner
-com.ailiwean.core.view.NBZxingView: NBZxingView(android.content.Context,android.util.AttributeSet)
+com.ailiwean.core.view.style1.NBZxingView: NBZxingView(android.content.Context,android.util.AttributeSet)
com.zhihu.matisse.R$style: int Widget_AppCompat_Light_ActivityChooserView
androidx.appcompat.R$drawable: int abc_ratingbar_small_material
com.zhihu.matisse.R$drawable: int abc_seekbar_tick_mark_material
@@ -1771,7 +1771,7 @@ androidx.appcompat.widget.ActivityChooserView$InnerLayout
androidx.appcompat.R$styleable: int Spinner_android_entries
com.google.android.cameraview.R$styleable: int[] ButtonBarLayout
com.zhihu.matisse.R$attr: int splitTrack
-com.ailiwean.core.view.LocationView: LocationView(android.content.Context,android.util.AttributeSet,int)
+com.ailiwean.core.view.style1.LocationView: LocationView(android.content.Context,android.util.AttributeSet,int)
androidx.appcompat.R$dimen: int abc_dropdownitem_text_padding_right
com.ailiwean.core.view.FreeZxingView: com.ailiwean.core.view.ScanLocViewCallBack getLocView()
com.zhihu.matisse.R$style: int TextAppearance_AppCompat_Widget_ActionMode_Title
@@ -2276,7 +2276,7 @@ com.zhihu.matisse.R$attr: int alertDialogCenterButtons
com.zhihu.matisse.R$dimen: int abc_dialog_min_width_minor
androidx.appcompat.R$id: int split_action_bar
com.zhihu.matisse.R$color: int button_material_dark
-com.ailiwean.core.view.NBZxingView
+com.ailiwean.core.view.style1.NBZxingView
androidx.vectordrawable.graphics.drawable.VectorDrawableCompat$VFullPath: int getStrokeColor()
com.zhihu.matisse.R$attr: int colorControlNormal
androidx.viewpager.widget.ViewPager: void setPageMarginDrawable(android.graphics.drawable.Drawable)
@@ -2765,7 +2765,7 @@ androidx.core.R$id: int tag_transition_group
androidx.appcompat.R$style: int TextAppearance_AppCompat_Widget_ActionBar_Title_Inverse
com.zhihu.matisse.R$style: int ThemeOverlay_AppCompat_Light
androidx.appcompat.R$attr: int subMenuArrow
-com.ailiwean.core.view.LocationView: LocationView(android.content.Context,android.util.AttributeSet)
+com.ailiwean.core.view.style1.LocationView: LocationView(android.content.Context,android.util.AttributeSet)
com.google.android.cameraview.R$style: int TextAppearance_AppCompat
androidx.lifecycle.Lifecycle$Event: androidx.lifecycle.Lifecycle$Event ON_PAUSE
androidx.appcompat.R$attr: int tooltipFrameBackground
@@ -3112,7 +3112,7 @@ com.zhihu.matisse.R$color: int zhihu_bottom_toolbar_preview_text
androidx.appcompat.R$attr: int titleMarginEnd
com.zhihu.matisse.R$id: int async
com.zhihu.matisse.R$attr: int alphabeticModifiers
-com.ailiwean.core.view.MaskView: MaskView(android.content.Context,android.util.AttributeSet,int)
+com.ailiwean.core.view.style1.MaskView: MaskView(android.content.Context,android.util.AttributeSet,int)
com.google.android.cameraview.R$id: int none
androidx.recyclerview.R$styleable: int FontFamilyFont_android_ttcIndex
com.zhihu.matisse.R$dimen: int abc_action_button_min_width_overflow_material
@@ -3152,7 +3152,7 @@ androidx.core.R$id: int forever
com.ailiwean.core.zxing.core.common.CharacterSetECI: com.ailiwean.core.zxing.core.common.CharacterSetECI[] values()
androidx.appcompat.widget.AppCompatButton: int getAutoSizeMinTextSize()
com.google.android.cameraview.R$styleable: int ActionBar_navigationMode
-com.ailiwean.core.view.NBZxingView: NBZxingView(android.content.Context,android.util.AttributeSet,int,int,kotlin.jvm.internal.DefaultConstructorMarker)
+com.ailiwean.core.view.style1.NBZxingView: NBZxingView(android.content.Context,android.util.AttributeSet,int,int,kotlin.jvm.internal.DefaultConstructorMarker)
com.google.android.cameraview.R$id: int redEye
androidx.appcompat.R$id: int accessibility_custom_action_12
com.google.android.cameraview.R$styleable: int FontFamilyFont_fontWeight
@@ -3447,7 +3447,7 @@ androidx.appcompat.R$color: int bright_foreground_inverse_material_dark
com.zhihu.matisse.R$attr: int allowStacking
com.google.android.cameraview.R$style: int Base_V22_Theme_AppCompat
com.zhihu.matisse.R$attr: int album_emptyView_textColor
-com.ailiwean.core.view.MaskView: MaskView(android.content.Context)
+com.ailiwean.core.view.style1.MaskView: MaskView(android.content.Context)
androidx.appcompat.R$attr: int actionModeCutDrawable
androidx.recyclerview.R$dimen: int compat_button_inset_horizontal_material
com.google.android.cameraview.R$styleable: int Toolbar_buttonGravity
@@ -3864,7 +3864,7 @@ com.zhihu.matisse.R$color: int background_material_dark
com.zhihu.matisse.R$id: int container
androidx.appcompat.widget.AppCompatTextView: AppCompatTextView(android.content.Context,android.util.AttributeSet,int)
com.zhihu.matisse.R$attr: int drawableEndCompat
-com.ailiwean.core.view.NBZxingView: NBZxingView(android.content.Context,android.util.AttributeSet,int)
+com.ailiwean.core.view.style1.NBZxingView: NBZxingView(android.content.Context,android.util.AttributeSet,int)
androidx.appcompat.R$dimen: int abc_text_size_subhead_material
com.google.android.cameraview.R$style: int Base_Widget_AppCompat_DrawerArrowToggle
com.google.android.cameraview.R$id: int image
@@ -4055,7 +4055,7 @@ androidx.core.R$attr: int fontProviderFetchStrategy
androidx.appcompat.R$layout: int abc_action_mode_close_item_material
com.google.android.cameraview.R$styleable: int AppCompatTheme_textAppearanceListItemSecondary
androidx.appcompat.R$id: int accessibility_custom_action_25
-com.ailiwean.core.view.ScanLightView: ScanLightView(android.content.Context)
+com.ailiwean.core.view.style1.ScanLightView: ScanLightView(android.content.Context)
androidx.appcompat.R$attr: int alertDialogCenterButtons
androidx.appcompat.widget.Toolbar: java.lang.CharSequence getTitle()
com.zhihu.matisse.R$dimen: int abc_text_size_small_material
@@ -4070,7 +4070,7 @@ com.zhihu.matisse.R$attr: int stackFromEnd
androidx.appcompat.R$color: int error_color_material_light
androidx.appcompat.widget.AppCompatMultiAutoCompleteTextView: void setBackgroundDrawable(android.graphics.drawable.Drawable)
com.google.android.cameraview.R$styleable: int[] SwitchCompat
-com.ailiwean.core.view.MaskView
+com.ailiwean.core.view.style1.MaskView
com.google.android.cameraview.R$drawable: int abc_cab_background_internal_bg
com.zhihu.matisse.R$id: int up
androidx.appcompat.R$drawable: int abc_cab_background_top_material
@@ -4135,7 +4135,7 @@ com.google.android.cameraview.R$id: int accessibility_custom_action_9
androidx.appcompat.R$styleable: int AppCompatTheme_windowFixedWidthMinor
androidx.appcompat.R$drawable: int abc_text_select_handle_right_mtrl_light
androidx.appcompat.widget.DropDownListView: void setSelector(android.graphics.drawable.Drawable)
-com.ailiwean.core.view.ScanLightView: ScanLightView(android.content.Context,android.util.AttributeSet,int)
+com.ailiwean.core.view.style1.ScanLightView: ScanLightView(android.content.Context,android.util.AttributeSet,int)
androidx.appcompat.widget.LinearLayoutCompat: void setShowDividers(int)
com.zhihu.matisse.R$string: int abc_searchview_description_clear
com.google.android.cameraview.R$id: int screen
@@ -4294,7 +4294,7 @@ androidx.appcompat.widget.ViewStubCompat: int getInflatedId()
com.google.android.cameraview.R$styleable: int ActionBar_contentInsetStartWithNavigation
com.google.android.cameraview.R$styleable: int AppCompatTheme_buttonStyle
com.google.android.cameraview.R$styleable: int[] StateListDrawable
-com.ailiwean.core.view.ScanBarView: ScanBarView(android.content.Context,android.util.AttributeSet,int)
+com.ailiwean.core.view.style1.ScanBarView: ScanBarView(android.content.Context,android.util.AttributeSet,int)
androidx.appcompat.R$styleable: int Toolbar_android_gravity
androidx.appcompat.widget.Toolbar: void setContentInsetEndWithActions(int)
androidx.appcompat.R$dimen: int abc_text_size_display_3_material
@@ -4353,7 +4353,7 @@ com.google.android.cameraview.R$drawable: int abc_control_background_material
androidx.recyclerview.widget.RecyclerView: void setClipToPadding(boolean)
com.zhihu.matisse.R$id: int accessibility_custom_action_26
com.google.android.cameraview.R$styleable: int AppCompatTheme_colorControlActivated
-com.ailiwean.core.view.LocationView: LocationView(android.content.Context,android.util.AttributeSet,int,int,kotlin.jvm.internal.DefaultConstructorMarker)
+com.ailiwean.core.view.style1.LocationView: LocationView(android.content.Context,android.util.AttributeSet,int,int,kotlin.jvm.internal.DefaultConstructorMarker)
androidx.appcompat.widget.AppCompatCheckBox: void setButtonDrawable(android.graphics.drawable.Drawable)
com.zhihu.matisse.R$attr: int album_thumbnail_placeholder
com.google.android.cameraview.R$id: int action_mode_bar_stub
@@ -4621,7 +4621,7 @@ androidx.appcompat.widget.ButtonBarLayout: int getMinimumHeight()
com.google.android.cameraview.R$style: int Base_AlertDialog_AppCompat_Light
com.zhihu.matisse.R$dimen: int tooltip_corner_radius
androidx.appcompat.R$color: int abc_search_url_text
-com.ailiwean.core.view.ScanLightView
+com.ailiwean.core.view.style1.ScanLightView
androidx.appcompat.R$color: int notification_icon_bg_color
com.zhihu.matisse.R$style: int Platform_V21_AppCompat_Light
androidx.appcompat.widget.ButtonBarLayout
@@ -4748,7 +4748,7 @@ androidx.recyclerview.widget.RecyclerView: androidx.recyclerview.widget.Recycler
com.zhihu.matisse.R$style: int TextAppearance_AppCompat_Widget_Button_Colored
androidx.appcompat.R$color: int abc_secondary_text_material_light
com.google.android.cameraview.R$styleable: int Toolbar_titleTextAppearance
-com.ailiwean.core.view.ScanLightView: ScanLightView(android.content.Context,android.util.AttributeSet)
+com.ailiwean.core.view.style1.ScanLightView: ScanLightView(android.content.Context,android.util.AttributeSet)
com.zhihu.matisse.R$layout: int support_simple_spinner_dropdown_item
androidx.appcompat.R$style: int TextAppearance_AppCompat_Large
com.google.android.cameraview.R$id: int off
@@ -4886,7 +4886,7 @@ androidx.appcompat.R$styleable: int ActionBar_contentInsetLeft
com.google.android.cameraview.R$styleable: int Toolbar_contentInsetStart
com.zhihu.matisse.R$dimen: int notification_media_narrow_margin
androidx.loader.app.LoaderManagerImpl$LoaderViewModel: LoaderManagerImpl$LoaderViewModel()
-com.ailiwean.core.view.LocationView: LocationView(android.content.Context)
+com.ailiwean.core.view.style1.LocationView: LocationView(android.content.Context)
androidx.appcompat.R$styleable: int FontFamilyFont_android_fontVariationSettings
com.google.android.cameraview.CameraView: void setAdjustViewBounds(boolean)
com.google.android.cameraview.R$style: int TextAppearance_Widget_AppCompat_Toolbar_Title
@@ -4995,7 +4995,7 @@ androidx.appcompat.R$style: int TextAppearance_AppCompat_Widget_Button_Borderles
com.zhihu.matisse.R$id: int submenuarrow
com.google.android.cameraview.R$styleable: int GradientColor_android_gradientRadius
com.google.android.cameraview.R$style: int Widget_AppCompat_ListPopupWindow
-com.ailiwean.core.view.NBZxingView: NBZxingView(android.content.Context)
+com.ailiwean.core.view.style1.NBZxingView: NBZxingView(android.content.Context)
androidx.appcompat.R$attr: int backgroundTintMode
com.google.android.cameraview.R$styleable: int View_paddingStart
com.zhihu.matisse.R$layout: int abc_activity_chooser_view_list_item
@@ -5237,7 +5237,7 @@ com.zhihu.matisse.R$attr: int spinnerDropDownItemStyle
androidx.core.R$id: int accessibility_custom_action_30
com.ailiwean.core.view.LifeOwner
com.zhihu.matisse.R$style: int Base_TextAppearance_AppCompat
-com.ailiwean.core.view.MaskView: MaskView(android.content.Context,android.util.AttributeSet)
+com.ailiwean.core.view.style1.MaskView: MaskView(android.content.Context,android.util.AttributeSet)
com.zhihu.matisse.R$attr: int seekBarStyle
androidx.appcompat.R$styleable: int AppCompatTheme_colorPrimary
androidx.appcompat.widget.Toolbar: void setSubtitle(java.lang.CharSequence)
@@ -5251,7 +5251,7 @@ com.zhihu.matisse.R$id: int action_mode_bar_stub
androidx.appcompat.R$color: int abc_primary_text_material_dark
androidx.appcompat.widget.AppCompatButton: android.graphics.PorterDuff$Mode getSupportBackgroundTintMode()
com.zhihu.matisse.R$style: int Widget_AppCompat_Light_ActionBar_TabText_Inverse
-com.ailiwean.core.view.ScanBarView: ScanBarView(android.content.Context)
+com.ailiwean.core.view.style1.ScanBarView: ScanBarView(android.content.Context)
androidx.appcompat.widget.AppCompatSpinner: void setSupportBackgroundTintList(android.content.res.ColorStateList)
androidx.appcompat.R$attr: int listPreferredItemPaddingStart
com.google.android.cameraview.R$id: int tabMode
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index ec54547..6e8d702 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -36,6 +36,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/android/NBZxing/CusScanView.kt b/app/src/main/java/com/android/NBZxing/CusScanView.kt
index a70b845..78ee066 100644
--- a/app/src/main/java/com/android/NBZxing/CusScanView.kt
+++ b/app/src/main/java/com/android/NBZxing/CusScanView.kt
@@ -3,7 +3,8 @@ package com.android.NBZxing
import android.content.Context
import android.util.AttributeSet
import android.widget.Toast
-import com.ailiwean.core.view.NBZxingView
+import com.ailiwean.core.Result
+import com.ailiwean.core.view.style1.NBZxingView
import com.ailiwean.core.zxing.ScanTypeConfig
import com.google.android.cameraview.AspectRatio
@@ -17,8 +18,8 @@ import com.google.android.cameraview.AspectRatio
*/
class CusScanView @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, def: Int = 0) : NBZxingView(context, attributeSet, def) {
- override fun resultBack(content: String) {
- Toast.makeText(context, content, Toast.LENGTH_SHORT).show()
+ override fun resultBack(content: Result) {
+ Toast.makeText(context, content.text, Toast.LENGTH_LONG).show()
}
/***
diff --git a/app/src/main/java/com/android/NBZxing/CusScanView2.kt b/app/src/main/java/com/android/NBZxing/CusScanView2.kt
new file mode 100644
index 0000000..2f21170
--- /dev/null
+++ b/app/src/main/java/com/android/NBZxing/CusScanView2.kt
@@ -0,0 +1,50 @@
+package com.android.NBZxing
+
+import android.content.Context
+import android.util.AttributeSet
+import android.widget.Toast
+import com.ailiwean.core.Result
+import com.ailiwean.core.view.style2.NBZxingView
+import com.ailiwean.core.zxing.ScanTypeConfig
+import com.google.android.cameraview.AspectRatio
+
+
+/**
+ * @Package: com.android.NBZXing
+ * @ClassName: CusZxing
+ * @Description:
+ * @Author: SWY
+ * @CreateDate: 2020/4/30 4:06 PM
+ */
+class CusScanView2 @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, def: Int = 0) : NBZxingView(context, attributeSet, def) {
+
+ override fun resultBack(content: Result) {
+ Toast.makeText(context, content.text, Toast.LENGTH_LONG).show()
+ }
+
+ /***
+ * 返回扫码类型
+ * 1 ScanTypeConfig.HIGH_FREQUENCY 高频率格式(默认)
+ * 2 ScanTypeConfig.ALL 所有格式
+ * 3 ScanTypeConfig.ONLY_QR_CODE 仅QR_CODE格式
+ * 4 ScanTypeConfig.TWO_DIMENSION 所有二维码格式
+ * 5 ScanTypeConfig.ONE_DIMENSION 所有一维码格式
+ */
+ override fun getScanType(): ScanTypeConfig {
+ return ScanTypeConfig.HIGH_FREQUENCY
+ }
+
+ fun toParse(string: String) {
+ parseFile(string)
+ }
+
+ override fun provideAspectRatio(): AspectRatio {
+ return AspectRatio.of(16, 9)
+ }
+
+ override fun resultBackFile(content: String) {
+ if (content.isEmpty())
+ Toast.makeText(context, "未扫描到内容", Toast.LENGTH_SHORT).show()
+ else Toast.makeText(context, content, Toast.LENGTH_SHORT).show()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/android/NBZxing/MainActiviy.kt b/app/src/main/java/com/android/NBZxing/MainActiviy.kt
index f7f06a5..b7c5993 100644
--- a/app/src/main/java/com/android/NBZxing/MainActiviy.kt
+++ b/app/src/main/java/com/android/NBZxing/MainActiviy.kt
@@ -3,6 +3,7 @@ package com.android.NBZxing
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
+import kotlinx.android.synthetic.main.activity_select.*
/**
* @Package: com.android.NBZxing
@@ -19,7 +20,10 @@ class MainActiviy : AppCompatActivity() {
}
fun toClick(view: View) {
- ScanActivity.startSelf(this)
+ if (view == style1)
+ ScanActivity.startSelf(this)
+ if (view == style2)
+ ScanActivity2.startSelf(this)
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/android/NBZxing/ScanActivity2.kt b/app/src/main/java/com/android/NBZxing/ScanActivity2.kt
new file mode 100644
index 0000000..7e49300
--- /dev/null
+++ b/app/src/main/java/com/android/NBZxing/ScanActivity2.kt
@@ -0,0 +1,115 @@
+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
+import android.os.Build
+import android.os.Bundle
+import android.view.View
+import android.widget.TextView
+import androidx.appcompat.app.AppCompatActivity
+import com.google.android.cameraview.AspectRatio
+import com.zhihu.matisse.Matisse
+import com.zhihu.matisse.MimeType
+import com.zhihu.matisse.engine.impl.GlideEngine
+import kotlinx.android.synthetic.main.activity_main2.*
+
+class ScanActivity2 : 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_main2)
+ findViewById(R.id.zxingview2)
+ .synchLifeStart(this)
+ initView()
+// ZxingFragment fragment = new ZxingFragment();
+// getSupportFragmentManager().beginTransaction()
+// .replace(R.id.parent, fragment)
+// .commit();
+ }
+
+ companion object {
+ fun startSelf(context: Context) {
+ context.startActivity(Intent(context, ScanActivity2::class.java))
+ }
+ }
+
+ fun initView() {
+
+ findViewById(R.id.vTitle).text = "扫一扫"
+
+ findViewById(R.id.vLeftImage)
+ .setOnClickListener { v: View? ->
+ finish()
+ }
+
+ findViewById(R.id.vRightTextView).text = "相册"
+ findViewById(R.id.vRightTextView)
+ .setOnClickListener { v: View? ->
+ if (!checkPermissionRW()) {
+ requstPermissionRW()
+ return@setOnClickListener
+ }
+ Matisse.from(this)
+ .choose(MimeType.ofAll())
+ .countable(true)
+ .maxSelectable(9)
+ .gridExpectedSize(300)
+ .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
+ .thumbnailScale(0.85f)
+ .imageEngine(GlideEngine())
+ .showPreview(false) // Default is `true`
+ .forResult(1)
+ }
+ }
+
+ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+ super.onActivityResult(requestCode, resultCode, data)
+ if (requestCode == 1) {
+ if (resultCode == Activity.RESULT_OK) {
+ val path = Matisse.obtainPathResult(data)[0]
+ findViewById(R.id.zxingview).toParse(path)
+ }
+ }
+ }
+
+ fun checkPermissionRW(): Boolean {
+ return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ checkSelfPermission(
+ Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
+
+ checkSelfPermission(
+ Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
+
+ } else {
+ return true
+ }
+ }
+
+ fun requstPermissionRW() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE), 200)
+ }
+ }
+
+ var a = 0
+
+ fun change(view: View) {
+ if (a % 2 == 0)
+ zxingview2.setAspectRatio(AspectRatio.of(1, 1))
+ else zxingview2.setAspectRatio(AspectRatio.of(16, 9))
+ a++;
+ }
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/android/NBZxing/ZxingFragment.java b/app/src/main/java/com/android/NBZxing/ZxingFragment.java
index eb9a2f0..ecbf31a 100644
--- a/app/src/main/java/com/android/NBZxing/ZxingFragment.java
+++ b/app/src/main/java/com/android/NBZxing/ZxingFragment.java
@@ -10,7 +10,8 @@
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
-import com.ailiwean.core.view.NBZxingView;
+import com.ailiwean.core.Result;
+import com.ailiwean.core.view.style1.NBZxingView;
import org.jetbrains.annotations.NotNull;
@@ -30,8 +31,8 @@ public class ZxingFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
NBZxingView = new NBZxingView(container.getContext()) {
@Override
- public void resultBack(@NotNull String content) {
- Toast.makeText(container.getContext(), content, Toast.LENGTH_LONG).show();
+ public void resultBack(@NotNull Result content) {
+ Toast.makeText(getContext(), content.getText(), Toast.LENGTH_LONG).show();
}
};
return NBZxingView;
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 8115f7a..cf98729 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -15,8 +15,8 @@
+ android:onClick="change"
+ android:visibility="gone" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main2.xml b/app/src/main/res/layout/activity_main2.xml
new file mode 100644
index 0000000..5bae6ea
--- /dev/null
+++ b/app/src/main/res/layout/activity_main2.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
\ 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
index de234d3..cd1199b 100644
--- a/app/src/main/res/layout/activity_select.xml
+++ b/app/src/main/res/layout/activity_select.xml
@@ -6,12 +6,21 @@
android:orientation="vertical"
tools:ignore="MissingDefaultResource">
+
+ android:text="风格二扫码" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/floorview_layout.xml b/app/src/main/res/layout/floorview_layout.xml
index 5a69a3a..26d7c29 100644
--- a/app/src/main/res/layout/floorview_layout.xml
+++ b/app/src/main/res/layout/floorview_layout.xml
@@ -6,20 +6,20 @@
android:layout_height="match_parent"
android:orientation="vertical">
-
-
-
- ()
private static final int REFLECTIVE_CALLBACK
private static final int GENERATED_CALLBACK
-com.ailiwean.core.view.LocationView
+com.ailiwean.core.view.style1.LocationView
public android.view.View _$_findCachedViewById(int)
public void _$_clearFindViewByIdCache()
private java.util.HashMap _$_findViewCache
@@ -4584,7 +4584,7 @@ androidx.core.view.accessibility.AccessibilityViewCommand$MoveAtGranularityArgum
androidx.core.view.inputmethod.InputConnectionCompat$OnCommitContentListener
com.bumptech.glide.request.transition.ViewAnimationFactory$ConcreteViewTransitionAnimationFactory
kotlin.sequences.TakeSequence$iterator$1
-com.ailiwean.core.view.ScanBarView
+com.ailiwean.core.view.style1.ScanBarView
public android.view.View _$_findCachedViewById(int)
public void _$_clearFindViewByIdCache()
private java.util.HashMap _$_findViewCache
diff --git a/module_camera/src/main/java/com/ailiwean/core/Result.java b/module_camera/src/main/java/com/ailiwean/core/Result.java
index d086737..c87769d 100644
--- a/module_camera/src/main/java/com/ailiwean/core/Result.java
+++ b/module_camera/src/main/java/com/ailiwean/core/Result.java
@@ -4,6 +4,8 @@
import androidx.annotation.NonNull;
+import com.ailiwean.core.zxing.core.BarcodeFormat;
+
/**
* @Package: com.ailiwean.core
* @ClassName: Result
@@ -13,12 +15,24 @@
*/
public class Result {
+ //二维码内容
String text;
- PointF pointF;
+ //二维码中心坐标(已转换)
+ PointF qrPointF;
+
+ //二维码边长(已转换)
+ int qrLeng;
+
+ //二维码旋转角度
+ float qrRotate;
+ //是否旋转过
boolean isRotate;
+ //二维码格式
+ BarcodeFormat format;
+
public String getText() {
return text;
}
@@ -28,16 +42,15 @@ public Result setText(String text) {
return this;
}
- public PointF getPointF() {
- return pointF;
+ public PointF getQrPointF() {
+ return qrPointF;
}
- public Result setPointF(PointF pointF) {
- this.pointF = pointF;
+ public Result setQrPointF(PointF qrPointF) {
+ this.qrPointF = qrPointF;
return this;
}
-
public boolean isRotate() {
return isRotate;
}
@@ -47,6 +60,33 @@ public Result setRotate(boolean rotate) {
return this;
}
+ public int getQrLeng() {
+ return qrLeng;
+ }
+
+ public Result setQrLeng(int qrLeng) {
+ this.qrLeng = qrLeng;
+ return this;
+ }
+
+ public float getQrRotate() {
+ return qrRotate;
+ }
+
+ public Result setQrRotate(float qrRotate) {
+ this.qrRotate = qrRotate;
+ return this;
+ }
+
+ public BarcodeFormat getFormat() {
+ return format;
+ }
+
+ public Result setFormat(BarcodeFormat format) {
+ this.format = format;
+ return this;
+ }
+
@NonNull
@Override
public String toString() {
diff --git a/module_camera/src/main/java/com/ailiwean/core/able/GrayscaleStrengAble.java b/module_camera/src/main/java/com/ailiwean/core/able/GrayscaleStrengAble.java
index 87345ae..7697506 100644
--- a/module_camera/src/main/java/com/ailiwean/core/able/GrayscaleStrengAble.java
+++ b/module_camera/src/main/java/com/ailiwean/core/able/GrayscaleStrengAble.java
@@ -1,7 +1,7 @@
package com.ailiwean.core.able;
+import android.graphics.PointF;
import android.os.Handler;
-import android.os.Message;
import com.ailiwean.core.Config;
import com.ailiwean.core.helper.ScanHelper;
@@ -50,8 +50,11 @@ protected void needParseDeploy(PlanarYUVLuminanceSource source) {
protected com.ailiwean.core.Result covertResult(Result result) {
com.ailiwean.core.Result result_ = new com.ailiwean.core.Result();
- result_.setText(result.getText());
- result_.setPointF(ScanHelper.rotatePoint(result.getResultPoints()));
+ PointF[] pointFS = ScanHelper.rotatePoint(result.getResultPoints());
+ result_.setQrPointF(ScanHelper.calCenterPointF(pointFS));
+ result_.setQrLeng(ScanHelper.calQrLenghtShow(result.getResultPoints()));
+ result_.setFormat(result.getBarcodeFormat());
+ result_.setQrRotate(ScanHelper.calQrRotate(pointFS));
return result_;
}
diff --git a/module_camera/src/main/java/com/ailiwean/core/able/XQRScanAble.java b/module_camera/src/main/java/com/ailiwean/core/able/XQRScanAble.java
index 96e54f7..5bcb266 100644
--- a/module_camera/src/main/java/com/ailiwean/core/able/XQRScanAble.java
+++ b/module_camera/src/main/java/com/ailiwean/core/able/XQRScanAble.java
@@ -1,7 +1,7 @@
package com.ailiwean.core.able;
+import android.graphics.PointF;
import android.os.Handler;
-import android.os.Message;
import com.ailiwean.core.Config;
import com.ailiwean.core.helper.ScanHelper;
@@ -37,7 +37,11 @@ protected void needParseDeploy(PlanarYUVLuminanceSource source) {
protected com.ailiwean.core.Result covertResult(Result result) {
com.ailiwean.core.Result result_ = new com.ailiwean.core.Result();
result_.setText(result.getText());
- result_.setPointF(ScanHelper.rotatePoint(result.getResultPoints()));
+ PointF[] pointFS = ScanHelper.rotatePoint(result.getResultPoints());
+ result_.setQrPointF(ScanHelper.calCenterPointF(pointFS));
+ result_.setQrLeng(ScanHelper.calQrLenghtShow(result.getResultPoints()));
+ result_.setFormat(result.getBarcodeFormat());
+ result_.setQrRotate(ScanHelper.calQrRotate(pointFS));
return result_;
}
}
diff --git a/module_camera/src/main/java/com/ailiwean/core/able/XQRScanAbleRotate.java b/module_camera/src/main/java/com/ailiwean/core/able/XQRScanAbleRotate.java
index 7b9af1b..a8c47ec 100644
--- a/module_camera/src/main/java/com/ailiwean/core/able/XQRScanAbleRotate.java
+++ b/module_camera/src/main/java/com/ailiwean/core/able/XQRScanAbleRotate.java
@@ -1,8 +1,8 @@
package com.ailiwean.core.able;
+import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Handler;
-import android.os.Message;
import com.ailiwean.core.Config;
import com.ailiwean.core.helper.ScanHelper;
@@ -68,7 +68,11 @@ private byte[] rotateByte(byte[] data, int dataWidth, int dataHeight) {
protected com.ailiwean.core.Result covertResultRotate(Result result) {
com.ailiwean.core.Result result_ = new com.ailiwean.core.Result();
result_.setText(result.getText());
- result_.setPointF(ScanHelper.rotatePointR(result.getResultPoints()));
+ PointF[] pointFS = ScanHelper.rotatePointR(result.getResultPoints());
+ result_.setQrPointF(ScanHelper.calCenterPointF(pointFS));
+ result_.setQrLeng(ScanHelper.calQrLenghtShow(result.getResultPoints()));
+ result_.setFormat(result.getBarcodeFormat());
+ result_.setQrRotate(ScanHelper.calQrRotate(pointFS));
result_.setRotate(true);
return result_;
}
diff --git a/module_camera/src/main/java/com/ailiwean/core/able/XQRScanCrudeAble.java b/module_camera/src/main/java/com/ailiwean/core/able/XQRScanCrudeAble.java
index 9e94c82..cb95851 100644
--- a/module_camera/src/main/java/com/ailiwean/core/able/XQRScanCrudeAble.java
+++ b/module_camera/src/main/java/com/ailiwean/core/able/XQRScanCrudeAble.java
@@ -1,5 +1,6 @@
package com.ailiwean.core.able;
+import android.graphics.PointF;
import android.os.Handler;
import com.ailiwean.core.Config;
@@ -36,7 +37,11 @@ protected void needParseDeploy(PlanarYUVLuminanceSource source) {
protected com.ailiwean.core.Result covertResult(Result result) {
com.ailiwean.core.Result result_ = new com.ailiwean.core.Result();
result_.setText(result.getText());
- result_.setPointF(ScanHelper.rotatePoint(result.getResultPoints()));
+ PointF[] pointFS = ScanHelper.rotatePoint(result.getResultPoints());
+ result_.setQrPointF(ScanHelper.calCenterPointF(pointFS));
+ result_.setQrLeng(ScanHelper.calQrLenghtShow(result.getResultPoints()));
+ result_.setFormat(result.getBarcodeFormat());
+ result_.setQrRotate(ScanHelper.calQrRotate(pointFS));
return result_;
}
}
diff --git a/module_camera/src/main/java/com/ailiwean/core/able/XQRScanFineAble.java b/module_camera/src/main/java/com/ailiwean/core/able/XQRScanFineAble.java
index d546393..e5d0f5c 100644
--- a/module_camera/src/main/java/com/ailiwean/core/able/XQRScanFineAble.java
+++ b/module_camera/src/main/java/com/ailiwean/core/able/XQRScanFineAble.java
@@ -1,7 +1,7 @@
package com.ailiwean.core.able;
+import android.graphics.PointF;
import android.os.Handler;
-import android.os.Message;
import com.ailiwean.core.Config;
import com.ailiwean.core.helper.ScanHelper;
@@ -36,8 +36,11 @@ protected void needParseDeploy(PlanarYUVLuminanceSource source) {
protected com.ailiwean.core.Result covertResult(Result result) {
com.ailiwean.core.Result result_ = new com.ailiwean.core.Result();
- result_.setText(result.getText());
- result_.setPointF(ScanHelper.rotatePoint(result.getResultPoints()));
+ PointF[] pointFS = ScanHelper.rotatePoint(result.getResultPoints());
+ result_.setQrPointF(ScanHelper.calCenterPointF(pointFS));
+ result_.setQrLeng(ScanHelper.calQrLenghtShow(result.getResultPoints()));
+ result_.setFormat(result.getBarcodeFormat());
+ result_.setQrRotate(ScanHelper.calQrRotate(pointFS));
return result_;
}
}
diff --git a/module_camera/src/main/java/com/ailiwean/core/helper/LightHelper.java b/module_camera/src/main/java/com/ailiwean/core/helper/LightHelper.java
index d1715a7..98f5a55 100644
--- a/module_camera/src/main/java/com/ailiwean/core/helper/LightHelper.java
+++ b/module_camera/src/main/java/com/ailiwean/core/helper/LightHelper.java
@@ -35,8 +35,8 @@ public static int getAvDark(byte[] data, int dataWidth, int dataheight) {
lastRecordTime = currentTime;
long pixelLightCount = 0L;
long pixCount = 0L;
- int step = 10;
- for (int i = 0; i < dataWidth * dataheight; i += step) {
+ int step = 20;
+ for (int i = 0; i < data.length; i += step) {
pixelLightCount += data[i] & 0xff;
pixCount++;
}
diff --git a/module_camera/src/main/java/com/ailiwean/core/helper/ScanHelper.java b/module_camera/src/main/java/com/ailiwean/core/helper/ScanHelper.java
index 22c5129..06f7825 100644
--- a/module_camera/src/main/java/com/ailiwean/core/helper/ScanHelper.java
+++ b/module_camera/src/main/java/com/ailiwean/core/helper/ScanHelper.java
@@ -140,21 +140,22 @@ public static Rect scaleRect(Rect rect, float ratio, int maxWidth, int maxHeight
* @param point
* @return
*/
- public static PointF rotatePoint(ResultPoint[] point) {
+ public static PointF[] rotatePoint(ResultPoint[] point) {
if (point == null || point.length == 0)
- return new PointF(0, 0);
+ return null;
if (Config.scanRect.getScanR() == null)
- return new PointF(0, 0);
+ return null;
+
+// PointF avargPoint = new PointF();
+// for (ResultPoint item : point) {
+// avargPoint.x += Math.abs(item.getX());
+// avargPoint.y += Math.abs(item.getY());
+// }
+// avargPoint.x /= point.length;
+// avargPoint.y /= point.length;
- PointF avargPoint = new PointF();
- for (ResultPoint item : point) {
- avargPoint.x += Math.abs(item.getX());
- avargPoint.y += Math.abs(item.getY());
- }
- avargPoint.x /= point.length;
- avargPoint.y /= point.length;
float preX = Config.scanRect.getPreX();
float preY = Config.scanRect.getPreY();
float extraX = Config.scanRect.getExtraX();
@@ -170,42 +171,42 @@ public static PointF rotatePoint(ResultPoint[] point) {
aspeY = (preY + extraY) / (float) Config.scanRect.getDataX();
}
- float relatPointX, relatPointY;
+ PointF[] pointFS = new PointF[point.length];
- if (Config.is90()) {
- relatPointX = (Config.scanRect.getScanR().left + avargPoint.x) * aspeX - extraX / 2;
- relatPointY = (Config.scanRect.getScanR().top + avargPoint.y) * aspeY - extraY / 2;
- } else if (Config.is270()) {
- relatPointX = preX - (Config.scanRect.getScanR().left + avargPoint.x) * aspeX + extraX / 2;
- relatPointY = preY - (Config.scanRect.getScanR().top + avargPoint.y) * aspeY + extraY / 2;
- } else {
- relatPointX = preX + extraX / 2 - (Config.scanRect.getScanR().top + avargPoint.y) * aspeX;
- relatPointY = (Config.scanRect.getScanR().left + avargPoint.x) * aspeY - extraY / 2;
+ for (int i = 0; i < point.length; i++) {
+
+ float relatPointX, relatPointY;
+
+ if (Config.is90()) {
+ relatPointX = (Config.scanRect.getScanR().left + point[i].getX()) * aspeX - extraX / 2;
+ relatPointY = (Config.scanRect.getScanR().top + point[i].getY()) * aspeY - extraY / 2;
+ } else if (Config.is270()) {
+ relatPointX = preX - (Config.scanRect.getScanR().left + point[i].getX()) * aspeX + extraX / 2;
+ relatPointY = preY - (Config.scanRect.getScanR().top + point[i].getY()) * aspeY + extraY / 2;
+ } else {
+ relatPointX = preX + extraX / 2 - (Config.scanRect.getScanR().top + point[i].getY()) * aspeX;
+ relatPointY = (Config.scanRect.getScanR().left + point[i].getX()) * aspeY - extraY / 2;
+ }
+
+ pointFS[i] = new PointF(relatPointX, relatPointY);
}
- return new PointF(relatPointX, relatPointY);
+ return pointFS;
}
/***
- * 二维码坐标转换屏幕坐标
+ * 二维码坐标转换屏幕坐标(旋转后)
* @param point
* @return
*/
- public static PointF rotatePointR(ResultPoint[] point) {
+ public static PointF[] rotatePointR(ResultPoint[] point) {
if (point == null || point.length == 0)
- return new PointF(0, 0);
+ return null;
if (Config.scanRect.getScanRR() == null)
- return new PointF(0, 0);
+ return null;
- PointF avargPoint = new PointF();
- for (ResultPoint item : point) {
- avargPoint.x += Math.abs(item.getX());
- avargPoint.y += Math.abs(item.getY());
- }
- avargPoint.x /= point.length;
- avargPoint.y /= point.length;
float preX = Config.scanRect.getPreX();
float preY = Config.scanRect.getPreY();
float extraX = Config.scanRect.getExtraX();
@@ -221,21 +222,93 @@ public static PointF rotatePointR(ResultPoint[] point) {
aspeY = (preY + extraY) / (float) Config.scanRect.getDataX();
}
- float relatPointX, relatPointY;
+ PointF[] pointFS = new PointF[point.length];
- if (Config.is90()) {
- relatPointX = (Config.scanRect.getScanRR().top + avargPoint.y) * aspeX - extraX / 2;
- relatPointY = (Config.scanRect.getScanRR().left - avargPoint.x +
- Config.scanRect.getScanRR().width()) * aspeY - extraY / 2;
- } else if (Config.is270()) {
- relatPointX = preX - (Config.scanRect.getScanRR().top + avargPoint.y) * aspeX + extraX / 2;
- relatPointY = preY - (Config.scanRect.getScanRR().left - avargPoint.x +
- Config.scanRect.getScanRR().width()) * aspeY + extraY / 2;
- } else {
- relatPointX = (Config.scanRect.getScanRR().left + avargPoint.x) * aspeX - extraX / 2;
- relatPointY = (Config.scanRect.getScanRR().top + avargPoint.y) * aspeY - extraY / 2;
+ for (int i = 0; i < point.length; i++) {
+
+ float relatPointX, relatPointY;
+
+ if (Config.is90()) {
+ relatPointX = (Config.scanRect.getScanRR().top + point[i].getY()) * aspeX - extraX / 2;
+ relatPointY = (Config.scanRect.getScanRR().left - point[i].getX() +
+ Config.scanRect.getScanRR().width()) * aspeY - extraY / 2;
+ } else if (Config.is270()) {
+ relatPointX = preX - (Config.scanRect.getScanRR().top + point[i].getY()) * aspeX + extraX / 2;
+ relatPointY = preY - (Config.scanRect.getScanRR().left - point[i].getX() +
+ Config.scanRect.getScanRR().width()) * aspeY + extraY / 2;
+ } else {
+ relatPointX = (Config.scanRect.getScanRR().left + point[i].getX()) * aspeX - extraX / 2;
+ relatPointY = (Config.scanRect.getScanRR().top + point[i].getY()) * aspeY - extraY / 2;
+ }
+
+ pointFS[i] = new PointF(relatPointX, relatPointY);
+
+ }
+
+ return pointFS;
+ }
+
+
+ /***
+ * 二维码边长转屏幕px
+ */
+ public static int calQrLenghtShow(ResultPoint[] point) {
+
+ if (point == null || point.length == 0)
+ return 0;
+
+ PointF avargPoint = new PointF();
+ for (ResultPoint item : point) {
+ avargPoint.x += Math.abs(item.getX());
+ avargPoint.y += Math.abs(item.getY());
+ }
+ avargPoint.x /= point.length;
+ avargPoint.y /= point.length;
+
+ int x = (int) Math.pow((avargPoint.x - point[0].getX()), 2);
+ int y = (int) Math.pow((avargPoint.y - point[0].getY()), 2);
+
+ float asp = Math.max(Config.scanRect.getPreX(), Config.scanRect.getPreY()) /
+ (float) Math.max(Config.scanRect.getDataX(), Config.scanRect.getDataY());
+
+ return (int) (Math.sqrt(x + y) / Math.sqrt(2) * 2 * asp);
+ }
+
+
+ /***
+ * 计算中心点
+ * @param point
+ * @return
+ */
+ public static PointF calCenterPointF(PointF[] point) {
+
+ if (point == null || point.length == 0)
+ return new PointF();
+
+ PointF avargPoint = new PointF();
+ for (PointF item : point) {
+ avargPoint.x += Math.abs(item.x);
+ avargPoint.y += Math.abs(item.y);
}
- return new PointF(relatPointX, relatPointY);
+ avargPoint.x /= point.length;
+ avargPoint.y /= point.length;
+
+ return avargPoint;
+ }
+
+
+ /***
+ * 二维码旋转角度(相对对角线与x轴45度夹角)
+ */
+ public static float calQrRotate(PointF[] point) {
+
+ PointF avargPoint = calCenterPointF(point);
+
+ int x = (int) Math.abs(avargPoint.x - point[0].x);
+ int y = (int) Math.abs(avargPoint.y - point[0].y);
+
+ float maxRotate = (float) ((float) Math.atan2(x, y) / 2 / Math.PI * 360);
+ return (float) (maxRotate - 45);
}
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 96a2dba..fb1411f 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
@@ -94,7 +94,7 @@ abstract class FreeZxingView @JvmOverloads constructor(context: Context, attribu
SCAN_RESULT -> {
scanSucHelper()
if (message.obj is Result) {
- showQRLoc((message.obj as Result).pointF, message.obj.toString())
+ showQRLoc(message.obj as Result)
}
}
@@ -176,9 +176,9 @@ abstract class FreeZxingView @JvmOverloads constructor(context: Context, attribu
/***
* 显示二维码位置, 动画播放完回调扫描结果
*/
- fun showQRLoc(point: PointF, content: String) {
- locView?.toLocation(point) {
- resultBack(content)
+ fun showQRLoc(result: Result) {
+ locView?.toLocation(result) {
+ resultBack(result)
}
}
@@ -218,7 +218,7 @@ abstract class FreeZxingView @JvmOverloads constructor(context: Context, attribu
/***
* 扫码结果回调
*/
- abstract fun resultBack(content: String)
+ abstract fun resultBack(content: Result)
/***
* 图片文件扫码
diff --git a/module_camera/src/main/java/com/ailiwean/core/view/ScanLocViewCallBack.java b/module_camera/src/main/java/com/ailiwean/core/view/ScanLocViewCallBack.java
index a6a79cb..c48fd83 100644
--- a/module_camera/src/main/java/com/ailiwean/core/view/ScanLocViewCallBack.java
+++ b/module_camera/src/main/java/com/ailiwean/core/view/ScanLocViewCallBack.java
@@ -2,6 +2,8 @@
import android.graphics.PointF;
+import com.ailiwean.core.Result;
+
/**
* @Package: com.ailiwean.core.view
* @ClassName: LocationCallBack
@@ -12,9 +14,9 @@
public interface ScanLocViewCallBack extends CameraStarLater {
/***
- * @param qrPoint 二维码中心位置坐标,相对于FreeZxingView
+ * @param result 扫码结果
* @param runnable 扫码结果回调
*/
- void toLocation(PointF qrPoint, Runnable runnable);
+ void toLocation(Result result, Runnable runnable);
}
diff --git a/module_camera/src/main/java/com/ailiwean/core/view/LocationView.kt b/module_camera/src/main/java/com/ailiwean/core/view/style1/LocationView.kt
similarity index 85%
rename from module_camera/src/main/java/com/ailiwean/core/view/LocationView.kt
rename to module_camera/src/main/java/com/ailiwean/core/view/style1/LocationView.kt
index 20bc003..03ba1ac 100644
--- a/module_camera/src/main/java/com/ailiwean/core/view/LocationView.kt
+++ b/module_camera/src/main/java/com/ailiwean/core/view/style1/LocationView.kt
@@ -1,11 +1,12 @@
-package com.ailiwean.core.view
+package com.ailiwean.core.view.style1
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.content.Context
-import android.graphics.PointF
import android.util.AttributeSet
import android.view.View
+import com.ailiwean.core.Result
+import com.ailiwean.core.view.ScanLocViewCallBack
import com.google.android.cameraview.R
/**
@@ -23,7 +24,8 @@ class LocationView @JvmOverloads constructor(context: Context, attributeSet: Att
setImageResource(R.drawable.ic_qr_loc)
}
- override fun toLocation(qrPoint: PointF, run: Runnable) {
+ override fun toLocation(result: Result, run: Runnable) {
+ var qrPoint = result.qrPointF
visibility = View.VISIBLE
translationX = (qrPoint.x - layoutParams.width / 2)
translationY = (qrPoint.y - layoutParams.height / 2)
diff --git a/module_camera/src/main/java/com/ailiwean/core/view/MaskView.java b/module_camera/src/main/java/com/ailiwean/core/view/style1/MaskView.java
similarity index 79%
rename from module_camera/src/main/java/com/ailiwean/core/view/MaskView.java
rename to module_camera/src/main/java/com/ailiwean/core/view/style1/MaskView.java
index 214fc8f..dbaf495 100644
--- a/module_camera/src/main/java/com/ailiwean/core/view/MaskView.java
+++ b/module_camera/src/main/java/com/ailiwean/core/view/style1/MaskView.java
@@ -1,5 +1,6 @@
-package com.ailiwean.core.view;
+package com.ailiwean.core.view.style1;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
@@ -25,7 +26,7 @@
public class MaskView extends View {
private Paint paint;
- private Rect clearRect;
+ private Rect clearRect = new Rect();
private Rect[] drawRects;
private float margin_left;
private float margin_top;
@@ -70,9 +71,11 @@ public void initPaint() {
paint.setStyle(Paint.Style.FILL);
}
+
+ @SuppressLint("DrawAllocation")
@Override
- protected void onFinishInflate() {
- super.onFinishInflate();
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
post(() -> {
ViewGroup viewGroup = (ViewGroup) getParent();
View parseRectView = viewGroup.findViewById(id);
@@ -83,17 +86,18 @@ protected void onFinishInflate() {
int[] parent_screen = new int[2];
viewGroup.getLocationInWindow(parent_screen);
- clearRect = new Rect(
- parse_screen[0] - parent_screen[0],
- parse_screen[1] - parent_screen[1],
- parse_screen[0] - parent_screen[0] + parseRectView.getMeasuredWidth(),
- parse_screen[1] - parent_screen[1] + parseRectView.getMeasuredHeight());
+ clearRect.left = parse_screen[0] - parent_screen[0];
+ clearRect.top = parse_screen[1] - parent_screen[1];
+ clearRect.right = parse_screen[0] - parent_screen[0] + parseRectView.getMeasuredWidth();
+ clearRect.bottom = parse_screen[1] - parent_screen[1] + parseRectView.getMeasuredHeight();
+
} else {
- clearRect = new Rect(
- (int) margin_left,
- (int) margin_top,
- (int) (getMeasuredWidth() - margin_right),
- (int) (getMeasuredHeight() - margin_bottom));
+
+ clearRect.left = (int) margin_left;
+ clearRect.top = (int) margin_top;
+ clearRect.right = (int) (getMeasuredWidth() - margin_right);
+ clearRect.bottom = (int) (getMeasuredHeight() - margin_bottom);
+
}
drawRects = clearRect2Rect();
invalidate();
diff --git a/module_camera/src/main/java/com/ailiwean/core/view/NBZxingView.kt b/module_camera/src/main/java/com/ailiwean/core/view/style1/NBZxingView.kt
similarity index 67%
rename from module_camera/src/main/java/com/ailiwean/core/view/NBZxingView.kt
rename to module_camera/src/main/java/com/ailiwean/core/view/style1/NBZxingView.kt
index 7b77b38..2d7c15d 100644
--- a/module_camera/src/main/java/com/ailiwean/core/view/NBZxingView.kt
+++ b/module_camera/src/main/java/com/ailiwean/core/view/style1/NBZxingView.kt
@@ -1,11 +1,15 @@
-package com.ailiwean.core.view
+package com.ailiwean.core.view.style1
import android.content.Context
import android.util.AttributeSet
import android.view.View
-import android.widget.Toast
+import com.ailiwean.core.Result
+import com.ailiwean.core.view.FreeZxingView
+import com.ailiwean.core.view.ScanBarCallBack
+import com.ailiwean.core.view.ScanLightViewCallBack
+import com.ailiwean.core.view.ScanLocViewCallBack
import com.google.android.cameraview.R
-import kotlinx.android.synthetic.main.nbzxing_default_floorview.view.*
+import kotlinx.android.synthetic.main.nbzxing_style1_floorview.view.*
/**
* @Package: com.google.android.cameraview
@@ -17,12 +21,12 @@ import kotlinx.android.synthetic.main.nbzxing_default_floorview.view.*
open class NBZxingView @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, def: Int = 0) :
FreeZxingView(context, attributeSet, def) {
- override fun resultBack(content: String) {
- Toast.makeText(context, content, Toast.LENGTH_SHORT).show()
+ override fun resultBack(content: Result) {
+
}
override fun provideFloorView(): Int {
- return R.layout.nbzxing_default_floorview
+ return R.layout.nbzxing_style1_floorview
}
override fun provideParseRectView(): View? {
diff --git a/module_camera/src/main/java/com/ailiwean/core/view/ScanBarView.kt b/module_camera/src/main/java/com/ailiwean/core/view/style1/ScanBarView.kt
similarity index 73%
rename from module_camera/src/main/java/com/ailiwean/core/view/ScanBarView.kt
rename to module_camera/src/main/java/com/ailiwean/core/view/style1/ScanBarView.kt
index a82317d..4cbb426 100644
--- a/module_camera/src/main/java/com/ailiwean/core/view/ScanBarView.kt
+++ b/module_camera/src/main/java/com/ailiwean/core/view/style1/ScanBarView.kt
@@ -1,4 +1,4 @@
-package com.ailiwean.core.view
+package com.ailiwean.core.view.style1
import android.animation.ValueAnimator
import android.content.Context
@@ -8,6 +8,7 @@ import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import com.ailiwean.core.Utils
+import com.ailiwean.core.view.ScanBarCallBack
import com.google.android.cameraview.R
/**
@@ -20,11 +21,13 @@ import com.google.android.cameraview.R
class ScanBarView @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, def: Int = 0) :
FrameLayout(context, attributeSet, def), ScanBarCallBack {
- private val ALPHA_LENGHT = 100f
+ private val BAR_HEIGHT = Utils.dp2px(20f)
+
+ private val ALPHA_LENGHT = 0.2f
private val barView: ImageView by lazy {
val view = ImageView(context)
- view.layoutParams = ViewGroup.LayoutParams(-1, Utils.dp2px(50f))
+ view.layoutParams = ViewGroup.LayoutParams(-1, BAR_HEIGHT)
view.setBackgroundResource(R.drawable.ic_scan_bar)
view
}
@@ -46,17 +49,19 @@ class ScanBarView @JvmOverloads constructor(context: Context, attributeSet: Attr
if (measuredHeight == 0)
return
+ val alpha_height = ALPHA_LENGHT * measuredHeight
+
visibility = View.VISIBLE
- animator = ValueAnimator.ofFloat(0f, measuredHeight.toFloat())
- .setDuration(2000)
+ animator = ValueAnimator.ofFloat((-BAR_HEIGHT).toFloat(), measuredHeight.toFloat())
+ .setDuration(4000)
animator?.addUpdateListener { it ->
val values = it.animatedValue as Float
- alpha = if (values <= ALPHA_LENGHT) {
- values / ALPHA_LENGHT
+ barView.alpha = if (values <= alpha_height) {
+ values / alpha_height
} else {
- (measuredHeight - values) / ALPHA_LENGHT
+ (measuredHeight - values) / alpha_height
}
- translationY = values
+ barView.translationY = values
}
animator?.repeatCount = Int.MAX_VALUE - 1
animator?.repeatMode = ValueAnimator.RESTART
diff --git a/module_camera/src/main/java/com/ailiwean/core/view/ScanLightView.java b/module_camera/src/main/java/com/ailiwean/core/view/style1/ScanLightView.java
similarity index 96%
rename from module_camera/src/main/java/com/ailiwean/core/view/ScanLightView.java
rename to module_camera/src/main/java/com/ailiwean/core/view/style1/ScanLightView.java
index 7f4dee2..a3d4678 100644
--- a/module_camera/src/main/java/com/ailiwean/core/view/ScanLightView.java
+++ b/module_camera/src/main/java/com/ailiwean/core/view/style1/ScanLightView.java
@@ -1,4 +1,4 @@
-package com.ailiwean.core.view;
+package com.ailiwean.core.view.style1;
import android.content.Context;
import android.util.AttributeSet;
@@ -8,6 +8,7 @@
import android.widget.ImageView;
import android.widget.TextView;
+import com.ailiwean.core.view.ScanLightViewCallBack;
import com.google.android.cameraview.R;
/***
diff --git a/module_camera/src/main/java/com/ailiwean/core/view/style2/LocationView.kt b/module_camera/src/main/java/com/ailiwean/core/view/style2/LocationView.kt
new file mode 100644
index 0000000..f50b84b
--- /dev/null
+++ b/module_camera/src/main/java/com/ailiwean/core/view/style2/LocationView.kt
@@ -0,0 +1,60 @@
+package com.ailiwean.core.view.style2
+
+import android.animation.Animator
+import android.animation.ObjectAnimator
+import android.animation.PropertyValuesHolder
+import android.animation.ValueAnimator
+import android.annotation.SuppressLint
+import android.content.Context
+import android.util.AttributeSet
+import android.view.Gravity
+import android.widget.FrameLayout
+import com.ailiwean.core.Result
+import com.ailiwean.core.view.ScanLocViewCallBack
+
+
+/**
+ * @Package: com.ailiwean.core.view
+ * @ClassName: LocationView2
+ * @Description:
+ * @Author: SWY(https://github.com/ailiwean)
+ * @CreateDate: 2020/10/25 3:35 PM
+ */
+class LocationView @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, def: Int = 0) :
+ androidx.appcompat.widget.AppCompatImageView(context, attributeSet, def), ScanLocViewCallBack {
+
+ private var animator: ObjectAnimator? = null
+
+ override fun cameraStartLaterInit() {
+ startAnim()
+ }
+
+ fun startAnim() {
+ val scaleYProper = PropertyValuesHolder.ofFloat("scaleY", 1f, 0.8f, 1f)
+ val scaleXProper = PropertyValuesHolder.ofFloat("scaleX", 1f, 0.8f, 1f)
+ animator = ObjectAnimator.ofPropertyValuesHolder(this, scaleYProper, scaleXProper)
+ animator?.repeatMode = ValueAnimator.RESTART
+ animator?.duration = 2000
+ animator?.repeatCount = Int.MAX_VALUE - 1
+ animator?.start()
+ }
+
+ override fun toLocation(result: Result?, runnable: Runnable?) {
+ var params = layoutParams
+ result?.let {
+ translationX = it.qrPointF.x - it.qrLeng * 1f
+ translationY = it.qrPointF.y - it.qrLeng * 1f
+ rotation = it.qrRotate
+ params.width = (it.qrLeng * 2f).toInt()
+ params.height = (it.qrLeng * 2f).toInt()
+ (params as FrameLayout.LayoutParams).gravity = Gravity.TOP or Gravity.LEFT
+ layoutParams = params
+ }
+ runnable?.run()
+ }
+
+ override fun onDetachedFromWindow() {
+ super.onDetachedFromWindow()
+ animator?.cancel()
+ }
+}
\ No newline at end of file
diff --git a/module_camera/src/main/java/com/ailiwean/core/view/style2/NBZxing.kt b/module_camera/src/main/java/com/ailiwean/core/view/style2/NBZxing.kt
new file mode 100644
index 0000000..c8bc883
--- /dev/null
+++ b/module_camera/src/main/java/com/ailiwean/core/view/style2/NBZxing.kt
@@ -0,0 +1,48 @@
+package com.ailiwean.core.view.style2
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.View
+import com.ailiwean.core.Result
+import com.ailiwean.core.view.FreeZxingView
+import com.ailiwean.core.view.ScanBarCallBack
+import com.ailiwean.core.view.ScanLightViewCallBack
+import com.ailiwean.core.view.ScanLocViewCallBack
+import com.google.android.cameraview.R
+import kotlinx.android.synthetic.main.nbzxing_style2_floorview.view.*
+
+/**
+ * @Package: com.google.android.cameraview
+ * @ClassName: ZxingCamera
+ * @Description:
+ * @Author: SWY
+ * @CreateDate: 2020/4/19 12:38 AM
+ */
+open class NBZxingView @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, def: Int = 0) :
+ FreeZxingView(context, attributeSet, def) {
+
+ override fun resultBack(content: Result) {
+
+ }
+
+ override fun provideFloorView(): Int {
+ return R.layout.nbzxing_style2_floorview
+ }
+
+ override fun provideParseRectView(): View? {
+ return scanRectView
+ }
+
+ override fun provideLightView(): ScanLightViewCallBack? {
+ return lightView
+ }
+
+ override fun provideLocView(): ScanLocViewCallBack? {
+ return locView
+ }
+
+ override fun provideScanBarView(): ScanBarCallBack? {
+ return null
+ }
+
+}
\ No newline at end of file
diff --git a/module_camera/src/main/java/com/ailiwean/core/zxing/LightGreySource.java b/module_camera/src/main/java/com/ailiwean/core/zxing/LightGreySource.java
index 2e3dd30..d6ba14e 100644
--- a/module_camera/src/main/java/com/ailiwean/core/zxing/LightGreySource.java
+++ b/module_camera/src/main/java/com/ailiwean/core/zxing/LightGreySource.java
@@ -112,7 +112,6 @@ public synchronized void toPut(byte[] nv21, int w, int h) {
if (count == 0) {
continue;
}
- avage /= stepX * stepY;
for (int y_ = step_h; y_ < step_h + stepY; y_++) {
for (int x_ = step_w; x_ < step_w + stepX; x_++) {
cropNv21[y_ * w + x_] = (byte) (min / 3 * 2);
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 e916c67..a6c5cbf 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
@@ -22,6 +22,7 @@
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.RectF;
+import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcel;
@@ -125,12 +126,12 @@ public CameraView(Context context, AttributeSet attrs, int defStyleAttr) {
setBackgroundColor(Color.BLACK);
// Internal setup
mCallbacks = new CallbackBridge();
-// if (Build.VERSION.SDK_INT < 21) {
-// mImpl = new Camera1(mCallbacks);
-// } else {
-// mImpl = new Camera2(mCallbacks, context);
-// }
- mImpl = new Camera1(mCallbacks);
+ if (Build.VERSION.SDK_INT < 21) {
+ mImpl = new Camera1(mCallbacks);
+ } else {
+ mImpl = new Camera2(mCallbacks, context);
+ }
+// mImpl = new Camera1(mCallbacks);
// Attributes
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CameraView, defStyleAttr,
R.style.Widget_CameraView);
@@ -228,6 +229,10 @@ protected void defineScanParseRect(View view) {
int oriWidth = getMeasuredWidth();
AspectRatio ratio = getAspectRatio();
+
+ if (ratio == null)
+ return;
+
if (getContext().getResources().getConfiguration().orientation
== Configuration.ORIENTATION_PORTRAIT) {
Config.displayOrientation = 0;
@@ -236,10 +241,6 @@ protected void defineScanParseRect(View view) {
if (mDisplayOrientationDetector.getLastKnownDisplayOrientation() != 0)
Config.displayOrientation = mDisplayOrientationDetector.getLastKnownDisplayOrientation();
}
-
- if (ratio == null)
- return;
-
if (oriHeight < oriWidth * ratio.getY() / ratio.getX()) {
int measureHeight = (int) (oriWidth * ratio.getY() / (float) ratio.getX());
float expectRatio = (measureHeight - oriHeight) / 2f / measureHeight;
diff --git a/module_camera/src/main/res/drawable/bac.xml b/module_camera/src/main/res/drawable/bac.xml
new file mode 100644
index 0000000..5a73ad8
--- /dev/null
+++ b/module_camera/src/main/res/drawable/bac.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
diff --git a/module_camera/src/main/res/drawable/frame_background.xml b/module_camera/src/main/res/drawable/frame_background.xml
new file mode 100644
index 0000000..ca3826a
--- /dev/null
+++ b/module_camera/src/main/res/drawable/frame_background.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/module_camera/src/main/res/drawable/frame_foreground.xml b/module_camera/src/main/res/drawable/frame_foreground.xml
new file mode 100644
index 0000000..5a73ad8
--- /dev/null
+++ b/module_camera/src/main/res/drawable/frame_foreground.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
diff --git a/module_camera/src/main/res/drawable/ic_style2_scan.xml b/module_camera/src/main/res/drawable/ic_style2_scan.xml
new file mode 100644
index 0000000..c7e82db
--- /dev/null
+++ b/module_camera/src/main/res/drawable/ic_style2_scan.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
diff --git a/module_camera/src/main/res/layout-land/nbzxing_default_floorview.xml b/module_camera/src/main/res/layout-land/nbzxing_style1_floorview.xml
similarity index 86%
rename from module_camera/src/main/res/layout-land/nbzxing_default_floorview.xml
rename to module_camera/src/main/res/layout-land/nbzxing_style1_floorview.xml
index 9ae90ce..5c66099 100644
--- a/module_camera/src/main/res/layout-land/nbzxing_default_floorview.xml
+++ b/module_camera/src/main/res/layout-land/nbzxing_style1_floorview.xml
@@ -6,14 +6,14 @@
android:layout_height="match_parent"
android:orientation="vertical">
-
-
-
-
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/module_camera/src/main/res/layout/nbzxing_default_floorview.xml b/module_camera/src/main/res/layout/nbzxing_style1_floorview.xml
similarity index 70%
rename from module_camera/src/main/res/layout/nbzxing_default_floorview.xml
rename to module_camera/src/main/res/layout/nbzxing_style1_floorview.xml
index b1dd18a..05b49ea 100644
--- a/module_camera/src/main/res/layout/nbzxing_default_floorview.xml
+++ b/module_camera/src/main/res/layout/nbzxing_style1_floorview.xml
@@ -6,20 +6,19 @@
android:layout_height="match_parent"
android:orientation="vertical">
-
+ android:alpha="0.7" />
-
+ android:layout_width="200dp"
+ android:layout_height="200dp"
+ android:layout_gravity="center" />
-
-
-
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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 2bd9d31..816a2ed 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
@@ -23,7 +23,7 @@ object GrayScaleDispatch : Dispatch {
grayScaleProcess.add(OverBrightScale())
grayScaleProcess.add(OverDarkScale())
grayScaleProcess.add(RevGrayScale())
- grayScaleProcess.add(OverlyGrayScale())
+// grayScaleProcess.add(OverlyGrayScale())
grayScaleProcess.add(InterruptGrayScale())
grayScaleProcess.add(ReductionAreaScale(this))
}
@@ -31,7 +31,7 @@ object GrayScaleDispatch : Dispatch {
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)
@@ -40,7 +40,7 @@ object GrayScaleDispatch : Dispatch {
override fun dispatch(data: ByteArray?, width: Int, height: Int, rect: Rect?): ByteArray {
if (rect == null || (rect.left == 0 && rect.right == 0) ||
- rect.top == 0 && rect.bottom == 0)
+ (rect.top == 0 && rect.bottom == 0))
return dispatch(data, width, height)
return grayScaleProcess[random.nextInt(grayScaleProcess.size)].dispatch(
diff --git a/module_grayscale/src/main/java/com/ailiwean/module_grayscale/InterruptGrayScale.java b/module_grayscale/src/main/java/com/ailiwean/module_grayscale/InterruptGrayScale.java
index d3f1911..264bf95 100644
--- a/module_grayscale/src/main/java/com/ailiwean/module_grayscale/InterruptGrayScale.java
+++ b/module_grayscale/src/main/java/com/ailiwean/module_grayscale/InterruptGrayScale.java
@@ -5,73 +5,85 @@
/**
* @Package: com.ailiwean.module_grayscale
* @ClassName: InterruptScale
- * @Description: 膨胀处理
+ * @Description: 开闭操作
* @Author: SWY
* @CreateDate: 2020/9/12 10:14 PM
*/
class InterruptGrayScale implements Dispatch {
//结构元素步长
- private int stepX = 3;
- private int stepY = 3;
+ private int stepX = 2;
+ private int stepY = 2;
@Override
public byte[] dispatch(byte[] data, int width, int height) {
+ return data;
+ }
+
+ @Override
+ public byte[] dispatch(byte[] data, int width, int height, Rect rect) {
byte[] newByte = data.clone();
- for (int step_h = 0; step_h + stepY < height; step_h += stepY) {
- for (int step_w = 0; step_w + stepX < width; step_w += stepX) {
+ int offset = (int) (Math.random() * 5) + 1;
+ for (int i = 0; i < offset; i++) {
+ openOp(newByte, width, rect, i);
+ closeOp(newByte, width, rect, i);
+ }
+ return newByte;
+ }
+
+ private void openOp(byte[] newByte, int width, Rect rect, int offset) {
+
+ for (int step_h = rect.top + offset; step_h + stepY < rect.bottom; step_h += stepY) {
+ for (int step_w = rect.left + offset; step_w + stepX < rect.right; step_w += stepX) {
int count = 0;
int avage = 0;
+ int min = Integer.MAX_VALUE;
for (int y_ = step_h; y_ < step_h + stepY; y_++) {
for (int x_ = step_w; x_ < step_w + stepX; x_++) {
- if ((newByte[y_ * width + x_] & 0xff) < 130)
+ if ((newByte[y_ * width + x_] & 0xff) < 150)
count++;
avage += newByte[y_ * width + x_] & 0xff;
+ if ((newByte[y_ * width + x_] & 0xff) < min)
+ min = newByte[y_ * width + x_] & 0xff;
}
}
if (count == 0) {
continue;
}
+ avage /= stepY * stepX;
for (int y_ = step_h; y_ < step_h + stepY; y_++) {
for (int x_ = step_w; x_ < step_w + stepX; x_++) {
- if ((newByte[y_ * width + x_] & 0xff) > avage)
- newByte[y_ * width + x_] = (byte) ((avage & 0xff));
- else newByte[y_ * width + x_] = (byte) (newByte[y_ * width + x_] & 0xff);
+ newByte[y_ * width + x_] = (byte) (min / 5 * 4);
}
}
}
}
- return newByte;
}
- @Override
- public byte[] dispatch(byte[] data, int width, int height, Rect rect) {
- byte[] newByte = data.clone();
- int offset = (int) (Math.random() * 5);
-
+ private void closeOp(byte[] newByte, int width, Rect rect, int offset) {
for (int step_h = rect.top + offset; step_h + stepY < rect.bottom; step_h += stepY) {
for (int step_w = rect.left + offset; step_w + stepX < rect.right; step_w += stepX) {
int count = 0;
- int avage = 0;
+ int max = 0;
for (int y_ = step_h; y_ < step_h + stepY; y_++) {
for (int x_ = step_w; x_ < step_w + stepX; x_++) {
if ((newByte[y_ * width + x_] & 0xff) < 150)
count++;
- avage += newByte[y_ * width + x_] & 0xff;
+ if ((newByte[y_ * width + x_] & 0xff) > max)
+ max = newByte[y_ * width + x_] & 0xff;
+
}
}
- if (count < stepY * stepX / 4) {
+ if (count > stepX * stepY / 2) {
continue;
}
for (int y_ = step_h; y_ < step_h + stepY; y_++) {
for (int x_ = step_w; x_ < step_w + stepX; x_++) {
- if ((newByte[y_ * width + x_] & 0xff) > avage)
- newByte[y_ * width + x_] = (byte) ((avage & 0xff));
- else newByte[y_ * width + x_] = (byte) (newByte[y_ * width + x_] & 0xff);
+ newByte[y_ * width + x_] = (byte) max;
}
}
}
}
- return newByte;
}
+
}
diff --git a/module_grayscale/src/main/java/com/ailiwean/module_grayscale/InterruptGrayScale_.java b/module_grayscale/src/main/java/com/ailiwean/module_grayscale/InterruptGrayScale_.java
new file mode 100644
index 0000000..585fa3a
--- /dev/null
+++ b/module_grayscale/src/main/java/com/ailiwean/module_grayscale/InterruptGrayScale_.java
@@ -0,0 +1,348 @@
+package com.ailiwean.module_grayscale;
+
+import android.graphics.Rect;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @Package: com.ailiwean.module_grayscale
+ * @ClassName: InterruptScale
+ * @Description: 开闭操作
+ * @Author: SWY
+ * @CreateDate: 2020/9/12 10:14 PM
+ */
+class InterruptGrayScale_ implements Dispatch {
+
+ //结构元素步长
+ private int stepX = 10;
+ private int stepY = 10;
+
+ @Override
+ public byte[] dispatch(byte[] data, int width, int height) {
+ byte[] newByte = data.clone();
+ for (int step_h = 0; step_h + stepY < height; step_h += stepY) {
+ for (int step_w = 0; step_w + stepX < width; step_w += stepX) {
+ int count = 0;
+ int avage = 0;
+ for (int y_ = step_h; y_ < step_h + stepY; y_++) {
+ for (int x_ = step_w; x_ < step_w + stepX; x_++) {
+ if ((newByte[y_ * width + x_] & 0xff) < 130)
+ count++;
+ avage += newByte[y_ * width + x_] & 0xff;
+ }
+ }
+ if (count == 0) {
+ continue;
+ }
+ for (int y_ = step_h; y_ < step_h + stepY; y_++) {
+ for (int x_ = step_w; x_ < step_w + stepX; x_++) {
+ if ((newByte[y_ * width + x_] & 0xff) > avage)
+ newByte[y_ * width + x_] = (byte) ((avage & 0xff));
+ else newByte[y_ * width + x_] = (byte) (newByte[y_ * width + x_] & 0xff);
+ }
+ }
+ }
+ }
+ return newByte;
+ }
+
+ @Override
+ public byte[] dispatch(byte[] data, int width, int height, Rect rect) {
+ byte[] newByte = data.clone();
+
+// int offset = (int) (Math.random() * 3);
+// for (int i = 0; i < offset; i++) {
+// openOp(newByte, width, rect, i);
+// }
+// for (int i = 0; i < offset; i++) {
+// closeOp(newByte, width, rect, i);
+// }
+
+ byte[] binarizationByte = new byte[rect.width() * rect.height()];
+
+ int linkIndex = 0;
+ for (int start_h = rect.top; start_h < rect.bottom; start_h++) {
+ for (int start_w = rect.left; start_w < rect.right; start_w++) {
+ int index = start_h * width + start_w;
+ binarizationByte[linkIndex++] = newByte[index];
+ }
+ }
+ linkIndex = 0;
+ toBinarization(binarizationByte, rect.width(), rect.height());
+
+ for (int i = 0; i < 5; i++) {
+ openOp(binarizationByte, rect.width(), rect.height(), 0);
+ closeOp(binarizationByte, rect.width(), rect.height(), 0);
+ }
+
+ for (int start_h = rect.top; start_h < rect.bottom; start_h++) {
+ for (int start_w = rect.left; start_w < rect.right; start_w++) {
+ int index = start_h * width + start_w;
+ newByte[index] = binarizationByte[linkIndex++];
+ }
+ }
+
+
+// stepX = 2;
+// stepY = 2;
+// setA.clear();
+// for (int step_h = offset; step_h + stepY < height; step_h += 1) {
+// for (int step_w = offset; step_w + stepX < width; step_w += 1) {
+// int count = 0;
+// for (int y_ = step_h; y_ < step_h + stepY; y_++) {
+// for (int x_ = step_w; x_ < step_w + stepX; x_++) {
+//
+// if (y_ * width + x_ >= width * height)
+// continue;
+//
+// if ((newByte[y_ * width + x_] & 0xff) == 255)
+// count++;
+// }
+// }
+// if (count == 0) {
+// continue;
+// }
+//
+// for (int y_ = step_h; y_ < step_h + stepY; y_++) {
+// for (int x_ = step_w; x_ < step_w + stepX; x_++) {
+// setA.add(y_ * width + x_);
+// }
+// }
+// }
+// }
+//
+//// for (Integer integer : setA) {
+//// newByte[integer] = (byte) 255;
+//// }
+
+
+ return newByte;
+ }
+
+ private void openOp(byte[] newByte, int width, int height, int offset) {
+
+ Set set = new HashSet<>();
+
+ for (int step_h = offset; step_h + stepY < height; step_h += stepY) {
+ for (int step_w = offset; step_w + stepX < width; step_w += stepX) {
+ int count = 0;
+ for (int y_ = step_h; y_ < step_h + stepY; y_++) {
+ for (int x_ = step_w; x_ < step_w + stepX; x_++) {
+
+ if (y_ * width + x_ >= width * height)
+ return;
+
+ if ((newByte[y_ * width + x_] & 0xff) == 0)
+ count++;
+ }
+ }
+ if (count == 0) {
+ continue;
+ }
+ for (int y_ = step_h; y_ < step_h + stepY; y_++) {
+ for (int x_ = step_w; x_ < step_w + stepX; x_++) {
+ set.add(y_ * width + x_);
+// newByte[y_ * width + x_] = 0;
+ }
+ }
+ }
+ }
+
+ for (int index : set) {
+ newByte[index] = 0;
+ }
+
+ }
+
+ private void closeOp(byte[] newByte, int width, int height, int offset) {
+
+
+ Set set = new HashSet<>();
+
+ for (int step_h = offset; step_h + stepY < height; step_h += stepY) {
+ for (int step_w = offset; step_w + stepX < width; step_w += stepX) {
+ int count = 0;
+ for (int y_ = step_h; y_ < step_h + stepY; y_++) {
+ for (int x_ = step_w; x_ < step_w + stepX; x_++) {
+
+
+ if (y_ * width + x_ >= width * height)
+ return;
+
+ if ((newByte[y_ * width + x_] & 0xff) == 255)
+ count++;
+ }
+ }
+ if (count == 0) {
+ continue;
+ }
+ for (int y_ = step_h; y_ < step_h + stepY; y_++) {
+ for (int x_ = step_w; x_ < step_w + stepX; x_++) {
+ set.add(y_ * width + x_);
+ }
+ }
+ }
+ }
+
+ for (int index : set) {
+ newByte[index] = (byte) 255;
+ }
+
+ }
+
+
+ // This class uses 5x5 blocks to compute local luminance, where each block is 8x8 pixels.
+ // So this is the smallest dimension in each axis we can accept.
+ private static final int BLOCK_SIZE_POWER = 2;
+ private static final int BLOCK_SIZE = 1 << BLOCK_SIZE_POWER; // ...0100...00
+ private static final int BLOCK_SIZE_MASK = BLOCK_SIZE - 1; // ...0011...11
+ private static final int MINIMUM_DIMENSION = BLOCK_SIZE * 5;
+ private static final int MIN_DYNAMIC_RANGE = 24;
+
+
+ private void toBinarization(byte[] luminances, int width, int height) {
+ int subWidth = width >> BLOCK_SIZE_POWER;
+ if ((width & BLOCK_SIZE_MASK) != 0) {
+ subWidth++;
+ }
+ int subHeight = height >> BLOCK_SIZE_POWER;
+ if ((height & BLOCK_SIZE_MASK) != 0) {
+ subHeight++;
+ }
+ int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height);
+
+ calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints);
+ }
+
+
+ private int[][] calculateBlackPoints(byte[] luminances,
+ int subWidth,
+ int subHeight,
+ int width,
+ int height) {
+ int maxYOffset = height - BLOCK_SIZE;
+ int maxXOffset = width - BLOCK_SIZE;
+ int[][] blackPoints = new int[subHeight][subWidth];
+ for (int y = 0; y < subHeight; y++) {
+ int yoffset = y << BLOCK_SIZE_POWER;
+ if (yoffset > maxYOffset) {
+ yoffset = maxYOffset;
+ }
+ for (int x = 0; x < subWidth; x++) {
+ int xoffset = x << BLOCK_SIZE_POWER;
+ if (xoffset > maxXOffset) {
+ xoffset = maxXOffset;
+ }
+ int sum = 0;
+ int min = 0xFF;
+ int max = 0;
+ for (int yy = 0, offset = yoffset * width + xoffset; yy < BLOCK_SIZE; yy++, offset += width) {
+ for (int xx = 0; xx < BLOCK_SIZE; xx++) {
+ int pixel = luminances[offset + xx] & 0xFF;
+ sum += pixel;
+ // still looking for good contrast
+ if (pixel < min) {
+ min = pixel;
+ }
+ if (pixel > max) {
+ max = pixel;
+ }
+ }
+ // short-circuit min/max tests once dynamic range is met
+ if (max - min > MIN_DYNAMIC_RANGE) {
+ // finish the rest of the rows quickly
+ for (yy++, offset += width; yy < BLOCK_SIZE; yy++, offset += width) {
+ for (int xx = 0; xx < BLOCK_SIZE; xx++) {
+ sum += luminances[offset + xx] & 0xFF;
+ }
+ }
+ }
+ }
+
+ // The default estimate is the average of the values in the block.
+ int average = sum >> (BLOCK_SIZE_POWER * 2);
+ if (max - min <= MIN_DYNAMIC_RANGE) {
+ // If variation within the block is low, assume this is a block with only light or only
+ // dark pixels. In that case we do not want to use the average, as it would divide this
+ // low contrast area into black and white pixels, essentially creating data out of noise.
+ //
+ // The default assumption is that the block is light/background. Since no estimate for
+ // the level of dark pixels exists locally, use half the min for the block.
+ average = min / 2;
+
+ if (y > 0 && x > 0) {
+ // Correct the "white background" assumption for blocks that have neighbors by comparing
+ // the pixels in this block to the previously calculated black points. This is based on
+ // the fact that dark barcode symbology is always surrounded by some amount of light
+ // background for which reasonable black point estimates were made. The bp estimated at
+ // the boundaries is used for the interior.
+
+ // The (min < bp) is arbitrary but works better than other heuristics that were tried.
+ int averageNeighborBlackPoint =
+ (blackPoints[y - 1][x] + (2 * blackPoints[y][x - 1]) + blackPoints[y - 1][x - 1]) / 4;
+ if (min < averageNeighborBlackPoint) {
+ average = averageNeighborBlackPoint;
+ }
+ }
+ }
+ blackPoints[y][x] = average;
+ }
+ }
+ return blackPoints;
+ }
+
+
+ private void calculateThresholdForBlock(byte[] luminances,
+ int subWidth,
+ int subHeight,
+ int width,
+ int height,
+ int[][] blackPoints) {
+ int maxYOffset = height - BLOCK_SIZE;
+ int maxXOffset = width - BLOCK_SIZE;
+ for (int y = 0; y < subHeight; y++) {
+ int yoffset = y << BLOCK_SIZE_POWER;
+ if (yoffset > maxYOffset) {
+ yoffset = maxYOffset;
+ }
+ int top = cap(y, subHeight - 3);
+ for (int x = 0; x < subWidth; x++) {
+ int xoffset = x << BLOCK_SIZE_POWER;
+ if (xoffset > maxXOffset) {
+ xoffset = maxXOffset;
+ }
+ int left = cap(x, subWidth - 3);
+ int sum = 0;
+ for (int z = -2; z <= 2; z++) {
+ int[] blackRow = blackPoints[top + z];
+ sum += blackRow[left - 2] + blackRow[left - 1] + blackRow[left] + blackRow[left + 1] + blackRow[left + 2];
+ }
+ int average = sum / 25;
+ thresholdBlock(luminances, xoffset, yoffset, average, width);
+ }
+ }
+ }
+
+ private int cap(int value, int max) {
+ return value < 2 ? 2 : Math.min(value, max);
+ }
+
+ private void thresholdBlock(byte[] luminances,
+ int xoffset,
+ int yoffset,
+ int threshold,
+ int stride) {
+ for (int y = 0, offset = yoffset * stride + xoffset; y < BLOCK_SIZE; y++, offset += stride) {
+ for (int x = 0; x < BLOCK_SIZE; x++) {
+ // Comparison needs to be <= so that black == 0 pixels are black even if the threshold is 0.
+ if ((luminances[offset + x] & 0xFF) <= threshold) {
+ // matrix.set(xoffset + x, yoffset + y);
+ //luminances[(yoffset + y) * ((stride + 31) / 32) + ((xoffset + x) / 32)] = 0;
+ luminances[offset + x] = 0;
+ } else luminances[offset + x] = (byte) 255;
+ }
+ }
+ }
+
+}
diff --git a/module_grayscale/src/main/java/com/ailiwean/module_grayscale/ReductionAreaScale.java b/module_grayscale/src/main/java/com/ailiwean/module_grayscale/ReductionAreaScale.java
index 127df57..b80dfea 100644
--- a/module_grayscale/src/main/java/com/ailiwean/module_grayscale/ReductionAreaScale.java
+++ b/module_grayscale/src/main/java/com/ailiwean/module_grayscale/ReductionAreaScale.java
@@ -12,12 +12,14 @@
*/
class ReductionAreaScale implements Dispatch {
- GrayScaleDispatch dispatch;
+ GrayScaleDispatch grayScaleDispatch;
+
ReductionAreaScale(GrayScaleDispatch dispatch) {
- this.dispatch = dispatch;
+ this.grayScaleDispatch = dispatch;
}
+
@Override
public byte[] dispatch(byte[] data, int width, int height) {
return data;
@@ -28,8 +30,7 @@ public byte[] dispatch(byte[] data, int width, int height, Rect rect) {
byte[] newByte = data.clone();
byte[] emptyByte = new byte[rect.width() * rect.height()];
int areaSize = 0;
-// double step = Math.random() * 2 + 1;
- double step = 3;
+ double step = Math.random() * 2 + 1;
int reductWidth, reductHeight = 0;
@@ -58,6 +59,6 @@ public byte[] dispatch(byte[] data, int width, int height, Rect rect) {
}
}
- return dispatch.dispatch(newByte, width, height, rect);
+ return grayScaleDispatch.dispatch(newByte, width, height, rect);
}
}