-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Compat PlatlogoActivity edgeToEdge
Signed-off-by: Hu Shenghao <[email protected]>
- Loading branch information
1 parent
ac7ec8e
commit 3493249
Showing
7 changed files
with
106 additions
and
45 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
# DrawableKt.installApi24InflateDelegates | ||
-keep class androidx.appcompat.widget.ResourceManagerInternal { *; } | ||
-keep class androidx.appcompat.widget.ResourceManagerInternal$InflateDelegate { *; } | ||
-keep class * extends androidx.appcompat.widget.ResourceManagerInternal$InflateDelegate { *; } | ||
-keep class * extends androidx.appcompat.widget.ResourceManagerInternal$InflateDelegate { *; } | ||
|
||
# EdgeToEdgeCompat | ||
-keep class androidx.activity.EdgeToEdgeImpl { *; } | ||
-keep class * extends androidx.activity.EdgeToEdgeImpl { *; } |
89 changes: 89 additions & 0 deletions
89
basic/src/main/java/androidx/activity/EdgeToEdgeCompat.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,89 @@ | ||
package androidx.activity; | ||
|
||
import android.app.Activity; | ||
import android.graphics.Color; | ||
import android.os.Build; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.view.Window; | ||
|
||
import com.dede.basic.utils.DynamicObjectUtils; | ||
import com.dede.basic.utils.dynamic.DynamicResult; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* EdgeToEdge compat | ||
* | ||
* @see EdgeToEdge | ||
*/ | ||
public class EdgeToEdgeCompat { | ||
|
||
private static final String TAG = "EdgeToEdgeCompat"; | ||
|
||
@Nullable | ||
private final static EdgeToEdgeImpl impl = createEdgeToEdgeImpl(); | ||
|
||
/** | ||
* Create EdgeToEdge instance | ||
* | ||
* @return EdgeToEdgeImpl instance | ||
* @see EdgeToEdge#enable(ComponentActivity) | ||
*/ | ||
@Nullable | ||
private static EdgeToEdgeImpl createEdgeToEdgeImpl() { | ||
String className = "androidx.activity.EdgeToEdgeBase"; | ||
final int[] apis = { | ||
Build.VERSION_CODES.R, // 30 | ||
Build.VERSION_CODES.Q, // 29 | ||
Build.VERSION_CODES.P, // 28 | ||
Build.VERSION_CODES.O, // 26 | ||
Build.VERSION_CODES.M, // 23 | ||
Build.VERSION_CODES.LOLLIPOP,// 21 | ||
}; | ||
for (int api : apis) { | ||
if (Build.VERSION.SDK_INT >= api) { | ||
className = "androidx.activity.EdgeToEdgeApi" + api; | ||
break; | ||
} | ||
} | ||
DynamicResult dynamicResult = DynamicObjectUtils.asDynamicObject(className) | ||
.newInstance(new Class[0], new Object[0]); | ||
EdgeToEdgeImpl impl = DynamicResult.getTypeValue(dynamicResult, EdgeToEdgeImpl.class); | ||
Log.i(TAG, "EdgeToEdgeImpl: " + impl); | ||
return impl; | ||
} | ||
|
||
private static boolean getDetectDarkMode(SystemBarStyle systemBarStyle, View view) { | ||
// internal val detectDarkMode: (Resources) -> Boolean | ||
// androidx.activity library | ||
// release build | ||
return systemBarStyle.getDetectDarkMode$activity_release().invoke(view.getResources()); | ||
} | ||
|
||
public static void enable(Activity activity, SystemBarStyle statusBarStyle, SystemBarStyle navigationBarStyle) { | ||
if (activity instanceof ComponentActivity) { | ||
EdgeToEdge.enable((ComponentActivity) activity, statusBarStyle, navigationBarStyle); | ||
return; | ||
} | ||
|
||
if (impl == null) { | ||
Log.w(TAG, "enableEdgeToEdge, impl == null"); | ||
return; | ||
} | ||
|
||
Window window = activity.getWindow(); | ||
View view = window.getDecorView(); | ||
boolean statusBarIsDark = getDetectDarkMode(statusBarStyle, view); | ||
boolean navigationBarIsDark = getDetectDarkMode(navigationBarStyle, view); | ||
impl.setUp( | ||
statusBarStyle, navigationBarStyle, window, view, statusBarIsDark, navigationBarIsDark | ||
); | ||
impl.adjustLayoutInDisplayCutoutMode(window); | ||
} | ||
|
||
public static void enable(Activity activity) { | ||
enable(activity, SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT), | ||
SystemBarStyle.auto(EdgeToEdge.getDefaultLightScrim(), EdgeToEdge.getDefaultDarkScrim())); | ||
} | ||
} |
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
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
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
8 changes: 4 additions & 4 deletions
8
...tivity-actions/src/main/java/com/dede/android_eggs/util/actions/PlatLogoActivityAction.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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
package com.dede.android_eggs.util.actions | ||
|
||
import android.app.Activity | ||
import androidx.activity.EdgeToEdgeCompat | ||
import com.dede.android_eggs.util.ActivityActionDispatcher | ||
import com.dede.android_eggs.views.main.util.EasterEggShortcutsHelp | ||
import com.dede.basic.Utils.isPlatLogoActivity | ||
import com.dede.basic.Utils.platLogoEdge2Edge | ||
|
||
internal class PlatLogoActivityAction : ActivityActionDispatcher.ActivityAction { | ||
|
||
override fun onPreCreate(activity: Activity) { | ||
if (activity.isPlatLogoActivity) { | ||
activity.platLogoEdge2Edge() | ||
EdgeToEdgeCompat.enable(activity) | ||
} | ||
} | ||
|
||
override fun onCreate(activity: Activity) { | ||
if (activity.isPlatLogoActivity) { | ||
EasterEggShortcutsHelp.reportShortcutUsed(activity, activity.intent) | ||
EasterEggShortcutsHelp.autoReportShortcutUsed(activity, activity.intent) | ||
} | ||
} | ||
} | ||
} |
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