com.eg.agent.android.instrumentation.InstrumentView Maven / Gradle / Ivy
The newest version!
/*
* Decompiled with CFR 0.137.
*
* Could not load the following classes:
* android.view.View
* android.view.View$OnClickListener
* android.view.View$OnLongClickListener
* android.view.View$OnTouchListener
* android.view.ViewStub
*/
package com.eg.agent.android.instrumentation;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.view.View;
import android.view.ViewStub;
import androidx.fragment.app.Fragment;
import com.eg.agent.android.gestures.GestureReporter;
import com.eg.agent.android.instrumentation.ViewListeners;
import com.eg.agent.android.Features;
import com.eg.agent.android.util.Utils;
import java.util.Set;
public class InstrumentView {
static final String ON_TOUCH_LISTENER_FIELD = "onTouchListener";
static final String ON_CLICK_LISTENER_FIELD = "mOnClickListener";
static final String ON_LONG_CLICK_LISTENER_FIELD = "mOnLongClickListener";
private static final String VIEW_CLASS_NAME = "android.view.View";
private static final String LISTENER_INFO_FIELD_NAME = "mListenerInfo";
private static final String ANDROID_VIEW_LISTENER_INFO = "android.view.View$ListenerInfo";
InstrumentView() {
}
public static final View inflate(ViewStub viewStub) {
View view = viewStub.inflate();
GestureReporter gestureReporter = GestureReporter.getGestureReporter();
if (gestureReporter != null) {
gestureReporter.addView(view);
}
return view;
}
public static final void setOnTouchListener(View view, View.OnTouchListener listener) {
try {
if (Utils.isExcluded(getActivity(view))) {
return;
}
if (Features.featureEnabled(Features.GestureInstrumentation)) {
View.OnTouchListener current = (View.OnTouchListener)InstrumentView.getViewListener(view, ON_TOUCH_LISTENER_FIELD);
if (current == null) {
ViewListeners.OnTouchListenerDelegate delegate = new ViewListeners.OnTouchListenerDelegate(view, listener);
view.setOnTouchListener((View.OnTouchListener)delegate);
} else if (current instanceof ViewListeners.OnTouchListenerDelegate) {
ViewListeners.OnTouchListenerDelegate delegate = (ViewListeners.OnTouchListenerDelegate)current;
delegate.addListener(listener);
} else {
ViewListeners.OnTouchListenerDelegate delegate = new ViewListeners.OnTouchListenerDelegate(view, current);
delegate.addListener(listener);
view.setOnTouchListener((View.OnTouchListener)delegate);
}
} else {
view.setOnTouchListener(listener);
}
}
catch (NoSuchFieldError e) {
view.setOnTouchListener(listener);
}
}
public static final void setOnClickListener(View view, View.OnClickListener listener) {
try {
if(Utils.isExcluded(getActivity(view))) {
return;
}
if (Features.featureEnabled(Features.GestureInstrumentation)) {
View.OnClickListener current = (View.OnClickListener)InstrumentView.getViewListener(view, ON_CLICK_LISTENER_FIELD);
if (current == null) {
ViewListeners.OnClickListenerDelegate delegate = new ViewListeners.OnClickListenerDelegate(view, listener);
view.setOnClickListener((View.OnClickListener)delegate);
} else if (current instanceof ViewListeners.OnClickListenerDelegate) {
ViewListeners.OnClickListenerDelegate delegate = (ViewListeners.OnClickListenerDelegate)current;
delegate.addListener(listener);
} else {
ViewListeners.OnClickListenerDelegate delegate = new ViewListeners.OnClickListenerDelegate(view, current);
delegate.addListener(listener);
view.setOnClickListener((View.OnClickListener)delegate);
}
} else {
view.setOnClickListener(listener);
}
}
catch (Exception e) {
view.setOnClickListener(listener);
}
}
public static String getActivity(View view) {
Context context = view.getContext();
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
return ((Activity)context).getClass().getName().replaceAll("\\.", "/").trim();
}
context = ((ContextWrapper)context).getBaseContext();
}
return "";
}
public static final void setOnLongClickListener(View view, View.OnLongClickListener listener) {
try {
if(Utils.isExcluded(getActivity(view))) {
return;
}
if (Features.featureEnabled(Features.GestureInstrumentation)) {
View.OnLongClickListener current = (View.OnLongClickListener)InstrumentView.getViewListener(view, ON_LONG_CLICK_LISTENER_FIELD);
if (current == null) {
ViewListeners.OnLongClickListenerDelegate delegate = new ViewListeners.OnLongClickListenerDelegate(view, listener);
view.setOnLongClickListener((View.OnLongClickListener)delegate);
} else if (current instanceof ViewListeners.OnLongClickListenerDelegate) {
ViewListeners.OnLongClickListenerDelegate delegate = (ViewListeners.OnLongClickListenerDelegate)current;
delegate.addListener(listener);
} else {
ViewListeners.OnLongClickListenerDelegate delegate = new ViewListeners.OnLongClickListenerDelegate(view, current);
delegate.addListener(listener);
view.setOnLongClickListener((View.OnLongClickListener)delegate);
}
} else {
view.setOnLongClickListener(listener);
}
}
catch (NoSuchFieldError e) {
view.setOnLongClickListener(listener);
}
}
static Object getViewListener(View view, String listenerFieldname) {
Object returnedField = null;
return returnedField;
}
}