30
30
31
31
public class WaypointsActivity extends ListActivity {
32
32
33
- private static final int [] samples = new int []{
34
- R .string .title_get_sample ,
35
- R .string .title_post_sample ,
36
- R .string .title_delete_sample ,
37
- R .string .title_put_sample ,
38
- R .string .title_json_sample ,
39
- R .string .title_sax_example ,
40
- R .string .title_file_sample ,
41
- R .string .title_binary_sample ,
42
- R .string .title_gzip_sample ,
43
- R .string .title_redirect_302 ,
44
- R .string .title_threading_timeout ,
45
- R .string .title_cancel_all ,
46
- R .string .title_cancel_handle ,
47
- R .string .title_synchronous ,
48
- R .string .title_intent_service_sample ,
49
- R .string .title_post_files
50
- };
51
- private static final Class [] targets = {
52
- GetSample .class ,
53
- PostSample .class ,
54
- DeleteSample .class ,
55
- PutSample .class ,
56
- JsonSample .class ,
57
- SaxSample .class ,
58
- FileSample .class ,
59
- BinarySample .class ,
60
- GzipSample .class ,
61
- Redirect302Sample .class ,
62
- ThreadingTimeoutSample .class ,
63
- CancelAllRequestsSample .class ,
64
- CancelRequestHandleSample .class ,
65
- SynchronousClientSample .class ,
66
- IntentServiceSample .class ,
67
- FilesSample .class
33
+ private static final SampleConfig [] samplesConfig = new SampleConfig [] {
34
+ new SampleConfig (R .string .title_get_sample , GetSample .class ),
35
+ new SampleConfig (R .string .title_post_sample , PostSample .class ),
36
+ new SampleConfig (R .string .title_delete_sample , DeleteSample .class ),
37
+ new SampleConfig (R .string .title_put_sample , PutSample .class ),
38
+ new SampleConfig (R .string .title_json_sample , JsonSample .class ),
39
+ new SampleConfig (R .string .title_sax_example , SaxSample .class ),
40
+ new SampleConfig (R .string .title_file_sample , FileSample .class ),
41
+ new SampleConfig (R .string .title_binary_sample , BinarySample .class ),
42
+ new SampleConfig (R .string .title_gzip_sample , GzipSample .class ),
43
+ new SampleConfig (R .string .title_redirect_302 , Redirect302Sample .class ),
44
+ new SampleConfig (R .string .title_threading_timeout , ThreadingTimeoutSample .class ),
45
+ new SampleConfig (R .string .title_cancel_all , CancelAllRequestsSample .class ),
46
+ new SampleConfig (R .string .title_cancel_handle , CancelRequestHandleSample .class ),
47
+ new SampleConfig (R .string .title_synchronous , SynchronousClientSample .class ),
48
+ new SampleConfig (R .string .title_intent_service_sample , IntentServiceSample .class ),
49
+ new SampleConfig (R .string .title_post_files , FilesSample .class )
68
50
};
69
51
70
52
@ Override
@@ -75,15 +57,28 @@ protected void onCreate(Bundle savedInstanceState) {
75
57
76
58
private List <String > getTitlesList () {
77
59
List <String > titles = new ArrayList <String >();
78
- for (int title : samples ) {
79
- titles .add (getString (title ));
60
+ for (SampleConfig config : samplesConfig ) {
61
+ titles .add (getString (config . titleId ));
80
62
}
81
63
return titles ;
82
64
}
83
65
84
66
@ Override
85
67
protected void onListItemClick (ListView l , View v , int position , long id ) {
86
- if (position >= 0 && position < targets .length )
87
- startActivity (new Intent (this , targets [position ]));
68
+ if (position >= 0 && position < samplesConfig .length )
69
+ startActivity (new Intent (this , samplesConfig [position ]. targetClass ));
88
70
}
71
+
72
+ private static class SampleConfig {
73
+
74
+ final int titleId ;
75
+ final Class targetClass ;
76
+
77
+ SampleConfig (int titleId , Class targetClass ) {
78
+ this .titleId = titleId ;
79
+ this .targetClass = targetClass ;
80
+ }
81
+
82
+ }
83
+
89
84
}
0 commit comments