6
6
import android .support .v7 .app .AlertDialog ;
7
7
import android .support .v7 .widget .Toolbar ;
8
8
import android .view .View ;
9
- import android .widget .ArrayAdapter ;
10
- import android .widget .Toast ;
11
9
12
10
import com .example .instabug .BaseActivity ;
13
11
import com .example .instabug .R ;
12
+ import com .instabug .bug .BugReporting ;
14
13
import com .instabug .library .Instabug ;
15
14
import com .instabug .library .InstabugColorTheme ;
16
15
import com .instabug .library .invocation .InstabugInvocationEvent ;
17
16
17
+ import java .util .ArrayList ;
18
+ import java .util .Arrays ;
19
+
18
20
import petrov .kristiyan .colorpicker .ColorPicker ;
19
21
20
22
public class SettingsActivity extends BaseActivity {
23
+
24
+ final String [] invocationEvents = getInvocationEventsNames (InstabugInvocationEvent .class );
25
+ final boolean [] invocationEventsState = {false , false , false , false , false };
26
+
21
27
@ Override
22
28
protected void onCreate (@ Nullable Bundle savedInstanceState ) {
23
29
super .onCreate (savedInstanceState );
@@ -26,37 +32,45 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
26
32
Toolbar toolbar = findViewById (R .id .toolbar );
27
33
setSupportActionBar (toolbar );
28
34
35
+
36
+ for (int i = 0 ; i < invocationEvents .length ; i ++) {
37
+ invocationEvents [i ] = invocationEvents [i ].replace ("_" , " " );
38
+ }
29
39
}
30
40
31
41
public void onShowInvocationEventsClicked (View view ) {
32
- final CharSequence [] items = {"Shake" , "Floating Button" , "Screenshot" , "Two Finger Swipe" , "None" };
33
-
42
+ // reset events
43
+ for (int i = 0 ; i < invocationEventsState .length ; i ++) {
44
+ invocationEventsState [i ] = false ;
45
+ }
34
46
AlertDialog .Builder builder = new AlertDialog .Builder (this );
35
- builder .setTitle ("Select Invocation Event" );
36
- builder .setItems (items , new DialogInterface .OnClickListener () {
37
- public void onClick (DialogInterface dialog , int item ) {
38
- switch (item ) {
39
- case 0 :
40
- Instabug .changeInvocationEvent (InstabugInvocationEvent .SHAKE );
41
- break ;
42
- case 1 :
43
- Instabug .changeInvocationEvent (InstabugInvocationEvent .FLOATING_BUTTON );
44
- break ;
45
- case 2 :
46
- Instabug .changeInvocationEvent (InstabugInvocationEvent .SCREENSHOT_GESTURE );
47
- break ;
48
- case 3 :
49
- Instabug .changeInvocationEvent (InstabugInvocationEvent .TWO_FINGER_SWIPE_LEFT );
50
- break ;
51
- case 4 :
52
- Instabug .changeInvocationEvent (InstabugInvocationEvent .NONE );
53
- break ;
47
+ builder .setTitle ("Select Invocation Events" );
48
+ builder .setMultiChoiceItems (invocationEvents , null , new DialogInterface .OnMultiChoiceClickListener () {
49
+ @ Override
50
+ public void onClick (DialogInterface dialog , int which , boolean isChecked ) {
51
+ invocationEventsState [which ] = isChecked ;
52
+ }
53
+ });
54
+ builder .setPositiveButton ("Done" , new DialogInterface .OnClickListener () {
55
+ @ Override
56
+ public void onClick (DialogInterface dialog , int which ) {
57
+ ArrayList <InstabugInvocationEvent > selectedEvents = new ArrayList ();
58
+ for (int i = 0 ; i < invocationEvents .length ; i ++) {
59
+ if (invocationEventsState [i ]) {
60
+ selectedEvents .add (InstabugInvocationEvent .valueOf (invocationEvents [i ].toUpperCase ().replace (" " , "_" )));
61
+ }
54
62
}
63
+ // set new invocation events here
64
+ BugReporting .setInvocationEvents (selectedEvents .toArray (new InstabugInvocationEvent [selectedEvents .size ()]));
55
65
}
56
66
});
57
67
builder .show ();
58
68
}
59
69
70
+ public static String [] getInvocationEventsNames (Class <? extends Enum <?>> e ) {
71
+ return Arrays .toString (e .getEnumConstants ()).replaceAll ("^.|.$" , "" ).split (", " );
72
+ }
73
+
60
74
public void onChangeThemeClicked (View view ) {
61
75
final CharSequence [] items = {"Light" , "Dark" };
62
76
@@ -66,10 +80,10 @@ public void onChangeThemeClicked(View view) {
66
80
public void onClick (DialogInterface dialog , int item ) {
67
81
switch (item ) {
68
82
case 0 :
69
- Instabug .setTheme (InstabugColorTheme .InstabugColorThemeLight );
83
+ Instabug .setColorTheme (InstabugColorTheme .InstabugColorThemeLight );
70
84
break ;
71
85
case 1 :
72
- Instabug .setTheme (InstabugColorTheme .InstabugColorThemeDark );
86
+ Instabug .setColorTheme (InstabugColorTheme .InstabugColorThemeDark );
73
87
break ;
74
88
}
75
89
}
@@ -83,9 +97,7 @@ public void onChangePrimaryColorClicked(View view) {
83
97
colorPicker .setOnChooseColorListener (new ColorPicker .OnChooseColorListener () {
84
98
@ Override
85
99
public void onChooseColor (int position , int color ) {
86
- Instabug .disable ();
87
100
Instabug .setPrimaryColor (color );
88
- Instabug .enable ();
89
101
}
90
102
91
103
@ Override
0 commit comments