Rabbit-R1/android (non root)/java/sources/androidx/appcompat/widget/DropDownListView.java
2024-05-21 17:08:36 -04:00

638 lines
22 KiB
Java

package androidx.appcompat.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import androidx.appcompat.R;
import androidx.appcompat.graphics.drawable.DrawableWrapperCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.os.BuildCompat;
import androidx.core.view.ViewPropertyAnimatorCompat;
import androidx.core.widget.ListViewAutoScrollHelper;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public class DropDownListView extends ListView {
public static final int INVALID_POSITION = -1;
public static final int NO_POSITION = -1;
private ViewPropertyAnimatorCompat mClickAnimation;
private boolean mDrawsInPressedState;
private boolean mHijackFocus;
private boolean mListSelectionHidden;
private int mMotionPosition;
ResolveHoverRunnable mResolveHoverRunnable;
private ListViewAutoScrollHelper mScrollHelper;
private int mSelectionBottomPadding;
private int mSelectionLeftPadding;
private int mSelectionRightPadding;
private int mSelectionTopPadding;
private GateKeeperDrawable mSelector;
private final Rect mSelectorRect;
private boolean touchModeDrawsInPressedStateCompat() {
return this.mDrawsInPressedState;
}
/* JADX INFO: Access modifiers changed from: package-private */
public void setListSelectionHidden(boolean z) {
this.mListSelectionHidden = z;
}
/* JADX INFO: Access modifiers changed from: package-private */
public DropDownListView(Context context, boolean z) {
super(context, null, R.attr.dropDownListViewStyle);
this.mSelectorRect = new Rect();
this.mSelectionLeftPadding = 0;
this.mSelectionTopPadding = 0;
this.mSelectionRightPadding = 0;
this.mSelectionBottomPadding = 0;
this.mHijackFocus = z;
setCacheColorHint(0);
}
private boolean superIsSelectedChildViewEnabled() {
if (BuildCompat.isAtLeastT()) {
return Api33Impl.isSelectedChildViewEnabled(this);
}
return PreApi33Impl.isSelectedChildViewEnabled(this);
}
private void superSetSelectedChildViewEnabled(boolean z) {
if (BuildCompat.isAtLeastT()) {
Api33Impl.setSelectedChildViewEnabled(this, z);
} else {
PreApi33Impl.setSelectedChildViewEnabled(this, z);
}
}
@Override // android.view.View
public boolean isInTouchMode() {
return (this.mHijackFocus && this.mListSelectionHidden) || super.isInTouchMode();
}
@Override // android.view.View
public boolean hasWindowFocus() {
return this.mHijackFocus || super.hasWindowFocus();
}
@Override // android.view.View
public boolean isFocused() {
return this.mHijackFocus || super.isFocused();
}
@Override // android.view.ViewGroup, android.view.View
public boolean hasFocus() {
return this.mHijackFocus || super.hasFocus();
}
@Override // android.widget.AbsListView
public void setSelector(Drawable drawable) {
GateKeeperDrawable gateKeeperDrawable = drawable != null ? new GateKeeperDrawable(drawable) : null;
this.mSelector = gateKeeperDrawable;
super.setSelector(gateKeeperDrawable);
Rect rect = new Rect();
if (drawable != null) {
drawable.getPadding(rect);
}
this.mSelectionLeftPadding = rect.left;
this.mSelectionTopPadding = rect.top;
this.mSelectionRightPadding = rect.right;
this.mSelectionBottomPadding = rect.bottom;
}
@Override // android.widget.AbsListView, android.view.ViewGroup, android.view.View
protected void drawableStateChanged() {
if (this.mResolveHoverRunnable != null) {
return;
}
super.drawableStateChanged();
setSelectorEnabled(true);
updateSelectorStateCompat();
}
@Override // android.widget.ListView, android.widget.AbsListView, android.view.ViewGroup, android.view.View
protected void dispatchDraw(Canvas canvas) {
drawSelectorCompat(canvas);
super.dispatchDraw(canvas);
}
@Override // android.widget.AbsListView, android.view.View
public boolean onTouchEvent(MotionEvent motionEvent) {
if (motionEvent.getAction() == 0) {
this.mMotionPosition = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY());
}
ResolveHoverRunnable resolveHoverRunnable = this.mResolveHoverRunnable;
if (resolveHoverRunnable != null) {
resolveHoverRunnable.cancel();
}
return super.onTouchEvent(motionEvent);
}
public int lookForSelectablePosition(int i, boolean z) {
int min;
ListAdapter adapter = getAdapter();
if (adapter != null && !isInTouchMode()) {
int count = adapter.getCount();
if (!getAdapter().areAllItemsEnabled()) {
if (z) {
min = Math.max(0, i);
while (min < count && !adapter.isEnabled(min)) {
min++;
}
} else {
min = Math.min(i, count - 1);
while (min >= 0 && !adapter.isEnabled(min)) {
min--;
}
}
if (min < 0 || min >= count) {
return -1;
}
return min;
}
if (i >= 0 && i < count) {
return i;
}
}
return -1;
}
public int measureHeightOfChildrenCompat(int i, int i2, int i3, int i4, int i5) {
int makeMeasureSpec;
int listPaddingTop = getListPaddingTop();
int listPaddingBottom = getListPaddingBottom();
int dividerHeight = getDividerHeight();
Drawable divider = getDivider();
ListAdapter adapter = getAdapter();
if (adapter == null) {
return listPaddingTop + listPaddingBottom;
}
int i6 = listPaddingTop + listPaddingBottom;
if (dividerHeight <= 0 || divider == null) {
dividerHeight = 0;
}
int count = adapter.getCount();
int i7 = 0;
int i8 = 0;
int i9 = 0;
View view = null;
while (i7 < count) {
int itemViewType = adapter.getItemViewType(i7);
if (itemViewType != i8) {
view = null;
i8 = itemViewType;
}
view = adapter.getView(i7, view, this);
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
if (layoutParams == null) {
layoutParams = generateDefaultLayoutParams();
view.setLayoutParams(layoutParams);
}
if (layoutParams.height > 0) {
makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(layoutParams.height, 1073741824);
} else {
makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, 0);
}
view.measure(i, makeMeasureSpec);
view.forceLayout();
if (i7 > 0) {
i6 += dividerHeight;
}
i6 += view.getMeasuredHeight();
if (i6 >= i4) {
return (i5 < 0 || i7 <= i5 || i9 <= 0 || i6 == i4) ? i4 : i9;
}
if (i5 >= 0 && i7 >= i5) {
i9 = i6;
}
i7++;
}
return i6;
}
private void setSelectorEnabled(boolean z) {
GateKeeperDrawable gateKeeperDrawable = this.mSelector;
if (gateKeeperDrawable != null) {
gateKeeperDrawable.setEnabled(z);
}
}
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes.dex */
public static class GateKeeperDrawable extends DrawableWrapperCompat {
private boolean mEnabled;
void setEnabled(boolean z) {
this.mEnabled = z;
}
GateKeeperDrawable(Drawable drawable) {
super(drawable);
this.mEnabled = true;
}
@Override // androidx.appcompat.graphics.drawable.DrawableWrapperCompat, android.graphics.drawable.Drawable
public boolean setState(int[] iArr) {
if (this.mEnabled) {
return super.setState(iArr);
}
return false;
}
@Override // androidx.appcompat.graphics.drawable.DrawableWrapperCompat, android.graphics.drawable.Drawable
public void draw(Canvas canvas) {
if (this.mEnabled) {
super.draw(canvas);
}
}
@Override // androidx.appcompat.graphics.drawable.DrawableWrapperCompat, android.graphics.drawable.Drawable
public void setHotspot(float f, float f2) {
if (this.mEnabled) {
super.setHotspot(f, f2);
}
}
@Override // androidx.appcompat.graphics.drawable.DrawableWrapperCompat, android.graphics.drawable.Drawable
public void setHotspotBounds(int i, int i2, int i3, int i4) {
if (this.mEnabled) {
super.setHotspotBounds(i, i2, i3, i4);
}
}
@Override // androidx.appcompat.graphics.drawable.DrawableWrapperCompat, android.graphics.drawable.Drawable
public boolean setVisible(boolean z, boolean z2) {
if (this.mEnabled) {
return super.setVisible(z, z2);
}
return false;
}
}
@Override // android.view.View
public boolean onHoverEvent(MotionEvent motionEvent) {
int actionMasked = motionEvent.getActionMasked();
if (actionMasked == 10 && this.mResolveHoverRunnable == null) {
ResolveHoverRunnable resolveHoverRunnable = new ResolveHoverRunnable();
this.mResolveHoverRunnable = resolveHoverRunnable;
resolveHoverRunnable.post();
}
boolean onHoverEvent = super.onHoverEvent(motionEvent);
if (actionMasked == 9 || actionMasked == 7) {
int pointToPosition = pointToPosition((int) motionEvent.getX(), (int) motionEvent.getY());
if (pointToPosition != -1 && pointToPosition != getSelectedItemPosition()) {
View childAt = getChildAt(pointToPosition - getFirstVisiblePosition());
if (childAt.isEnabled()) {
requestFocus();
if (Api30Impl.canPositionSelectorForHoveredItem()) {
Api30Impl.positionSelectorForHoveredItem(this, pointToPosition, childAt);
} else {
setSelectionFromTop(pointToPosition, childAt.getTop() - getTop());
}
}
updateSelectorStateCompat();
}
} else {
setSelection(-1);
}
return onHoverEvent;
}
@Override // android.widget.ListView, android.widget.AbsListView, android.widget.AdapterView, android.view.ViewGroup, android.view.View
protected void onDetachedFromWindow() {
this.mResolveHoverRunnable = null;
super.onDetachedFromWindow();
}
/* JADX WARN: Code restructure failed: missing block: B:6:0x000c, code lost:
if (r0 != 3) goto L8;
*/
/* JADX WARN: Removed duplicated region for block: B:11:0x004f */
/* JADX WARN: Removed duplicated region for block: B:17:0x0065 */
/* JADX WARN: Removed duplicated region for block: B:9:0x0048 A[ADDED_TO_REGION] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public boolean onForwardedEvent(android.view.MotionEvent r8, int r9) {
/*
r7 = this;
int r0 = r8.getActionMasked()
r1 = 1
r2 = 0
if (r0 == r1) goto L16
r3 = 2
if (r0 == r3) goto L14
r9 = 3
if (r0 == r9) goto L11
Le:
r3 = r1
r9 = r2
goto L46
L11:
r9 = r2
r3 = r9
goto L46
L14:
r3 = r1
goto L17
L16:
r3 = r2
L17:
int r9 = r8.findPointerIndex(r9)
if (r9 >= 0) goto L1e
goto L11
L1e:
float r4 = r8.getX(r9)
int r4 = (int) r4
float r9 = r8.getY(r9)
int r9 = (int) r9
int r5 = r7.pointToPosition(r4, r9)
r6 = -1
if (r5 != r6) goto L31
r9 = r1
goto L46
L31:
int r3 = r7.getFirstVisiblePosition()
int r3 = r5 - r3
android.view.View r3 = r7.getChildAt(r3)
float r4 = (float) r4
float r9 = (float) r9
r7.setPressedItem(r3, r5, r4, r9)
if (r0 != r1) goto Le
r7.clickPressedItem(r3, r5)
goto Le
L46:
if (r3 == 0) goto L4a
if (r9 == 0) goto L4d
L4a:
r7.clearPressedItem()
L4d:
if (r3 == 0) goto L65
androidx.core.widget.ListViewAutoScrollHelper r9 = r7.mScrollHelper
if (r9 != 0) goto L5a
androidx.core.widget.ListViewAutoScrollHelper r9 = new androidx.core.widget.ListViewAutoScrollHelper
r9.<init>(r7)
r7.mScrollHelper = r9
L5a:
androidx.core.widget.ListViewAutoScrollHelper r9 = r7.mScrollHelper
r9.setEnabled(r1)
androidx.core.widget.ListViewAutoScrollHelper r9 = r7.mScrollHelper
r9.onTouch(r7, r8)
goto L6c
L65:
androidx.core.widget.ListViewAutoScrollHelper r7 = r7.mScrollHelper
if (r7 == 0) goto L6c
r7.setEnabled(r2)
L6c:
return r3
*/
throw new UnsupportedOperationException("Method not decompiled: androidx.appcompat.widget.DropDownListView.onForwardedEvent(android.view.MotionEvent, int):boolean");
}
private void clickPressedItem(View view, int i) {
performItemClick(view, i, getItemIdAtPosition(i));
}
private void updateSelectorStateCompat() {
Drawable selector = getSelector();
if (selector != null && touchModeDrawsInPressedStateCompat() && isPressed()) {
selector.setState(getDrawableState());
}
}
private void drawSelectorCompat(Canvas canvas) {
Drawable selector;
if (this.mSelectorRect.isEmpty() || (selector = getSelector()) == null) {
return;
}
selector.setBounds(this.mSelectorRect);
selector.draw(canvas);
}
private void positionSelectorLikeTouchCompat(int i, View view, float f, float f2) {
positionSelectorLikeFocusCompat(i, view);
Drawable selector = getSelector();
if (selector == null || i == -1) {
return;
}
DrawableCompat.setHotspot(selector, f, f2);
}
private void positionSelectorLikeFocusCompat(int i, View view) {
Drawable selector = getSelector();
boolean z = (selector == null || i == -1) ? false : true;
if (z) {
selector.setVisible(false, false);
}
positionSelectorCompat(i, view);
if (z) {
Rect rect = this.mSelectorRect;
float exactCenterX = rect.exactCenterX();
float exactCenterY = rect.exactCenterY();
selector.setVisible(getVisibility() == 0, false);
DrawableCompat.setHotspot(selector, exactCenterX, exactCenterY);
}
}
private void positionSelectorCompat(int i, View view) {
Rect rect = this.mSelectorRect;
rect.set(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
rect.left -= this.mSelectionLeftPadding;
rect.top -= this.mSelectionTopPadding;
rect.right += this.mSelectionRightPadding;
rect.bottom += this.mSelectionBottomPadding;
boolean superIsSelectedChildViewEnabled = superIsSelectedChildViewEnabled();
if (view.isEnabled() != superIsSelectedChildViewEnabled) {
superSetSelectedChildViewEnabled(!superIsSelectedChildViewEnabled);
if (i != -1) {
refreshDrawableState();
}
}
}
private void clearPressedItem() {
this.mDrawsInPressedState = false;
setPressed(false);
drawableStateChanged();
View childAt = getChildAt(this.mMotionPosition - getFirstVisiblePosition());
if (childAt != null) {
childAt.setPressed(false);
}
ViewPropertyAnimatorCompat viewPropertyAnimatorCompat = this.mClickAnimation;
if (viewPropertyAnimatorCompat != null) {
viewPropertyAnimatorCompat.cancel();
this.mClickAnimation = null;
}
}
private void setPressedItem(View view, int i, float f, float f2) {
View childAt;
this.mDrawsInPressedState = true;
Api21Impl.drawableHotspotChanged(this, f, f2);
if (!isPressed()) {
setPressed(true);
}
layoutChildren();
int i2 = this.mMotionPosition;
if (i2 != -1 && (childAt = getChildAt(i2 - getFirstVisiblePosition())) != null && childAt != view && childAt.isPressed()) {
childAt.setPressed(false);
}
this.mMotionPosition = i;
Api21Impl.drawableHotspotChanged(view, f - view.getLeft(), f2 - view.getTop());
if (!view.isPressed()) {
view.setPressed(true);
}
positionSelectorLikeTouchCompat(i, view, f, f2);
setSelectorEnabled(false);
refreshDrawableState();
}
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes.dex */
public class ResolveHoverRunnable implements Runnable {
ResolveHoverRunnable() {
}
@Override // java.lang.Runnable
public void run() {
DropDownListView.this.mResolveHoverRunnable = null;
DropDownListView.this.drawableStateChanged();
}
public void cancel() {
DropDownListView.this.mResolveHoverRunnable = null;
DropDownListView.this.removeCallbacks(this);
}
public void post() {
DropDownListView.this.post(this);
}
}
/* loaded from: classes.dex */
static class Api30Impl {
private static boolean sHasMethods;
private static Method sPositionSelector;
private static Method sSetNextSelectedPositionInt;
private static Method sSetSelectedPositionInt;
static boolean canPositionSelectorForHoveredItem() {
return sHasMethods;
}
static {
try {
Method declaredMethod = AbsListView.class.getDeclaredMethod("positionSelector", Integer.TYPE, View.class, Boolean.TYPE, Float.TYPE, Float.TYPE);
sPositionSelector = declaredMethod;
declaredMethod.setAccessible(true);
Method declaredMethod2 = AdapterView.class.getDeclaredMethod("setSelectedPositionInt", Integer.TYPE);
sSetSelectedPositionInt = declaredMethod2;
declaredMethod2.setAccessible(true);
Method declaredMethod3 = AdapterView.class.getDeclaredMethod("setNextSelectedPositionInt", Integer.TYPE);
sSetNextSelectedPositionInt = declaredMethod3;
declaredMethod3.setAccessible(true);
sHasMethods = true;
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
private Api30Impl() {
}
static void positionSelectorForHoveredItem(DropDownListView dropDownListView, int i, View view) {
try {
sPositionSelector.invoke(dropDownListView, Integer.valueOf(i), view, false, -1, -1);
sSetSelectedPositionInt.invoke(dropDownListView, Integer.valueOf(i));
sSetNextSelectedPositionInt.invoke(dropDownListView, Integer.valueOf(i));
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e2) {
e2.printStackTrace();
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public static class Api21Impl {
private Api21Impl() {
}
static void drawableHotspotChanged(View view, float f, float f2) {
view.drawableHotspotChanged(f, f2);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public static class PreApi33Impl {
private static final Field sIsChildViewEnabled;
static {
Field field = null;
try {
field = AbsListView.class.getDeclaredField("mIsChildViewEnabled");
field.setAccessible(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
sIsChildViewEnabled = field;
}
private PreApi33Impl() {
}
static boolean isSelectedChildViewEnabled(AbsListView absListView) {
Field field = sIsChildViewEnabled;
if (field == null) {
return false;
}
try {
return field.getBoolean(absListView);
} catch (IllegalAccessException e) {
e.printStackTrace();
return false;
}
}
static void setSelectedChildViewEnabled(AbsListView absListView, boolean z) {
Field field = sIsChildViewEnabled;
if (field != null) {
try {
field.set(absListView, Boolean.valueOf(z));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public static class Api33Impl {
private Api33Impl() {
}
static boolean isSelectedChildViewEnabled(AbsListView absListView) {
return absListView.isSelectedChildViewEnabled();
}
static void setSelectedChildViewEnabled(AbsListView absListView, boolean z) {
absListView.setSelectedChildViewEnabled(z);
}
}
}