android platform channel added.

main
taha.alam 2 years ago
parent d0709a4c54
commit a6bc5790bc

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

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

@ -2,12 +2,16 @@ package com.eventtan.test.penguin_flutter_sample
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build
import android.util.Log 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.app.penguin_flutter_sample.penguin.PenguinViewFactory
import com.eventtan.test.penguin_flutter_sample.PermissionManager.PermissionHelper import com.eventtan.test.penguin_flutter_sample.PermissionManager.PermissionHelper
import com.eventtan.test.penguin_flutter_sample.PermissionManager.PermissionManager import com.eventtan.test.penguin_flutter_sample.PermissionManager.PermissionManager
import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine 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 lateinit var flutterEngine: FlutterEngine
private val CHANNEL = "com.aamir/launch_penguin_ui"
/** /**
* Configures the Flutter engine by registering platform view factories. * Configures the Flutter engine by registering platform view factories.
* *
* @param flutterEngine The [FlutterEngine] instance associated with this activity. * @param flutterEngine The [FlutterEngine] instance associated with this activity.
*/ */
@RequiresApi(Build.VERSION_CODES.O)
override fun configureFlutterEngine(flutterEngine: FlutterEngine) { override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(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.app.Activity
import android.content.Context import android.content.Context
import android.content.Context.RECEIVER_EXPORTED
import android.content.IntentFilter import android.content.IntentFilter
import android.graphics.Color import android.graphics.Color
import android.os.Build
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.util.Log import android.util.Log
@ -11,6 +13,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.RelativeLayout import android.widget.RelativeLayout
import android.widget.Toast import android.widget.Toast
import androidx.annotation.RequiresApi
import com.eventtan.test.penguin_flutter_sample.MainActivity 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.PermissionHelper
import com.eventtan.test.penguin_flutter_sample.PermissionManager.PermissionManager 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, * Implements `PlatformView` for rendering the view, `MethodChannel.MethodCallHandler` for handling method calls,
* and `PenNavUIDelegate` for handling SDK events. * and `PenNavUIDelegate` for handling SDK events.
*/ */
@RequiresApi(Build.VERSION_CODES.O)
internal class PenguinView( internal class PenguinView(
context: Context, context: Context,
id: Int, id: Int,
creationParams: Map<String?, Any?>?, val creationParams: Map<String, String>,
messenger: BinaryMessenger, messenger: BinaryMessenger,
activity: MainActivity activity: MainActivity
) : PlatformView, MethodChannel.MethodCallHandler, PenNavUIDelegate { ) : PlatformView, MethodChannel.MethodCallHandler, PenNavUIDelegate {
// The layout for displaying the Penguin UI // The layout for displaying the Penguin UI
private val mapLayout: RelativeLayout = RelativeLayout(context) private val mapLayout: RelativeLayout = RelativeLayout(context)
private val _context: Context = context.applicationContext private val _context: Context = context
private val permissionResultReceiver: PermissionResultReceiver private val permissionResultReceiver: PermissionResultReceiver
private val permissionIntentFilter = IntentFilter("PERMISSION_RESULT_ACTION") private val permissionIntentFilter = IntentFilter("PERMISSION_RESULT_ACTION")
@ -71,8 +75,8 @@ internal class PenguinView(
onPermissionsDenied() onPermissionsDenied()
} }
} }
//todo handle properly the way it in the main app check the sdk version and cal it appropiately
mContext.registerReceiver(permissionResultReceiver, permissionIntentFilter) mContext.registerReceiver(permissionResultReceiver, permissionIntentFilter,RECEIVER_EXPORTED)
// Set the background color of the layout // Set the background color of the layout
mapLayout.setBackgroundColor(Color.RED) mapLayout.setBackgroundColor(Color.RED)
@ -155,12 +159,12 @@ internal class PenguinView(
private fun initPenguin() { private fun initPenguin() {
// Configure the PlugAndPlaySDK // Configure the PlugAndPlaySDK
PlugAndPlaySDK.configuration = PlugAndPlayConfiguration.Builder() PlugAndPlaySDK.configuration = PlugAndPlayConfiguration.Builder()
.setBaseUrl("https://temp.penguinin.com", "https://temp.penguinin.com") .setBaseUrl(creationParams["baseURL"], creationParams["positionURL"])
.setServiceName("api", "pe") .setServiceName(creationParams["dataServiceName"], creationParams["positionServiceName"])
.setClientData("Client", "clientkey") .setClientData(creationParams["clientID"], creationParams["clientKey"])
.setUserName("client") .setUserName("client")
.setLanguageID(Languages.en) .setLanguageID(Languages.en)
.setSimulationModeEnabled(true) .setSimulationModeEnabled(false)
.setEnableBackButton(true) .setEnableBackButton(true)
.setDeepLinkData("deeplink") .setDeepLinkData("deeplink")
.setCustomizeColor("#2CA0AF") .setCustomizeColor("#2CA0AF")
@ -189,16 +193,17 @@ internal class PenguinView(
* @param warningCode Optional warning code received from the SDK. * @param warningCode Optional warning code received from the SDK.
*/ */
override fun onPenNavSuccess(warningCode: String?) { override fun onPenNavSuccess(warningCode: String?) {
if (_context is Activity) { // if (_context is Activity) {
_context.runOnUiThread { // _context.runOnUiThread {
Toast.makeText(_context, "Success Info: $warningCode", Toast.LENGTH_SHORT).show() // Toast.makeText(_context, "Success Info: $warningCode", Toast.LENGTH_SHORT).show()
} // }
} else { // } else {
val handler = Handler(Looper.getMainLooper()) // println("the warming is presented $$warningCode")
handler.post { //// val handler = Handler(Looper.getMainLooper())
Toast.makeText(_context, "Success Info: $warningCode", Toast.LENGTH_SHORT).show() //// handler.post {
} //// Toast.makeText(_context, "Success Info: $warningCode", Toast.LENGTH_SHORT).show()
} //// }
// }
} }
/** /**

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

@ -12,6 +12,6 @@
<string name="client_key" translatable="false">UGVuZ3VpbklOX1Blbk5hdl9QSUY=</string> <string name="client_key" translatable="false">UGVuZ3VpbklOX1Blbk5hdl9QSUY=</string>
<string name="deep_link_schema" translatable="false"></string> <string name="deep_link_schema" translatable="false"></string>
<string name="deep_link_domain" 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> </resources>

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

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

Loading…
Cancel
Save