6.6.4 - Alpha2 - API 变更: ui.(status/navigation)BarAppearanceLight[By] -> ui.(status/navigation)BarIconLight[By]
This commit is contained in:
@@ -19,10 +19,10 @@ setTimeout(() => {
|
||||
ui.backgroundColor(themeColor);
|
||||
|
||||
ui.statusBarColor(themeColor);
|
||||
ui.statusBarAppearanceLightBy(themeColor);
|
||||
ui.statusBarIconLightBy(themeColor);
|
||||
|
||||
ui.navigationBarColor(themeColor);
|
||||
ui.navigationBarAppearanceLightBy(themeColor);
|
||||
ui.navigationBarIconLightBy(themeColor);
|
||||
|
||||
/** @type {JsTextClock} */
|
||||
let textClockView = ui['text_clock'];
|
||||
|
||||
@@ -80,10 +80,10 @@ class ScriptExecuteActivity : AppCompatActivity(), OnActivityResultDelegate.Dele
|
||||
if (windowBackground is ColorDrawable) windowBackground.color.let { backgroundColor ->
|
||||
val isLightColor = ViewUtils.isLuminanceDark(backgroundColor)
|
||||
ViewUtils.setStatusBarBackgroundColor(this, backgroundColor)
|
||||
ViewUtils.setStatusBarAppearanceLight(this, isLightColor)
|
||||
ViewUtils.setStatusBarIconLight(this, isLightColor)
|
||||
ViewUtils.setNavigationBarBackgroundColor(this, backgroundColor)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
ViewUtils.setNavigationBarAppearanceLight(this, isLightColor)
|
||||
ViewUtils.setNavigationBarIconLight(this, isLightColor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,12 +114,12 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
::registerWidget.name,
|
||||
::setContentView.name,
|
||||
::statusBarColor.name,
|
||||
::statusBarAppearanceLight.name,
|
||||
::statusBarAppearanceLightBy.name,
|
||||
::statusBarIconLight.name,
|
||||
::statusBarIconLightBy.name,
|
||||
::backgroundColor.name,
|
||||
::navigationBarColor.name,
|
||||
::navigationBarAppearanceLight.name,
|
||||
::navigationBarAppearanceLightBy.name,
|
||||
::navigationBarIconLight.name,
|
||||
::navigationBarIconLightBy.name,
|
||||
::findById.name,
|
||||
::findByStringId.name,
|
||||
::findView.name,
|
||||
@@ -539,11 +539,11 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
|
||||
@JvmStatic
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun statusBarAppearanceLight(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsAtMost(args, 1) { argList ->
|
||||
fun statusBarIconLight(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsAtMost(args, 1) { argList ->
|
||||
val (isLight) = argList
|
||||
ensureActivity(scriptRuntime) { activity ->
|
||||
runRhinoRuntime(scriptRuntime, newBaseFunction("action", {
|
||||
ViewUtils.setStatusBarAppearanceLight(activity, coerceBoolean(isLight, true))
|
||||
ViewUtils.setStatusBarIconLight(activity, coerceBoolean(isLight, true))
|
||||
}, NOT_CONSTRUCTABLE))
|
||||
}
|
||||
UNDEFINED
|
||||
@@ -551,10 +551,10 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
|
||||
@JvmStatic
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun statusBarAppearanceLightBy(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsOnlyOne(args) { refColor ->
|
||||
fun statusBarIconLightBy(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsOnlyOne(args) { refColor ->
|
||||
ensureActivity(scriptRuntime) { activity ->
|
||||
runRhinoRuntime(scriptRuntime, newBaseFunction("action", {
|
||||
Colors.toIntRhino(refColor).also { ViewUtils.setStatusBarAppearanceLight(activity, ViewUtils.isLuminanceDark(it)) }
|
||||
Colors.toIntRhino(refColor).also { ViewUtils.setStatusBarIconLight(activity, ViewUtils.isLuminanceDark(it)) }
|
||||
}, NOT_CONSTRUCTABLE))
|
||||
}
|
||||
UNDEFINED
|
||||
@@ -586,14 +586,14 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
|
||||
@JvmStatic
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun navigationBarAppearanceLight(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsAtMost(args, 1) { argList ->
|
||||
fun navigationBarIconLight(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsAtMost(args, 1) { argList ->
|
||||
val (isLight) = argList
|
||||
ensureActivity(scriptRuntime) { activity ->
|
||||
runRhinoRuntime(scriptRuntime, newBaseFunction("action", {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
ScriptRuntime.requiresApi(Build.VERSION_CODES.O)
|
||||
} else {
|
||||
ViewUtils.setNavigationBarAppearanceLight(activity, coerceBoolean(isLight, true))
|
||||
ViewUtils.setNavigationBarIconLight(activity, coerceBoolean(isLight, true))
|
||||
}
|
||||
}, NOT_CONSTRUCTABLE))
|
||||
}
|
||||
@@ -602,14 +602,14 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
|
||||
@JvmStatic
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun navigationBarAppearanceLightBy(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsOnlyOne(args) { refColor ->
|
||||
fun navigationBarIconLightBy(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Undefined = ensureArgumentsOnlyOne(args) { refColor ->
|
||||
ensureActivity(scriptRuntime) { activity ->
|
||||
runRhinoRuntime(scriptRuntime, newBaseFunction("action", {
|
||||
Colors.toIntRhino(refColor).also {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
ScriptRuntime.requiresApi(Build.VERSION_CODES.O)
|
||||
} else {
|
||||
ViewUtils.setNavigationBarAppearanceLight(activity, ViewUtils.isLuminanceDark(it))
|
||||
ViewUtils.setNavigationBarIconLight(activity, ViewUtils.isLuminanceDark(it))
|
||||
}
|
||||
}
|
||||
}, NOT_CONSTRUCTABLE))
|
||||
|
||||
@@ -100,8 +100,8 @@ object ThemeColorManager {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setStatusBarAppearanceLight(activity: Activity) {
|
||||
ViewUtils.setStatusBarAppearanceLight(activity, isLuminanceDark())
|
||||
fun setStatusBarIconLight(activity: Activity) {
|
||||
ViewUtils.setStatusBarIconLight(activity, isLuminanceDark())
|
||||
}
|
||||
|
||||
private object BackgroundColorManager {
|
||||
|
||||
@@ -37,7 +37,7 @@ class ColorSearchHelpActivity : BaseActivity() {
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
setUpStatusBarAppearanceLightByNightMode()
|
||||
setUpStatusBarIconLightByNightMode()
|
||||
}
|
||||
|
||||
private fun getContent(contentResourceId: Int) = runCatching {
|
||||
|
||||
@@ -145,7 +145,7 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
|
||||
super.initThemeColors()
|
||||
updateToolbarColors()
|
||||
updateSearchViewColors()
|
||||
ViewUtils.setStatusBarAppearanceLightByColorLuminance(this, currentColor)
|
||||
ViewUtils.setStatusBarIconLightByColorLuminance(this, currentColor)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
|
||||
@@ -48,7 +48,7 @@ abstract class BaseActivity : AppCompatActivity() {
|
||||
initThemeColors()
|
||||
if (handleStatusBarThemeColorAutomatically) {
|
||||
ThemeColorManager.setStatusBarBackgroundColor(this)
|
||||
setUpStatusBarAppearanceLightByThemeColor()
|
||||
setUpStatusBarIconLightByThemeColor()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ abstract class BaseActivity : AppCompatActivity() {
|
||||
initThemeColors()
|
||||
if (handleStatusBarThemeColorAutomatically) {
|
||||
ThemeColorManager.addActivityStatusBar(this)
|
||||
setUpStatusBarAppearanceLightByThemeColor()
|
||||
setUpStatusBarIconLightByThemeColor()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,12 +92,12 @@ abstract class BaseActivity : AppCompatActivity() {
|
||||
|
||||
fun setToolbarAsBack(title: String?) = ViewUtils.setToolbarAsBack(this, title)
|
||||
|
||||
protected fun setUpStatusBarAppearanceLightByNightMode() {
|
||||
ViewUtils.setStatusBarAppearanceLight(this, ViewUtils.isNightModeEnabled)
|
||||
protected fun setUpStatusBarIconLightByNightMode() {
|
||||
ViewUtils.setStatusBarIconLight(this, ViewUtils.isNightModeEnabled)
|
||||
}
|
||||
|
||||
protected fun setUpStatusBarAppearanceLightByThemeColor() {
|
||||
ThemeColorManager.setStatusBarAppearanceLight(this)
|
||||
protected fun setUpStatusBarIconLightByThemeColor() {
|
||||
ThemeColorManager.setStatusBarIconLight(this)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class DocumentationActivity : BaseActivity() {
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
setUpStatusBarAppearanceLightByNightMode()
|
||||
setUpStatusBarIconLightByNightMode()
|
||||
}
|
||||
|
||||
@SuppressLint("MissingSuperCall")
|
||||
|
||||
@@ -758,7 +758,7 @@ class EditorView : LinearLayout, OnHintClickListener, ClickCallback, ToolbarFrag
|
||||
|
||||
private val TAG = EditorView::class.java.simpleName
|
||||
|
||||
private const val MIN_CONFIDENCE_TO_WRITE_FILE = 60
|
||||
private const val MIN_CONFIDENCE_TO_WRITE_FILE = 90
|
||||
private val DEFAULT_CHARSET_TO_WRITE_FILE = StandardCharsets.UTF_8
|
||||
|
||||
const val EXTRA_PATH = "path"
|
||||
|
||||
@@ -199,8 +199,8 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
// ! zh-CN:
|
||||
// ! 此处改为中间值 (如 `slideOffset < 0.5`) 会带来更好的通知栏亮暗色转换视觉体验,
|
||||
// ! 但会造成抽屉视图滑动时出现些微卡顿.
|
||||
slideOffset < 1 -> setUpStatusBarAppearanceLightByThemeColor()
|
||||
else -> setUpStatusBarAppearanceLightByNightMode()
|
||||
slideOffset < 1 -> setUpStatusBarIconLightByThemeColor()
|
||||
else -> setUpStatusBarIconLightByNightMode()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,13 +258,13 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
super.initThemeColors()
|
||||
setUpToolbarColors()
|
||||
setUpTabLayoutColors()
|
||||
setUpStatusBarAppearanceLight()
|
||||
setUpStatusBarIconLight()
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
if (hasFocus) {
|
||||
setUpStatusBarAppearanceLight()
|
||||
setUpStatusBarIconLight()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,12 +294,12 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
mTab.setSelectedTabIndicatorColor(tabSelectedIndicatorColor)
|
||||
}
|
||||
|
||||
private fun setUpStatusBarAppearanceLight() {
|
||||
private fun setUpStatusBarIconLight() {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
if (sIsActionBarDrawerOpened) {
|
||||
setUpStatusBarAppearanceLightByNightMode()
|
||||
setUpStatusBarIconLightByNightMode()
|
||||
} else {
|
||||
setUpStatusBarAppearanceLightByThemeColor()
|
||||
setUpStatusBarIconLightByThemeColor()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ abstract class BaseDisplayContentActivity : BaseActivity() {
|
||||
internalFabView = binding.fab.apply {
|
||||
if (internalMenuResource > 0) {
|
||||
setOnClickListener { view -> showPopupMenu(view, internalTextView) }
|
||||
ViewUtils.excludeFloatingActionButtonFromNavigationBar(this)
|
||||
ViewUtils.excludeFloatingActionButtonFromBottomNavigationBar(this)
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,7 @@ abstract class BaseDisplayContentActivity : BaseActivity() {
|
||||
val scaleGestureDetector = ScaleGestureDetector(this, ScaleListener(internalTextView))
|
||||
|
||||
val innerScrollView = binding.innerScrollView.also {
|
||||
ViewUtils.excludePaddingClippableViewFromBottomNavigationBar(it)
|
||||
it.setOnTouchListener { view, event ->
|
||||
when (event.pointerCount) {
|
||||
2 -> {
|
||||
@@ -118,7 +119,6 @@ abstract class BaseDisplayContentActivity : BaseActivity() {
|
||||
else -> super.onTouchEvent(event)
|
||||
}
|
||||
}
|
||||
ViewUtils.excludePaddingClippableViewFromNavigationBar(it)
|
||||
}
|
||||
|
||||
// 使用协程加载内容
|
||||
@@ -148,12 +148,12 @@ abstract class BaseDisplayContentActivity : BaseActivity() {
|
||||
internalFabView.backgroundTintList = ColorStateList.valueOf(themeColorNight)
|
||||
internalFabView.imageTintList = ColorStateList.valueOf(if (ViewUtils.isLuminanceDark(themeColorNight)) getColor(R.color.night) else getColor(R.color.day))
|
||||
ViewUtils.setStatusBarBackgroundColor(this, themeColorNight)
|
||||
ViewUtils.setStatusBarAppearanceLight(this, ViewUtils.isLuminanceDark(themeColorNight))
|
||||
ViewUtils.setStatusBarIconLight(this, ViewUtils.isLuminanceDark(themeColorNight))
|
||||
} else {
|
||||
internalFabView.backgroundTintList = ColorStateList.valueOf(themeColorDay)
|
||||
internalFabView.imageTintList = ColorStateList.valueOf(if (ViewUtils.isLuminanceDark(themeColorDay)) getColor(R.color.night) else getColor(R.color.day))
|
||||
ViewUtils.setStatusBarBackgroundColor(this, themeColorDay)
|
||||
ViewUtils.setStatusBarAppearanceLight(this, ViewUtils.isLuminanceDark(themeColorDay))
|
||||
ViewUtils.setStatusBarIconLight(this, ViewUtils.isLuminanceDark(themeColorDay))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ object StringUtils {
|
||||
@JvmStatic
|
||||
fun detectCharset(bytes: ByteArray): CharsetMatchWrapper {
|
||||
val matches = kotlin.runCatching {
|
||||
CharsetDetector().apply { setText(bytes) }.detectAll()
|
||||
CharsetDetector().apply { setText(bytes).setDeclaredEncoding("UTF-8") }.detectAll()
|
||||
}.getOrNull() ?: return CharsetMatchWrapper(null)
|
||||
|
||||
matches.firstOrNull {
|
||||
|
||||
@@ -35,7 +35,6 @@ import android.widget.ImageView
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.appcompat.widget.SearchView
|
||||
@@ -215,28 +214,22 @@ object ViewUtils {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isStatusBarAppearanceLight(activity: Activity): Boolean {
|
||||
return !isStatusBarAppearanceDark(activity)
|
||||
fun isStatusBarIconLight(activity: Activity): Boolean {
|
||||
return !WindowInsetsControllerCompat(activity.window, activity.window.decorView).isAppearanceLightStatusBars
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isStatusBarAppearanceDark(activity: Activity): Boolean {
|
||||
@Suppress("DEPRECATION")
|
||||
return hasSystemUiVisibility(activity, View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
|
||||
fun isStatusBarIconDark(activity: Activity): Boolean {
|
||||
return !isStatusBarIconLight(activity)
|
||||
}
|
||||
|
||||
fun setStatusBarAppearanceLight(activity: Activity, isLight: Boolean) {
|
||||
@Suppress("DEPRECATION")
|
||||
when {
|
||||
isStatusBarAppearanceLight(activity) == isLight -> return
|
||||
isLight -> removeSystemUiVisibility(activity, View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
|
||||
else -> appendSystemUiVisibility(activity, View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
|
||||
}
|
||||
fun setStatusBarIconLight(activity: Activity, isLight: Boolean) {
|
||||
WindowInsetsControllerCompat(activity.window, activity.window.decorView).isAppearanceLightStatusBars = !isLight
|
||||
}
|
||||
|
||||
fun setStatusBarAppearanceLightByColorLuminance(activity: Activity, @ColorInt aimColor: Int) {
|
||||
val shouldBeLight = isLuminanceDark(aimColor)
|
||||
setStatusBarAppearanceLight(activity, shouldBeLight)
|
||||
fun setStatusBarIconLightByColorLuminance(activity: Activity, @ColorInt referenceBackgroundColor: Int) {
|
||||
val shouldBeLight = isLuminanceDark(referenceBackgroundColor)
|
||||
setStatusBarIconLight(activity, shouldBeLight)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -276,27 +269,23 @@ object ViewUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
@JvmStatic
|
||||
fun isNavigationBarAppearanceLight(activity: Activity): Boolean {
|
||||
return !isNavigationBarAppearanceDark(activity)
|
||||
fun isNavigationBarIconLight(activity: Activity): Boolean {
|
||||
return !WindowInsetsControllerCompat(activity.window, activity.window.decorView).isAppearanceLightNavigationBars
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
@JvmStatic
|
||||
fun isNavigationBarAppearanceDark(activity: Activity): Boolean {
|
||||
@Suppress("DEPRECATION")
|
||||
return hasSystemUiVisibility(activity, View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR)
|
||||
fun isNavigationBarIconDark(activity: Activity): Boolean {
|
||||
return !isNavigationBarIconLight(activity)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
fun setNavigationBarAppearanceLight(activity: Activity, isLight: Boolean) {
|
||||
@Suppress("DEPRECATION")
|
||||
when {
|
||||
isNavigationBarAppearanceLight(activity) == isLight -> return
|
||||
isLight -> removeSystemUiVisibility(activity, View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR)
|
||||
else -> appendSystemUiVisibility(activity, View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR)
|
||||
}
|
||||
fun setNavigationBarIconLight(activity: Activity, isLight: Boolean) {
|
||||
WindowInsetsControllerCompat(activity.window, activity.window.decorView).isAppearanceLightNavigationBars = isLight
|
||||
}
|
||||
|
||||
fun setNavigationBarIconLightByColorLuminance(activity: Activity, @ColorInt referenceBackgroundColor: Int) {
|
||||
val shouldBeLight = isLuminanceDark(referenceBackgroundColor)
|
||||
setNavigationBarIconLight(activity, shouldBeLight)
|
||||
}
|
||||
|
||||
fun setNavigationBarBackgroundColor(activity: Activity, color: Int) {
|
||||
@@ -365,11 +354,10 @@ object ViewUtils {
|
||||
|
||||
fun makeBarsAdaptToNightMode(activity: AppCompatActivity) {
|
||||
val isConfigDark = isNightModeYes(activity)
|
||||
val isConfigTakenAsLight = !isConfigDark
|
||||
|
||||
getWindowInsetsController(activity).apply {
|
||||
isAppearanceLightStatusBars = isConfigTakenAsLight
|
||||
isAppearanceLightNavigationBars = isConfigTakenAsLight
|
||||
isAppearanceLightStatusBars = isConfigDark
|
||||
isAppearanceLightNavigationBars = isConfigDark
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user