151 lines
5.8 KiB
Java
151 lines
5.8 KiB
Java
package io.flutter.embedding.engine.mutatorsstack;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Matrix;
|
|
import android.graphics.Path;
|
|
import android.view.MotionEvent;
|
|
import android.view.View;
|
|
import android.view.ViewTreeObserver;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
import android.widget.FrameLayout;
|
|
import io.flutter.embedding.android.AndroidTouchProcessor;
|
|
import io.flutter.util.ViewUtils;
|
|
import java.util.Iterator;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class FlutterMutatorView extends FrameLayout {
|
|
ViewTreeObserver.OnGlobalFocusChangeListener activeFocusListener;
|
|
private final AndroidTouchProcessor androidTouchProcessor;
|
|
private int left;
|
|
private FlutterMutatorsStack mutatorsStack;
|
|
private int prevLeft;
|
|
private int prevTop;
|
|
private float screenDensity;
|
|
private int top;
|
|
|
|
@Override // android.view.ViewGroup
|
|
public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
|
|
return true;
|
|
}
|
|
|
|
public FlutterMutatorView(Context context, float f, AndroidTouchProcessor androidTouchProcessor) {
|
|
super(context, null);
|
|
this.screenDensity = f;
|
|
this.androidTouchProcessor = androidTouchProcessor;
|
|
}
|
|
|
|
public FlutterMutatorView(Context context) {
|
|
this(context, 1.0f, null);
|
|
}
|
|
|
|
public void setOnDescendantFocusChangeListener(View.OnFocusChangeListener onFocusChangeListener) {
|
|
unsetOnDescendantFocusChangeListener();
|
|
ViewTreeObserver viewTreeObserver = getViewTreeObserver();
|
|
if (viewTreeObserver.isAlive() && this.activeFocusListener == null) {
|
|
ViewTreeObserver.OnGlobalFocusChangeListener onGlobalFocusChangeListener = new ViewTreeObserver.OnGlobalFocusChangeListener(this, onFocusChangeListener, this) { // from class: io.flutter.embedding.engine.mutatorsstack.FlutterMutatorView.1
|
|
final FlutterMutatorView this$0;
|
|
final View val$mutatorView;
|
|
final View.OnFocusChangeListener val$userFocusListener;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$userFocusListener = onFocusChangeListener;
|
|
this.val$mutatorView = this;
|
|
}
|
|
|
|
@Override // android.view.ViewTreeObserver.OnGlobalFocusChangeListener
|
|
public void onGlobalFocusChanged(View view, View view2) {
|
|
View.OnFocusChangeListener onFocusChangeListener2 = this.val$userFocusListener;
|
|
View view3 = this.val$mutatorView;
|
|
onFocusChangeListener2.onFocusChange(view3, ViewUtils.childHasFocus(view3));
|
|
}
|
|
};
|
|
this.activeFocusListener = onGlobalFocusChangeListener;
|
|
viewTreeObserver.addOnGlobalFocusChangeListener(onGlobalFocusChangeListener);
|
|
}
|
|
}
|
|
|
|
public void unsetOnDescendantFocusChangeListener() {
|
|
ViewTreeObserver.OnGlobalFocusChangeListener onGlobalFocusChangeListener;
|
|
ViewTreeObserver viewTreeObserver = getViewTreeObserver();
|
|
if (!viewTreeObserver.isAlive() || (onGlobalFocusChangeListener = this.activeFocusListener) == null) {
|
|
return;
|
|
}
|
|
this.activeFocusListener = null;
|
|
viewTreeObserver.removeOnGlobalFocusChangeListener(onGlobalFocusChangeListener);
|
|
}
|
|
|
|
public void readyToDisplay(FlutterMutatorsStack flutterMutatorsStack, int i, int i2, int i3, int i4) {
|
|
this.mutatorsStack = flutterMutatorsStack;
|
|
this.left = i;
|
|
this.top = i2;
|
|
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(i3, i4);
|
|
layoutParams.leftMargin = i;
|
|
layoutParams.topMargin = i2;
|
|
setLayoutParams(layoutParams);
|
|
setWillNotDraw(false);
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void draw(Canvas canvas) {
|
|
canvas.save();
|
|
Iterator<Path> it = this.mutatorsStack.getFinalClippingPaths().iterator();
|
|
while (it.hasNext()) {
|
|
Path path = new Path(it.next());
|
|
path.offset(-this.left, -this.top);
|
|
canvas.clipPath(path);
|
|
}
|
|
super.draw(canvas);
|
|
canvas.restore();
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
public void dispatchDraw(Canvas canvas) {
|
|
canvas.save();
|
|
canvas.concat(getPlatformViewMatrix());
|
|
super.dispatchDraw(canvas);
|
|
canvas.restore();
|
|
}
|
|
|
|
private Matrix getPlatformViewMatrix() {
|
|
Matrix matrix = new Matrix(this.mutatorsStack.getFinalMatrix());
|
|
float f = 1.0f / this.screenDensity;
|
|
matrix.preScale(f, f);
|
|
matrix.postTranslate(-this.left, -this.top);
|
|
return matrix;
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.ViewParent
|
|
public boolean requestSendAccessibilityEvent(View view, AccessibilityEvent accessibilityEvent) {
|
|
View childAt = getChildAt(0);
|
|
if (childAt == null || childAt.getImportantForAccessibility() != 4) {
|
|
return super.requestSendAccessibilityEvent(view, accessibilityEvent);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public boolean onTouchEvent(MotionEvent motionEvent) {
|
|
if (this.androidTouchProcessor == null) {
|
|
return super.onTouchEvent(motionEvent);
|
|
}
|
|
Matrix matrix = new Matrix();
|
|
int action = motionEvent.getAction();
|
|
if (action == 0) {
|
|
int i = this.left;
|
|
this.prevLeft = i;
|
|
int i2 = this.top;
|
|
this.prevTop = i2;
|
|
matrix.postTranslate(i, i2);
|
|
} else if (action == 2) {
|
|
matrix.postTranslate(this.prevLeft, this.prevTop);
|
|
this.prevLeft = this.left;
|
|
this.prevTop = this.top;
|
|
} else {
|
|
matrix.postTranslate(this.left, this.top);
|
|
}
|
|
return this.androidTouchProcessor.onTouchEvent(motionEvent, matrix);
|
|
}
|
|
}
|