-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Changed compileSdkVersion to 35 * Fixed bitmap.config nullability issues * Fixed signing nullabiliy issues * Marked onLowMemory as deprecated * Temporarily commented out deprecated status/navbar code * Changed targetSdkVersion to 35 * Added detectNonSdkApiUsage to StrictMode * Re-enabled StrictMode * Temporarily disabled StrictMode disk read/write * Re-enabled StrictMode disk read/write * Added Android 15+ version of setWindowStatusBarColor * Added Android 15+ version of setWindowNavigationBarColor * Minor formatting changes * Replaced deprecated removeLast * Don't remove quick link if empty * Fixed test * Fixed failing test due to unsupported removeLast * Don't shadow resource references * Removed unused deprecated window extension functions * Revert to targetSdkVersion to prevent system bar overlap * Use WindowExtensions.setWindowNavigationBarColor * Perform version check when setting crop activity status bar color * Suppress DEPRECATION in WidgetUtils.kt * Added strict mode comment * Rename .java to .kt * Convert WordPressDebug to Kotlin * Comment out enableStrictMode * Set uCrop status bar color based on SDK version * Use fun setWindowBarColor to set either status or navBar colors * Added recommended changes to SignatureUtils * Added detectUnsafeIntentLaunch() to strict mode
- Loading branch information
Showing
16 changed files
with
136 additions
and
155 deletions.
There are no files selected for viewing
47 changes: 0 additions & 47 deletions
47
WordPress/src/debug/java/org/wordpress/android/WordPressDebug.java
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
WordPress/src/debug/java/org/wordpress/android/WordPressDebug.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,57 @@ | ||
package org.wordpress.android | ||
|
||
import android.os.Build | ||
import android.os.StrictMode | ||
import android.os.StrictMode.ThreadPolicy | ||
import android.os.StrictMode.VmPolicy | ||
import dagger.hilt.android.HiltAndroidApp | ||
import org.wordpress.android.util.AppLog | ||
|
||
@HiltAndroidApp | ||
class WordPressDebug : WordPressApp() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
// enableStrictMode() | ||
} | ||
|
||
/** | ||
* enables "strict mode" for testing - should NEVER be used in release builds | ||
*/ | ||
private fun enableStrictMode() { | ||
// return if the build is not a debug build | ||
if (!BuildConfig.DEBUG) { | ||
AppLog.e(AppLog.T.UTILS, "You should not call enableStrictMode() on a non debug build") | ||
return | ||
} | ||
|
||
StrictMode.setThreadPolicy( | ||
ThreadPolicy.Builder() | ||
.detectDiskReads() | ||
.detectDiskWrites() | ||
.detectNetwork() | ||
.penaltyLog() | ||
.penaltyFlashScreen() | ||
.build() | ||
) | ||
|
||
StrictMode.setVmPolicy( | ||
VmPolicy.Builder() | ||
.detectActivityLeaks() | ||
.detectLeakedSqlLiteObjects() | ||
.detectLeakedClosableObjects() | ||
.detectLeakedRegistrationObjects() | ||
.penaltyLog() | ||
.apply { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
detectNonSdkApiUsage() | ||
} | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
detectUnsafeIntentLaunch() | ||
} | ||
} | ||
.build() | ||
) | ||
|
||
AppLog.w(AppLog.T.UTILS, "Strict mode enabled") | ||
} | ||
} |
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
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
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
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
99 changes: 40 additions & 59 deletions
99
WordPress/src/main/java/org/wordpress/android/util/extensions/WindowExtensions.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,78 +1,59 @@ | ||
package org.wordpress.android.util.extensions | ||
|
||
import android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | ||
import android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE | ||
import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | ||
import android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | ||
import android.os.Build | ||
import android.view.Window | ||
import androidx.core.content.ContextCompat | ||
import android.view.WindowInsets | ||
import androidx.core.view.WindowCompat | ||
import androidx.core.view.WindowInsetsControllerCompat | ||
import org.wordpress.android.util.ColorUtils | ||
import android.R as AndroidR | ||
import com.google.android.material.R as MaterialR | ||
|
||
@Suppress("DEPRECATION") | ||
fun Window.setLightStatusBar(showInLightMode: Boolean) { | ||
if (isLightTheme()) { | ||
decorView.systemUiVisibility = decorView.systemUiVisibility.let { | ||
if (showInLightMode) { | ||
it or SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | ||
} else { | ||
it and SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Suppress("DEPRECATION") | ||
fun Window.setLightNavigationBar(showInLightMode: Boolean, applyDefaultColors: Boolean = false) { | ||
if (isLightTheme()) { | ||
decorView.systemUiVisibility = decorView.systemUiVisibility.let { | ||
if (showInLightMode) { | ||
it or SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | ||
} else { | ||
it and SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv() | ||
} | ||
} | ||
if (applyDefaultColors) { | ||
navigationBarColor = if (showInLightMode) { | ||
context.getColorFromAttribute(MaterialR.attr.colorSurface) | ||
} else { | ||
ContextCompat.getColor(context, AndroidR.color.black) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun Window.setEdgeToEdgeContentDisplay(isEnabled: Boolean) { | ||
val decorFitsSystemWindows = !isEnabled | ||
WindowCompat.setDecorFitsSystemWindows(this, decorFitsSystemWindows) | ||
} | ||
|
||
@Suppress("DEPRECATION") | ||
fun Window.showFullScreen() { | ||
decorView.systemUiVisibility = decorView.systemUiVisibility.let { | ||
it or SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or SYSTEM_UI_FLAG_LAYOUT_STABLE | ||
} | ||
} | ||
|
||
fun Window.setWindowStatusBarColor(color: Int) { | ||
val windowInsetsController = WindowInsetsControllerCompat(this, decorView) | ||
|
||
statusBarColor = color | ||
windowInsetsController.isAppearanceLightStatusBars = ColorUtils.isColorLight(statusBarColor) | ||
|
||
// we need to set the light navigation appearance here because, for some reason, changing the status bar also | ||
// changes the navigation bar appearance but this method is supposed to only change the status bar | ||
windowInsetsController.isAppearanceLightNavigationBars = ColorUtils.isColorLight(navigationBarColor) | ||
setWindowBarColor(color, InsetsType.STATUS_BAR) | ||
} | ||
|
||
fun Window.setWindowNavigationBarColor(color: Int) { | ||
val windowInsetsController = WindowInsetsControllerCompat(this, decorView) | ||
setWindowBarColor(color, InsetsType.NAVIGATION_BAR) | ||
} | ||
|
||
navigationBarColor = color | ||
windowInsetsController.isAppearanceLightNavigationBars = ColorUtils.isColorLight(navigationBarColor) | ||
/** | ||
* Sets the status bar or navigation bar color | ||
* TODO Setting both the status bar color and navigation bar color causes the insets to be set twice | ||
*/ | ||
@Suppress("DEPRECATION") | ||
private fun Window.setWindowBarColor(color: Int, insetsType: InsetsType) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { | ||
// Android 15+ | ||
decorView.setOnApplyWindowInsetsListener { view, insets -> | ||
view.setBackgroundColor(color) | ||
val barInsets = insets.getInsets( | ||
when (insetsType) { | ||
InsetsType.STATUS_BAR -> WindowInsets.Type.statusBars() | ||
InsetsType.NAVIGATION_BAR -> WindowInsets.Type.navigationBars() | ||
} | ||
) | ||
// Adjust padding to avoid overlap | ||
view.setPadding(0, barInsets.top, 0, 0) | ||
insets | ||
} | ||
} else { | ||
when(insetsType) { | ||
InsetsType.STATUS_BAR -> statusBarColor = color | ||
InsetsType.NAVIGATION_BAR -> navigationBarColor = color | ||
} | ||
val windowInsetsController = WindowInsetsControllerCompat(this, decorView) | ||
if (insetsType == InsetsType.STATUS_BAR) { | ||
windowInsetsController.isAppearanceLightStatusBars = ColorUtils.isColorLight(statusBarColor) | ||
} | ||
windowInsetsController.isAppearanceLightNavigationBars = ColorUtils.isColorLight(navigationBarColor) | ||
} | ||
} | ||
|
||
private fun Window.isLightTheme() = !context.resources.configuration.isDarkTheme() | ||
private enum class InsetsType { | ||
STATUS_BAR, | ||
NAVIGATION_BAR | ||
} |
Oops, something went wrong.