Java 类com.loopj.android.http.JsonHttpResponseHandler 实例源码

项目:AmazingAvatar    文件:NetworkHelper.java   
public static void getAvatar(@NonNull final AvatarCallback callback) {
    AsyncHttpClient client = getClient();

    client.get(AVATAR_URL, new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            super.onSuccess(statusCode, headers, response);
            if (statusCode != 200) {
                callback.onFail();
            } else {
                try {
                    JSONObject jsonObject = response.getJSONObject(0);
                    AvatarModel model = new AvatarModel();
                    model.url = jsonObject.getJSONArray("avatars").getJSONObject(0)
                            .getString("url");
                    model.firstName = jsonObject.getString("first_name");
                    model.lastName = jsonObject.getString("last_name");
                    callback.onSuccess(model);
                } catch (JSONException ignore) {
                    callback.onFail();
                }
            }
        }
    });
}
项目:MyTvLauncher    文件:MainActivity.java   
private void setBingImg() {
    AsyncHttpClient client = new AsyncHttpClient();
    client.get("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1", new JsonHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    if (statusCode == 200) {
                        Gson gson = new Gson();
                        BingImage bingImage = gson.fromJson(response.toString(), BingImage.class);
                        List<BingImage.ImagesBean> img = bingImage.getImages();
                        if (img != null && img.size() > 0) {
                            backImgUrl = "https://cn.bing.com" + img.get(0).getUrl();
                            setBackgroundImage();
                        } else Log.d("main", "onSuccess: 没有获取到类型");

                    }
                }
            }
    );
}
项目:Coding-Android    文件:MyPushReceiver.java   
@Override
    public void onReceive(Context context, Intent intent) {
        String url = intent.getStringExtra("data");

        if (url != null) {
            closeNotify(context, url);
            if (MyApp.getMainActivityState()) {
                URLSpanNoUnderline.openActivityByUri(context, url, true);
            } else {
                Intent mainIntent = new Intent(context, MainActivity_.class);
                mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                mainIntent.putExtra("mPushUrl", url);
                context.startActivity(mainIntent);
                URLSpanNoUnderline.openActivityByUri(context, url, true);
            }
        }

        String id = intent.getStringExtra("id");
        if (id != null && !id.isEmpty()) {
            AsyncHttpClient client = MyAsyncHttpClient.createClient(context);
            final String host = Global.HOST_API + "/notification/mark-read?id=%s";
            client.post(String.format(host, id), new JsonHttpResponseHandler() {
            });
        }
    }
项目:Coding-Android    文件:UnreadNotify.java   
public static void update(Context context) {
    final MyApp myApp = (MyApp) context.getApplicationContext();
    AsyncHttpClient client = MyAsyncHttpClient.createClient(context);

    client.get(Global.HOST_API + "/user/unread-count", new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                if (response.getInt("code") == 0) {
                    JSONObject json = response.getJSONObject("data");
                    Unread unread = new Unread(json);
                    MyApp.sUnread = unread;

                    UnreadNotifySubject.getInstance().notifyObserver();
                }

            } catch (Exception e) {
                Global.errorLog(e);
            }
        }
    });
}
项目:Gizwits-AirPurifier_Android    文件:LocationService.java   
/**
 * 启动定位服务
 */
public void startLocation(){
    AsyncHttpClient client = new AsyncHttpClient();
    client.get(requestUrl, new JsonHttpResponseHandler(){

        @Override
        public void onFailure(Throwable arg0, JSONObject arg1) {
            super.onFailure(arg0, arg1);
            onFailed();
        }

        @Override
        public void onSuccess(JSONObject json) {
            LocationService.this.onSuccess(json);
        }
    });
}
项目:Gizwits-AirPurifier_Android    文件:GetPMService.java   
/**
 * 启动定位服务
 */
public void GetWeather(String city){
    AsyncHttpClient client = new AsyncHttpClient();
    client.addHeader("X-XPG-Application-Id", "c79c8ef6002111e48a9b00163e0e2e0d");
    client.addHeader("X-XPG-REST-API-Key", "c79cd5c8002111e48a9b00163e0e2e0d");
    client.addHeader("Content-Type", "application/json");
    client.get(requestUrl+city, new JsonHttpResponseHandler(){

        @Override
        public void onFailure(Throwable arg0, JSONObject arg1) {
            super.onFailure(arg0, arg1);
            onFailed();
        }

        @Override
        public void onSuccess(JSONObject json) {
            GetPMService.this.onSuccess(json);
        }
    });
}
项目:KUAS-AP-Material    文件:Helper.java   
public static void getNews(final Context context) {
    mClient.get(NEWS_URL, new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            super.onSuccess(statusCode, headers, response);
            // TODO wait for API update
            try {
                Memory.setString(context, Constant.PREF_NEWS_TITLE, response.getString(2));
                Memory.setString(context, Constant.PREF_NEWS_CONTENT, response.getString(3));
                Memory.setString(context, Constant.PREF_NEWS_URL, response.getString(4));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}
项目:KUAS-AP-Material    文件:Helper.java   
public static void getNews(final Context context) {
    mClient.get(NEWS_URL, new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            super.onSuccess(statusCode, headers, response);
            // TODO wait for API update
            try {
                Memory.setString(context, Constant.PREF_NEWS_TITLE, response.getString(2));
                Memory.setString(context, Constant.PREF_NEWS_CONTENT, response.getString(3));
                Memory.setString(context, Constant.PREF_NEWS_URL, response.getString(4));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}
项目:StreamHub-Android-Comments-App    文件:WriteClient.java   
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        The token of the logged in user.
 * @param action
 * @param parameters
 * @param handler      Response handler
 */

public static void flagContent(String collectionId, String contentId,
                               String token, LFSFlag action, RequestParams parameters,
                               JsonHttpResponseHandler handler) {

    String url = (new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("")) +
            contentId + (new Uri.Builder().appendPath("").appendPath("flag")
            .appendPath(flags[action.value()])
            .appendQueryParameter("lftoken", token)
            .appendQueryParameter("collection_id", collectionId));

    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
项目:StreamHub-Android-Comments-App    文件:WriteClient.java   
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        The token of the logged in user.
 * @param action
 * @param parameters
 * @param networkID    Livefyre provided network name.
 * @param handler      Response handler
 */
public static void flagContent(String collectionId, String contentId,
                               String token, LFSFlag action, RequestParams parameters,
                               String networkID, JsonHttpResponseHandler handler) {

    String url = (new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("")) +
            contentId + (new Uri.Builder().appendPath("").appendPath("flag")
            .appendPath(flags[action.value()])
            .appendQueryParameter("lftoken", token)
            .appendQueryParameter("collection_id", collectionId));

    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
项目:StreamHub-Android-Comments-App    文件:WriteClient.java   
/**
 * @param action
 * @param contentId
 * @param collectionId The Id of the collection.
 * @param userToken    The token of the logged in user.
 * @param parameters
 * @param handler      Response handler
 * @throws MalformedURLException
 */

public static void featureMessage(String action, String contentId,
                                  String collectionId, String userToken,
                                  HashMap<String, Object> parameters, JsonHttpResponseHandler handler)
        throws MalformedURLException {
    RequestParams bodyParams = new RequestParams();
    bodyParams.put("lftoken", userToken);

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("collection")
            .appendPath(collectionId).appendPath(action)
            .appendPath(contentId).appendPath("")
            .appendQueryParameter("lftoken", userToken)
            .appendQueryParameter("collection_id", collectionId);

    Log.d("SDK", "" + uriBuilder);
    HttpClient.client.post(uriBuilder.toString(), bodyParams, handler);
}
项目:StreamHub-Android-Comments-App    文件:WriteClient.java   
/**
 * @param action
 * @param contentId
 * @param collectionId The Id of the collection.
 * @param userToken    The token of the logged in user.
 * @param parameters
 * @param networkID    Livefyre provided network name
 * @param handler      Response handler
 * @throws MalformedURLException
 */
public static void featureMessage(String action, String contentId,
                                  String collectionId, String userToken,
                                  HashMap<String, Object> parameters, String networkID, JsonHttpResponseHandler handler)
        throws MalformedURLException {
    RequestParams bodyParams = new RequestParams();
    bodyParams.put("lftoken", userToken);

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("collection")
            .appendPath(collectionId).appendPath(action)
            .appendPath(contentId).appendPath("")
            .appendQueryParameter("lftoken", userToken)
            .appendQueryParameter("collection_id", collectionId);

    Log.d("SDK", "" + uriBuilder);
    HttpClient.client.post(uriBuilder.toString(), bodyParams, handler);
}
项目:StreamHub-Android-Comments-App    文件:WriteClient.java   
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        The token of the logged in user.
 * @param action
 * @param parameters
 * @param handler      Response handler
 */

public static void postAction(String collectionId, String contentId,
                              String token, LFSActions action, RequestParams parameters,
                              JsonHttpResponseHandler handler) {
    // Build the URL
    String url = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("") + contentId +
            (new Uri.Builder().appendPath(actions[action.value()]).appendPath("")
                    .appendQueryParameter("lftoken", token)
                    .appendQueryParameter("collection_id", collectionId));


    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
项目:StreamHub-Android-Comments-App    文件:WriteClient.java   
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        Livefyre Token
 * @param action
 * @param parameters
 * @param networkID    Livefyre provided network name
 * @param handler      Response handler
 */

public static void postAction(String collectionId, String contentId,
                              String token, LFSActions action, RequestParams parameters,
                              String networkID, JsonHttpResponseHandler handler) {
    // Build the URL
    String url = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("") + contentId +
            (new Uri.Builder().appendPath(actions[action.value()]).appendPath("")
                    .appendQueryParameter("lftoken", token)
                    .appendQueryParameter("collection_id", collectionId));


    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
项目:vtu-life-android    文件:GCMRegisterManager.java   
@Override
protected void onPostExecute(final String gcmRegisterIdString) {
    super.onPostExecute(gcmRegisterIdString);
    if (gcmRegisterIdString != null) {
        VTULifeRestClient.registerGcm(gcmRegisterIdString,
                SystemFeatureChecker.getDeviceUuid(mContext),
                new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode,
                            JSONObject response) {
                        super.onSuccess(statusCode, response);
                        Settings.storeRegistrationIdWithAppVersion(
                                mContext, gcmRegisterIdString);
                        ((VTULifeMainActivity) mContext).showCrouton(
                                R.string.registered_for_notification,
                                Style.INFO, true);
                    }
                });
    }

}
项目:ShopAfter    文件:ViewActivity.java   
private void getAd(final String adID) {
  GoRestClient.get(":8080/ad/" + adID, new JsonHttpResponseHandler() {
    @Override public void onSuccess(JSONObject jsonObject) {
      Log.d(TAG, jsonObject.toString());
      Gson gson = new GsonBuilder().create();
      AdResult adResult = gson.fromJson(jsonObject.toString(), AdResult.class);
      String egg = adResult.getData().getImage1();
      String[] parts = adResult.getData().getImage1().split("_");
      tvTitle.setText(adResult.getData().getTitle());
      tvDescription.setText(adResult.getData().getDescription());
      ivImage1.setBackgroundColor(Color.parseColor("#" + parts[2]));
      if (adResult.status.equals("OK")) {
        Picasso.with(getApplicationContext())
            .load(GoRestClient.getAbsoluteUrl(":9090/egg/" + egg))
            .into(ivImage1);
      }
    }
  });
}
项目:v2ex-daily-android    文件:NodeFragment.java   
private void syncCollection(final int nodeId, final boolean added, String regTime){
    V2EX.syncCollection(getActivity(), nodeId, regTime, added, new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            if(getActivity() != null){
                try {
                    if(response.getString("result").equals("ok")){
                        mProgressDialog.setMessage("OK");
                        mAllNodesDataHelper.setCollected(added, nodeId);
                    }else if(response.getString("result").equals("fail")){
                        mProgressDialog.setMessage("Fail");
                        MessageUtils.toast(getActivity(), "Sync collections failed.");
                    }
                    mProgressDialog.dismiss();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}
项目:v2ex-daily-android    文件:AllNodesAdapter.java   
private void syncCollection(final int nodeId, final boolean added, String regTime){
    V2EX.syncCollection(mContext, nodeId, regTime, added, new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                if(response.getString("result").equals("ok")){
                    mProgressDialog.setMessage("OK");
                    mAllNodesDataHelper.setCollected(added, nodeId);
                }else if(response.getString("result").equals("fail")){
                    mProgressDialog.setMessage("Fail");
                    MessageUtils.toast(mContext, "Sync collections failed.");
                }
                mProgressDialog.dismiss();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}
项目:v2ex-daily-android    文件:SearchAllNodeAdapter.java   
private void syncCollection(final int nodeId, final boolean added, String regTime){
    V2EX.syncCollection(mContext, nodeId, regTime, added, new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                if(response.getString("result").equals("ok")){
                    mProgressDialog.setMessage("OK");
                    mAllNodesDataHelper.setCollected(added, nodeId);
                }else if(response.getString("result").equals("fail")){
                    mProgressDialog.setMessage("Fail");
                    MessageUtils.toast(mContext, "Sync collections failed.");
                }
                mProgressDialog.dismiss();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}
项目:v2ex-daily-android    文件:LoginActivity.java   
private void getOnceCode(){
    mProgressDialog = ProgressDialog.show(LoginActivity.this, null, "Get Once Code...", true, true);
    V2EX.getOnceCode(this, "https://www.v2ex.com/signin", new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            if(LoginActivity.this != null){
                try {
                    if(response.getString("result").equals("ok")){
                        int onceCode = response.getJSONObject("content").getInt("once");
                        mProgressDialog.setMessage("Login...");
                        login(onceCode);
                    }else{
                        MessageUtils.toast(LoginActivity.this, "get once code fail");
                    }
                } catch (JSONException e) {
                    MessageUtils.toast(LoginActivity.this, "json error");
                    e.printStackTrace();
                }
            }
        }
    });
}
项目:v2ex-daily-android    文件:LoginActivity.java   
private void login(int onceCode){
    V2EX.login(LoginActivity.this, mUsername.getText().toString(), mPassword.getText().toString(), onceCode, new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            if(LoginActivity.this != null){
                try {
                    if(response.getString("result").equals("ok")){
                        mProgressDialog.setMessage("Get userinfo...");
                        getUserInfo();
                    }else if(response.getString("result").equals("fail")){
                        String errorContent = response.getJSONObject("content").getString("error_msg");
                        MessageUtils.toast(LoginActivity.this, errorContent);
                        mProgressDialog.dismiss();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}
项目:so_moviles    文件:MainActivity.java   
@Override
public void onClick(View view) {
    Log.i("ULIMA", "Hizo click");
    WCRestClient.get("/teams", null, new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers,
                JSONArray response) {
            super.onSuccess(statusCode, headers, response);
            String paises = "";
            for (int i=0; i<response.length(); i++){
                try {
                    JSONObject js = response.getJSONObject(i);
                    String nombre = js.getString("country");    
                    paises += " , " + nombre;
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            ete.setText(paises);
        }
    });
}
项目:SimpleTwitterClient    文件:HomeTimelineFragment.java   
/**
 * Upserts the current logged in user's credentials. Saves to SharedPreferences.
 */
private void upsertCurrentUserCredentials() {
    // JSON request in AsyncTask for verifyCreds.
    // store username, screen_name, profileurl in sharedpref
    // store user profile bitmap in file.
    client.getLoggedInUserCredentials(new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(JSONObject json) {
            User currentUser = User.fromJSON(json);
            // TODO(debangsu): can we avoid using getActivity()?
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()
                    .getApplicationContext());
            SharedPreferences.Editor prefsEditor = prefs.edit();
            Gson gson = new Gson();
            String loggedinUserJson = gson.toJson(currentUser);
            prefsEditor.putString(CURRENT_USER_KEY, loggedinUserJson);
            prefsEditor.commit();
        }

        @Override
        public void onFailure(Throwable e, String s) {
            Log.d("debug", e.toString());
            Log.d("debug", s.toString());
        }
    });
}
项目:SimpleTwitterClient    文件:ComposeActivity.java   
/**
 * Handles user's request to post the tweet. Passes control back to TimelineActivity.
 */
public void onComposeTweet(MenuItem mi) {
    EditText etBody = (EditText) findViewById(R.id.etBody);
    String tweet = etBody.getText().toString();
    etBody.setText("");
    client.postTweet(tweet, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(JSONObject json) {
            Tweet composedTweet = Tweet.fromJSON(json);
            Intent i = new Intent();
            i.putExtra("composedTweet", composedTweet);
            // Package with result.
            setResult(RESULT_OK, i); // e.g. http 200. intent is set similar to post data.
            // Dismiss the activity.
            finish();
        }

        @Override
        public void onFailure(Throwable e, String s) {
            Log.d("debug", e.toString());
            Log.d("debug", s.toString());
            Toast.makeText(ComposeActivity.this, "Error posting tweet",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:SimpleTwitterClient    文件:TwitterClient.java   
/**
 * Performs GET Request to retrieve timeline e.g. home, mentions, user timeslines.
 */
public void getTimeline(String endpoint, Integer count, @Nullable Long maxId,
                        @Nullable String screenName, JsonHttpResponseHandler handler) {
    if (!NetworkUtils.isNetworkAvailable(this.context)) {
        return;
    }
    String apiUrl = getApiUrl(endpoint);
    RequestParams params = new RequestParams();
    params.put("count", String.valueOf(count));
    if (maxId != null) {
        params.put("max_id", String.valueOf(maxId));
    }
    if (screenName != null) {
        params.put("screen_name", screenName);
    }
    client.get(apiUrl, params, handler);
}
项目:Nefete    文件:ViewActivity.java   
private void getAd(final String adID) {
  GoRestClient.get(":8080/ad/" + adID, new JsonHttpResponseHandler() {
    @Override public void onSuccess(JSONObject jsonObject) {
      Log.d(TAG, jsonObject.toString());
      Gson gson = new GsonBuilder().create();
      AdResult adResult = gson.fromJson(jsonObject.toString(), AdResult.class);
      String egg = adResult.getData().getImage1();
      String[] parts = adResult.getData().getImage1().split("_");
      tvTitle.setText(adResult.getData().getTitle());
      tvDescription.setText(adResult.getData().getDescription());
      ivImage1.setBackgroundColor(Color.parseColor("#" + parts[2]));
      if (adResult.status.equals("OK")) {
        Picasso.with(getApplicationContext())
            .load(GoRestClient.getAbsoluteUrl(":9090/egg/" + egg))
            .into(ivImage1);
      }
    }
  });
}
项目:AndroidTwitterApp    文件:ProfileActivity.java   
protected void loadProfileInfo(String user_id) {
    getActionBar().setTitle(R.string.loading_profile);
    TwitterApp.getRestClient().getUserInfo(user_id, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(JSONObject jsonObject) {
            User u = User.fromJson(jsonObject);
            getActionBar().setTitle("@" + u.getScreenName());
            populateProfileHeader(u);
        }

        @Override
        public void onFailure(Throwable e, String s) {
            Log.d("debug", e.toString());
            Toast.makeText(ProfileActivity.this, "Oops,  an error occurred:\n" + e.toString(),
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:codetalk    文件:MessageViewerActivity.java   
private void requestBarcodeDetails(String barcode) throws JSONException {
    UPCDatabaseRestClient.get(barcode, null, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(int a, JSONObject result) {
            if (result != null) {
                try {
                    // for UPC database
                    // if (result.getBoolean("valid")) {
                    // setCodeDetails(result.getString("description"));
                    // }

                    // for EAN database
                    JSONObject product = result.getJSONObject("product");
                    if (product != null) {
                        JSONObject attributes = product.getJSONObject("attributes");
                        if (attributes != null) {
                            setCodeDetails(attributes.getString("product"));
                        }
                    }
                } catch (JSONException e) {
                    // parse error - ignore
                }
            }
        }
    });
}
项目:flow-android    文件:FlowApiRequests.java   
public static void login(String facebookId, String facebookAccessToken,
                         final FlowApiRequestCallback callback) {
    RequestParams params = new RequestParams();
    params.put(Constants.FBID, facebookId);
    params.put(Constants.FACEBOOK_ACCESS_TOKEN, facebookAccessToken);

    FlowAsyncClient.post(Constants.API_LOGIN, params, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(JSONObject response) {
            Log.d(TAG, "Login success");
            callback.onSuccess(response);
        }

        @Override
        public void onFailure(String responseBody, Throwable error) {
            Log.d(TAG, "Login failed");
            callback.onFailure(responseBody);
        }
    });
}
项目:books    文件:BookListFragment.java   
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (scanResult != null) {
        String barcode = scanResult.getContents();
        BookResource.add(getActivity(), barcode, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(JSONObject response) {
                refreshBooks();
                DialogUtil.showOkDialog(getActivity(), R.string.add_book_success_title, R.string.add_book_success);
            }

            @Override
            public void onFailure(Throwable e, JSONObject errorResponse) {
                DialogUtil.showOkDialog(getActivity(), R.string.add_book_error_title, errorResponse.optString("message"));
            }
        });
    }
}
项目:books    文件:ApplicationContext.java   
/**
 * Asynchronously get user info.
 * @param activity Activity
 * @param callbackListener Callback
 */
public void fetchUserInfo(final Activity activity, final CallbackListener callbackListener) {
    UserResource.info(activity.getApplicationContext(), new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(final JSONObject json) {
            // Save data in application context
            if (!json.optBoolean("anonymous", true)) {
                setUserInfo(activity.getApplicationContext(), json);
            }
        }

        @Override
        public void onFinish() {
            if (callbackListener != null) {
                callbackListener.onComplete();
            }
        }
    });
}
项目:books    文件:BookListActivity.java   
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.settings:
            return true;

        case R.id.logout:
            UserResource.logout(getApplicationContext(), new JsonHttpResponseHandler() {
                @Override
                public void onFinish() {
                    // Force logout in all cases, so the user is not stuck in case of network error
                    ApplicationContext.getInstance().setUserInfo(getApplicationContext(), null);
                    startActivity(new Intent(BookListActivity.this, LoginActivity.class));
                    finish();
                }
            });
            return true;
    }

    return super.onOptionsItemSelected(item);
}
项目:java-day-app    文件:ScheduleDetailsFragment.java   
private void sendVote(int rate, final int sessionId) {
    String comment = commentToSpeaker.getText().toString().trim();
    HttpEntity entity = Vote.create(rate, sessionId, comment);
    showProgressDialog();
    FeedbackService.post(getActivity().getApplicationContext(), entity, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(JSONObject response) {
            super.onSuccess(response);
            sharedPrefsService.saveVoteForSession(sessionId);
            setVoteGroupState(sessionId);
            hideProgressDialog();
        }

        @Override
        public void onFailure(Throwable e, JSONObject errorResponse) {
            logger.w("Failed to send Vote");
            hideProgressDialog();
        }
    });
}
项目:StreamHub-Android-SDK    文件:WriteClient.java   
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        The token of the logged in user.
 * @param action
 * @param parameters
 * @param handler      Response handler
 */

public static void flagContent(String collectionId, String contentId,
                               String token, LFSFlag action, RequestParams parameters,
                               JsonHttpResponseHandler handler) {

    String url = (new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("")) +
            contentId + (new Uri.Builder().appendPath("").appendPath("flag")
            .appendPath(flags[action.value()])
            .appendQueryParameter("lftoken", token)
            .appendQueryParameter("collection_id", collectionId));

    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
项目:StreamHub-Android-SDK    文件:WriteClient.java   
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        The token of the logged in user.
 * @param action
 * @param parameters
 * @param networkID    Livefyre provided network name.
 * @param handler      Response handler
 */
public static void flagContent(String collectionId, String contentId,
                               String token, LFSFlag action, RequestParams parameters,
                               String networkID, JsonHttpResponseHandler handler) {

    String url = (new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("")) +
            contentId + (new Uri.Builder().appendPath("").appendPath("flag")
            .appendPath(flags[action.value()])
            .appendQueryParameter("lftoken", token)
            .appendQueryParameter("collection_id", collectionId));

    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
项目:StreamHub-Android-SDK    文件:WriteClient.java   
/**
 * @param action
 * @param contentId
 * @param collectionId The Id of the collection.
 * @param userToken    The token of the logged in user.
 * @param parameters
 * @param handler      Response handler
 * @throws MalformedURLException
 */

public static void featureMessage(String action, String contentId,
                                  String collectionId, String userToken,
                                  HashMap<String, Object> parameters, JsonHttpResponseHandler handler)
        throws MalformedURLException {
    RequestParams bodyParams = new RequestParams();
    bodyParams.put("lftoken", userToken);

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("collection")
            .appendPath(collectionId).appendPath(action)
            .appendPath(contentId).appendPath("")
            .appendQueryParameter("lftoken", userToken)
            .appendQueryParameter("collection_id", collectionId);

    Log.d("SDK", "" + uriBuilder);
    HttpClient.client.post(uriBuilder.toString(), bodyParams, handler);
}
项目:StreamHub-Android-SDK    文件:WriteClient.java   
/**
 * @param action
 * @param contentId
 * @param collectionId The Id of the collection.
 * @param userToken    The token of the logged in user.
 * @param parameters
 * @param networkID    Livefyre provided network name
 * @param handler      Response handler
 * @throws MalformedURLException
 */
public static void featureMessage(String action, String contentId,
                                  String collectionId, String userToken,
                                  HashMap<String, Object> parameters, String networkID, JsonHttpResponseHandler handler)
        throws MalformedURLException {
    RequestParams bodyParams = new RequestParams();
    bodyParams.put("lftoken", userToken);

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("collection")
            .appendPath(collectionId).appendPath(action)
            .appendPath(contentId).appendPath("")
            .appendQueryParameter("lftoken", userToken)
            .appendQueryParameter("collection_id", collectionId);

    Log.d("SDK", "" + uriBuilder);
    HttpClient.client.post(uriBuilder.toString(), bodyParams, handler);
}
项目:StreamHub-Android-SDK    文件:WriteClient.java   
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        The token of the logged in user.
 * @param action
 * @param parameters
 * @param handler      Response handler
 */

public static void postAction(String collectionId, String contentId,
                              String token, LFSActions action, RequestParams parameters,
                              JsonHttpResponseHandler handler) {
    // Build the URL
    String url = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("") + contentId +
            (new Uri.Builder().appendPath(actions[action.value()]).appendPath("")
                    .appendQueryParameter("lftoken", token)
                    .appendQueryParameter("collection_id", collectionId));


    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
项目:StreamHub-Android-SDK    文件:WriteClient.java   
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        Livefyre Token
 * @param action
 * @param parameters
 * @param networkID    Livefyre provided network name
 * @param handler      Response handler
 */

public static void postAction(String collectionId, String contentId,
                              String token, LFSActions action, RequestParams parameters,
                              String networkID, JsonHttpResponseHandler handler) {
    // Build the URL
    String url = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("") + contentId +
            (new Uri.Builder().appendPath(actions[action.value()]).appendPath("")
                    .appendQueryParameter("lftoken", token)
                    .appendQueryParameter("collection_id", collectionId));


    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
项目:otm-android    文件:FallbackGeocoder.java   
public void httpGeocode(String address, JsonHttpResponseHandler handler) {
    String urlFormat = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=%s";
    String url;
    if (extent != null) {
        // Use this format to compose a url for google's geocode
        urlFormat += "&bounds=%f,%f%%7c%f,%f";
        // interpolate address and bounds into that format string
        url = String.format(Locale.US, urlFormat, URLEncoder.encode(address), extent.southwest.latitude,
                extent.southwest.longitude, extent.northeast.latitude, extent.northeast.longitude);
    } else {
        url = String.format(Locale.US, urlFormat, URLEncoder.encode(address));
    }

    // execute the http request.
    client.get(url, new RequestParams(), handler);
}