1
1
package com.thanksmister.iot.mqtt.alarmpanel.ui.views
2
2
3
3
import android.annotation.SuppressLint
4
- import android.annotation.TargetApi
5
4
import android.content.Context
6
- import android.hardware.fingerprint.FingerprintManager
7
5
import android.media.AudioManager
8
- import android.os.Build
9
- import android.support.annotation.RequiresApi
6
+ import android.media.MediaPlayer
7
+ import android.media.RingtoneManager
8
+ import android.net.Uri
10
9
import android.util.AttributeSet
11
10
import android.view.View
12
11
import android.widget.LinearLayout
13
- import com.samsung.android.sdk.SsdkUnsupportedException
14
- import com.samsung.android.sdk.SsdkVendorCheck
15
- import com.samsung.android.sdk.pass.Spass
16
12
import com.thanksmister.iot.mqtt.alarmpanel.R
17
- import com.thanksmister.iot.mqtt.alarmpanel.utils.SoundUtils
18
13
import com.wei.android.lib.fingerprintidentify.FingerprintIdentify
19
14
import com.wei.android.lib.fingerprintidentify.base.BaseFingerprint
20
15
import kotlinx.android.synthetic.main.dialog_alarm_code_set.view.*
21
16
import kotlinx.android.synthetic.main.view_keypad.view.*
22
17
import timber.log.Timber
23
- import android.os.Vibrator
24
- import android.content.Context.VIBRATOR_SERVICE
25
- import android.os.VibrationEffect
26
- import android.media.MediaPlayer
27
- import android.media.RingtoneManager
28
- import android.net.Uri
29
18
import java.io.FileNotFoundException
30
19
31
20
abstract class BaseAlarmView : LinearLayout {
@@ -34,11 +23,7 @@ abstract class BaseAlarmView : LinearLayout {
34
23
var enteredCode = " "
35
24
var useSystemSound: Boolean = true
36
25
var useFingerprint: Boolean = false
37
- var vibrator: Vibrator ? = null
38
26
private var mediaPlayer: MediaPlayer ? = null
39
-
40
- private var soundUtils: SoundUtils ? = null
41
-
42
27
private var fingerPrintIdentity: FingerprintIdentify ? = null
43
28
44
29
constructor (context: Context ) : super (context) {
@@ -112,11 +97,13 @@ abstract class BaseAlarmView : LinearLayout {
112
97
@SuppressLint(" InlinedApi" )
113
98
override fun onVisibilityChanged (changedView : View ? , visibility : Int ) {
114
99
super .onVisibilityChanged(changedView, visibility)
115
- // Fingerprint API only available on from Android 6.0 (M) and we only use this code if user had hardware
116
- // has setup the fingerprint, and user has activated the settings. Be aware of Samsung devices and their issues.
117
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M && useFingerprint) {
118
- if (isFingerprintSupported()) {
119
- fingerPrintIdentity = FingerprintIdentify (context)
100
+
101
+ fingerPrintIdentity = FingerprintIdentify (context, BaseFingerprint .FingerprintIdentifyExceptionListener {
102
+ Timber .e(" Fingerprint Error: " + it.message)
103
+ })
104
+
105
+ if (fingerPrintIdentity != null ) {
106
+ if (fingerPrintIdentity!! .isFingerprintEnable && fingerPrintIdentity!! .isHardwareEnable) {
120
107
if (! this .isShown){
121
108
stopFingerprintIdentity()
122
109
return
@@ -127,31 +114,6 @@ abstract class BaseAlarmView : LinearLayout {
127
114
}
128
115
}
129
116
130
- @RequiresApi(Build .VERSION_CODES .M )
131
- private fun isFingerprintSupported (): Boolean {
132
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
133
- val fingerprintManager = context!! .getSystemService(Context .FINGERPRINT_SERVICE ) as FingerprintManager
134
- if (SsdkVendorCheck .isSamsungDevice()) {
135
- if (! fingerprintManager.isHardwareDetected && SsdkVendorCheck .isSamsungDevice()) {
136
- val spass = Spass ()
137
- try {
138
- spass.initialize(context)
139
- return spass.isFeatureEnabled(Spass .DEVICE_FINGERPRINT )
140
- } catch (e: SsdkUnsupportedException ) {
141
- Timber .e(e.message)
142
- return false
143
- } catch (e: UnsupportedOperationException ) {
144
- Timber .e(e.message)
145
- return false
146
- }
147
- }
148
- } else {
149
- return (fingerprintManager.isHardwareDetected && fingerprintManager.hasEnrolledFingerprints())
150
- }
151
- }
152
- return false
153
- }
154
-
155
117
override fun onDetachedFromWindow () {
156
118
super .onDetachedFromWindow()
157
119
destroySoundUtils()
@@ -175,10 +137,12 @@ abstract class BaseAlarmView : LinearLayout {
175
137
176
138
override fun onFailed (isDeviceLocked : Boolean ) {
177
139
Timber .d(" Fingerprint identity failed" );
140
+ fingerNoMatch()
178
141
}
179
142
180
143
override fun onStartFailedByDeviceLocked () {
181
144
Timber .d(" Fingerprint identity failed by device locked" );
145
+ fingerNoMatch()
182
146
}
183
147
})
184
148
}
@@ -203,45 +167,39 @@ abstract class BaseAlarmView : LinearLayout {
203
167
abstract fun fingerNoMatch ()
204
168
205
169
fun destroySoundUtils () {
206
- if (! useSystemSound)
207
- return
208
-
209
- if (soundUtils != null ) {
210
- soundUtils?.destroyBuzzer()
211
- }
212
-
213
170
if (mediaPlayer != null ) {
214
171
mediaPlayer?.stop()
215
172
}
216
173
}
217
174
218
175
fun playContinuousAlarm () {
219
- if (! useSystemSound)
220
- return
221
-
222
- try {
223
- var alert: Uri ? = RingtoneManager .getDefaultUri(RingtoneManager .TYPE_ALARM )
224
- if (alert == null ) {
225
- alert = RingtoneManager .getDefaultUri(RingtoneManager .TYPE_NOTIFICATION )
176
+ if (useSystemSound) {
177
+ try {
178
+ var alert: Uri ? = RingtoneManager .getDefaultUri(RingtoneManager .TYPE_ALARM )
226
179
if (alert == null ) {
227
- alert = RingtoneManager .getDefaultUri(RingtoneManager .TYPE_RINGTONE )
180
+ alert = RingtoneManager .getDefaultUri(RingtoneManager .TYPE_NOTIFICATION )
181
+ if (alert == null ) {
182
+ alert = RingtoneManager .getDefaultUri(RingtoneManager .TYPE_RINGTONE )
183
+ }
228
184
}
185
+ mediaPlayer = MediaPlayer .create(context!! , alert)
186
+ mediaPlayer?.isLooping = true
187
+ mediaPlayer?.start()
188
+ } catch (e: SecurityException ) {
189
+ playContinuousBeep()
190
+ } catch (e: FileNotFoundException ) {
191
+ playContinuousBeep()
229
192
}
230
- mediaPlayer = MediaPlayer .create(context!! , alert)
231
- mediaPlayer?.start()
232
- } catch (e: SecurityException ) {
233
- playContinuousBeep()
234
- } catch (e: FileNotFoundException ) {
193
+ } else {
235
194
playContinuousBeep()
236
195
}
237
196
}
238
197
239
198
private fun playContinuousBeep () {
240
- if (soundUtils == null ) {
241
- soundUtils = SoundUtils (context)
242
- soundUtils?.init ()
243
- soundUtils?.playBuzzerRepeat()
244
- }
199
+ Timber .d(" playContinuousBeep" )
200
+ mediaPlayer = MediaPlayer .create(context!! , R .raw.beep_loop)
201
+ mediaPlayer?.isLooping = true
202
+ mediaPlayer?.start()
245
203
}
246
204
247
205
protected fun showFilledPins (pinsShown : Int ) {
0 commit comments