|
23 | 23 | import android.graphics.Color;
|
24 | 24 | import android.os.Bundle;
|
25 | 25 | import android.util.Log;
|
| 26 | +import android.view.Menu; |
| 27 | +import android.view.MenuItem; |
26 | 28 | import android.view.View;
|
27 | 29 | import android.view.ViewGroup;
|
28 | 30 | import android.widget.Button;
|
@@ -68,7 +70,15 @@ protected AsyncHttpRequest newAsyncHttpRequest(DefaultHttpClient client, HttpCon
|
68 | 70 | private final List<RequestHandle> requestHandles = new LinkedList<RequestHandle>();
|
69 | 71 | private static final String LOG_TAG = "SampleParentActivity";
|
70 | 72 |
|
71 |
| - protected static final String PROTOCOL = "https://"; |
| 73 | + private static final int MENU_USE_HTTPS = 0; |
| 74 | + private static final int MENU_CLEAR_VIEW = 1; |
| 75 | + |
| 76 | + private boolean useHttps = true; |
| 77 | + |
| 78 | + protected static final String PROTOCOL_HTTP = "http://"; |
| 79 | + protected static final String PROTOCOL_HTTPS = "https://"; |
| 80 | + |
| 81 | + protected static String PROTOCOL = PROTOCOL_HTTPS; |
72 | 82 | protected static final int LIGHTGREEN = Color.parseColor("#00FF66");
|
73 | 83 | protected static final int LIGHTRED = Color.parseColor("#FF3300");
|
74 | 84 | protected static final int YELLOW = Color.parseColor("#FFFF00");
|
@@ -106,6 +116,36 @@ protected void onCreate(Bundle savedInstanceState) {
|
106 | 116 | }
|
107 | 117 | }
|
108 | 118 |
|
| 119 | + @Override |
| 120 | + public boolean onPrepareOptionsMenu(Menu menu) { |
| 121 | + MenuItem useHttpsMenuItem = menu.findItem(MENU_USE_HTTPS); |
| 122 | + if (useHttpsMenuItem != null) { |
| 123 | + useHttpsMenuItem.setChecked(useHttps); |
| 124 | + } |
| 125 | + return super.onPrepareOptionsMenu(menu); |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public boolean onCreateOptionsMenu(Menu menu) { |
| 130 | + menu.add(Menu.NONE, MENU_USE_HTTPS, R.string.menu_use_https, Menu.NONE).setCheckable(true); |
| 131 | + menu.add(Menu.NONE, MENU_CLEAR_VIEW, R.string.menu_clear_view, Menu.NONE); |
| 132 | + return super.onCreateOptionsMenu(menu); |
| 133 | + } |
| 134 | + |
| 135 | + @Override |
| 136 | + public boolean onOptionsItemSelected(MenuItem item) { |
| 137 | + switch (item.getItemId()) { |
| 138 | + case MENU_USE_HTTPS: |
| 139 | + useHttps = !useHttps; |
| 140 | + PROTOCOL = useHttps ? PROTOCOL_HTTPS : PROTOCOL_HTTP; |
| 141 | + return true; |
| 142 | + case MENU_CLEAR_VIEW: |
| 143 | + clearOutputs(); |
| 144 | + return true; |
| 145 | + } |
| 146 | + return super.onOptionsItemSelected(item); |
| 147 | + } |
| 148 | + |
109 | 149 | @Override
|
110 | 150 | public AsyncHttpRequest getHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
|
111 | 151 | return null;
|
|
0 commit comments