Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support setting the horizontal and vertical screen orientation … #1258

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading