Remove warnings

Summary: Addresses a few warnings raised

Reviewed By: LukeDefeo

Differential Revision: D39430004

fbshipit-source-id: 877698e8515f08a5cb38b414689615c1b6e4b6cc
This commit is contained in:
Lorenzo Blasa
2022-09-12 08:17:39 -07:00
committed by Facebook GitHub Bot
parent 69812d543e
commit d999f68f62
8 changed files with 107 additions and 126 deletions

View File

@@ -13,30 +13,30 @@ import com.facebook.flipper.plugins.uidebugger.stetho.FragmentCompat
object ActivityDescriptor : AbstractChainedDescriptor<Activity>() {
override fun onGetId(activity: Activity): String {
return Integer.toString(System.identityHashCode(activity))
override fun onGetId(node: Activity): String {
return System.identityHashCode(node).toString()
}
override fun onGetName(activity: Activity): String {
return activity.javaClass.simpleName
override fun onGetName(node: Activity): String {
return node.javaClass.simpleName
}
override fun onGetChildren(activity: Activity, children: MutableList<Any>) {
activity.window?.let { window -> children.add(activity.window) }
override fun onGetChildren(node: Activity, children: MutableList<Any>) {
node.window?.let { window -> children.add(window) }
var fragments = getDialogFragments(FragmentCompat.supportInstance, activity)
var fragments = getDialogFragments(FragmentCompat.supportInstance, node)
for (fragment in fragments) {
children.add(fragment)
}
fragments = getDialogFragments(FragmentCompat.frameworkInstance, activity)
fragments = getDialogFragments(FragmentCompat.frameworkInstance, node)
for (fragment in fragments) {
children.add(fragment)
}
}
override fun onGetData(
activity: Activity,
node: Activity,
attributeSections: MutableMap<String, InspectableObject>
) {}

View File

@@ -13,22 +13,22 @@ import com.facebook.flipper.plugins.uidebugger.core.ApplicationRef
object ApplicationRefDescriptor : AbstractChainedDescriptor<ApplicationRef>() {
override fun onGetActiveChild(node: ApplicationRef): Any? {
return if (node.activitiesStack.size > 0) node.activitiesStack.last() else null
return if (node.activitiesStack.isNotEmpty()) node.activitiesStack.last() else null
}
override fun onGetId(applicationRef: ApplicationRef): String {
return applicationRef.application.packageName
override fun onGetId(node: ApplicationRef): String {
return node.application.packageName
}
override fun onGetName(applicationRef: ApplicationRef): String {
val applicationInfo = applicationRef.application.getApplicationInfo()
override fun onGetName(node: ApplicationRef): String {
val applicationInfo = node.application.applicationInfo
val stringId = applicationInfo.labelRes
return if (stringId == 0) applicationInfo.nonLocalizedLabel.toString()
else applicationRef.application.getString(stringId)
else node.application.getString(stringId)
}
override fun onGetChildren(applicationRef: ApplicationRef, children: MutableList<Any>) {
for (activity: Activity in applicationRef.activitiesStack) {
override fun onGetChildren(node: ApplicationRef, children: MutableList<Any>) {
for (activity: Activity in node.activitiesStack) {
children.add(activity)
}
}

View File

@@ -12,16 +12,13 @@ import com.facebook.flipper.plugins.uidebugger.common.InspectableObject
object ButtonDescriptor : AbstractChainedDescriptor<Button>() {
override fun onGetId(button: Button): String {
return Integer.toString(System.identityHashCode(button))
override fun onGetId(node: Button): String {
return System.identityHashCode(node).toString()
}
override fun onGetName(button: Button): String {
return button.javaClass.simpleName
override fun onGetName(node: Button): String {
return node.javaClass.simpleName
}
override fun onGetData(
button: Button,
attributeSections: MutableMap<String, InspectableObject>
) {}
override fun onGetData(node: Button, attributeSections: MutableMap<String, InspectableObject>) {}
}

View File

@@ -13,15 +13,15 @@ object ObjectDescriptor : Descriptor<Any>() {
override fun getActiveChild(node: Any): Any? = null
override fun getId(obj: Any): String {
return Integer.toString(System.identityHashCode(obj))
override fun getId(node: Any): String {
return System.identityHashCode(node).toString()
}
override fun getName(obj: Any): String {
return obj.javaClass.simpleName
override fun getName(node: Any): String {
return node.javaClass.simpleName
}
override fun getChildren(node: Any, children: MutableList<Any>) {}
override fun getData(obj: Any, builder: MutableMap<String, InspectableObject>) {}
override fun getData(node: Any, builder: MutableMap<String, InspectableObject>) {}
}

View File

@@ -12,16 +12,16 @@ import com.facebook.flipper.plugins.uidebugger.common.InspectableObject
object TextViewDescriptor : AbstractChainedDescriptor<TextView>() {
override fun onGetId(textView: TextView): String {
return Integer.toString(System.identityHashCode(textView))
override fun onGetId(node: TextView): String {
return System.identityHashCode(node).toString()
}
override fun onGetName(textView: TextView): String {
return textView.javaClass.simpleName
override fun onGetName(node: TextView): String {
return node.javaClass.simpleName
}
override fun onGetData(
textView: TextView,
node: TextView,
attributeSections: MutableMap<String, InspectableObject>
) {}
}

View File

@@ -7,6 +7,7 @@
package com.facebook.flipper.plugins.uidebugger.descriptors
import android.annotation.SuppressLint
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.util.SparseArray
@@ -22,129 +23,117 @@ import com.facebook.flipper.plugins.uidebugger.common.InspectableValue
import com.facebook.flipper.plugins.uidebugger.stetho.ResourcesUtil
import java.lang.reflect.Field
@SuppressLint("DiscouragedPrivateApi")
object ViewDescriptor : AbstractChainedDescriptor<View>() {
override fun onGetId(view: View): String {
return Integer.toBinaryString(System.identityHashCode(view))
override fun onGetId(node: View): String {
return Integer.toBinaryString(System.identityHashCode(node))
}
override fun onGetName(view: View): String {
return view.javaClass.simpleName
override fun onGetName(node: View): String {
return node.javaClass.simpleName
}
override fun onGetData(view: View, attributeSections: MutableMap<String, InspectableObject>) {
override fun onGetData(node: View, attributeSections: MutableMap<String, InspectableObject>) {
val positionOnScreen = IntArray(2)
view.getLocationOnScreen(positionOnScreen)
node.getLocationOnScreen(positionOnScreen)
val props = mutableMapOf<String, Inspectable>()
props.put("height", InspectableValue.Number(view.height, mutable = true))
props.put("width", InspectableValue.Number(view.width, mutable = true))
props.put("alpha", InspectableValue.Number(view.alpha, mutable = true))
props.put("visibility", VisibilityMapping.toInspectable(view.visibility, mutable = false))
props["height"] = InspectableValue.Number(node.height, mutable = true)
props["width"] = InspectableValue.Number(node.width, mutable = true)
props["alpha"] = InspectableValue.Number(node.alpha, mutable = true)
props["visibility"] = VisibilityMapping.toInspectable(node.visibility, mutable = false)
fromDrawable(view.background)?.let { props.put("background", it) }
fromDrawable(node.background)?.let { props["background"] = it }
view.tag?.let { InspectableValue.fromAny(it, mutable = false) }?.let { props.put("tag", it) }
props.put("keyedTags", InspectableObject(getTags(view)))
props.put("layoutParams", getLayoutParams(view))
props.put(
"state",
node.tag?.let { InspectableValue.fromAny(it, mutable = false) }?.let { props.put("tag", it) }
props["keyedTags"] = InspectableObject(getTags(node))
props["layoutParams"] = getLayoutParams(node)
props["state"] =
InspectableObject(
mapOf(
"enabled" to InspectableValue.Boolean(view.isEnabled, mutable = false),
"activated" to InspectableValue.Boolean(view.isActivated, mutable = false),
"focused" to InspectableValue.Boolean(view.isFocused, mutable = false),
"selected" to InspectableValue.Boolean(view.isSelected, mutable = false))))
"enabled" to InspectableValue.Boolean(node.isEnabled, mutable = false),
"activated" to InspectableValue.Boolean(node.isActivated, mutable = false),
"focused" to InspectableValue.Boolean(node.isFocused, mutable = false),
"selected" to InspectableValue.Boolean(node.isSelected, mutable = false)))
props.put(
"bounds",
props["bounds"] =
InspectableObject(
mapOf<String, Inspectable>(
"left" to InspectableValue.Number(view.left, mutable = true),
"right" to InspectableValue.Number(view.right, mutable = true),
"top" to InspectableValue.Number(view.top, mutable = true),
"bottom" to InspectableValue.Number(view.bottom, mutable = true))))
props.put(
"padding",
"left" to InspectableValue.Number(node.left, mutable = true),
"right" to InspectableValue.Number(node.right, mutable = true),
"top" to InspectableValue.Number(node.top, mutable = true),
"bottom" to InspectableValue.Number(node.bottom, mutable = true)))
props["padding"] =
InspectableObject(
mapOf<String, Inspectable>(
"left" to InspectableValue.Number(view.paddingLeft, mutable = true),
"right" to InspectableValue.Number(view.paddingRight, mutable = true),
"top" to InspectableValue.Number(view.paddingTop, mutable = true),
"bottom" to InspectableValue.Number(view.paddingBottom, mutable = true))))
"left" to InspectableValue.Number(node.paddingLeft, mutable = true),
"right" to InspectableValue.Number(node.paddingRight, mutable = true),
"top" to InspectableValue.Number(node.paddingTop, mutable = true),
"bottom" to InspectableValue.Number(node.paddingBottom, mutable = true)))
props.put(
"rotation",
props["rotation"] =
InspectableObject(
mapOf<String, Inspectable>(
"x" to InspectableValue.Number(view.rotationX, mutable = true),
"y" to InspectableValue.Number(view.rotationY, mutable = true),
"z" to InspectableValue.Number(view.rotation, mutable = true))))
"x" to InspectableValue.Number(node.rotationX, mutable = true),
"y" to InspectableValue.Number(node.rotationY, mutable = true),
"z" to InspectableValue.Number(node.rotation, mutable = true)))
props.put(
"scale",
props["scale"] =
InspectableObject(
mapOf(
"x" to InspectableValue.Number(view.scaleX, mutable = true),
"y" to InspectableValue.Number(view.scaleY, mutable = true))))
props.put(
"pivot",
"x" to InspectableValue.Number(node.scaleX, mutable = true),
"y" to InspectableValue.Number(node.scaleY, mutable = true)))
props["pivot"] =
InspectableObject(
mapOf(
"x" to InspectableValue.Number(view.pivotX, mutable = true),
"y" to InspectableValue.Number(view.pivotY, mutable = true))))
"x" to InspectableValue.Number(node.pivotX, mutable = true),
"y" to InspectableValue.Number(node.pivotY, mutable = true)))
props.put(
"globalPosition",
props["globalPosition"] =
InspectableObject(
mapOf(
"x" to InspectableValue.Number(positionOnScreen[0], mutable = false),
"y" to InspectableValue.Number(positionOnScreen[1], mutable = false))))
"y" to InspectableValue.Number(positionOnScreen[1], mutable = false)))
attributeSections.put("View", InspectableObject(props.toMap()))
attributeSections["View"] = InspectableObject(props.toMap())
}
fun fromDrawable(d: Drawable?): Inspectable? {
private fun fromDrawable(d: Drawable?): Inspectable? {
return if (d is ColorDrawable) {
InspectableValue.Color(d.color, mutable = false)
} else null
}
fun getLayoutParams(node: View): InspectableObject {
private fun getLayoutParams(node: View): InspectableObject {
val layoutParams = node.layoutParams
val params = mutableMapOf<String, Inspectable>()
params.put("width", LayoutParamsMapping.toInspectable(layoutParams.width, mutable = true))
params.put("height", LayoutParamsMapping.toInspectable(layoutParams.height, mutable = true))
params["width"] = LayoutParamsMapping.toInspectable(layoutParams.width, mutable = true)
params["height"] = LayoutParamsMapping.toInspectable(layoutParams.height, mutable = true)
if (layoutParams is ViewGroup.MarginLayoutParams) {
val marginLayoutParams = layoutParams
val margin =
InspectableObject(
mapOf<String, Inspectable>(
"left" to InspectableValue.Number(marginLayoutParams.leftMargin, mutable = true),
"top" to InspectableValue.Number(marginLayoutParams.topMargin, mutable = true),
"right" to
InspectableValue.Number(marginLayoutParams.rightMargin, mutable = true),
"bottom" to
InspectableValue.Number(marginLayoutParams.bottomMargin, mutable = true)))
"left" to InspectableValue.Number(layoutParams.leftMargin, mutable = true),
"top" to InspectableValue.Number(layoutParams.topMargin, mutable = true),
"right" to InspectableValue.Number(layoutParams.rightMargin, mutable = true),
"bottom" to InspectableValue.Number(layoutParams.bottomMargin, mutable = true)))
params.put("margin", margin)
params["margin"] = margin
}
if (layoutParams is FrameLayout.LayoutParams) {
params.put("gravity", GravityMapping.toInspectable(layoutParams.gravity, mutable = true))
params["gravity"] = GravityMapping.toInspectable(layoutParams.gravity, mutable = true)
}
if (layoutParams is LinearLayout.LayoutParams) {
val linearLayoutParams = layoutParams
params.put("weight", InspectableValue.Number(linearLayoutParams.weight, mutable = true))
params.put(
"gravity", GravityMapping.toInspectable(linearLayoutParams.gravity, mutable = true))
params["weight"] = InspectableValue.Number(layoutParams.weight, mutable = true)
params["gravity"] = GravityMapping.toInspectable(layoutParams.gravity, mutable = true)
}
return InspectableObject(params)
}
fun getTags(node: View): MutableMap<String, Inspectable> {
private fun getTags(node: View): MutableMap<String, Inspectable> {
val tags = mutableMapOf<String, Inspectable>()
KeyedTagsField?.let { field ->

View File

@@ -20,18 +20,18 @@ import com.facebook.flipper.plugins.uidebugger.stetho.FragmentCompat
object ViewGroupDescriptor : AbstractChainedDescriptor<ViewGroup>() {
override fun onGetId(viewGroup: ViewGroup): String {
return Integer.toString(System.identityHashCode(viewGroup))
override fun onGetId(node: ViewGroup): String {
return System.identityHashCode(node).toString()
}
override fun onGetName(viewGroup: ViewGroup): String {
return viewGroup.javaClass.simpleName
override fun onGetName(node: ViewGroup): String {
return node.javaClass.simpleName
}
override fun onGetChildren(viewGroup: ViewGroup, children: MutableList<Any>) {
val count = viewGroup.childCount - 1
override fun onGetChildren(node: ViewGroup, children: MutableList<Any>) {
val count = node.childCount - 1
for (i in 0..count) {
val child: View = viewGroup.getChildAt(i)
val child: View = node.getChildAt(i)
val fragment = getAttachedFragmentForView(child)
if (fragment != null && !FragmentCompat.isDialogFragment(fragment)) {
children.add(fragment)
@@ -40,25 +40,20 @@ object ViewGroupDescriptor : AbstractChainedDescriptor<ViewGroup>() {
}
override fun onGetData(
viewGroup: ViewGroup,
node: ViewGroup,
attributeSections: MutableMap<String, InspectableObject>
) {
val viewGroupAttrs = mutableMapOf<String, Inspectable>()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
viewGroupAttrs.put(
"LayoutMode", LayoutModeMapping.toInspectable(viewGroup.getLayoutMode(), true))
viewGroupAttrs.put(
"ClipChildren",
InspectableValue.Boolean(viewGroup.getClipChildren(), true),
)
viewGroupAttrs["LayoutMode"] = LayoutModeMapping.toInspectable(node.layoutMode, true)
viewGroupAttrs["ClipChildren"] = InspectableValue.Boolean(node.clipChildren, true)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
viewGroupAttrs.put(
"ClipToPadding", InspectableValue.Boolean(viewGroup.getClipToPadding(), true))
viewGroupAttrs["ClipToPadding"] = InspectableValue.Boolean(node.clipToPadding, true)
}
attributeSections.put("ViewGroup", InspectableObject(viewGroupAttrs))
attributeSections["ViewGroup"] = InspectableObject(viewGroupAttrs)
}
private val LayoutModeMapping: EnumMapping<Int> =

View File

@@ -11,15 +11,15 @@ import android.view.Window
object WindowDescriptor : AbstractChainedDescriptor<Window>() {
override fun onGetId(window: Window): String {
return Integer.toString(System.identityHashCode(window))
override fun onGetId(node: Window): String {
return System.identityHashCode(node).toString()
}
override fun onGetName(window: Window): String {
return window.javaClass.simpleName
override fun onGetName(node: Window): String {
return node.javaClass.simpleName
}
override fun onGetChildren(window: Window, children: MutableList<Any>) {
children.add(window.decorView)
override fun onGetChildren(node: Window, children: MutableList<Any>) {
children.add(node.decorView)
}
}