Compare commits
12 Commits
dev_v3.13.
...
king_kahil
| Author | SHA1 | Date |
|---|---|---|
|
|
7f9e825a78 | 5 months ago |
|
|
e31cfb803c | 5 months ago |
|
|
58a55682f2 | 8 months ago |
|
|
5c98b40803 | 8 months ago |
|
|
9144bccc75 | 1 year ago |
|
|
8b7d0d4a7e | 1 year ago |
|
|
65a3f3bfff | 1 year ago |
|
|
faf5280338 | 1 year ago |
|
|
8636180de3 | 1 year ago |
|
|
0f592c8a92 | 1 year ago |
|
|
6139a38f37 | 1 year ago |
|
|
493c85d28e | 1 year ago |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 7.8 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 9.8 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 9.9 KiB |
@ -0,0 +1,140 @@
|
|||||||
|
{
|
||||||
|
"images": [
|
||||||
|
{
|
||||||
|
"size": "24x24",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-24@2x.png",
|
||||||
|
"role": "notificationCenter",
|
||||||
|
"subtype": "38mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "27.5x27.5",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-27.5@2x.png",
|
||||||
|
"role": "notificationCenter",
|
||||||
|
"subtype": "42mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "33x33",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-33@2x.png",
|
||||||
|
"role": "notificationCenter",
|
||||||
|
"subtype": "45mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "29x29",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-29@2x.png",
|
||||||
|
"role": "companionSettings"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "29x29",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "3x",
|
||||||
|
"filename": "Icon-29@3x.png",
|
||||||
|
"role": "companionSettings"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "40x40",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-40@2x.png",
|
||||||
|
"role": "appLauncher",
|
||||||
|
"subtype": "38mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "44x44",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-44@2x.png",
|
||||||
|
"role": "appLauncher",
|
||||||
|
"subtype": "40mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "46x46",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-46@2x.png",
|
||||||
|
"role": "appLauncher",
|
||||||
|
"subtype": "41mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "50x50",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-50@2x.png",
|
||||||
|
"role": "appLauncher",
|
||||||
|
"subtype": "44mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "51x51",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-51@2x.png",
|
||||||
|
"role": "appLauncher",
|
||||||
|
"subtype": "45mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "54x54",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-54@2x.png",
|
||||||
|
"role": "appLauncher",
|
||||||
|
"subtype": "49mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "86x86",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-86@2x.png",
|
||||||
|
"role": "quickLook",
|
||||||
|
"subtype": "38mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "98x98",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-98@2x.png",
|
||||||
|
"role": "quickLook",
|
||||||
|
"subtype": "42mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "108x108",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-108@2x.png",
|
||||||
|
"role": "quickLook",
|
||||||
|
"subtype": "44mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "117x117",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-117@2x.png",
|
||||||
|
"role": "quickLook",
|
||||||
|
"subtype": "45mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "129x129",
|
||||||
|
"idiom": "watch",
|
||||||
|
"scale": "2x",
|
||||||
|
"filename": "Icon-129@2x.png",
|
||||||
|
"role": "quickLook",
|
||||||
|
"subtype": "49mm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"size": "1024x1024",
|
||||||
|
"idiom": "watch-marketing",
|
||||||
|
"filename": "ItunesArtwork@2x.png",
|
||||||
|
"scale": "1x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info": {
|
||||||
|
"version": 1,
|
||||||
|
"author": "makeappicon"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 9.8 KiB |
|
After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 9.9 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 100 KiB |
@ -0,0 +1,6 @@
|
|||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQg5RaefOuG8Q/5I7wM
|
||||||
|
JA/2GKcBp/eV1Tfe6zeWBAk58zOgCgYIKoZIzj0DAQehRANCAAQ8JuxrvWtIvYfy
|
||||||
|
aIMpvgbvDmzpZVMZ1uRhBSgtkO49AAYX8JFkq7bMMgq90b8GbvWA8nMkLchIATvX
|
||||||
|
yuSNSQFx
|
||||||
|
-----END PRIVATE KEY-----
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
-----BEGIN PRIVATE KEY-----
|
||||||
|
MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQg5RaefOuG8Q/5I7wM
|
||||||
|
JA/2GKcBp/eV1Tfe6zeWBAk58zOgCgYIKoZIzj0DAQehRANCAAQ8JuxrvWtIvYfy
|
||||||
|
aIMpvgbvDmzpZVMZ1uRhBSgtkO49AAYX8JFkq7bMMgq90b8GbvWA8nMkLchIATvX
|
||||||
|
yuSNSQFx
|
||||||
|
-----END PRIVATE KEY-----
|
||||||
|
After Width: | Height: | Size: 286 KiB |
|
After Width: | Height: | Size: 290 KiB |
|
After Width: | Height: | Size: 217 KiB |
|
After Width: | Height: | Size: 246 KiB |
|
After Width: | Height: | Size: 194 KiB |
|
After Width: | Height: | Size: 143 KiB |
|
After Width: | Height: | Size: 102 KiB |
|
After Width: | Height: | Size: 71 KiB |
@ -1,58 +1,58 @@
|
|||||||
package com.ejada.hmg.geofence
|
//package com.ejada.hmg.geofence
|
||||||
|
//
|
||||||
import com.google.android.gms.location.Geofence
|
//import com.google.android.gms.location.Geofence
|
||||||
import com.google.gson.Gson
|
//import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
//import com.google.gson.reflect.TypeToken
|
||||||
|
//
|
||||||
class GeoZoneModel {
|
//class GeoZoneModel {
|
||||||
var GEOF_ID:Int = 0
|
// var GEOF_ID:Int = 0
|
||||||
var Radius:Int = 0
|
// var Radius:Int = 0
|
||||||
var Type:Int = 0
|
// var Type:Int = 0
|
||||||
var ProjectID:Int = 0
|
// var ProjectID:Int = 0
|
||||||
|
//
|
||||||
var Description:String? = null
|
// var Description:String? = null
|
||||||
var DescriptionN:String? = null
|
// var DescriptionN:String? = null
|
||||||
var Latitude:String? = null
|
// var Latitude:String? = null
|
||||||
var Longitude:String? = null
|
// var Longitude:String? = null
|
||||||
var ImageURL:String? = null
|
// var ImageURL:String? = null
|
||||||
var IsCity:String? = null
|
// var IsCity:String? = null
|
||||||
|
//
|
||||||
fun identifier():String{
|
// fun identifier():String{
|
||||||
return "$GEOF_ID" + "_hmg"
|
// return "$GEOF_ID" + "_hmg"
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun message():String{
|
// fun message():String{
|
||||||
return Description ?: "nil"
|
// return Description ?: "nil"
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun listFrom(jsonString: String) : List<GeoZoneModel>{
|
// fun listFrom(jsonString: String) : List<GeoZoneModel>{
|
||||||
val type = object : TypeToken<List<GeoZoneModel?>?>() {}.getType()
|
// val type = object : TypeToken<List<GeoZoneModel?>?>() {}.getType()
|
||||||
return Gson().fromJson(jsonString, type)
|
// return Gson().fromJson(jsonString, type)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun toGeofence() : Geofence?{
|
// fun toGeofence() : Geofence?{
|
||||||
if (!Latitude.isNullOrEmpty() && !Longitude.isNullOrEmpty() && Radius > 50) {
|
// if (!Latitude.isNullOrEmpty() && !Longitude.isNullOrEmpty() && Radius > 50) {
|
||||||
val lat = Latitude!!.trim().toDoubleOrNull()
|
// val lat = Latitude!!.trim().toDoubleOrNull()
|
||||||
val long = Longitude!!.trim().toDoubleOrNull()
|
// val long = Longitude!!.trim().toDoubleOrNull()
|
||||||
val rad = Radius.toFloat()
|
// val rad = Radius.toFloat()
|
||||||
if(lat != null && long != null){
|
// if(lat != null && long != null){
|
||||||
|
//
|
||||||
val loiteringDelayMinutes:Int = 2 // in Minutes
|
// val loiteringDelayMinutes:Int = 2 // in Minutes
|
||||||
return Geofence.Builder()
|
// return Geofence.Builder()
|
||||||
.setRequestId(identifier())
|
// .setRequestId(identifier())
|
||||||
.setCircularRegion(
|
// .setCircularRegion(
|
||||||
lat,
|
// lat,
|
||||||
long,
|
// long,
|
||||||
rad
|
// rad
|
||||||
)
|
// )
|
||||||
.setTransitionTypes(GeofenceTransition.ENTER_EXIT.value)
|
// .setTransitionTypes(GeofenceTransition.ENTER_EXIT.value)
|
||||||
.setNotificationResponsiveness(0)
|
// .setNotificationResponsiveness(0)
|
||||||
.setLoiteringDelay(loiteringDelayMinutes * 60 * 1000)
|
// .setLoiteringDelay(loiteringDelayMinutes * 60 * 1000)
|
||||||
.setExpirationDuration(Geofence.NEVER_EXPIRE)
|
// .setExpirationDuration(Geofence.NEVER_EXPIRE)
|
||||||
.build()
|
// .build()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return null
|
// return null
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,291 +1,291 @@
|
|||||||
package com.ejada.hmg.geofence
|
//package com.ejada.hmg.geofence
|
||||||
|
//
|
||||||
import android.Manifest
|
//import android.Manifest
|
||||||
import android.app.PendingIntent
|
//import android.app.PendingIntent
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.content.Intent
|
//import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
//import android.content.SharedPreferences
|
||||||
import android.content.pm.PackageManager
|
//import android.content.pm.PackageManager
|
||||||
import android.location.Location
|
//import android.location.Location
|
||||||
import androidx.core.content.ContextCompat
|
//import androidx.core.content.ContextCompat
|
||||||
import com.ejada.hmg.geofence.intent_receivers.GeofenceBroadcastReceiver
|
//import com.ejada.hmg.geofence.intent_receivers.GeofenceBroadcastReceiver
|
||||||
import com.ejada.hmg.geofence.intent_receivers.ReregisterGeofenceJobService
|
//import com.ejada.hmg.geofence.intent_receivers.ReregisterGeofenceJobService
|
||||||
import com.ejada.hmg.utils.*
|
//import com.ejada.hmg.utils.*
|
||||||
import com.google.android.gms.location.Geofence
|
//import com.google.android.gms.location.Geofence
|
||||||
import com.google.android.gms.location.GeofencingClient
|
//import com.google.android.gms.location.GeofencingClient
|
||||||
import com.google.android.gms.location.GeofencingRequest
|
//import com.google.android.gms.location.GeofencingRequest
|
||||||
import com.google.android.gms.location.LocationServices
|
//import com.google.android.gms.location.LocationServices
|
||||||
import com.google.gson.Gson
|
//import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
//import com.google.gson.reflect.TypeToken
|
||||||
|
//
|
||||||
enum class GeofenceTransition(val value: Int) {
|
//enum class GeofenceTransition(val value: Int) {
|
||||||
ENTER(1),
|
// ENTER(1),
|
||||||
EXIT(2),
|
// EXIT(2),
|
||||||
DWELL(4),
|
// DWELL(4),
|
||||||
|
//
|
||||||
ENTER_EXIT((ENTER.value or EXIT.value)),
|
// ENTER_EXIT((ENTER.value or EXIT.value)),
|
||||||
DWELL_EXIT((DWELL.value or EXIT.value));
|
// DWELL_EXIT((DWELL.value or EXIT.value));
|
||||||
|
//
|
||||||
companion object {
|
// companion object {
|
||||||
fun fromInt(value: Int) = GeofenceTransition.values().first { it.value == value }
|
// fun fromInt(value: Int) = GeofenceTransition.values().first { it.value == value }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun named(): String {
|
// fun named(): String {
|
||||||
if (value == 1) return "Enter"
|
// if (value == 1) return "Enter"
|
||||||
if (value == 2) return "Exit"
|
// if (value == 2) return "Exit"
|
||||||
if (value == 4) return "dWell"
|
// if (value == 4) return "dWell"
|
||||||
if (value == (ENTER.value or EXIT.value)) return "Enter or Exit"
|
// if (value == (ENTER.value or EXIT.value)) return "Enter or Exit"
|
||||||
if (value == (DWELL.value or EXIT.value)) return "DWell or Exit"
|
// if (value == (DWELL.value or EXIT.value)) return "DWell or Exit"
|
||||||
return "unknown"
|
// return "unknown"
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
class HMG_Geofence {
|
//class HMG_Geofence {
|
||||||
// https://developer.android.com/training/location/geofencing#java
|
// // https://developer.android.com/training/location/geofencing#java
|
||||||
|
//
|
||||||
private lateinit var context: Context
|
// private lateinit var context: Context
|
||||||
private lateinit var preferences: SharedPreferences
|
// private lateinit var preferences: SharedPreferences
|
||||||
private val gson = Gson()
|
// private val gson = Gson()
|
||||||
|
//
|
||||||
private lateinit var geofencingClient: GeofencingClient
|
// private lateinit var geofencingClient: GeofencingClient
|
||||||
private val geofencePendingIntent: PendingIntent by lazy {
|
// private val geofencePendingIntent: PendingIntent by lazy {
|
||||||
val intent = Intent(context, GeofenceBroadcastReceiver::class.java)
|
// val intent = Intent(context, GeofenceBroadcastReceiver::class.java)
|
||||||
PendingIntent.getBroadcast(
|
// PendingIntent.getBroadcast(
|
||||||
context,
|
// context,
|
||||||
0,
|
// 0,
|
||||||
intent,
|
// intent,
|
||||||
PendingIntent.FLAG_IMMUTABLE
|
// PendingIntent.FLAG_IMMUTABLE
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
companion object {
|
// companion object {
|
||||||
|
//
|
||||||
var instance: HMG_Geofence? = null
|
// var instance: HMG_Geofence? = null
|
||||||
fun shared(context: Context): HMG_Geofence {
|
// fun shared(context: Context): HMG_Geofence {
|
||||||
if (instance == null) {
|
// if (instance == null) {
|
||||||
instance = HMG_Geofence()
|
// instance = HMG_Geofence()
|
||||||
instance?.context = context
|
// instance?.context = context
|
||||||
instance?.geofencingClient = LocationServices.getGeofencingClient(context)
|
// instance?.geofencingClient = LocationServices.getGeofencingClient(context)
|
||||||
instance?.preferences =
|
// instance?.preferences =
|
||||||
context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
// context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
||||||
}
|
// }
|
||||||
return instance!!
|
// return instance!!
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private fun limitize(zones: List<GeoZoneModel>): List<GeoZoneModel> {
|
// private fun limitize(zones: List<GeoZoneModel>): List<GeoZoneModel> {
|
||||||
var geoZones_ = zones
|
// var geoZones_ = zones
|
||||||
if (zones.size > 100)
|
// if (zones.size > 100)
|
||||||
geoZones_ = zones.subList(0, 99)
|
// geoZones_ = zones.subList(0, 99)
|
||||||
return geoZones_
|
// return geoZones_
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
fun register(completion: ((Boolean, java.lang.Exception?) -> Unit)) {
|
// fun register(completion: ((Boolean, java.lang.Exception?) -> Unit)) {
|
||||||
unRegisterAll { status, exception ->
|
// unRegisterAll { status, exception ->
|
||||||
val geoZones = getGeoZonesFromPreference(context)
|
// val geoZones = getGeoZonesFromPreference(context)
|
||||||
doRegister(geoZones) { status_, error ->
|
// doRegister(geoZones) { status_, error ->
|
||||||
completion.let { it(status_, error) }
|
// completion.let { it(status_, error) }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun unRegisterAll(completion: (status: Boolean, exception: Exception?) -> Unit) {
|
// fun unRegisterAll(completion: (status: Boolean, exception: Exception?) -> Unit) {
|
||||||
getActiveGeofences({ success ->
|
// getActiveGeofences({ success ->
|
||||||
removeActiveGeofences()
|
// removeActiveGeofences()
|
||||||
if (success.isNotEmpty())
|
// if (success.isNotEmpty())
|
||||||
geofencingClient
|
// geofencingClient
|
||||||
.removeGeofences(success)
|
// .removeGeofences(success)
|
||||||
.addOnSuccessListener {
|
// .addOnSuccessListener {
|
||||||
completion(true, null)
|
// completion(true, null)
|
||||||
}
|
// }
|
||||||
.addOnFailureListener {
|
// .addOnFailureListener {
|
||||||
completion(false, it)
|
// completion(false, it)
|
||||||
saveLog(context, "error:REMOVE_GEOFENCES", it.localizedMessage)
|
// saveLog(context, "error:REMOVE_GEOFENCES", it.localizedMessage)
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
completion(true, null)
|
// completion(true, null)
|
||||||
|
//
|
||||||
}, { failed ->
|
// }, { failed ->
|
||||||
// Nothing to do with failed geofences.
|
// // Nothing to do with failed geofences.
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private fun doRegister(
|
// private fun doRegister(
|
||||||
geoZones: List<GeoZoneModel>,
|
// geoZones: List<GeoZoneModel>,
|
||||||
completion: ((Boolean, java.lang.Exception?) -> Unit)? = null
|
// completion: ((Boolean, java.lang.Exception?) -> Unit)? = null
|
||||||
) {
|
// ) {
|
||||||
if (geoZones.isEmpty())
|
// if (geoZones.isEmpty())
|
||||||
return
|
// return
|
||||||
|
//
|
||||||
val geoZones_ = limitize(geoZones)
|
// val geoZones_ = limitize(geoZones)
|
||||||
|
//
|
||||||
fun buildGeofencingRequest(geofences: List<Geofence>): GeofencingRequest {
|
// fun buildGeofencingRequest(geofences: List<Geofence>): GeofencingRequest {
|
||||||
return GeofencingRequest.Builder()
|
// return GeofencingRequest.Builder()
|
||||||
.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_DWELL)
|
// .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_DWELL)
|
||||||
.addGeofences(geofences)
|
// .addGeofences(geofences)
|
||||||
.build()
|
// .build()
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
getActiveGeofences({ active ->
|
// getActiveGeofences({ active ->
|
||||||
|
//
|
||||||
val geofences = mutableListOf<Geofence>()
|
// val geofences = mutableListOf<Geofence>()
|
||||||
geoZones_.forEach {
|
// geoZones_.forEach {
|
||||||
it.toGeofence()?.let { geof ->
|
// it.toGeofence()?.let { geof ->
|
||||||
if (!active.contains(geof.requestId)) { // if not already registered then register
|
// if (!active.contains(geof.requestId)) { // if not already registered then register
|
||||||
geofences.add(geof)
|
// geofences.add(geof)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (checkPermission() && geofences.isNotEmpty()) {
|
// if (checkPermission() && geofences.isNotEmpty()) {
|
||||||
geofencingClient
|
// geofencingClient
|
||||||
.addGeofences(buildGeofencingRequest(geofences), geofencePendingIntent)
|
// .addGeofences(buildGeofencingRequest(geofences), geofencePendingIntent)
|
||||||
.addOnSuccessListener {
|
// .addOnSuccessListener {
|
||||||
Logs.RegisterGeofence.save(
|
// Logs.RegisterGeofence.save(
|
||||||
context,
|
// context,
|
||||||
"SUCCESS",
|
// "SUCCESS",
|
||||||
"Successfuly registered the geofences",
|
// "Successfuly registered the geofences",
|
||||||
Logs.STATUS.SUCCESS
|
// Logs.STATUS.SUCCESS
|
||||||
)
|
// )
|
||||||
saveActiveGeofence(geofences.map { it.requestId }, listOf())
|
// saveActiveGeofence(geofences.map { it.requestId }, listOf())
|
||||||
completion?.let { it(true, null) }
|
// completion?.let { it(true, null) }
|
||||||
}
|
// }
|
||||||
.addOnFailureListener { exc ->
|
// .addOnFailureListener { exc ->
|
||||||
Logs.RegisterGeofence.save(
|
// Logs.RegisterGeofence.save(
|
||||||
context,
|
// context,
|
||||||
"FAILED_TO_REGISTER",
|
// "FAILED_TO_REGISTER",
|
||||||
"Failed to register geofence",
|
// "Failed to register geofence",
|
||||||
Logs.STATUS.ERROR
|
// Logs.STATUS.ERROR
|
||||||
)
|
// )
|
||||||
completion?.let { it(false, exc) }
|
// completion?.let { it(false, exc) }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// Schedule the job to register after specified duration (due to: events not calling after long period.. days or days [Needs to register fences again])
|
// // Schedule the job to register after specified duration (due to: events not calling after long period.. days or days [Needs to register fences again])
|
||||||
HMGUtils.scheduleJob(
|
// HMGUtils.scheduleJob(
|
||||||
context,
|
// context,
|
||||||
ReregisterGeofenceJobService::class.java,
|
// ReregisterGeofenceJobService::class.java,
|
||||||
ReregisterGeofenceJobService.JobID,
|
// ReregisterGeofenceJobService.JobID,
|
||||||
ReregisterGeofenceJobService.TriggerIntervalDuration
|
// ReregisterGeofenceJobService.TriggerIntervalDuration
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}, null)
|
// }, null)
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun getGeoZonesFromPreference(context: Context): List<GeoZoneModel> {
|
// fun getGeoZonesFromPreference(context: Context): List<GeoZoneModel> {
|
||||||
val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
// val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
||||||
val json = pref.getString(PREF_KEY_HMG_ZONES, "[]")
|
// val json = pref.getString(PREF_KEY_HMG_ZONES, "[]")
|
||||||
|
//
|
||||||
val geoZones = GeoZoneModel().listFrom(json!!)
|
// val geoZones = GeoZoneModel().listFrom(json!!)
|
||||||
return geoZones
|
// return geoZones
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun saveActiveGeofence(success: List<String>, failed: List<String>) {
|
// fun saveActiveGeofence(success: List<String>, failed: List<String>) {
|
||||||
val jsonSuccess = gson.toJson(success)
|
// val jsonSuccess = gson.toJson(success)
|
||||||
val jsonFailure = gson.toJson(failed)
|
// val jsonFailure = gson.toJson(failed)
|
||||||
preferences.edit().putString(PREF_KEY_SUCCESS, jsonSuccess).apply()
|
// preferences.edit().putString(PREF_KEY_SUCCESS, jsonSuccess).apply()
|
||||||
preferences.edit().putString(PREF_KEY_FAILED, jsonFailure).apply()
|
// preferences.edit().putString(PREF_KEY_FAILED, jsonFailure).apply()
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun removeActiveGeofences() {
|
// fun removeActiveGeofences() {
|
||||||
preferences.edit().putString(PREF_KEY_SUCCESS, "[]").apply()
|
// preferences.edit().putString(PREF_KEY_SUCCESS, "[]").apply()
|
||||||
preferences.edit().putString(PREF_KEY_FAILED, "[]").apply()
|
// preferences.edit().putString(PREF_KEY_FAILED, "[]").apply()
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun getActiveGeofences(
|
// fun getActiveGeofences(
|
||||||
success: (success: List<String>) -> Unit,
|
// success: (success: List<String>) -> Unit,
|
||||||
failure: ((failed: List<String>) -> Unit)?
|
// failure: ((failed: List<String>) -> Unit)?
|
||||||
) {
|
// ) {
|
||||||
val type = object : TypeToken<List<String?>?>() {}.type
|
// val type = object : TypeToken<List<String?>?>() {}.type
|
||||||
|
//
|
||||||
val jsonSuccess = preferences.getString(PREF_KEY_SUCCESS, "[]")
|
// val jsonSuccess = preferences.getString(PREF_KEY_SUCCESS, "[]")
|
||||||
val success = gson.fromJson<List<String>>(jsonSuccess, type)
|
// val success = gson.fromJson<List<String>>(jsonSuccess, type)
|
||||||
success(success)
|
// success(success)
|
||||||
|
//
|
||||||
if (failure != null) {
|
// if (failure != null) {
|
||||||
val jsonFailure = preferences.getString(PREF_KEY_FAILED, "[]")
|
// val jsonFailure = preferences.getString(PREF_KEY_FAILED, "[]")
|
||||||
val failed = gson.fromJson<List<String>>(jsonFailure, type)
|
// val failed = gson.fromJson<List<String>>(jsonFailure, type)
|
||||||
failure(failed)
|
// failure(failed)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private fun checkPermission(): Boolean {
|
// private fun checkPermission(): Boolean {
|
||||||
return ContextCompat.checkSelfPermission(
|
// return ContextCompat.checkSelfPermission(
|
||||||
context,
|
// context,
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION
|
// Manifest.permission.ACCESS_FINE_LOCATION
|
||||||
) == PackageManager.PERMISSION_GRANTED
|
// ) == PackageManager.PERMISSION_GRANTED
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun getPatientID(): Int? {
|
// fun getPatientID(): Int? {
|
||||||
var profileJson = preferences.getString("flutter.imei-user-data", null)
|
// var profileJson = preferences.getString("flutter.imei-user-data", null)
|
||||||
if (profileJson == null)
|
// if (profileJson == null)
|
||||||
profileJson = preferences.getString("flutter.user-profile", null)
|
// profileJson = preferences.getString("flutter.user-profile", null)
|
||||||
|
//
|
||||||
val type = object : TypeToken<Map<String?, Any?>?>() {}.type
|
// val type = object : TypeToken<Map<String?, Any?>?>() {}.type
|
||||||
return gson.fromJson<Map<String?, Any?>?>(profileJson, type)
|
// return gson.fromJson<Map<String?, Any?>?>(profileJson, type)
|
||||||
?.get("PatientID")
|
// ?.get("PatientID")
|
||||||
.toString()
|
// .toString()
|
||||||
.toDoubleOrNull()
|
// .toDoubleOrNull()
|
||||||
?.toInt()
|
// ?.toInt()
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
fun handleEvent(
|
// fun handleEvent(
|
||||||
triggerGeofences: List<Geofence>,
|
// triggerGeofences: List<Geofence>,
|
||||||
location: Location,
|
// location: Location,
|
||||||
transition: GeofenceTransition
|
// transition: GeofenceTransition
|
||||||
) {
|
// ) {
|
||||||
getPatientID()?.let { patientId ->
|
// getPatientID()?.let { patientId ->
|
||||||
getActiveGeofences({ activeGeofences ->
|
// getActiveGeofences({ activeGeofences ->
|
||||||
|
//
|
||||||
triggerGeofences.forEach { geofence ->
|
// triggerGeofences.forEach { geofence ->
|
||||||
// Extract PointID from 'geofence.requestId' and find from active geofences
|
// // Extract PointID from 'geofence.requestId' and find from active geofences
|
||||||
val pointID =
|
// val pointID =
|
||||||
activeGeofences.firstOrNull { it == geofence.requestId }?.split('_')
|
// activeGeofences.firstOrNull { it == geofence.requestId }?.split('_')
|
||||||
?.first()
|
// ?.first()
|
||||||
if (!pointID.isNullOrEmpty() && pointID.toIntOrNull() != null) {
|
// if (!pointID.isNullOrEmpty() && pointID.toIntOrNull() != null) {
|
||||||
|
//
|
||||||
val body = mutableMapOf<String, Any?>(
|
// val body = mutableMapOf<String, Any?>(
|
||||||
"PointsID" to pointID.toIntOrNull(),
|
// "PointsID" to pointID.toIntOrNull(),
|
||||||
"GeoType" to transition.value,
|
// "GeoType" to transition.value,
|
||||||
"PatientID" to patientId
|
// "PatientID" to patientId
|
||||||
)
|
// )
|
||||||
body.putAll(HMGUtils.defaultHTTPParams(context))
|
// body.putAll(HMGUtils.defaultHTTPParams(context))
|
||||||
|
//
|
||||||
httpPost<Map<String, Any>>(API.LOG_GEOFENCE, body, { response ->
|
// httpPost<Map<String, Any>>(API.LOG_GEOFENCE, body, { response ->
|
||||||
saveLog(
|
// saveLog(
|
||||||
context,
|
// context,
|
||||||
"HMG_GEOFENCE_NOTIFY",
|
// "HMG_GEOFENCE_NOTIFY",
|
||||||
"Success: Notified to server\uD83D\uDE0E."
|
// "Success: Notified to server\uD83D\uDE0E."
|
||||||
)
|
// )
|
||||||
sendNotification(
|
// sendNotification(
|
||||||
context,
|
// context,
|
||||||
transition.named(),
|
// transition.named(),
|
||||||
geofence.requestId,
|
// geofence.requestId,
|
||||||
"Notified to server.😎"
|
// "Notified to server.😎"
|
||||||
)
|
// )
|
||||||
}, { exception ->
|
// }, { exception ->
|
||||||
val errorMessage = "${transition.named()}, ${geofence.requestId}"
|
// val errorMessage = "${transition.named()}, ${geofence.requestId}"
|
||||||
saveLog(
|
// saveLog(
|
||||||
context,
|
// context,
|
||||||
"HMG_GEOFENCE_NOTIFY",
|
// "HMG_GEOFENCE_NOTIFY",
|
||||||
"failed: $errorMessage | error: ${exception.localizedMessage}"
|
// "failed: $errorMessage | error: ${exception.localizedMessage}"
|
||||||
)
|
// )
|
||||||
sendNotification(
|
// sendNotification(
|
||||||
context,
|
// context,
|
||||||
transition.named(),
|
// transition.named(),
|
||||||
geofence.requestId,
|
// geofence.requestId,
|
||||||
"Failed to notify server😔 -> ${exception.localizedMessage}"
|
// "Failed to notify server😔 -> ${exception.localizedMessage}"
|
||||||
)
|
// )
|
||||||
})
|
// })
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}, null)
|
// }, null)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
@ -1,71 +1,71 @@
|
|||||||
package com.ejada.hmg.geofence.intent_receivers
|
//package com.ejada.hmg.geofence.intent_receivers
|
||||||
|
//
|
||||||
import android.annotation.SuppressLint
|
//import android.annotation.SuppressLint
|
||||||
import android.content.BroadcastReceiver
|
//import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.content.Intent
|
//import android.content.Intent
|
||||||
import android.util.Log
|
//import android.util.Log
|
||||||
import com.ejada.hmg.geofence.GeofenceTransition
|
//import com.ejada.hmg.geofence.GeofenceTransition
|
||||||
import com.ejada.hmg.geofence.HMG_Geofence
|
//import com.ejada.hmg.geofence.HMG_Geofence
|
||||||
import com.ejada.hmg.utils.Logs
|
//import com.ejada.hmg.utils.Logs
|
||||||
import com.google.android.gms.location.GeofenceStatusCodes
|
//import com.google.android.gms.location.GeofenceStatusCodes
|
||||||
import com.google.android.gms.location.GeofencingEvent
|
//import com.google.android.gms.location.GeofencingEvent
|
||||||
|
//
|
||||||
class GeofenceBroadcastReceiver : BroadcastReceiver() {
|
//class GeofenceBroadcastReceiver : BroadcastReceiver() {
|
||||||
private val LOG_TAG = "GeofenceBroadcastReceiver"
|
// private val LOG_TAG = "GeofenceBroadcastReceiver"
|
||||||
|
//
|
||||||
@SuppressLint("LongLogTag")
|
// @SuppressLint("LongLogTag")
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
// override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
//
|
||||||
val geofencingEvent = GeofencingEvent.fromIntent(intent)
|
// val geofencingEvent = GeofencingEvent.fromIntent(intent)
|
||||||
if (geofencingEvent != null) {
|
// if (geofencingEvent != null) {
|
||||||
if (geofencingEvent.hasError()) {
|
// if (geofencingEvent.hasError()) {
|
||||||
val errorMessage =
|
// val errorMessage =
|
||||||
GeofenceErrorMessages.getErrorString(context, geofencingEvent.errorCode)
|
// GeofenceErrorMessages.getErrorString(context, geofencingEvent.errorCode)
|
||||||
Log.e(LOG_TAG, errorMessage)
|
// Log.e(LOG_TAG, errorMessage)
|
||||||
|
//
|
||||||
Logs.GeofenceEvent.save(
|
// Logs.GeofenceEvent.save(
|
||||||
context,
|
// context,
|
||||||
LOG_TAG,
|
// LOG_TAG,
|
||||||
"Error while triggering geofence event",
|
// "Error while triggering geofence event",
|
||||||
Logs.STATUS.ERROR
|
// Logs.STATUS.ERROR
|
||||||
)
|
// )
|
||||||
doReRegisterIfRequired(context, geofencingEvent.errorCode)
|
// doReRegisterIfRequired(context, geofencingEvent.errorCode)
|
||||||
|
//
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (geofencingEvent != null) {
|
// if (geofencingEvent != null) {
|
||||||
Logs.GeofenceEvent.save(
|
// Logs.GeofenceEvent.save(
|
||||||
context,
|
// context,
|
||||||
LOG_TAG,
|
// LOG_TAG,
|
||||||
"Geofence event triggered: ${GeofenceTransition.fromInt(geofencingEvent.geofenceTransition).value} for ${geofencingEvent.triggeringGeofences?.map { it.requestId }}",
|
// "Geofence event triggered: ${GeofenceTransition.fromInt(geofencingEvent.geofenceTransition).value} for ${geofencingEvent.triggeringGeofences?.map { it.requestId }}",
|
||||||
Logs.STATUS.SUCCESS
|
// Logs.STATUS.SUCCESS
|
||||||
)
|
// )
|
||||||
geofencingEvent.triggeringLocation?.let {
|
// geofencingEvent.triggeringLocation?.let {
|
||||||
geofencingEvent.triggeringGeofences?.let { it1 ->
|
// geofencingEvent.triggeringGeofences?.let { it1 ->
|
||||||
HMG_Geofence.shared(context).handleEvent(
|
// HMG_Geofence.shared(context).handleEvent(
|
||||||
it1,
|
// it1,
|
||||||
it, GeofenceTransition.fromInt(geofencingEvent.geofenceTransition)
|
// it, GeofenceTransition.fromInt(geofencingEvent.geofenceTransition)
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun doReRegisterIfRequired(context: Context, errorCode: Int) {
|
// fun doReRegisterIfRequired(context: Context, errorCode: Int) {
|
||||||
val errorRequiredReregister = listOf(
|
// val errorRequiredReregister = listOf(
|
||||||
GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE,
|
// GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE,
|
||||||
GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES,
|
// GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES,
|
||||||
GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS,
|
// GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS,
|
||||||
GeofenceStatusCodes.GEOFENCE_REQUEST_TOO_FREQUENT
|
// GeofenceStatusCodes.GEOFENCE_REQUEST_TOO_FREQUENT
|
||||||
)
|
// )
|
||||||
|
//
|
||||||
if (errorRequiredReregister.contains(errorCode))
|
// if (errorRequiredReregister.contains(errorCode))
|
||||||
HMG_Geofence.shared(context).register() { status, error ->
|
// HMG_Geofence.shared(context).register() { status, error ->
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
@ -1,16 +1,16 @@
|
|||||||
|
//
|
||||||
|
//
|
||||||
package com.ejada.hmg.geofence.intent_receivers
|
//package com.ejada.hmg.geofence.intent_receivers
|
||||||
|
//
|
||||||
import android.content.BroadcastReceiver
|
//import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.content.Intent
|
//import android.content.Intent
|
||||||
import com.ejada.hmg.geofence.HMG_Geofence
|
//import com.ejada.hmg.geofence.HMG_Geofence
|
||||||
import com.google.android.gms.location.GeofenceStatusCodes
|
//import com.google.android.gms.location.GeofenceStatusCodes
|
||||||
|
//
|
||||||
class GeofenceBroadcastReceiverWithJobService : BroadcastReceiver() {
|
//class GeofenceBroadcastReceiverWithJobService : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
// override fun onReceive(context: Context, intent: Intent) {
|
||||||
GeofenceTransitionsJobIntentService.enqueueWork(context, intent)
|
// GeofenceTransitionsJobIntentService.enqueueWork(context, intent)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
@ -1,43 +1,43 @@
|
|||||||
|
//
|
||||||
|
//
|
||||||
package com.ejada.hmg.geofence.intent_receivers
|
//package com.ejada.hmg.geofence.intent_receivers
|
||||||
|
//
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import com.ejada.hmg.R
|
//import sa.edu.kku.kkuMcApp.R
|
||||||
import com.ejada.hmg.geofence.HMG_Geofence
|
//import com.ejada.hmg.geofence.HMG_Geofence
|
||||||
import com.google.android.gms.common.api.ApiException
|
//import com.google.android.gms.common.api.ApiException
|
||||||
import com.google.android.gms.location.GeofenceStatusCodes
|
//import com.google.android.gms.location.GeofenceStatusCodes
|
||||||
|
//
|
||||||
object GeofenceErrorMessages {
|
//object GeofenceErrorMessages {
|
||||||
fun getErrorString(context: Context, e: Exception): String {
|
// fun getErrorString(context: Context, e: Exception): String {
|
||||||
return if (e is ApiException) {
|
// return if (e is ApiException) {
|
||||||
getErrorString(context, e.statusCode)
|
// getErrorString(context, e.statusCode)
|
||||||
} else {
|
// } else {
|
||||||
context.resources.getString(R.string.geofence_unknown_error)
|
// context.resources.getString(R.string.geofence_unknown_error)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun getErrorString(context: Context, errorCode: Int): String {
|
// fun getErrorString(context: Context, errorCode: Int): String {
|
||||||
val resources = context.resources
|
// val resources = context.resources
|
||||||
val errorMessage = when (errorCode) {
|
// val errorMessage = when (errorCode) {
|
||||||
GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE ->
|
// GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE ->
|
||||||
resources.getString(R.string.geofence_not_available)
|
// resources.getString(R.string.geofence_not_available)
|
||||||
|
//
|
||||||
GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES ->
|
// GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES ->
|
||||||
resources.getString(R.string.geofence_too_many_geofences)
|
// resources.getString(R.string.geofence_too_many_geofences)
|
||||||
|
//
|
||||||
GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS ->
|
// GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS ->
|
||||||
resources.getString(R.string.geofence_too_many_pending_intents)
|
// resources.getString(R.string.geofence_too_many_pending_intents)
|
||||||
|
//
|
||||||
GeofenceStatusCodes.GEOFENCE_INSUFFICIENT_LOCATION_PERMISSION ->
|
// GeofenceStatusCodes.GEOFENCE_INSUFFICIENT_LOCATION_PERMISSION ->
|
||||||
resources.getString(R.string.GEOFENCE_INSUFFICIENT_LOCATION_PERMISSION)
|
// resources.getString(R.string.GEOFENCE_INSUFFICIENT_LOCATION_PERMISSION)
|
||||||
|
//
|
||||||
GeofenceStatusCodes.GEOFENCE_REQUEST_TOO_FREQUENT ->
|
// GeofenceStatusCodes.GEOFENCE_REQUEST_TOO_FREQUENT ->
|
||||||
resources.getString(R.string.GEOFENCE_REQUEST_TOO_FREQUENT)
|
// resources.getString(R.string.GEOFENCE_REQUEST_TOO_FREQUENT)
|
||||||
|
//
|
||||||
else -> resources.getString(R.string.geofence_unknown_error)
|
// else -> resources.getString(R.string.geofence_unknown_error)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return errorMessage
|
// return errorMessage
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
@ -1,97 +1,97 @@
|
|||||||
/*
|
///*
|
||||||
* Copyright (c) 2018 Razeware LLC
|
// * Copyright (c) 2018 Razeware LLC
|
||||||
*
|
// *
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
// * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
// * of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
// * in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
// * copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
// * furnished to do so, subject to the following conditions:
|
||||||
*
|
// *
|
||||||
* The above copyright notice and this permission notice shall be included in
|
// * The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
// * all copies or substantial portions of the Software.
|
||||||
*
|
// *
|
||||||
* Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
|
// * Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
|
||||||
* distribute, sublicense, create a derivative work, and/or sell copies of the
|
// * distribute, sublicense, create a derivative work, and/or sell copies of the
|
||||||
* Software in any work that is designed, intended, or marketed for pedagogical or
|
// * Software in any work that is designed, intended, or marketed for pedagogical or
|
||||||
* instructional purposes related to programming, coding, application development,
|
// * instructional purposes related to programming, coding, application development,
|
||||||
* or information technology. Permission for such use, copying, modification,
|
// * or information technology. Permission for such use, copying, modification,
|
||||||
* merger, publication, distribution, sublicensing, creation of derivative works,
|
// * merger, publication, distribution, sublicensing, creation of derivative works,
|
||||||
* or sale is expressly withheld.
|
// * or sale is expressly withheld.
|
||||||
*
|
// *
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
// * THE SOFTWARE.
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
|
//
|
||||||
package com.ejada.hmg.geofence.intent_receivers
|
//package com.ejada.hmg.geofence.intent_receivers
|
||||||
|
//
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.content.Intent
|
//import android.content.Intent
|
||||||
import android.util.Log
|
//import android.util.Log
|
||||||
import androidx.core.app.JobIntentService
|
//import androidx.core.app.JobIntentService
|
||||||
import com.ejada.hmg.geofence.GeofenceTransition
|
//import com.ejada.hmg.geofence.GeofenceTransition
|
||||||
import com.ejada.hmg.geofence.HMG_Geofence
|
//import com.ejada.hmg.geofence.HMG_Geofence
|
||||||
import com.ejada.hmg.utils.saveLog
|
//import com.ejada.hmg.utils.saveLog
|
||||||
import com.google.android.gms.location.GeofenceStatusCodes
|
//import com.google.android.gms.location.GeofenceStatusCodes
|
||||||
import com.google.android.gms.location.GeofencingEvent
|
//import com.google.android.gms.location.GeofencingEvent
|
||||||
|
//
|
||||||
class GeofenceTransitionsJobIntentService : JobIntentService() {
|
//class GeofenceTransitionsJobIntentService : JobIntentService() {
|
||||||
|
//
|
||||||
companion object {
|
// companion object {
|
||||||
private const val LOG_TAG = "GeoTrIntentService"
|
// private const val LOG_TAG = "GeoTrIntentService"
|
||||||
|
//
|
||||||
private const val JOB_ID = 95902
|
// private const val JOB_ID = 95902
|
||||||
var context_: Context? = null
|
// var context_: Context? = null
|
||||||
fun enqueueWork(context: Context, intent: Intent) {
|
// fun enqueueWork(context: Context, intent: Intent) {
|
||||||
context_ = context
|
// context_ = context
|
||||||
enqueueWork(
|
// enqueueWork(
|
||||||
context,
|
// context,
|
||||||
GeofenceTransitionsJobIntentService::class.java, JOB_ID,
|
// GeofenceTransitionsJobIntentService::class.java, JOB_ID,
|
||||||
intent)
|
// intent)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override fun onHandleWork(intent: Intent) {
|
// override fun onHandleWork(intent: Intent) {
|
||||||
val geofencingEvent = GeofencingEvent.fromIntent(intent)
|
// val geofencingEvent = GeofencingEvent.fromIntent(intent)
|
||||||
if (geofencingEvent != null) {
|
// if (geofencingEvent != null) {
|
||||||
if (geofencingEvent.hasError()) {
|
// if (geofencingEvent.hasError()) {
|
||||||
val errorMessage = GeofenceErrorMessages.getErrorString(context_!!, geofencingEvent.errorCode)
|
// val errorMessage = GeofenceErrorMessages.getErrorString(context_!!, geofencingEvent.errorCode)
|
||||||
Log.e(LOG_TAG, errorMessage)
|
// Log.e(LOG_TAG, errorMessage)
|
||||||
|
//
|
||||||
|
//
|
||||||
saveLog(context_!!,LOG_TAG,errorMessage)
|
// saveLog(context_!!,LOG_TAG,errorMessage)
|
||||||
doReRegisterIfRequired(context_!!, geofencingEvent.errorCode)
|
// doReRegisterIfRequired(context_!!, geofencingEvent.errorCode)
|
||||||
|
//
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (geofencingEvent != null) {
|
// if (geofencingEvent != null) {
|
||||||
geofencingEvent.triggeringGeofences?.let { geofencingEvent.triggeringLocation?.let { it1 ->
|
// geofencingEvent.triggeringGeofences?.let { geofencingEvent.triggeringLocation?.let { it1 ->
|
||||||
HMG_Geofence.shared(context_!!).handleEvent(it,
|
// HMG_Geofence.shared(context_!!).handleEvent(it,
|
||||||
it1, GeofenceTransition.fromInt(geofencingEvent.geofenceTransition))
|
// it1, GeofenceTransition.fromInt(geofencingEvent.geofenceTransition))
|
||||||
} }
|
// } }
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
fun doReRegisterIfRequired(context: Context, errorCode: Int){
|
// fun doReRegisterIfRequired(context: Context, errorCode: Int){
|
||||||
val errorRequiredReregister = listOf(
|
// val errorRequiredReregister = listOf(
|
||||||
GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE,
|
// GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE,
|
||||||
GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES,
|
// GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES,
|
||||||
GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS,
|
// GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS,
|
||||||
GeofenceStatusCodes.GEOFENCE_REQUEST_TOO_FREQUENT
|
// GeofenceStatusCodes.GEOFENCE_REQUEST_TOO_FREQUENT
|
||||||
)
|
// )
|
||||||
|
//
|
||||||
if(errorRequiredReregister.contains(errorCode))
|
// if(errorRequiredReregister.contains(errorCode))
|
||||||
HMG_Geofence.shared(context).register(){ status, exc -> }
|
// HMG_Geofence.shared(context).register(){ status, exc -> }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
@ -1,23 +1,23 @@
|
|||||||
|
//
|
||||||
|
//
|
||||||
package com.ejada.hmg.geofence.intent_receivers
|
//package com.ejada.hmg.geofence.intent_receivers
|
||||||
|
//
|
||||||
import android.content.BroadcastReceiver
|
//import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.content.Intent
|
//import android.content.Intent
|
||||||
import com.ejada.hmg.geofence.HMG_Geofence
|
//import com.ejada.hmg.geofence.HMG_Geofence
|
||||||
import com.ejada.hmg.utils.PREFS_STORAGE
|
//import com.ejada.hmg.utils.PREFS_STORAGE
|
||||||
|
//
|
||||||
class GeofencingRebootBroadcastReceiver : BroadcastReceiver(){
|
//class GeofencingRebootBroadcastReceiver : BroadcastReceiver(){
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
// override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
//
|
||||||
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.action)) {
|
// if (Intent.ACTION_BOOT_COMPLETED.equals(intent.action)) {
|
||||||
// if (intent.action.equals("android.intent.action.BOOT_COMPLETE")) {
|
//// if (intent.action.equals("android.intent.action.BOOT_COMPLETE")) {
|
||||||
val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
// val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
||||||
pref.edit().putString("REBOOT_DETECTED","YES").apply()
|
// pref.edit().putString("REBOOT_DETECTED","YES").apply()
|
||||||
|
//
|
||||||
HMG_Geofence.shared(context).register(){ status, error -> }
|
// HMG_Geofence.shared(context).register(){ status, error -> }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
@ -1,25 +1,25 @@
|
|||||||
|
//
|
||||||
|
//
|
||||||
package com.ejada.hmg.geofence.intent_receivers
|
//package com.ejada.hmg.geofence.intent_receivers
|
||||||
|
//
|
||||||
import android.content.BroadcastReceiver
|
//import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.content.Intent
|
//import android.content.Intent
|
||||||
import android.location.LocationManager
|
//import android.location.LocationManager
|
||||||
import com.ejada.hmg.geofence.HMG_Geofence
|
//import com.ejada.hmg.geofence.HMG_Geofence
|
||||||
import com.ejada.hmg.utils.HMGUtils
|
//import com.ejada.hmg.utils.HMGUtils
|
||||||
import com.ejada.hmg.utils.PREFS_STORAGE
|
//import com.ejada.hmg.utils.PREFS_STORAGE
|
||||||
|
//
|
||||||
class LocationProviderChangeReceiver : BroadcastReceiver() {
|
//class LocationProviderChangeReceiver : BroadcastReceiver() {
|
||||||
private val LOG_TAG = "LocationProviderChangeReceiver"
|
// private val LOG_TAG = "LocationProviderChangeReceiver"
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
// override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
//
|
||||||
if (LocationManager.PROVIDERS_CHANGED_ACTION.equals(intent.action)) {
|
// if (LocationManager.PROVIDERS_CHANGED_ACTION.equals(intent.action)) {
|
||||||
val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
// val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
||||||
pref.edit().putString("LOCATION_PROVIDER_CHANGE","YES").apply()
|
// pref.edit().putString("LOCATION_PROVIDER_CHANGE","YES").apply()
|
||||||
|
//
|
||||||
HMG_Geofence.shared(context).register(){ s, e -> }
|
// HMG_Geofence.shared(context).register(){ s, e -> }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
@ -1,24 +1,24 @@
|
|||||||
package com.ejada.hmg.geofence.intent_receivers
|
//package com.ejada.hmg.geofence.intent_receivers
|
||||||
|
//
|
||||||
import android.app.job.JobParameters
|
//import android.app.job.JobParameters
|
||||||
import android.app.job.JobService
|
//import android.app.job.JobService
|
||||||
import com.ejada.hmg.geofence.HMG_Geofence
|
//import com.ejada.hmg.geofence.HMG_Geofence
|
||||||
import com.ejada.hmg.utils.Logs
|
//import com.ejada.hmg.utils.Logs
|
||||||
|
//
|
||||||
class ReregisterGeofenceJobService : JobService(){
|
//class ReregisterGeofenceJobService : JobService(){
|
||||||
companion object{
|
// companion object{
|
||||||
val TriggerIntervalDuration:String = "06:00:00"
|
// val TriggerIntervalDuration:String = "06:00:00"
|
||||||
val JobID = 918273
|
// val JobID = 918273
|
||||||
}
|
// }
|
||||||
override fun onStartJob(params: JobParameters?): Boolean {
|
// override fun onStartJob(params: JobParameters?): Boolean {
|
||||||
Logs.save(applicationContext,"ReregisterGeofenceJobService.onStartJob", "triggered to re-register the geofences after $TriggerIntervalDuration >> [HH:mm:ss]")
|
// Logs.save(applicationContext,"ReregisterGeofenceJobService.onStartJob", "triggered to re-register the geofences after $TriggerIntervalDuration >> [HH:mm:ss]")
|
||||||
HMG_Geofence.shared(applicationContext).register(){ status, error ->
|
// HMG_Geofence.shared(applicationContext).register(){ status, error ->
|
||||||
jobFinished(params, true)
|
// jobFinished(params, true)
|
||||||
}
|
// }
|
||||||
return true
|
// return true
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override fun onStopJob(params: JobParameters?): Boolean {
|
// override fun onStopJob(params: JobParameters?): Boolean {
|
||||||
return true
|
// return true
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
@ -1,257 +1,257 @@
|
|||||||
package com.ejada.hmg.hmgwifi
|
//package sa.edu.kku.kkuMcApp.hmgwifi
|
||||||
|
//
|
||||||
import android.annotation.SuppressLint
|
//import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.content.Intent
|
//import android.content.Intent
|
||||||
import android.net.*
|
//import android.net.*
|
||||||
import android.net.wifi.*
|
//import android.net.wifi.*
|
||||||
import android.os.Build
|
//import android.os.Build
|
||||||
import android.os.PatternMatcher
|
//import android.os.PatternMatcher
|
||||||
import android.provider.Settings
|
//import android.provider.Settings
|
||||||
import android.util.Log
|
//import android.util.Log
|
||||||
import androidx.annotation.RequiresApi
|
//import androidx.annotation.RequiresApi
|
||||||
import com.ejada.hmg.MainActivity
|
//import sa.edu.kku.kkuMcApp.MainActivity
|
||||||
import com.ejada.hmg.utils.HMGUtils
|
//import sa.edu.kku.kkuMcApp.utils.HMGUtils
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
class HMG_Guest(private var context: MainActivity, ssid: String) {
|
//class HMG_Guest(private var context: MainActivity, ssid: String) {
|
||||||
private val TAG = "HMG_Guest"
|
// private val TAG = "HMG_Guest"
|
||||||
private val TEST = false
|
// private val TEST = false
|
||||||
private var SSID = ssid
|
// private var SSID = ssid
|
||||||
// private var SSID = "HMG-MOHEMM"
|
//// private var SSID = "HMG-MOHEMM"
|
||||||
|
//
|
||||||
val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager?
|
// val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager?
|
||||||
|
//
|
||||||
private lateinit var completionListener: ((status: Boolean, message: String) -> Unit)
|
// private lateinit var completionListener: ((status: Boolean, message: String) -> Unit)
|
||||||
|
//
|
||||||
fun completionOnUiThread(status: Boolean, message: String){
|
// fun completionOnUiThread(status: Boolean, message: String){
|
||||||
completionListener(status, message)
|
// completionListener(status, message)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun enableWifi(){
|
// fun enableWifi(){
|
||||||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q){
|
// if(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q){
|
||||||
wifiManager?.setWifiEnabled(true)
|
// wifiManager?.setWifiEnabled(true)
|
||||||
HMGUtils.popFlutterText(context,"enablingWifi");
|
// HMGUtils.popFlutterText(context,"enablingWifi");
|
||||||
HMGUtils.timer(2000,false){
|
// HMGUtils.timer(2000,false){
|
||||||
connectApiLessThen29()
|
// connectApiLessThen29()
|
||||||
}
|
// }
|
||||||
}else {
|
// }else {
|
||||||
val panelIntent = Intent(Settings.Panel.ACTION_WIFI)
|
// val panelIntent = Intent(Settings.Panel.ACTION_WIFI)
|
||||||
context.startActivityForResult(panelIntent, 1)
|
// context.startActivityForResult(panelIntent, 1)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
/*
|
// /*
|
||||||
* Helpful:
|
// * Helpful:
|
||||||
* http://stackoverflow.com/questions/8818290/how-to-connect-to-a-specific-wifi-network-in-android-programmatically
|
// * http://stackoverflow.com/questions/8818290/how-to-connect-to-a-specific-wifi-network-in-android-programmatically
|
||||||
*/
|
// */
|
||||||
fun connectToHMGGuestNetwork(completion: (status: Boolean, message: String) -> Unit) {
|
// fun connectToHMGGuestNetwork(completion: (status: Boolean, message: String) -> Unit) {
|
||||||
completionListener = completion
|
// completionListener = completion
|
||||||
wifiManager?.let { wm ->
|
// wifiManager?.let { wm ->
|
||||||
if (!wm.isWifiEnabled){
|
// if (!wm.isWifiEnabled){
|
||||||
enableWifi()
|
// enableWifi()
|
||||||
}else{
|
// }else{
|
||||||
connectWifi()
|
// connectWifi()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
private fun errorConnecting(){
|
|
||||||
completionOnUiThread(false, "errorConnectingHmgNetwork")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun connectWifi(){
|
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
|
|
||||||
connectApiGreaterThen28()
|
|
||||||
}else {
|
|
||||||
connectApiLessThen29()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// I }else{f CompileSDK is greater and equals to APILevel 29
|
|
||||||
@RequiresApi(Build.VERSION_CODES.Q)
|
|
||||||
private fun connectApiGreaterThen28(){
|
|
||||||
Log.e(TAG, "connection wifi with Android Q+")
|
|
||||||
|
|
||||||
val networkRequest: NetworkRequest = NetworkRequest.Builder()
|
|
||||||
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
|
|
||||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
|
|
||||||
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) //removeCapability added for hotspots without internet
|
|
||||||
.setNetworkSpecifier(
|
|
||||||
WifiNetworkSpecifier.Builder()
|
|
||||||
.setSsid(SSID)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
).build()
|
|
||||||
|
|
||||||
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
|
||||||
val networkCallback = object : ConnectivityManager.NetworkCallback() {
|
|
||||||
override fun onAvailable(network: Network) {
|
|
||||||
super.onAvailable(network)
|
|
||||||
connectivityManager.bindProcessToNetwork(network)
|
|
||||||
HMGUtils.timer(2000,false){
|
|
||||||
completionListener(true, "Success")
|
|
||||||
}
|
|
||||||
Log.e(TAG, "onAvailable")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLosing(network: Network, maxMsToLive: Int) {
|
|
||||||
super.onLosing(network, maxMsToLive)
|
|
||||||
Log.e(TAG, "onLosing")
|
|
||||||
completionListener(false, "fail")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLost(network: Network) {
|
|
||||||
super.onLost(network)
|
|
||||||
Log.e(TAG, "onLosing")
|
|
||||||
Log.e(TAG, "losing active connection")
|
|
||||||
completionListener(false, "fail")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onUnavailable() {
|
|
||||||
super.onUnavailable()
|
|
||||||
Log.e(TAG, "onUnavailable")
|
|
||||||
completionListener(false, "fail")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//timeout add because "No devices found" wasn't handled correct and doesn't throw Unavailable
|
|
||||||
connectivityManager.requestNetwork(networkRequest, networkCallback, 30000)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun connectApiLessThen29(){
|
|
||||||
val wifi = WifiConfiguration()
|
|
||||||
wifi.SSID = """"$SSID""""
|
|
||||||
wifi.status = WifiConfiguration.Status.ENABLED
|
|
||||||
wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE)
|
|
||||||
|
|
||||||
wifi.networkId = ssidToNetworkId(wifi.SSID)
|
|
||||||
if (wifi.networkId == -1) {
|
|
||||||
wifiManager?.addNetwork(wifi)
|
|
||||||
} else {
|
|
||||||
Log.v(TAG, "WiFi found - updating it.\n")
|
|
||||||
wifiManager?.updateNetwork(wifi)
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.v(TAG, "saving config.\n")
|
|
||||||
wifiManager?.saveConfiguration()
|
|
||||||
|
|
||||||
wifi.networkId = ssidToNetworkId(wifi.SSID)
|
|
||||||
|
|
||||||
Log.v(TAG, "wifi ID in device = " + wifi.networkId)
|
|
||||||
|
|
||||||
var supState: SupplicantState
|
|
||||||
val networkIdToConnect = wifi.networkId
|
|
||||||
if (networkIdToConnect >= 0) {
|
|
||||||
Log.v(TAG, "Start connecting...\n")
|
|
||||||
|
|
||||||
// We disable the network before connecting, because if this was the last connection before
|
|
||||||
// a disconnect(), this will not reconnect.
|
|
||||||
wifiManager?.disableNetwork(networkIdToConnect)
|
|
||||||
wifiManager?.enableNetwork(networkIdToConnect, true)
|
|
||||||
|
|
||||||
val wifiInfo: WifiInfo = wifiManager!!.connectionInfo
|
|
||||||
|
|
||||||
HMGUtils.timer(5000,false){
|
|
||||||
supState = wifiInfo.supplicantState
|
|
||||||
Log.i(TAG, "Done connect to network : status = $supState")
|
|
||||||
val successStates = listOf(SupplicantState.COMPLETED, SupplicantState.ASSOCIATED)
|
|
||||||
if (successStates.contains(supState))
|
|
||||||
completionListener(true,"Connected to internet Wifi")
|
|
||||||
else
|
|
||||||
completionListener(false,"errorConnectingHmgNetwork")
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.v(TAG, "WifiWizard: cannot connect to network")
|
|
||||||
completionListener(false,"errorConnectingHmgNetwork")
|
|
||||||
}
|
|
||||||
|
|
||||||
// val wifi = WifiConfiguration()
|
|
||||||
// wifi.SSID = SSID
|
|
||||||
// wifi.status = WifiConfiguration.Status.ENABLED
|
|
||||||
// wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
|
||||||
//
|
//
|
||||||
// wifi.networkId = ssidToNetworkId(SSID)
|
// private fun errorConnecting(){
|
||||||
|
// completionOnUiThread(false, "errorConnectingHmgNetwork")
|
||||||
|
// }
|
||||||
//
|
//
|
||||||
// // Set network to highest priority (deprecated in API >= 26)
|
// fun connectWifi(){
|
||||||
// if(Build.VERSION.SDK_INT < 26) {
|
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
|
||||||
// wifi.priority = getMaxWifiPriority(wifiManager!!) + 1;
|
// connectApiGreaterThen28()
|
||||||
|
// }else {
|
||||||
|
// connectApiLessThen29()
|
||||||
// }
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // I }else{f CompileSDK is greater and equals to APILevel 29
|
||||||
|
// @RequiresApi(Build.VERSION_CODES.Q)
|
||||||
|
// private fun connectApiGreaterThen28(){
|
||||||
|
// Log.e(TAG, "connection wifi with Android Q+")
|
||||||
//
|
//
|
||||||
// // After processing authentication types, add or update network
|
// val networkRequest: NetworkRequest = NetworkRequest.Builder()
|
||||||
// if(wifi.networkId == -1) { // -1 means SSID configuration does not exist yet
|
// .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
|
||||||
|
// .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
|
||||||
|
// .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) //removeCapability added for hotspots without internet
|
||||||
|
// .setNetworkSpecifier(
|
||||||
|
// WifiNetworkSpecifier.Builder()
|
||||||
|
// .setSsid(SSID)
|
||||||
|
// .build()
|
||||||
//
|
//
|
||||||
// val newNetId = wifiManager?.addNetwork(wifi)!!
|
// ).build()
|
||||||
// if( newNetId > -1 ){
|
//
|
||||||
// completionListener(true,"Success")
|
// val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
// } else {
|
// val networkCallback = object : ConnectivityManager.NetworkCallback() {
|
||||||
// completionListener(false, "ERROR_ADDING_NETWORK" )
|
// override fun onAvailable(network: Network) {
|
||||||
|
// super.onAvailable(network)
|
||||||
|
// connectivityManager.bindProcessToNetwork(network)
|
||||||
|
// HMGUtils.timer(2000,false){
|
||||||
|
// completionListener(true, "Success")
|
||||||
|
// }
|
||||||
|
// Log.e(TAG, "onAvailable")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override fun onLosing(network: Network, maxMsToLive: Int) {
|
||||||
|
// super.onLosing(network, maxMsToLive)
|
||||||
|
// Log.e(TAG, "onLosing")
|
||||||
|
// completionListener(false, "fail")
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
// override fun onLost(network: Network) {
|
||||||
|
// super.onLost(network)
|
||||||
|
// Log.e(TAG, "onLosing")
|
||||||
|
// Log.e(TAG, "losing active connection")
|
||||||
|
// completionListener(false, "fail")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override fun onUnavailable() {
|
||||||
|
// super.onUnavailable()
|
||||||
|
// Log.e(TAG, "onUnavailable")
|
||||||
|
// completionListener(false, "fail")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// //timeout add because "No devices found" wasn't handled correct and doesn't throw Unavailable
|
||||||
|
// connectivityManager.requestNetwork(networkRequest, networkCallback, 30000)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// fun connectApiLessThen29(){
|
||||||
|
// val wifi = WifiConfiguration()
|
||||||
|
// wifi.SSID = """"$SSID""""
|
||||||
|
// wifi.status = WifiConfiguration.Status.ENABLED
|
||||||
|
// wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE)
|
||||||
|
//
|
||||||
|
// wifi.networkId = ssidToNetworkId(wifi.SSID)
|
||||||
|
// if (wifi.networkId == -1) {
|
||||||
|
// wifiManager?.addNetwork(wifi)
|
||||||
// } else {
|
// } else {
|
||||||
|
// Log.v(TAG, "WiFi found - updating it.\n")
|
||||||
|
// wifiManager?.updateNetwork(wifi)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Log.v(TAG, "saving config.\n")
|
||||||
|
// wifiManager?.saveConfiguration()
|
||||||
|
//
|
||||||
|
// wifi.networkId = ssidToNetworkId(wifi.SSID)
|
||||||
//
|
//
|
||||||
// var updatedNetID = wifiManager?.updateNetwork(wifi)
|
// Log.v(TAG, "wifi ID in device = " + wifi.networkId)
|
||||||
//
|
//
|
||||||
// if(updatedNetID == -1)
|
// var supState: SupplicantState
|
||||||
// updatedNetID = wifiManager?.addNetwork(wifi)
|
// val networkIdToConnect = wifi.networkId
|
||||||
|
// if (networkIdToConnect >= 0) {
|
||||||
|
// Log.v(TAG, "Start connecting...\n")
|
||||||
//
|
//
|
||||||
// if(updatedNetID > -1) {
|
// // We disable the network before connecting, because if this was the last connection before
|
||||||
// callbackContext.success( updatedNetID )
|
// // a disconnect(), this will not reconnect.
|
||||||
// } else {
|
// wifiManager?.disableNetwork(networkIdToConnect)
|
||||||
// callbackContext.error("ERROR_UPDATING_NETWORK")
|
// wifiManager?.enableNetwork(networkIdToConnect, true)
|
||||||
|
//
|
||||||
|
// val wifiInfo: WifiInfo = wifiManager!!.connectionInfo
|
||||||
|
//
|
||||||
|
// HMGUtils.timer(5000,false){
|
||||||
|
// supState = wifiInfo.supplicantState
|
||||||
|
// Log.i(TAG, "Done connect to network : status = $supState")
|
||||||
|
// val successStates = listOf(SupplicantState.COMPLETED, SupplicantState.ASSOCIATED)
|
||||||
|
// if (successStates.contains(supState))
|
||||||
|
// completionListener(true,"Connected to internet Wifi")
|
||||||
|
// else
|
||||||
|
// completionListener(false,"errorConnectingHmgNetwork")
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
// } else {
|
||||||
|
// Log.v(TAG, "WifiWizard: cannot connect to network")
|
||||||
|
// completionListener(false,"errorConnectingHmgNetwork")
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// // WifiManager configurations are presistent for API 26+
|
//// val wifi = WifiConfiguration()
|
||||||
// if(Build.VERSION.SDK_INT < 26) {
|
//// wifi.SSID = SSID
|
||||||
// wifiManager?.saveConfiguration(); // Call saveConfiguration for older < 26 API
|
//// wifi.status = WifiConfiguration.Status.ENABLED
|
||||||
|
//// wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
|
||||||
|
////
|
||||||
|
//// wifi.networkId = ssidToNetworkId(SSID)
|
||||||
|
////
|
||||||
|
//// // Set network to highest priority (deprecated in API >= 26)
|
||||||
|
//// if(Build.VERSION.SDK_INT < 26) {
|
||||||
|
//// wifi.priority = getMaxWifiPriority(wifiManager!!) + 1;
|
||||||
|
//// }
|
||||||
|
////
|
||||||
|
//// // After processing authentication types, add or update network
|
||||||
|
//// if(wifi.networkId == -1) { // -1 means SSID configuration does not exist yet
|
||||||
|
////
|
||||||
|
//// val newNetId = wifiManager?.addNetwork(wifi)!!
|
||||||
|
//// if( newNetId > -1 ){
|
||||||
|
//// completionListener(true,"Success")
|
||||||
|
//// } else {
|
||||||
|
//// completionListener(false, "ERROR_ADDING_NETWORK" )
|
||||||
|
//// }
|
||||||
|
////
|
||||||
|
//// } else {
|
||||||
|
////
|
||||||
|
//// var updatedNetID = wifiManager?.updateNetwork(wifi)
|
||||||
|
////
|
||||||
|
//// if(updatedNetID == -1)
|
||||||
|
//// updatedNetID = wifiManager?.addNetwork(wifi)
|
||||||
|
////
|
||||||
|
//// if(updatedNetID > -1) {
|
||||||
|
//// callbackContext.success( updatedNetID )
|
||||||
|
//// } else {
|
||||||
|
//// callbackContext.error("ERROR_UPDATING_NETWORK")
|
||||||
|
//// }
|
||||||
|
////
|
||||||
|
//// }
|
||||||
|
////
|
||||||
|
//// // WifiManager configurations are presistent for API 26+
|
||||||
|
//// if(Build.VERSION.SDK_INT < 26) {
|
||||||
|
//// wifiManager?.saveConfiguration(); // Call saveConfiguration for older < 26 API
|
||||||
|
//// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * This method takes a given String, searches the current list of configured WiFi
|
||||||
|
// * networks, and returns the networkId for the network if the SSID matches. If not,
|
||||||
|
// * it returns -1.
|
||||||
|
// */
|
||||||
|
// @SuppressLint("MissingPermission")
|
||||||
|
// private fun ssidToNetworkId(ssid: String): Int {
|
||||||
|
// val currentNetworks = wifiManager!!.configuredNetworks
|
||||||
|
// var networkId = -1
|
||||||
|
//
|
||||||
|
// // For each network in the list, compare the SSID with the given one
|
||||||
|
// for (test in currentNetworks) {
|
||||||
|
// if (test.SSID == ssid) {
|
||||||
|
// networkId = test.networkId
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return networkId
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// companion object{
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Figure out what the highest priority network in the network list is and return that priority
|
||||||
|
// */
|
||||||
|
// @RequiresApi(Build.VERSION_CODES.S)
|
||||||
|
// fun getMaxWifiPriority(wifiManager:WifiManager) : Int {
|
||||||
|
// val configurations = wifiManager.callerConfiguredNetworks
|
||||||
|
// var maxPriority = 0
|
||||||
|
// configurations.forEach {
|
||||||
|
// if (it.priority > maxPriority) {
|
||||||
|
// maxPriority = it.priority;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return maxPriority;
|
||||||
// }
|
// }
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method takes a given String, searches the current list of configured WiFi
|
|
||||||
* networks, and returns the networkId for the network if the SSID matches. If not,
|
|
||||||
* it returns -1.
|
|
||||||
*/
|
|
||||||
@SuppressLint("MissingPermission")
|
|
||||||
private fun ssidToNetworkId(ssid: String): Int {
|
|
||||||
val currentNetworks = wifiManager!!.configuredNetworks
|
|
||||||
var networkId = -1
|
|
||||||
|
|
||||||
// For each network in the list, compare the SSID with the given one
|
|
||||||
for (test in currentNetworks) {
|
|
||||||
if (test.SSID == ssid) {
|
|
||||||
networkId = test.networkId
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return networkId
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Figure out what the highest priority network in the network list is and return that priority
|
|
||||||
*/
|
|
||||||
@RequiresApi(Build.VERSION_CODES.S)
|
|
||||||
fun getMaxWifiPriority(wifiManager:WifiManager) : Int {
|
|
||||||
val configurations = wifiManager.callerConfiguredNetworks
|
|
||||||
var maxPriority = 0
|
|
||||||
configurations.forEach {
|
|
||||||
if (it.priority > maxPriority) {
|
|
||||||
maxPriority = it.priority;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return maxPriority;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,120 +1,120 @@
|
|||||||
package com.ejada.hmg.hmgwifi
|
//package com.ejada.hmg.hmgwifi
|
||||||
|
//
|
||||||
import android.annotation.SuppressLint
|
//import android.annotation.SuppressLint
|
||||||
import com.ejada.hmg.utils.API
|
//import com.ejada.hmg.utils.API
|
||||||
import com.ejada.hmg.MainActivity
|
//import com.ejada.hmg.MainActivity
|
||||||
import com.github.kittinunf.fuel.core.extensions.jsonBody
|
//import com.github.kittinunf.fuel.core.extensions.jsonBody
|
||||||
import com.github.kittinunf.fuel.httpGet
|
//import com.github.kittinunf.fuel.httpGet
|
||||||
import com.github.kittinunf.fuel.httpPost
|
//import com.github.kittinunf.fuel.httpPost
|
||||||
import org.json.JSONObject
|
//import org.json.JSONObject
|
||||||
import java.util.*
|
//import java.util.*
|
||||||
|
//
|
||||||
|
//
|
||||||
@SuppressLint("MissingPermission")
|
//@SuppressLint("MissingPermission")
|
||||||
class HMG_Internet(flutterMainActivity: MainActivity) {
|
//class HMG_Internet(flutterMainActivity: MainActivity) {
|
||||||
private val TAG = "HMG_Wifi"
|
// private val TAG = "HMG_Wifi"
|
||||||
private val TEST = true
|
// private val TEST = true
|
||||||
|
//
|
||||||
private var context = flutterMainActivity;
|
// private var context = flutterMainActivity;
|
||||||
|
//
|
||||||
private lateinit var completionListener: ((status: Boolean, message: String) -> Unit)
|
// private lateinit var completionListener: ((status: Boolean, message: String) -> Unit)
|
||||||
|
//
|
||||||
private var SSID = "GUEST-POC"
|
// private var SSID = "GUEST-POC"
|
||||||
|
//
|
||||||
fun completionOnUiThread(status: Boolean, message: String){
|
// fun completionOnUiThread(status: Boolean, message: String){
|
||||||
completionListener(status, message)
|
// completionListener(status, message)
|
||||||
// context.runOnUiThread {
|
//// context.runOnUiThread {
|
||||||
// .with(message){localized ->
|
//// .with(message){localized ->
|
||||||
// completionListener(status, localized)
|
//// completionListener(status, localized)
|
||||||
// }
|
//// }
|
||||||
|
//// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /*
|
||||||
|
// * Helpful:
|
||||||
|
// * http://stackoverflow.com/questions/8818290/how-to-connect-to-a-specific-wifi-network-in-android-programmatically
|
||||||
|
// */
|
||||||
|
// fun connectToHMGGuestNetwork(username: String, password: String, completion: (status: Boolean, message: String) -> Unit): HMG_Internet {
|
||||||
|
// completionListener = completion
|
||||||
|
// WpaEnterprise(context,SSID).connect(username,username) { status, message ->
|
||||||
|
// completionOnUiThread(status,message)
|
||||||
// }
|
// }
|
||||||
}
|
// return this
|
||||||
|
// }
|
||||||
/*
|
//
|
||||||
* Helpful:
|
// private fun haveInternet(completion: ((status: Boolean) -> Unit)){
|
||||||
* http://stackoverflow.com/questions/8818290/how-to-connect-to-a-specific-wifi-network-in-android-programmatically
|
// if (TEST)
|
||||||
*/
|
// completion(true)
|
||||||
fun connectToHMGGuestNetwork(username: String, password: String, completion: (status: Boolean, message: String) -> Unit): HMG_Internet {
|
//
|
||||||
completionListener = completion
|
// "https://captive.apple.com".httpGet().response { request, response, result ->
|
||||||
WpaEnterprise(context,SSID).connect(username,username) { status, message ->
|
// result.fold(success = {
|
||||||
completionOnUiThread(status,message)
|
// val html = String(it).toLowerCase(Locale.ENGLISH)
|
||||||
}
|
// .replace(" ", "", true)
|
||||||
return this
|
// .replace("\n","",true)
|
||||||
}
|
// val have = html.contains("<title>success</title>", true)
|
||||||
|
// completion(have)
|
||||||
private fun haveInternet(completion: ((status: Boolean) -> Unit)){
|
//
|
||||||
if (TEST)
|
// },failure = {
|
||||||
completion(true)
|
// completion(false)
|
||||||
|
// })
|
||||||
"https://captive.apple.com".httpGet().response { request, response, result ->
|
// }
|
||||||
result.fold(success = {
|
// }
|
||||||
val html = String(it).toLowerCase(Locale.ENGLISH)
|
//
|
||||||
.replace(" ", "", true)
|
// private fun getWifiCredentials(patientId:String, success: ((String?,String?) -> Unit)){
|
||||||
.replace("\n","",true)
|
// if (TEST){
|
||||||
val have = html.contains("<title>success</title>", true)
|
// SSID = "GUEST-POC"
|
||||||
completion(have)
|
// success("2300", "0000")
|
||||||
|
// return
|
||||||
},failure = {
|
// }
|
||||||
completion(false)
|
//
|
||||||
})
|
// val jsonBody = """{
|
||||||
}
|
// "PatientID":$patientId
|
||||||
}
|
// "VersionID": 8.8,
|
||||||
|
// "Channel": 3,
|
||||||
private fun getWifiCredentials(patientId:String, success: ((String?,String?) -> Unit)){
|
// "LanguageID": 2,
|
||||||
if (TEST){
|
// "IPAdress": "10.20.10.20",
|
||||||
SSID = "GUEST-POC"
|
// "generalid": "Cs2020@2016$2958",
|
||||||
success("2300", "0000")
|
// "PatientOutSA": 0,
|
||||||
return
|
// "SessionID": "@admin",
|
||||||
}
|
// "isDentalAllowedBackend": false,
|
||||||
|
// "DeviceTypeID": 2,
|
||||||
val jsonBody = """{
|
// "TokenID": "@admin",
|
||||||
"PatientID":$patientId
|
// "PatientTypeID": 1,
|
||||||
"VersionID": 8.8,
|
// "PatientType": 1
|
||||||
"Channel": 3,
|
// }""".trimMargin()
|
||||||
"LanguageID": 2,
|
// API.WIFI_CREDENTIALS.
|
||||||
"IPAdress": "10.20.10.20",
|
// httpPost()
|
||||||
"generalid": "Cs2020@2016$2958",
|
// .jsonBody(jsonBody, Charsets.UTF_8)
|
||||||
"PatientOutSA": 0,
|
// .response { request, response, result ->
|
||||||
"SessionID": "@admin",
|
//
|
||||||
"isDentalAllowedBackend": false,
|
// result.fold(success = { data ->
|
||||||
"DeviceTypeID": 2,
|
// val jsonString = String(data)
|
||||||
"TokenID": "@admin",
|
// val jsonObject = JSONObject(jsonString)
|
||||||
"PatientTypeID": 1,
|
// if(!jsonObject.getString("ErrorMessage").equals("null")){
|
||||||
"PatientType": 1
|
// val errorMsg = jsonObject.getString("ErrorMessage")
|
||||||
}""".trimMargin()
|
// completionOnUiThread(false, errorMsg)
|
||||||
API.WIFI_CREDENTIALS.
|
//
|
||||||
httpPost()
|
// }else{
|
||||||
.jsonBody(jsonBody, Charsets.UTF_8)
|
// jsonObject.getJSONArray("Hmg_SMS_Get_By_ProjectID_And_PatientIDList").let { array ->
|
||||||
.response { request, response, result ->
|
// array.getJSONObject(0).let { object_ ->
|
||||||
|
// if (object_.has("UserName") && object_.has("UserName")){
|
||||||
result.fold(success = { data ->
|
// try {
|
||||||
val jsonString = String(data)
|
// val userName = object_.getString("UserName")
|
||||||
val jsonObject = JSONObject(jsonString)
|
// val password = object_.getString("Password")
|
||||||
if(!jsonObject.getString("ErrorMessage").equals("null")){
|
// success(userName, password)
|
||||||
val errorMsg = jsonObject.getString("ErrorMessage")
|
// }catch (e:Exception){
|
||||||
completionOnUiThread(false, errorMsg)
|
// success(null, null)
|
||||||
|
// }
|
||||||
}else{
|
// }else{
|
||||||
jsonObject.getJSONArray("Hmg_SMS_Get_By_ProjectID_And_PatientIDList").let { array ->
|
// completionOnUiThread(false, "somethingWentWrong")
|
||||||
array.getJSONObject(0).let { object_ ->
|
// }
|
||||||
if (object_.has("UserName") && object_.has("UserName")){
|
// }
|
||||||
try {
|
// }
|
||||||
val userName = object_.getString("UserName")
|
// }
|
||||||
val password = object_.getString("Password")
|
//
|
||||||
success(userName, password)
|
// },failure = { error ->
|
||||||
}catch (e:Exception){
|
// completionOnUiThread(false, "somethingWentWrong" )
|
||||||
success(null, null)
|
// })
|
||||||
}
|
// }
|
||||||
}else{
|
// }
|
||||||
completionOnUiThread(false, "somethingWentWrong")
|
//}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
},failure = { error ->
|
|
||||||
completionOnUiThread(false, "somethingWentWrong" )
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,105 +1,105 @@
|
|||||||
package com.ejada.hmg.hmgwifi
|
//package com.ejada.hmg.hmgwifi
|
||||||
|
//
|
||||||
import android.annotation.SuppressLint
|
//import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.net.ConnectivityManager
|
//import android.net.ConnectivityManager
|
||||||
import android.net.wifi.*
|
//import android.net.wifi.*
|
||||||
import android.net.wifi.SupplicantState.ASSOCIATED
|
//import android.net.wifi.SupplicantState.ASSOCIATED
|
||||||
import android.net.wifi.SupplicantState.COMPLETED
|
//import android.net.wifi.SupplicantState.COMPLETED
|
||||||
import android.util.Log
|
//import android.util.Log
|
||||||
import com.ejada.hmg.MainActivity
|
//import com.ejada.hmg.MainActivity
|
||||||
import com.ejada.hmg.utils.HMGUtils
|
//import com.ejada.hmg.utils.HMGUtils
|
||||||
|
//
|
||||||
class WPA(mainActivity: MainActivity, SSID:String) {
|
//class WPA(mainActivity: MainActivity, SSID:String) {
|
||||||
private var TAG = "WPA"
|
// private var TAG = "WPA"
|
||||||
private var SSID = "GUEST-POC"
|
// private var SSID = "GUEST-POC"
|
||||||
private var wifiManager_: WifiManager? = null
|
// private var wifiManager_: WifiManager? = null
|
||||||
private var connectivityManager_: ConnectivityManager? = null
|
// private var connectivityManager_: ConnectivityManager? = null
|
||||||
|
//
|
||||||
init {
|
// init {
|
||||||
wifiManager_ = mainActivity.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager?
|
// wifiManager_ = mainActivity.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager?
|
||||||
connectivityManager_ = mainActivity.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager?
|
// connectivityManager_ = mainActivity.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager?
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun connect(identity:String, password:String, completion: (status: Boolean, message: String) -> Unit) {
|
// fun connect(identity:String, password:String, completion: (status: Boolean, message: String) -> Unit) {
|
||||||
if(wifiManager_ == null || connectivityManager_ == null){
|
// if(wifiManager_ == null || connectivityManager_ == null){
|
||||||
completion(false,"errorConnectingHmgNetwork")
|
// completion(false,"errorConnectingHmgNetwork")
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
val wifiManager = wifiManager_!!
|
// val wifiManager = wifiManager_!!
|
||||||
val connectivityManager = connectivityManager_!!
|
// val connectivityManager = connectivityManager_!!
|
||||||
|
//
|
||||||
// Initialize the WifiConfiguration object
|
// // Initialize the WifiConfiguration object
|
||||||
val enterpriseConfig = WifiEnterpriseConfig()
|
// val enterpriseConfig = WifiEnterpriseConfig()
|
||||||
val wifi = WifiConfiguration()
|
// val wifi = WifiConfiguration()
|
||||||
wifi.SSID = """"$SSID""""
|
// wifi.SSID = """"$SSID""""
|
||||||
wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP)
|
// wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP)
|
||||||
wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X)
|
// wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X)
|
||||||
enterpriseConfig.eapMethod = WifiEnterpriseConfig.Eap.PEAP
|
// enterpriseConfig.eapMethod = WifiEnterpriseConfig.Eap.PEAP
|
||||||
enterpriseConfig.identity = identity
|
// enterpriseConfig.identity = identity
|
||||||
enterpriseConfig.password = password
|
// enterpriseConfig.password = password
|
||||||
wifi.enterpriseConfig = enterpriseConfig
|
// wifi.enterpriseConfig = enterpriseConfig
|
||||||
wifi.networkId = ssidToNetworkId(wifi.SSID)
|
// wifi.networkId = ssidToNetworkId(wifi.SSID)
|
||||||
if (wifi.networkId == -1) {
|
// if (wifi.networkId == -1) {
|
||||||
wifiManager.addNetwork(wifi)
|
// wifiManager.addNetwork(wifi)
|
||||||
} else {
|
// } else {
|
||||||
Log.v(TAG, "WiFi found - updating it.\n")
|
// Log.v(TAG, "WiFi found - updating it.\n")
|
||||||
wifiManager.updateNetwork(wifi)
|
// wifiManager.updateNetwork(wifi)
|
||||||
}
|
// }
|
||||||
Log.v(TAG, "saving config.\n")
|
// Log.v(TAG, "saving config.\n")
|
||||||
wifiManager.saveConfiguration()
|
// wifiManager.saveConfiguration()
|
||||||
wifi.networkId = ssidToNetworkId(wifi.SSID)
|
// wifi.networkId = ssidToNetworkId(wifi.SSID)
|
||||||
|
//
|
||||||
Log.v(TAG, "wifi ID in device = " + wifi.networkId)
|
// Log.v(TAG, "wifi ID in device = " + wifi.networkId)
|
||||||
|
//
|
||||||
var supState: SupplicantState
|
// var supState: SupplicantState
|
||||||
val networkIdToConnect = wifi.networkId
|
// val networkIdToConnect = wifi.networkId
|
||||||
if (networkIdToConnect >= 0) {
|
// if (networkIdToConnect >= 0) {
|
||||||
Log.v(TAG, "Start connecting...\n")
|
// Log.v(TAG, "Start connecting...\n")
|
||||||
|
//
|
||||||
// We disable the network before connecting, because if this was the last connection before
|
// // We disable the network before connecting, because if this was the last connection before
|
||||||
// a disconnect(), this will not reconnect.
|
// // a disconnect(), this will not reconnect.
|
||||||
wifiManager.disableNetwork(networkIdToConnect)
|
// wifiManager.disableNetwork(networkIdToConnect)
|
||||||
wifiManager.enableNetwork(networkIdToConnect, true)
|
// wifiManager.enableNetwork(networkIdToConnect, true)
|
||||||
|
//
|
||||||
val wifiInfo: WifiInfo = wifiManager.connectionInfo
|
// val wifiInfo: WifiInfo = wifiManager.connectionInfo
|
||||||
|
//
|
||||||
HMGUtils.timer(5000,false){
|
// HMGUtils.timer(5000,false){
|
||||||
supState = wifiInfo.supplicantState
|
// supState = wifiInfo.supplicantState
|
||||||
Log.i(TAG, "WifiWizard: Done connect to network : status = $supState")
|
// Log.i(TAG, "WifiWizard: Done connect to network : status = $supState")
|
||||||
val successStates = listOf(COMPLETED, ASSOCIATED)
|
// val successStates = listOf(COMPLETED, ASSOCIATED)
|
||||||
if (successStates.contains(COMPLETED /*supState*/))
|
// if (successStates.contains(COMPLETED /*supState*/))
|
||||||
|
//
|
||||||
completion(true,"Connected to internet Wifi")
|
// completion(true,"Connected to internet Wifi")
|
||||||
|
//
|
||||||
else
|
// else
|
||||||
completion(false,"errorConnectingHmgNetwork")
|
// completion(false,"errorConnectingHmgNetwork")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
} else {
|
// } else {
|
||||||
Log.v(TAG, "WifiWizard: cannot connect to network")
|
// Log.v(TAG, "WifiWizard: cannot connect to network")
|
||||||
completion(false,"errorConnectingHmgNetwork")
|
// completion(false,"errorConnectingHmgNetwork")
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* This method takes a given String, searches the current list of configured WiFi
|
// * This method takes a given String, searches the current list of configured WiFi
|
||||||
* networks, and returns the networkId for the network if the SSID matches. If not,
|
// * networks, and returns the networkId for the network if the SSID matches. If not,
|
||||||
* it returns -1.
|
// * it returns -1.
|
||||||
*/
|
// */
|
||||||
@SuppressLint("MissingPermission")
|
// @SuppressLint("MissingPermission")
|
||||||
private fun ssidToNetworkId(ssid: String): Int {
|
// private fun ssidToNetworkId(ssid: String): Int {
|
||||||
val currentNetworks = wifiManager_!!.configuredNetworks
|
// val currentNetworks = wifiManager_!!.configuredNetworks
|
||||||
var networkId = -1
|
// var networkId = -1
|
||||||
|
//
|
||||||
// For each network in the list, compare the SSID with the given one
|
// // For each network in the list, compare the SSID with the given one
|
||||||
for (test in currentNetworks) {
|
// for (test in currentNetworks) {
|
||||||
if (test.SSID == ssid) {
|
// if (test.SSID == ssid) {
|
||||||
networkId = test.networkId
|
// networkId = test.networkId
|
||||||
break
|
// break
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return networkId
|
// return networkId
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
@ -1,166 +1,166 @@
|
|||||||
package com.ejada.hmg.hmgwifi
|
//package com.ejada.hmg.hmgwifi
|
||||||
|
//
|
||||||
import android.annotation.SuppressLint
|
//import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.net.ConnectivityManager
|
//import android.net.ConnectivityManager
|
||||||
import android.net.Network
|
//import android.net.Network
|
||||||
import android.net.NetworkCapabilities
|
//import android.net.NetworkCapabilities
|
||||||
import android.net.NetworkRequest
|
//import android.net.NetworkRequest
|
||||||
import android.net.wifi.*
|
//import android.net.wifi.*
|
||||||
import android.net.wifi.SupplicantState.ASSOCIATED
|
//import android.net.wifi.SupplicantState.ASSOCIATED
|
||||||
import android.net.wifi.SupplicantState.COMPLETED
|
//import android.net.wifi.SupplicantState.COMPLETED
|
||||||
import android.os.Build
|
//import android.os.Build
|
||||||
import android.util.Log
|
//import android.util.Log
|
||||||
import androidx.annotation.RequiresApi
|
//import androidx.annotation.RequiresApi
|
||||||
import com.ejada.hmg.MainActivity
|
//import com.ejada.hmg.MainActivity
|
||||||
import com.ejada.hmg.utils.HMGUtils
|
//import com.ejada.hmg.utils.HMGUtils
|
||||||
import java.security.cert.X509Certificate
|
//import java.security.cert.X509Certificate
|
||||||
|
//
|
||||||
class WpaEnterprise(private val mainActivity: MainActivity, private var SSID: String) {
|
//class WpaEnterprise(private val mainActivity: MainActivity, private var SSID: String) {
|
||||||
private var TAG = "WpaEnterprise"
|
// private var TAG = "WpaEnterprise"
|
||||||
|
//
|
||||||
private lateinit var identity:String
|
// private lateinit var identity:String
|
||||||
private lateinit var password:String
|
// private lateinit var password:String
|
||||||
private lateinit var completion:((status: Boolean, message: String) -> Unit)
|
// private lateinit var completion:((status: Boolean, message: String) -> Unit)
|
||||||
|
//
|
||||||
fun connect(identity:String, password:String, completion: (status: Boolean, message: String) -> Unit) {
|
// fun connect(identity:String, password:String, completion: (status: Boolean, message: String) -> Unit) {
|
||||||
this.password = password
|
// this.password = password
|
||||||
this.identity = identity
|
// this.identity = identity
|
||||||
this.completion = completion
|
// this.completion = completion
|
||||||
|
//
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
|
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
|
||||||
apiGreaterThen28()
|
// apiGreaterThen28()
|
||||||
}else if(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q){
|
// }else if(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q){
|
||||||
apiLessThen29()
|
// apiLessThen29()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
// @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
fun apiLessThen29(){
|
// fun apiLessThen29(){
|
||||||
val wifiManager = mainActivity.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
// val wifiManager = mainActivity.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||||
|
//
|
||||||
val wifi = WifiConfiguration()
|
// val wifi = WifiConfiguration()
|
||||||
wifi.SSID = """"$SSID""""
|
// wifi.SSID = """"$SSID""""
|
||||||
wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP)
|
// wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP)
|
||||||
wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X)
|
// wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X)
|
||||||
wifi.enterpriseConfig = enterpriseConfig()
|
// wifi.enterpriseConfig = enterpriseConfig()
|
||||||
wifi.networkId = ssidToNetworkId(wifi.SSID, wifiManager)
|
// wifi.networkId = ssidToNetworkId(wifi.SSID, wifiManager)
|
||||||
if (wifi.networkId == -1) {
|
// if (wifi.networkId == -1) {
|
||||||
wifiManager.addNetwork(wifi)
|
// wifiManager.addNetwork(wifi)
|
||||||
} else {
|
// } else {
|
||||||
Log.v(TAG, "WiFi found - updating it.\n")
|
// Log.v(TAG, "WiFi found - updating it.\n")
|
||||||
wifiManager.updateNetwork(wifi)
|
// wifiManager.updateNetwork(wifi)
|
||||||
}
|
// }
|
||||||
Log.v(TAG, "saving config.\n")
|
// Log.v(TAG, "saving config.\n")
|
||||||
wifiManager.saveConfiguration()
|
// wifiManager.saveConfiguration()
|
||||||
wifi.networkId = ssidToNetworkId(wifi.SSID, wifiManager)
|
// wifi.networkId = ssidToNetworkId(wifi.SSID, wifiManager)
|
||||||
|
//
|
||||||
Log.v(TAG, "wifi ID in device = " + wifi.networkId)
|
// Log.v(TAG, "wifi ID in device = " + wifi.networkId)
|
||||||
|
//
|
||||||
var supState: SupplicantState
|
// var supState: SupplicantState
|
||||||
val networkIdToConnect = wifi.networkId
|
// val networkIdToConnect = wifi.networkId
|
||||||
if (networkIdToConnect >= 0) {
|
// if (networkIdToConnect >= 0) {
|
||||||
Log.v(TAG, "Start connecting...\n")
|
// Log.v(TAG, "Start connecting...\n")
|
||||||
|
//
|
||||||
// We disable the network before connecting, because if this was the last connection before
|
// // We disable the network before connecting, because if this was the last connection before
|
||||||
// a disconnect(), this will not reconnect.
|
// // a disconnect(), this will not reconnect.
|
||||||
wifiManager.disableNetwork(networkIdToConnect)
|
// wifiManager.disableNetwork(networkIdToConnect)
|
||||||
wifiManager.enableNetwork(networkIdToConnect, true)
|
// wifiManager.enableNetwork(networkIdToConnect, true)
|
||||||
|
//
|
||||||
val wifiInfo: WifiInfo = wifiManager.connectionInfo
|
// val wifiInfo: WifiInfo = wifiManager.connectionInfo
|
||||||
|
//
|
||||||
HMGUtils.timer(5000,false){
|
// HMGUtils.timer(5000,false){
|
||||||
supState = wifiInfo.supplicantState
|
// supState = wifiInfo.supplicantState
|
||||||
Log.i(TAG, "Done connect to network : status = $supState")
|
// Log.i(TAG, "Done connect to network : status = $supState")
|
||||||
val successStates = listOf(COMPLETED, ASSOCIATED)
|
// val successStates = listOf(COMPLETED, ASSOCIATED)
|
||||||
if (successStates.contains(supState))
|
// if (successStates.contains(supState))
|
||||||
completion(true,"Connected to internet Wifi")
|
// completion(true,"Connected to internet Wifi")
|
||||||
else
|
// else
|
||||||
completion(false,"errorConnectingHmgNetwork")
|
// completion(false,"errorConnectingHmgNetwork")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
} else {
|
// } else {
|
||||||
Log.v(TAG, "WifiWizard: cannot connect to network")
|
// Log.v(TAG, "WifiWizard: cannot connect to network")
|
||||||
completion(false,"errorConnectingHmgNetwork")
|
// completion(false,"errorConnectingHmgNetwork")
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* This method takes a given String, searches the current list of configured WiFi
|
// * This method takes a given String, searches the current list of configured WiFi
|
||||||
* networks, and returns the networkId for the network if the SSID matches. If not,
|
// * networks, and returns the networkId for the network if the SSID matches. If not,
|
||||||
* it returns -1.
|
// * it returns -1.
|
||||||
*/
|
// */
|
||||||
@SuppressLint("MissingPermission")
|
// @SuppressLint("MissingPermission")
|
||||||
private fun ssidToNetworkId(ssid: String, wifiManager: WifiManager): Int {
|
// private fun ssidToNetworkId(ssid: String, wifiManager: WifiManager): Int {
|
||||||
val currentNetworks = wifiManager.configuredNetworks
|
// val currentNetworks = wifiManager.configuredNetworks
|
||||||
var networkId = -1
|
// var networkId = -1
|
||||||
// For each network in the list, compare the SSID with the given one
|
// // For each network in the list, compare the SSID with the given one
|
||||||
for (test in currentNetworks) {
|
// for (test in currentNetworks) {
|
||||||
if (test.SSID == ssid) {
|
// if (test.SSID == ssid) {
|
||||||
networkId = test.networkId
|
// networkId = test.networkId
|
||||||
break
|
// break
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return networkId
|
// return networkId
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@RequiresApi(Build.VERSION_CODES.Q)
|
// @RequiresApi(Build.VERSION_CODES.Q)
|
||||||
fun apiGreaterThen28(){
|
// fun apiGreaterThen28(){
|
||||||
val connectivityManager = mainActivity.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
// val connectivityManager = mainActivity.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
//
|
||||||
Log.e(TAG, "connection wifi with Android Q+")
|
// Log.e(TAG, "connection wifi with Android Q+")
|
||||||
val wifiNetworkSpecifier: WifiNetworkSpecifier = WifiNetworkSpecifier.Builder()
|
// val wifiNetworkSpecifier: WifiNetworkSpecifier = WifiNetworkSpecifier.Builder()
|
||||||
.setSsid(SSID)
|
// .setSsid(SSID)
|
||||||
.setWpa2EnterpriseConfig(enterpriseConfig())
|
// .setWpa2EnterpriseConfig(enterpriseConfig())
|
||||||
.build()
|
// .build()
|
||||||
|
//
|
||||||
val networkRequest: NetworkRequest = NetworkRequest.Builder()
|
// val networkRequest: NetworkRequest = NetworkRequest.Builder()
|
||||||
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
|
// .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
|
||||||
.setNetworkSpecifier(wifiNetworkSpecifier)
|
// .setNetworkSpecifier(wifiNetworkSpecifier)
|
||||||
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) //removeCapability added for hotspots without internet
|
// .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) //removeCapability added for hotspots without internet
|
||||||
.build()
|
// .build()
|
||||||
|
//
|
||||||
val networkCallback = object : ConnectivityManager.NetworkCallback() {
|
// val networkCallback = object : ConnectivityManager.NetworkCallback() {
|
||||||
override fun onAvailable(network: Network) {
|
// override fun onAvailable(network: Network) {
|
||||||
super.onAvailable(network)
|
// super.onAvailable(network)
|
||||||
connectivityManager.bindProcessToNetwork(network)
|
// connectivityManager.bindProcessToNetwork(network)
|
||||||
completion(true, "200")
|
// completion(true, "200")
|
||||||
Log.e(TAG, "onAvailable")
|
// Log.e(TAG, "onAvailable")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override fun onLosing(network: Network, maxMsToLive: Int) {
|
// override fun onLosing(network: Network, maxMsToLive: Int) {
|
||||||
super.onLosing(network, maxMsToLive)
|
// super.onLosing(network, maxMsToLive)
|
||||||
Log.e(TAG, "onLosing")
|
// Log.e(TAG, "onLosing")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override fun onLost(network: Network) {
|
// override fun onLost(network: Network) {
|
||||||
super.onLost(network)
|
// super.onLost(network)
|
||||||
Log.e(TAG, "onLosing")
|
// Log.e(TAG, "onLosing")
|
||||||
Log.e(TAG, "losing active connection")
|
// Log.e(TAG, "losing active connection")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override fun onUnavailable() {
|
// override fun onUnavailable() {
|
||||||
super.onUnavailable()
|
// super.onUnavailable()
|
||||||
completion(false, "401")
|
// completion(false, "401")
|
||||||
Log.e(TAG, "onUnavailable")
|
// Log.e(TAG, "onUnavailable")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//timeout add because "No devices found" wasn't handled correct and doesn't throw Unavailable
|
// //timeout add because "No devices found" wasn't handled correct and doesn't throw Unavailable
|
||||||
connectivityManager.requestNetwork(networkRequest, networkCallback, 30000)
|
// connectivityManager.requestNetwork(networkRequest, networkCallback, 30000)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun enterpriseConfig() : WifiEnterpriseConfig{
|
// fun enterpriseConfig() : WifiEnterpriseConfig{
|
||||||
// Initialize the WifiConfiguration object
|
// // Initialize the WifiConfiguration object
|
||||||
val enterpriseConfig = WifiEnterpriseConfig()
|
// val enterpriseConfig = WifiEnterpriseConfig()
|
||||||
enterpriseConfig.eapMethod = WifiEnterpriseConfig.Eap.PEAP
|
// enterpriseConfig.eapMethod = WifiEnterpriseConfig.Eap.PEAP
|
||||||
enterpriseConfig.identity = identity
|
// enterpriseConfig.identity = identity
|
||||||
enterpriseConfig.password = password
|
// enterpriseConfig.password = password
|
||||||
enterpriseConfig.phase2Method = WifiEnterpriseConfig.Phase2.NONE
|
// enterpriseConfig.phase2Method = WifiEnterpriseConfig.Phase2.NONE
|
||||||
// enterpriseConfig.caCertificates = WifiEnterpriseConfig.Phase2.
|
//// enterpriseConfig.caCertificates = WifiEnterpriseConfig.Phase2.
|
||||||
return enterpriseConfig;
|
// return enterpriseConfig;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
@ -1,36 +1,36 @@
|
|||||||
package com.ejada.hmg.utils
|
//package com.ejada.hmg.utils
|
||||||
|
//
|
||||||
import io.flutter.plugin.common.MethodChannel
|
//import io.flutter.plugin.common.MethodChannel
|
||||||
import io.flutter.plugin.common.MethodChannel.Result
|
//import io.flutter.plugin.common.MethodChannel.Result
|
||||||
|
//
|
||||||
class FlutterText{
|
//class FlutterText{
|
||||||
|
//
|
||||||
companion object{
|
// companion object{
|
||||||
fun with(key:String, completion:(String)->Unit){
|
// fun with(key:String, completion:(String)->Unit){
|
||||||
HMGUtils.getPlatformChannel().invokeMethod("localizedValue",key, object:MethodChannel.Result{
|
// HMGUtils.getPlatformChannel().invokeMethod("localizedValue",key, object:MethodChannel.Result{
|
||||||
override fun success(result: Any?) {
|
// override fun success(result: Any?) {
|
||||||
val localized = result as String?
|
// val localized = result as String?
|
||||||
if (localized != null){
|
// if (localized != null){
|
||||||
completion(localized)
|
// completion(localized)
|
||||||
}else{
|
// }else{
|
||||||
completion(key)
|
// completion(key)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
|
// override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
|
||||||
completion(key)
|
// completion(key)
|
||||||
require(false){
|
// require(false){
|
||||||
"'localizedValue' $errorMessage"
|
// "'localizedValue' $errorMessage"
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override fun notImplemented() {
|
// override fun notImplemented() {
|
||||||
require(false){
|
// require(false){
|
||||||
"'localizedValue' method not implemented at flutter"
|
// "'localizedValue' method not implemented at flutter"
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
@ -1,223 +1,224 @@
|
|||||||
package com.ejada.hmg.utils
|
//package com.ejada.hmg.utils
|
||||||
|
//
|
||||||
import android.app.NotificationChannel
|
//import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
//import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
//import android.app.PendingIntent
|
||||||
import android.app.job.JobInfo
|
//import android.app.job.JobInfo
|
||||||
import android.app.job.JobScheduler
|
//import android.app.job.JobScheduler
|
||||||
import android.content.ComponentName
|
//import android.content.ComponentName
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.content.Intent
|
//import android.content.Intent
|
||||||
import android.os.Build
|
//import android.os.Build
|
||||||
import android.widget.Toast
|
//import android.widget.Toast
|
||||||
import androidx.annotation.Nullable
|
//import androidx.annotation.Nullable
|
||||||
import androidx.core.app.NotificationCompat
|
//import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.TaskStackBuilder
|
//import androidx.core.app.TaskStackBuilder
|
||||||
import com.ejada.hmg.BuildConfig
|
////import com.ejada.hmg.BuildConfig
|
||||||
import com.ejada.hmg.MainActivity
|
//import sa.edu.kku.kkuMcApp.BuildConfig
|
||||||
import com.ejada.hmg.R
|
//import com.ejada.hmg.MainActivity
|
||||||
import com.ejada.hmg.geofence.GeoZoneModel
|
//import sa.edu.kku.kkuMcApp.R
|
||||||
import com.github.kittinunf.fuel.core.extensions.jsonBody
|
//import com.ejada.hmg.geofence.GeoZoneModel
|
||||||
import com.github.kittinunf.fuel.httpPost
|
//import com.github.kittinunf.fuel.core.extensions.jsonBody
|
||||||
import com.google.gson.Gson
|
//import com.github.kittinunf.fuel.httpPost
|
||||||
import com.google.gson.reflect.TypeToken
|
//import com.google.gson.Gson
|
||||||
import io.flutter.plugin.common.MethodChannel
|
//import com.google.gson.reflect.TypeToken
|
||||||
import org.json.JSONArray
|
//import io.flutter.plugin.common.MethodChannel
|
||||||
import org.json.JSONException
|
//import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
//import org.json.JSONException
|
||||||
import java.text.SimpleDateFormat
|
//import org.json.JSONObject
|
||||||
import java.util.*
|
//import java.text.SimpleDateFormat
|
||||||
import kotlin.concurrent.timerTask
|
//import java.util.*
|
||||||
|
//import kotlin.concurrent.timerTask
|
||||||
|
//
|
||||||
class HMGUtils {
|
//
|
||||||
|
//class HMGUtils {
|
||||||
companion object{
|
//
|
||||||
private lateinit var platformChannel: MethodChannel
|
// companion object{
|
||||||
fun getPlatformChannel():MethodChannel{
|
// private lateinit var platformChannel: MethodChannel
|
||||||
return platformChannel
|
// fun getPlatformChannel():MethodChannel{
|
||||||
}
|
// return platformChannel
|
||||||
fun setPlatformChannel(channel: MethodChannel){
|
// }
|
||||||
platformChannel = channel
|
// fun setPlatformChannel(channel: MethodChannel){
|
||||||
}
|
// platformChannel = channel
|
||||||
|
// }
|
||||||
fun timer(delay: Long, repeat: Boolean, tick: (Timer) -> Unit) : Timer{
|
//
|
||||||
val timer = Timer()
|
// fun timer(delay: Long, repeat: Boolean, tick: (Timer) -> Unit) : Timer{
|
||||||
if(repeat)
|
// val timer = Timer()
|
||||||
timer.schedule(timerTask {
|
// if(repeat)
|
||||||
tick(timer)
|
// timer.schedule(timerTask {
|
||||||
}, delay, delay)
|
// tick(timer)
|
||||||
else
|
// }, delay, delay)
|
||||||
timer.schedule(timerTask {
|
// else
|
||||||
tick(timer)
|
// timer.schedule(timerTask {
|
||||||
}, delay)
|
// tick(timer)
|
||||||
|
// }, delay)
|
||||||
return timer
|
//
|
||||||
}
|
// return timer
|
||||||
|
// }
|
||||||
fun popMessage(context: MainActivity, message: String){
|
//
|
||||||
context.runOnUiThread {
|
// fun popMessage(context: MainActivity, message: String){
|
||||||
Toast.makeText(context, message, Toast.LENGTH_LONG).show()
|
// context.runOnUiThread {
|
||||||
}
|
// Toast.makeText(context, message, Toast.LENGTH_LONG).show()
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
fun popFlutterText(context: MainActivity, key: String){
|
//
|
||||||
context.runOnUiThread {
|
// fun popFlutterText(context: MainActivity, key: String){
|
||||||
FlutterText.with(key){
|
// context.runOnUiThread {
|
||||||
Toast.makeText(context, it, Toast.LENGTH_LONG).show()
|
// FlutterText.with(key){
|
||||||
}
|
// Toast.makeText(context, it, Toast.LENGTH_LONG).show()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
fun getLanguageCode(context: Context) : Int {
|
//
|
||||||
val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
// fun getLanguageCode(context: Context) : Int {
|
||||||
val lang = pref.getString(PREF_KEY_LANGUAGE, "ar")
|
// val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
||||||
return if (lang == "ar") 2 else 1
|
// val lang = pref.getString(PREF_KEY_LANGUAGE, "ar")
|
||||||
}
|
// return if (lang == "ar") 2 else 1
|
||||||
|
// }
|
||||||
fun defaultHTTPParams(context: Context) : Map<String, Any?>{
|
//
|
||||||
return mapOf(
|
// fun defaultHTTPParams(context: Context) : Map<String, Any?>{
|
||||||
"ZipCode" to "966",
|
// return mapOf(
|
||||||
"VersionID" to 5.8,
|
// "ZipCode" to "966",
|
||||||
"Channel" to 3,
|
// "VersionID" to 5.8,
|
||||||
"LanguageID" to getLanguageCode(context),
|
// "Channel" to 3,
|
||||||
"IPAdress" to "10.20.10.20",
|
// "LanguageID" to getLanguageCode(context),
|
||||||
"generalid" to "Cs2020@2016$2958",
|
// "IPAdress" to "10.20.10.20",
|
||||||
"PatientOutSA" to 0,
|
// "generalid" to "Cs2020@2016$2958",
|
||||||
"SessionID" to null,
|
// "PatientOutSA" to 0,
|
||||||
"isDentalAllowedBackend" to false,
|
// "SessionID" to null,
|
||||||
"DeviceTypeID" to 2)
|
// "isDentalAllowedBackend" to false,
|
||||||
}
|
// "DeviceTypeID" to 2)
|
||||||
|
// }
|
||||||
|
//
|
||||||
fun <T>scheduleJob(context: Context, pendingIntentClassType:Class<T>, jobId:Int, intervalDuration:String, deadlineMillis:Long = (30 * 1000)) { // default deadline: 30 Seconds
|
//
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
// fun <T>scheduleJob(context: Context, pendingIntentClassType:Class<T>, jobId:Int, intervalDuration:String, deadlineMillis:Long = (30 * 1000)) { // default deadline: 30 Seconds
|
||||||
val jobScheduler: JobScheduler = context.getSystemService(JobScheduler::class.java)
|
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||||
|
// val jobScheduler: JobScheduler = context.getSystemService(JobScheduler::class.java)
|
||||||
val serviceComponent = ComponentName(context, pendingIntentClassType)
|
//
|
||||||
val builder = JobInfo.Builder(jobId, serviceComponent)
|
// val serviceComponent = ComponentName(context, pendingIntentClassType)
|
||||||
builder.setPersisted(true)
|
// val builder = JobInfo.Builder(jobId, serviceComponent)
|
||||||
builder.setBackoffCriteria(30000, JobInfo.BACKOFF_POLICY_LINEAR)
|
// builder.setPersisted(true)
|
||||||
|
// builder.setBackoffCriteria(30000, JobInfo.BACKOFF_POLICY_LINEAR)
|
||||||
val intervalMillis = timeToMillis(intervalDuration,"HH:mm:ss")
|
//
|
||||||
builder.setMinimumLatency(intervalMillis) // wait at least
|
// val intervalMillis = timeToMillis(intervalDuration,"HH:mm:ss")
|
||||||
builder.setOverrideDeadline((intervalMillis + deadlineMillis)) // maximum delay
|
// builder.setMinimumLatency(intervalMillis) // wait at least
|
||||||
if (jobScheduler.schedule(builder.build()) == JobScheduler.RESULT_SUCCESS){
|
// builder.setOverrideDeadline((intervalMillis + deadlineMillis)) // maximum delay
|
||||||
Logs.save(context,"ScheduleJob", "${pendingIntentClassType.simpleName}: Job scheduled to trigger after duration $intervalDuration >> HH:mm:ss --('MinimumLatency:$intervalMillis Deadline:${(intervalMillis + deadlineMillis)}')--",Logs.STATUS.SUCCESS)
|
// if (jobScheduler.schedule(builder.build()) == JobScheduler.RESULT_SUCCESS){
|
||||||
}else{
|
// Logs.save(context,"ScheduleJob", "${pendingIntentClassType.simpleName}: Job scheduled to trigger after duration $intervalDuration >> HH:mm:ss --('MinimumLatency:$intervalMillis Deadline:${(intervalMillis + deadlineMillis)}')--",Logs.STATUS.SUCCESS)
|
||||||
Logs.save(context,"ScheduleJob", "${pendingIntentClassType.simpleName}: Failed to scheduled Job",Logs.STATUS.ERROR)
|
// }else{
|
||||||
}
|
// Logs.save(context,"ScheduleJob", "${pendingIntentClassType.simpleName}: Failed to scheduled Job",Logs.STATUS.ERROR)
|
||||||
|
// }
|
||||||
} else {
|
//
|
||||||
Logs.save(context,"ScheduleJob", "${pendingIntentClassType.simpleName}: Failed to scheduled Job on VERSION.SDK_INT < ${android.os.Build.VERSION_CODES.M}",Logs.STATUS.ERROR)
|
// } else {
|
||||||
}
|
// Logs.save(context,"ScheduleJob", "${pendingIntentClassType.simpleName}: Failed to scheduled Job on VERSION.SDK_INT < ${android.os.Build.VERSION_CODES.M}",Logs.STATUS.ERROR)
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
}
|
//
|
||||||
|
//}
|
||||||
|
//
|
||||||
private const val NOTIFICATION_CHANNEL_ID = BuildConfig.APPLICATION_ID + ".channel"
|
//
|
||||||
|
//private const val NOTIFICATION_CHANNEL_ID = BuildConfig.APPLICATION_ID + ".channel"
|
||||||
|
//
|
||||||
fun timeToMillis(time:String, format:String):Long{
|
//
|
||||||
val sdf = SimpleDateFormat(format, Locale.US)
|
//fun timeToMillis(time:String, format:String):Long{
|
||||||
val millis = sdf.parse(time).time + TimeZone.getDefault().rawOffset
|
// val sdf = SimpleDateFormat(format, Locale.US)
|
||||||
return millis
|
// val millis = sdf.parse(time).time + TimeZone.getDefault().rawOffset
|
||||||
}
|
// return millis
|
||||||
|
//}
|
||||||
fun sendNotification(context: Context, title: String, @Nullable subtitle: String?, message: String?) {
|
//
|
||||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
//fun sendNotification(context: Context, title: String, @Nullable subtitle: String?, message: String?) {
|
||||||
|
// val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
//
|
||||||
&& notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID) == null) {
|
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||||
val name = context.getString(R.string.app_name)
|
// && notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID) == null) {
|
||||||
val channel = NotificationChannel(NOTIFICATION_CHANNEL_ID,
|
// val name = context.getString(R.string.app_name)
|
||||||
name,
|
// val channel = NotificationChannel(NOTIFICATION_CHANNEL_ID,
|
||||||
NotificationManager.IMPORTANCE_DEFAULT)
|
// name,
|
||||||
|
// NotificationManager.IMPORTANCE_DEFAULT)
|
||||||
notificationManager.createNotificationChannel(channel)
|
//
|
||||||
}
|
// notificationManager.createNotificationChannel(channel)
|
||||||
|
// }
|
||||||
val intent = Intent(context, MainActivity::class.java)
|
//
|
||||||
|
// val intent = Intent(context, MainActivity::class.java)
|
||||||
val stackBuilder = TaskStackBuilder.create(context)
|
//
|
||||||
.addParentStack(MainActivity::class.java)
|
// val stackBuilder = TaskStackBuilder.create(context)
|
||||||
.addNextIntent(intent)
|
// .addParentStack(MainActivity::class.java)
|
||||||
val notificationPendingIntent = stackBuilder.getPendingIntent(getUniqueId(), PendingIntent.FLAG_UPDATE_CURRENT)
|
// .addNextIntent(intent)
|
||||||
|
// val notificationPendingIntent = stackBuilder.getPendingIntent(getUniqueId(), PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
val notification = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
|
//
|
||||||
.setSmallIcon(R.mipmap.ic_launcher)
|
// val notification = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
|
||||||
.setContentIntent(notificationPendingIntent)
|
// .setSmallIcon(R.mipmap.ic_launcher)
|
||||||
.setAutoCancel(true)
|
// .setContentIntent(notificationPendingIntent)
|
||||||
.setContentTitle(title)
|
// .setAutoCancel(true)
|
||||||
|
// .setContentTitle(title)
|
||||||
subtitle.let { notification.setContentText(it) }
|
//
|
||||||
message.let { notification.setSubText(it) }
|
// subtitle.let { notification.setContentText(it) }
|
||||||
|
// message.let { notification.setSubText(it) }
|
||||||
notificationManager.notify(getUniqueId(), notification.build())
|
//
|
||||||
}
|
// notificationManager.notify(getUniqueId(), notification.build())
|
||||||
|
//}
|
||||||
//-------------------------
|
//
|
||||||
// Open Helper Methods
|
////-------------------------
|
||||||
//-------------------------
|
//// Open Helper Methods
|
||||||
fun getUniqueId() = ((System.currentTimeMillis() % 10000).toInt())
|
////-------------------------
|
||||||
|
//fun getUniqueId() = ((System.currentTimeMillis() % 10000).toInt())
|
||||||
object DateUtils {
|
//
|
||||||
@JvmStatic
|
//object DateUtils {
|
||||||
fun dateTimeNow() : String {
|
// @JvmStatic
|
||||||
val format = SimpleDateFormat("dd-MMM-yyy hh:mm:ss")
|
// fun dateTimeNow() : String {
|
||||||
return format.format(Date())
|
// val format = SimpleDateFormat("dd-MMM-yyy hh:mm:ss")
|
||||||
}
|
// return format.format(Date())
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
fun isJSONValid(jsonString: String?): Boolean {
|
//
|
||||||
try { JSONObject(jsonString) } catch (ex: JSONException) {
|
//fun isJSONValid(jsonString: String?): Boolean {
|
||||||
try { JSONArray(jsonString) } catch (ex1: JSONException) {
|
// try { JSONObject(jsonString) } catch (ex: JSONException) {
|
||||||
return false
|
// try { JSONArray(jsonString) } catch (ex1: JSONException) {
|
||||||
}
|
// return false
|
||||||
}
|
// }
|
||||||
return true
|
// }
|
||||||
}
|
// return true
|
||||||
|
//}
|
||||||
fun saveLog(context: Context, tag: String, message: String){
|
//
|
||||||
val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
//fun saveLog(context: Context, tag: String, message: String){
|
||||||
var logs = pref.getString("LOGS", "")
|
// val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
||||||
logs += "$tag -> $message \n"
|
// var logs = pref.getString("LOGS", "")
|
||||||
pref.edit().putString("LOGS", logs).apply();
|
// logs += "$tag -> $message \n"
|
||||||
}
|
// pref.edit().putString("LOGS", logs).apply();
|
||||||
|
//}
|
||||||
fun getLogs(context: Context) : String?{
|
//
|
||||||
val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
//fun getLogs(context: Context) : String?{
|
||||||
return pref.getString("LOGS", "")
|
// val pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
||||||
}
|
// return pref.getString("LOGS", "")
|
||||||
|
//}
|
||||||
class HTTPResponse<T>(data: T){
|
//
|
||||||
final var data:T = data
|
//class HTTPResponse<T>(data: T){
|
||||||
}
|
// final var data:T = data
|
||||||
|
//}
|
||||||
fun <T>httpPost(url: String, body: Map<String, Any?>, onSuccess: (response: HTTPResponse<T>) -> Unit, onError: (error: Exception) -> Unit){
|
//
|
||||||
val gson = Gson()
|
//fun <T>httpPost(url: String, body: Map<String, Any?>, onSuccess: (response: HTTPResponse<T>) -> Unit, onError: (error: Exception) -> Unit){
|
||||||
val type = object : TypeToken<T>() {}.type
|
// val gson = Gson()
|
||||||
val jsonBody = gson.toJson(body)
|
// val type = object : TypeToken<T>() {}.type
|
||||||
url.httpPost()
|
// val jsonBody = gson.toJson(body)
|
||||||
.jsonBody(jsonBody, Charsets.UTF_8)
|
// url.httpPost()
|
||||||
.timeout(10000)
|
// .jsonBody(jsonBody, Charsets.UTF_8)
|
||||||
.header("Content-Type", "application/json")
|
// .timeout(10000)
|
||||||
.header("Allow", "*/*")
|
// .header("Content-Type", "application/json")
|
||||||
.response { request, response, result ->
|
// .header("Allow", "*/*")
|
||||||
result.fold({ data ->
|
// .response { request, response, result ->
|
||||||
val dataString = String(data)
|
// result.fold({ data ->
|
||||||
if (isJSONValid(dataString)) {
|
// val dataString = String(data)
|
||||||
val responseData = gson.fromJson<T>(dataString, type)
|
// if (isJSONValid(dataString)) {
|
||||||
onSuccess(HTTPResponse(responseData))
|
// val responseData = gson.fromJson<T>(dataString, type)
|
||||||
} else {
|
// onSuccess(HTTPResponse(responseData))
|
||||||
onError(Exception("Invalid response from server (Not a valid JSON)"))
|
// } else {
|
||||||
}
|
// onError(Exception("Invalid response from server (Not a valid JSON)"))
|
||||||
}, {
|
// }
|
||||||
onError(it)
|
// }, {
|
||||||
})
|
// onError(it)
|
||||||
|
// })
|
||||||
}
|
//
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
@ -1,145 +1,146 @@
|
|||||||
package com.ejada.hmg.utils
|
//package com.ejada.hmg.utils
|
||||||
|
//
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.content.SharedPreferences
|
//import android.content.SharedPreferences
|
||||||
import android.os.Build
|
//import android.os.Build
|
||||||
import com.ejada.hmg.BuildConfig
|
////import com.ejada.hmg.BuildConfig
|
||||||
import com.google.gson.Gson
|
//import sa.edu.kku.kkuMcApp.BuildConfig
|
||||||
|
//import com.google.gson.Gson
|
||||||
class Logs {
|
//
|
||||||
|
//class Logs {
|
||||||
enum class STATUS{
|
//
|
||||||
SUCCESS,
|
// enum class STATUS{
|
||||||
ERROR;
|
// SUCCESS,
|
||||||
}
|
// ERROR;
|
||||||
class GeofenceEvent{
|
// }
|
||||||
companion object{
|
// class GeofenceEvent{
|
||||||
fun save(context: Context, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
// companion object{
|
||||||
Logs.Common.save(context,"GeofenceEvent", tag, message, status)
|
// fun save(context: Context, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
||||||
}
|
// Logs.Common.save(context,"GeofenceEvent", tag, message, status)
|
||||||
|
// }
|
||||||
fun list(context: Context, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
//
|
||||||
return Logs.Common.list(context,"GeofenceEvent", tag, status)
|
// fun list(context: Context, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
||||||
}
|
// return Logs.Common.list(context,"GeofenceEvent", tag, status)
|
||||||
|
// }
|
||||||
fun raw(context: Context):String{
|
//
|
||||||
return Logs.Common.raw(context,"GeofenceEvent")
|
// fun raw(context: Context):String{
|
||||||
}
|
// return Logs.Common.raw(context,"GeofenceEvent")
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
class RegisterGeofence{
|
//
|
||||||
companion object{
|
// class RegisterGeofence{
|
||||||
fun save(context: Context, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
// companion object{
|
||||||
Logs.Common.save(context,"RegisterGeofence", tag, message, status)
|
// fun save(context: Context, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
||||||
}
|
// Logs.Common.save(context,"RegisterGeofence", tag, message, status)
|
||||||
|
// }
|
||||||
fun list(context: Context, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
//
|
||||||
return Logs.Common.list(context,"RegisterGeofence", tag, status)
|
// fun list(context: Context, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
||||||
}
|
// return Logs.Common.list(context,"RegisterGeofence", tag, status)
|
||||||
|
// }
|
||||||
fun raw(context: Context):String{
|
//
|
||||||
return Logs.Common.raw(context,"RegisterGeofence");
|
// fun raw(context: Context):String{
|
||||||
}
|
// return Logs.Common.raw(context,"RegisterGeofence");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
companion object{
|
//
|
||||||
private var pref:SharedPreferences? = null
|
// companion object{
|
||||||
fun save(context: Context, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
// private var pref:SharedPreferences? = null
|
||||||
Logs.Common.save(context,"Logs", tag, message, status)
|
// fun save(context: Context, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
||||||
}
|
// Logs.Common.save(context,"Logs", tag, message, status)
|
||||||
|
// }
|
||||||
fun list(context: Context, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
//
|
||||||
return Logs.Common.list(context,"Logs", tag, status)
|
// fun list(context: Context, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
||||||
}
|
// return Logs.Common.list(context,"Logs", tag, status)
|
||||||
|
// }
|
||||||
fun raw(context: Context):String{
|
//
|
||||||
return Logs.Common.raw(context,"Logs");
|
// fun raw(context: Context):String{
|
||||||
}
|
// return Logs.Common.raw(context,"Logs");
|
||||||
|
// }
|
||||||
private fun storage(context: Context):SharedPreferences{
|
//
|
||||||
if(pref == null) {
|
// private fun storage(context: Context):SharedPreferences{
|
||||||
pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
// if(pref == null) {
|
||||||
}
|
// pref = context.getSharedPreferences(PREFS_STORAGE, Context.MODE_PRIVATE)
|
||||||
return pref!!
|
// }
|
||||||
}
|
// return pref!!
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
private class Common{
|
//
|
||||||
companion object{
|
// private class Common{
|
||||||
private val gson = Gson()
|
// companion object{
|
||||||
|
// private val gson = Gson()
|
||||||
fun save(context: Context, key:String, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
//
|
||||||
if(!BuildConfig.DEBUG)
|
// fun save(context: Context, key:String, tag:String, message:String, status:Logs.STATUS = STATUS.SUCCESS){
|
||||||
return
|
// if(!BuildConfig.DEBUG)
|
||||||
|
// return
|
||||||
val pref = Logs.storage(context)
|
//
|
||||||
|
// val pref = Logs.storage(context)
|
||||||
val string = pref.getString(key,"{}")
|
//
|
||||||
val json = gson.fromJson<LogsContainerModel>(string,LogsContainerModel::class.java)
|
// val string = pref.getString(key,"{}")
|
||||||
json.add(
|
// val json = gson.fromJson<LogsContainerModel>(string,LogsContainerModel::class.java)
|
||||||
LogModel().apply {
|
// json.add(
|
||||||
this.TAG = tag
|
// LogModel().apply {
|
||||||
this.MESSAGE = message
|
// this.TAG = tag
|
||||||
this.STATUS = status.name
|
// this.MESSAGE = message
|
||||||
this.DATE = DateUtils.dateTimeNow()
|
// this.STATUS = status.name
|
||||||
}
|
// this.DATE = DateUtils.dateTimeNow()
|
||||||
)
|
// }
|
||||||
|
// )
|
||||||
pref.edit().putString(key,gson.toJson(json)).apply()
|
//
|
||||||
}
|
// pref.edit().putString(key,gson.toJson(json)).apply()
|
||||||
|
// }
|
||||||
fun list(context: Context, key:String, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
//
|
||||||
val pref = Logs.storage(context)
|
// fun list(context: Context, key:String, tag:String? = null, status:Logs.STATUS? = null):List<LogModel>{
|
||||||
val string = pref.getString(key,"{}")
|
// val pref = Logs.storage(context)
|
||||||
val json = gson.fromJson<LogsContainerModel>(string,LogsContainerModel::class.java)
|
// val string = pref.getString(key,"{}")
|
||||||
if(tag == null && status == null) {
|
// val json = gson.fromJson<LogsContainerModel>(string,LogsContainerModel::class.java)
|
||||||
return json.LOGS
|
// if(tag == null && status == null) {
|
||||||
}else if(tag != null && status != null){
|
// return json.LOGS
|
||||||
return json.LOGS.filter { (it.TAG == tag && it.STATUS == status.name) }
|
// }else if(tag != null && status != null){
|
||||||
}else if(tag != null){
|
// return json.LOGS.filter { (it.TAG == tag && it.STATUS == status.name) }
|
||||||
return json.LOGS.filter { (it.TAG == tag) }
|
// }else if(tag != null){
|
||||||
}else if(status != null){
|
// return json.LOGS.filter { (it.TAG == tag) }
|
||||||
return json.LOGS.filter { (it.STATUS == status.name) }
|
// }else if(status != null){
|
||||||
}
|
// return json.LOGS.filter { (it.STATUS == status.name) }
|
||||||
return listOf()
|
// }
|
||||||
}
|
// return listOf()
|
||||||
|
// }
|
||||||
fun raw(context: Context, key:String):String{
|
//
|
||||||
val pref = Logs.storage(context)
|
// fun raw(context: Context, key:String):String{
|
||||||
val string = pref.getString(key,"{}")
|
// val pref = Logs.storage(context)
|
||||||
return string!!
|
// val string = pref.getString(key,"{}")
|
||||||
}
|
// return string!!
|
||||||
|
// }
|
||||||
}
|
//
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
class LogModel{
|
//
|
||||||
lateinit var TAG:String
|
// class LogModel{
|
||||||
lateinit var MESSAGE:String
|
// lateinit var TAG:String
|
||||||
lateinit var STATUS:String
|
// lateinit var MESSAGE:String
|
||||||
lateinit var DATE:String
|
// lateinit var STATUS:String
|
||||||
|
// lateinit var DATE:String
|
||||||
companion object{
|
//
|
||||||
fun with(tag:String, message:String, status:String):LogModel{
|
// companion object{
|
||||||
return LogModel().apply {
|
// fun with(tag:String, message:String, status:String):LogModel{
|
||||||
this.TAG = tag
|
// return LogModel().apply {
|
||||||
this.MESSAGE = message
|
// this.TAG = tag
|
||||||
this.STATUS = status
|
// this.MESSAGE = message
|
||||||
this.DATE = DateUtils.dateTimeNow()
|
// this.STATUS = status
|
||||||
}
|
// this.DATE = DateUtils.dateTimeNow()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
class LogsContainerModel{
|
//
|
||||||
var LOGS = mutableListOf<LogModel>()
|
// class LogsContainerModel{
|
||||||
fun add(log:LogModel){
|
// var LOGS = mutableListOf<LogModel>()
|
||||||
LOGS.add(log)
|
// fun add(log:LogModel){
|
||||||
}
|
// LOGS.add(log)
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
}
|
//
|
||||||
|
//}
|
||||||
@ -1,45 +1,45 @@
|
|||||||
package com.ejada.hmg.utils
|
//package com.ejada.hmg.utils
|
||||||
|
//
|
||||||
import com.ejada.hmg.MainActivity
|
//import com.ejada.hmg.MainActivity
|
||||||
import com.ejada.hmg.opentok.OpenTok
|
//import com.ejada.hmg.opentok.OpenTok
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
//import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.plugin.common.MethodCall
|
//import io.flutter.plugin.common.MethodCall
|
||||||
import io.flutter.plugin.common.MethodChannel
|
//import io.flutter.plugin.common.MethodChannel
|
||||||
|
//
|
||||||
class OpenTokPlatformBridge(private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity) {
|
//class OpenTokPlatformBridge(private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity) {
|
||||||
|
//
|
||||||
private lateinit var channel: MethodChannel
|
// private lateinit var channel: MethodChannel
|
||||||
private lateinit var openTok: OpenTok
|
// private lateinit var openTok: OpenTok
|
||||||
|
//
|
||||||
companion object {
|
// companion object {
|
||||||
private const val CHANNEL = "OpenTok-Platform-Bridge"
|
// private const val CHANNEL = "OpenTok-Platform-Bridge"
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun create(){
|
// fun create(){
|
||||||
openTok = OpenTok(mainActivity, flutterEngine)
|
// openTok = OpenTok(mainActivity, flutterEngine)
|
||||||
channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
|
// channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
|
||||||
channel.setMethodCallHandler { call: MethodCall, result: MethodChannel.Result ->
|
// channel.setMethodCallHandler { call: MethodCall, result: MethodChannel.Result ->
|
||||||
when (call.method) {
|
// when (call.method) {
|
||||||
"initSession" -> {
|
// "initSession" -> {
|
||||||
openTok.initSession(call, result)
|
// openTok.initSession(call, result)
|
||||||
}
|
// }
|
||||||
"swapCamera" -> {
|
// "swapCamera" -> {
|
||||||
openTok.swapCamera(call, result)
|
// openTok.swapCamera(call, result)
|
||||||
}
|
// }
|
||||||
"toggleAudio" -> {
|
// "toggleAudio" -> {
|
||||||
openTok.toggleAudio(call, result)
|
// openTok.toggleAudio(call, result)
|
||||||
}
|
// }
|
||||||
"toggleVideo" -> {
|
// "toggleVideo" -> {
|
||||||
openTok.toggleVideo(call, result)
|
// openTok.toggleVideo(call, result)
|
||||||
}
|
// }
|
||||||
"hangupCall" -> {
|
// "hangupCall" -> {
|
||||||
openTok.hangupCall(call, result)
|
// openTok.hangupCall(call, result)
|
||||||
}
|
// }
|
||||||
else -> {
|
// else -> {
|
||||||
result.notImplemented()
|
// result.notImplemented()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,199 +1,199 @@
|
|||||||
package com.ejada.hmg.utils
|
//package com.ejada.hmg.utils
|
||||||
|
//
|
||||||
import android.content.Context
|
//import android.content.Context
|
||||||
import android.content.Intent
|
//import android.content.Intent
|
||||||
import android.content.Intent.getIntent
|
//import android.content.Intent.getIntent
|
||||||
import android.net.Uri
|
//import android.net.Uri
|
||||||
import android.os.Build
|
//import android.os.Build
|
||||||
import android.os.Bundle
|
//import android.os.Bundle
|
||||||
import android.provider.Settings
|
//import android.provider.Settings
|
||||||
import android.widget.Toast
|
//import android.widget.Toast
|
||||||
import androidx.core.app.ActivityCompat.startActivityForResult
|
//import androidx.core.app.ActivityCompat.startActivityForResult
|
||||||
import android.net.wifi.WifiManager
|
//import android.net.wifi.WifiManager
|
||||||
import android.util.Log
|
//import android.util.Log
|
||||||
import com.ejada.hmg.MainActivity
|
//import com.ejada.hmg.MainActivity
|
||||||
import com.ejada.hmg.hmgwifi.HMG_Guest
|
//import com.ejada.hmg.hmgwifi.HMG_Guest
|
||||||
import com.ejada.hmg.geofence.GeoZoneModel
|
//import com.ejada.hmg.geofence.GeoZoneModel
|
||||||
import com.ejada.hmg.geofence.HMG_Geofence
|
//import com.ejada.hmg.geofence.HMG_Geofence
|
||||||
import com.ejada.hmg.hmgwifi.WpaEnterprise
|
//import com.ejada.hmg.hmgwifi.WpaEnterprise
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
//import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.plugin.common.MethodCall
|
//import io.flutter.plugin.common.MethodCall
|
||||||
import io.flutter.plugin.common.MethodChannel
|
//import io.flutter.plugin.common.MethodChannel
|
||||||
|
//
|
||||||
class PlatformBridge(private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity) {
|
//class PlatformBridge(private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity) {
|
||||||
|
//
|
||||||
private lateinit var channel: MethodChannel
|
// private lateinit var channel: MethodChannel
|
||||||
|
//
|
||||||
companion object {
|
// companion object {
|
||||||
private const val CHANNEL = "HMG-Platform-Bridge"
|
// private const val CHANNEL = "HMG-Platform-Bridge"
|
||||||
private const val HMG_INTERNET_WIFI_CONNECT_METHOD = "connectHMGInternetWifi"
|
// private const val HMG_INTERNET_WIFI_CONNECT_METHOD = "connectHMGInternetWifi"
|
||||||
private const val HMG_GUEST_WIFI_CONNECT_METHOD = "connectHMGGuestWifi"
|
// private const val HMG_GUEST_WIFI_CONNECT_METHOD = "connectHMGGuestWifi"
|
||||||
private const val ENABLE_WIFI_IF_NOT = "enableWifiIfNot"
|
// private const val ENABLE_WIFI_IF_NOT = "enableWifiIfNot"
|
||||||
private const val REGISTER_HMG_GEOFENCES = "registerHmgGeofences"
|
// private const val REGISTER_HMG_GEOFENCES = "registerHmgGeofences"
|
||||||
private const val UN_REGISTER_HMG_GEOFENCES = "unRegisterHmgGeofences"
|
// private const val UN_REGISTER_HMG_GEOFENCES = "unRegisterHmgGeofences"
|
||||||
private const val IS_DRAW_OVER_APPS_PERMISSION_ALLOWED = "isDrawOverAppsPermissionAllowed"
|
// private const val IS_DRAW_OVER_APPS_PERMISSION_ALLOWED = "isDrawOverAppsPermissionAllowed"
|
||||||
private const val ASK_DRAW_OVER_APPS_PERMISSION = "askDrawOverAppsPermission"
|
// private const val ASK_DRAW_OVER_APPS_PERMISSION = "askDrawOverAppsPermission"
|
||||||
private const val GET_INTENT = "getIntent"
|
// private const val GET_INTENT = "getIntent"
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fun create() {
|
// fun create() {
|
||||||
channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
|
// channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
|
||||||
HMGUtils.setPlatformChannel(channel)
|
// HMGUtils.setPlatformChannel(channel)
|
||||||
channel.setMethodCallHandler { methodCall: MethodCall, result: MethodChannel.Result ->
|
// channel.setMethodCallHandler { methodCall: MethodCall, result: MethodChannel.Result ->
|
||||||
|
//
|
||||||
if (methodCall.method == HMG_INTERNET_WIFI_CONNECT_METHOD) {
|
// if (methodCall.method == HMG_INTERNET_WIFI_CONNECT_METHOD) {
|
||||||
connectHMGInternetWifi(methodCall, result)
|
// connectHMGInternetWifi(methodCall, result)
|
||||||
|
//
|
||||||
} else if (methodCall.method == HMG_GUEST_WIFI_CONNECT_METHOD) {
|
// } else if (methodCall.method == HMG_GUEST_WIFI_CONNECT_METHOD) {
|
||||||
connectHMGGuestWifi(methodCall, result)
|
// connectHMGGuestWifi(methodCall, result)
|
||||||
|
|
||||||
} else if (methodCall.method == ENABLE_WIFI_IF_NOT) {
|
|
||||||
enableWifiIfNot(methodCall, result)
|
|
||||||
} else if (methodCall.method == REGISTER_HMG_GEOFENCES) {
|
|
||||||
registerHmgGeofences(methodCall, result)
|
|
||||||
} else if (methodCall.method == UN_REGISTER_HMG_GEOFENCES) {
|
|
||||||
unRegisterHmgGeofences(methodCall, result)
|
|
||||||
} else if (methodCall.method == IS_DRAW_OVER_APPS_PERMISSION_ALLOWED) {
|
|
||||||
isDrawOverAppsPermissionAllowed(methodCall, result)
|
|
||||||
} else if (methodCall.method == ASK_DRAW_OVER_APPS_PERMISSION) {
|
|
||||||
askDrawOverAppsPermission(methodCall, result)
|
|
||||||
} else if (methodCall.method == GET_INTENT) {
|
|
||||||
getIntentData(methodCall, result)
|
|
||||||
} else {
|
|
||||||
result.notImplemented()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
val res = channel.invokeMethod("localizedValue", "errorConnectingHmgNetwork")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun connectHMGInternetWifi(methodCall: MethodCall, result: MethodChannel.Result) {
|
|
||||||
(methodCall.arguments as ArrayList<*>).let {
|
|
||||||
require(it.size == 3 && (it[0] is String) && (it[1] is String), lazyMessage = {
|
|
||||||
"Missing or invalid arguments (Must have three argument of 'String'"
|
|
||||||
})
|
|
||||||
|
|
||||||
val ssid = it[0].toString()
|
|
||||||
val username = it[1].toString()
|
|
||||||
val password = it[2].toString()
|
|
||||||
|
|
||||||
WpaEnterprise(mainActivity,ssid).connect(username,password) { status, message ->
|
|
||||||
HMGUtils.timer(2000,false){
|
|
||||||
mainActivity.runOnUiThread {
|
|
||||||
if(status)
|
|
||||||
result.success(if (status) 1 else 0)
|
|
||||||
else
|
|
||||||
result.error(message, null, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HMG_Internet(mainActivity)
|
|
||||||
// .connectToHMGGuestNetwork(username, password) { status, message ->
|
|
||||||
// mainActivity.runOnUiThread {
|
|
||||||
// result.success(if (status) 1 else 0)
|
|
||||||
//
|
//
|
||||||
// HMGUtils.popFlutterText(mainActivity, message)
|
// } else if (methodCall.method == ENABLE_WIFI_IF_NOT) {
|
||||||
// Log.v(this.javaClass.simpleName, "$status | $message")
|
// enableWifiIfNot(methodCall, result)
|
||||||
// }
|
// } else if (methodCall.method == REGISTER_HMG_GEOFENCES) {
|
||||||
|
// registerHmgGeofences(methodCall, result)
|
||||||
|
// } else if (methodCall.method == UN_REGISTER_HMG_GEOFENCES) {
|
||||||
|
// unRegisterHmgGeofences(methodCall, result)
|
||||||
|
// } else if (methodCall.method == IS_DRAW_OVER_APPS_PERMISSION_ALLOWED) {
|
||||||
|
// isDrawOverAppsPermissionAllowed(methodCall, result)
|
||||||
|
// } else if (methodCall.method == ASK_DRAW_OVER_APPS_PERMISSION) {
|
||||||
|
// askDrawOverAppsPermission(methodCall, result)
|
||||||
|
// } else if (methodCall.method == GET_INTENT) {
|
||||||
|
// getIntentData(methodCall, result)
|
||||||
|
// } else {
|
||||||
|
// result.notImplemented()
|
||||||
|
// }
|
||||||
//
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// val res = channel.invokeMethod("localizedValue", "errorConnectingHmgNetwork")
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private fun connectHMGInternetWifi(methodCall: MethodCall, result: MethodChannel.Result) {
|
||||||
|
// (methodCall.arguments as ArrayList<*>).let {
|
||||||
|
// require(it.size == 3 && (it[0] is String) && (it[1] is String), lazyMessage = {
|
||||||
|
// "Missing or invalid arguments (Must have three argument of 'String'"
|
||||||
|
// })
|
||||||
|
//
|
||||||
|
// val ssid = it[0].toString()
|
||||||
|
// val username = it[1].toString()
|
||||||
|
// val password = it[2].toString()
|
||||||
|
//
|
||||||
|
// WpaEnterprise(mainActivity,ssid).connect(username,password) { status, message ->
|
||||||
|
// HMGUtils.timer(2000,false){
|
||||||
|
// mainActivity.runOnUiThread {
|
||||||
|
// if(status)
|
||||||
|
// result.success(if (status) 1 else 0)
|
||||||
|
// else
|
||||||
|
// result.error(message, null, null)
|
||||||
// }
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//// HMG_Internet(mainActivity)
|
||||||
private fun connectHMGGuestWifi(methodCall: MethodCall, result: MethodChannel.Result) {
|
//// .connectToHMGGuestNetwork(username, password) { status, message ->
|
||||||
(methodCall.arguments as ArrayList<*>).let {
|
//// mainActivity.runOnUiThread {
|
||||||
require(it.size == 1 && (it[0] is String), lazyMessage = {
|
//// result.success(if (status) 1 else 0)
|
||||||
"Missing or invalid arguments (Must have one argument 'String at 0'"
|
////
|
||||||
})
|
//// HMGUtils.popFlutterText(mainActivity, message)
|
||||||
|
//// Log.v(this.javaClass.simpleName, "$status | $message")
|
||||||
val ssid = it[0].toString()
|
//// }
|
||||||
HMG_Guest(mainActivity, ssid).connectToHMGGuestNetwork { status, message ->
|
////
|
||||||
mainActivity.runOnUiThread {
|
//// }
|
||||||
result.success(if (status) 1 else 0)
|
// }
|
||||||
|
// }
|
||||||
HMGUtils.popFlutterText(mainActivity, message)
|
//
|
||||||
Log.v(this.javaClass.simpleName, "$status | $message")
|
//
|
||||||
}
|
// private fun connectHMGGuestWifi(methodCall: MethodCall, result: MethodChannel.Result) {
|
||||||
}
|
// (methodCall.arguments as ArrayList<*>).let {
|
||||||
}
|
// require(it.size == 1 && (it[0] is String), lazyMessage = {
|
||||||
}
|
// "Missing or invalid arguments (Must have one argument 'String at 0'"
|
||||||
|
// })
|
||||||
private fun enableWifiIfNot(methodCall: MethodCall, result: MethodChannel.Result) {
|
//
|
||||||
val wm = mainActivity.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager?
|
// val ssid = it[0].toString()
|
||||||
if (wm != null) {
|
// HMG_Guest(mainActivity, ssid).connectToHMGGuestNetwork { status, message ->
|
||||||
if (!wm.isWifiEnabled)
|
// mainActivity.runOnUiThread {
|
||||||
wm.isWifiEnabled = true
|
// result.success(if (status) 1 else 0)
|
||||||
result.success(true)
|
//
|
||||||
} else
|
// HMGUtils.popFlutterText(mainActivity, message)
|
||||||
result.error("101", "Error while opening wifi, Please try to open wifi yourself and try again", "'WifiManager' service failed");
|
// Log.v(this.javaClass.simpleName, "$status | $message")
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
private fun registerHmgGeofences(methodCall: MethodCall, result: MethodChannel.Result) {
|
// }
|
||||||
|
//
|
||||||
channel.invokeMethod("getGeoZones", null, object : MethodChannel.Result {
|
// private fun enableWifiIfNot(methodCall: MethodCall, result: MethodChannel.Result) {
|
||||||
override fun success(result: Any?) {
|
// val wm = mainActivity.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager?
|
||||||
if (result is String) {
|
// if (wm != null) {
|
||||||
val geoZones = GeoZoneModel().listFrom(result)
|
// if (!wm.isWifiEnabled)
|
||||||
HMG_Geofence.shared(mainActivity).register() { s, e -> }
|
// wm.isWifiEnabled = true
|
||||||
}
|
// result.success(true)
|
||||||
}
|
// } else
|
||||||
|
// result.error("101", "Error while opening wifi, Please try to open wifi yourself and try again", "'WifiManager' service failed");
|
||||||
override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {}
|
// }
|
||||||
override fun notImplemented() {}
|
//
|
||||||
})
|
//
|
||||||
|
// private fun registerHmgGeofences(methodCall: MethodCall, result: MethodChannel.Result) {
|
||||||
}
|
//
|
||||||
|
// channel.invokeMethod("getGeoZones", null, object : MethodChannel.Result {
|
||||||
private fun unRegisterHmgGeofences(methodCall: MethodCall, result: MethodChannel.Result) {
|
// override fun success(result: Any?) {
|
||||||
HMG_Geofence.shared(mainActivity).unRegisterAll { status, exception ->
|
// if (result is String) {
|
||||||
if (status)
|
// val geoZones = GeoZoneModel().listFrom(result)
|
||||||
result.success(true)
|
// HMG_Geofence.shared(mainActivity).register() { s, e -> }
|
||||||
else
|
// }
|
||||||
result.error("101", exception?.localizedMessage, exception);
|
// }
|
||||||
}
|
//
|
||||||
}
|
// override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {}
|
||||||
|
// override fun notImplemented() {}
|
||||||
private fun isDrawOverAppsPermissionAllowed(methodCall: MethodCall, result: MethodChannel.Result) {
|
// })
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
//
|
||||||
if (
|
// }
|
||||||
Settings.canDrawOverlays(mainActivity)
|
//
|
||||||
) {
|
// private fun unRegisterHmgGeofences(methodCall: MethodCall, result: MethodChannel.Result) {
|
||||||
result.success(true)
|
// HMG_Geofence.shared(mainActivity).unRegisterAll { status, exception ->
|
||||||
} else {
|
// if (status)
|
||||||
result.success(false)
|
// result.success(true)
|
||||||
}
|
// else
|
||||||
} else {
|
// result.error("101", exception?.localizedMessage, exception);
|
||||||
result.success(false)
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
// private fun isDrawOverAppsPermissionAllowed(methodCall: MethodCall, result: MethodChannel.Result) {
|
||||||
private fun askDrawOverAppsPermission(methodCall: MethodCall, result: MethodChannel.Result) {
|
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
// if (
|
||||||
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)
|
// Settings.canDrawOverlays(mainActivity)
|
||||||
val uri = Uri.parse("package:" + mainActivity.getPackageName())
|
// ) {
|
||||||
intent.setData(uri)
|
// result.success(true)
|
||||||
startActivityForResult(mainActivity, intent, 102, null)
|
// } else {
|
||||||
result.success(true)
|
// result.success(false)
|
||||||
} else {
|
// }
|
||||||
result.success(false)
|
// } else {
|
||||||
}
|
// result.success(false)
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
private fun getIntentData(methodCall: MethodCall, result: MethodChannel.Result) {
|
//
|
||||||
|
// private fun askDrawOverAppsPermission(methodCall: MethodCall, result: MethodChannel.Result) {
|
||||||
val bundle: Bundle? = getIntent("").extras
|
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
if (bundle != null) {
|
// val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)
|
||||||
val message = bundle.getString("notification") // 1
|
// val uri = Uri.parse("package:" + mainActivity.getPackageName())
|
||||||
System.out.println("BundleExtra:" + message)
|
// intent.setData(uri)
|
||||||
Toast.makeText(this.mainActivity, message + "", Toast.LENGTH_SHORT).show()
|
// startActivityForResult(mainActivity, intent, 102, null)
|
||||||
} else {
|
// result.success(true)
|
||||||
Toast.makeText(this.mainActivity, "Bundle Null", Toast.LENGTH_SHORT).show();
|
// } else {
|
||||||
}
|
// result.success(false)
|
||||||
result.success(true);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
// private fun getIntentData(methodCall: MethodCall, result: MethodChannel.Result) {
|
||||||
|
//
|
||||||
|
// val bundle: Bundle? = getIntent("").extras
|
||||||
|
// if (bundle != null) {
|
||||||
|
// val message = bundle.getString("notification") // 1
|
||||||
|
// System.out.println("BundleExtra:" + message)
|
||||||
|
// Toast.makeText(this.mainActivity, message + "", Toast.LENGTH_SHORT).show()
|
||||||
|
// } else {
|
||||||
|
// Toast.makeText(this.mainActivity, "Bundle Null", Toast.LENGTH_SHORT).show();
|
||||||
|
// }
|
||||||
|
// result.success(true);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background"/>
|
||||||
|
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||||
|
</adaptive-icon>
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background"/>
|
||||||
|
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||||
|
</adaptive-icon>
|
||||||
|
Before Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 11 KiB |
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="ic_launcher_background">#F0F4F2</color>
|
||||||
|
</resources>
|
||||||
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 143 KiB |
@ -0,0 +1 @@
|
|||||||
|
extensions:
|
||||||