Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ compileSdk = "34"
buildTools = "34.0.0"

agp = "8.6.0"
androidXActivity = "1.9.0"
androidXCore = "1.6.0"
androidXLifecycle = "2.8.7"
detekt = "1.19.0"
Expand Down Expand Up @@ -42,6 +43,7 @@ maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPubli

[libraries]

androidx-activity = { module = "androidx.activity:activity-ktx", version.ref = "androidXActivity" }
androidx-annotation = { module = "androidx.annotation:annotation", version = "1.4.0" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version = "1.4.0" }
androidx-browser = { module = "androidx.browser:browser", version = "1.4.0" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/pluto___white"
android:fitsSystemWindows="true">
android:background="@color/pluto___white">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/container"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/pluto___white"
android:fitsSystemWindows="true">
android:background="@color/pluto___white">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/container"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import android.os.Bundle
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
Expand All @@ -31,11 +29,6 @@ internal class ViewInfoFragment : Fragment(R.layout.pluto_li___fragment_view_inf

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, insets ->
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
binding.bsContainer.previewPanelBottomSheet.setPadding(0, 0, 0, systemBarsInsets.bottom)
insets
}
ActivityLifecycle.topActivity?.let { binding.operableView.tryGetFrontView(it) }
binding.operableView.setOnClickListener(this)
binding.leftControls.initialise(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
Expand Down Expand Up @@ -49,8 +53,21 @@ internal class ViewHierarchyFragment : DialogFragment() {

override fun getTheme(): Int = R.style.PlutoLIFullScreenDialogStyle

override fun onStart() {
super.onStart()
dialog?.window?.let { WindowCompat.setDecorFitsSystemWindows(it, false) }
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val appBarContentInitialPaddingTop = binding.appBarContent.paddingTop
val listInitialPaddingBottom = binding.list.paddingBottom
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
binding.appBarContent.updatePadding(top = appBarContentInitialPaddingTop + insets.top)
binding.list.updatePadding(bottom = listInitialPaddingBottom + insets.bottom)
WindowInsetsCompat.CONSUMED
}
onBackPressed { findNavController().navigateUp() }
binding.close.setOnDebounceClickListener {
findNavController().navigateUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.view.View
import android.view.ViewConfiguration
import android.view.ViewGroup
import androidx.core.view.children
import androidx.core.view.doOnLayout
import com.pluto.plugins.layoutinspector.internal.inspect.canvas.CaptureCanvas
import com.pluto.plugins.layoutinspector.internal.inspect.canvas.DimensionCanvas
import com.pluto.plugins.layoutinspector.internal.inspect.canvas.GridCanvas
Expand Down Expand Up @@ -62,7 +63,15 @@ internal class InspectOverlay : View {
}

fun tryGetFrontView(targetActivity: Activity) {
traverse(targetActivity.getFrontView())
// Defer the view traversal until after this overlay has completed its own layout
// pass so that getLocationOnScreen() (called inside InspectedView.reset()) returns
// the correct screen position, not [0, 0]. doOnLayout fires synchronously when the
// view is already laid out, or on the next layout pass otherwise – covering both the
// "first launch" and "navigate-back" cases.
doOnLayout {
traverse(targetActivity.getFrontView())
invalidate()
}
}

override fun onTouchEvent(event: MotionEvent?): Boolean {
Expand Down Expand Up @@ -241,7 +250,9 @@ internal class InspectOverlay : View {

private fun traverse(view: View) {
if (view.alpha == 0f || view.visibility != VISIBLE) return
inspectedViews.add(InspectedView(view))
// Pass 'this' so InspectedView can dynamically compute the overlay's screen offset
// inside each reset() call, keeping all rects in overlay-local coordinates.
inspectedViews.add(InspectedView(view, this))
if (view is ViewGroup) {
view.children.forEach {
traverse(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@ package com.pluto.plugins.layoutinspector.internal.inspect
import android.graphics.Rect
import android.view.View

internal class InspectedView(val view: View) {
/**
* Wraps an inspected [view] and maintains a [rect] in **overlay-local coordinates**
* (i.e. relative to the top-left of [InspectOverlay]) so that hit-testing and canvas
* drawing are both correct regardless of whether the host (Pluto) activity is running
* edge-to-edge or not.
*
* @param overlay The [InspectOverlay] view. Its current screen position is subtracted
* from [view]'s screen position inside every [reset] call, so the stored [rect] is
* always in overlay-local space even after window-inset changes.
*/
internal class InspectedView(val view: View, private val overlay: View? = null) {

private val originRect: Rect = Rect()
val rect: Rect = Rect()
private val location = IntArray(2)
private val overlayLoc = IntArray(2)

val parent: InspectedView?
get() {
val parentView: Any = view.parent
return if (parentView is View) {
InspectedView(parentView)
InspectedView(parentView, overlay)
} else {
null
}
Expand All @@ -24,10 +36,16 @@ internal class InspectedView(val view: View) {
}

fun reset() {
// Always recompute the overlay's position so this works correctly even if called
// before the first layout pass (overlayLoc will just be [0,0] then, harmlessly).
overlay?.getLocationOnScreen(overlayLoc)
view.getLocationOnScreen(location)
val left = location[0]
// Subtract the overlay's screen offset → rect is in overlay-local space.
// This cancels out the status-bar (and/or action-bar) offset introduced by the
// Pluto activity's paddingTop when edge-to-edge is enabled.
val left = location[0] - overlayLoc[0]
val right = left + view.width
val top = location[1]
val top = location[1] - overlayLoc[1]
val bottom = top + view.height
rect.set(left, top, right, bottom)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/pluto___white">

<com.google.android.material.appbar.AppBarLayout
Expand All @@ -13,6 +12,7 @@
android:theme="@style/PlutoTheme.AppBarOverlay">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/appBarContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
android:layout_height="wrap_content">

<com.pluto.plugins.layoutinspector.internal.control.ControlsWidget
android:id="@+id/leftControls"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
<item name="android:windowFullscreen">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/pluto___white"
android:fitsSystemWindows="true">
android:background="@color/pluto___white">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/container"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/pluto___white"
android:fitsSystemWindows="true"
tools:context=".base.internal.NetworkFragment">

<androidx.fragment.app.FragmentContainerView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/pluto___white"
android:fitsSystemWindows="true">
android:background="@color/pluto___white">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/container"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/pluto___white"
android:fitsSystemWindows="true">
android:background="@color/pluto___white">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/container"
Expand Down
1 change: 1 addition & 0 deletions pluto/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ mavenPublishing {
dependencies {
api(project(":pluto-plugins:base:lib"))

implementation(libs.androidx.activity)
implementation(libs.androidx.core)
implementation(libs.androidx.appcompat)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package com.pluto.tool.modules.ruler
import android.os.Bundle
import android.view.View.GONE
import android.view.View.VISIBLE
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.pluto.R
import com.pluto.databinding.PlutoToolRulerActivityBinding
import com.pluto.tool.modules.ruler.internal.ControlsWidget
Expand All @@ -28,8 +32,21 @@ class RulerActivity : AppCompatActivity() {
*/
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
binding = PlutoToolRulerActivityBinding.inflate(layoutInflater)
setContentView(binding.root)
val controlsInitialTopMargin =
(binding.leftControls.layoutParams as? ConstraintLayout.LayoutParams)?.topMargin ?: 0
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
listOf(binding.leftControls, binding.rightControls).forEach { controls ->
(controls.layoutParams as? ConstraintLayout.LayoutParams)?.let { params ->
params.topMargin = controlsInitialTopMargin + insets.top
controls.layoutParams = params
}
}
WindowInsetsCompat.CONSUMED
}

// Add the ruler fragment to the container
supportFragmentManager.beginTransaction().apply {
Expand Down
22 changes: 11 additions & 11 deletions pluto/lib/src/main/java/com/pluto/ui/container/PlutoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.pluto.ui.container

import android.content.Intent
import android.os.Bundle
import android.view.WindowManager
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.WindowCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.lifecycle.Observer
import com.pluto.Pluto
import com.pluto.R
Expand Down Expand Up @@ -33,15 +34,14 @@ class PlutoActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
val binding = PlutoActivityPlutoBinding.inflate(layoutInflater)
setContentView(binding.root)
WindowCompat.setDecorFitsSystemWindows(window, false)
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = ContextCompat.getColor(this, com.pluto.plugin.R.color.pluto___dark)
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
v.updatePadding(top = insets.top, bottom = insets.bottom)
windowInsets
}
sharer.data.observe(this) {
val shareFragment = ShareFragment()
shareFragment.arguments = Bundle().apply {
Expand Down Expand Up @@ -110,7 +110,7 @@ class PlutoActivity : AppCompatActivity() {
// }
// }

override fun onNewIntent(intent: Intent?) {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
handleIntent(intent)
}
Expand Down
Loading
Loading