Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
222765ea
authored
Aug 03, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ButtonTask替换为kotlin
parent
29fa5e2b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
68 deletions
+49
-68
app/src/main/java/com/bgycc/smartcanteen/task/ButtonTask.java
+0
-68
app/src/main/java/com/bgycc/smartcanteen/task/ButtonTask.kt
+49
-0
No files found.
app/src/main/java/com/bgycc/smartcanteen/task/ButtonTask.java
deleted
100644 → 0
View file @
29fa5e2b
package
com
.
bgycc
.
smartcanteen
.
task
;
import
android.content.Context
;
import
android.media.AudioManager
;
import
android.util.Log
;
import
com.bgycc.smartcanteen.App
;
import
com.szxb.jni.libszxb
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
public
class
ButtonTask
{
private
static
final
String
TAG
=
ButtonTask
.
class
.
getSimpleName
();
private
static
ButtonTask
sInstance
;
public
static
synchronized
ButtonTask
getInstance
()
{
if
(
sInstance
==
null
)
{
sInstance
=
new
ButtonTask
();
}
return
sInstance
;
}
private
ScheduledExecutorService
mScanExec
;
private
AudioManager
mAudioManager
;
private
ButtonTask
()
{}
public
void
start
()
{
if
(
mScanExec
==
null
)
{
mAudioManager
=
(
AudioManager
)
App
.
Companion
.
getDefault
().
getSystemService
(
Context
.
AUDIO_SERVICE
);
mScanExec
=
Executors
.
newSingleThreadScheduledExecutor
();
mScanExec
.
scheduleAtFixedRate
(
new
LoopTimerTask
(),
0
,
200
,
TimeUnit
.
MILLISECONDS
);
}
}
public
void
stop
()
{
mAudioManager
=
null
;
if
(
mScanExec
!=
null
)
{
mScanExec
.
shutdown
();
mScanExec
=
null
;
}
}
private
class
LoopTimerTask
extends
TimerTask
{
@Override
public
void
run
()
{
try
{
byte
[]
buf
=
new
byte
[
5
];
libszxb
.
devicekey
(
buf
);
// Log.i(TAG, String.format("%02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3]));
if
(
buf
[
1
]
==
1
)
{
mAudioManager
.
adjustStreamVolume
(
AudioManager
.
STREAM_SYSTEM
,
AudioManager
.
ADJUST_RAISE
,
AudioManager
.
FLAG_SHOW_UI
);
}
if
(
buf
[
2
]
==
1
)
{
mAudioManager
.
adjustStreamVolume
(
AudioManager
.
STREAM_SYSTEM
,
AudioManager
.
ADJUST_LOWER
,
AudioManager
.
FLAG_SHOW_UI
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
app/src/main/java/com/bgycc/smartcanteen/task/ButtonTask.kt
0 → 100644
View file @
222765ea
package
com.bgycc.smartcanteen.task
import
android.content.Context
import
android.media.AudioManager
import
android.util.Log
import
com.bgycc.smartcanteen.App
import
com.bgycc.smartcanteen.helper.TimerHelper
import
com.szxb.jni.libszxb
object
ButtonTask
{
private
val
TAG
=
ButtonTask
::
class
.
java
.
simpleName
private
var
mTimerId
:
Long
=
-
1
private
var
mAudioManager
:
AudioManager
?
=
null
fun
start
()
{
if
(
mTimerId
<
0
)
{
mAudioManager
=
App
.
getDefault
().
getSystemService
(
Context
.
AUDIO_SERVICE
)
as
AudioManager
mTimerId
=
TimerHelper
.
loop
({
val
buf
=
ByteArray
(
5
)
libszxb
.
devicekey
(
buf
)
Log
.
i
(
TAG
,
String
.
format
(
"%02x %02x %02x %02x"
,
buf
[
0
],
buf
[
1
],
buf
[
2
],
buf
[
3
]));
if
(
buf
[
1
].
toInt
()
==
1
)
{
mAudioManager
!!
.
adjustStreamVolume
(
AudioManager
.
STREAM_SYSTEM
,
AudioManager
.
ADJUST_RAISE
,
AudioManager
.
FLAG_SHOW_UI
)
}
if
(
buf
[
2
].
toInt
()
==
1
)
{
mAudioManager
!!
.
adjustStreamVolume
(
AudioManager
.
STREAM_SYSTEM
,
AudioManager
.
ADJUST_LOWER
,
AudioManager
.
FLAG_SHOW_UI
)
}
true
},
200
)
}
}
fun
stop
()
{
mAudioManager
=
null
TimerHelper
.
cancel
(
mTimerId
)
mTimerId
=
-
1
}
}
\ No newline at end of file
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