20
20
21
21
import android .annotation .TargetApi ;
22
22
import android .app .Activity ;
23
+ import android .app .AlertDialog ;
23
24
import android .content .Context ;
25
+ import android .content .DialogInterface ;
24
26
import android .graphics .Color ;
25
27
import android .os .Build ;
26
28
import android .os .Bundle ;
@@ -75,8 +77,11 @@ protected AsyncHttpRequest newAsyncHttpRequest(DefaultHttpClient client, HttpCon
75
77
76
78
private static final int MENU_USE_HTTPS = 0 ;
77
79
private static final int MENU_CLEAR_VIEW = 1 ;
80
+ private static final int MENU_LOGGING_VERBOSITY = 2 ;
81
+ private static final int MENU_ENABLE_LOGGING = 3 ;
78
82
79
83
private boolean useHttps = true ;
84
+ private boolean enableLogging = true ;
80
85
81
86
protected static final String PROTOCOL_HTTP = "http://" ;
82
87
protected static final String PROTOCOL_HTTPS = "https://" ;
@@ -128,13 +133,19 @@ public boolean onPrepareOptionsMenu(Menu menu) {
128
133
if (useHttpsMenuItem != null ) {
129
134
useHttpsMenuItem .setChecked (useHttps );
130
135
}
136
+ MenuItem enableLoggingMenuItem = menu .findItem (MENU_ENABLE_LOGGING );
137
+ if (enableLoggingMenuItem != null ) {
138
+ enableLoggingMenuItem .setChecked (enableLogging );
139
+ }
131
140
return super .onPrepareOptionsMenu (menu );
132
141
}
133
142
134
143
@ Override
135
144
public boolean onCreateOptionsMenu (Menu menu ) {
136
145
menu .add (Menu .NONE , MENU_USE_HTTPS , Menu .NONE , R .string .menu_use_https ).setCheckable (true );
137
146
menu .add (Menu .NONE , MENU_CLEAR_VIEW , Menu .NONE , R .string .menu_clear_view );
147
+ menu .add (Menu .NONE , MENU_ENABLE_LOGGING , Menu .NONE , "Enable Logging" ).setCheckable (true );
148
+ menu .add (Menu .NONE , MENU_LOGGING_VERBOSITY , Menu .NONE , "Set Logging Verbosity" );
138
149
return super .onCreateOptionsMenu (menu );
139
150
}
140
151
@@ -146,6 +157,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
146
157
PROTOCOL = useHttps ? PROTOCOL_HTTPS : PROTOCOL_HTTP ;
147
158
urlEditText .setText (getDefaultURL ());
148
159
return true ;
160
+ case MENU_ENABLE_LOGGING :
161
+ enableLogging = !enableLogging ;
162
+ getAsyncHttpClient ().setLoggingEnabled (enableLogging );
163
+ return true ;
164
+ case MENU_LOGGING_VERBOSITY :
165
+ showLoggingVerbosityDialog ();
166
+ return true ;
149
167
case MENU_CLEAR_VIEW :
150
168
clearOutputs ();
151
169
return true ;
@@ -172,6 +190,29 @@ public void addRequestHandle(RequestHandle handle) {
172
190
}
173
191
}
174
192
193
+ private void showLoggingVerbosityDialog () {
194
+ AlertDialog ad = new AlertDialog .Builder (this )
195
+ .setTitle ("Set Logging Verbosity" )
196
+ .setSingleChoiceItems (new String []{
197
+ "VERBOSE" ,
198
+ "DEBUG" ,
199
+ "INFO" ,
200
+ "WARN" ,
201
+ "ERROR" ,
202
+ "WTF"
203
+ }, getAsyncHttpClient ().getLoggingLevel () - 2 , new DialogInterface .OnClickListener () {
204
+ @ Override
205
+ public void onClick (DialogInterface dialog , int which ) {
206
+ getAsyncHttpClient ().setLoggingLevel (which + 2 );
207
+ dialog .dismiss ();
208
+ }
209
+ })
210
+ .setCancelable (true )
211
+ .setNeutralButton ("Cancel" , null )
212
+ .create ();
213
+ ad .show ();
214
+ }
215
+
175
216
public void onRunButtonPressed () {
176
217
addRequestHandle (executeSample (getAsyncHttpClient (),
177
218
getUrlText (getDefaultURL ()),
0 commit comments