[6.2.8][View点击态] 添加View#setBackgroundResource方法的hook

This commit is contained in:
renwj
2024-01-16 20:27:17 +08:00
parent 92159a6f21
commit 1789c3c062

View File

@@ -214,6 +214,41 @@ public class ViewPressedStateLancet {
}
}
@TargetClass(value = "android.view.View", scope = Scope.ALL)
@TargetMethod(methodName = "setBackgroundResource")
@ReplaceInvoke
public static void setBackgroundResource(View view, int resId) {
if (view == null) {
return;
}
if (!view.isLongClickable() && !view.isClickable()) {
view.setBackgroundResource(resId);
return;
}
float alpha = getAlpha(view);
if (alpha >= 0) {
Drawable drawable = null;
try {
drawable = ContextCompat.getDrawable(view.getContext(), resId);
} catch (Throwable ignore) {}
Drawable replaced = checkAndReplaceDrawable(drawable, alpha);
if (replaced != null) {
view.setTag(R.id.click_pressed_attr_replaced, drawable);
int paddingLeft = view.getPaddingLeft();
int paddingRight = view.getPaddingRight();
int paddingTop = view.getPaddingTop();
int paddingBottom = view.getPaddingBottom();
view.setBackground(replaced);
view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
} else {
view.setBackground(drawable);
}
} else {
view.setBackgroundResource(resId);
}
}
@TargetClass(value = "android.widget.ImageView", scope = Scope.ALL)
@TargetMethod(methodName = "setImageDrawable")
@ReplaceInvoke