forked from Tencent/Shadow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Tencent#334
- Loading branch information
Showing
20 changed files
with
287 additions
and
435 deletions.
There are no files selected for viewing
53 changes: 0 additions & 53 deletions
53
projects/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/ShadowDialog.java
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
...s/sdk/core/runtime/src/main/java/com/tencent/shadow/core/runtime/ShadowDialogSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.tencent.shadow.core.runtime; | ||
|
||
import android.app.Activity; | ||
import android.app.Dialog; | ||
|
||
import com.tencent.shadow.core.runtime.container.PluginContainerActivity; | ||
|
||
public class ShadowDialogSupport { | ||
|
||
public static void dialogSetOwnerActivity(Dialog dialog, ShadowActivity activity) { | ||
Activity hostActivity = (Activity) activity.hostActivityDelegator.getHostActivity(); | ||
dialog.setOwnerActivity(hostActivity); | ||
} | ||
|
||
public static ShadowActivity dialogGetOwnerActivity(Dialog dialog) { | ||
PluginContainerActivity ownerActivity = (PluginContainerActivity) dialog.getOwnerActivity(); | ||
if (ownerActivity != null) { | ||
return (ShadowActivity) PluginActivity.get(ownerActivity); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...form/src/main/kotlin/com/tencent/shadow/core/transform/specific/DialogSupportTransform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Tencent Shadow available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the BSD 3-Clause License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.tencent.shadow.core.transform.specific | ||
|
||
import com.tencent.shadow.core.transform_kit.CodeConverterExtension | ||
import com.tencent.shadow.core.transform_kit.SpecificTransform | ||
import com.tencent.shadow.core.transform_kit.TransformStep | ||
import javassist.CtClass | ||
import javassist.bytecode.Descriptor | ||
|
||
class DialogSupportTransform : SpecificTransform() { | ||
companion object { | ||
const val ShadowActivityClassname = "com.tencent.shadow.core.runtime.ShadowActivity" | ||
const val AndroidDialogClassname = "android.app.Dialog" | ||
const val DialogSupportTransformClassname = "com.tencent.shadow.core.runtime.ShadowDialogSupport" | ||
} | ||
|
||
override fun setup(allInputClass: Set<CtClass>) { | ||
val androidDialog = mClassPool[AndroidDialogClassname] | ||
val shadowDialogSupport = mClassPool[DialogSupportTransformClassname] | ||
val shadowActivity = mClassPool[ShadowActivityClassname] | ||
|
||
val setOwnerActivityMethod = androidDialog.getDeclaredMethod("setOwnerActivity") | ||
val getOwnerActivityMethod = androidDialog.getDeclaredMethod("getOwnerActivity") | ||
|
||
//appClass中的Activity都已经被改名为ShadowActivity了.所以要把方法签名也先改一下. | ||
val shadowActivitySig = "Lcom/tencent/shadow/core/runtime/ShadowActivity;" | ||
setOwnerActivityMethod.methodInfo.descriptor = "($shadowActivitySig)V" | ||
getOwnerActivityMethod.methodInfo.descriptor = "()$shadowActivitySig" | ||
|
||
val dialogSetOwnerActivityMethod = shadowDialogSupport.getMethod("dialogSetOwnerActivity", | ||
Descriptor.ofMethod(CtClass.voidType, | ||
arrayOf(androidDialog, shadowActivity))) | ||
val dialogGetOwnerActivityMethod = shadowDialogSupport.getMethod("dialogGetOwnerActivity", | ||
Descriptor.ofMethod(shadowActivity, | ||
arrayOf(androidDialog))) | ||
|
||
newStep(object : TransformStep { | ||
override fun filter(allInputClass: Set<CtClass>) = allInputClass | ||
|
||
override fun transform(ctClass: CtClass) { | ||
ctClass.defrost() | ||
val codeConverter = CodeConverterExtension() | ||
codeConverter.redirectMethodCallToStaticMethodCall(setOwnerActivityMethod, dialogSetOwnerActivityMethod) | ||
codeConverter.redirectMethodCallToStaticMethodCall(getOwnerActivityMethod, dialogGetOwnerActivityMethod) | ||
try { | ||
ctClass.instrument(codeConverter) | ||
} catch (e: Exception) { | ||
System.err.println("处理" + ctClass.name + "时出错:" + e) | ||
throw e | ||
} | ||
} | ||
}) | ||
|
||
} | ||
|
||
} |
103 changes: 0 additions & 103 deletions
103
...e/transform/src/main/kotlin/com/tencent/shadow/core/transform/specific/DialogTransform.kt
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
projects/sdk/core/transform/src/test/java/android/app/Dialog.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
projects/sdk/core/transform/src/test/java/com/tencent/shadow/core/runtime/ShadowDialog.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
projects/sdk/core/transform/src/test/java/test/dialog/SubDialog.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
projects/sdk/core/transform/src/test/java/test/dialog/UseDialog.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
projects/sdk/core/transform/src/test/java/test/dialog/UseSubDialog.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
projects/sdk/core/transform/src/test/java/test/dialog/UseSubSubDialog.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.