discord-jadx/app/src/main/java/androidx/appcompat/widget/TooltipCompatHandler.java

204 lines
7.4 KiB
Java

package androidx.appcompat.widget;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityManager;
import androidx.annotation.RestrictTo;
import androidx.core.view.ViewCompat;
import androidx.core.view.ViewConfigurationCompat;
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
public class TooltipCompatHandler implements View.OnLongClickListener, View.OnHoverListener, View.OnAttachStateChangeListener {
private static final long HOVER_HIDE_TIMEOUT_MS = 15000;
private static final long HOVER_HIDE_TIMEOUT_SHORT_MS = 3000;
private static final long LONG_CLICK_HIDE_TIMEOUT_MS = 2500;
private static final String TAG = "TooltipCompatHandler";
private static TooltipCompatHandler sActiveHandler;
private static TooltipCompatHandler sPendingHandler;
private final View mAnchor;
private int mAnchorX;
private int mAnchorY;
private boolean mFromTouch;
private final Runnable mHideRunnable = new AnonymousClass2();
private final int mHoverSlop;
private TooltipPopup mPopup;
private final Runnable mShowRunnable = new AnonymousClass1();
private final CharSequence mTooltipText;
/* renamed from: androidx.appcompat.widget.TooltipCompatHandler$1 reason: invalid class name */
public class AnonymousClass1 implements Runnable {
public AnonymousClass1() {
}
@Override // java.lang.Runnable
public void run() {
TooltipCompatHandler.this.show(false);
}
}
/* renamed from: androidx.appcompat.widget.TooltipCompatHandler$2 reason: invalid class name */
public class AnonymousClass2 implements Runnable {
public AnonymousClass2() {
}
@Override // java.lang.Runnable
public void run() {
TooltipCompatHandler.this.hide();
}
}
private TooltipCompatHandler(View view, CharSequence charSequence) {
this.mAnchor = view;
this.mTooltipText = charSequence;
this.mHoverSlop = ViewConfigurationCompat.getScaledHoverSlop(ViewConfiguration.get(view.getContext()));
clearAnchorPos();
view.setOnLongClickListener(this);
view.setOnHoverListener(this);
}
private void cancelPendingShow() {
this.mAnchor.removeCallbacks(this.mShowRunnable);
}
private void clearAnchorPos() {
this.mAnchorX = Integer.MAX_VALUE;
this.mAnchorY = Integer.MAX_VALUE;
}
private void scheduleShow() {
this.mAnchor.postDelayed(this.mShowRunnable, (long) ViewConfiguration.getLongPressTimeout());
}
private static void setPendingHandler(TooltipCompatHandler tooltipCompatHandler) {
TooltipCompatHandler tooltipCompatHandler2 = sPendingHandler;
if (tooltipCompatHandler2 != null) {
tooltipCompatHandler2.cancelPendingShow();
}
sPendingHandler = tooltipCompatHandler;
if (tooltipCompatHandler != null) {
tooltipCompatHandler.scheduleShow();
}
}
public static void setTooltipText(View view, CharSequence charSequence) {
TooltipCompatHandler tooltipCompatHandler = sPendingHandler;
if (tooltipCompatHandler != null && tooltipCompatHandler.mAnchor == view) {
setPendingHandler(null);
}
if (TextUtils.isEmpty(charSequence)) {
TooltipCompatHandler tooltipCompatHandler2 = sActiveHandler;
if (tooltipCompatHandler2 != null && tooltipCompatHandler2.mAnchor == view) {
tooltipCompatHandler2.hide();
}
view.setOnLongClickListener(null);
view.setLongClickable(false);
view.setOnHoverListener(null);
return;
}
new TooltipCompatHandler(view, charSequence);
}
private boolean updateAnchorPos(MotionEvent motionEvent) {
int x2 = (int) motionEvent.getX();
int y2 = (int) motionEvent.getY();
if (Math.abs(x2 - this.mAnchorX) <= this.mHoverSlop && Math.abs(y2 - this.mAnchorY) <= this.mHoverSlop) {
return false;
}
this.mAnchorX = x2;
this.mAnchorY = y2;
return true;
}
public void hide() {
if (sActiveHandler == this) {
sActiveHandler = null;
TooltipPopup tooltipPopup = this.mPopup;
if (tooltipPopup != null) {
tooltipPopup.hide();
this.mPopup = null;
clearAnchorPos();
this.mAnchor.removeOnAttachStateChangeListener(this);
} else {
Log.e(TAG, "sActiveHandler.mPopup == null");
}
}
if (sPendingHandler == this) {
setPendingHandler(null);
}
this.mAnchor.removeCallbacks(this.mHideRunnable);
}
@Override // android.view.View.OnHoverListener
public boolean onHover(View view, MotionEvent motionEvent) {
if (this.mPopup != null && this.mFromTouch) {
return false;
}
AccessibilityManager accessibilityManager = (AccessibilityManager) this.mAnchor.getContext().getSystemService("accessibility");
if (accessibilityManager.isEnabled() && accessibilityManager.isTouchExplorationEnabled()) {
return false;
}
int action = motionEvent.getAction();
if (action != 7) {
if (action == 10) {
clearAnchorPos();
hide();
}
} else if (this.mAnchor.isEnabled() && this.mPopup == null && updateAnchorPos(motionEvent)) {
setPendingHandler(this);
}
return false;
}
@Override // android.view.View.OnLongClickListener
public boolean onLongClick(View view) {
this.mAnchorX = view.getWidth() / 2;
this.mAnchorY = view.getHeight() / 2;
show(true);
return true;
}
@Override // android.view.View.OnAttachStateChangeListener
public void onViewAttachedToWindow(View view) {
}
@Override // android.view.View.OnAttachStateChangeListener
public void onViewDetachedFromWindow(View view) {
hide();
}
public void show(boolean z2) {
long j;
int i;
long j2;
if (ViewCompat.isAttachedToWindow(this.mAnchor)) {
setPendingHandler(null);
TooltipCompatHandler tooltipCompatHandler = sActiveHandler;
if (tooltipCompatHandler != null) {
tooltipCompatHandler.hide();
}
sActiveHandler = this;
this.mFromTouch = z2;
TooltipPopup tooltipPopup = new TooltipPopup(this.mAnchor.getContext());
this.mPopup = tooltipPopup;
tooltipPopup.show(this.mAnchor, this.mAnchorX, this.mAnchorY, this.mFromTouch, this.mTooltipText);
this.mAnchor.addOnAttachStateChangeListener(this);
if (this.mFromTouch) {
j = LONG_CLICK_HIDE_TIMEOUT_MS;
} else {
if ((ViewCompat.getWindowSystemUiVisibility(this.mAnchor) & 1) == 1) {
j2 = HOVER_HIDE_TIMEOUT_SHORT_MS;
i = ViewConfiguration.getLongPressTimeout();
} else {
j2 = HOVER_HIDE_TIMEOUT_MS;
i = ViewConfiguration.getLongPressTimeout();
}
j = j2 - ((long) i);
}
this.mAnchor.removeCallbacks(this.mHideRunnable);
this.mAnchor.postDelayed(this.mHideRunnable, j);
}
}
}