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
public interface SessionManager { | |
void startSession(int timeoutMillis); | |
void keepAlive(); | |
void stopSession(); | |
void checkSession(); |
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
fun turnOnNfc() { | |
runBlocking { | |
var count = 0 | |
NfcAdapter.getDefaultAdapter(get())?.run { | |
enableNfc() | |
while (!isEnabled) { | |
Log.i("TAG", "Waiting for NFC adapter to turn on") | |
delay(200) | |
count += 1 | |
if(count > 10) { |
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
val hardwareId | |
get() = "getprop ro.hardware".runAsCommand().trim() | |
fun setSystemUIVisibility(show: Boolean) { | |
GlobalScope.launch { | |
if (show) { | |
if(hardwareId.equals("qcom")) { // ZPAD Plus 4G (7.1.1) | |
"am broadcast -a com.android.zkteco.SHOW_NAVIGATION".runAsCommand() | |
"am broadcast -a com.android.zkteco.SHOW_STATUS".runAsCommand() | |
} else { // ZPAD Plus (6.0.1) |
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
fun <T> Fragment.collectLifecycleFlow(flow: Flow<T>, collect: suspend (T) -> Unit){ | |
viewLifecycleOwner.lifecycleScope.launch { | |
repeatOnLifecycle(Lifecycle.State.STARTED){ | |
flow.collectLatest(collect) | |
} | |
} | |
} |
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
// We have RfidListener interface where you can get callback when a card is punched. | |
// This class has two methods: | |
// fun onRfidRead(rfidInfo : String) | |
// fun onRfidReadWithOldValue(rfidInfo : String, oldRfidInfo: String, useRfidStandardization: Boolean) | |
// onRfidRead method is used right now to get card value from SDK but due to some reasons such as supporting new card types etc... | |
// We have to update old card values with new ones using onRfidReadWithOldValue function | |
// Launcher applications are good place to handle with update process at least we update old values in that application. | |
// You have to override onRfidReadWithOldValue function in order to update old values and call | |
// super.onRfidReadWithOldValue function after update process | |
// I am sharing code snippet from our implementation |
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
import android.app.AlarmManager | |
import android.app.PendingIntent | |
import android.content.BroadcastReceiver | |
import android.content.Context | |
import android.content.Intent | |
import android.content.IntentFilter | |
import android.os.SystemClock | |
import android.util.Log | |
import com.zk.android.constant.SdkException | |
import kotlinx.coroutines.GlobalScope |
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
private val rebootCodesArray = intArrayOf(-1500, -1501, -1502, -4010) | |
private val resetMcuInterval = 25000 | |
private var isReOpenDevice = false | |
private var lastResetTime = 0L | |
//Check error code after calling checkCardEx(buffer) and if there is a error reset it | |
//////// This block has to be called after checkCardEx(buffer) | |
(errorCode != -4013).ifTrue { | |
"Error $errorCode checking card ID".log(TAG) | |
} |
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
enum class Sport { HIKE, RUN, TOURING_BICYCLE, E_TOURING_BICYCLE } | |
data class Summary(val sport: Sport, val distance: Int) | |
fun main() { | |
val sportStats = listOf(Summary(Sport.HIKE, 92), | |
Summary(Sport.RUN, 77), | |
Summary(Sport.TOURING_BICYCLE, 322), | |
Summary(Sport.E_TOURING_BICYCLE, 656)) | |
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
object ZipManager { | |
fun zip(files: List<File>, zipFile: File) { | |
ZipOutputStream(BufferedOutputStream(FileOutputStream(zipFile))).use { output -> | |
files.forEach { file -> | |
(file.length() > 1).ifTrue { | |
FileInputStream(file).use { input -> | |
BufferedInputStream(input).use { origin -> | |
val entry = ZipEntry(file.name.toRealName()) | |
output.putNextEntry(entry) |
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
parse_config_values() { | |
serial_obtained=false | |
shift | |
while [[ $# -gt 1 ]]; do | |
case "$1" in | |
--serial) | |
config_serial=$2 | |
echo $config_serial | |
serial_obtained=true |
NewerOlder