66import android .support .v7 .app .AlertDialog ;
77import android .support .v7 .widget .Toolbar ;
88import android .view .View ;
9- import android .widget .ArrayAdapter ;
10- import android .widget .Toast ;
119
1210import com .example .instabug .BaseActivity ;
1311import com .example .instabug .R ;
12+ import com .instabug .bug .BugReporting ;
1413import com .instabug .library .Instabug ;
1514import com .instabug .library .InstabugColorTheme ;
1615import com .instabug .library .invocation .InstabugInvocationEvent ;
1716
17+ import java .util .ArrayList ;
18+ import java .util .Arrays ;
19+
1820import petrov .kristiyan .colorpicker .ColorPicker ;
1921
2022public class SettingsActivity extends BaseActivity {
23+
24+ final String [] invocationEvents = getInvocationEventsNames (InstabugInvocationEvent .class );
25+ final boolean [] invocationEventsState = {false , false , false , false , false };
26+
2127 @ Override
2228 protected void onCreate (@ Nullable Bundle savedInstanceState ) {
2329 super .onCreate (savedInstanceState );
@@ -26,37 +32,45 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
2632 Toolbar toolbar = findViewById (R .id .toolbar );
2733 setSupportActionBar (toolbar );
2834
35+
36+ for (int i = 0 ; i < invocationEvents .length ; i ++) {
37+ invocationEvents [i ] = invocationEvents [i ].replace ("_" , " " );
38+ }
2939 }
3040
3141 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+ }
3446 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+ }
5462 }
63+ // set new invocation events here
64+ BugReporting .setInvocationEvents (selectedEvents .toArray (new InstabugInvocationEvent [selectedEvents .size ()]));
5565 }
5666 });
5767 builder .show ();
5868 }
5969
70+ public static String [] getInvocationEventsNames (Class <? extends Enum <?>> e ) {
71+ return Arrays .toString (e .getEnumConstants ()).replaceAll ("^.|.$" , "" ).split (", " );
72+ }
73+
6074 public void onChangeThemeClicked (View view ) {
6175 final CharSequence [] items = {"Light" , "Dark" };
6276
@@ -66,10 +80,10 @@ public void onChangeThemeClicked(View view) {
6680 public void onClick (DialogInterface dialog , int item ) {
6781 switch (item ) {
6882 case 0 :
69- Instabug .setTheme (InstabugColorTheme .InstabugColorThemeLight );
83+ Instabug .setColorTheme (InstabugColorTheme .InstabugColorThemeLight );
7084 break ;
7185 case 1 :
72- Instabug .setTheme (InstabugColorTheme .InstabugColorThemeDark );
86+ Instabug .setColorTheme (InstabugColorTheme .InstabugColorThemeDark );
7387 break ;
7488 }
7589 }
@@ -83,9 +97,7 @@ public void onChangePrimaryColorClicked(View view) {
8397 colorPicker .setOnChooseColorListener (new ColorPicker .OnChooseColorListener () {
8498 @ Override
8599 public void onChooseColor (int position , int color ) {
86- Instabug .disable ();
87100 Instabug .setPrimaryColor (color );
88- Instabug .enable ();
89101 }
90102
91103 @ Override
0 commit comments