Search in sources :

Example 36 with BasicNameValuePair

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;
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Editor(android.content.SharedPreferences.Editor) PopupWindowUtil(cn.eoe.app.utils.PopupWindowUtil) FeedbackAgent(com.umeng.fb.FeedbackAgent)

Example 37 with BasicNameValuePair

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;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedList(java.util.LinkedList)

Example 38 with BasicNameValuePair

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;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 39 with BasicNameValuePair

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 40 with BasicNameValuePair

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");
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpPost(org.apache.http.client.methods.HttpPost) ArrayList(java.util.ArrayList) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) JSONObject(org.json.JSONObject) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Map(java.util.Map)

Aggregations

BasicNameValuePair (org.apache.http.message.BasicNameValuePair)289 NameValuePair (org.apache.http.NameValuePair)199 ArrayList (java.util.ArrayList)187 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)101 HttpPost (org.apache.http.client.methods.HttpPost)87 HttpResponse (org.apache.http.HttpResponse)77 HttpEntity (org.apache.http.HttpEntity)58 IOException (java.io.IOException)55 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)33 Test (org.junit.Test)32 HttpGet (org.apache.http.client.methods.HttpGet)29 ClientProtocolException (org.apache.http.client.ClientProtocolException)28 CSVReader (com.talend.csv.CSVReader)27 HttpClient (org.apache.http.client.HttpClient)25 UnsupportedEncodingException (java.io.UnsupportedEncodingException)23 HashMap (java.util.HashMap)20 JSONObject (org.json.JSONObject)20 Map (java.util.Map)19 URI (java.net.URI)16 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)15