188 lines
6.0 KiB
Java
188 lines
6.0 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.core.view.ViewCompat;
|
|
import androidx.core.view.ViewConfigurationCompat;
|
|
|
|
/* loaded from: classes.dex */
|
|
class TooltipCompatHandler implements View.OnLongClickListener, View.OnHoverListener, View.OnAttachStateChangeListener {
|
|
private static TooltipCompatHandler j;
|
|
private static TooltipCompatHandler k;
|
|
private final View a;
|
|
private final CharSequence b;
|
|
private final int c;
|
|
private final Runnable d = new Runnable() { // from class: androidx.appcompat.widget.TooltipCompatHandler.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
TooltipCompatHandler.this.a(false);
|
|
}
|
|
};
|
|
private final Runnable e = new Runnable() { // from class: androidx.appcompat.widget.TooltipCompatHandler.2
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
TooltipCompatHandler.this.a();
|
|
}
|
|
};
|
|
private int f;
|
|
private int g;
|
|
private TooltipPopup h;
|
|
private boolean i;
|
|
|
|
private TooltipCompatHandler(View view, CharSequence charSequence) {
|
|
this.a = view;
|
|
this.b = charSequence;
|
|
this.c = ViewConfigurationCompat.a(ViewConfiguration.get(this.a.getContext()));
|
|
c();
|
|
this.a.setOnLongClickListener(this);
|
|
this.a.setOnHoverListener(this);
|
|
}
|
|
|
|
public static void a(View view, CharSequence charSequence) {
|
|
TooltipCompatHandler tooltipCompatHandler = j;
|
|
if (tooltipCompatHandler != null && tooltipCompatHandler.a == view) {
|
|
a((TooltipCompatHandler) null);
|
|
}
|
|
if (!TextUtils.isEmpty(charSequence)) {
|
|
new TooltipCompatHandler(view, charSequence);
|
|
return;
|
|
}
|
|
TooltipCompatHandler tooltipCompatHandler2 = k;
|
|
if (tooltipCompatHandler2 != null && tooltipCompatHandler2.a == view) {
|
|
tooltipCompatHandler2.a();
|
|
}
|
|
view.setOnLongClickListener(null);
|
|
view.setLongClickable(false);
|
|
view.setOnHoverListener(null);
|
|
}
|
|
|
|
private void b() {
|
|
this.a.removeCallbacks(this.d);
|
|
}
|
|
|
|
private void c() {
|
|
this.f = Integer.MAX_VALUE;
|
|
this.g = Integer.MAX_VALUE;
|
|
}
|
|
|
|
private void d() {
|
|
this.a.postDelayed(this.d, ViewConfiguration.getLongPressTimeout());
|
|
}
|
|
|
|
@Override // android.view.View.OnHoverListener
|
|
public boolean onHover(View view, MotionEvent motionEvent) {
|
|
if (this.h != null && this.i) {
|
|
return false;
|
|
}
|
|
AccessibilityManager accessibilityManager = (AccessibilityManager) this.a.getContext().getSystemService("accessibility");
|
|
if (accessibilityManager.isEnabled() && accessibilityManager.isTouchExplorationEnabled()) {
|
|
return false;
|
|
}
|
|
int action = motionEvent.getAction();
|
|
if (action != 7) {
|
|
if (action == 10) {
|
|
c();
|
|
a();
|
|
}
|
|
} else if (this.a.isEnabled() && this.h == null && a(motionEvent)) {
|
|
a(this);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // android.view.View.OnLongClickListener
|
|
public boolean onLongClick(View view) {
|
|
this.f = view.getWidth() / 2;
|
|
this.g = view.getHeight() / 2;
|
|
a(true);
|
|
return true;
|
|
}
|
|
|
|
@Override // android.view.View.OnAttachStateChangeListener
|
|
public void onViewAttachedToWindow(View view) {
|
|
}
|
|
|
|
@Override // android.view.View.OnAttachStateChangeListener
|
|
public void onViewDetachedFromWindow(View view) {
|
|
a();
|
|
}
|
|
|
|
void a(boolean z) {
|
|
long j2;
|
|
int longPressTimeout;
|
|
long j3;
|
|
if (ViewCompat.w(this.a)) {
|
|
a((TooltipCompatHandler) null);
|
|
TooltipCompatHandler tooltipCompatHandler = k;
|
|
if (tooltipCompatHandler != null) {
|
|
tooltipCompatHandler.a();
|
|
}
|
|
k = this;
|
|
this.i = z;
|
|
this.h = new TooltipPopup(this.a.getContext());
|
|
this.h.a(this.a, this.f, this.g, this.i, this.b);
|
|
this.a.addOnAttachStateChangeListener(this);
|
|
if (this.i) {
|
|
j3 = 2500;
|
|
} else {
|
|
if ((ViewCompat.q(this.a) & 1) == 1) {
|
|
j2 = 3000;
|
|
longPressTimeout = ViewConfiguration.getLongPressTimeout();
|
|
} else {
|
|
j2 = 15000;
|
|
longPressTimeout = ViewConfiguration.getLongPressTimeout();
|
|
}
|
|
j3 = j2 - longPressTimeout;
|
|
}
|
|
this.a.removeCallbacks(this.e);
|
|
this.a.postDelayed(this.e, j3);
|
|
}
|
|
}
|
|
|
|
void a() {
|
|
if (k == this) {
|
|
k = null;
|
|
TooltipPopup tooltipPopup = this.h;
|
|
if (tooltipPopup != null) {
|
|
tooltipPopup.a();
|
|
this.h = null;
|
|
c();
|
|
this.a.removeOnAttachStateChangeListener(this);
|
|
} else {
|
|
Log.e("TooltipCompatHandler", "sActiveHandler.mPopup == null");
|
|
}
|
|
}
|
|
if (j == this) {
|
|
a((TooltipCompatHandler) null);
|
|
}
|
|
this.a.removeCallbacks(this.e);
|
|
}
|
|
|
|
private static void a(TooltipCompatHandler tooltipCompatHandler) {
|
|
TooltipCompatHandler tooltipCompatHandler2 = j;
|
|
if (tooltipCompatHandler2 != null) {
|
|
tooltipCompatHandler2.b();
|
|
}
|
|
j = tooltipCompatHandler;
|
|
TooltipCompatHandler tooltipCompatHandler3 = j;
|
|
if (tooltipCompatHandler3 != null) {
|
|
tooltipCompatHandler3.d();
|
|
}
|
|
}
|
|
|
|
private boolean a(MotionEvent motionEvent) {
|
|
int x = (int) motionEvent.getX();
|
|
int y = (int) motionEvent.getY();
|
|
if (Math.abs(x - this.f) <= this.c && Math.abs(y - this.g) <= this.c) {
|
|
return false;
|
|
}
|
|
this.f = x;
|
|
this.g = y;
|
|
return true;
|
|
}
|
|
}
|