From 3795b195c889fb323d0317dbbc769779c9f6c4c9 Mon Sep 17 00:00:00 2001 From: renwj Date: Mon, 25 Dec 2023 19:18:53 +0800 Subject: [PATCH] =?UTF-8?q?[6.2.6][View=E7=82=B9=E5=87=BB=E6=80=81]=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=89=93=E5=BC=80;=E5=8F=AA=E6=9C=89?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E8=BF=87=E7=82=B9=E5=87=BB=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E7=9A=84view=E6=89=8Dcheck=E6=98=AF=E5=90=A6=E8=A6=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=82=B9=E5=87=BB=E6=80=81;=E5=A2=9E=E5=8A=A0textView?= =?UTF-8?q?=E7=9A=84color=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/res/layout/charter_p_video_view.xml | 1 - .../src/main/res/layout/taxi_p_video_show.xml | 1 - .../main/res/layout/task_fragment_current.xml | 1 - .../main/res/layout/taxt_u_p_video_show.xml | 1 - .../lancet/ViewPressedStateLancet.java | 484 +++++++++++++----- .../radio_button_normal_background_right.xml | 2 +- .../setting_toggle_button_background.xml | 2 +- .../src/main/res/layout/item_notice_video.xml | 1 - .../mogo-core-res/src/main/res/values/ids.xml | 2 + gradle/bytex/bytex_lancetx.gradle | 2 +- 10 files changed, 363 insertions(+), 134 deletions(-) diff --git a/OCH/charter/passenger/src/main/res/layout/charter_p_video_view.xml b/OCH/charter/passenger/src/main/res/layout/charter_p_video_view.xml index d711fe3a71..ec63d7a270 100644 --- a/OCH/charter/passenger/src/main/res/layout/charter_p_video_view.xml +++ b/OCH/charter/passenger/src/main/res/layout/charter_p_video_view.xml @@ -62,7 +62,6 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:layout_height="@dimen/dp_119" - app:pressed_enabled="false" app:layout_constraintBottom_toBottomOf="parent"> = 0) { + 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.setBackground(drawable); + } + } + + @TargetClass(value = "android.widget.ImageView", scope = Scope.ALL) + @TargetMethod(methodName = "setImageDrawable") + @ReplaceInvoke + public static void setImageViewDrawable(ImageView view, Drawable drawable) { + if (view == null) { + return; + } + if (!view.isLongClickable() && !view.isClickable()) { + view.setImageDrawable(drawable); + return; + } + float alpha = getAlpha(view); + if (alpha >= 0.0) { + 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.setImageDrawable(replaced); + view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + } else { + view.setImageDrawable(drawable); + } + } else { + view.setImageDrawable(drawable); + } + } + + @TargetClass(value = "android.widget.ImageView", scope = Scope.ALL) + @TargetMethod(methodName = "setImageResource") + @ReplaceInvoke + public static void setImageViewResource(ImageView view, int resId) { + if (view == null) { + return; + } + if (!view.isLongClickable() && !view.isClickable()) { + view.setImageResource(resId); + return; + } + float alpha = getAlpha(view); + if (alpha >= 0.0) { + Drawable drawable = ContextCompat.getDrawable(view.getContext(), resId); + 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.setImageDrawable(replaced); + view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + } else { + view.setImageDrawable(drawable); + } + } else { + view.setImageResource(resId); + } + } + + public static float getAlpha(View view) { + Object tag = view.getTag(R.id.click_pressed_attr_enabled); + if (tag != null && !((Boolean) tag)) { + return -1.0f; + } + tag = view.getTag(R.id.click_pressed_attr_id); + if (tag instanceof AttributeSet) { + AttributeSet attr = (AttributeSet) tag; + TypedArray array = null; + try { + array = view.getContext().obtainStyledAttributes(attr, R.styleable.ClickPressedStyle); + return array.getFloat(R.styleable.ClickPressedStyle_pressed_alpha, 0.6f); + } finally { + if (array != null) { + array.recycle(); + } + } + } + return -1.0f; + } + + @ImplementedInterface(value = "android.view.LayoutInflater$Factory", scope = Scope.LEAF) @Insert(mayCreateSuper = true) @TargetMethod(methodName = "onCreateView") @@ -101,7 +275,7 @@ public class ViewPressedStateLancet { if (view == null && attrs != null) { view = tryCreateView(name, context, attrs); } - checkSetBgIfNeed(null, view, attrs); + checkSetBgIfNeed(null, view, attrs, false); return view; } @@ -113,7 +287,7 @@ public class ViewPressedStateLancet { if (view == null && attrs != null) { view = tryCreateView(name, context, attrs); } - checkSetBgIfNeed(parent, view, attrs); + checkSetBgIfNeed(parent, view, attrs, false); return view; } @@ -143,7 +317,7 @@ public class ViewPressedStateLancet { return ret; } - private static void checkSetBgIfNeed(View parent, View view, AttributeSet attr) { + private static void checkSetBgIfNeed(View parent, View view, AttributeSet attr, boolean check) { try { TypedArray t = null; float alpha = 0.6f; @@ -156,7 +330,6 @@ public class ViewPressedStateLancet { if (context == null) { return; } - if (parent != null) { Object tag = parent.getTag(R.id.click_pressed_attr_enabled); if (tag != null && !((Boolean) tag)) { @@ -182,80 +355,156 @@ public class ViewPressedStateLancet { throw new AssertionError("view custom attr \\'alpha\\' must be in [0.0, 1.0]"); } } - view.setTag(R.id.click_pressed_attr_id, attr); + if (!check) { + view.setTag(R.id.click_pressed_attr_id, attr); + return; + } } } finally { if (t != null) { t.recycle(); } } - if (view instanceof ImageView) { - ImageView image = (ImageView) view; - Drawable replaced = checkAndReplaceDrawable(image.getBackground(), alpha); - if (replaced != null) { - ViewCompat.setBackground(image, replaced); - return; - } - replaced = checkAndReplaceDrawable(image.getDrawable(), alpha); - if (replaced != null) { - image.setImageDrawable(replaced); - return; - } - return; - } - if (view instanceof TextView) { - TextView text = (TextView) view; - Drawable replaced = checkAndReplaceDrawable(text.getBackground(), alpha); - if (replaced != null) { - ViewCompat.setBackground(text, replaced); - return; - } - ColorStateList textColor = text.getTextColors(); - if (textColor != null) { - int pressed = textColor.getColorForState(new int[]{ android.R.attr.state_pressed }, Integer.MIN_VALUE); - if (pressed != Integer.MIN_VALUE) { - return; - } - int color = textColor.getColorForState(new int[] { android.R.attr.state_enabled }, Integer.MIN_VALUE); - int defaultColor = color; - if (color == Integer.MIN_VALUE) { - defaultColor = textColor.getDefaultColor(); - } - int pressedColor = Color.argb((int)(Color.alpha(defaultColor) * alpha), Color.red(defaultColor), Color.green(defaultColor), Color.blue(defaultColor)); - int disableColor = textColor.getColorForState(new int[] { -android.R.attr.state_enabled }, Integer.MIN_VALUE); - int size = 2; - if (disableColor != Integer.MIN_VALUE) { - size += 1; - } - int[][] states = new int[size][1]; - int[] colors = new int[size]; - states[0] = new int[] { android.R.attr.state_pressed }; - colors[0] = pressedColor; - if (size > 2) { - states[1] = new int[] { -android.R.attr.state_enabled }; - colors[1] = disableColor; - states[2] = new int[] { android.R.attr.state_enabled }; - colors[2] = defaultColor; - } else { - states[1] = new int[] { -android.R.attr.state_pressed }; - colors[1] = defaultColor; - } - ColorStateList newColor = new ColorStateList(states, colors); - text.setTextColor(newColor); - } - return; - } - if (view != null) { - Drawable replaced = checkAndReplaceDrawable(view.getBackground(), alpha); - if (replaced != null) { - ViewCompat.setBackground(view, replaced); - } + boolean rst = check(view, alpha); + if (!rst && view != null) { + view.setTag(R.id.click_pressed_attr_enabled, false); } } catch (Throwable t) { t.printStackTrace(); } } + private static boolean check(View view, float alpha) { + if (view instanceof ImageView) { + ImageView image = (ImageView) view; + Drawable old = image.getBackground(); + Drawable replaced = checkAndReplaceDrawable(old, alpha); + if (replaced != null) { + view.setTag(R.id.click_pressed_attr_replaced, old); + image.setBackground(replaced); + return true; + } + old = image.getDrawable(); + replaced = checkAndReplaceDrawable(old, alpha); + if (replaced != null) { + view.setTag(R.id.click_pressed_attr_replaced, old); + int paddingLeft = view.getPaddingLeft(); + int paddingRight = view.getPaddingRight(); + int paddingTop = view.getPaddingTop(); + int paddingBottom = view.getPaddingBottom(); + image.setImageDrawable(replaced); + image.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + return true; + } + return false; + } + + if (view instanceof TextView) { + TextView text = (TextView) view; + Drawable background = text.getBackground(); + Drawable replaced = checkAndReplaceDrawable(background, alpha); + if (replaced != null) { + view.setTag(R.id.click_pressed_attr_replaced, background); + int paddingLeft = text.getPaddingLeft(); + int paddingRight = text.getPaddingRight(); + int paddingTop = text.getPaddingTop(); + int paddingBottom = text.getPaddingBottom(); + text.setBackground(replaced); + text.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + return true; + } + + ColorStateList textColor = text.getTextColors(); + if (textColor != null) { + int current = text.getCurrentTextColor(); + int pressed = textColor.getColorForState(new int[]{ android.R.attr.state_pressed }, Integer.MIN_VALUE); + if (pressed != Integer.MIN_VALUE && pressed != current) { + return false; + } + int enableColor = textColor.getColorForState(new int[] { android.R.attr.state_enabled }, Integer.MIN_VALUE); + int defaultColor = current; + if (enableColor == Integer.MIN_VALUE && enableColor != current) { + defaultColor = textColor.getDefaultColor(); + } + int pressedColor = Color.argb((int)(Color.alpha(defaultColor) * alpha), Color.red(defaultColor), Color.green(defaultColor), Color.blue(defaultColor)); + int disableColor = textColor.getColorForState(new int[] { -android.R.attr.state_enabled }, Integer.MIN_VALUE); + int size = 2; + if (disableColor != Integer.MIN_VALUE && disableColor != current) { + size += 1; + } + boolean hasChecked = false; + int checkedColor = textColor.getColorForState(new int[] { android.R.attr.state_checked }, Integer.MIN_VALUE); + if (checkedColor != Integer.MIN_VALUE && checkedColor != current) { + hasChecked = true; + size += 1; + } + boolean hasUnChecked = false; + int unCheckedColor = textColor.getColorForState(new int[]{ -android.R.attr.state_checked }, Integer.MIN_VALUE); + if (unCheckedColor != Integer.MIN_VALUE && unCheckedColor != current) { + hasUnChecked = true; + size += 1; + } + int[][] states = new int[size][1]; + int[] colors = new int[size]; + states[0] = new int[] { android.R.attr.state_pressed }; + colors[0] = pressedColor; + if (size > 2) { + states[1] = new int[] { -android.R.attr.state_enabled }; + colors[1] = disableColor; + states[2] = new int[] { android.R.attr.state_enabled }; + colors[2] = defaultColor; + if (hasChecked) { + states[3] = new int[] { android.R.attr.state_checked }; + colors[3] = checkedColor; + } + if (hasUnChecked) { + if (size > 4) { + states[4] = new int[] { -android.R.attr.state_checked }; + colors[4] = unCheckedColor; + } else { + states[3] = new int[] { -android.R.attr.state_checked }; + colors[3] = unCheckedColor; + } + } + } else { + states[1] = new int[] { -android.R.attr.state_pressed }; + colors[1] = defaultColor; + } + ColorStateList newColor = new ColorStateList(states, colors); + text.setTag(R.id.click_pressed_attr_replaced_color, textColor); + text.setTextColor(newColor); + return true; + } + + return false; + } + if (view != null) { + Drawable old = view.getBackground(); + Drawable replaced = checkAndReplaceDrawable(old, alpha); + if (replaced != null) { + view.setTag(R.id.click_pressed_attr_replaced, old); + 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); + return true; + } + } + if (view instanceof ViewGroup) { + ViewGroup group = (ViewGroup) view; + int count = group.getChildCount(); + for (int i = 0; i < count; i++) { + View child = group.getChildAt(i); + if (check(child, alpha)) { + return true; + } + } + } + return false; + } + private static Drawable checkAndReplaceDrawable(Drawable old, float alpha) { if (old == null) { return null; @@ -264,47 +513,30 @@ public class ViewPressedStateLancet { StateListDrawable drawable = (StateListDrawable) old; int[] states = drawable.getState(); boolean hasPressed = false; - int index = 0; - int targetIndex = -1; for (int state : states) { - if (!hasPressed && state == android.R.attr.state_pressed) { + if (state == android.R.attr.state_pressed) { hasPressed = true; - } - if (targetIndex == -1 && state != -android.R.attr.state_enabled) { - targetIndex = index; - } - if (hasPressed && targetIndex != -1) { break; } - index ++; } if (hasPressed) { return null; } - if (targetIndex != -1) { - Drawable origin= null; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - origin = drawable.getStateDrawable(targetIndex); - } else { - origin = drawable.getCurrent(); - } - if (origin != null) { - Drawable.ConstantState constantState = origin.getConstantState(); - if (constantState != null) { - Drawable pressed = DrawableCompat.wrap(constantState.newDrawable().mutate()); - pressed.setAlpha((int)(255 * alpha)); - drawable.addState(new int[] { android.R.attr.state_pressed }, pressed); - return drawable; - } - } - return null; + Drawable origin = drawable.getCurrent(); + Drawable.ConstantState constantState = origin.getConstantState(); + if (constantState != null) { + Drawable pressed = DrawableCompat.wrap(constantState.newDrawable().mutate()); + pressed.setAlpha((int)(255 * alpha)); + drawable.addState(new int[] { android.R.attr.state_pressed }, pressed); + return drawable; } return null; } Drawable.ConstantState constantState = old.getConstantState(); if (constantState != null) { StateListDrawable result = new StateListDrawable(); - result.addState(new int[] { -android.R.attr.state_pressed }, old); + int[] state = { -android.R.attr.state_pressed }; + result.addState(state, old); Drawable pressed = DrawableCompat.wrap(constantState.newDrawable().mutate()); pressed.setAlpha((int)(255 * alpha)); result.addState(new int[] { android.R.attr.state_pressed }, pressed); diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/radio_button_normal_background_right.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/radio_button_normal_background_right.xml index cacee166bb..888b1a143c 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/radio_button_normal_background_right.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/radio_button_normal_background_right.xml @@ -1,7 +1,7 @@ - + diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/setting_toggle_button_background.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/setting_toggle_button_background.xml index 6dda1e9b28..0251939415 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/setting_toggle_button_background.xml +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/drawable/setting_toggle_button_background.xml @@ -1,7 +1,7 @@ - + diff --git a/core/mogo-core-res/src/main/res/layout/item_notice_video.xml b/core/mogo-core-res/src/main/res/layout/item_notice_video.xml index e990ebc08b..1b6f4c391b 100644 --- a/core/mogo-core-res/src/main/res/layout/item_notice_video.xml +++ b/core/mogo-core-res/src/main/res/layout/item_notice_video.xml @@ -32,7 +32,6 @@ android:layout_height="match_parent" android:layout_alignParentBottom="true" android:gravity="bottom" - app:pressed_enabled="false" android:orientation="horizontal"> + + \ No newline at end of file diff --git a/gradle/bytex/bytex_lancetx.gradle b/gradle/bytex/bytex_lancetx.gradle index 13f4e389f9..2f9e8ef35c 100644 --- a/gradle/bytex/bytex_lancetx.gradle +++ b/gradle/bytex/bytex_lancetx.gradle @@ -27,7 +27,7 @@ LancetX { enable rootProject.isJunkDetectEnable() } view_pressed_state { - enable false + enable true } } }