use of org.apache.http.message.BasicNameValuePair in project android-app by eoecn.
the class MainActivity method onClick.
// [end]
// [start]继承方法
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()) {
case R.id.Linear_above_toHome:
showMenu();
break;
case R.id.login_login:
SharedPreferences share = this.getSharedPreferences(UserLoginUidActivity.SharedName, Context.MODE_PRIVATE);
// [start] 修复上一个bug
String Key = share.getString(UserLoginUidActivity.KEY, "");
if (Key != "" && !Key.contains(":")) {
Editor edit = share.edit();
edit.putString(UserLoginUidActivity.KEY, "");
edit.commit();
}
// [end] 下一版本删除掉
if (share.contains(UserLoginUidActivity.KEY) && !share.getString(UserLoginUidActivity.KEY, "").equals("")) {
IntentUtil.start_activity(this, UserCenterActivity.class);
} else {
IntentUtil.start_activity(this, UserLoginActivity.class);
}
break;
case R.id.imageview_above_more:
if (isShowPopupWindows) {
new PopupWindowUtil(mViewPager).showActionWindow(v, this, mBasePageAdapter.tabs);
}
break;
case R.id.imageview_above_query:
if (NetWorkHelper.isNetworkAvailable(MainActivity.this)) {
IntentUtil.start_activity(this, SearchActivity.class, new BasicNameValuePair("tag", current_page));
} else {
Toast.makeText(getApplicationContext(), "网络连接失败,请检查网络", Toast.LENGTH_LONG).show();
}
break;
case R.id.cbFeedback:
FeedbackAgent agent = new FeedbackAgent(this);
agent.startFeedbackActivity();
break;
case R.id.cbAbove:
IntentUtil.start_activity(this, AboutActivity.class);
break;
case R.id.bn_refresh:
switch(mTag) {
case 0:
imgQuery.setVisibility(View.GONE);
new MyTask().execute(topDao);
break;
case 1:
new MyTask().execute(newsDao);
break;
case 2:
new MyTask().execute(wikiDao);
break;
case 3:
new MyTask().execute(blogsDao);
break;
default:
break;
}
break;
}
}
use of org.apache.http.message.BasicNameValuePair in project Libraries-for-Android-Developers by eoecn.
the class RequestParams method getParamsList.
protected List<BasicNameValuePair> getParamsList() {
List<BasicNameValuePair> lparams = new LinkedList<BasicNameValuePair>();
for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
lparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
lparams.addAll(getParamsList(null, urlParamsWithObjects));
return lparams;
}
use of org.apache.http.message.BasicNameValuePair in project Libraries-for-Android-Developers by eoecn.
the class RequestParams method createMultipartEntity.
private HttpEntity createMultipartEntity(ResponseHandlerInterface progressHandler) throws IOException {
SimpleMultipartEntity entity = new SimpleMultipartEntity(progressHandler);
entity.setIsRepeatable(isRepeatable);
// Add string params
for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
entity.addPart(entry.getKey(), entry.getValue());
}
// Add non-string params
List<BasicNameValuePair> params = getParamsList(null, urlParamsWithObjects);
for (BasicNameValuePair kv : params) {
entity.addPart(kv.getName(), kv.getValue());
}
// Add stream params
for (ConcurrentHashMap.Entry<String, StreamWrapper> entry : streamParams.entrySet()) {
StreamWrapper stream = entry.getValue();
if (stream.inputStream != null) {
entity.addPart(entry.getKey(), stream.name, stream.inputStream, stream.contentType);
}
}
// Add file params
for (ConcurrentHashMap.Entry<String, FileWrapper> entry : fileParams.entrySet()) {
FileWrapper fileWrapper = entry.getValue();
entity.addPart(entry.getKey(), fileWrapper.file, fileWrapper.contentType);
}
return entity;
}
use of org.apache.http.message.BasicNameValuePair in project Libraries-for-Android-Developers by eoecn.
the class RequestParams method getParamsList.
private List<BasicNameValuePair> getParamsList(String key, Object value) {
List<BasicNameValuePair> params = new LinkedList<BasicNameValuePair>();
if (value instanceof Map) {
Map<String, Object> map = (Map<String, Object>) value;
List<String> list = new ArrayList<String>(map.keySet());
// Ensure consistent ordering in query string
Collections.sort(list);
for (String nestedKey : list) {
Object nestedValue = map.get(nestedKey);
if (nestedValue != null) {
params.addAll(getParamsList(key == null ? nestedKey : String.format("%s[%s]", key, nestedKey), nestedValue));
}
}
} else if (value instanceof List) {
List<Object> list = (List<Object>) value;
for (Object nestedValue : list) {
params.addAll(getParamsList(String.format("%s[]", key), nestedValue));
}
} else if (value instanceof Object[]) {
Object[] array = (Object[]) value;
for (Object nestedValue : array) {
params.addAll(getParamsList(String.format("%s[]", key), nestedValue));
}
} else if (value instanceof Set) {
Set<Object> set = (Set<Object>) value;
for (Object nestedValue : set) {
params.addAll(getParamsList(key, nestedValue));
}
} else if (value instanceof String) {
params.add(new BasicNameValuePair(key, (String) value));
}
return params;
}
use of org.apache.http.message.BasicNameValuePair in project OpenRefine by OpenRefine.
the class RefineBroker method getUserId.
// ----------------------------------------------------------------------------------------
@SuppressWarnings("unchecked")
protected String getUserId(HttpServletRequest request) throws Exception {
// This is useful for testing
if (developmentMode) {
return getParameter(request, "uid");
}
String oauth = request.getHeader(DELEGATED_OAUTH_HEADER);
if (oauth == null) {
throw new RuntimeException("The request needs to contain the '" + DELEGATED_OAUTH_HEADER + "' header set to obtain user identity via Freebase.");
}
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
Map<String, String> params = (Map<String, String>) request.getParameterMap();
for (Entry<String, String> e : params.entrySet()) {
formparams.add(new BasicNameValuePair((String) e.getKey(), (String) e.getValue()));
}
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
HttpPost httpRequest = new HttpPost(USER_INFO_URL);
httpRequest.setHeader(OAUTH_HEADER, oauth);
httpRequest.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "OpenRefine Broker");
httpRequest.setEntity(entity);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httpRequest, responseHandler);
JSONObject o = new JSONObject(responseBody);
return o.getString("username");
}
Aggregations