@@ -50,135 +50,147 @@ protected void onCreate(Bundle savedInstanceState) { |
50 | 50 | setupActionBar(); |
51 | 51 |
|
52 | 52 | try { |
53 | | - initHarLog(getIntent().getIntExtra("pos",-1)); |
54 | | - }catch (Exception e){ |
| 53 | + initHarLog(getIntent().getIntExtra("pos", -1)); |
| 54 | + } catch (Exception e) { |
55 | 55 | e.printStackTrace(); |
56 | 56 | finish(); |
57 | 57 | } |
58 | 58 | } |
59 | 59 |
|
60 | | - public void initHarLog(int pos){ |
61 | | - HarLog harLog = ((SysApplication)getApplication()).proxy.getHar().getLog(); |
| 60 | + public void initHarLog(int pos) { |
| 61 | + HarLog harLog = ((SysApplication) getApplication()).proxy.getHar().getLog(); |
62 | 62 | HarEntry harEntry = harLog.getEntries().get(pos); |
63 | 63 |
|
64 | 64 | HarRequest harRequest = harEntry.getRequest(); |
65 | 65 | HarResponse harResponse = harEntry.getResponse(); |
66 | 66 |
|
67 | 67 | addItem("Overview"); |
68 | | - addItem("URL",harRequest.getUrl()); |
| 68 | + addItem("URL", harRequest.getUrl()); |
69 | 69 |
|
70 | | - addItem("Method",harRequest.getMethod()); |
71 | | - addItem("Code",harResponse.getStatus()+""); |
72 | | - addItem("TotalTime",harEntry.getTime()+"ms"); |
73 | | - addItem("Size",harResponse.getBodySize()+"Bytes"); |
| 70 | + addItem("Method", harRequest.getMethod()); |
| 71 | + addItem("Code", harResponse.getStatus() + ""); |
| 72 | + addItem("TotalTime", harEntry.getTime() + "ms"); |
| 73 | + addItem("Size", harResponse.getBodySize() + "Bytes"); |
74 | 74 |
|
75 | | - if(harRequest.getQueryString().size()>0){ |
| 75 | + if (harRequest.getQueryString().size() > 0) { |
76 | 76 | addItem("Request Query"); |
77 | | - for (HarNameValuePair pair: harRequest.getQueryString()) { |
| 77 | + for (HarNameValuePair pair : harRequest.getQueryString()) { |
78 | 78 | addItem(pair.getName(), pair.getDecodeValue()); |
79 | 79 | } |
80 | 80 | } |
81 | 81 |
|
82 | 82 | addItem("Request Header"); |
83 | | - for (HarNameValuePair pair:harRequest.getHeaders()) { |
84 | | - if(pair.getName().equals("Cookie")){ |
| 83 | + for (HarNameValuePair pair : harRequest.getHeaders()) { |
| 84 | + if (pair.getName().equals("Cookie")) { |
85 | 85 | break; |
86 | 86 | } |
87 | | - addItem(pair.getName(),pair.getDecodeValue()); |
| 87 | + addItem(pair.getName(), pair.getDecodeValue()); |
88 | 88 | } |
89 | 89 |
|
90 | | - if(harRequest.getCookies().size()>0) { |
| 90 | + if (harRequest.getCookies().size() > 0) { |
91 | 91 | addItem("Request Cookies"); |
92 | 92 | for (HarCookie cookie : harRequest.getCookies()) { |
93 | 93 | addItem(cookie.getName(), cookie.getDecodeValue()); |
94 | 94 | } |
95 | 95 | } |
96 | 96 |
|
97 | | - if(harRequest.getPostData()!=null) { |
| 97 | + if (harRequest.getPostData() != null) { |
98 | 98 | addItem("Request Content"); |
99 | 99 | addItem("PostData", harRequest.getPostData().getText()); |
100 | 100 | } |
101 | 101 |
|
102 | 102 | addItem("Response Header"); |
103 | | - for (HarNameValuePair pair:harResponse.getHeaders()) { |
104 | | - if(pair.getName().equals("Cookie")){ |
| 103 | + for (HarNameValuePair pair : harResponse.getHeaders()) { |
| 104 | + if (pair.getName().equals("Cookie")) { |
105 | 105 | break; |
106 | 106 | } |
107 | | - addItem(pair.getName(),pair.getDecodeValue()); |
| 107 | + addItem(pair.getName(), pair.getDecodeValue()); |
108 | 108 | } |
109 | 109 |
|
110 | | - if(harResponse.getCookies().size()>0) { |
| 110 | + if (harResponse.getCookies().size() > 0) { |
111 | 111 | addItem("Response Cookies"); |
112 | | - for (HarCookie cookie:harResponse.getCookies()) { |
113 | | - addItem(cookie.getName(),cookie.getDecodeValue()); |
| 112 | + for (HarCookie cookie : harResponse.getCookies()) { |
| 113 | + addItem(cookie.getName(), cookie.getDecodeValue()); |
114 | 114 | } |
115 | 115 | } |
116 | 116 |
|
117 | | - if((harResponse.getRedirectURL() != null && harResponse.getRedirectURL().length()>0) || |
118 | | - (harResponse.getContent().getText() != null && harResponse.getContent().getText().length()>0) ) { |
| 117 | + if ((harResponse.getRedirectURL() != null && harResponse.getRedirectURL().length() > 0) || |
| 118 | + (harResponse.getContent().getText() != null && harResponse.getContent().getText().length() > 0)) { |
119 | 119 | addItem("Response Content"); |
120 | 120 | } |
121 | | - if(harResponse.getRedirectURL() != null && harResponse.getRedirectURL().length()>0) { |
| 121 | + if (harResponse.getRedirectURL() != null && harResponse.getRedirectURL().length() > 0) { |
122 | 122 | addItem("RedirectURL", harResponse.getRedirectURL()); |
123 | 123 | } |
124 | | - if(harResponse.getContent().getText() != null && harResponse.getContent().getText().length()>0) { |
125 | | - addItem("Content",harResponse.getContent().getText()); |
| 124 | + if (harResponse.getContent().getText() != null && harResponse.getContent().getText().length() > 0) { |
| 125 | + addItem("Content", harResponse.getContent().getText(), pos); |
126 | 126 | } |
127 | 127 |
|
128 | 128 | } |
129 | 129 |
|
130 | | - public void addItem(String title, final String value){ |
| 130 | + public void addItem(String title, final String value, final int pos) { |
131 | 131 | View view = LayoutInflater.from(this).inflate(R.layout.item_detail, null); |
132 | 132 |
|
133 | 133 | TextView textView = (TextView) view.findViewById(R.id.tv_title); |
134 | 134 | textView.setText(title); |
135 | 135 |
|
136 | 136 | TextView valueTextView = (TextView) view.findViewById(R.id.tv_value); |
137 | | - valueTextView.setText(value.substring(0,value.length()>50?50:value.length())); |
| 137 | + valueTextView.setText(value.substring(0, value.length() > 50 ? 50 : value.length())); |
138 | 138 |
|
139 | | - if(title.equals("Content")){ |
| 139 | + if (title.equals("Content")) { |
140 | 140 | view.setOnClickListener(new View.OnClickListener() { |
141 | 141 | @Override |
142 | 142 | public void onClick(View view) { |
143 | 143 | if (value != null && value.length() > 10) { |
144 | | - Intent intent = new Intent(HarDetailActivity.this,JsonPreviewActivity.class); |
145 | | - intent.putExtra("content",value); |
| 144 | + Intent intent = new Intent(HarDetailActivity.this, JsonPreviewActivity.class); |
| 145 | + intent.putExtra("pos", pos); |
146 | 146 | HarDetailActivity.this.startActivity(intent); |
147 | 147 | } |
148 | 148 | } |
149 | 149 | }); |
150 | | - }else { |
151 | | - view.setOnClickListener(new View.OnClickListener() { |
152 | | - @Override |
153 | | - public void onClick(View view) { |
154 | | - if (value != null && value.length() > 10) { |
155 | | - View textEntryView = LayoutInflater.from(HarDetailActivity.this).inflate(R.layout.alert_textview, null); |
156 | | - TextView edtInput = (TextView) textEntryView.findViewById(R.id.tv_content); |
157 | | - edtInput.setText(value); |
158 | | - |
159 | | - AlertDialog.Builder builder = new AlertDialog.Builder(HarDetailActivity.this); |
160 | | - builder.setCancelable(true); |
161 | | - builder.setView(textEntryView); |
162 | | - builder.setPositiveButton("确认", null); |
163 | | - builder.show(); |
164 | | - } |
165 | | - } |
166 | | - }); |
167 | 150 | } |
| 151 | + linearLayout.addView(view); |
| 152 | + } |
| 153 | + |
| 154 | + public void addItem(String title, final String value) { |
| 155 | + View view = LayoutInflater.from(this).inflate(R.layout.item_detail, null); |
| 156 | + |
| 157 | + TextView textView = (TextView) view.findViewById(R.id.tv_title); |
| 158 | + textView.setText(title); |
| 159 | + |
| 160 | + TextView valueTextView = (TextView) view.findViewById(R.id.tv_value); |
| 161 | + valueTextView.setText(value.substring(0, value.length() > 50 ? 50 : value.length())); |
| 162 | + |
| 163 | + view.setOnClickListener(new View.OnClickListener() { |
| 164 | + @Override |
| 165 | + public void onClick(View view) { |
| 166 | + if (value != null && value.length() > 10) { |
| 167 | + View textEntryView = LayoutInflater.from(HarDetailActivity.this).inflate(R.layout.alert_textview, null); |
| 168 | + TextView edtInput = (TextView) textEntryView.findViewById(R.id.tv_content); |
| 169 | + edtInput.setText(value); |
| 170 | + |
| 171 | + AlertDialog.Builder builder = new AlertDialog.Builder(HarDetailActivity.this); |
| 172 | + builder.setCancelable(true); |
| 173 | + builder.setView(textEntryView); |
| 174 | + builder.setPositiveButton("确认", null); |
| 175 | + builder.show(); |
| 176 | + } |
| 177 | + } |
| 178 | + }); |
| 179 | + |
168 | 180 |
|
169 | 181 | linearLayout.addView(view); |
170 | 182 | } |
171 | 183 |
|
172 | | - public void addItem(String cateName){ |
| 184 | + public void addItem(String cateName) { |
173 | 185 | View view = LayoutInflater.from(this).inflate(R.layout.item_cate, null); |
174 | 186 | TextView textView = (TextView) view.findViewById(R.id.tv_catetitle); |
175 | 187 | textView.setText(cateName); |
176 | 188 | linearLayout.addView(view); |
177 | 189 | } |
178 | 190 |
|
179 | 191 | /** |
180 | | - * Set up the {@link android.app.ActionBar}, if the API is available. |
181 | | - */ |
| 192 | + * Set up the {@link android.app.ActionBar}, if the API is available. |
| 193 | + */ |
182 | 194 | private void setupActionBar() { |
183 | 195 | setTitle("数据详情"); |
184 | 196 | ActionBar actionBar = getSupportActionBar(); |
|