android platform channel added.

main
taha.alam 1 year ago
parent d0709a4c54
commit a6bc5790bc

@ -57,12 +57,12 @@ android {
signingConfigs {
release {
storeFile file("key.jks")
storePassword "123456"
keyAlias "key0"
keyPassword "123456"
}
// release {
// storeFile file("key.jks")
// storePassword "123456"
// keyAlias "key0"
// keyPassword "123456"
// }
}
@ -71,15 +71,15 @@ android {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
// signingConfig signingConfigs.release
}
debug {
debuggable true
minifyEnabled true
signingConfig signingConfigs.release
minifyEnabled false
// signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

@ -46,6 +46,8 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data

@ -2,12 +2,16 @@ package com.eventtan.test.penguin_flutter_sample
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import com.eventtan.app.penguin_flutter_sample.penguin.PenguinView
import com.eventtan.app.penguin_flutter_sample.penguin.PenguinViewFactory
import com.eventtan.test.penguin_flutter_sample.PermissionManager.PermissionHelper
import com.eventtan.test.penguin_flutter_sample.PermissionManager.PermissionManager
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
/**
@ -20,23 +24,33 @@ class MainActivity : FlutterActivity() {
private lateinit var flutterEngine: FlutterEngine
private val CHANNEL = "com.aamir/launch_penguin_ui"
/**
* Configures the Flutter engine by registering platform view factories.
*
* @param flutterEngine The [FlutterEngine] instance associated with this activity.
*/
@RequiresApi(Build.VERSION_CODES.O)
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
flutterEngine.platformViewsController.registry.registerViewFactory(
"penguin_lib", // Unique identifier for the view factory
PenguinViewFactory(
flutterEngine.dartExecutor.binaryMessenger, // Used for communication with Dart
this // Reference to the current MainActivity
)
)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
call, result ->
when (call.method) {
"launchPenguin" -> {
print("the platform channel is being called" )
val args = call.arguments as Map<String, String>?
Log.d("TAG", "configureFlutterEngine: $args")
println("args")
args?.let {
PenguinView(activity,100,args,flutterEngine.dartExecutor.binaryMessenger , activity = this,)
}
}
}
}
}

@ -2,8 +2,10 @@ package com.eventtan.app.penguin_flutter_sample.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.os.Handler
import android.os.Looper
import android.util.Log
@ -11,6 +13,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import android.widget.Toast
import androidx.annotation.RequiresApi
import com.eventtan.test.penguin_flutter_sample.MainActivity
import com.eventtan.test.penguin_flutter_sample.PermissionManager.PermissionHelper
import com.eventtan.test.penguin_flutter_sample.PermissionManager.PermissionManager
@ -30,16 +33,17 @@ import io.flutter.plugin.platform.PlatformView
* 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,
creationParams: Map<String?, Any?>?,
val creationParams: Map<String, String>,
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.applicationContext
private val _context: Context = context
private val permissionResultReceiver: PermissionResultReceiver
private val permissionIntentFilter = IntentFilter("PERMISSION_RESULT_ACTION")
@ -71,8 +75,8 @@ internal class PenguinView(
onPermissionsDenied()
}
}
mContext.registerReceiver(permissionResultReceiver, permissionIntentFilter)
//todo handle properly the way it in the main app check the sdk version and cal it appropiately
mContext.registerReceiver(permissionResultReceiver, permissionIntentFilter,RECEIVER_EXPORTED)
// Set the background color of the layout
mapLayout.setBackgroundColor(Color.RED)
@ -155,12 +159,12 @@ internal class PenguinView(
private fun initPenguin() {
// Configure the PlugAndPlaySDK
PlugAndPlaySDK.configuration = PlugAndPlayConfiguration.Builder()
.setBaseUrl("https://temp.penguinin.com", "https://temp.penguinin.com")
.setServiceName("api", "pe")
.setClientData("Client", "clientkey")
.setBaseUrl(creationParams["baseURL"], creationParams["positionURL"])
.setServiceName(creationParams["dataServiceName"], creationParams["positionServiceName"])
.setClientData(creationParams["clientID"], creationParams["clientKey"])
.setUserName("client")
.setLanguageID(Languages.en)
.setSimulationModeEnabled(true)
.setSimulationModeEnabled(false)
.setEnableBackButton(true)
.setDeepLinkData("deeplink")
.setCustomizeColor("#2CA0AF")
@ -189,16 +193,17 @@ internal class PenguinView(
* @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 {
val handler = Handler(Looper.getMainLooper())
handler.post {
Toast.makeText(_context, "Success Info: $warningCode", Toast.LENGTH_SHORT).show()
}
}
// 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()
//// }
// }
}
/**

@ -1,6 +1,8 @@
package com.eventtan.app.penguin_flutter_sample.penguin
import android.content.Context
import android.os.Build
import androidx.annotation.RequiresApi
import com.eventtan.test.penguin_flutter_sample.MainActivity
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.StandardMessageCodec
@ -28,9 +30,10 @@ class PenguinViewFactory(
* @param args Optional arguments passed for creating the view, expected to be a [Map].
* @return A new instance of [PenguinView].
*/
@RequiresApi(Build.VERSION_CODES.O)
override fun create(context: Context, viewId: Int, args: Any?): PlatformView {
// Cast the arguments to a Map if they are provided
val creationParams = args as Map<String?, Any?>?
val creationParams = args as Map<String, String>
// Instantiate and return the PenguinView with the provided parameters
return PenguinView(context, viewId, creationParams, messenger, mainActivity)

@ -12,6 +12,6 @@
<string name="client_key" translatable="false">UGVuZ3VpbklOX1Blbk5hdl9QSUY=</string>
<string name="deep_link_schema" translatable="false"></string>
<string name="deep_link_domain" translatable="false"></string>
<string name="mapbox_access_token" translatable="false">mapbox_token</string>
<string name="mapbox_access_token" translatable="false">sk.eyJ1IjoicndhaWQiLCJhIjoiY2x6NWo0bTMzMWZodzJrcGZpemYzc3Z4dSJ9.uSSZuwNSGCcCdPAiORECmg</string>
////////////////////////////////////////////
</resources>

@ -2,20 +2,21 @@ buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://plugins.gradle.org/m2' }
// maven { url 'https://plugins.gradle.org/m2' }
// maven { url 'https://jitpack.io' }
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
username = 'mapbox'
password = "sk.eyJ1IjoidmlyYWwtbW9ibWF4aW1lIiwiYSI6ImNseWZ0MzByYTAzZ2MyeHMxMXp3NWRscWYifQ.Dq-SRE-hyED1ojrJcq3JKA"
password = "sk.eyJ1IjoicndhaWQiLCJhIjoiY2x6NWo0bTMzMWZodzJrcGZpemYzc3Z4dSJ9.uSSZuwNSGCcCdPAiORECmg"
if (password == null || password == "") {
throw new GradleException("MAPBOX_DOWNLOADS_TOKEN isn't set. Set it to the project properties or to the enviroment variables.")
}
}
authentication {
basic(BasicAuthentication)
}
}
}
dependencies {
@ -35,7 +36,7 @@ allprojects {
}
credentials {
username = 'mapbox'
password = "sk.eyJ1IjoidmlyYWwtbW9ibWF4aW1lIiwiYSI6ImNseWZ0MzByYTAzZ2MyeHMxMXp3NWRscWYifQ.Dq-SRE-hyED1ojrJcq3JKA"
password = "sk.eyJ1IjoicndhaWQiLCJhIjoiY2x6NWo0bTMzMWZodzJrcGZpemYzc3Z4dSJ9.uSSZuwNSGCcCdPAiORECmg"
if (password == null || password == "") {
throw new GradleException("MAPBOX_DOWNLOADS_TOKEN isn't set. Set it to the project properties or to the enviroment variables.")
}

@ -4,5 +4,5 @@ android.enableJetifier=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
MAPBOX_USER_NAME = "mapbox"
MAPBOX_DOWNLOADS_TOKEN="sk.eyJ1IjoidmlyYWwtbW9ibWF4aW1lIiwiYSI6ImNseWZ0MzByYTAzZ2MyeHMxMXp3NWRscWYifQ.Dq-SRE-hyED1ojrJcq3JKA"
MAPBOX_DOWNLOADS_TOKEN="sk.eyJ1IjoicndhaWQiLCJhIjoiY2x6NWo0bTMzMWZodzJrcGZpemYzc3Z4dSJ9.uSSZuwNSGCcCdPAiORECmg"

@ -13,13 +13,12 @@ pluginManagement {
google()
mavenCentral()
gradlePluginPortal()
maven { url 'https://plugins.gradle.org/m2' }
maven { url 'https://jitpack.io' }
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
credentials {
username = 'mapbox'
password = 'sk.eyJ1IjoidmlyYWwtbW9ibWF4aW1lIiwiYSI6ImNseWZ0MzByYTAzZ2MyeHMxMXp3NWRscWYifQ.Dq-SRE-hyED1ojrJcq3JKA'
password = 'sk.eyJ1IjoicndhaWQiLCJhIjoiY2x6NWo0bTMzMWZodzJrcGZpemYzc3Z4dSJ9.uSSZuwNSGCcCdPAiORECmg'
if (password == null || password == "") {
throw new GradleException("MAPBOX_DOWNLOADS_TOKEN isn't set. Set it to the project properties or to the enviroment variables.")
}

Loading…
Cancel
Save