forked from mintware-de/flutter_barcode_reader
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mergeMerge branch 'master' of https://github.com/dupengw3/flutter_bar…
- Loading branch information
Showing
24 changed files
with
293 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
android/src/main/kotlin/de/mintware/barcode_scan/CustomViewFinderView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package de.mintware.barcode_scan | ||
|
||
import android.animation.ValueAnimator | ||
import android.animation.ValueAnimator.INFINITE | ||
import android.animation.ValueAnimator.RESTART | ||
import android.content.Context | ||
import android.content.res.Resources | ||
import android.graphics.* | ||
import android.os.Build | ||
import android.util.Log | ||
import android.view.View | ||
import android.view.animation.AccelerateInterpolator | ||
import android.view.animation.LinearInterpolator | ||
import androidx.annotation.RequiresApi | ||
import me.dm7.barcodescanner.core.ViewFinderView | ||
import kotlin.math.roundToInt | ||
|
||
/** | ||
* Created on 2020/7/21. | ||
* 包名:de.mintware.barcode_scan | ||
* @author 李舰舸 <[email protected]> | ||
*/ | ||
class CustomViewFinderView(context: Context) : ViewFinderView(context) { | ||
|
||
private var currentAnimValue: Float = 0f | ||
private var laser : Bitmap | ||
private val animator: ValueAnimator | ||
|
||
init { | ||
setLayerType(LAYER_TYPE_SOFTWARE, null); | ||
setBorderColor(Color.parseColor("#3EBADE")) | ||
setSquareViewFinder(true) | ||
setBorderLineLength((Resources.getSystem().displayMetrics.density * 15).toInt()) | ||
setLaserEnabled(true) | ||
laser = BitmapFactory.decodeResource(resources, R.drawable.laser) | ||
|
||
animator = ValueAnimator.ofFloat(0f, 1f) | ||
animator.addUpdateListener { animation -> | ||
currentAnimValue = animation.animatedValue as Float | ||
invalidate() | ||
} | ||
animator.duration = 2000 | ||
animator.interpolator = LinearInterpolator() | ||
animator.repeatMode = RESTART | ||
animator.repeatCount = INFINITE | ||
animator.startDelay = 500 | ||
animator.start() | ||
} | ||
|
||
override fun drawLaser(canvas: Canvas?) { | ||
val total = framingRect.height() + laser.height | ||
val percent = (laser.height.toFloat() / total) | ||
var laserheight = laser.height.toFloat() | ||
if (currentAnimValue < percent || currentAnimValue > (1 - percent)) { | ||
val tempValue = if (currentAnimValue > 0.5) 1 - currentAnimValue else currentAnimValue | ||
laserheight *= tempValue / percent | ||
} | ||
mLaserPaint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_OVER) | ||
val rect = Rect() | ||
rect.top = (framingRect.top - laserheight + currentAnimValue * (framingRect.height() + laserheight)).toInt() | ||
rect.left = framingRect.left | ||
rect.right = framingRect.right | ||
rect.bottom = (framingRect.top + currentAnimValue * (framingRect.height() + laserheight)).toInt() | ||
canvas?.drawBitmap(laser, null, rect, mLaserPaint) | ||
} | ||
|
||
override fun onWindowVisibilityChanged(visibility: Int) { | ||
if (visibility == View.GONE) { | ||
animator.removeAllListeners() | ||
animator.cancel() | ||
} | ||
super.onWindowVisibilityChanged(visibility) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
|
||
<de.mintware.barcode_scan.ZXingAutofocusScannerView | ||
android:id="@+id/scannerView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"/> | ||
|
||
<LinearLayout | ||
android:layout_gravity="top" | ||
android:theme="@style/Theme.MaterialComponents" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:fitsSystemWindows="true" | ||
android:gravity="center_vertical"> | ||
<ImageView | ||
android:id="@+id/back" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingVertical="12dp" | ||
android:paddingLeft="16dp" | ||
android:paddingRight="4dp" | ||
android:src="@drawable/icon_back"/> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/add_search_switch" | ||
android:textSize="16sp" | ||
android:textColor="@android:color/white"/> | ||
</LinearLayout> | ||
|
||
<LinearLayout | ||
android:layout_gravity="bottom" | ||
android:orientation="horizontal" | ||
android:background="#80000000" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<LinearLayout | ||
android:id="@+id/hand_input" | ||
android:orientation="vertical" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:layout_weight="1"> | ||
|
||
<ImageView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="18dp" | ||
android:src="@drawable/icon_input"/> | ||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="4dp" | ||
android:layout_marginBottom="12dp" | ||
android:text="@string/hand_input" | ||
android:textSize="16sp" | ||
android:textColor="#80FFFFFF"/> | ||
|
||
</LinearLayout> | ||
|
||
<LinearLayout | ||
android:id="@+id/flashlight" | ||
android:orientation="vertical" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:layout_weight="1"> | ||
|
||
<ImageView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="18dp" | ||
android:src="@drawable/icon_light"/> | ||
|
||
<TextView | ||
android:id="@+id/tv_flashlight" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="4dp" | ||
android:layout_marginBottom="12dp" | ||
android:text="@string/open_flashlight" | ||
android:textSize="16sp" | ||
android:textColor="#80FFFFFF"/> | ||
|
||
</LinearLayout> | ||
|
||
|
||
</LinearLayout> | ||
|
||
|
||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> | ||
<item name="android:windowTranslucentStatus">true</item> | ||
<item name="android:windowTranslucentNavigation">true</item> | ||
</style> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> | ||
<item name="android:windowTranslucentStatus">true</item> | ||
<item name="android:windowTranslucentNavigation">true</item> | ||
<!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色--> | ||
<item name="android:statusBarColor">@android:color/transparent</item> | ||
</style> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="hand_input">手动输入</string> | ||
<string name="open_flashlight">打开手电筒</string> | ||
<string name="close_flashlight">关闭手电筒</string> | ||
<string name="add_search_switch">添加/查询母开关</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar" /> | ||
</resources> |
Oops, something went wrong.