fix(android): support new demo debug mode

This commit is contained in:
maxli
2023-05-17 18:30:48 +08:00
committed by siguangli
parent fac396504e
commit 486e541782
12 changed files with 112 additions and 27 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ buildscript {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.github.kezong:fat-aar:1.3.8'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21'
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 1, 'seconds'
@@ -171,6 +171,14 @@ public abstract class HippyEngineManagerImpl extends HippyEngineManager implemen
}
}
@Nullable
public View getDevButton(int rootId) {
if (mDevSupportManager != null) {
return mDevSupportManager.getDevImp().getDevButton(rootId);
}
return null;
}
@Override
public void destroyEngine() {
if (mEngineContext != null) {
@@ -150,6 +150,14 @@ public class DevServerImpl implements DevServerInterface, View.OnClickListener,
}
}
@Override
public View getDevButton(int rootId) {
if (mDevButtonMaps != null) {
return mDevButtonMaps.get(rootId);
}
return null;
}
@Override
@Nullable
public String createResourceUrl(String resName) {
@@ -16,6 +16,7 @@
package com.tencent.mtt.hippy.devsupport;
import android.content.Context;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -37,4 +38,7 @@ public interface DevServerInterface {
void detachFromHost(Context context, int rootId);
void handleException(Throwable throwable);
@Nullable
View getDevButton(int rootId);
}
@@ -91,6 +91,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core-ktx:+'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Binary file not shown.
@@ -14,11 +14,13 @@
android:roundIcon="@drawable/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Hippy"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:exported="false"
android:name=".PageConfiguration"
android:configChanges="orientation|screenSize|keyboardHidden">
android:configChanges="orientation|screenSize|keyboardHidden"
android:launchMode="singleInstance">
<meta-data
android:name="android.app.lib_name"
android:value="" />
@@ -15,13 +15,16 @@
package com.openhippy.example
import android.app.Activity
import android.content.Context
import android.graphics.Bitmap
import android.view.View
import android.view.ViewGroup
import android.view.ViewParent
import com.tencent.mtt.hippy.HippyAPIProvider
import com.tencent.mtt.hippy.HippyEngine
import com.tencent.mtt.hippy.HippyEngine.*
import com.tencent.mtt.hippy.HippyEngineManagerImpl
import com.tencent.mtt.hippy.adapter.DefaultLogAdapter
import com.tencent.mtt.hippy.adapter.exception.HippyExceptionHandlerAdapter
import com.tencent.mtt.hippy.common.HippyJsException
@@ -33,10 +36,12 @@ class HippyEngineWrapper {
var hippyEngine: HippyEngine
var hippyRootView: ViewGroup? = null
var devButton: View? = null
var snapshot: Bitmap? = null
var pageItem: View? = null
val driverMode: PageConfiguration.DriverMode
val renderMode: PageConfiguration.RenderMode
val engineId: Int
constructor(dm: PageConfiguration.DriverMode,
rm: PageConfiguration.RenderMode,
@@ -60,6 +65,9 @@ class HippyEngineWrapper {
PageConfiguration.DriverMode.JS_VUE_3 -> {
initParams.coreJSAssetsPath = "vue3/vendor.android.js"
}
PageConfiguration.DriverMode.VL -> {
//TODO: Coming soon
}
}
initParams.codeCacheTag = "common"
initParams.exceptionHandler = object : HippyExceptionHandlerAdapter {
@@ -77,6 +85,34 @@ class HippyEngineWrapper {
initParams.providers = providers
initParams.enableTurbo = true
hippyEngine = create(initParams)
engineId = hippyEngine.engineId
}
fun onStop() {
if (devButton == null) {
hippyRootView?.let {
devButton = (hippyEngine as HippyEngineManagerImpl).getDevButton(it.id)
}
}
devButton?.let {
val parent: ViewParent = it.parent
parent?.let {
(parent as ViewGroup).removeView(devButton)
}
}
}
fun onResume(context: Context) {
hippyRootView?.let {
devButton = (hippyEngine as HippyEngineManagerImpl).getDevButton(it.id)
if (devButton != null) {
val parent: ViewParent? = devButton?.parent
if (parent == null) {
val decorView = (context as Activity).window.decorView as ViewGroup
decorView.addView(devButton)
}
}
}
}
fun destroy() {
@@ -104,6 +140,9 @@ class HippyEngineWrapper {
PageConfiguration.DriverMode.JS_VUE_3 -> {
loadParams.jsAssetsPath = "vue3/index.android.js"
}
PageConfiguration.DriverMode.VL -> {
//TODO: Coming soon
}
}
loadParams.jsFilePath = null
loadParams.jsParams = HippyMap()
@@ -141,9 +180,4 @@ class HippyEngineWrapper {
fun onCreateRootView(hippyRootView: ViewGroup?)
fun onLoadModuleCompleted(statusCode: ModuleLoadStatus, msg: String?)
}
interface HippyEngineDestroyCallback {
fun onDestroyCompleted()
}
}
@@ -46,11 +46,17 @@ class PageConfiguration : AppCompatActivity(), View.OnClickListener {
NATIVE, TDF_CORE, FLUTTER
}
companion object {
var currentEngineId: Int = -1
}
private lateinit var pageConfigurationRoot: View
private lateinit var pageConfigurationContainer: View
private lateinit var pageConfigurationSetting: View
private lateinit var pageConfigurationTitle: View
private lateinit var driverSettingText: View
private lateinit var rendererSettingText: View
private var hasRunOnCreate = false
private var hippyEngineWrapper: HippyEngineWrapper? = null
private var debugMode: Boolean = false
private var debugServerHost: String = "localhost:38989"
@@ -65,42 +71,62 @@ class PageConfiguration : AppCompatActivity(), View.OnClickListener {
pageConfigurationRoot = layoutInflater.inflate(R.layout.activity_page_configuration, null)
pageConfigurationContainer =
pageConfigurationRoot.findViewById(R.id.page_configuration_container)
pageConfigurationSetting = pageConfigurationRoot.findViewById(R.id.page_configuration_setting)
pageConfigurationTitle =
pageConfigurationRoot.findViewById(R.id.page_configuration_navigation_title)
val backButton =
pageConfigurationRoot.findViewById<View>(R.id.page_configuration_navigation_back)
backButton.setOnClickListener { v ->
buildSnapshot { onBackPressedDispatcher.onBackPressed() }
}
if (hippyEngineWrapper == null) {
val pageId = intent.extras?.getInt("PAGE_ITEM_ID")
val hippyEngineList = HippyEngineHelper.getHippyEngineList()
for (engine in hippyEngineList) {
if (engine.pageItem?.id == pageId) {
hippyEngineWrapper = engine
}
buildSnapshot {
moveTaskToBack(true)
}
}
if (hippyEngineWrapper?.hippyRootView != null) {
(pageConfigurationTitle as TextView).text =
resources.getText(R.string.page_configuration_navigation_title_demo)
(pageConfigurationContainer as ViewGroup).removeAllViews()
(pageConfigurationContainer as ViewGroup).addView(hippyEngineWrapper?.hippyRootView)
} else {
initSettingView()
}
initSettingView()
hasRunOnCreate = true
setContentView(pageConfigurationRoot)
}
override fun onStop() {
hippyEngineWrapper?.let {
it.onStop()
}
super.onStop()
}
override fun onResume() {
if (!hasRunOnCreate) {
(pageConfigurationContainer as ViewGroup).removeAllViews()
if (currentEngineId == -1) {
(pageConfigurationTitle as TextView).text =
resources.getText(R.string.page_configuration_navigation_title)
(pageConfigurationContainer as ViewGroup).addView(pageConfigurationSetting)
} else {
val hippyEngineList = HippyEngineHelper.getHippyEngineList()
for (engine in hippyEngineList) {
if (engine.engineId == currentEngineId) {
hippyEngineWrapper = engine
}
}
(pageConfigurationTitle as TextView).text =
resources.getText(R.string.page_configuration_navigation_title_demo)
hippyEngineWrapper?.let {
(pageConfigurationContainer as ViewGroup).addView(it.hippyRootView)
it.onResume(this)
}
}
}
hasRunOnCreate = false
super.onResume()
}
override fun onBackPressed() {
buildSnapshot { onBackPressedDispatcher.onBackPressed() }
buildSnapshot { moveTaskToBack(true) }
}
private fun buildSnapshot(runnable: Runnable) {
val rootView = hippyEngineWrapper?.hippyRootView
if (rootView == null) {
(pageConfigurationContainer as ViewGroup).removeAllViews()
runnable.run()
} else {
generateBitmapFromView(rootView, object : SnapshotBuildCallback {
@@ -194,8 +194,8 @@ class PageManagement : AppCompatActivity() {
it.height = pageItemHeight
}
pageItemImage.setOnClickListener { v ->
PageConfiguration.currentEngineId = hippyEngineWrapper?.engineId?: -1
val intent = Intent(this, PageConfiguration::class.java)
intent.putExtra("PAGE_ITEM_ID", pageItem.id)
startActivity(intent)
}
hippyEngineWrapper?.pageItem = pageItem
@@ -64,6 +64,7 @@
app:layout_constraintTop_toBottomOf="@id/page_configuration_navigation_bar">
<ScrollView
android:id="@+id/page_configuration_setting"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
@@ -8,5 +8,6 @@
<string name="renderer_tdf_core">TDF Core</string>
<string name="renderer_flutter">Flutter</string>
<string name="setting_not_available">Coming soon</string>
<string name="page_configuration_navigation_title">Page setting</string>
<string name="page_configuration_navigation_title_demo">Demo</string>
</resources>