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 @@