forked from david-byng/instabug-cordova-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInstabugPhoneGap.java
57 lines (52 loc) · 2.82 KB
/
InstabugPhoneGap.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.instabug.phonegap.android;
import com.instabug.library.Instabug;
import com.instabug.library.activity.InstabugAnnotationActivity;
import org.apache.cordova.*;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.graphics.Color;
public class InstabugPhoneGap extends CordovaPlugin {
CordovaInterface mCordova;
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
mCordova = cordova;
}
//{"emailEnabled":false, "showTutorial":true, "showIntroDialog":true, "barBackground" : "#FF0000", "barForeground": "#FFFFFF"}
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException{
if("init".equals(action)) {
JSONObject configJson = args.optJSONObject(0);
if(configJson == null) {
configJson = new JSONObject();
}
int barBackground = Color.parseColor(configJson.getString("barBackground"));
int barForeground = Color.parseColor(configJson.getString("barForeground"));
String bugHeaderText = configJson.getString("bugHeaderText");
Instabug.initialize(mCordova.getActivity().getApplication(), configJson.getString("androidToken"))
.setAnnotationActivityClass(InstabugAnnotationActivity.class)
.setInvocationEvent(Instabug.INVOCATION_SHAKE)
.setShowIntroDialog(configJson.optBoolean("showIntroDialog", true))
.enableEmailField(configJson.optBoolean("emailEnabled", true), configJson.optBoolean("emailRequired", false))
.setSdkStyleColors(0xFFFFFFFF, barBackground, barForeground, barBackground, barForeground)
.setShowPostFeedbackToast(true)
.setShowTutorial(configJson.optBoolean("showTutorial", true));
Instabug.getInstance().setActivity(mCordova.getActivity());
if(bugHeaderText != null && ! bugHeaderText.isEmpty()) {
Instabug.getInstance().setBugHeaderText(bugHeaderText);
}
if(bugHeaderText != null && ! bugHeaderText.isEmpty()) {
Instabug.getInstance().setBugHeaderText(bugHeaderText);
}
callbackContext.success();
} else if("invoke".equals(action)) {
Instabug.getInstance().invokeFeedbackProcess();
} else if("invokeFeedbackSender".equals(action)) {
Instabug.getInstance().invokeFeedbackProcess(Instabug.INSTABUG_FEEDBACK_FEEDBACK);
} else if("invokeBugReporter".equals(action)) {
Instabug.getInstance().invokeFeedbackProcess(Instabug.INSTABUG_FEEDBACK_BUG);
}
return super.execute(action, args, callbackContext);
}
}