Skip to content

Commit

Permalink
feat: Support screen orientation in plugin's AndroidManifest
Browse files Browse the repository at this point in the history
判断requestedOrientation和插件manifest中不一致时主动设置它
  • Loading branch information
AntonioShare committed Nov 28, 2023
1 parent a7de6d1 commit 67da8b3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<activity
android:name="com.tencent.shadow.sample.plugin.app.lib.usecases.activity.TestActivityOrientation"
android:configChanges="orientation|screenSize|fontScale"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustResize" />

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ open class ShadowActivityDelegate(private val mDI: DI) : GeneratedShadowActivity
pluginActivity.applicationInfo.theme
}
pluginActivity.setTheme(activityTheme)
val screenOrientation = pluginActivityInfo.screenOrientation
if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED && screenOrientation != pluginActivity.requestedOrientation) {
pluginActivity.requestedOrientation = screenOrientation
}
}

override fun getLoaderVersion() = BuildConfig.VERSION_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sealed class AndroidManifestKeys {
const val name = "android:name"
const val theme = "android:theme"
const val configChanges = "android:configChanges"
const val screenOrientation = "android:screenOrientation"
const val windowSoftInputMode = "android:windowSoftInputMode"
const val authorities = "android:authorities"
const val `intent-filter` = "intent-filter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class AndroidManifestReader {
AndroidManifestKeys.theme,
AndroidManifestKeys.configChanges,
AndroidManifestKeys.windowSoftInputMode,
AndroidManifestKeys.screenOrientation,
).forEach { attributeKey ->
activityMap.putAttributeIfNotNull(element, attributeKey)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,14 @@ private class PluginManifestBuilder(val manifestMap: ManifestMap) {
private fun toNewActivityInfo(componentMap: ComponentMap): String {
fun makeResIdLiteral(
key: String,
defaultValue: String = "0",
valueToResId: (value: String) -> String
): String {
val value = componentMap[key] as String?
val literal = if (value != null) {
valueToResId(value)
} else {
"0"
defaultValue
}
return literal
}
Expand All @@ -204,12 +205,17 @@ private class PluginManifestBuilder(val manifestMap: ManifestMap) {
it
}

val screenOrientation = makeResIdLiteral(AndroidManifestKeys.screenOrientation, "-1") {
it
}

return "new com.tencent.shadow.core.runtime.PluginManifest" +
".ActivityInfo(" +
"\"${componentMap[AndroidManifestKeys.name]}\", " +
"$themeLiteral ," +
"$configChangesLiteral ," +
softInputModeLiteral +
"$softInputModeLiteral ," +
screenOrientation +
")"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,26 @@ final class ActivityInfo extends ComponentInfo implements Parcelable {
public final int theme;
public final int configChanges;
public final int softInputMode;
public final int screenOrientation;

public ActivityInfo(String className,
int theme,
int configChanges,
int softInputMode) {
int softInputMode,
int screenOrientation) {
super(className);
this.theme = theme;
this.configChanges = configChanges;
this.softInputMode = softInputMode;
this.screenOrientation = screenOrientation;
}

protected ActivityInfo(Parcel in) {
super(in);
theme = in.readInt();
configChanges = in.readInt();
softInputMode = in.readInt();
screenOrientation = in.readInt();
}

@Override
Expand All @@ -94,6 +98,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(theme);
dest.writeInt(configChanges);
dest.writeInt(softInputMode);
dest.writeInt(screenOrientation);
}

@Override
Expand Down

0 comments on commit 67da8b3

Please sign in to comment.