Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MiYaFastCashier
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangjiantao
MiYaFastCashier
Commits
14a115b3
Commit
14a115b3
authored
Jan 13, 2022
by
jiangjiantao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev
parent
7a78f29f
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
297 additions
and
9 deletions
+297
-9
build.gradle
app/build.gradle
+2
-1
CodeScanDialog.java
...main/java/com/miya/fastcashier/dialog/CodeScanDialog.java
+72
-0
MainActivity.kt
...rc/main/java/com/miya/fastcashier/ui/main/MainActivity.kt
+10
-6
ScanGunKeyEventHelper.java
...ava/com/miya/fastcashier/utils/ScanGunKeyEventHelper.java
+132
-0
MainViewModel.kt
...main/java/com/miya/fastcashier/viewmodel/MainViewModel.kt
+21
-2
in_bottom.xml
app/src/main/res/anim/in_bottom.xml
+8
-0
in_right.xml
app/src/main/res/anim/in_right.xml
+8
-0
out_bottom.xml
app/src/main/res/anim/out_bottom.xml
+8
-0
out_left.xml
app/src/main/res/anim/out_left.xml
+8
-0
activity_main.xml
app/src/main/res/layout/activity_main.xml
+0
-0
dialog_code_scan.xml
app/src/main/res/layout/dialog_code_scan.xml
+21
-0
styles.xml
app/src/main/res/values/styles.xml
+6
-0
settings.gradle
settings.gradle
+1
-0
No files found.
app/build.gradle
View file @
14a115b3
...
@@ -37,7 +37,7 @@ android {
...
@@ -37,7 +37,7 @@ android {
dependencies
{
dependencies
{
implementation
fileTree
(
include:
[
'*.jar'
],
dir:
'libs'
)
implementation
fileTree
(
include:
[
'*.jar'
],
dir:
'libs'
)
implementation
"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
//
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation
'androidx.core:core-ktx:1.3.1'
implementation
'androidx.core:core-ktx:1.3.1'
implementation
'androidx.appcompat:appcompat:1.2.0'
implementation
'androidx.appcompat:appcompat:1.2.0'
implementation
'com.google.android.material:material:1.2.1'
implementation
'com.google.android.material:material:1.2.1'
...
@@ -47,6 +47,7 @@ dependencies {
...
@@ -47,6 +47,7 @@ dependencies {
implementation
(
"com.squareup.okhttp3:okhttp:4.9.3"
)
implementation
(
"com.squareup.okhttp3:okhttp:4.9.3"
)
implementation
(
"com.squareup.okhttp3:logging-interceptor:3.9.0"
)
implementation
(
"com.squareup.okhttp3:logging-interceptor:3.9.0"
)
implementation
(
"com.squareup.retrofit2:retrofit:2.9.0"
)
implementation
(
"com.squareup.retrofit2:retrofit:2.9.0"
)
implementation
(
"com.google.android.material:material:1.2.0"
)
implementation
'androidx.annotation:annotation:1.1.0'
implementation
'androidx.annotation:annotation:1.1.0'
testImplementation
'junit:junit:4.+'
testImplementation
'junit:junit:4.+'
implementation
'com.squareup.retrofit2:converter-gson:2.9.0'
implementation
'com.squareup.retrofit2:converter-gson:2.9.0'
...
...
app/src/main/java/com/miya/fastcashier/dialog/CodeScanDialog.java
0 → 100644
View file @
14a115b3
package
com
.
miya
.
fastcashier
.
dialog
;
import
android.app.Dialog
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.text.TextUtils
;
import
android.view.Gravity
;
import
android.view.KeyEvent
;
import
android.view.View
;
import
android.view.Window
;
import
android.view.WindowManager
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
androidx.constraintlayout.widget.Group
;
import
com.miya.fastcashier.R
;
import
com.miya.fastcashier.utils.ScanGunKeyEventHelper
;
public
class
CodeScanDialog
extends
Dialog
implements
DialogInterface
.
OnDismissListener
{
private
final
ScanGunKeyEventHelper
scanGunKeyEventHelper
;
private
OnScanListener
listener
;
public
CodeScanDialog
(
Context
context
)
{
super
(
context
);
initWindow
();
setContentView
(
R
.
layout
.
dialog_code_scan
);
setCanceledOnTouchOutside
(
false
);
setOnDismissListener
(
this
);
scanGunKeyEventHelper
=
new
ScanGunKeyEventHelper
();
scanGunKeyEventHelper
.
setOnBarCodeCatchListener
(
barcode
->
{
if
(
listener
!=
null
)
{
listener
.
onScan
(
barcode
);
}
});
}
@Override
public
boolean
dispatchKeyEvent
(
KeyEvent
event
)
{
scanGunKeyEventHelper
.
analysisKeyEvent
(
event
);
return
true
;
}
private
void
initWindow
()
{
Window
win
=
this
.
getWindow
();
win
.
getDecorView
().
setPadding
(
0
,
0
,
0
,
0
);
WindowManager
.
LayoutParams
lp
=
win
.
getAttributes
();
lp
.
width
=
WindowManager
.
LayoutParams
.
MATCH_PARENT
;
lp
.
height
=
WindowManager
.
LayoutParams
.
WRAP_CONTENT
;
lp
.
gravity
=
Gravity
.
BOTTOM
;
lp
.
windowAnimations
=
R
.
style
.
BottomInAndOutStyle
;
win
.
setAttributes
(
lp
);
win
.
setBackgroundDrawableResource
(
android
.
R
.
color
.
transparent
);
}
public
void
setOnScanListener
(
OnScanListener
listener
)
{
this
.
listener
=
listener
;
}
@Override
public
void
onDismiss
(
DialogInterface
dialogInterface
)
{
if
(
scanGunKeyEventHelper
!=
null
)
{
scanGunKeyEventHelper
.
onDestroy
();
}
}
public
interface
OnScanListener
{
void
onScan
(
String
result
);
}
}
app/src/main/java/com/miya/fastcashier/ui/main/MainActivity.kt
View file @
14a115b3
...
@@ -4,18 +4,22 @@ import androidx.appcompat.app.AppCompatActivity
...
@@ -4,18 +4,22 @@ import androidx.appcompat.app.AppCompatActivity
import
android.os.Bundle
import
android.os.Bundle
import
androidx.lifecycle.ViewModelProvider
import
androidx.lifecycle.ViewModelProvider
import
com.miya.fastcashier.R
import
com.miya.fastcashier.R
import
com.miya.fastcashier.viewmodel.MainViewModel
import
com.miya.fastcashier.dialog.CodeScanDialog
import
com.miya.fastcashier.viewmodel.PayViewModel
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
private
lateinit
var
viewModel
:
MainViewModel
private
lateinit
var
viewModel
:
PayViewModel
private
lateinit
var
scanDialog
:
CodeScanDialog
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
main_activity
)
setContentView
(
R
.
layout
.
activity_main
)
viewModel
=
ViewModelProvider
(
this
).
get
(
MainViewModel
::
class
.
java
)
viewModel
=
ViewModelProvider
(
this
).
get
(
PayViewModel
::
class
.
java
)
scanDialog
=
CodeScanDialog
(
this
);
scanDialog
.
setOnScanListener
{
viewModel
.
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/utils/ScanGunKeyEventHelper.java
0 → 100644
View file @
14a115b3
package
com
.
miya
.
fastcashier
.
utils
;
import
android.os.Handler
;
import
android.text.TextUtils
;
import
android.view.KeyEvent
;
/**
* 扫码枪解码器
* Created by fengyu on 2018/1/12.
*/
public
class
ScanGunKeyEventHelper
{
//延迟500ms,判断扫码是否完成。
private
final
static
long
MESSAGE_DELAY
=
500
;
//扫码内容
private
final
StringBuffer
mStringBufferResult
=
new
StringBuffer
();
//大小写区分
private
boolean
mCaps
;
private
OnScanSuccessListener
mOnScanSuccessListener
;
private
final
Handler
mHandler
=
new
Handler
();
private
final
Runnable
mScanningFishedRunnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
performScanSuccess
();
}
};
//返回扫描结果
private
void
performScanSuccess
()
{
String
barcode
=
mStringBufferResult
.
toString
();
if
(
mOnScanSuccessListener
!=
null
&&
!
TextUtils
.
isEmpty
(
barcode
))
mOnScanSuccessListener
.
onScanSuccess
(
barcode
);
mStringBufferResult
.
setLength
(
0
);
}
//key事件处理
public
void
analysisKeyEvent
(
KeyEvent
event
)
{
int
keyCode
=
event
.
getKeyCode
();
//字母大小写判断
checkLetterStatus
(
event
);
if
(
event
.
getAction
()
==
KeyEvent
.
ACTION_DOWN
)
{
char
aChar
=
getInputCode
(
event
);
if
(
keyCode
==
KeyEvent
.
KEYCODE_ENTER
)
{
//若为回车键,直接返回
mHandler
.
removeCallbacks
(
mScanningFishedRunnable
);
mHandler
.
post
(
mScanningFishedRunnable
);
}
else
{
if
(
aChar
!=
0
)
{
mStringBufferResult
.
append
(
aChar
);
}
//延迟post,若500ms内,有其他事件
mHandler
.
removeCallbacks
(
mScanningFishedRunnable
);
mHandler
.
postDelayed
(
mScanningFishedRunnable
,
MESSAGE_DELAY
);
}
}
}
//检查shift键
private
void
checkLetterStatus
(
KeyEvent
event
)
{
int
keyCode
=
event
.
getKeyCode
();
if
(
keyCode
==
KeyEvent
.
KEYCODE_SHIFT_RIGHT
||
keyCode
==
KeyEvent
.
KEYCODE_SHIFT_LEFT
)
{
if
(
event
.
getAction
()
==
KeyEvent
.
ACTION_DOWN
)
{
//按着shift键,表示大写
mCaps
=
true
;
}
else
{
//松开shift键,表示小写
mCaps
=
false
;
}
}
}
//获取扫描内容
private
char
getInputCode
(
KeyEvent
event
)
{
int
keyCode
=
event
.
getKeyCode
();
char
aChar
;
if
(
keyCode
>=
KeyEvent
.
KEYCODE_A
&&
keyCode
<=
KeyEvent
.
KEYCODE_Z
)
{
//字母
aChar
=
(
char
)
((
mCaps
?
'A'
:
'a'
)
+
keyCode
-
KeyEvent
.
KEYCODE_A
);
}
else
if
(
keyCode
>=
KeyEvent
.
KEYCODE_0
&&
keyCode
<=
KeyEvent
.
KEYCODE_9
)
{
//数字
aChar
=
(
char
)
(
'0'
+
keyCode
-
KeyEvent
.
KEYCODE_0
);
}
else
{
//其他符号
switch
(
keyCode
)
{
case
KeyEvent
.
KEYCODE_PERIOD
:
aChar
=
'.'
;
break
;
case
KeyEvent
.
KEYCODE_MINUS
:
aChar
=
mCaps
?
'_'
:
'-'
;
break
;
case
KeyEvent
.
KEYCODE_SLASH
:
aChar
=
'/'
;
break
;
case
KeyEvent
.
KEYCODE_BACKSLASH
:
aChar
=
mCaps
?
'|'
:
'\\'
;
break
;
default
:
aChar
=
0
;
break
;
}
}
return
aChar
;
}
public
interface
OnScanSuccessListener
{
public
void
onScanSuccess
(
String
barcode
);
}
public
void
setOnBarCodeCatchListener
(
OnScanSuccessListener
onScanSuccessListener
)
{
mOnScanSuccessListener
=
onScanSuccessListener
;
}
public
void
onDestroy
()
{
mHandler
.
removeCallbacks
(
mScanningFishedRunnable
);
mOnScanSuccessListener
=
null
;
}
}
app/src/main/java/com/miya/fastcashier/viewmodel/MainViewModel.kt
View file @
14a115b3
package
com.miya.fastcashier.viewmodel
package
com.miya.fastcashier.viewmodel
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.viewModelScope
import
com.miya.fastcashier.beans.LoginRequest
import
com.miya.fastcashier.service.LoginService
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.async
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
class
PayViewModel
:
ViewModel
()
{
fun
refund
(
userName
:
String
,
passWord
:
String
)
{
viewModelScope
.
launch
{
val
refundResult
=
async
(
Dispatchers
.
IO
)
{
booksRepository
.
getAllBooks
()
}
refundResult
,
}
}
class
MainViewModel
:
ViewModel
()
{
// TODO: Implement the ViewModel
}
}
\ No newline at end of file
app/src/main/res/anim/in_bottom.xml
0 → 100644
View file @
14a115b3
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<translate
android:duration=
"300"
android:fromYDelta=
"100%p"
android:toYDelta=
"0"
/>
</set>
app/src/main/res/anim/in_right.xml
0 → 100644
View file @
14a115b3
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<translate
android:duration=
"300"
android:fromXDelta=
"100%p"
android:toXDelta=
"0"
/>
</set>
app/src/main/res/anim/out_bottom.xml
0 → 100644
View file @
14a115b3
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<translate
android:duration=
"300"
android:fromYDelta=
"0"
android:toYDelta=
"100%p"
/>
</set>
app/src/main/res/anim/out_left.xml
0 → 100644
View file @
14a115b3
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<translate
android:duration=
"300"
android:fromXDelta=
"0"
android:toXDelta=
"-100%p"
/>
</set>
app/src/main/res/layout/
main_activity
.xml
→
app/src/main/res/layout/
activity_main
.xml
View file @
14a115b3
File moved
app/src/main/res/layout/dialog_code_scan.xml
0 → 100644
View file @
14a115b3
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/main"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<TextView
android:id=
"@+id/tvRefund"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"请扫码退款"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.498"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintVertical_bias=
"0.258"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/values/styles.xml
0 → 100644
View file @
14a115b3
<resources>
<style
name=
"BottomInAndOutStyle"
>
<item
name=
"android:windowEnterAnimation"
>
@anim/in_bottom
</item>
<item
name=
"android:windowExitAnimation"
>
@anim/out_bottom
</item>
</style>
</resources>
settings.gradle
View file @
14a115b3
rootProject
.
name
=
"MiYaFastCashier"
rootProject
.
name
=
"MiYaFastCashier"
include
':app'
include
':app'
include
':core'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment