1111import com .instabug .library .Instabug ;
1212import com .instabug .library .invocation .InstabugInvocationEvent ;
1313
14+ import java .lang .reflect .Array ;
15+ import java .lang .reflect .InvocationTargetException ;
16+ import java .lang .reflect .Method ;
17+ import java .lang .reflect .Parameter ;
1418import java .util .ArrayList ;
1519import java .util .Arrays ;
1620import java .util .Collections ;
21+ import java .util .HashMap ;
22+ import java .util .Iterator ;
1723import java .util .List ;
24+ import java .util .Map ;
25+
26+ import android .os .Handler ;
27+ import android .os .Looper ;
28+ import android .util .Log ;
1829
1930// import com.instabug.library.InstabugColorTheme;
2031// import com.instabug.library.InstabugCustomTextPlaceHolder;
2334
2435/** InstabugFlutterPlugin */
2536public class InstabugFlutterPlugin implements MethodCallHandler {
26-
27- private ArrayList <InstabugInvocationEvent > invocationEvents = new ArrayList <>();
37+
38+ final public static String INVOCATION_EVENT_NONE = "InvocationEvent.none" ;
39+ final public static String INVOCATION_EVENT_SCREENSHOT = "InvocationEvent.screenshot" ;
40+ final public static String INVOCATION_EVENT_TWO_FINGER_SWIPE_LEFT = "InvocationEvent.twoFingersSwipeLeft" ;
41+ final public static String INVOCATION_EVENT_FLOATING_BUTTON = "InvocationEvent.floatingButton" ;
42+ final public static String INVOCATION_EVENT_SHAKE = "InvocationEvent.shake" ;
43+
44+ private Map <String , Object > constants = getConstants ();
2845
2946 /** Plugin registration. */
3047 public static void registerWith (Registrar registrar ) {
@@ -34,14 +51,62 @@ public static void registerWith(Registrar registrar) {
3451
3552 @ Override
3653 public void onMethodCall (MethodCall call , Result result ) {
37- if (call .method .equals ("start" )) {
38- result .success (null );
39- } else {
54+ Method [] methods = this .getClass ().getMethods ();
55+ boolean isImplemented = false ;
56+ String callMethod = call .method ;
57+ if (callMethod .contains (":" )) {
58+ callMethod = call .method .substring ( 0 , call .method .indexOf (":" ));
59+ }
60+ for (Method method : methods ) {
61+ if (callMethod .equals (method .getName ())) {
62+ isImplemented = true ;
63+ ArrayList <Object > tempParamValues = new ArrayList <>();
64+ HashMap map = (HashMap <String , String >)call .arguments ;
65+ Iterator iterator = map .entrySet ().iterator ();
66+ while (iterator .hasNext ()) {
67+ Map .Entry pair = (Map .Entry )iterator .next ();
68+ tempParamValues .add (pair .getValue ());
69+ iterator .remove ();
70+ }
71+ Object [] paramValues = tempParamValues .toArray ();
72+ try {
73+ method .invoke (this , paramValues );
74+ } catch (Exception e ) {
75+ e .printStackTrace ();
76+ result .notImplemented ();
77+ }
78+ result .success (null );
79+ break ;
80+ }
81+ }
82+ if (!isImplemented ) {
4083 result .notImplemented ();
4184 }
4285 }
43- public void start (Application application , String token ) {
44- new Instabug .Builder (application , token ).build ();
86+
87+ /**
88+ * starts the SDK
89+ * @param application the application Object
90+ * @param token token The token that identifies the app, you can find
91+ * it on your dashboard.
92+ * @param invocationEvents invocationEvents The events that invoke
93+ * the SDK's UI.
94+ */
95+ public void start (Application application , String token , ArrayList <String > invocationEvents ) {
96+ InstabugInvocationEvent [] invocationEventsArray = new InstabugInvocationEvent [invocationEvents .size ()];
97+ for (int i = 0 ; i < invocationEvents .size (); i ++) {
98+ invocationEventsArray [i ] = (InstabugInvocationEvent )constants .get (invocationEvents .get (i ));
99+ }
100+ new Instabug .Builder (application , token ).setInvocationEvents (invocationEventsArray ).build ();
45101 }
46102
103+ public Map <String , Object > getConstants () {
104+ final Map <String , Object > constants = new HashMap <>();
105+ constants .put ("InvocationEvent.none" , InstabugInvocationEvent .NONE );
106+ constants .put ("InvocationEvent.screenshot" , InstabugInvocationEvent .SCREENSHOT );
107+ constants .put ("InvocationEvent.twoFingersSwipeLeft" , InstabugInvocationEvent .TWO_FINGER_SWIPE_LEFT );
108+ constants .put ("InvocationEvent.floatingButton" , InstabugInvocationEvent .FLOATING_BUTTON );
109+ constants .put ("InvocationEvent.shake" , InstabugInvocationEvent .SHAKE );
110+ return constants ;
111+ }
47112}
0 commit comments