本文整理汇总了Java中com.loopj.android.http.JsonHttpResponseHandler类的典型用法代码示例。如果您正苦于以下问题:Java JsonHttpResponseHandler类的具体用法?Java JsonHttpResponseHandler怎么用?Java JsonHttpResponseHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonHttpResponseHandler类属于com.loopj.android.http包,在下文中一共展示了JsonHttpResponseHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setBingImg
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
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: 没有获取到类型");
}
}
}
);
}
示例2: onReceive
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
@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() {
});
}
}
示例3: update
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
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);
}
}
});
}
示例4: startLocation
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
/**
* 启动定位服务
*/
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);
}
});
}
示例5: GetWeather
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
/**
* 启动定位服务
*/
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);
}
});
}
示例6: getNews
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
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();
}
}
});
}
示例7: flagContent
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
/**
* @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);
}
示例8: featureMessage
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
/**
* @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);
}
示例9: postAction
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
/**
* @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);
}
示例10: onPostExecute
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
@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);
}
});
}
}
示例11: getAd
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
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);
}
}
});
}
示例12: syncCollection
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
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();
}
}
}
});
}
示例13: syncCollection
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
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();
}
}
});
}
示例14: getOnceCode
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
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();
}
}
}
});
}
示例15: login
import com.loopj.android.http.JsonHttpResponseHandler; //导入依赖的package包/类
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();
}
}
}
});
}