6.6.2 - Alpha7 - 新增 ui.statusBarHeight 属性 (getter) (issue #357)
This commit is contained in:
@@ -14,6 +14,8 @@ import android.view.MenuItem
|
||||
import android.view.MotionEvent
|
||||
import android.view.WindowManager
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
import androidx.core.view.isNotEmpty
|
||||
import org.autojs.autojs.AbstractAutoJs.Companion.isInrt
|
||||
import org.autojs.autojs.annotation.ScriptInterface
|
||||
import org.autojs.autojs.core.eventloop.EventEmitter
|
||||
@@ -65,7 +67,7 @@ class ScriptExecuteActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val windowBackground: Drawable = window.decorView.background
|
||||
?: ColorDrawable(getColor(R.color.md_gray_50)).also { window.setBackgroundDrawable(it) }
|
||||
?: getColor(R.color.md_gray_50).toDrawable().also { window.setBackgroundDrawable(it) }
|
||||
|
||||
if (windowBackground is ColorDrawable) windowBackground.color.let { backgroundColor ->
|
||||
val isLightColor = ViewUtils.isLuminanceDark(backgroundColor)
|
||||
@@ -220,7 +222,7 @@ class ScriptExecuteActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
emit("create_options_menu", menu)
|
||||
return menu.size() > 0
|
||||
return menu.isNotEmpty()
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.autojs.autojs.runtime.api.augment.ui
|
||||
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Build
|
||||
import android.view.ContextThemeWrapper
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
import org.autojs.autojs.annotation.RhinoFunctionBody
|
||||
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
|
||||
import org.autojs.autojs.core.ui.JsViewHelper
|
||||
@@ -131,6 +131,9 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
val activity = getActivity(scriptRuntime)
|
||||
(activity as? ScriptExecuteActivity)?.eventEmitter
|
||||
},
|
||||
"statusBarHeight" to Supplier {
|
||||
ViewUtils.getStatusBarHeightByDimen(globalContext)
|
||||
}
|
||||
)
|
||||
|
||||
init {
|
||||
@@ -555,7 +558,7 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
ensureActivity(scriptRuntime) { activity ->
|
||||
runRhinoRuntime(scriptRuntime, newBaseFunction("action", {
|
||||
Colors.toIntRhino(Colors.setAlphaRhino(color, 1.0)).also {
|
||||
activity.window.setBackgroundDrawable(ColorDrawable(it))
|
||||
activity.window.setBackgroundDrawable(it.toDrawable())
|
||||
}
|
||||
}, NOT_CONSTRUCTABLE))
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ open class LayoutBoundsView : View {
|
||||
|
||||
init {
|
||||
this.setWillNotDraw(false)
|
||||
statusBarHeight = ViewUtils.getStatusBarHeight(context)
|
||||
statusBarHeight = ViewUtils.getStatusBarHeightByWindow(context)
|
||||
}
|
||||
|
||||
fun setOnNodeInfoSelectListener(onNodeInfoSelectListener: OnNodeInfoSelectListener?) {
|
||||
|
||||
@@ -155,7 +155,7 @@ public class LayoutHierarchyView extends MultiLevelListView {
|
||||
mPaint.setStyle(Paint.Style.STROKE);
|
||||
mPaint.setAntiAlias(true);
|
||||
mPaint.setStrokeWidth(3);
|
||||
mStatusBarHeight = ViewUtils.getStatusBarHeight(getContext());
|
||||
mStatusBarHeight = ViewUtils.getStatusBarHeightByWindow(getContext());
|
||||
}
|
||||
|
||||
public Paint getBoundsPaint() {
|
||||
|
||||
@@ -9,8 +9,6 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.marginBottom
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
@@ -50,8 +48,6 @@ class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickListen
|
||||
private var mFloatingActionMenu: FloatingActionMenu? = null
|
||||
private var mIsCurrentPageFiles = false
|
||||
|
||||
private var mBottomInset: Int = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
EventBus.getDefault().register(this)
|
||||
@@ -63,10 +59,6 @@ class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickListen
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
|
||||
mBottomInset = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom
|
||||
insets
|
||||
}
|
||||
mExplorerView = binding.itemList.also { explorerView ->
|
||||
explorerView.setOnItemClickListener(object : ExplorerView.OnItemClickListener {
|
||||
override fun onItemClick(view: View?, item: ExplorerItem) {
|
||||
|
||||
@@ -48,6 +48,8 @@ import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.util.StringUtils.key
|
||||
import org.autojs.autojs6.R
|
||||
import kotlin.math.roundToInt
|
||||
import androidx.core.view.size
|
||||
import androidx.core.view.get
|
||||
|
||||
/**
|
||||
* Created by Stardust on Jan 24, 2017.
|
||||
@@ -100,29 +102,40 @@ object ViewUtils {
|
||||
// ! 在一些设备上无法正常获取结果.
|
||||
// ! 参阅: https://github.com/hyb1996/Auto.js/issues/268
|
||||
@SuppressLint("InternalInsetResource", "DiscouragedApi")
|
||||
fun getStatusBarHeightLegacy(context: Context): Int {
|
||||
return context.resources.getIdentifier("status_bar_height", "dimen", "android").let { resourceId ->
|
||||
when (resourceId > 0) {
|
||||
true -> context.resources.getDimensionPixelSize(resourceId)
|
||||
else -> 0
|
||||
}
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun getStatusBarHeightByDimen(context: Context, withFallback: Boolean = true): Int {
|
||||
val resourceId = context.resources.getIdentifier("status_bar_height", "dimen", "android")
|
||||
val dimenStatusBarHeight = when (resourceId > 0) {
|
||||
true -> context.resources.getDimensionPixelSize(resourceId)
|
||||
else -> 0
|
||||
}
|
||||
return when {
|
||||
dimenStatusBarHeight > 0 -> dimenStatusBarHeight
|
||||
withFallback -> TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24f, context.resources.displayMetrics).toInt()
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getStatusBarHeight(context: Context): Int {
|
||||
return getWindowForContext(context)?.let { window ->
|
||||
Rect().let { rect ->
|
||||
window.decorView.getWindowVisibleDisplayFrame(rect)
|
||||
rect.top.takeIf { it >= 0 }
|
||||
}
|
||||
} ?: TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24f, context.resources.displayMetrics).toInt()
|
||||
@JvmOverloads
|
||||
fun getStatusBarHeightByWindow(context: Context, withFallback: Boolean = true): Int {
|
||||
val windowStatusBarHeight = getWindowForContext(context)?.decorView?.let { decorView ->
|
||||
Rect().also { rect ->
|
||||
decorView.getWindowVisibleDisplayFrame(rect)
|
||||
}.top
|
||||
} ?: 0
|
||||
return when {
|
||||
windowStatusBarHeight > 0 -> windowStatusBarHeight
|
||||
withFallback -> TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24f, context.resources.displayMetrics).toInt()
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
fun getTitleBarHeight(context: Context): Int {
|
||||
val window = getWindowForContext(context)
|
||||
val contentViewTop = window?.findViewById<View>(Window.ID_ANDROID_CONTENT)?.top ?: 0
|
||||
return contentViewTop - getStatusBarHeight(context)
|
||||
return contentViewTop - getStatusBarHeightByWindow(context)
|
||||
}
|
||||
|
||||
fun getScreenHeight(activity: Activity) = DisplayMetrics().let { metrics ->
|
||||
@@ -415,8 +428,8 @@ object ViewUtils {
|
||||
}
|
||||
|
||||
fun Menu.setItemsColor(color: Int) {
|
||||
for (i in 0 until size()) {
|
||||
val menuItem = getItem(i)
|
||||
for (i in 0 until size) {
|
||||
val menuItem = this[i]
|
||||
menuItem.icon = menuItem.icon?.applyColorFilterWith(color)
|
||||
menuItem.subMenu?.setItemsColor(color)
|
||||
}
|
||||
@@ -471,11 +484,7 @@ object ViewUtils {
|
||||
val view = this
|
||||
val viewTreeObserver = view.viewTreeObserver
|
||||
if (viewTreeObserver.isAlive) {
|
||||
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
listener.invoke()
|
||||
}
|
||||
})
|
||||
viewTreeObserver.addOnGlobalLayoutListener { listener.invoke() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,7 +517,7 @@ object ViewUtils {
|
||||
val fullColor = context.getColor(if (isAimColorLight) R.color.day_full else R.color.night_full)
|
||||
val hintColor = context.getColor(if (isAimColorLight) R.color.day_alpha_70 else R.color.night_alpha_70)
|
||||
|
||||
findViewById<EditText?>(androidx.appcompat.R.id.search_src_text).apply {
|
||||
findViewById<EditText?>(androidx.appcompat.R.id.search_src_text)?.apply {
|
||||
setTextColor(fullColor)
|
||||
setHintTextColor(hintColor)
|
||||
setLinkTextColor(fullColor)
|
||||
|
||||
Reference in New Issue
Block a user