Compare commits
3 Commits
dev_v3.13.
...
dev_v3.13.
| Author | SHA1 | Date |
|---|---|---|
|
|
b1432280a1 | 1 year ago |
|
|
fb4cf08b89 | 1 year ago |
|
|
53015422e5 | 1 year ago |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,51 @@
|
||||
package com.cloud.diplomaticquarterapp
|
||||
import com.ejada.hmg.MainActivity
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.cloud.diplomaticquarterapp.penguin.PenguinView
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
class PenguinInPlatformBridge(
|
||||
private var flutterEngine: FlutterEngine,
|
||||
private var mainActivity: MainActivity
|
||||
) {
|
||||
|
||||
private lateinit var channel: MethodChannel
|
||||
|
||||
companion object {
|
||||
private const val CHANNEL = "launch_penguin_ui"
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
fun create() {
|
||||
// openTok = OpenTok(mainActivity, flutterEngine)
|
||||
channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
|
||||
channel.setMethodCallHandler { call: MethodCall, result: MethodChannel.Result ->
|
||||
when (call.method) {
|
||||
"launchPenguin" -> {
|
||||
print("the platform channel is being called")
|
||||
val args = call.arguments as Map<String, Any>?
|
||||
Log.d("TAG", "configureFlutterEngine: $args")
|
||||
println("args")
|
||||
args?.let {
|
||||
PenguinView(
|
||||
mainActivity,
|
||||
100,
|
||||
args,
|
||||
flutterEngine.dartExecutor.binaryMessenger,
|
||||
activity = mainActivity,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.cloud.diplomaticquarterapp.PermissionManager
|
||||
|
||||
import android.Manifest
|
||||
|
||||
object PermissionHelper {
|
||||
|
||||
fun getRequiredPermissions(): Array<String> {
|
||||
return arrayOf(
|
||||
Manifest.permission.INTERNET,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
Manifest.permission.ACCESS_NETWORK_STATE,
|
||||
Manifest.permission.BLUETOOTH,
|
||||
Manifest.permission.BLUETOOTH_ADMIN,
|
||||
Manifest.permission.BLUETOOTH_SCAN,
|
||||
Manifest.permission.BLUETOOTH_CONNECT,
|
||||
Manifest.permission.HIGH_SAMPLING_RATE_SENSORS,
|
||||
// Manifest.permission.ACTIVITY_RECOGNITION
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package com.cloud.diplomaticquarterapp.PermissionManager
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
|
||||
class PermissionManager(
|
||||
private val context: Context,
|
||||
val listener: PermissionListener,
|
||||
private val requestCode: Int,
|
||||
vararg permissions: String
|
||||
) {
|
||||
|
||||
private val permissionsArray = permissions
|
||||
|
||||
interface PermissionListener {
|
||||
fun onPermissionGranted()
|
||||
fun onPermissionDenied()
|
||||
}
|
||||
|
||||
fun arePermissionsGranted(): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
permissionsArray.all {
|
||||
ContextCompat.checkSelfPermission(context, it) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fun requestPermissions(activity: Activity) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
ActivityCompat.requestPermissions(activity, permissionsArray, requestCode)
|
||||
}
|
||||
}
|
||||
|
||||
fun handlePermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
if (this.requestCode == requestCode) {
|
||||
val allGranted = grantResults.all { it == PackageManager.PERMISSION_GRANTED }
|
||||
if (allGranted) {
|
||||
listener.onPermissionGranted()
|
||||
} else {
|
||||
listener.onPermissionDenied()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.cloud.diplomaticquarterapp.PermissionManager
|
||||
|
||||
// PermissionResultReceiver.kt
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
||||
class PermissionResultReceiver(
|
||||
private val callback: (Boolean) -> Unit
|
||||
) : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
val granted = intent?.getBooleanExtra("PERMISSION_GRANTED", false) ?: false
|
||||
callback(granted)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,261 @@
|
||||
package com.cloud.diplomaticquarterapp.penguin
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Context.RECEIVER_EXPORTED
|
||||
import android.content.IntentFilter
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.cloud.diplomaticquarterapp.PermissionManager.PermissionHelper
|
||||
import com.cloud.diplomaticquarterapp.PermissionManager.PermissionManager
|
||||
import com.cloud.diplomaticquarterapp.PermissionManager.PermissionResultReceiver
|
||||
import com.ejada.hmg.MainActivity
|
||||
import com.peng.pennavmap.PlugAndPlayConfiguration
|
||||
import com.peng.pennavmap.PlugAndPlaySDK
|
||||
import com.peng.pennavmap.enums.InitializationErrorType
|
||||
import com.peng.pennavmap.interfaces.PenNavUIDelegate
|
||||
import com.peng.pennavmap.utils.Languages
|
||||
import io.flutter.plugin.common.BinaryMessenger
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugin.platform.PlatformView
|
||||
|
||||
/**
|
||||
* Custom PlatformView for displaying Penguin UI components within a Flutter app.
|
||||
* Implements `PlatformView` for rendering the view, `MethodChannel.MethodCallHandler` for handling method calls,
|
||||
* and `PenNavUIDelegate` for handling SDK events.
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
internal class PenguinView(
|
||||
context: Context,
|
||||
id: Int,
|
||||
val creationParams: Map<String, Any>,
|
||||
messenger: BinaryMessenger,
|
||||
activity: MainActivity
|
||||
) : PlatformView, MethodChannel.MethodCallHandler, PenNavUIDelegate {
|
||||
// The layout for displaying the Penguin UI
|
||||
private val mapLayout: RelativeLayout = RelativeLayout(context)
|
||||
private val _context: Context = context
|
||||
|
||||
private val permissionResultReceiver: PermissionResultReceiver
|
||||
private val permissionIntentFilter = IntentFilter("PERMISSION_RESULT_ACTION")
|
||||
|
||||
private companion object {
|
||||
const val PERMISSIONS_REQUEST_CODE = 1
|
||||
}
|
||||
|
||||
private lateinit var permissionManager: PermissionManager
|
||||
|
||||
// Reference to the main activity
|
||||
private var _activity: Activity = activity
|
||||
|
||||
private lateinit var mContext: Context
|
||||
|
||||
init {
|
||||
// Set layout parameters for the mapLayout
|
||||
mapLayout.layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
|
||||
mContext = context
|
||||
|
||||
|
||||
permissionResultReceiver = PermissionResultReceiver { granted ->
|
||||
if (granted) {
|
||||
onPermissionsGranted()
|
||||
} else {
|
||||
onPermissionsDenied()
|
||||
}
|
||||
}
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
mContext.registerReceiver(
|
||||
permissionResultReceiver,
|
||||
permissionIntentFilter,
|
||||
RECEIVER_EXPORTED
|
||||
)
|
||||
}else{
|
||||
mContext.registerReceiver(
|
||||
permissionResultReceiver,
|
||||
permissionIntentFilter,
|
||||
)
|
||||
}
|
||||
|
||||
// Set the background color of the layout
|
||||
mapLayout.setBackgroundColor(Color.RED)
|
||||
|
||||
permissionManager = PermissionManager(
|
||||
context = mContext,
|
||||
listener = object : PermissionManager.PermissionListener {
|
||||
override fun onPermissionGranted() {
|
||||
// Handle permissions granted
|
||||
onPermissionsGranted()
|
||||
}
|
||||
|
||||
override fun onPermissionDenied() {
|
||||
// Handle permissions denied
|
||||
onPermissionsDenied()
|
||||
}
|
||||
},
|
||||
requestCode = PERMISSIONS_REQUEST_CODE,
|
||||
*PermissionHelper.getRequiredPermissions()
|
||||
)
|
||||
|
||||
if (!permissionManager.arePermissionsGranted()) {
|
||||
permissionManager.requestPermissions(_activity)
|
||||
} else {
|
||||
// Permissions already granted
|
||||
permissionManager.listener.onPermissionGranted()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun onPermissionsGranted() {
|
||||
// Handle the actions when permissions are granted
|
||||
Log.d("PermissionsResult", "onPermissionsGranted")
|
||||
// Register the platform view factory for creating custom views
|
||||
|
||||
// Initialize the Penguin SDK
|
||||
initPenguin()
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun onPermissionsDenied() {
|
||||
// Handle the actions when permissions are denied
|
||||
Log.d("PermissionsResult", "onPermissionsDenied")
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view associated with this PlatformView.
|
||||
*
|
||||
* @return The main view for this PlatformView.
|
||||
*/
|
||||
override fun getView(): View {
|
||||
return mapLayout
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up resources associated with this PlatformView.
|
||||
*/
|
||||
override fun dispose() {
|
||||
// Cleanup code if needed
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles method calls from Dart code.
|
||||
*
|
||||
* @param call The method call from Dart.
|
||||
* @param result The result callback to send responses back to Dart.
|
||||
*/
|
||||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
||||
// Handle method calls from Dart code here
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Penguin SDK with custom configuration and delegates.
|
||||
*/
|
||||
private fun initPenguin() {
|
||||
// Configure the PlugAndPlaySDK
|
||||
val language = when (creationParams["languageCode"] as String) {
|
||||
"ar" -> Languages.ar
|
||||
"en" -> Languages.en
|
||||
else -> {
|
||||
Languages.en
|
||||
}
|
||||
}
|
||||
Log.d(
|
||||
"TAG",
|
||||
"initPenguin: ${Languages.getLanguageEnum(creationParams["languageCode"] as String)}"
|
||||
)
|
||||
PlugAndPlaySDK.configuration = PlugAndPlayConfiguration.Builder()
|
||||
.setBaseUrl(
|
||||
creationParams["baseURL"] as String,
|
||||
creationParams["positionURL"] as String
|
||||
)
|
||||
.setServiceName(
|
||||
creationParams["dataServiceName"] as String,
|
||||
creationParams["positionServiceName"] as String
|
||||
)
|
||||
.setClientData(
|
||||
creationParams["clientID"] as String,
|
||||
creationParams["clientKey"] as String
|
||||
)
|
||||
.setUserName(creationParams["username"] as String)
|
||||
// .setLanguageID(Languages.en)
|
||||
.setLanguageID(language)
|
||||
.setSimulationModeEnabled(creationParams["isSimulationModeEnabled"] as Boolean)
|
||||
.setEnableBackButton(true)
|
||||
.setDeepLinkData("deeplink")
|
||||
.setCustomizeColor("#2CA0AF")
|
||||
.setDeepLinkSchema("")
|
||||
.build()
|
||||
|
||||
// Set location delegate to handle location updates
|
||||
PlugAndPlaySDK.setPiLocationDelegate {
|
||||
// Example code to handle location updates
|
||||
// Uncomment and modify as needed
|
||||
// if (location.size() > 0)
|
||||
// Toast.makeText(_context, "Location Info Latitude: ${location[0]}, Longitude: ${location[1]}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
// Set events delegate for reporting issues
|
||||
PlugAndPlaySDK.setPiEventsDelegate { }
|
||||
|
||||
// Start the Penguin SDK
|
||||
PlugAndPlaySDK.start(mContext, this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Penguin UI setup is successful.
|
||||
*
|
||||
* @param warningCode Optional warning code received from the SDK.
|
||||
*/
|
||||
override fun onPenNavSuccess(warningCode: String?) {
|
||||
// if (_context is Activity) {
|
||||
// _context.runOnUiThread {
|
||||
// Toast.makeText(_context, "Success Info: $warningCode", Toast.LENGTH_SHORT).show()
|
||||
// }
|
||||
// } else {
|
||||
// println("the warming is presented $$warningCode")
|
||||
//// val handler = Handler(Looper.getMainLooper())
|
||||
//// handler.post {
|
||||
//// Toast.makeText(_context, "Success Info: $warningCode", Toast.LENGTH_SHORT).show()
|
||||
//// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there is an initialization error with Penguin UI.
|
||||
*
|
||||
* @param description Description of the error.
|
||||
* @param errorType Type of initialization error.
|
||||
*/
|
||||
override fun onPenNavInitializationError(
|
||||
description: String?,
|
||||
errorType: InitializationErrorType?
|
||||
) {
|
||||
Toast.makeText(mContext, "Navigation Error: $description", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Penguin UI is dismissed.
|
||||
*/
|
||||
override fun onPenNavUIDismiss() {
|
||||
// Handle UI dismissal if needed
|
||||
try {
|
||||
mContext.unregisterReceiver(permissionResultReceiver)
|
||||
dispose();
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Log.e("PenguinView", "Receiver not registered: $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="21.035" height="25.699" viewBox="0 0 21.035 25.699">
|
||||
<g id="file_4_" data-name="file (4)" transform="translate(0 0)">
|
||||
<path id="Path_4376" data-name="Path 4376" d="M199.117,108.4h.751v18.461a2.228,2.228,0,0,0,2.225,2.225h13.668v.684a1.42,1.42,0,0,1-1.42,1.42H199.12a1.42,1.42,0,0,1-1.42-1.42V109.82A1.418,1.418,0,0,1,199.117,108.4Z" transform="translate(-197.7 -105.491)" fill="#00000"/>
|
||||
<path id="Path_4377" data-name="Path 4377" d="M95.931,22.79H88.32a1.42,1.42,0,0,1-1.42-1.42V1.42A1.42,1.42,0,0,1,88.32,0H98.462V.47a1.378,1.378,0,0,0-.008.15V4.509a2,2,0,0,0,2,2h3.889c.04,0,.083,0,.123-.005h.494V21.371a1.42,1.42,0,0,1-1.42,1.42H95.931Zm-.287-4.825h4.962a.671.671,0,0,0,0-1.342H95.641a.671.671,0,1,0,0,1.342Zm-4.965-3.424h9.927a.671.671,0,0,0,0-1.342H90.679a.671.671,0,0,0,0,1.342Zm9.927-4.978H90.679a.671.671,0,0,0,0,1.342h9.927a.671.671,0,0,0,0-1.342Z" transform="translate(-83.924 0)" fill="#00000"/>
|
||||
<path id="Path_4378" data-name="Path 4378" d="M92.626,6.481h-3.9A1.191,1.191,0,0,1,87.546,5.3V1.4a.6.6,0,0,1,.6-.6.582.582,0,0,1,.419.177L93.05,5.462A.6.6,0,0,1,92.626,6.481Z" transform="translate(-72.209 -0.779)" fill="#00000"/>
|
||||
<path id="Path_4376" data-name="Path 4376" d="M199.117,108.4h.751v18.461a2.228,2.228,0,0,0,2.225,2.225h13.668v.684a1.42,1.42,0,0,1-1.42,1.42H199.12a1.42,1.42,0,0,1-1.42-1.42V109.82A1.418,1.418,0,0,1,199.117,108.4Z" transform="translate(-197.7 -105.491)" fill="#989898"/>
|
||||
<path id="Path_4377" data-name="Path 4377" d="M95.931,22.79H88.32a1.42,1.42,0,0,1-1.42-1.42V1.42A1.42,1.42,0,0,1,88.32,0H98.462V.47a1.378,1.378,0,0,0-.008.15V4.509a2,2,0,0,0,2,2h3.889c.04,0,.083,0,.123-.005h.494V21.371a1.42,1.42,0,0,1-1.42,1.42H95.931Zm-.287-4.825h4.962a.671.671,0,0,0,0-1.342H95.641a.671.671,0,1,0,0,1.342Zm-4.965-3.424h9.927a.671.671,0,0,0,0-1.342H90.679a.671.671,0,0,0,0,1.342Zm9.927-4.978H90.679a.671.671,0,0,0,0,1.342h9.927a.671.671,0,0,0,0-1.342Z" transform="translate(-83.924 0)" fill="#989898"/>
|
||||
<path id="Path_4378" data-name="Path 4378" d="M92.626,6.481h-3.9A1.191,1.191,0,0,1,87.546,5.3V1.4a.6.6,0,0,1,.6-.6.582.582,0,0,1,.419.177L93.05,5.462A.6.6,0,0,1,92.626,6.481Z" transform="translate(-72.209 -0.779)" fill="#989898"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB |
@ -1,6 +1,5 @@
|
||||
import 'package:diplomaticquarterapp/theme/theme_value.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
final Color? secondaryColor = appColor;
|
||||
final Color? secondaryColor = Colors.red[800];
|
||||
|
||||
final Color? dividerColor = Colors.grey[600];
|
||||
@ -0,0 +1,29 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class PenguinMethodChannel {
|
||||
static const MethodChannel _channel = MethodChannel('launch_penguin_ui');
|
||||
|
||||
static Future<void> launch(String storyboardName, String languageCode, String username) async {
|
||||
try {
|
||||
await _channel.invokeMethod('launchPenguin', {
|
||||
"storyboardName": storyboardName,
|
||||
"baseURL": "https://hmg.nav.penguinin.com",
|
||||
"dataURL": "https://hmg.nav.penguinin.com",
|
||||
"positionURL": "https://hmg.nav.penguinin.com",
|
||||
"dataServiceName": "api",
|
||||
"positionServiceName": "pe",
|
||||
"clientID": "HMG",
|
||||
"username": username,
|
||||
"isSimulationModeEnabled": false,
|
||||
"isShowUserName": false,
|
||||
"isUpdateUserLocationSmoothly": true,
|
||||
"isEnableReportIssue": true,
|
||||
"languageCode": languageCode,
|
||||
"clientKey": "UGVuZ3VpbklOX1Blbk5hdl9QSUY=",
|
||||
"mapBoxKey": "sk.eyJ1IjoicndhaWQiLCJhIjoiY2x6NWo0bTMzMWZodzJrcGZpemYzc3Z4dSJ9.uSSZuwNSGCcCdPAiORECmg"
|
||||
});
|
||||
} on PlatformException catch (e) {
|
||||
print("Failed to launch PenguinIn: '${e.message}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue