11package cf .netdex .hidfuzzer ;
22
3+ import android .content .Context ;
34import android .os .Bundle ;
45import android .support .v7 .app .AppCompatActivity ;
6+ import android .widget .ArrayAdapter ;
57import android .widget .CompoundButton ;
68import android .widget .Spinner ;
79import android .widget .ToggleButton ;
810
11+ import java .lang .reflect .InvocationTargetException ;
12+ import java .util .ArrayList ;
13+ import java .util .HashMap ;
14+
915import cf .netdex .hidfuzzer .task .PowershellTask ;
1016import cf .netdex .hidfuzzer .task .DownloadTask ;
1117import cf .netdex .hidfuzzer .task .WallpaperTask ;
@@ -18,37 +24,55 @@ public class MainActivity extends AppCompatActivity {
1824 public static String TAG = "tag_hidfuzzer" ;
1925 private HIDTask RUNNING_TASK ;
2026
27+ static final Class [] TASKS = {
28+ TestTask .class ,
29+ WallpaperTask .class ,
30+ DownloadTask .class ,
31+ PowershellTask .class ,
32+ FuzzerTask .class
33+ };
34+
35+ static final HashMap <String , Class > mTaskMap = new HashMap <>();
36+ static final ArrayList <String > mTaskSpinnerItems = new ArrayList <>();
37+ static {
38+ for (Class c : TASKS ) {
39+ mTaskMap .put (c .getName (), c );
40+ mTaskSpinnerItems .add (c .getName ());
41+ }
42+ }
43+
2144 protected void onCreate (Bundle savedInstanceState ) {
2245 super .onCreate (savedInstanceState );
2346 setContentView (R .layout .activity_main );
2447
25-
2648 final ToggleButton btnPoll = (ToggleButton ) findViewById (R .id .btnPoll );
2749 final Spinner spnTask = (Spinner ) findViewById (R .id .spnTask );
2850
51+
52+ ArrayAdapter <String > adapter = new ArrayAdapter <String >(
53+ this , android .R .layout .simple_spinner_item , mTaskSpinnerItems );
54+ adapter .setDropDownViewResource (android .R .layout .simple_spinner_dropdown_item );
55+ spnTask .setAdapter (adapter );
56+
2957 btnPoll .setOnCheckedChangeListener (new CompoundButton .OnCheckedChangeListener () {
3058 @ Override
3159 public void onCheckedChanged (CompoundButton buttonView , boolean isChecked ) {
3260 if (isChecked ) {
3361 String stask = (String ) spnTask .getSelectedItem ();
34- switch (stask ){
35- case "Fuzzer" :
36- RUNNING_TASK = new FuzzerTask (MainActivity .this );
37- break ;
38- case "Test" :
39- RUNNING_TASK = new TestTask (MainActivity .this );
40- break ;
41- case "Wallpaper" :
42- RUNNING_TASK = new WallpaperTask (MainActivity .this );
43- break ;
44- case "Download" :
45- RUNNING_TASK = new DownloadTask (MainActivity .this );
46- break ;
47- case "PowerShell" :
48- RUNNING_TASK = new PowershellTask (MainActivity .this );
49- break ;
62+ Class c = mTaskMap .get (stask );
63+ try {
64+
65+ RUNNING_TASK = (HIDTask ) c .getDeclaredConstructor (Context .class ).newInstance (MainActivity .this );
66+ RUNNING_TASK .execute ();
67+ } catch (InstantiationException e ) {
68+ e .printStackTrace ();
69+ } catch (IllegalAccessException e ) {
70+ e .printStackTrace ();
71+ } catch (InvocationTargetException e ) {
72+ e .printStackTrace ();
73+ } catch (NoSuchMethodException e ) {
74+ e .printStackTrace ();
5075 }
51- RUNNING_TASK .execute ();
5276 } else {
5377 if (RUNNING_TASK != null )
5478 RUNNING_TASK .cancel (false );
0 commit comments