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>() { object ActivityDescriptor : AbstractChainedDescriptor<Activity>() {
override fun onGetId(activity: Activity): String { override fun onGetId(node: Activity): String {
return Integer.toString(System.identityHashCode(activity)) return System.identityHashCode(node).toString()
} }
override fun onGetName(activity: Activity): String { override fun onGetName(node: Activity): String {
return activity.javaClass.simpleName return node.javaClass.simpleName
} }
override fun onGetChildren(activity: Activity, children: MutableList<Any>) { override fun onGetChildren(node: Activity, children: MutableList<Any>) {
activity.window?.let { window -> children.add(activity.window) } node.window?.let { window -> children.add(window) }
var fragments = getDialogFragments(FragmentCompat.supportInstance, activity) var fragments = getDialogFragments(FragmentCompat.supportInstance, node)
for (fragment in fragments) { for (fragment in fragments) {
children.add(fragment) children.add(fragment)
} }
fragments = getDialogFragments(FragmentCompat.frameworkInstance, activity) fragments = getDialogFragments(FragmentCompat.frameworkInstance, node)
for (fragment in fragments) { for (fragment in fragments) {
children.add(fragment) children.add(fragment)
} }
} }
override fun onGetData( override fun onGetData(
activity: Activity, node: Activity,
attributeSections: MutableMap<String, InspectableObject> attributeSections: MutableMap<String, InspectableObject>
) {} ) {}

View File

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

View File

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

View File

@@ -13,15 +13,15 @@ object ObjectDescriptor : Descriptor<Any>() {
override fun getActiveChild(node: Any): Any? = null override fun getActiveChild(node: Any): Any? = null
override fun getId(obj: Any): String { override fun getId(node: Any): String {
return Integer.toString(System.identityHashCode(obj)) return System.identityHashCode(node).toString()
} }
override fun getName(obj: Any): String { override fun getName(node: Any): String {
return obj.javaClass.simpleName return node.javaClass.simpleName
} }
override fun getChildren(node: Any, children: MutableList<Any>) {} 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>() { object TextViewDescriptor : AbstractChainedDescriptor<TextView>() {
override fun onGetId(textView: TextView): String { override fun onGetId(node: TextView): String {
return Integer.toString(System.identityHashCode(textView)) return System.identityHashCode(node).toString()
} }
override fun onGetName(textView: TextView): String { override fun onGetName(node: TextView): String {
return textView.javaClass.simpleName return node.javaClass.simpleName
} }
override fun onGetData( override fun onGetData(
textView: TextView, node: TextView,
attributeSections: MutableMap<String, InspectableObject> attributeSections: MutableMap<String, InspectableObject>
) {} ) {}
} }

View File

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

View File

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

View File

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