Skip to content

Commit

Permalink
feat: Support setting the horizontal and vertical screen orientation …
Browse files Browse the repository at this point in the history
…in the plugin's AndroidManifest.

fix: fix format-code

fix: fix format-code
  • Loading branch information
AntonioShare committed Nov 27, 2023
1 parent a7de6d1 commit f36245d
Show file tree
Hide file tree
Showing 6 changed files with 20 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,9 @@ open class ShadowActivityDelegate(private val mDI: DI) : GeneratedShadowActivity
pluginActivity.applicationInfo.theme
}
pluginActivity.setTheme(activityTheme)
if (pluginActivityInfo.screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED && pluginActivityInfo.screenOrientation != pluginActivity.requestedOrientation) {
pluginActivity.requestedOrientation = pluginActivityInfo.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 f36245d

Please sign in to comment.